three.js 791 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '72dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. // polyfills
  13. ( function () {
  14. var lastTime = 0;
  15. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  16. for ( var x = 0; x < vendors.length && ! self.requestAnimationFrame; ++ x ) {
  17. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  18. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  19. }
  20. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  21. self.requestAnimationFrame = function ( callback ) {
  22. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  23. var id = self.setTimeout( function () {
  24. callback( currTime + timeToCall );
  25. }, timeToCall );
  26. lastTime = currTime + timeToCall;
  27. return id;
  28. };
  29. }
  30. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  31. self.cancelAnimationFrame = function ( id ) {
  32. self.clearTimeout( id );
  33. };
  34. }
  35. }() );
  36. if ( Math.sign === undefined ) {
  37. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  38. Math.sign = function ( x ) {
  39. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  40. };
  41. }
  42. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  43. // Missing in IE9-11.
  44. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  45. Object.defineProperty( Function.prototype, 'name', {
  46. get: function () {
  47. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  48. }
  49. } );
  50. }
  51. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  52. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  53. // GL STATE CONSTANTS
  54. THREE.CullFaceNone = 0;
  55. THREE.CullFaceBack = 1;
  56. THREE.CullFaceFront = 2;
  57. THREE.CullFaceFrontBack = 3;
  58. THREE.FrontFaceDirectionCW = 0;
  59. THREE.FrontFaceDirectionCCW = 1;
  60. // SHADOWING TYPES
  61. THREE.BasicShadowMap = 0;
  62. THREE.PCFShadowMap = 1;
  63. THREE.PCFSoftShadowMap = 2;
  64. // MATERIAL CONSTANTS
  65. // side
  66. THREE.FrontSide = 0;
  67. THREE.BackSide = 1;
  68. THREE.DoubleSide = 2;
  69. // shading
  70. THREE.NoShading = 0;
  71. THREE.FlatShading = 1;
  72. THREE.SmoothShading = 2;
  73. // colors
  74. THREE.NoColors = 0;
  75. THREE.FaceColors = 1;
  76. THREE.VertexColors = 2;
  77. // blending modes
  78. THREE.NoBlending = 0;
  79. THREE.NormalBlending = 1;
  80. THREE.AdditiveBlending = 2;
  81. THREE.SubtractiveBlending = 3;
  82. THREE.MultiplyBlending = 4;
  83. THREE.CustomBlending = 5;
  84. // custom blending equations
  85. // (numbers start from 100 not to clash with other
  86. // mappings to OpenGL constants defined in Texture.js)
  87. THREE.AddEquation = 100;
  88. THREE.SubtractEquation = 101;
  89. THREE.ReverseSubtractEquation = 102;
  90. THREE.MinEquation = 103;
  91. THREE.MaxEquation = 104;
  92. // custom blending destination factors
  93. THREE.ZeroFactor = 200;
  94. THREE.OneFactor = 201;
  95. THREE.SrcColorFactor = 202;
  96. THREE.OneMinusSrcColorFactor = 203;
  97. THREE.SrcAlphaFactor = 204;
  98. THREE.OneMinusSrcAlphaFactor = 205;
  99. THREE.DstAlphaFactor = 206;
  100. THREE.OneMinusDstAlphaFactor = 207;
  101. // custom blending source factors
  102. //THREE.ZeroFactor = 200;
  103. //THREE.OneFactor = 201;
  104. //THREE.SrcAlphaFactor = 204;
  105. //THREE.OneMinusSrcAlphaFactor = 205;
  106. //THREE.DstAlphaFactor = 206;
  107. //THREE.OneMinusDstAlphaFactor = 207;
  108. THREE.DstColorFactor = 208;
  109. THREE.OneMinusDstColorFactor = 209;
  110. THREE.SrcAlphaSaturateFactor = 210;
  111. // depth modes
  112. THREE.NeverDepth = 0;
  113. THREE.AlwaysDepth = 1;
  114. THREE.LessDepth = 2;
  115. THREE.LessEqualDepth = 3;
  116. THREE.EqualDepth = 4;
  117. THREE.GreaterEqualDepth = 5;
  118. THREE.GreaterDepth = 6;
  119. THREE.NotEqualDepth = 7;
  120. // TEXTURE CONSTANTS
  121. THREE.MultiplyOperation = 0;
  122. THREE.MixOperation = 1;
  123. THREE.AddOperation = 2;
  124. // Mapping modes
  125. THREE.UVMapping = 300;
  126. THREE.CubeReflectionMapping = 301;
  127. THREE.CubeRefractionMapping = 302;
  128. THREE.EquirectangularReflectionMapping = 303;
  129. THREE.EquirectangularRefractionMapping = 304;
  130. THREE.SphericalReflectionMapping = 305;
  131. // Wrapping modes
  132. THREE.RepeatWrapping = 1000;
  133. THREE.ClampToEdgeWrapping = 1001;
  134. THREE.MirroredRepeatWrapping = 1002;
  135. // Filters
  136. THREE.NearestFilter = 1003;
  137. THREE.NearestMipMapNearestFilter = 1004;
  138. THREE.NearestMipMapLinearFilter = 1005;
  139. THREE.LinearFilter = 1006;
  140. THREE.LinearMipMapNearestFilter = 1007;
  141. THREE.LinearMipMapLinearFilter = 1008;
  142. // Data types
  143. THREE.UnsignedByteType = 1009;
  144. THREE.ByteType = 1010;
  145. THREE.ShortType = 1011;
  146. THREE.UnsignedShortType = 1012;
  147. THREE.IntType = 1013;
  148. THREE.UnsignedIntType = 1014;
  149. THREE.FloatType = 1015;
  150. THREE.HalfFloatType = 1025;
  151. // Pixel types
  152. //THREE.UnsignedByteType = 1009;
  153. THREE.UnsignedShort4444Type = 1016;
  154. THREE.UnsignedShort5551Type = 1017;
  155. THREE.UnsignedShort565Type = 1018;
  156. // Pixel formats
  157. THREE.AlphaFormat = 1019;
  158. THREE.RGBFormat = 1020;
  159. THREE.RGBAFormat = 1021;
  160. THREE.LuminanceFormat = 1022;
  161. THREE.LuminanceAlphaFormat = 1023;
  162. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  163. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  164. // DDS / ST3C Compressed texture formats
  165. THREE.RGB_S3TC_DXT1_Format = 2001;
  166. THREE.RGBA_S3TC_DXT1_Format = 2002;
  167. THREE.RGBA_S3TC_DXT3_Format = 2003;
  168. THREE.RGBA_S3TC_DXT5_Format = 2004;
  169. // PVRTC compressed texture formats
  170. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  171. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  172. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  173. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  174. // DEPRECATED
  175. THREE.Projector = function () {
  176. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  177. this.projectVector = function ( vector, camera ) {
  178. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  179. vector.project( camera );
  180. };
  181. this.unprojectVector = function ( vector, camera ) {
  182. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  183. vector.unproject( camera );
  184. };
  185. this.pickingRay = function ( vector, camera ) {
  186. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  187. };
  188. };
  189. THREE.CanvasRenderer = function () {
  190. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  191. this.domElement = document.createElement( 'canvas' );
  192. this.clear = function () {};
  193. this.render = function () {};
  194. this.setClearColor = function () {};
  195. this.setSize = function () {};
  196. };
  197. // File:src/math/Color.js
  198. /**
  199. * @author mrdoob / http://mrdoob.com/
  200. */
  201. THREE.Color = function ( color ) {
  202. if ( arguments.length === 3 ) {
  203. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  204. }
  205. return this.set( color );
  206. };
  207. THREE.Color.prototype = {
  208. constructor: THREE.Color,
  209. r: 1, g: 1, b: 1,
  210. set: function ( value ) {
  211. if ( value instanceof THREE.Color ) {
  212. this.copy( value );
  213. } else if ( typeof value === 'number' ) {
  214. this.setHex( value );
  215. } else if ( typeof value === 'string' ) {
  216. this.setStyle( value );
  217. }
  218. return this;
  219. },
  220. setHex: function ( hex ) {
  221. hex = Math.floor( hex );
  222. this.r = ( hex >> 16 & 255 ) / 255;
  223. this.g = ( hex >> 8 & 255 ) / 255;
  224. this.b = ( hex & 255 ) / 255;
  225. return this;
  226. },
  227. setRGB: function ( r, g, b ) {
  228. this.r = r;
  229. this.g = g;
  230. this.b = b;
  231. return this;
  232. },
  233. setHSL: function () {
  234. function hue2rgb ( p, q, t ) {
  235. if ( t < 0 ) t += 1;
  236. if ( t > 1 ) t -= 1;
  237. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  238. if ( t < 1 / 2 ) return q;
  239. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  240. return p;
  241. }
  242. return function ( h, s, l ) {
  243. // h,s,l ranges are in 0.0 - 1.0
  244. h = THREE.Math.euclideanModulo( h, 1 );
  245. s = THREE.Math.clamp( s, 0, 1 );
  246. l = THREE.Math.clamp( l, 0, 1 );
  247. if ( s === 0 ) {
  248. this.r = this.g = this.b = l;
  249. } else {
  250. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  251. var q = ( 2 * l ) - p;
  252. this.r = hue2rgb( q, p, h + 1 / 3 );
  253. this.g = hue2rgb( q, p, h );
  254. this.b = hue2rgb( q, p, h - 1 / 3 );
  255. }
  256. return this;
  257. };
  258. }(),
  259. setStyle: function ( style ) {
  260. var parseAlpha = function ( strAlpha ) {
  261. var alpha = parseFloat( strAlpha );
  262. if ( alpha < 1 ) {
  263. console.warn( 'THREE.Color: Alpha component of color ' + style + ' will be ignored.' );
  264. }
  265. return alpha;
  266. }
  267. var m;
  268. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  269. // rgb / hsl
  270. var color;
  271. var name = m[ 1 ];
  272. var components = m[ 2 ];
  273. switch ( name ) {
  274. case 'rgb':
  275. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*$/.exec( components ) ) {
  276. // rgb(255,0,0)
  277. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  278. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  279. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  280. return this;
  281. }
  282. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  283. // rgb(100%,0%,0%)
  284. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  285. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  286. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  287. return this;
  288. }
  289. break;
  290. case 'rgba':
  291. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  292. // rgba(255,0,0,0.5)
  293. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  294. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  295. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  296. parseAlpha( color[ 4 ] );
  297. return this;
  298. }
  299. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  300. // rgba(100%,0%,0%,0.5)
  301. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  302. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  303. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  304. parseAlpha( color[ 4 ] );
  305. return this;
  306. }
  307. break;
  308. case 'hsl':
  309. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  310. // hsl(120,50%,50%)
  311. var h = parseFloat( color[ 1 ] );
  312. var s = parseInt( color[ 2 ], 10 ) / 100;
  313. var l = parseInt( color[ 3 ], 10 ) / 100;
  314. return this.setHSL( h, s, l );
  315. }
  316. break;
  317. case 'hsla':
  318. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  319. // hsla(120,50%,50%,0.5)
  320. var h = parseFloat( color[ 1 ] );
  321. var s = parseInt( color[ 2 ], 10 ) / 100;
  322. var l = parseInt( color[ 3 ], 10 ) / 100;
  323. parseAlpha( color[ 4 ] );
  324. return this.setHSL( h, s, l );
  325. }
  326. break;
  327. }
  328. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  329. // hex color
  330. var hex = m[ 1 ];
  331. var size = hex.length;
  332. if ( size === 3 ) {
  333. // #ff0
  334. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  335. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  336. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  337. return this;
  338. } else if ( size === 6 ) {
  339. // #ff0000
  340. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  341. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  342. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  343. return this;
  344. }
  345. }
  346. if ( style && style.length > 0 ) {
  347. // color keywords
  348. var hex = THREE.ColorKeywords[ style ];
  349. if ( hex !== undefined ) {
  350. // red
  351. this.setHex( hex );
  352. } else {
  353. // unknown color
  354. console.warn( 'THREE.Color: Unknown color ' + style );
  355. }
  356. }
  357. return this;
  358. },
  359. copy: function ( color ) {
  360. this.r = color.r;
  361. this.g = color.g;
  362. this.b = color.b;
  363. return this;
  364. },
  365. copyGammaToLinear: function ( color, gammaFactor ) {
  366. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  367. this.r = Math.pow( color.r, gammaFactor );
  368. this.g = Math.pow( color.g, gammaFactor );
  369. this.b = Math.pow( color.b, gammaFactor );
  370. return this;
  371. },
  372. copyLinearToGamma: function ( color, gammaFactor ) {
  373. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  374. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  375. this.r = Math.pow( color.r, safeInverse );
  376. this.g = Math.pow( color.g, safeInverse );
  377. this.b = Math.pow( color.b, safeInverse );
  378. return this;
  379. },
  380. convertGammaToLinear: function () {
  381. var r = this.r, g = this.g, b = this.b;
  382. this.r = r * r;
  383. this.g = g * g;
  384. this.b = b * b;
  385. return this;
  386. },
  387. convertLinearToGamma: function () {
  388. this.r = Math.sqrt( this.r );
  389. this.g = Math.sqrt( this.g );
  390. this.b = Math.sqrt( this.b );
  391. return this;
  392. },
  393. getHex: function () {
  394. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  395. },
  396. getHexString: function () {
  397. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  398. },
  399. getHSL: function ( optionalTarget ) {
  400. // h,s,l ranges are in 0.0 - 1.0
  401. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  402. var r = this.r, g = this.g, b = this.b;
  403. var max = Math.max( r, g, b );
  404. var min = Math.min( r, g, b );
  405. var hue, saturation;
  406. var lightness = ( min + max ) / 2.0;
  407. if ( min === max ) {
  408. hue = 0;
  409. saturation = 0;
  410. } else {
  411. var delta = max - min;
  412. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  413. switch ( max ) {
  414. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  415. case g: hue = ( b - r ) / delta + 2; break;
  416. case b: hue = ( r - g ) / delta + 4; break;
  417. }
  418. hue /= 6;
  419. }
  420. hsl.h = hue;
  421. hsl.s = saturation;
  422. hsl.l = lightness;
  423. return hsl;
  424. },
  425. getStyle: function () {
  426. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  427. },
  428. offsetHSL: function ( h, s, l ) {
  429. var hsl = this.getHSL();
  430. hsl.h += h; hsl.s += s; hsl.l += l;
  431. this.setHSL( hsl.h, hsl.s, hsl.l );
  432. return this;
  433. },
  434. add: function ( color ) {
  435. this.r += color.r;
  436. this.g += color.g;
  437. this.b += color.b;
  438. return this;
  439. },
  440. addColors: function ( color1, color2 ) {
  441. this.r = color1.r + color2.r;
  442. this.g = color1.g + color2.g;
  443. this.b = color1.b + color2.b;
  444. return this;
  445. },
  446. addScalar: function ( s ) {
  447. this.r += s;
  448. this.g += s;
  449. this.b += s;
  450. return this;
  451. },
  452. multiply: function ( color ) {
  453. this.r *= color.r;
  454. this.g *= color.g;
  455. this.b *= color.b;
  456. return this;
  457. },
  458. multiplyScalar: function ( s ) {
  459. this.r *= s;
  460. this.g *= s;
  461. this.b *= s;
  462. return this;
  463. },
  464. lerp: function ( color, alpha ) {
  465. this.r += ( color.r - this.r ) * alpha;
  466. this.g += ( color.g - this.g ) * alpha;
  467. this.b += ( color.b - this.b ) * alpha;
  468. return this;
  469. },
  470. equals: function ( c ) {
  471. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  472. },
  473. fromArray: function ( array ) {
  474. this.r = array[ 0 ];
  475. this.g = array[ 1 ];
  476. this.b = array[ 2 ];
  477. return this;
  478. },
  479. toArray: function ( array, offset ) {
  480. if ( array === undefined ) array = [];
  481. if ( offset === undefined ) offset = 0;
  482. array[ offset ] = this.r;
  483. array[ offset + 1 ] = this.g;
  484. array[ offset + 2 ] = this.b;
  485. return array;
  486. },
  487. clone: function () {
  488. return new THREE.Color().copy( this );
  489. }
  490. };
  491. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  492. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  493. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  494. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  495. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  496. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  497. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  498. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  499. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  500. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  501. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  502. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  503. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  504. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  505. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  506. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  507. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  508. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  509. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  510. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  511. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  512. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  513. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  514. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  515. // File:src/math/Quaternion.js
  516. /**
  517. * @author mikael emtinger / http://gomo.se/
  518. * @author alteredq / http://alteredqualia.com/
  519. * @author WestLangley / http://github.com/WestLangley
  520. * @author bhouston / http://exocortex.com
  521. */
  522. THREE.Quaternion = function ( x, y, z, w ) {
  523. this._x = x || 0;
  524. this._y = y || 0;
  525. this._z = z || 0;
  526. this._w = ( w !== undefined ) ? w : 1;
  527. };
  528. THREE.Quaternion.prototype = {
  529. constructor: THREE.Quaternion,
  530. get x () {
  531. return this._x;
  532. },
  533. set x ( value ) {
  534. this._x = value;
  535. this.onChangeCallback();
  536. },
  537. get y () {
  538. return this._y;
  539. },
  540. set y ( value ) {
  541. this._y = value;
  542. this.onChangeCallback();
  543. },
  544. get z () {
  545. return this._z;
  546. },
  547. set z ( value ) {
  548. this._z = value;
  549. this.onChangeCallback();
  550. },
  551. get w () {
  552. return this._w;
  553. },
  554. set w ( value ) {
  555. this._w = value;
  556. this.onChangeCallback();
  557. },
  558. set: function ( x, y, z, w ) {
  559. this._x = x;
  560. this._y = y;
  561. this._z = z;
  562. this._w = w;
  563. this.onChangeCallback();
  564. return this;
  565. },
  566. copy: function ( quaternion ) {
  567. this._x = quaternion.x;
  568. this._y = quaternion.y;
  569. this._z = quaternion.z;
  570. this._w = quaternion.w;
  571. this.onChangeCallback();
  572. return this;
  573. },
  574. setFromEuler: function ( euler, update ) {
  575. if ( euler instanceof THREE.Euler === false ) {
  576. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  577. }
  578. // http://www.mathworks.com/matlabcentral/fileexchange/
  579. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  580. // content/SpinCalc.m
  581. var c1 = Math.cos( euler._x / 2 );
  582. var c2 = Math.cos( euler._y / 2 );
  583. var c3 = Math.cos( euler._z / 2 );
  584. var s1 = Math.sin( euler._x / 2 );
  585. var s2 = Math.sin( euler._y / 2 );
  586. var s3 = Math.sin( euler._z / 2 );
  587. if ( euler.order === 'XYZ' ) {
  588. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  589. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  590. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  591. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  592. } else if ( euler.order === 'YXZ' ) {
  593. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  594. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  595. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  596. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  597. } else if ( euler.order === 'ZXY' ) {
  598. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  599. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  600. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  601. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  602. } else if ( euler.order === 'ZYX' ) {
  603. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  604. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  605. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  606. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  607. } else if ( euler.order === 'YZX' ) {
  608. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  609. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  610. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  611. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  612. } else if ( euler.order === 'XZY' ) {
  613. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  614. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  615. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  616. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  617. }
  618. if ( update !== false ) this.onChangeCallback();
  619. return this;
  620. },
  621. setFromAxisAngle: function ( axis, angle ) {
  622. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  623. // assumes axis is normalized
  624. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  625. this._x = axis.x * s;
  626. this._y = axis.y * s;
  627. this._z = axis.z * s;
  628. this._w = Math.cos( halfAngle );
  629. this.onChangeCallback();
  630. return this;
  631. },
  632. setFromRotationMatrix: function ( m ) {
  633. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  634. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  635. var te = m.elements,
  636. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  637. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  638. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  639. trace = m11 + m22 + m33,
  640. s;
  641. if ( trace > 0 ) {
  642. s = 0.5 / Math.sqrt( trace + 1.0 );
  643. this._w = 0.25 / s;
  644. this._x = ( m32 - m23 ) * s;
  645. this._y = ( m13 - m31 ) * s;
  646. this._z = ( m21 - m12 ) * s;
  647. } else if ( m11 > m22 && m11 > m33 ) {
  648. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  649. this._w = ( m32 - m23 ) / s;
  650. this._x = 0.25 * s;
  651. this._y = ( m12 + m21 ) / s;
  652. this._z = ( m13 + m31 ) / s;
  653. } else if ( m22 > m33 ) {
  654. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  655. this._w = ( m13 - m31 ) / s;
  656. this._x = ( m12 + m21 ) / s;
  657. this._y = 0.25 * s;
  658. this._z = ( m23 + m32 ) / s;
  659. } else {
  660. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  661. this._w = ( m21 - m12 ) / s;
  662. this._x = ( m13 + m31 ) / s;
  663. this._y = ( m23 + m32 ) / s;
  664. this._z = 0.25 * s;
  665. }
  666. this.onChangeCallback();
  667. return this;
  668. },
  669. setFromUnitVectors: function () {
  670. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  671. // assumes direction vectors vFrom and vTo are normalized
  672. var v1, r;
  673. var EPS = 0.000001;
  674. return function ( vFrom, vTo ) {
  675. if ( v1 === undefined ) v1 = new THREE.Vector3();
  676. r = vFrom.dot( vTo ) + 1;
  677. if ( r < EPS ) {
  678. r = 0;
  679. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  680. v1.set( - vFrom.y, vFrom.x, 0 );
  681. } else {
  682. v1.set( 0, - vFrom.z, vFrom.y );
  683. }
  684. } else {
  685. v1.crossVectors( vFrom, vTo );
  686. }
  687. this._x = v1.x;
  688. this._y = v1.y;
  689. this._z = v1.z;
  690. this._w = r;
  691. this.normalize();
  692. return this;
  693. }
  694. }(),
  695. inverse: function () {
  696. this.conjugate().normalize();
  697. return this;
  698. },
  699. conjugate: function () {
  700. this._x *= - 1;
  701. this._y *= - 1;
  702. this._z *= - 1;
  703. this.onChangeCallback();
  704. return this;
  705. },
  706. dot: function ( v ) {
  707. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  708. },
  709. lengthSq: function () {
  710. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  711. },
  712. length: function () {
  713. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  714. },
  715. normalize: function () {
  716. var l = this.length();
  717. if ( l === 0 ) {
  718. this._x = 0;
  719. this._y = 0;
  720. this._z = 0;
  721. this._w = 1;
  722. } else {
  723. l = 1 / l;
  724. this._x = this._x * l;
  725. this._y = this._y * l;
  726. this._z = this._z * l;
  727. this._w = this._w * l;
  728. }
  729. this.onChangeCallback();
  730. return this;
  731. },
  732. multiply: function ( q, p ) {
  733. if ( p !== undefined ) {
  734. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  735. return this.multiplyQuaternions( q, p );
  736. }
  737. return this.multiplyQuaternions( this, q );
  738. },
  739. multiplyQuaternions: function ( a, b ) {
  740. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  741. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  742. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  743. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  744. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  745. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  746. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  747. this.onChangeCallback();
  748. return this;
  749. },
  750. multiplyVector3: function ( vector ) {
  751. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  752. return vector.applyQuaternion( this );
  753. },
  754. slerp: function ( qb, t ) {
  755. if ( t === 0 ) return this;
  756. if ( t === 1 ) return this.copy( qb );
  757. var x = this._x, y = this._y, z = this._z, w = this._w;
  758. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  759. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  760. if ( cosHalfTheta < 0 ) {
  761. this._w = - qb._w;
  762. this._x = - qb._x;
  763. this._y = - qb._y;
  764. this._z = - qb._z;
  765. cosHalfTheta = - cosHalfTheta;
  766. } else {
  767. this.copy( qb );
  768. }
  769. if ( cosHalfTheta >= 1.0 ) {
  770. this._w = w;
  771. this._x = x;
  772. this._y = y;
  773. this._z = z;
  774. return this;
  775. }
  776. var halfTheta = Math.acos( cosHalfTheta );
  777. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  778. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  779. this._w = 0.5 * ( w + this._w );
  780. this._x = 0.5 * ( x + this._x );
  781. this._y = 0.5 * ( y + this._y );
  782. this._z = 0.5 * ( z + this._z );
  783. return this;
  784. }
  785. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  786. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  787. this._w = ( w * ratioA + this._w * ratioB );
  788. this._x = ( x * ratioA + this._x * ratioB );
  789. this._y = ( y * ratioA + this._y * ratioB );
  790. this._z = ( z * ratioA + this._z * ratioB );
  791. this.onChangeCallback();
  792. return this;
  793. },
  794. equals: function ( quaternion ) {
  795. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  796. },
  797. fromArray: function ( array, offset ) {
  798. if ( offset === undefined ) offset = 0;
  799. this._x = array[ offset ];
  800. this._y = array[ offset + 1 ];
  801. this._z = array[ offset + 2 ];
  802. this._w = array[ offset + 3 ];
  803. this.onChangeCallback();
  804. return this;
  805. },
  806. toArray: function ( array, offset ) {
  807. if ( array === undefined ) array = [];
  808. if ( offset === undefined ) offset = 0;
  809. array[ offset ] = this._x;
  810. array[ offset + 1 ] = this._y;
  811. array[ offset + 2 ] = this._z;
  812. array[ offset + 3 ] = this._w;
  813. return array;
  814. },
  815. onChange: function ( callback ) {
  816. this.onChangeCallback = callback;
  817. return this;
  818. },
  819. onChangeCallback: function () {},
  820. clone: function () {
  821. return new THREE.Quaternion( this._x, this._y, this._z, this._w );
  822. }
  823. };
  824. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  825. return qm.copy( qa ).slerp( qb, t );
  826. };
  827. // File:src/math/Vector2.js
  828. /**
  829. * @author mrdoob / http://mrdoob.com/
  830. * @author philogb / http://blog.thejit.org/
  831. * @author egraether / http://egraether.com/
  832. * @author zz85 / http://www.lab4games.net/zz85/blog
  833. */
  834. THREE.Vector2 = function ( x, y ) {
  835. this.x = x || 0;
  836. this.y = y || 0;
  837. };
  838. THREE.Vector2.prototype = {
  839. constructor: THREE.Vector2,
  840. set: function ( x, y ) {
  841. this.x = x;
  842. this.y = y;
  843. return this;
  844. },
  845. setX: function ( x ) {
  846. this.x = x;
  847. return this;
  848. },
  849. setY: function ( y ) {
  850. this.y = y;
  851. return this;
  852. },
  853. setComponent: function ( index, value ) {
  854. switch ( index ) {
  855. case 0: this.x = value; break;
  856. case 1: this.y = value; break;
  857. default: throw new Error( 'index is out of range: ' + index );
  858. }
  859. },
  860. getComponent: function ( index ) {
  861. switch ( index ) {
  862. case 0: return this.x;
  863. case 1: return this.y;
  864. default: throw new Error( 'index is out of range: ' + index );
  865. }
  866. },
  867. copy: function ( v ) {
  868. this.x = v.x;
  869. this.y = v.y;
  870. return this;
  871. },
  872. add: function ( v, w ) {
  873. if ( w !== undefined ) {
  874. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  875. return this.addVectors( v, w );
  876. }
  877. this.x += v.x;
  878. this.y += v.y;
  879. return this;
  880. },
  881. addScalar: function ( s ) {
  882. this.x += s;
  883. this.y += s;
  884. return this;
  885. },
  886. addVectors: function ( a, b ) {
  887. this.x = a.x + b.x;
  888. this.y = a.y + b.y;
  889. return this;
  890. },
  891. addScaledVector: function ( v, s ) {
  892. this.x += v.x * s;
  893. this.y += v.y * s;
  894. return this;
  895. },
  896. sub: function ( v, w ) {
  897. if ( w !== undefined ) {
  898. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  899. return this.subVectors( v, w );
  900. }
  901. this.x -= v.x;
  902. this.y -= v.y;
  903. return this;
  904. },
  905. subScalar: function ( s ) {
  906. this.x -= s;
  907. this.y -= s;
  908. return this;
  909. },
  910. subVectors: function ( a, b ) {
  911. this.x = a.x - b.x;
  912. this.y = a.y - b.y;
  913. return this;
  914. },
  915. multiply: function ( v ) {
  916. this.x *= v.x;
  917. this.y *= v.y;
  918. return this;
  919. },
  920. multiplyScalar: function ( s ) {
  921. this.x *= s;
  922. this.y *= s;
  923. return this;
  924. },
  925. divide: function ( v ) {
  926. this.x /= v.x;
  927. this.y /= v.y;
  928. return this;
  929. },
  930. divideScalar: function ( scalar ) {
  931. if ( scalar !== 0 ) {
  932. var invScalar = 1 / scalar;
  933. this.x *= invScalar;
  934. this.y *= invScalar;
  935. } else {
  936. this.x = 0;
  937. this.y = 0;
  938. }
  939. return this;
  940. },
  941. min: function ( v ) {
  942. if ( this.x > v.x ) {
  943. this.x = v.x;
  944. }
  945. if ( this.y > v.y ) {
  946. this.y = v.y;
  947. }
  948. return this;
  949. },
  950. max: function ( v ) {
  951. if ( this.x < v.x ) {
  952. this.x = v.x;
  953. }
  954. if ( this.y < v.y ) {
  955. this.y = v.y;
  956. }
  957. return this;
  958. },
  959. clamp: function ( min, max ) {
  960. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  961. if ( this.x < min.x ) {
  962. this.x = min.x;
  963. } else if ( this.x > max.x ) {
  964. this.x = max.x;
  965. }
  966. if ( this.y < min.y ) {
  967. this.y = min.y;
  968. } else if ( this.y > max.y ) {
  969. this.y = max.y;
  970. }
  971. return this;
  972. },
  973. clampScalar: function () {
  974. var min, max;
  975. return function clampScalar( minVal, maxVal ) {
  976. if ( min === undefined ) {
  977. min = new THREE.Vector2();
  978. max = new THREE.Vector2();
  979. }
  980. min.set( minVal, minVal );
  981. max.set( maxVal, maxVal );
  982. return this.clamp( min, max );
  983. };
  984. }(),
  985. floor: function () {
  986. this.x = Math.floor( this.x );
  987. this.y = Math.floor( this.y );
  988. return this;
  989. },
  990. ceil: function () {
  991. this.x = Math.ceil( this.x );
  992. this.y = Math.ceil( this.y );
  993. return this;
  994. },
  995. round: function () {
  996. this.x = Math.round( this.x );
  997. this.y = Math.round( this.y );
  998. return this;
  999. },
  1000. roundToZero: function () {
  1001. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1002. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1003. return this;
  1004. },
  1005. negate: function () {
  1006. this.x = - this.x;
  1007. this.y = - this.y;
  1008. return this;
  1009. },
  1010. dot: function ( v ) {
  1011. return this.x * v.x + this.y * v.y;
  1012. },
  1013. lengthSq: function () {
  1014. return this.x * this.x + this.y * this.y;
  1015. },
  1016. length: function () {
  1017. return Math.sqrt( this.x * this.x + this.y * this.y );
  1018. },
  1019. lengthManhattan: function() {
  1020. return Math.abs( this.x ) + Math.abs( this.y );
  1021. },
  1022. normalize: function () {
  1023. return this.divideScalar( this.length() );
  1024. },
  1025. distanceTo: function ( v ) {
  1026. return Math.sqrt( this.distanceToSquared( v ) );
  1027. },
  1028. distanceToSquared: function ( v ) {
  1029. var dx = this.x - v.x, dy = this.y - v.y;
  1030. return dx * dx + dy * dy;
  1031. },
  1032. setLength: function ( l ) {
  1033. var oldLength = this.length();
  1034. if ( oldLength !== 0 && l !== oldLength ) {
  1035. this.multiplyScalar( l / oldLength );
  1036. }
  1037. return this;
  1038. },
  1039. lerp: function ( v, alpha ) {
  1040. this.x += ( v.x - this.x ) * alpha;
  1041. this.y += ( v.y - this.y ) * alpha;
  1042. return this;
  1043. },
  1044. lerpVectors: function ( v1, v2, alpha ) {
  1045. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1046. return this;
  1047. },
  1048. equals: function ( v ) {
  1049. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1050. },
  1051. fromArray: function ( array, offset ) {
  1052. if ( offset === undefined ) offset = 0;
  1053. this.x = array[ offset ];
  1054. this.y = array[ offset + 1 ];
  1055. return this;
  1056. },
  1057. toArray: function ( array, offset ) {
  1058. if ( array === undefined ) array = [];
  1059. if ( offset === undefined ) offset = 0;
  1060. array[ offset ] = this.x;
  1061. array[ offset + 1 ] = this.y;
  1062. return array;
  1063. },
  1064. fromAttribute: function ( attribute, index, offset ) {
  1065. if ( offset === undefined ) offset = 0;
  1066. index = index * attribute.itemSize + offset;
  1067. this.x = attribute.array[ index ];
  1068. this.y = attribute.array[ index + 1 ];
  1069. return this;
  1070. },
  1071. clone: function () {
  1072. return new THREE.Vector2( this.x, this.y );
  1073. }
  1074. };
  1075. // File:src/math/Vector3.js
  1076. /**
  1077. * @author mrdoob / http://mrdoob.com/
  1078. * @author *kile / http://kile.stravaganza.org/
  1079. * @author philogb / http://blog.thejit.org/
  1080. * @author mikael emtinger / http://gomo.se/
  1081. * @author egraether / http://egraether.com/
  1082. * @author WestLangley / http://github.com/WestLangley
  1083. */
  1084. THREE.Vector3 = function ( x, y, z ) {
  1085. this.x = x || 0;
  1086. this.y = y || 0;
  1087. this.z = z || 0;
  1088. };
  1089. THREE.Vector3.prototype = {
  1090. constructor: THREE.Vector3,
  1091. set: function ( x, y, z ) {
  1092. this.x = x;
  1093. this.y = y;
  1094. this.z = z;
  1095. return this;
  1096. },
  1097. setX: function ( x ) {
  1098. this.x = x;
  1099. return this;
  1100. },
  1101. setY: function ( y ) {
  1102. this.y = y;
  1103. return this;
  1104. },
  1105. setZ: function ( z ) {
  1106. this.z = z;
  1107. return this;
  1108. },
  1109. setComponent: function ( index, value ) {
  1110. switch ( index ) {
  1111. case 0: this.x = value; break;
  1112. case 1: this.y = value; break;
  1113. case 2: this.z = value; break;
  1114. default: throw new Error( 'index is out of range: ' + index );
  1115. }
  1116. },
  1117. getComponent: function ( index ) {
  1118. switch ( index ) {
  1119. case 0: return this.x;
  1120. case 1: return this.y;
  1121. case 2: return this.z;
  1122. default: throw new Error( 'index is out of range: ' + index );
  1123. }
  1124. },
  1125. copy: function ( v ) {
  1126. this.x = v.x;
  1127. this.y = v.y;
  1128. this.z = v.z;
  1129. return this;
  1130. },
  1131. add: function ( v, w ) {
  1132. if ( w !== undefined ) {
  1133. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1134. return this.addVectors( v, w );
  1135. }
  1136. this.x += v.x;
  1137. this.y += v.y;
  1138. this.z += v.z;
  1139. return this;
  1140. },
  1141. addScalar: function ( s ) {
  1142. this.x += s;
  1143. this.y += s;
  1144. this.z += s;
  1145. return this;
  1146. },
  1147. addVectors: function ( a, b ) {
  1148. this.x = a.x + b.x;
  1149. this.y = a.y + b.y;
  1150. this.z = a.z + b.z;
  1151. return this;
  1152. },
  1153. addScaledVector: function ( v, s ) {
  1154. this.x += v.x * s;
  1155. this.y += v.y * s;
  1156. this.z += v.z * s;
  1157. return this;
  1158. },
  1159. sub: function ( v, w ) {
  1160. if ( w !== undefined ) {
  1161. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1162. return this.subVectors( v, w );
  1163. }
  1164. this.x -= v.x;
  1165. this.y -= v.y;
  1166. this.z -= v.z;
  1167. return this;
  1168. },
  1169. subScalar: function ( s ) {
  1170. this.x -= s;
  1171. this.y -= s;
  1172. this.z -= s;
  1173. return this;
  1174. },
  1175. subVectors: function ( a, b ) {
  1176. this.x = a.x - b.x;
  1177. this.y = a.y - b.y;
  1178. this.z = a.z - b.z;
  1179. return this;
  1180. },
  1181. multiply: function ( v, w ) {
  1182. if ( w !== undefined ) {
  1183. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1184. return this.multiplyVectors( v, w );
  1185. }
  1186. this.x *= v.x;
  1187. this.y *= v.y;
  1188. this.z *= v.z;
  1189. return this;
  1190. },
  1191. multiplyScalar: function ( scalar ) {
  1192. this.x *= scalar;
  1193. this.y *= scalar;
  1194. this.z *= scalar;
  1195. return this;
  1196. },
  1197. multiplyVectors: function ( a, b ) {
  1198. this.x = a.x * b.x;
  1199. this.y = a.y * b.y;
  1200. this.z = a.z * b.z;
  1201. return this;
  1202. },
  1203. applyEuler: function () {
  1204. var quaternion;
  1205. return function applyEuler( euler ) {
  1206. if ( euler instanceof THREE.Euler === false ) {
  1207. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1208. }
  1209. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1210. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1211. return this;
  1212. };
  1213. }(),
  1214. applyAxisAngle: function () {
  1215. var quaternion;
  1216. return function applyAxisAngle( axis, angle ) {
  1217. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1218. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1219. return this;
  1220. };
  1221. }(),
  1222. applyMatrix3: function ( m ) {
  1223. var x = this.x;
  1224. var y = this.y;
  1225. var z = this.z;
  1226. var e = m.elements;
  1227. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1228. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1229. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1230. return this;
  1231. },
  1232. applyMatrix4: function ( m ) {
  1233. // input: THREE.Matrix4 affine matrix
  1234. var x = this.x, y = this.y, z = this.z;
  1235. var e = m.elements;
  1236. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1237. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1238. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1239. return this;
  1240. },
  1241. applyProjection: function ( m ) {
  1242. // input: THREE.Matrix4 projection matrix
  1243. var x = this.x, y = this.y, z = this.z;
  1244. var e = m.elements;
  1245. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1246. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1247. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1248. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1249. return this;
  1250. },
  1251. applyQuaternion: function ( q ) {
  1252. var x = this.x;
  1253. var y = this.y;
  1254. var z = this.z;
  1255. var qx = q.x;
  1256. var qy = q.y;
  1257. var qz = q.z;
  1258. var qw = q.w;
  1259. // calculate quat * vector
  1260. var ix = qw * x + qy * z - qz * y;
  1261. var iy = qw * y + qz * x - qx * z;
  1262. var iz = qw * z + qx * y - qy * x;
  1263. var iw = - qx * x - qy * y - qz * z;
  1264. // calculate result * inverse quat
  1265. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1266. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1267. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1268. return this;
  1269. },
  1270. project: function () {
  1271. var matrix;
  1272. return function project( camera ) {
  1273. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1274. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1275. return this.applyProjection( matrix );
  1276. };
  1277. }(),
  1278. unproject: function () {
  1279. var matrix;
  1280. return function unproject( camera ) {
  1281. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1282. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1283. return this.applyProjection( matrix );
  1284. };
  1285. }(),
  1286. transformDirection: function ( m ) {
  1287. // input: THREE.Matrix4 affine matrix
  1288. // vector interpreted as a direction
  1289. var x = this.x, y = this.y, z = this.z;
  1290. var e = m.elements;
  1291. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1292. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1293. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1294. this.normalize();
  1295. return this;
  1296. },
  1297. divide: function ( v ) {
  1298. this.x /= v.x;
  1299. this.y /= v.y;
  1300. this.z /= v.z;
  1301. return this;
  1302. },
  1303. divideScalar: function ( scalar ) {
  1304. if ( scalar !== 0 ) {
  1305. var invScalar = 1 / scalar;
  1306. this.x *= invScalar;
  1307. this.y *= invScalar;
  1308. this.z *= invScalar;
  1309. } else {
  1310. this.x = 0;
  1311. this.y = 0;
  1312. this.z = 0;
  1313. }
  1314. return this;
  1315. },
  1316. min: function ( v ) {
  1317. if ( this.x > v.x ) {
  1318. this.x = v.x;
  1319. }
  1320. if ( this.y > v.y ) {
  1321. this.y = v.y;
  1322. }
  1323. if ( this.z > v.z ) {
  1324. this.z = v.z;
  1325. }
  1326. return this;
  1327. },
  1328. max: function ( v ) {
  1329. if ( this.x < v.x ) {
  1330. this.x = v.x;
  1331. }
  1332. if ( this.y < v.y ) {
  1333. this.y = v.y;
  1334. }
  1335. if ( this.z < v.z ) {
  1336. this.z = v.z;
  1337. }
  1338. return this;
  1339. },
  1340. clamp: function ( min, max ) {
  1341. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1342. if ( this.x < min.x ) {
  1343. this.x = min.x;
  1344. } else if ( this.x > max.x ) {
  1345. this.x = max.x;
  1346. }
  1347. if ( this.y < min.y ) {
  1348. this.y = min.y;
  1349. } else if ( this.y > max.y ) {
  1350. this.y = max.y;
  1351. }
  1352. if ( this.z < min.z ) {
  1353. this.z = min.z;
  1354. } else if ( this.z > max.z ) {
  1355. this.z = max.z;
  1356. }
  1357. return this;
  1358. },
  1359. clampScalar: function () {
  1360. var min, max;
  1361. return function clampScalar( minVal, maxVal ) {
  1362. if ( min === undefined ) {
  1363. min = new THREE.Vector3();
  1364. max = new THREE.Vector3();
  1365. }
  1366. min.set( minVal, minVal, minVal );
  1367. max.set( maxVal, maxVal, maxVal );
  1368. return this.clamp( min, max );
  1369. };
  1370. }(),
  1371. floor: function () {
  1372. this.x = Math.floor( this.x );
  1373. this.y = Math.floor( this.y );
  1374. this.z = Math.floor( this.z );
  1375. return this;
  1376. },
  1377. ceil: function () {
  1378. this.x = Math.ceil( this.x );
  1379. this.y = Math.ceil( this.y );
  1380. this.z = Math.ceil( this.z );
  1381. return this;
  1382. },
  1383. round: function () {
  1384. this.x = Math.round( this.x );
  1385. this.y = Math.round( this.y );
  1386. this.z = Math.round( this.z );
  1387. return this;
  1388. },
  1389. roundToZero: function () {
  1390. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1391. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1392. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1393. return this;
  1394. },
  1395. negate: function () {
  1396. this.x = - this.x;
  1397. this.y = - this.y;
  1398. this.z = - this.z;
  1399. return this;
  1400. },
  1401. dot: function ( v ) {
  1402. return this.x * v.x + this.y * v.y + this.z * v.z;
  1403. },
  1404. lengthSq: function () {
  1405. return this.x * this.x + this.y * this.y + this.z * this.z;
  1406. },
  1407. length: function () {
  1408. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1409. },
  1410. lengthManhattan: function () {
  1411. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1412. },
  1413. normalize: function () {
  1414. return this.divideScalar( this.length() );
  1415. },
  1416. setLength: function ( l ) {
  1417. var oldLength = this.length();
  1418. if ( oldLength !== 0 && l !== oldLength ) {
  1419. this.multiplyScalar( l / oldLength );
  1420. }
  1421. return this;
  1422. },
  1423. lerp: function ( v, alpha ) {
  1424. this.x += ( v.x - this.x ) * alpha;
  1425. this.y += ( v.y - this.y ) * alpha;
  1426. this.z += ( v.z - this.z ) * alpha;
  1427. return this;
  1428. },
  1429. lerpVectors: function ( v1, v2, alpha ) {
  1430. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1431. return this;
  1432. },
  1433. cross: function ( v, w ) {
  1434. if ( w !== undefined ) {
  1435. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1436. return this.crossVectors( v, w );
  1437. }
  1438. var x = this.x, y = this.y, z = this.z;
  1439. this.x = y * v.z - z * v.y;
  1440. this.y = z * v.x - x * v.z;
  1441. this.z = x * v.y - y * v.x;
  1442. return this;
  1443. },
  1444. crossVectors: function ( a, b ) {
  1445. var ax = a.x, ay = a.y, az = a.z;
  1446. var bx = b.x, by = b.y, bz = b.z;
  1447. this.x = ay * bz - az * by;
  1448. this.y = az * bx - ax * bz;
  1449. this.z = ax * by - ay * bx;
  1450. return this;
  1451. },
  1452. projectOnVector: function () {
  1453. var v1, dot;
  1454. return function projectOnVector( vector ) {
  1455. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1456. v1.copy( vector ).normalize();
  1457. dot = this.dot( v1 );
  1458. return this.copy( v1 ).multiplyScalar( dot );
  1459. };
  1460. }(),
  1461. projectOnPlane: function () {
  1462. var v1;
  1463. return function projectOnPlane( planeNormal ) {
  1464. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1465. v1.copy( this ).projectOnVector( planeNormal );
  1466. return this.sub( v1 );
  1467. }
  1468. }(),
  1469. reflect: function () {
  1470. // reflect incident vector off plane orthogonal to normal
  1471. // normal is assumed to have unit length
  1472. var v1;
  1473. return function reflect( normal ) {
  1474. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1475. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1476. }
  1477. }(),
  1478. angleTo: function ( v ) {
  1479. var theta = this.dot( v ) / ( this.length() * v.length() );
  1480. // clamp, to handle numerical problems
  1481. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1482. },
  1483. distanceTo: function ( v ) {
  1484. return Math.sqrt( this.distanceToSquared( v ) );
  1485. },
  1486. distanceToSquared: function ( v ) {
  1487. var dx = this.x - v.x;
  1488. var dy = this.y - v.y;
  1489. var dz = this.z - v.z;
  1490. return dx * dx + dy * dy + dz * dz;
  1491. },
  1492. setEulerFromRotationMatrix: function ( m, order ) {
  1493. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1494. },
  1495. setEulerFromQuaternion: function ( q, order ) {
  1496. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1497. },
  1498. getPositionFromMatrix: function ( m ) {
  1499. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1500. return this.setFromMatrixPosition( m );
  1501. },
  1502. getScaleFromMatrix: function ( m ) {
  1503. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1504. return this.setFromMatrixScale( m );
  1505. },
  1506. getColumnFromMatrix: function ( index, matrix ) {
  1507. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1508. return this.setFromMatrixColumn( index, matrix );
  1509. },
  1510. setFromMatrixPosition: function ( m ) {
  1511. this.x = m.elements[ 12 ];
  1512. this.y = m.elements[ 13 ];
  1513. this.z = m.elements[ 14 ];
  1514. return this;
  1515. },
  1516. setFromMatrixScale: function ( m ) {
  1517. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1518. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1519. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1520. this.x = sx;
  1521. this.y = sy;
  1522. this.z = sz;
  1523. return this;
  1524. },
  1525. setFromMatrixColumn: function ( index, matrix ) {
  1526. var offset = index * 4;
  1527. var me = matrix.elements;
  1528. this.x = me[ offset ];
  1529. this.y = me[ offset + 1 ];
  1530. this.z = me[ offset + 2 ];
  1531. return this;
  1532. },
  1533. equals: function ( v ) {
  1534. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1535. },
  1536. fromArray: function ( array, offset ) {
  1537. if ( offset === undefined ) offset = 0;
  1538. this.x = array[ offset ];
  1539. this.y = array[ offset + 1 ];
  1540. this.z = array[ offset + 2 ];
  1541. return this;
  1542. },
  1543. toArray: function ( array, offset ) {
  1544. if ( array === undefined ) array = [];
  1545. if ( offset === undefined ) offset = 0;
  1546. array[ offset ] = this.x;
  1547. array[ offset + 1 ] = this.y;
  1548. array[ offset + 2 ] = this.z;
  1549. return array;
  1550. },
  1551. fromAttribute: function ( attribute, index, offset ) {
  1552. if ( offset === undefined ) offset = 0;
  1553. index = index * attribute.itemSize + offset;
  1554. this.x = attribute.array[ index ];
  1555. this.y = attribute.array[ index + 1 ];
  1556. this.z = attribute.array[ index + 2 ];
  1557. return this;
  1558. },
  1559. clone: function () {
  1560. return new THREE.Vector3( this.x, this.y, this.z );
  1561. }
  1562. };
  1563. // File:src/math/Vector4.js
  1564. /**
  1565. * @author supereggbert / http://www.paulbrunt.co.uk/
  1566. * @author philogb / http://blog.thejit.org/
  1567. * @author mikael emtinger / http://gomo.se/
  1568. * @author egraether / http://egraether.com/
  1569. * @author WestLangley / http://github.com/WestLangley
  1570. */
  1571. THREE.Vector4 = function ( x, y, z, w ) {
  1572. this.x = x || 0;
  1573. this.y = y || 0;
  1574. this.z = z || 0;
  1575. this.w = ( w !== undefined ) ? w : 1;
  1576. };
  1577. THREE.Vector4.prototype = {
  1578. constructor: THREE.Vector4,
  1579. set: function ( x, y, z, w ) {
  1580. this.x = x;
  1581. this.y = y;
  1582. this.z = z;
  1583. this.w = w;
  1584. return this;
  1585. },
  1586. setX: function ( x ) {
  1587. this.x = x;
  1588. return this;
  1589. },
  1590. setY: function ( y ) {
  1591. this.y = y;
  1592. return this;
  1593. },
  1594. setZ: function ( z ) {
  1595. this.z = z;
  1596. return this;
  1597. },
  1598. setW: function ( w ) {
  1599. this.w = w;
  1600. return this;
  1601. },
  1602. setComponent: function ( index, value ) {
  1603. switch ( index ) {
  1604. case 0: this.x = value; break;
  1605. case 1: this.y = value; break;
  1606. case 2: this.z = value; break;
  1607. case 3: this.w = value; break;
  1608. default: throw new Error( 'index is out of range: ' + index );
  1609. }
  1610. },
  1611. getComponent: function ( index ) {
  1612. switch ( index ) {
  1613. case 0: return this.x;
  1614. case 1: return this.y;
  1615. case 2: return this.z;
  1616. case 3: return this.w;
  1617. default: throw new Error( 'index is out of range: ' + index );
  1618. }
  1619. },
  1620. copy: function ( v ) {
  1621. this.x = v.x;
  1622. this.y = v.y;
  1623. this.z = v.z;
  1624. this.w = ( v.w !== undefined ) ? v.w : 1;
  1625. return this;
  1626. },
  1627. add: function ( v, w ) {
  1628. if ( w !== undefined ) {
  1629. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1630. return this.addVectors( v, w );
  1631. }
  1632. this.x += v.x;
  1633. this.y += v.y;
  1634. this.z += v.z;
  1635. this.w += v.w;
  1636. return this;
  1637. },
  1638. addScalar: function ( s ) {
  1639. this.x += s;
  1640. this.y += s;
  1641. this.z += s;
  1642. this.w += s;
  1643. return this;
  1644. },
  1645. addVectors: function ( a, b ) {
  1646. this.x = a.x + b.x;
  1647. this.y = a.y + b.y;
  1648. this.z = a.z + b.z;
  1649. this.w = a.w + b.w;
  1650. return this;
  1651. },
  1652. addScaledVector: function ( v, s ) {
  1653. this.x += v.x * s;
  1654. this.y += v.y * s;
  1655. this.z += v.z * s;
  1656. this.w += v.w * s;
  1657. return this;
  1658. },
  1659. sub: function ( v, w ) {
  1660. if ( w !== undefined ) {
  1661. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1662. return this.subVectors( v, w );
  1663. }
  1664. this.x -= v.x;
  1665. this.y -= v.y;
  1666. this.z -= v.z;
  1667. this.w -= v.w;
  1668. return this;
  1669. },
  1670. subScalar: function ( s ) {
  1671. this.x -= s;
  1672. this.y -= s;
  1673. this.z -= s;
  1674. this.w -= s;
  1675. return this;
  1676. },
  1677. subVectors: function ( a, b ) {
  1678. this.x = a.x - b.x;
  1679. this.y = a.y - b.y;
  1680. this.z = a.z - b.z;
  1681. this.w = a.w - b.w;
  1682. return this;
  1683. },
  1684. multiplyScalar: function ( scalar ) {
  1685. this.x *= scalar;
  1686. this.y *= scalar;
  1687. this.z *= scalar;
  1688. this.w *= scalar;
  1689. return this;
  1690. },
  1691. applyMatrix4: function ( m ) {
  1692. var x = this.x;
  1693. var y = this.y;
  1694. var z = this.z;
  1695. var w = this.w;
  1696. var e = m.elements;
  1697. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1698. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1699. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1700. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1701. return this;
  1702. },
  1703. divideScalar: function ( scalar ) {
  1704. if ( scalar !== 0 ) {
  1705. var invScalar = 1 / scalar;
  1706. this.x *= invScalar;
  1707. this.y *= invScalar;
  1708. this.z *= invScalar;
  1709. this.w *= invScalar;
  1710. } else {
  1711. this.x = 0;
  1712. this.y = 0;
  1713. this.z = 0;
  1714. this.w = 1;
  1715. }
  1716. return this;
  1717. },
  1718. setAxisAngleFromQuaternion: function ( q ) {
  1719. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1720. // q is assumed to be normalized
  1721. this.w = 2 * Math.acos( q.w );
  1722. var s = Math.sqrt( 1 - q.w * q.w );
  1723. if ( s < 0.0001 ) {
  1724. this.x = 1;
  1725. this.y = 0;
  1726. this.z = 0;
  1727. } else {
  1728. this.x = q.x / s;
  1729. this.y = q.y / s;
  1730. this.z = q.z / s;
  1731. }
  1732. return this;
  1733. },
  1734. setAxisAngleFromRotationMatrix: function ( m ) {
  1735. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1736. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1737. var angle, x, y, z, // variables for result
  1738. epsilon = 0.01, // margin to allow for rounding errors
  1739. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1740. te = m.elements,
  1741. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1742. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1743. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1744. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1745. && ( Math.abs( m13 - m31 ) < epsilon )
  1746. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1747. // singularity found
  1748. // first check for identity matrix which must have +1 for all terms
  1749. // in leading diagonal and zero in other terms
  1750. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1751. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1752. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1753. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1754. // this singularity is identity matrix so angle = 0
  1755. this.set( 1, 0, 0, 0 );
  1756. return this; // zero angle, arbitrary axis
  1757. }
  1758. // otherwise this singularity is angle = 180
  1759. angle = Math.PI;
  1760. var xx = ( m11 + 1 ) / 2;
  1761. var yy = ( m22 + 1 ) / 2;
  1762. var zz = ( m33 + 1 ) / 2;
  1763. var xy = ( m12 + m21 ) / 4;
  1764. var xz = ( m13 + m31 ) / 4;
  1765. var yz = ( m23 + m32 ) / 4;
  1766. if ( ( xx > yy ) && ( xx > zz ) ) {
  1767. // m11 is the largest diagonal term
  1768. if ( xx < epsilon ) {
  1769. x = 0;
  1770. y = 0.707106781;
  1771. z = 0.707106781;
  1772. } else {
  1773. x = Math.sqrt( xx );
  1774. y = xy / x;
  1775. z = xz / x;
  1776. }
  1777. } else if ( yy > zz ) {
  1778. // m22 is the largest diagonal term
  1779. if ( yy < epsilon ) {
  1780. x = 0.707106781;
  1781. y = 0;
  1782. z = 0.707106781;
  1783. } else {
  1784. y = Math.sqrt( yy );
  1785. x = xy / y;
  1786. z = yz / y;
  1787. }
  1788. } else {
  1789. // m33 is the largest diagonal term so base result on this
  1790. if ( zz < epsilon ) {
  1791. x = 0.707106781;
  1792. y = 0.707106781;
  1793. z = 0;
  1794. } else {
  1795. z = Math.sqrt( zz );
  1796. x = xz / z;
  1797. y = yz / z;
  1798. }
  1799. }
  1800. this.set( x, y, z, angle );
  1801. return this; // return 180 deg rotation
  1802. }
  1803. // as we have reached here there are no singularities so we can handle normally
  1804. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1805. + ( m13 - m31 ) * ( m13 - m31 )
  1806. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1807. if ( Math.abs( s ) < 0.001 ) s = 1;
  1808. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1809. // caught by singularity test above, but I've left it in just in case
  1810. this.x = ( m32 - m23 ) / s;
  1811. this.y = ( m13 - m31 ) / s;
  1812. this.z = ( m21 - m12 ) / s;
  1813. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1814. return this;
  1815. },
  1816. min: function ( v ) {
  1817. if ( this.x > v.x ) {
  1818. this.x = v.x;
  1819. }
  1820. if ( this.y > v.y ) {
  1821. this.y = v.y;
  1822. }
  1823. if ( this.z > v.z ) {
  1824. this.z = v.z;
  1825. }
  1826. if ( this.w > v.w ) {
  1827. this.w = v.w;
  1828. }
  1829. return this;
  1830. },
  1831. max: function ( v ) {
  1832. if ( this.x < v.x ) {
  1833. this.x = v.x;
  1834. }
  1835. if ( this.y < v.y ) {
  1836. this.y = v.y;
  1837. }
  1838. if ( this.z < v.z ) {
  1839. this.z = v.z;
  1840. }
  1841. if ( this.w < v.w ) {
  1842. this.w = v.w;
  1843. }
  1844. return this;
  1845. },
  1846. clamp: function ( min, max ) {
  1847. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1848. if ( this.x < min.x ) {
  1849. this.x = min.x;
  1850. } else if ( this.x > max.x ) {
  1851. this.x = max.x;
  1852. }
  1853. if ( this.y < min.y ) {
  1854. this.y = min.y;
  1855. } else if ( this.y > max.y ) {
  1856. this.y = max.y;
  1857. }
  1858. if ( this.z < min.z ) {
  1859. this.z = min.z;
  1860. } else if ( this.z > max.z ) {
  1861. this.z = max.z;
  1862. }
  1863. if ( this.w < min.w ) {
  1864. this.w = min.w;
  1865. } else if ( this.w > max.w ) {
  1866. this.w = max.w;
  1867. }
  1868. return this;
  1869. },
  1870. clampScalar: function () {
  1871. var min, max;
  1872. return function clampScalar( minVal, maxVal ) {
  1873. if ( min === undefined ) {
  1874. min = new THREE.Vector4();
  1875. max = new THREE.Vector4();
  1876. }
  1877. min.set( minVal, minVal, minVal, minVal );
  1878. max.set( maxVal, maxVal, maxVal, maxVal );
  1879. return this.clamp( min, max );
  1880. };
  1881. }(),
  1882. floor: function () {
  1883. this.x = Math.floor( this.x );
  1884. this.y = Math.floor( this.y );
  1885. this.z = Math.floor( this.z );
  1886. this.w = Math.floor( this.w );
  1887. return this;
  1888. },
  1889. ceil: function () {
  1890. this.x = Math.ceil( this.x );
  1891. this.y = Math.ceil( this.y );
  1892. this.z = Math.ceil( this.z );
  1893. this.w = Math.ceil( this.w );
  1894. return this;
  1895. },
  1896. round: function () {
  1897. this.x = Math.round( this.x );
  1898. this.y = Math.round( this.y );
  1899. this.z = Math.round( this.z );
  1900. this.w = Math.round( this.w );
  1901. return this;
  1902. },
  1903. roundToZero: function () {
  1904. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1905. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1906. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1907. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1908. return this;
  1909. },
  1910. negate: function () {
  1911. this.x = - this.x;
  1912. this.y = - this.y;
  1913. this.z = - this.z;
  1914. this.w = - this.w;
  1915. return this;
  1916. },
  1917. dot: function ( v ) {
  1918. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1919. },
  1920. lengthSq: function () {
  1921. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1922. },
  1923. length: function () {
  1924. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1925. },
  1926. lengthManhattan: function () {
  1927. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1928. },
  1929. normalize: function () {
  1930. return this.divideScalar( this.length() );
  1931. },
  1932. setLength: function ( l ) {
  1933. var oldLength = this.length();
  1934. if ( oldLength !== 0 && l !== oldLength ) {
  1935. this.multiplyScalar( l / oldLength );
  1936. }
  1937. return this;
  1938. },
  1939. lerp: function ( v, alpha ) {
  1940. this.x += ( v.x - this.x ) * alpha;
  1941. this.y += ( v.y - this.y ) * alpha;
  1942. this.z += ( v.z - this.z ) * alpha;
  1943. this.w += ( v.w - this.w ) * alpha;
  1944. return this;
  1945. },
  1946. lerpVectors: function ( v1, v2, alpha ) {
  1947. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1948. return this;
  1949. },
  1950. equals: function ( v ) {
  1951. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1952. },
  1953. fromArray: function ( array, offset ) {
  1954. if ( offset === undefined ) offset = 0;
  1955. this.x = array[ offset ];
  1956. this.y = array[ offset + 1 ];
  1957. this.z = array[ offset + 2 ];
  1958. this.w = array[ offset + 3 ];
  1959. return this;
  1960. },
  1961. toArray: function ( array, offset ) {
  1962. if ( array === undefined ) array = [];
  1963. if ( offset === undefined ) offset = 0;
  1964. array[ offset ] = this.x;
  1965. array[ offset + 1 ] = this.y;
  1966. array[ offset + 2 ] = this.z;
  1967. array[ offset + 3 ] = this.w;
  1968. return array;
  1969. },
  1970. fromAttribute: function ( attribute, index, offset ) {
  1971. if ( offset === undefined ) offset = 0;
  1972. index = index * attribute.itemSize + offset;
  1973. this.x = attribute.array[ index ];
  1974. this.y = attribute.array[ index + 1 ];
  1975. this.z = attribute.array[ index + 2 ];
  1976. this.w = attribute.array[ index + 3 ];
  1977. return this;
  1978. },
  1979. clone: function () {
  1980. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  1981. }
  1982. };
  1983. // File:src/math/Euler.js
  1984. /**
  1985. * @author mrdoob / http://mrdoob.com/
  1986. * @author WestLangley / http://github.com/WestLangley
  1987. * @author bhouston / http://exocortex.com
  1988. */
  1989. THREE.Euler = function ( x, y, z, order ) {
  1990. this._x = x || 0;
  1991. this._y = y || 0;
  1992. this._z = z || 0;
  1993. this._order = order || THREE.Euler.DefaultOrder;
  1994. };
  1995. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1996. THREE.Euler.DefaultOrder = 'XYZ';
  1997. THREE.Euler.prototype = {
  1998. constructor: THREE.Euler,
  1999. get x () {
  2000. return this._x;
  2001. },
  2002. set x ( value ) {
  2003. this._x = value;
  2004. this.onChangeCallback();
  2005. },
  2006. get y () {
  2007. return this._y;
  2008. },
  2009. set y ( value ) {
  2010. this._y = value;
  2011. this.onChangeCallback();
  2012. },
  2013. get z () {
  2014. return this._z;
  2015. },
  2016. set z ( value ) {
  2017. this._z = value;
  2018. this.onChangeCallback();
  2019. },
  2020. get order () {
  2021. return this._order;
  2022. },
  2023. set order ( value ) {
  2024. this._order = value;
  2025. this.onChangeCallback();
  2026. },
  2027. set: function ( x, y, z, order ) {
  2028. this._x = x;
  2029. this._y = y;
  2030. this._z = z;
  2031. this._order = order || this._order;
  2032. this.onChangeCallback();
  2033. return this;
  2034. },
  2035. copy: function ( euler ) {
  2036. this._x = euler._x;
  2037. this._y = euler._y;
  2038. this._z = euler._z;
  2039. this._order = euler._order;
  2040. this.onChangeCallback();
  2041. return this;
  2042. },
  2043. setFromRotationMatrix: function ( m, order, update ) {
  2044. var clamp = THREE.Math.clamp;
  2045. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2046. var te = m.elements;
  2047. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2048. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2049. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2050. order = order || this._order;
  2051. if ( order === 'XYZ' ) {
  2052. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2053. if ( Math.abs( m13 ) < 0.99999 ) {
  2054. this._x = Math.atan2( - m23, m33 );
  2055. this._z = Math.atan2( - m12, m11 );
  2056. } else {
  2057. this._x = Math.atan2( m32, m22 );
  2058. this._z = 0;
  2059. }
  2060. } else if ( order === 'YXZ' ) {
  2061. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2062. if ( Math.abs( m23 ) < 0.99999 ) {
  2063. this._y = Math.atan2( m13, m33 );
  2064. this._z = Math.atan2( m21, m22 );
  2065. } else {
  2066. this._y = Math.atan2( - m31, m11 );
  2067. this._z = 0;
  2068. }
  2069. } else if ( order === 'ZXY' ) {
  2070. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2071. if ( Math.abs( m32 ) < 0.99999 ) {
  2072. this._y = Math.atan2( - m31, m33 );
  2073. this._z = Math.atan2( - m12, m22 );
  2074. } else {
  2075. this._y = 0;
  2076. this._z = Math.atan2( m21, m11 );
  2077. }
  2078. } else if ( order === 'ZYX' ) {
  2079. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2080. if ( Math.abs( m31 ) < 0.99999 ) {
  2081. this._x = Math.atan2( m32, m33 );
  2082. this._z = Math.atan2( m21, m11 );
  2083. } else {
  2084. this._x = 0;
  2085. this._z = Math.atan2( - m12, m22 );
  2086. }
  2087. } else if ( order === 'YZX' ) {
  2088. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2089. if ( Math.abs( m21 ) < 0.99999 ) {
  2090. this._x = Math.atan2( - m23, m22 );
  2091. this._y = Math.atan2( - m31, m11 );
  2092. } else {
  2093. this._x = 0;
  2094. this._y = Math.atan2( m13, m33 );
  2095. }
  2096. } else if ( order === 'XZY' ) {
  2097. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2098. if ( Math.abs( m12 ) < 0.99999 ) {
  2099. this._x = Math.atan2( m32, m22 );
  2100. this._y = Math.atan2( m13, m11 );
  2101. } else {
  2102. this._x = Math.atan2( - m23, m33 );
  2103. this._y = 0;
  2104. }
  2105. } else {
  2106. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2107. }
  2108. this._order = order;
  2109. if ( update !== false ) this.onChangeCallback();
  2110. return this;
  2111. },
  2112. setFromQuaternion: function () {
  2113. var matrix;
  2114. return function ( q, order, update ) {
  2115. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2116. matrix.makeRotationFromQuaternion( q );
  2117. this.setFromRotationMatrix( matrix, order, update );
  2118. return this;
  2119. };
  2120. }(),
  2121. setFromVector3: function ( v, order ) {
  2122. return this.set( v.x, v.y, v.z, order || this._order );
  2123. },
  2124. reorder: function () {
  2125. // WARNING: this discards revolution information -bhouston
  2126. var q = new THREE.Quaternion();
  2127. return function ( newOrder ) {
  2128. q.setFromEuler( this );
  2129. this.setFromQuaternion( q, newOrder );
  2130. };
  2131. }(),
  2132. equals: function ( euler ) {
  2133. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2134. },
  2135. fromArray: function ( array ) {
  2136. this._x = array[ 0 ];
  2137. this._y = array[ 1 ];
  2138. this._z = array[ 2 ];
  2139. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2140. this.onChangeCallback();
  2141. return this;
  2142. },
  2143. toArray: function ( array, offset ) {
  2144. if ( array === undefined ) array = [];
  2145. if ( offset === undefined ) offset = 0;
  2146. array[ offset ] = this._x;
  2147. array[ offset + 1 ] = this._y;
  2148. array[ offset + 2 ] = this._z;
  2149. array[ offset + 3 ] = this._order;
  2150. return array;
  2151. },
  2152. toVector3: function ( optionalResult ) {
  2153. if ( optionalResult ) {
  2154. return optionalResult.set( this._x, this._y, this._z );
  2155. } else {
  2156. return new THREE.Vector3( this._x, this._y, this._z );
  2157. }
  2158. },
  2159. onChange: function ( callback ) {
  2160. this.onChangeCallback = callback;
  2161. return this;
  2162. },
  2163. onChangeCallback: function () {},
  2164. clone: function () {
  2165. return new THREE.Euler( this._x, this._y, this._z, this._order );
  2166. }
  2167. };
  2168. // File:src/math/Line3.js
  2169. /**
  2170. * @author bhouston / http://exocortex.com
  2171. */
  2172. THREE.Line3 = function ( start, end ) {
  2173. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2174. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2175. };
  2176. THREE.Line3.prototype = {
  2177. constructor: THREE.Line3,
  2178. set: function ( start, end ) {
  2179. this.start.copy( start );
  2180. this.end.copy( end );
  2181. return this;
  2182. },
  2183. copy: function ( line ) {
  2184. this.start.copy( line.start );
  2185. this.end.copy( line.end );
  2186. return this;
  2187. },
  2188. center: function ( optionalTarget ) {
  2189. var result = optionalTarget || new THREE.Vector3();
  2190. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2191. },
  2192. delta: function ( optionalTarget ) {
  2193. var result = optionalTarget || new THREE.Vector3();
  2194. return result.subVectors( this.end, this.start );
  2195. },
  2196. distanceSq: function () {
  2197. return this.start.distanceToSquared( this.end );
  2198. },
  2199. distance: function () {
  2200. return this.start.distanceTo( this.end );
  2201. },
  2202. at: function ( t, optionalTarget ) {
  2203. var result = optionalTarget || new THREE.Vector3();
  2204. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2205. },
  2206. closestPointToPointParameter: function () {
  2207. var startP = new THREE.Vector3();
  2208. var startEnd = new THREE.Vector3();
  2209. return function ( point, clampToLine ) {
  2210. startP.subVectors( point, this.start );
  2211. startEnd.subVectors( this.end, this.start );
  2212. var startEnd2 = startEnd.dot( startEnd );
  2213. var startEnd_startP = startEnd.dot( startP );
  2214. var t = startEnd_startP / startEnd2;
  2215. if ( clampToLine ) {
  2216. t = THREE.Math.clamp( t, 0, 1 );
  2217. }
  2218. return t;
  2219. };
  2220. }(),
  2221. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2222. var t = this.closestPointToPointParameter( point, clampToLine );
  2223. var result = optionalTarget || new THREE.Vector3();
  2224. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2225. },
  2226. applyMatrix4: function ( matrix ) {
  2227. this.start.applyMatrix4( matrix );
  2228. this.end.applyMatrix4( matrix );
  2229. return this;
  2230. },
  2231. equals: function ( line ) {
  2232. return line.start.equals( this.start ) && line.end.equals( this.end );
  2233. },
  2234. clone: function () {
  2235. return new THREE.Line3().copy( this );
  2236. }
  2237. };
  2238. // File:src/math/Box2.js
  2239. /**
  2240. * @author bhouston / http://exocortex.com
  2241. */
  2242. THREE.Box2 = function ( min, max ) {
  2243. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2244. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2245. };
  2246. THREE.Box2.prototype = {
  2247. constructor: THREE.Box2,
  2248. set: function ( min, max ) {
  2249. this.min.copy( min );
  2250. this.max.copy( max );
  2251. return this;
  2252. },
  2253. setFromPoints: function ( points ) {
  2254. this.makeEmpty();
  2255. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2256. this.expandByPoint( points[ i ] )
  2257. }
  2258. return this;
  2259. },
  2260. setFromCenterAndSize: function () {
  2261. var v1 = new THREE.Vector2();
  2262. return function ( center, size ) {
  2263. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2264. this.min.copy( center ).sub( halfSize );
  2265. this.max.copy( center ).add( halfSize );
  2266. return this;
  2267. };
  2268. }(),
  2269. copy: function ( box ) {
  2270. this.min.copy( box.min );
  2271. this.max.copy( box.max );
  2272. return this;
  2273. },
  2274. makeEmpty: function () {
  2275. this.min.x = this.min.y = Infinity;
  2276. this.max.x = this.max.y = - Infinity;
  2277. return this;
  2278. },
  2279. empty: function () {
  2280. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2281. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2282. },
  2283. center: function ( optionalTarget ) {
  2284. var result = optionalTarget || new THREE.Vector2();
  2285. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2286. },
  2287. size: function ( optionalTarget ) {
  2288. var result = optionalTarget || new THREE.Vector2();
  2289. return result.subVectors( this.max, this.min );
  2290. },
  2291. expandByPoint: function ( point ) {
  2292. this.min.min( point );
  2293. this.max.max( point );
  2294. return this;
  2295. },
  2296. expandByVector: function ( vector ) {
  2297. this.min.sub( vector );
  2298. this.max.add( vector );
  2299. return this;
  2300. },
  2301. expandByScalar: function ( scalar ) {
  2302. this.min.addScalar( - scalar );
  2303. this.max.addScalar( scalar );
  2304. return this;
  2305. },
  2306. containsPoint: function ( point ) {
  2307. if ( point.x < this.min.x || point.x > this.max.x ||
  2308. point.y < this.min.y || point.y > this.max.y ) {
  2309. return false;
  2310. }
  2311. return true;
  2312. },
  2313. containsBox: function ( box ) {
  2314. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2315. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2316. return true;
  2317. }
  2318. return false;
  2319. },
  2320. getParameter: function ( point, optionalTarget ) {
  2321. // This can potentially have a divide by zero if the box
  2322. // has a size dimension of 0.
  2323. var result = optionalTarget || new THREE.Vector2();
  2324. return result.set(
  2325. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2326. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2327. );
  2328. },
  2329. isIntersectionBox: function ( box ) {
  2330. // using 6 splitting planes to rule out intersections.
  2331. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2332. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2333. return false;
  2334. }
  2335. return true;
  2336. },
  2337. clampPoint: function ( point, optionalTarget ) {
  2338. var result = optionalTarget || new THREE.Vector2();
  2339. return result.copy( point ).clamp( this.min, this.max );
  2340. },
  2341. distanceToPoint: function () {
  2342. var v1 = new THREE.Vector2();
  2343. return function ( point ) {
  2344. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2345. return clampedPoint.sub( point ).length();
  2346. };
  2347. }(),
  2348. intersect: function ( box ) {
  2349. this.min.max( box.min );
  2350. this.max.min( box.max );
  2351. return this;
  2352. },
  2353. union: function ( box ) {
  2354. this.min.min( box.min );
  2355. this.max.max( box.max );
  2356. return this;
  2357. },
  2358. translate: function ( offset ) {
  2359. this.min.add( offset );
  2360. this.max.add( offset );
  2361. return this;
  2362. },
  2363. equals: function ( box ) {
  2364. return box.min.equals( this.min ) && box.max.equals( this.max );
  2365. },
  2366. clone: function () {
  2367. return new THREE.Box2().copy( this );
  2368. }
  2369. };
  2370. // File:src/math/Box3.js
  2371. /**
  2372. * @author bhouston / http://exocortex.com
  2373. * @author WestLangley / http://github.com/WestLangley
  2374. */
  2375. THREE.Box3 = function ( min, max ) {
  2376. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2377. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2378. };
  2379. THREE.Box3.prototype = {
  2380. constructor: THREE.Box3,
  2381. set: function ( min, max ) {
  2382. this.min.copy( min );
  2383. this.max.copy( max );
  2384. return this;
  2385. },
  2386. setFromPoints: function ( points ) {
  2387. this.makeEmpty();
  2388. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2389. this.expandByPoint( points[ i ] );
  2390. }
  2391. return this;
  2392. },
  2393. setFromCenterAndSize: function () {
  2394. var v1 = new THREE.Vector3();
  2395. return function ( center, size ) {
  2396. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2397. this.min.copy( center ).sub( halfSize );
  2398. this.max.copy( center ).add( halfSize );
  2399. return this;
  2400. };
  2401. }(),
  2402. setFromObject: function () {
  2403. // Computes the world-axis-aligned bounding box of an object (including its children),
  2404. // accounting for both the object's, and children's, world transforms
  2405. var v1 = new THREE.Vector3();
  2406. return function ( object ) {
  2407. var scope = this;
  2408. object.updateMatrixWorld( true );
  2409. this.makeEmpty();
  2410. object.traverse( function ( node ) {
  2411. var geometry = node.geometry;
  2412. if ( geometry !== undefined ) {
  2413. if ( geometry instanceof THREE.Geometry ) {
  2414. var vertices = geometry.vertices;
  2415. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2416. v1.copy( vertices[ i ] );
  2417. v1.applyMatrix4( node.matrixWorld );
  2418. scope.expandByPoint( v1 );
  2419. }
  2420. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2421. var positions = geometry.attributes[ 'position' ].array;
  2422. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2423. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2424. v1.applyMatrix4( node.matrixWorld );
  2425. scope.expandByPoint( v1 );
  2426. }
  2427. }
  2428. }
  2429. } );
  2430. return this;
  2431. };
  2432. }(),
  2433. copy: function ( box ) {
  2434. this.min.copy( box.min );
  2435. this.max.copy( box.max );
  2436. return this;
  2437. },
  2438. makeEmpty: function () {
  2439. this.min.x = this.min.y = this.min.z = Infinity;
  2440. this.max.x = this.max.y = this.max.z = - Infinity;
  2441. return this;
  2442. },
  2443. empty: function () {
  2444. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2445. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2446. },
  2447. center: function ( optionalTarget ) {
  2448. var result = optionalTarget || new THREE.Vector3();
  2449. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2450. },
  2451. size: function ( optionalTarget ) {
  2452. var result = optionalTarget || new THREE.Vector3();
  2453. return result.subVectors( this.max, this.min );
  2454. },
  2455. expandByPoint: function ( point ) {
  2456. this.min.min( point );
  2457. this.max.max( point );
  2458. return this;
  2459. },
  2460. expandByVector: function ( vector ) {
  2461. this.min.sub( vector );
  2462. this.max.add( vector );
  2463. return this;
  2464. },
  2465. expandByScalar: function ( scalar ) {
  2466. this.min.addScalar( - scalar );
  2467. this.max.addScalar( scalar );
  2468. return this;
  2469. },
  2470. containsPoint: function ( point ) {
  2471. if ( point.x < this.min.x || point.x > this.max.x ||
  2472. point.y < this.min.y || point.y > this.max.y ||
  2473. point.z < this.min.z || point.z > this.max.z ) {
  2474. return false;
  2475. }
  2476. return true;
  2477. },
  2478. containsBox: function ( box ) {
  2479. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2480. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2481. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2482. return true;
  2483. }
  2484. return false;
  2485. },
  2486. getParameter: function ( point, optionalTarget ) {
  2487. // This can potentially have a divide by zero if the box
  2488. // has a size dimension of 0.
  2489. var result = optionalTarget || new THREE.Vector3();
  2490. return result.set(
  2491. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2492. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2493. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2494. );
  2495. },
  2496. isIntersectionBox: function ( box ) {
  2497. // using 6 splitting planes to rule out intersections.
  2498. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2499. box.max.y < this.min.y || box.min.y > this.max.y ||
  2500. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2501. return false;
  2502. }
  2503. return true;
  2504. },
  2505. clampPoint: function ( point, optionalTarget ) {
  2506. var result = optionalTarget || new THREE.Vector3();
  2507. return result.copy( point ).clamp( this.min, this.max );
  2508. },
  2509. distanceToPoint: function () {
  2510. var v1 = new THREE.Vector3();
  2511. return function ( point ) {
  2512. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2513. return clampedPoint.sub( point ).length();
  2514. };
  2515. }(),
  2516. getBoundingSphere: function () {
  2517. var v1 = new THREE.Vector3();
  2518. return function ( optionalTarget ) {
  2519. var result = optionalTarget || new THREE.Sphere();
  2520. result.center = this.center();
  2521. result.radius = this.size( v1 ).length() * 0.5;
  2522. return result;
  2523. };
  2524. }(),
  2525. intersect: function ( box ) {
  2526. this.min.max( box.min );
  2527. this.max.min( box.max );
  2528. return this;
  2529. },
  2530. union: function ( box ) {
  2531. this.min.min( box.min );
  2532. this.max.max( box.max );
  2533. return this;
  2534. },
  2535. applyMatrix4: function () {
  2536. var points = [
  2537. new THREE.Vector3(),
  2538. new THREE.Vector3(),
  2539. new THREE.Vector3(),
  2540. new THREE.Vector3(),
  2541. new THREE.Vector3(),
  2542. new THREE.Vector3(),
  2543. new THREE.Vector3(),
  2544. new THREE.Vector3()
  2545. ];
  2546. return function ( matrix ) {
  2547. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2548. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2549. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2550. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2551. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2552. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2553. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2554. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2555. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2556. this.makeEmpty();
  2557. this.setFromPoints( points );
  2558. return this;
  2559. };
  2560. }(),
  2561. translate: function ( offset ) {
  2562. this.min.add( offset );
  2563. this.max.add( offset );
  2564. return this;
  2565. },
  2566. equals: function ( box ) {
  2567. return box.min.equals( this.min ) && box.max.equals( this.max );
  2568. },
  2569. clone: function () {
  2570. return new THREE.Box3().copy( this );
  2571. }
  2572. };
  2573. // File:src/math/Matrix3.js
  2574. /**
  2575. * @author alteredq / http://alteredqualia.com/
  2576. * @author WestLangley / http://github.com/WestLangley
  2577. * @author bhouston / http://exocortex.com
  2578. */
  2579. THREE.Matrix3 = function () {
  2580. this.elements = new Float32Array( [
  2581. 1, 0, 0,
  2582. 0, 1, 0,
  2583. 0, 0, 1
  2584. ] );
  2585. if ( arguments.length > 0 ) {
  2586. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2587. }
  2588. };
  2589. THREE.Matrix3.prototype = {
  2590. constructor: THREE.Matrix3,
  2591. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2592. var te = this.elements;
  2593. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2594. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2595. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2596. return this;
  2597. },
  2598. identity: function () {
  2599. this.set(
  2600. 1, 0, 0,
  2601. 0, 1, 0,
  2602. 0, 0, 1
  2603. );
  2604. return this;
  2605. },
  2606. copy: function ( m ) {
  2607. var me = m.elements;
  2608. this.set(
  2609. me[ 0 ], me[ 3 ], me[ 6 ],
  2610. me[ 1 ], me[ 4 ], me[ 7 ],
  2611. me[ 2 ], me[ 5 ], me[ 8 ]
  2612. );
  2613. return this;
  2614. },
  2615. multiplyVector3: function ( vector ) {
  2616. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2617. return vector.applyMatrix3( this );
  2618. },
  2619. multiplyVector3Array: function ( a ) {
  2620. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2621. return this.applyToVector3Array( a );
  2622. },
  2623. applyToVector3Array: function () {
  2624. var v1;
  2625. return function ( array, offset, length ) {
  2626. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2627. if ( offset === undefined ) offset = 0;
  2628. if ( length === undefined ) length = array.length;
  2629. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2630. v1.fromArray( array, j );
  2631. v1.applyMatrix3( this );
  2632. v1.toArray( array, j );
  2633. }
  2634. return array;
  2635. };
  2636. }(),
  2637. applyToBuffer: function () {
  2638. var v1;
  2639. return function applyToBuffer( buffer, offset, length ) {
  2640. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2641. if ( offset === undefined ) offset = 0;
  2642. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2643. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2644. v1.x = buffer.getX( j );
  2645. v1.y = buffer.getY( j );
  2646. v1.z = buffer.getZ( j );
  2647. v1.applyMatrix3( this );
  2648. buffer.setXYZ( v1.x, v1.y, v1.z );
  2649. }
  2650. return buffer;
  2651. };
  2652. }(),
  2653. multiplyScalar: function ( s ) {
  2654. var te = this.elements;
  2655. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2656. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2657. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2658. return this;
  2659. },
  2660. determinant: function () {
  2661. var te = this.elements;
  2662. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2663. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2664. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2665. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2666. },
  2667. getInverse: function ( matrix, throwOnInvertible ) {
  2668. // input: THREE.Matrix4
  2669. // ( based on http://code.google.com/p/webgl-mjs/ )
  2670. var me = matrix.elements;
  2671. var te = this.elements;
  2672. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2673. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2674. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2675. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2676. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2677. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2678. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2679. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2680. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2681. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2682. // no inverse
  2683. if ( det === 0 ) {
  2684. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2685. if ( throwOnInvertible || false ) {
  2686. throw new Error( msg );
  2687. } else {
  2688. console.warn( msg );
  2689. }
  2690. this.identity();
  2691. return this;
  2692. }
  2693. this.multiplyScalar( 1.0 / det );
  2694. return this;
  2695. },
  2696. transpose: function () {
  2697. var tmp, m = this.elements;
  2698. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2699. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2700. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2701. return this;
  2702. },
  2703. flattenToArrayOffset: function ( array, offset ) {
  2704. var te = this.elements;
  2705. array[ offset ] = te[ 0 ];
  2706. array[ offset + 1 ] = te[ 1 ];
  2707. array[ offset + 2 ] = te[ 2 ];
  2708. array[ offset + 3 ] = te[ 3 ];
  2709. array[ offset + 4 ] = te[ 4 ];
  2710. array[ offset + 5 ] = te[ 5 ];
  2711. array[ offset + 6 ] = te[ 6 ];
  2712. array[ offset + 7 ] = te[ 7 ];
  2713. array[ offset + 8 ] = te[ 8 ];
  2714. return array;
  2715. },
  2716. getNormalMatrix: function ( m ) {
  2717. // input: THREE.Matrix4
  2718. this.getInverse( m ).transpose();
  2719. return this;
  2720. },
  2721. transposeIntoArray: function ( r ) {
  2722. var m = this.elements;
  2723. r[ 0 ] = m[ 0 ];
  2724. r[ 1 ] = m[ 3 ];
  2725. r[ 2 ] = m[ 6 ];
  2726. r[ 3 ] = m[ 1 ];
  2727. r[ 4 ] = m[ 4 ];
  2728. r[ 5 ] = m[ 7 ];
  2729. r[ 6 ] = m[ 2 ];
  2730. r[ 7 ] = m[ 5 ];
  2731. r[ 8 ] = m[ 8 ];
  2732. return this;
  2733. },
  2734. fromArray: function ( array ) {
  2735. this.elements.set( array );
  2736. return this;
  2737. },
  2738. toArray: function () {
  2739. var te = this.elements;
  2740. return [
  2741. te[ 0 ], te[ 1 ], te[ 2 ],
  2742. te[ 3 ], te[ 4 ], te[ 5 ],
  2743. te[ 6 ], te[ 7 ], te[ 8 ]
  2744. ];
  2745. },
  2746. clone: function () {
  2747. return new THREE.Matrix3().fromArray( this.elements );
  2748. }
  2749. };
  2750. // File:src/math/Matrix4.js
  2751. /**
  2752. * @author mrdoob / http://mrdoob.com/
  2753. * @author supereggbert / http://www.paulbrunt.co.uk/
  2754. * @author philogb / http://blog.thejit.org/
  2755. * @author jordi_ros / http://plattsoft.com
  2756. * @author D1plo1d / http://github.com/D1plo1d
  2757. * @author alteredq / http://alteredqualia.com/
  2758. * @author mikael emtinger / http://gomo.se/
  2759. * @author timknip / http://www.floorplanner.com/
  2760. * @author bhouston / http://exocortex.com
  2761. * @author WestLangley / http://github.com/WestLangley
  2762. */
  2763. THREE.Matrix4 = function () {
  2764. this.elements = new Float32Array( [
  2765. 1, 0, 0, 0,
  2766. 0, 1, 0, 0,
  2767. 0, 0, 1, 0,
  2768. 0, 0, 0, 1
  2769. ] );
  2770. if ( arguments.length > 0 ) {
  2771. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2772. }
  2773. };
  2774. THREE.Matrix4.prototype = {
  2775. constructor: THREE.Matrix4,
  2776. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2777. var te = this.elements;
  2778. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2779. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2780. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2781. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2782. return this;
  2783. },
  2784. identity: function () {
  2785. this.set(
  2786. 1, 0, 0, 0,
  2787. 0, 1, 0, 0,
  2788. 0, 0, 1, 0,
  2789. 0, 0, 0, 1
  2790. );
  2791. return this;
  2792. },
  2793. copy: function ( m ) {
  2794. this.elements.set( m.elements );
  2795. return this;
  2796. },
  2797. extractPosition: function ( m ) {
  2798. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2799. return this.copyPosition( m );
  2800. },
  2801. copyPosition: function ( m ) {
  2802. var te = this.elements;
  2803. var me = m.elements;
  2804. te[ 12 ] = me[ 12 ];
  2805. te[ 13 ] = me[ 13 ];
  2806. te[ 14 ] = me[ 14 ];
  2807. return this;
  2808. },
  2809. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2810. var te = this.elements;
  2811. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2812. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2813. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2814. return this;
  2815. },
  2816. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2817. this.set(
  2818. xAxis.x, yAxis.x, zAxis.x, 0,
  2819. xAxis.y, yAxis.y, zAxis.y, 0,
  2820. xAxis.z, yAxis.z, zAxis.z, 0,
  2821. 0, 0, 0, 1
  2822. );
  2823. return this;
  2824. },
  2825. extractRotation: function () {
  2826. var v1;
  2827. return function ( m ) {
  2828. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2829. var te = this.elements;
  2830. var me = m.elements;
  2831. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2832. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2833. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2834. te[ 0 ] = me[ 0 ] * scaleX;
  2835. te[ 1 ] = me[ 1 ] * scaleX;
  2836. te[ 2 ] = me[ 2 ] * scaleX;
  2837. te[ 4 ] = me[ 4 ] * scaleY;
  2838. te[ 5 ] = me[ 5 ] * scaleY;
  2839. te[ 6 ] = me[ 6 ] * scaleY;
  2840. te[ 8 ] = me[ 8 ] * scaleZ;
  2841. te[ 9 ] = me[ 9 ] * scaleZ;
  2842. te[ 10 ] = me[ 10 ] * scaleZ;
  2843. return this;
  2844. };
  2845. }(),
  2846. makeRotationFromEuler: function ( euler ) {
  2847. if ( euler instanceof THREE.Euler === false ) {
  2848. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2849. }
  2850. var te = this.elements;
  2851. var x = euler.x, y = euler.y, z = euler.z;
  2852. var a = Math.cos( x ), b = Math.sin( x );
  2853. var c = Math.cos( y ), d = Math.sin( y );
  2854. var e = Math.cos( z ), f = Math.sin( z );
  2855. if ( euler.order === 'XYZ' ) {
  2856. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2857. te[ 0 ] = c * e;
  2858. te[ 4 ] = - c * f;
  2859. te[ 8 ] = d;
  2860. te[ 1 ] = af + be * d;
  2861. te[ 5 ] = ae - bf * d;
  2862. te[ 9 ] = - b * c;
  2863. te[ 2 ] = bf - ae * d;
  2864. te[ 6 ] = be + af * d;
  2865. te[ 10 ] = a * c;
  2866. } else if ( euler.order === 'YXZ' ) {
  2867. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2868. te[ 0 ] = ce + df * b;
  2869. te[ 4 ] = de * b - cf;
  2870. te[ 8 ] = a * d;
  2871. te[ 1 ] = a * f;
  2872. te[ 5 ] = a * e;
  2873. te[ 9 ] = - b;
  2874. te[ 2 ] = cf * b - de;
  2875. te[ 6 ] = df + ce * b;
  2876. te[ 10 ] = a * c;
  2877. } else if ( euler.order === 'ZXY' ) {
  2878. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2879. te[ 0 ] = ce - df * b;
  2880. te[ 4 ] = - a * f;
  2881. te[ 8 ] = de + cf * b;
  2882. te[ 1 ] = cf + de * b;
  2883. te[ 5 ] = a * e;
  2884. te[ 9 ] = df - ce * b;
  2885. te[ 2 ] = - a * d;
  2886. te[ 6 ] = b;
  2887. te[ 10 ] = a * c;
  2888. } else if ( euler.order === 'ZYX' ) {
  2889. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2890. te[ 0 ] = c * e;
  2891. te[ 4 ] = be * d - af;
  2892. te[ 8 ] = ae * d + bf;
  2893. te[ 1 ] = c * f;
  2894. te[ 5 ] = bf * d + ae;
  2895. te[ 9 ] = af * d - be;
  2896. te[ 2 ] = - d;
  2897. te[ 6 ] = b * c;
  2898. te[ 10 ] = a * c;
  2899. } else if ( euler.order === 'YZX' ) {
  2900. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2901. te[ 0 ] = c * e;
  2902. te[ 4 ] = bd - ac * f;
  2903. te[ 8 ] = bc * f + ad;
  2904. te[ 1 ] = f;
  2905. te[ 5 ] = a * e;
  2906. te[ 9 ] = - b * e;
  2907. te[ 2 ] = - d * e;
  2908. te[ 6 ] = ad * f + bc;
  2909. te[ 10 ] = ac - bd * f;
  2910. } else if ( euler.order === 'XZY' ) {
  2911. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2912. te[ 0 ] = c * e;
  2913. te[ 4 ] = - f;
  2914. te[ 8 ] = d * e;
  2915. te[ 1 ] = ac * f + bd;
  2916. te[ 5 ] = a * e;
  2917. te[ 9 ] = ad * f - bc;
  2918. te[ 2 ] = bc * f - ad;
  2919. te[ 6 ] = b * e;
  2920. te[ 10 ] = bd * f + ac;
  2921. }
  2922. // last column
  2923. te[ 3 ] = 0;
  2924. te[ 7 ] = 0;
  2925. te[ 11 ] = 0;
  2926. // bottom row
  2927. te[ 12 ] = 0;
  2928. te[ 13 ] = 0;
  2929. te[ 14 ] = 0;
  2930. te[ 15 ] = 1;
  2931. return this;
  2932. },
  2933. setRotationFromQuaternion: function ( q ) {
  2934. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2935. return this.makeRotationFromQuaternion( q );
  2936. },
  2937. makeRotationFromQuaternion: function ( q ) {
  2938. var te = this.elements;
  2939. var x = q.x, y = q.y, z = q.z, w = q.w;
  2940. var x2 = x + x, y2 = y + y, z2 = z + z;
  2941. var xx = x * x2, xy = x * y2, xz = x * z2;
  2942. var yy = y * y2, yz = y * z2, zz = z * z2;
  2943. var wx = w * x2, wy = w * y2, wz = w * z2;
  2944. te[ 0 ] = 1 - ( yy + zz );
  2945. te[ 4 ] = xy - wz;
  2946. te[ 8 ] = xz + wy;
  2947. te[ 1 ] = xy + wz;
  2948. te[ 5 ] = 1 - ( xx + zz );
  2949. te[ 9 ] = yz - wx;
  2950. te[ 2 ] = xz - wy;
  2951. te[ 6 ] = yz + wx;
  2952. te[ 10 ] = 1 - ( xx + yy );
  2953. // last column
  2954. te[ 3 ] = 0;
  2955. te[ 7 ] = 0;
  2956. te[ 11 ] = 0;
  2957. // bottom row
  2958. te[ 12 ] = 0;
  2959. te[ 13 ] = 0;
  2960. te[ 14 ] = 0;
  2961. te[ 15 ] = 1;
  2962. return this;
  2963. },
  2964. lookAt: function () {
  2965. var x, y, z;
  2966. return function ( eye, target, up ) {
  2967. if ( x === undefined ) x = new THREE.Vector3();
  2968. if ( y === undefined ) y = new THREE.Vector3();
  2969. if ( z === undefined ) z = new THREE.Vector3();
  2970. var te = this.elements;
  2971. z.subVectors( eye, target ).normalize();
  2972. if ( z.length() === 0 ) {
  2973. z.z = 1;
  2974. }
  2975. x.crossVectors( up, z ).normalize();
  2976. if ( x.length() === 0 ) {
  2977. z.x += 0.0001;
  2978. x.crossVectors( up, z ).normalize();
  2979. }
  2980. y.crossVectors( z, x );
  2981. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2982. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2983. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2984. return this;
  2985. };
  2986. }(),
  2987. multiply: function ( m, n ) {
  2988. if ( n !== undefined ) {
  2989. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2990. return this.multiplyMatrices( m, n );
  2991. }
  2992. return this.multiplyMatrices( this, m );
  2993. },
  2994. multiplyMatrices: function ( a, b ) {
  2995. var ae = a.elements;
  2996. var be = b.elements;
  2997. var te = this.elements;
  2998. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2999. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3000. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3001. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3002. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3003. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3004. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3005. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3006. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3007. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3008. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3009. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3010. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3011. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3012. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3013. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3014. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3015. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3016. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3017. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3018. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3019. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3020. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3021. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3022. return this;
  3023. },
  3024. multiplyToArray: function ( a, b, r ) {
  3025. var te = this.elements;
  3026. this.multiplyMatrices( a, b );
  3027. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3028. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3029. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3030. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3031. return this;
  3032. },
  3033. multiplyScalar: function ( s ) {
  3034. var te = this.elements;
  3035. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3036. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3037. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3038. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3039. return this;
  3040. },
  3041. multiplyVector3: function ( vector ) {
  3042. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  3043. return vector.applyProjection( this );
  3044. },
  3045. multiplyVector4: function ( vector ) {
  3046. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3047. return vector.applyMatrix4( this );
  3048. },
  3049. multiplyVector3Array: function ( a ) {
  3050. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  3051. return this.applyToVector3Array( a );
  3052. },
  3053. applyToVector3Array: function () {
  3054. var v1;
  3055. return function ( array, offset, length ) {
  3056. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3057. if ( offset === undefined ) offset = 0;
  3058. if ( length === undefined ) length = array.length;
  3059. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3060. v1.fromArray( array, j );
  3061. v1.applyMatrix4( this );
  3062. v1.toArray( array, j );
  3063. }
  3064. return array;
  3065. };
  3066. }(),
  3067. applyToBuffer: function () {
  3068. var v1;
  3069. return function applyToBuffer( buffer, offset, length ) {
  3070. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3071. if ( offset === undefined ) offset = 0;
  3072. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3073. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3074. v1.x = buffer.getX( j );
  3075. v1.y = buffer.getY( j );
  3076. v1.z = buffer.getZ( j );
  3077. v1.applyMatrix4( this );
  3078. buffer.setXYZ( v1.x, v1.y, v1.z );
  3079. }
  3080. return buffer;
  3081. };
  3082. }(),
  3083. rotateAxis: function ( v ) {
  3084. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3085. v.transformDirection( this );
  3086. },
  3087. crossVector: function ( vector ) {
  3088. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3089. return vector.applyMatrix4( this );
  3090. },
  3091. determinant: function () {
  3092. var te = this.elements;
  3093. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3094. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3095. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3096. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3097. //TODO: make this more efficient
  3098. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3099. return (
  3100. n41 * (
  3101. + n14 * n23 * n32
  3102. - n13 * n24 * n32
  3103. - n14 * n22 * n33
  3104. + n12 * n24 * n33
  3105. + n13 * n22 * n34
  3106. - n12 * n23 * n34
  3107. ) +
  3108. n42 * (
  3109. + n11 * n23 * n34
  3110. - n11 * n24 * n33
  3111. + n14 * n21 * n33
  3112. - n13 * n21 * n34
  3113. + n13 * n24 * n31
  3114. - n14 * n23 * n31
  3115. ) +
  3116. n43 * (
  3117. + n11 * n24 * n32
  3118. - n11 * n22 * n34
  3119. - n14 * n21 * n32
  3120. + n12 * n21 * n34
  3121. + n14 * n22 * n31
  3122. - n12 * n24 * n31
  3123. ) +
  3124. n44 * (
  3125. - n13 * n22 * n31
  3126. - n11 * n23 * n32
  3127. + n11 * n22 * n33
  3128. + n13 * n21 * n32
  3129. - n12 * n21 * n33
  3130. + n12 * n23 * n31
  3131. )
  3132. );
  3133. },
  3134. transpose: function () {
  3135. var te = this.elements;
  3136. var tmp;
  3137. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3138. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3139. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3140. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3141. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3142. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3143. return this;
  3144. },
  3145. flattenToArrayOffset: function ( array, offset ) {
  3146. var te = this.elements;
  3147. array[ offset ] = te[ 0 ];
  3148. array[ offset + 1 ] = te[ 1 ];
  3149. array[ offset + 2 ] = te[ 2 ];
  3150. array[ offset + 3 ] = te[ 3 ];
  3151. array[ offset + 4 ] = te[ 4 ];
  3152. array[ offset + 5 ] = te[ 5 ];
  3153. array[ offset + 6 ] = te[ 6 ];
  3154. array[ offset + 7 ] = te[ 7 ];
  3155. array[ offset + 8 ] = te[ 8 ];
  3156. array[ offset + 9 ] = te[ 9 ];
  3157. array[ offset + 10 ] = te[ 10 ];
  3158. array[ offset + 11 ] = te[ 11 ];
  3159. array[ offset + 12 ] = te[ 12 ];
  3160. array[ offset + 13 ] = te[ 13 ];
  3161. array[ offset + 14 ] = te[ 14 ];
  3162. array[ offset + 15 ] = te[ 15 ];
  3163. return array;
  3164. },
  3165. getPosition: function () {
  3166. var v1;
  3167. return function () {
  3168. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3169. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3170. var te = this.elements;
  3171. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3172. };
  3173. }(),
  3174. setPosition: function ( v ) {
  3175. var te = this.elements;
  3176. te[ 12 ] = v.x;
  3177. te[ 13 ] = v.y;
  3178. te[ 14 ] = v.z;
  3179. return this;
  3180. },
  3181. getInverse: function ( m, throwOnInvertible ) {
  3182. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3183. var te = this.elements;
  3184. var me = m.elements;
  3185. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3186. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3187. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3188. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3189. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3190. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3191. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3192. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3193. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3194. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3195. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3196. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3197. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3198. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3199. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3200. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3201. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3202. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3203. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3204. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3205. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3206. if ( det === 0 ) {
  3207. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3208. if ( throwOnInvertible || false ) {
  3209. throw new Error( msg );
  3210. } else {
  3211. console.warn( msg );
  3212. }
  3213. this.identity();
  3214. return this;
  3215. }
  3216. this.multiplyScalar( 1 / det );
  3217. return this;
  3218. },
  3219. translate: function ( v ) {
  3220. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3221. },
  3222. rotateX: function ( angle ) {
  3223. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3224. },
  3225. rotateY: function ( angle ) {
  3226. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3227. },
  3228. rotateZ: function ( angle ) {
  3229. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3230. },
  3231. rotateByAxis: function ( axis, angle ) {
  3232. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3233. },
  3234. scale: function ( v ) {
  3235. var te = this.elements;
  3236. var x = v.x, y = v.y, z = v.z;
  3237. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3238. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3239. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3240. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3241. return this;
  3242. },
  3243. getMaxScaleOnAxis: function () {
  3244. var te = this.elements;
  3245. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3246. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3247. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3248. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3249. },
  3250. makeTranslation: function ( x, y, z ) {
  3251. this.set(
  3252. 1, 0, 0, x,
  3253. 0, 1, 0, y,
  3254. 0, 0, 1, z,
  3255. 0, 0, 0, 1
  3256. );
  3257. return this;
  3258. },
  3259. makeRotationX: function ( theta ) {
  3260. var c = Math.cos( theta ), s = Math.sin( theta );
  3261. this.set(
  3262. 1, 0, 0, 0,
  3263. 0, c, - s, 0,
  3264. 0, s, c, 0,
  3265. 0, 0, 0, 1
  3266. );
  3267. return this;
  3268. },
  3269. makeRotationY: function ( theta ) {
  3270. var c = Math.cos( theta ), s = Math.sin( theta );
  3271. this.set(
  3272. c, 0, s, 0,
  3273. 0, 1, 0, 0,
  3274. - s, 0, c, 0,
  3275. 0, 0, 0, 1
  3276. );
  3277. return this;
  3278. },
  3279. makeRotationZ: function ( theta ) {
  3280. var c = Math.cos( theta ), s = Math.sin( theta );
  3281. this.set(
  3282. c, - s, 0, 0,
  3283. s, c, 0, 0,
  3284. 0, 0, 1, 0,
  3285. 0, 0, 0, 1
  3286. );
  3287. return this;
  3288. },
  3289. makeRotationAxis: function ( axis, angle ) {
  3290. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3291. var c = Math.cos( angle );
  3292. var s = Math.sin( angle );
  3293. var t = 1 - c;
  3294. var x = axis.x, y = axis.y, z = axis.z;
  3295. var tx = t * x, ty = t * y;
  3296. this.set(
  3297. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3298. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3299. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3300. 0, 0, 0, 1
  3301. );
  3302. return this;
  3303. },
  3304. makeScale: function ( x, y, z ) {
  3305. this.set(
  3306. x, 0, 0, 0,
  3307. 0, y, 0, 0,
  3308. 0, 0, z, 0,
  3309. 0, 0, 0, 1
  3310. );
  3311. return this;
  3312. },
  3313. compose: function ( position, quaternion, scale ) {
  3314. this.makeRotationFromQuaternion( quaternion );
  3315. this.scale( scale );
  3316. this.setPosition( position );
  3317. return this;
  3318. },
  3319. decompose: function () {
  3320. var vector, matrix;
  3321. return function ( position, quaternion, scale ) {
  3322. if ( vector === undefined ) vector = new THREE.Vector3();
  3323. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3324. var te = this.elements;
  3325. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3326. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3327. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3328. // if determine is negative, we need to invert one scale
  3329. var det = this.determinant();
  3330. if ( det < 0 ) {
  3331. sx = - sx;
  3332. }
  3333. position.x = te[ 12 ];
  3334. position.y = te[ 13 ];
  3335. position.z = te[ 14 ];
  3336. // scale the rotation part
  3337. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3338. var invSX = 1 / sx;
  3339. var invSY = 1 / sy;
  3340. var invSZ = 1 / sz;
  3341. matrix.elements[ 0 ] *= invSX;
  3342. matrix.elements[ 1 ] *= invSX;
  3343. matrix.elements[ 2 ] *= invSX;
  3344. matrix.elements[ 4 ] *= invSY;
  3345. matrix.elements[ 5 ] *= invSY;
  3346. matrix.elements[ 6 ] *= invSY;
  3347. matrix.elements[ 8 ] *= invSZ;
  3348. matrix.elements[ 9 ] *= invSZ;
  3349. matrix.elements[ 10 ] *= invSZ;
  3350. quaternion.setFromRotationMatrix( matrix );
  3351. scale.x = sx;
  3352. scale.y = sy;
  3353. scale.z = sz;
  3354. return this;
  3355. };
  3356. }(),
  3357. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3358. var te = this.elements;
  3359. var x = 2 * near / ( right - left );
  3360. var y = 2 * near / ( top - bottom );
  3361. var a = ( right + left ) / ( right - left );
  3362. var b = ( top + bottom ) / ( top - bottom );
  3363. var c = - ( far + near ) / ( far - near );
  3364. var d = - 2 * far * near / ( far - near );
  3365. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3366. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3367. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3368. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3369. return this;
  3370. },
  3371. makePerspective: function ( fov, aspect, near, far ) {
  3372. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3373. var ymin = - ymax;
  3374. var xmin = ymin * aspect;
  3375. var xmax = ymax * aspect;
  3376. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3377. },
  3378. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3379. var te = this.elements;
  3380. var w = right - left;
  3381. var h = top - bottom;
  3382. var p = far - near;
  3383. var x = ( right + left ) / w;
  3384. var y = ( top + bottom ) / h;
  3385. var z = ( far + near ) / p;
  3386. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3387. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3388. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3389. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3390. return this;
  3391. },
  3392. equals: function ( matrix ) {
  3393. var te = this.elements;
  3394. var me = matrix.elements;
  3395. for ( var i = 0; i < 16; i ++ ) {
  3396. if ( te[ i ] !== me[ i ] ) return false;
  3397. }
  3398. return true;
  3399. },
  3400. fromArray: function ( array ) {
  3401. this.elements.set( array );
  3402. return this;
  3403. },
  3404. toArray: function () {
  3405. var te = this.elements;
  3406. return [
  3407. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3408. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3409. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3410. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3411. ];
  3412. },
  3413. clone: function () {
  3414. return new THREE.Matrix4().fromArray( this.elements );
  3415. }
  3416. };
  3417. // File:src/math/Ray.js
  3418. /**
  3419. * @author bhouston / http://exocortex.com
  3420. */
  3421. THREE.Ray = function ( origin, direction ) {
  3422. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3423. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3424. };
  3425. THREE.Ray.prototype = {
  3426. constructor: THREE.Ray,
  3427. set: function ( origin, direction ) {
  3428. this.origin.copy( origin );
  3429. this.direction.copy( direction );
  3430. return this;
  3431. },
  3432. copy: function ( ray ) {
  3433. this.origin.copy( ray.origin );
  3434. this.direction.copy( ray.direction );
  3435. return this;
  3436. },
  3437. at: function ( t, optionalTarget ) {
  3438. var result = optionalTarget || new THREE.Vector3();
  3439. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3440. },
  3441. recast: function () {
  3442. var v1 = new THREE.Vector3();
  3443. return function ( t ) {
  3444. this.origin.copy( this.at( t, v1 ) );
  3445. return this;
  3446. };
  3447. }(),
  3448. closestPointToPoint: function ( point, optionalTarget ) {
  3449. var result = optionalTarget || new THREE.Vector3();
  3450. result.subVectors( point, this.origin );
  3451. var directionDistance = result.dot( this.direction );
  3452. if ( directionDistance < 0 ) {
  3453. return result.copy( this.origin );
  3454. }
  3455. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3456. },
  3457. distanceToPoint: function ( point ) {
  3458. return Math.sqrt( this.distanceSqToPoint( point ) );
  3459. },
  3460. distanceSqToPoint: function () {
  3461. var v1 = new THREE.Vector3();
  3462. return function ( point ) {
  3463. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3464. // point behind the ray
  3465. if ( directionDistance < 0 ) {
  3466. return this.origin.distanceToSquared( point );
  3467. }
  3468. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3469. return v1.distanceToSquared( point );
  3470. };
  3471. }(),
  3472. distanceSqToSegment: function () {
  3473. var segCenter = new THREE.Vector3();
  3474. var segDir = new THREE.Vector3();
  3475. var diff = new THREE.Vector3();
  3476. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3477. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3478. // It returns the min distance between the ray and the segment
  3479. // defined by v0 and v1
  3480. // It can also set two optional targets :
  3481. // - The closest point on the ray
  3482. // - The closest point on the segment
  3483. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3484. segDir.copy( v1 ).sub( v0 ).normalize();
  3485. diff.copy( this.origin ).sub( segCenter );
  3486. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3487. var a01 = - this.direction.dot( segDir );
  3488. var b0 = diff.dot( this.direction );
  3489. var b1 = - diff.dot( segDir );
  3490. var c = diff.lengthSq();
  3491. var det = Math.abs( 1 - a01 * a01 );
  3492. var s0, s1, sqrDist, extDet;
  3493. if ( det > 0 ) {
  3494. // The ray and segment are not parallel.
  3495. s0 = a01 * b1 - b0;
  3496. s1 = a01 * b0 - b1;
  3497. extDet = segExtent * det;
  3498. if ( s0 >= 0 ) {
  3499. if ( s1 >= - extDet ) {
  3500. if ( s1 <= extDet ) {
  3501. // region 0
  3502. // Minimum at interior points of ray and segment.
  3503. var invDet = 1 / det;
  3504. s0 *= invDet;
  3505. s1 *= invDet;
  3506. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3507. } else {
  3508. // region 1
  3509. s1 = segExtent;
  3510. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3511. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3512. }
  3513. } else {
  3514. // region 5
  3515. s1 = - segExtent;
  3516. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3517. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3518. }
  3519. } else {
  3520. if ( s1 <= - extDet ) {
  3521. // region 4
  3522. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3523. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3524. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3525. } else if ( s1 <= extDet ) {
  3526. // region 3
  3527. s0 = 0;
  3528. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3529. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3530. } else {
  3531. // region 2
  3532. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3533. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3534. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3535. }
  3536. }
  3537. } else {
  3538. // Ray and segment are parallel.
  3539. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3540. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3541. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3542. }
  3543. if ( optionalPointOnRay ) {
  3544. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3545. }
  3546. if ( optionalPointOnSegment ) {
  3547. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3548. }
  3549. return sqrDist;
  3550. };
  3551. }(),
  3552. isIntersectionSphere: function ( sphere ) {
  3553. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3554. },
  3555. intersectSphere: function () {
  3556. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3557. var v1 = new THREE.Vector3();
  3558. return function ( sphere, optionalTarget ) {
  3559. v1.subVectors( sphere.center, this.origin );
  3560. var tca = v1.dot( this.direction );
  3561. var d2 = v1.dot( v1 ) - tca * tca;
  3562. var radius2 = sphere.radius * sphere.radius;
  3563. if ( d2 > radius2 ) return null;
  3564. var thc = Math.sqrt( radius2 - d2 );
  3565. // t0 = first intersect point - entrance on front of sphere
  3566. var t0 = tca - thc;
  3567. // t1 = second intersect point - exit point on back of sphere
  3568. var t1 = tca + thc;
  3569. // test to see if both t0 and t1 are behind the ray - if so, return null
  3570. if ( t0 < 0 && t1 < 0 ) return null;
  3571. // test to see if t0 is behind the ray:
  3572. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3573. // in order to always return an intersect point that is in front of the ray.
  3574. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3575. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3576. return this.at( t0, optionalTarget );
  3577. }
  3578. }(),
  3579. isIntersectionPlane: function ( plane ) {
  3580. // check if the ray lies on the plane first
  3581. var distToPoint = plane.distanceToPoint( this.origin );
  3582. if ( distToPoint === 0 ) {
  3583. return true;
  3584. }
  3585. var denominator = plane.normal.dot( this.direction );
  3586. if ( denominator * distToPoint < 0 ) {
  3587. return true;
  3588. }
  3589. // ray origin is behind the plane (and is pointing behind it)
  3590. return false;
  3591. },
  3592. distanceToPlane: function ( plane ) {
  3593. var denominator = plane.normal.dot( this.direction );
  3594. if ( denominator === 0 ) {
  3595. // line is coplanar, return origin
  3596. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3597. return 0;
  3598. }
  3599. // Null is preferable to undefined since undefined means.... it is undefined
  3600. return null;
  3601. }
  3602. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3603. // Return if the ray never intersects the plane
  3604. return t >= 0 ? t : null;
  3605. },
  3606. intersectPlane: function ( plane, optionalTarget ) {
  3607. var t = this.distanceToPlane( plane );
  3608. if ( t === null ) {
  3609. return null;
  3610. }
  3611. return this.at( t, optionalTarget );
  3612. },
  3613. isIntersectionBox: function () {
  3614. var v = new THREE.Vector3();
  3615. return function ( box ) {
  3616. return this.intersectBox( box, v ) !== null;
  3617. };
  3618. }(),
  3619. intersectBox: function ( box, optionalTarget ) {
  3620. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3621. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3622. var invdirx = 1 / this.direction.x,
  3623. invdiry = 1 / this.direction.y,
  3624. invdirz = 1 / this.direction.z;
  3625. var origin = this.origin;
  3626. if ( invdirx >= 0 ) {
  3627. tmin = ( box.min.x - origin.x ) * invdirx;
  3628. tmax = ( box.max.x - origin.x ) * invdirx;
  3629. } else {
  3630. tmin = ( box.max.x - origin.x ) * invdirx;
  3631. tmax = ( box.min.x - origin.x ) * invdirx;
  3632. }
  3633. if ( invdiry >= 0 ) {
  3634. tymin = ( box.min.y - origin.y ) * invdiry;
  3635. tymax = ( box.max.y - origin.y ) * invdiry;
  3636. } else {
  3637. tymin = ( box.max.y - origin.y ) * invdiry;
  3638. tymax = ( box.min.y - origin.y ) * invdiry;
  3639. }
  3640. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3641. // These lines also handle the case where tmin or tmax is NaN
  3642. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3643. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3644. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3645. if ( invdirz >= 0 ) {
  3646. tzmin = ( box.min.z - origin.z ) * invdirz;
  3647. tzmax = ( box.max.z - origin.z ) * invdirz;
  3648. } else {
  3649. tzmin = ( box.max.z - origin.z ) * invdirz;
  3650. tzmax = ( box.min.z - origin.z ) * invdirz;
  3651. }
  3652. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3653. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3654. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3655. //return point closest to the ray (positive side)
  3656. if ( tmax < 0 ) return null;
  3657. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3658. },
  3659. intersectTriangle: function () {
  3660. // Compute the offset origin, edges, and normal.
  3661. var diff = new THREE.Vector3();
  3662. var edge1 = new THREE.Vector3();
  3663. var edge2 = new THREE.Vector3();
  3664. var normal = new THREE.Vector3();
  3665. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3666. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3667. edge1.subVectors( b, a );
  3668. edge2.subVectors( c, a );
  3669. normal.crossVectors( edge1, edge2 );
  3670. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3671. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3672. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3673. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3674. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3675. var DdN = this.direction.dot( normal );
  3676. var sign;
  3677. if ( DdN > 0 ) {
  3678. if ( backfaceCulling ) return null;
  3679. sign = 1;
  3680. } else if ( DdN < 0 ) {
  3681. sign = - 1;
  3682. DdN = - DdN;
  3683. } else {
  3684. return null;
  3685. }
  3686. diff.subVectors( this.origin, a );
  3687. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3688. // b1 < 0, no intersection
  3689. if ( DdQxE2 < 0 ) {
  3690. return null;
  3691. }
  3692. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3693. // b2 < 0, no intersection
  3694. if ( DdE1xQ < 0 ) {
  3695. return null;
  3696. }
  3697. // b1+b2 > 1, no intersection
  3698. if ( DdQxE2 + DdE1xQ > DdN ) {
  3699. return null;
  3700. }
  3701. // Line intersects triangle, check if ray does.
  3702. var QdN = - sign * diff.dot( normal );
  3703. // t < 0, no intersection
  3704. if ( QdN < 0 ) {
  3705. return null;
  3706. }
  3707. // Ray intersects triangle.
  3708. return this.at( QdN / DdN, optionalTarget );
  3709. };
  3710. }(),
  3711. applyMatrix4: function ( matrix4 ) {
  3712. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3713. this.origin.applyMatrix4( matrix4 );
  3714. this.direction.sub( this.origin );
  3715. this.direction.normalize();
  3716. return this;
  3717. },
  3718. equals: function ( ray ) {
  3719. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3720. },
  3721. clone: function () {
  3722. return new THREE.Ray().copy( this );
  3723. }
  3724. };
  3725. // File:src/math/Sphere.js
  3726. /**
  3727. * @author bhouston / http://exocortex.com
  3728. * @author mrdoob / http://mrdoob.com/
  3729. */
  3730. THREE.Sphere = function ( center, radius ) {
  3731. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3732. this.radius = ( radius !== undefined ) ? radius : 0;
  3733. };
  3734. THREE.Sphere.prototype = {
  3735. constructor: THREE.Sphere,
  3736. set: function ( center, radius ) {
  3737. this.center.copy( center );
  3738. this.radius = radius;
  3739. return this;
  3740. },
  3741. setFromPoints: function () {
  3742. var box = new THREE.Box3();
  3743. return function ( points, optionalCenter ) {
  3744. var center = this.center;
  3745. if ( optionalCenter !== undefined ) {
  3746. center.copy( optionalCenter );
  3747. } else {
  3748. box.setFromPoints( points ).center( center );
  3749. }
  3750. var maxRadiusSq = 0;
  3751. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3752. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3753. }
  3754. this.radius = Math.sqrt( maxRadiusSq );
  3755. return this;
  3756. };
  3757. }(),
  3758. copy: function ( sphere ) {
  3759. this.center.copy( sphere.center );
  3760. this.radius = sphere.radius;
  3761. return this;
  3762. },
  3763. empty: function () {
  3764. return ( this.radius <= 0 );
  3765. },
  3766. containsPoint: function ( point ) {
  3767. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3768. },
  3769. distanceToPoint: function ( point ) {
  3770. return ( point.distanceTo( this.center ) - this.radius );
  3771. },
  3772. intersectsSphere: function ( sphere ) {
  3773. var radiusSum = this.radius + sphere.radius;
  3774. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3775. },
  3776. clampPoint: function ( point, optionalTarget ) {
  3777. var deltaLengthSq = this.center.distanceToSquared( point );
  3778. var result = optionalTarget || new THREE.Vector3();
  3779. result.copy( point );
  3780. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3781. result.sub( this.center ).normalize();
  3782. result.multiplyScalar( this.radius ).add( this.center );
  3783. }
  3784. return result;
  3785. },
  3786. getBoundingBox: function ( optionalTarget ) {
  3787. var box = optionalTarget || new THREE.Box3();
  3788. box.set( this.center, this.center );
  3789. box.expandByScalar( this.radius );
  3790. return box;
  3791. },
  3792. applyMatrix4: function ( matrix ) {
  3793. this.center.applyMatrix4( matrix );
  3794. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3795. return this;
  3796. },
  3797. translate: function ( offset ) {
  3798. this.center.add( offset );
  3799. return this;
  3800. },
  3801. equals: function ( sphere ) {
  3802. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3803. },
  3804. clone: function () {
  3805. return new THREE.Sphere().copy( this );
  3806. }
  3807. };
  3808. // File:src/math/Frustum.js
  3809. /**
  3810. * @author mrdoob / http://mrdoob.com/
  3811. * @author alteredq / http://alteredqualia.com/
  3812. * @author bhouston / http://exocortex.com
  3813. */
  3814. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3815. this.planes = [
  3816. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3817. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3818. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3819. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3820. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3821. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3822. ];
  3823. };
  3824. THREE.Frustum.prototype = {
  3825. constructor: THREE.Frustum,
  3826. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3827. var planes = this.planes;
  3828. planes[ 0 ].copy( p0 );
  3829. planes[ 1 ].copy( p1 );
  3830. planes[ 2 ].copy( p2 );
  3831. planes[ 3 ].copy( p3 );
  3832. planes[ 4 ].copy( p4 );
  3833. planes[ 5 ].copy( p5 );
  3834. return this;
  3835. },
  3836. copy: function ( frustum ) {
  3837. var planes = this.planes;
  3838. for ( var i = 0; i < 6; i ++ ) {
  3839. planes[ i ].copy( frustum.planes[ i ] );
  3840. }
  3841. return this;
  3842. },
  3843. setFromMatrix: function ( m ) {
  3844. var planes = this.planes;
  3845. var me = m.elements;
  3846. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3847. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3848. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3849. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3850. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3851. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3852. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3853. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3854. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3855. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3856. return this;
  3857. },
  3858. intersectsObject: function () {
  3859. var sphere = new THREE.Sphere();
  3860. return function ( object ) {
  3861. var geometry = object.geometry;
  3862. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3863. sphere.copy( geometry.boundingSphere );
  3864. sphere.applyMatrix4( object.matrixWorld );
  3865. return this.intersectsSphere( sphere );
  3866. };
  3867. }(),
  3868. intersectsSphere: function ( sphere ) {
  3869. var planes = this.planes;
  3870. var center = sphere.center;
  3871. var negRadius = - sphere.radius;
  3872. for ( var i = 0; i < 6; i ++ ) {
  3873. var distance = planes[ i ].distanceToPoint( center );
  3874. if ( distance < negRadius ) {
  3875. return false;
  3876. }
  3877. }
  3878. return true;
  3879. },
  3880. intersectsBox: function () {
  3881. var p1 = new THREE.Vector3(),
  3882. p2 = new THREE.Vector3();
  3883. return function ( box ) {
  3884. var planes = this.planes;
  3885. for ( var i = 0; i < 6 ; i ++ ) {
  3886. var plane = planes[ i ];
  3887. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3888. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3889. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3890. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3891. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3892. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3893. var d1 = plane.distanceToPoint( p1 );
  3894. var d2 = plane.distanceToPoint( p2 );
  3895. // if both outside plane, no intersection
  3896. if ( d1 < 0 && d2 < 0 ) {
  3897. return false;
  3898. }
  3899. }
  3900. return true;
  3901. };
  3902. }(),
  3903. containsPoint: function ( point ) {
  3904. var planes = this.planes;
  3905. for ( var i = 0; i < 6; i ++ ) {
  3906. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3907. return false;
  3908. }
  3909. }
  3910. return true;
  3911. },
  3912. clone: function () {
  3913. return new THREE.Frustum().copy( this );
  3914. }
  3915. };
  3916. // File:src/math/Plane.js
  3917. /**
  3918. * @author bhouston / http://exocortex.com
  3919. */
  3920. THREE.Plane = function ( normal, constant ) {
  3921. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3922. this.constant = ( constant !== undefined ) ? constant : 0;
  3923. };
  3924. THREE.Plane.prototype = {
  3925. constructor: THREE.Plane,
  3926. set: function ( normal, constant ) {
  3927. this.normal.copy( normal );
  3928. this.constant = constant;
  3929. return this;
  3930. },
  3931. setComponents: function ( x, y, z, w ) {
  3932. this.normal.set( x, y, z );
  3933. this.constant = w;
  3934. return this;
  3935. },
  3936. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3937. this.normal.copy( normal );
  3938. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3939. return this;
  3940. },
  3941. setFromCoplanarPoints: function () {
  3942. var v1 = new THREE.Vector3();
  3943. var v2 = new THREE.Vector3();
  3944. return function ( a, b, c ) {
  3945. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3946. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3947. this.setFromNormalAndCoplanarPoint( normal, a );
  3948. return this;
  3949. };
  3950. }(),
  3951. copy: function ( plane ) {
  3952. this.normal.copy( plane.normal );
  3953. this.constant = plane.constant;
  3954. return this;
  3955. },
  3956. normalize: function () {
  3957. // Note: will lead to a divide by zero if the plane is invalid.
  3958. var inverseNormalLength = 1.0 / this.normal.length();
  3959. this.normal.multiplyScalar( inverseNormalLength );
  3960. this.constant *= inverseNormalLength;
  3961. return this;
  3962. },
  3963. negate: function () {
  3964. this.constant *= - 1;
  3965. this.normal.negate();
  3966. return this;
  3967. },
  3968. distanceToPoint: function ( point ) {
  3969. return this.normal.dot( point ) + this.constant;
  3970. },
  3971. distanceToSphere: function ( sphere ) {
  3972. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3973. },
  3974. projectPoint: function ( point, optionalTarget ) {
  3975. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3976. },
  3977. orthoPoint: function ( point, optionalTarget ) {
  3978. var perpendicularMagnitude = this.distanceToPoint( point );
  3979. var result = optionalTarget || new THREE.Vector3();
  3980. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3981. },
  3982. isIntersectionLine: function ( line ) {
  3983. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3984. var startSign = this.distanceToPoint( line.start );
  3985. var endSign = this.distanceToPoint( line.end );
  3986. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3987. },
  3988. intersectLine: function () {
  3989. var v1 = new THREE.Vector3();
  3990. return function ( line, optionalTarget ) {
  3991. var result = optionalTarget || new THREE.Vector3();
  3992. var direction = line.delta( v1 );
  3993. var denominator = this.normal.dot( direction );
  3994. if ( denominator === 0 ) {
  3995. // line is coplanar, return origin
  3996. if ( this.distanceToPoint( line.start ) === 0 ) {
  3997. return result.copy( line.start );
  3998. }
  3999. // Unsure if this is the correct method to handle this case.
  4000. return undefined;
  4001. }
  4002. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4003. if ( t < 0 || t > 1 ) {
  4004. return undefined;
  4005. }
  4006. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4007. };
  4008. }(),
  4009. coplanarPoint: function ( optionalTarget ) {
  4010. var result = optionalTarget || new THREE.Vector3();
  4011. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4012. },
  4013. applyMatrix4: function () {
  4014. var v1 = new THREE.Vector3();
  4015. var v2 = new THREE.Vector3();
  4016. var m1 = new THREE.Matrix3();
  4017. return function ( matrix, optionalNormalMatrix ) {
  4018. // compute new normal based on theory here:
  4019. // http://www.songho.ca/opengl/gl_normaltransform.html
  4020. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4021. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4022. var newCoplanarPoint = this.coplanarPoint( v2 );
  4023. newCoplanarPoint.applyMatrix4( matrix );
  4024. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4025. return this;
  4026. };
  4027. }(),
  4028. translate: function ( offset ) {
  4029. this.constant = this.constant - offset.dot( this.normal );
  4030. return this;
  4031. },
  4032. equals: function ( plane ) {
  4033. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4034. },
  4035. clone: function () {
  4036. return new THREE.Plane().copy( this );
  4037. }
  4038. };
  4039. // File:src/math/Math.js
  4040. /**
  4041. * @author alteredq / http://alteredqualia.com/
  4042. * @author mrdoob / http://mrdoob.com/
  4043. */
  4044. THREE.Math = {
  4045. generateUUID: function () {
  4046. // http://www.broofa.com/Tools/Math.uuid.htm
  4047. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4048. var uuid = new Array( 36 );
  4049. var rnd = 0, r;
  4050. return function () {
  4051. for ( var i = 0; i < 36; i ++ ) {
  4052. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4053. uuid[ i ] = '-';
  4054. } else if ( i === 14 ) {
  4055. uuid[ i ] = '4';
  4056. } else {
  4057. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4058. r = rnd & 0xf;
  4059. rnd = rnd >> 4;
  4060. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4061. }
  4062. }
  4063. return uuid.join( '' );
  4064. };
  4065. }(),
  4066. // Clamp value to range <a, b>
  4067. clamp: function ( x, a, b ) {
  4068. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  4069. },
  4070. // Clamp value to range <a, inf)
  4071. clampBottom: function ( x, a ) {
  4072. return x < a ? a : x;
  4073. },
  4074. // compute euclidian modulo of m % n
  4075. // https://en.wikipedia.org/wiki/Modulo_operation
  4076. euclideanModulo: function ( n, m ) {
  4077. return ( ( n % m ) + m ) % m;
  4078. },
  4079. // Linear mapping from range <a1, a2> to range <b1, b2>
  4080. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4081. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4082. },
  4083. // http://en.wikipedia.org/wiki/Smoothstep
  4084. smoothstep: function ( x, min, max ) {
  4085. if ( x <= min ) return 0;
  4086. if ( x >= max ) return 1;
  4087. x = ( x - min ) / ( max - min );
  4088. return x * x * ( 3 - 2 * x );
  4089. },
  4090. smootherstep: function ( x, min, max ) {
  4091. if ( x <= min ) return 0;
  4092. if ( x >= max ) return 1;
  4093. x = ( x - min ) / ( max - min );
  4094. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4095. },
  4096. // Random float from <0, 1> with 16 bits of randomness
  4097. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4098. random16: function () {
  4099. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4100. },
  4101. // Random integer from <low, high> interval
  4102. randInt: function ( low, high ) {
  4103. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4104. },
  4105. // Random float from <low, high> interval
  4106. randFloat: function ( low, high ) {
  4107. return low + Math.random() * ( high - low );
  4108. },
  4109. // Random float from <-range/2, range/2> interval
  4110. randFloatSpread: function ( range ) {
  4111. return range * ( 0.5 - Math.random() );
  4112. },
  4113. degToRad: function () {
  4114. var degreeToRadiansFactor = Math.PI / 180;
  4115. return function ( degrees ) {
  4116. return degrees * degreeToRadiansFactor;
  4117. };
  4118. }(),
  4119. radToDeg: function () {
  4120. var radianToDegreesFactor = 180 / Math.PI;
  4121. return function ( radians ) {
  4122. return radians * radianToDegreesFactor;
  4123. };
  4124. }(),
  4125. isPowerOfTwo: function ( value ) {
  4126. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4127. },
  4128. nextPowerOfTwo: function ( value ) {
  4129. value --;
  4130. value |= value >> 1;
  4131. value |= value >> 2;
  4132. value |= value >> 4;
  4133. value |= value >> 8;
  4134. value |= value >> 16;
  4135. value ++;
  4136. return value;
  4137. }
  4138. };
  4139. // File:src/math/Spline.js
  4140. /**
  4141. * Spline from Tween.js, slightly optimized (and trashed)
  4142. * http://sole.github.com/tween.js/examples/05_spline.html
  4143. *
  4144. * @author mrdoob / http://mrdoob.com/
  4145. * @author alteredq / http://alteredqualia.com/
  4146. */
  4147. THREE.Spline = function ( points ) {
  4148. this.points = points;
  4149. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4150. point, intPoint, weight, w2, w3,
  4151. pa, pb, pc, pd;
  4152. this.initFromArray = function ( a ) {
  4153. this.points = [];
  4154. for ( var i = 0; i < a.length; i ++ ) {
  4155. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4156. }
  4157. };
  4158. this.getPoint = function ( k ) {
  4159. point = ( this.points.length - 1 ) * k;
  4160. intPoint = Math.floor( point );
  4161. weight = point - intPoint;
  4162. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4163. c[ 1 ] = intPoint;
  4164. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4165. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4166. pa = this.points[ c[ 0 ] ];
  4167. pb = this.points[ c[ 1 ] ];
  4168. pc = this.points[ c[ 2 ] ];
  4169. pd = this.points[ c[ 3 ] ];
  4170. w2 = weight * weight;
  4171. w3 = weight * w2;
  4172. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4173. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4174. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4175. return v3;
  4176. };
  4177. this.getControlPointsArray = function () {
  4178. var i, p, l = this.points.length,
  4179. coords = [];
  4180. for ( i = 0; i < l; i ++ ) {
  4181. p = this.points[ i ];
  4182. coords[ i ] = [ p.x, p.y, p.z ];
  4183. }
  4184. return coords;
  4185. };
  4186. // approximate length by summing linear segments
  4187. this.getLength = function ( nSubDivisions ) {
  4188. var i, index, nSamples, position,
  4189. point = 0, intPoint = 0, oldIntPoint = 0,
  4190. oldPosition = new THREE.Vector3(),
  4191. tmpVec = new THREE.Vector3(),
  4192. chunkLengths = [],
  4193. totalLength = 0;
  4194. // first point has 0 length
  4195. chunkLengths[ 0 ] = 0;
  4196. if ( ! nSubDivisions ) nSubDivisions = 100;
  4197. nSamples = this.points.length * nSubDivisions;
  4198. oldPosition.copy( this.points[ 0 ] );
  4199. for ( i = 1; i < nSamples; i ++ ) {
  4200. index = i / nSamples;
  4201. position = this.getPoint( index );
  4202. tmpVec.copy( position );
  4203. totalLength += tmpVec.distanceTo( oldPosition );
  4204. oldPosition.copy( position );
  4205. point = ( this.points.length - 1 ) * index;
  4206. intPoint = Math.floor( point );
  4207. if ( intPoint !== oldIntPoint ) {
  4208. chunkLengths[ intPoint ] = totalLength;
  4209. oldIntPoint = intPoint;
  4210. }
  4211. }
  4212. // last point ends with total length
  4213. chunkLengths[ chunkLengths.length ] = totalLength;
  4214. return { chunks: chunkLengths, total: totalLength };
  4215. };
  4216. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4217. var i, j,
  4218. index, indexCurrent, indexNext,
  4219. realDistance,
  4220. sampling, position,
  4221. newpoints = [],
  4222. tmpVec = new THREE.Vector3(),
  4223. sl = this.getLength();
  4224. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4225. for ( i = 1; i < this.points.length; i ++ ) {
  4226. //tmpVec.copy( this.points[ i - 1 ] );
  4227. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4228. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4229. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4230. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4231. indexNext = i / ( this.points.length - 1 );
  4232. for ( j = 1; j < sampling - 1; j ++ ) {
  4233. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4234. position = this.getPoint( index );
  4235. newpoints.push( tmpVec.copy( position ).clone() );
  4236. }
  4237. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4238. }
  4239. this.points = newpoints;
  4240. };
  4241. // Catmull-Rom
  4242. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4243. var v0 = ( p2 - p0 ) * 0.5,
  4244. v1 = ( p3 - p1 ) * 0.5;
  4245. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4246. }
  4247. };
  4248. // File:src/math/Triangle.js
  4249. /**
  4250. * @author bhouston / http://exocortex.com
  4251. * @author mrdoob / http://mrdoob.com/
  4252. */
  4253. THREE.Triangle = function ( a, b, c ) {
  4254. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4255. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4256. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4257. };
  4258. THREE.Triangle.normal = function () {
  4259. var v0 = new THREE.Vector3();
  4260. return function ( a, b, c, optionalTarget ) {
  4261. var result = optionalTarget || new THREE.Vector3();
  4262. result.subVectors( c, b );
  4263. v0.subVectors( a, b );
  4264. result.cross( v0 );
  4265. var resultLengthSq = result.lengthSq();
  4266. if ( resultLengthSq > 0 ) {
  4267. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4268. }
  4269. return result.set( 0, 0, 0 );
  4270. };
  4271. }();
  4272. // static/instance method to calculate barycentric coordinates
  4273. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4274. THREE.Triangle.barycoordFromPoint = function () {
  4275. var v0 = new THREE.Vector3();
  4276. var v1 = new THREE.Vector3();
  4277. var v2 = new THREE.Vector3();
  4278. return function ( point, a, b, c, optionalTarget ) {
  4279. v0.subVectors( c, a );
  4280. v1.subVectors( b, a );
  4281. v2.subVectors( point, a );
  4282. var dot00 = v0.dot( v0 );
  4283. var dot01 = v0.dot( v1 );
  4284. var dot02 = v0.dot( v2 );
  4285. var dot11 = v1.dot( v1 );
  4286. var dot12 = v1.dot( v2 );
  4287. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4288. var result = optionalTarget || new THREE.Vector3();
  4289. // collinear or singular triangle
  4290. if ( denom === 0 ) {
  4291. // arbitrary location outside of triangle?
  4292. // not sure if this is the best idea, maybe should be returning undefined
  4293. return result.set( - 2, - 1, - 1 );
  4294. }
  4295. var invDenom = 1 / denom;
  4296. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4297. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4298. // barycentric coordinates must always sum to 1
  4299. return result.set( 1 - u - v, v, u );
  4300. };
  4301. }();
  4302. THREE.Triangle.containsPoint = function () {
  4303. var v1 = new THREE.Vector3();
  4304. return function ( point, a, b, c ) {
  4305. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4306. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4307. };
  4308. }();
  4309. THREE.Triangle.prototype = {
  4310. constructor: THREE.Triangle,
  4311. set: function ( a, b, c ) {
  4312. this.a.copy( a );
  4313. this.b.copy( b );
  4314. this.c.copy( c );
  4315. return this;
  4316. },
  4317. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4318. this.a.copy( points[ i0 ] );
  4319. this.b.copy( points[ i1 ] );
  4320. this.c.copy( points[ i2 ] );
  4321. return this;
  4322. },
  4323. copy: function ( triangle ) {
  4324. this.a.copy( triangle.a );
  4325. this.b.copy( triangle.b );
  4326. this.c.copy( triangle.c );
  4327. return this;
  4328. },
  4329. area: function () {
  4330. var v0 = new THREE.Vector3();
  4331. var v1 = new THREE.Vector3();
  4332. return function () {
  4333. v0.subVectors( this.c, this.b );
  4334. v1.subVectors( this.a, this.b );
  4335. return v0.cross( v1 ).length() * 0.5;
  4336. };
  4337. }(),
  4338. midpoint: function ( optionalTarget ) {
  4339. var result = optionalTarget || new THREE.Vector3();
  4340. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4341. },
  4342. normal: function ( optionalTarget ) {
  4343. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4344. },
  4345. plane: function ( optionalTarget ) {
  4346. var result = optionalTarget || new THREE.Plane();
  4347. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4348. },
  4349. barycoordFromPoint: function ( point, optionalTarget ) {
  4350. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4351. },
  4352. containsPoint: function ( point ) {
  4353. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4354. },
  4355. equals: function ( triangle ) {
  4356. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4357. },
  4358. clone: function () {
  4359. return new THREE.Triangle().copy( this );
  4360. }
  4361. };
  4362. // File:src/core/Clock.js
  4363. /**
  4364. * @author alteredq / http://alteredqualia.com/
  4365. */
  4366. THREE.Clock = function ( autoStart ) {
  4367. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4368. this.startTime = 0;
  4369. this.oldTime = 0;
  4370. this.elapsedTime = 0;
  4371. this.running = false;
  4372. };
  4373. THREE.Clock.prototype = {
  4374. constructor: THREE.Clock,
  4375. start: function () {
  4376. this.startTime = self.performance !== undefined && self.performance.now !== undefined
  4377. ? self.performance.now()
  4378. : Date.now();
  4379. this.oldTime = this.startTime;
  4380. this.running = true;
  4381. },
  4382. stop: function () {
  4383. this.getElapsedTime();
  4384. this.running = false;
  4385. },
  4386. getElapsedTime: function () {
  4387. this.getDelta();
  4388. return this.elapsedTime;
  4389. },
  4390. getDelta: function () {
  4391. var diff = 0;
  4392. if ( this.autoStart && ! this.running ) {
  4393. this.start();
  4394. }
  4395. if ( this.running ) {
  4396. var newTime = self.performance !== undefined && self.performance.now !== undefined
  4397. ? self.performance.now()
  4398. : Date.now();
  4399. diff = 0.001 * ( newTime - this.oldTime );
  4400. this.oldTime = newTime;
  4401. this.elapsedTime += diff;
  4402. }
  4403. return diff;
  4404. }
  4405. };
  4406. // File:src/core/EventDispatcher.js
  4407. /**
  4408. * https://github.com/mrdoob/eventdispatcher.js/
  4409. */
  4410. THREE.EventDispatcher = function () {};
  4411. THREE.EventDispatcher.prototype = {
  4412. constructor: THREE.EventDispatcher,
  4413. apply: function ( object ) {
  4414. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4415. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4416. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4417. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4418. },
  4419. addEventListener: function ( type, listener ) {
  4420. if ( this._listeners === undefined ) this._listeners = {};
  4421. var listeners = this._listeners;
  4422. if ( listeners[ type ] === undefined ) {
  4423. listeners[ type ] = [];
  4424. }
  4425. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4426. listeners[ type ].push( listener );
  4427. }
  4428. },
  4429. hasEventListener: function ( type, listener ) {
  4430. if ( this._listeners === undefined ) return false;
  4431. var listeners = this._listeners;
  4432. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4433. return true;
  4434. }
  4435. return false;
  4436. },
  4437. removeEventListener: function ( type, listener ) {
  4438. if ( this._listeners === undefined ) return;
  4439. var listeners = this._listeners;
  4440. var listenerArray = listeners[ type ];
  4441. if ( listenerArray !== undefined ) {
  4442. var index = listenerArray.indexOf( listener );
  4443. if ( index !== - 1 ) {
  4444. listenerArray.splice( index, 1 );
  4445. }
  4446. }
  4447. },
  4448. dispatchEvent: function ( event ) {
  4449. if ( this._listeners === undefined ) return;
  4450. var listeners = this._listeners;
  4451. var listenerArray = listeners[ event.type ];
  4452. if ( listenerArray !== undefined ) {
  4453. event.target = this;
  4454. var array = [];
  4455. var length = listenerArray.length;
  4456. for ( var i = 0; i < length; i ++ ) {
  4457. array[ i ] = listenerArray[ i ];
  4458. }
  4459. for ( var i = 0; i < length; i ++ ) {
  4460. array[ i ].call( this, event );
  4461. }
  4462. }
  4463. }
  4464. };
  4465. // File:src/core/Raycaster.js
  4466. /**
  4467. * @author mrdoob / http://mrdoob.com/
  4468. * @author bhouston / http://exocortex.com/
  4469. * @author stephomi / http://stephaneginier.com/
  4470. */
  4471. ( function ( THREE ) {
  4472. THREE.Raycaster = function ( origin, direction, near, far ) {
  4473. this.ray = new THREE.Ray( origin, direction );
  4474. // direction is assumed to be normalized (for accurate distance calculations)
  4475. this.near = near || 0;
  4476. this.far = far || Infinity;
  4477. this.params = {
  4478. Sprite: {},
  4479. Mesh: {},
  4480. PointCloud: { threshold: 1 },
  4481. LOD: {},
  4482. Line: {}
  4483. };
  4484. };
  4485. var descSort = function ( a, b ) {
  4486. return a.distance - b.distance;
  4487. };
  4488. var intersectObject = function ( object, raycaster, intersects, recursive ) {
  4489. if ( object.visible === false ) return;
  4490. object.raycast( raycaster, intersects );
  4491. if ( recursive === true ) {
  4492. var children = object.children;
  4493. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4494. intersectObject( children[ i ], raycaster, intersects, true );
  4495. }
  4496. }
  4497. };
  4498. //
  4499. THREE.Raycaster.prototype = {
  4500. constructor: THREE.Raycaster,
  4501. linePrecision: 1,
  4502. set: function ( origin, direction ) {
  4503. // direction is assumed to be normalized (for accurate distance calculations)
  4504. this.ray.set( origin, direction );
  4505. },
  4506. setFromCamera: function ( coords, camera ) {
  4507. if ( camera instanceof THREE.PerspectiveCamera ) {
  4508. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4509. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4510. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4511. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4512. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4513. } else {
  4514. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4515. }
  4516. },
  4517. intersectObject: function ( object, recursive ) {
  4518. var intersects = [];
  4519. intersectObject( object, this, intersects, recursive );
  4520. intersects.sort( descSort );
  4521. return intersects;
  4522. },
  4523. intersectObjects: function ( objects, recursive ) {
  4524. var intersects = [];
  4525. if ( Array.isArray( objects ) === false ) {
  4526. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4527. return intersects;
  4528. }
  4529. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4530. intersectObject( objects[ i ], this, intersects, recursive );
  4531. }
  4532. intersects.sort( descSort );
  4533. return intersects;
  4534. }
  4535. };
  4536. }( THREE ) );
  4537. // File:src/core/Object3D.js
  4538. /**
  4539. * @author mrdoob / http://mrdoob.com/
  4540. * @author mikael emtinger / http://gomo.se/
  4541. * @author alteredq / http://alteredqualia.com/
  4542. * @author WestLangley / http://github.com/WestLangley
  4543. * @author elephantatwork / www.elephantatwork.ch
  4544. */
  4545. THREE.Object3D = function () {
  4546. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4547. this.uuid = THREE.Math.generateUUID();
  4548. this.name = '';
  4549. this.type = 'Object3D';
  4550. this.parent = undefined;
  4551. this.children = [];
  4552. this.up = THREE.Object3D.DefaultUp.clone();
  4553. var position = new THREE.Vector3();
  4554. var rotation = new THREE.Euler();
  4555. var quaternion = new THREE.Quaternion();
  4556. var scale = new THREE.Vector3( 1, 1, 1 );
  4557. var onRotationChange = function () {
  4558. quaternion.setFromEuler( rotation, false );
  4559. };
  4560. var onQuaternionChange = function () {
  4561. rotation.setFromQuaternion( quaternion, undefined, false );
  4562. };
  4563. rotation.onChange( onRotationChange );
  4564. quaternion.onChange( onQuaternionChange );
  4565. Object.defineProperties( this, {
  4566. position: {
  4567. enumerable: true,
  4568. value: position
  4569. },
  4570. rotation: {
  4571. enumerable: true,
  4572. value: rotation
  4573. },
  4574. quaternion: {
  4575. enumerable: true,
  4576. value: quaternion
  4577. },
  4578. scale: {
  4579. enumerable: true,
  4580. value: scale
  4581. }
  4582. } );
  4583. this.rotationAutoUpdate = true;
  4584. this.matrix = new THREE.Matrix4();
  4585. this.matrixWorld = new THREE.Matrix4();
  4586. this.matrixAutoUpdate = true;
  4587. this.matrixWorldNeedsUpdate = false;
  4588. this.visible = true;
  4589. this.castShadow = false;
  4590. this.receiveShadow = false;
  4591. this.frustumCulled = true;
  4592. this.renderOrder = 0;
  4593. this.userData = {};
  4594. };
  4595. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4596. THREE.Object3D.prototype = {
  4597. constructor: THREE.Object3D,
  4598. get eulerOrder () {
  4599. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4600. return this.rotation.order;
  4601. },
  4602. set eulerOrder ( value ) {
  4603. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4604. this.rotation.order = value;
  4605. },
  4606. get useQuaternion () {
  4607. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4608. },
  4609. set useQuaternion ( value ) {
  4610. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4611. },
  4612. set renderDepth ( value ) {
  4613. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4614. },
  4615. applyMatrix: function ( matrix ) {
  4616. this.matrix.multiplyMatrices( matrix, this.matrix );
  4617. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4618. },
  4619. setRotationFromAxisAngle: function ( axis, angle ) {
  4620. // assumes axis is normalized
  4621. this.quaternion.setFromAxisAngle( axis, angle );
  4622. },
  4623. setRotationFromEuler: function ( euler ) {
  4624. this.quaternion.setFromEuler( euler, true );
  4625. },
  4626. setRotationFromMatrix: function ( m ) {
  4627. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4628. this.quaternion.setFromRotationMatrix( m );
  4629. },
  4630. setRotationFromQuaternion: function ( q ) {
  4631. // assumes q is normalized
  4632. this.quaternion.copy( q );
  4633. },
  4634. rotateOnAxis: function () {
  4635. // rotate object on axis in object space
  4636. // axis is assumed to be normalized
  4637. var q1 = new THREE.Quaternion();
  4638. return function ( axis, angle ) {
  4639. q1.setFromAxisAngle( axis, angle );
  4640. this.quaternion.multiply( q1 );
  4641. return this;
  4642. };
  4643. }(),
  4644. rotateX: function () {
  4645. var v1 = new THREE.Vector3( 1, 0, 0 );
  4646. return function ( angle ) {
  4647. return this.rotateOnAxis( v1, angle );
  4648. };
  4649. }(),
  4650. rotateY: function () {
  4651. var v1 = new THREE.Vector3( 0, 1, 0 );
  4652. return function ( angle ) {
  4653. return this.rotateOnAxis( v1, angle );
  4654. };
  4655. }(),
  4656. rotateZ: function () {
  4657. var v1 = new THREE.Vector3( 0, 0, 1 );
  4658. return function ( angle ) {
  4659. return this.rotateOnAxis( v1, angle );
  4660. };
  4661. }(),
  4662. translateOnAxis: function () {
  4663. // translate object by distance along axis in object space
  4664. // axis is assumed to be normalized
  4665. var v1 = new THREE.Vector3();
  4666. return function ( axis, distance ) {
  4667. v1.copy( axis ).applyQuaternion( this.quaternion );
  4668. this.position.add( v1.multiplyScalar( distance ) );
  4669. return this;
  4670. };
  4671. }(),
  4672. translate: function ( distance, axis ) {
  4673. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4674. return this.translateOnAxis( axis, distance );
  4675. },
  4676. translateX: function () {
  4677. var v1 = new THREE.Vector3( 1, 0, 0 );
  4678. return function ( distance ) {
  4679. return this.translateOnAxis( v1, distance );
  4680. };
  4681. }(),
  4682. translateY: function () {
  4683. var v1 = new THREE.Vector3( 0, 1, 0 );
  4684. return function ( distance ) {
  4685. return this.translateOnAxis( v1, distance );
  4686. };
  4687. }(),
  4688. translateZ: function () {
  4689. var v1 = new THREE.Vector3( 0, 0, 1 );
  4690. return function ( distance ) {
  4691. return this.translateOnAxis( v1, distance );
  4692. };
  4693. }(),
  4694. localToWorld: function ( vector ) {
  4695. return vector.applyMatrix4( this.matrixWorld );
  4696. },
  4697. worldToLocal: function () {
  4698. var m1 = new THREE.Matrix4();
  4699. return function ( vector ) {
  4700. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4701. };
  4702. }(),
  4703. lookAt: function () {
  4704. // This routine does not support objects with rotated and/or translated parent(s)
  4705. var m1 = new THREE.Matrix4();
  4706. return function ( vector ) {
  4707. m1.lookAt( vector, this.position, this.up );
  4708. this.quaternion.setFromRotationMatrix( m1 );
  4709. };
  4710. }(),
  4711. add: function ( object ) {
  4712. if ( arguments.length > 1 ) {
  4713. for ( var i = 0; i < arguments.length; i ++ ) {
  4714. this.add( arguments[ i ] );
  4715. }
  4716. return this;
  4717. }
  4718. if ( object === this ) {
  4719. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4720. return this;
  4721. }
  4722. if ( object instanceof THREE.Object3D ) {
  4723. if ( object.parent !== undefined ) {
  4724. object.parent.remove( object );
  4725. }
  4726. object.parent = this;
  4727. object.dispatchEvent( { type: 'added' } );
  4728. this.children.push( object );
  4729. } else {
  4730. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4731. }
  4732. return this;
  4733. },
  4734. remove: function ( object ) {
  4735. if ( arguments.length > 1 ) {
  4736. for ( var i = 0; i < arguments.length; i ++ ) {
  4737. this.remove( arguments[ i ] );
  4738. }
  4739. }
  4740. var index = this.children.indexOf( object );
  4741. if ( index !== - 1 ) {
  4742. object.parent = undefined;
  4743. object.dispatchEvent( { type: 'removed' } );
  4744. this.children.splice( index, 1 );
  4745. }
  4746. },
  4747. getChildByName: function ( name ) {
  4748. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4749. return this.getObjectByName( name );
  4750. },
  4751. getObjectById: function ( id ) {
  4752. return this.getObjectByProperty( 'id', id );
  4753. },
  4754. getObjectByName: function ( name ) {
  4755. return this.getObjectByProperty( 'name', name );
  4756. },
  4757. getObjectByProperty: function ( name, value ) {
  4758. if ( this[ name ] === value ) return this;
  4759. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4760. var child = this.children[ i ];
  4761. var object = child.getObjectByProperty( name, value );
  4762. if ( object !== undefined ) {
  4763. return object;
  4764. }
  4765. }
  4766. return undefined;
  4767. },
  4768. getWorldPosition: function ( optionalTarget ) {
  4769. var result = optionalTarget || new THREE.Vector3();
  4770. this.updateMatrixWorld( true );
  4771. return result.setFromMatrixPosition( this.matrixWorld );
  4772. },
  4773. getWorldQuaternion: function () {
  4774. var position = new THREE.Vector3();
  4775. var scale = new THREE.Vector3();
  4776. return function ( optionalTarget ) {
  4777. var result = optionalTarget || new THREE.Quaternion();
  4778. this.updateMatrixWorld( true );
  4779. this.matrixWorld.decompose( position, result, scale );
  4780. return result;
  4781. };
  4782. }(),
  4783. getWorldRotation: function () {
  4784. var quaternion = new THREE.Quaternion();
  4785. return function ( optionalTarget ) {
  4786. var result = optionalTarget || new THREE.Euler();
  4787. this.getWorldQuaternion( quaternion );
  4788. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4789. };
  4790. }(),
  4791. getWorldScale: function () {
  4792. var position = new THREE.Vector3();
  4793. var quaternion = new THREE.Quaternion();
  4794. return function ( optionalTarget ) {
  4795. var result = optionalTarget || new THREE.Vector3();
  4796. this.updateMatrixWorld( true );
  4797. this.matrixWorld.decompose( position, quaternion, result );
  4798. return result;
  4799. };
  4800. }(),
  4801. getWorldDirection: function () {
  4802. var quaternion = new THREE.Quaternion();
  4803. return function ( optionalTarget ) {
  4804. var result = optionalTarget || new THREE.Vector3();
  4805. this.getWorldQuaternion( quaternion );
  4806. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4807. };
  4808. }(),
  4809. raycast: function () {},
  4810. traverse: function ( callback ) {
  4811. callback( this );
  4812. var children = this.children;
  4813. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4814. children[ i ].traverse( callback );
  4815. }
  4816. },
  4817. traverseVisible: function ( callback ) {
  4818. if ( this.visible === false ) return;
  4819. callback( this );
  4820. var children = this.children;
  4821. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4822. children[ i ].traverseVisible( callback );
  4823. }
  4824. },
  4825. traverseAncestors: function ( callback ) {
  4826. var parent = this.parent;
  4827. if ( parent !== undefined ) {
  4828. callback( parent );
  4829. parent.traverseAncestors( callback );
  4830. }
  4831. },
  4832. updateMatrix: function () {
  4833. this.matrix.compose( this.position, this.quaternion, this.scale );
  4834. this.matrixWorldNeedsUpdate = true;
  4835. },
  4836. updateMatrixWorld: function ( force ) {
  4837. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4838. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4839. if ( this.parent === undefined ) {
  4840. this.matrixWorld.copy( this.matrix );
  4841. } else {
  4842. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4843. }
  4844. this.matrixWorldNeedsUpdate = false;
  4845. force = true;
  4846. }
  4847. // update children
  4848. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4849. this.children[ i ].updateMatrixWorld( force );
  4850. }
  4851. },
  4852. toJSON: function ( meta ) {
  4853. var isRootObject = ( meta === undefined );
  4854. var data = {};
  4855. // meta is a hash used to collect geometries, materials.
  4856. // not providing it implies that this is the root object
  4857. // being serialized.
  4858. if ( isRootObject ) {
  4859. // initialize meta obj
  4860. meta = {
  4861. geometries: {},
  4862. materials: {},
  4863. textures: {},
  4864. images: {}
  4865. };
  4866. data.metadata = {
  4867. version: 4.4,
  4868. type: 'Object',
  4869. generator: 'Object3D.toJSON'
  4870. };
  4871. }
  4872. // standard Object3D serialization
  4873. data.uuid = this.uuid;
  4874. data.type = this.type;
  4875. if ( this.name !== '' ) data.name = this.name;
  4876. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4877. if ( this.visible !== true ) data.visible = this.visible;
  4878. data.matrix = this.matrix.toArray();
  4879. if ( this.children.length > 0 ) {
  4880. data.children = [];
  4881. for ( var i = 0; i < this.children.length; i ++ ) {
  4882. data.children.push( this.children[ i ].toJSON( meta ).object );
  4883. }
  4884. }
  4885. var output = {};
  4886. if ( isRootObject ) {
  4887. var geometries = extractFromCache( meta.geometries );
  4888. var materials = extractFromCache( meta.materials );
  4889. var textures = extractFromCache( meta.textures );
  4890. var images = extractFromCache( meta.images );
  4891. if ( geometries.length > 0 ) output.geometries = geometries;
  4892. if ( materials.length > 0 ) output.materials = materials;
  4893. if ( textures.length > 0 ) output.textures = textures;
  4894. if ( images.length > 0 ) output.images = images;
  4895. }
  4896. output.object = data;
  4897. return output;
  4898. // extract data from the cache hash
  4899. // remove metadata on each item
  4900. // and return as array
  4901. function extractFromCache ( cache ) {
  4902. var values = [];
  4903. for ( var key in cache ) {
  4904. var data = cache[ key ];
  4905. delete data.metadata;
  4906. values.push( data );
  4907. }
  4908. return values;
  4909. }
  4910. },
  4911. clone: function ( recursive ) {
  4912. return new THREE.Object3D().copy( this, recursive );
  4913. },
  4914. copy: function ( source, recursive ) {
  4915. if ( recursive === undefined ) recursive = true;
  4916. this.name = source.name;
  4917. this.up.copy( source.up );
  4918. this.position.copy( source.position );
  4919. this.quaternion.copy( source.quaternion );
  4920. this.scale.copy( source.scale );
  4921. this.rotationAutoUpdate = source.rotationAutoUpdate;
  4922. this.matrix.copy( source.matrix );
  4923. this.matrixWorld.copy( source.matrixWorld );
  4924. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4925. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4926. this.visible = source.visible;
  4927. this.castShadow = source.castShadow;
  4928. this.receiveShadow = source.receiveShadow;
  4929. this.frustumCulled = source.frustumCulled;
  4930. this.renderOrder = source.renderOrder;
  4931. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4932. if ( recursive === true ) {
  4933. for ( var i = 0; i < source.children.length; i ++ ) {
  4934. var child = source.children[ i ];
  4935. this.add( child.clone() );
  4936. }
  4937. }
  4938. return this;
  4939. }
  4940. };
  4941. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4942. THREE.Object3DIdCount = 0;
  4943. // File:src/core/Face3.js
  4944. /**
  4945. * @author mrdoob / http://mrdoob.com/
  4946. * @author alteredq / http://alteredqualia.com/
  4947. */
  4948. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  4949. this.a = a;
  4950. this.b = b;
  4951. this.c = c;
  4952. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4953. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4954. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4955. this.vertexColors = Array.isArray( color ) ? color : [];
  4956. this.vertexTangents = [];
  4957. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4958. };
  4959. THREE.Face3.prototype = {
  4960. constructor: THREE.Face3,
  4961. copy: function ( source ) {
  4962. this.a = source.a;
  4963. this.b = source.b;
  4964. this.c = source.c;
  4965. this.normal.copy( source.normal );
  4966. this.color.copy( source.color );
  4967. this.materialIndex = source.materialIndex;
  4968. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4969. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4970. }
  4971. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4972. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4973. }
  4974. for ( var i = 0, il = source.vertexTangents.length; i < il; i ++ ) {
  4975. this.vertexTangents[ i ] = source.vertexTangents[ i ].clone();
  4976. }
  4977. return this;
  4978. },
  4979. clone: function () {
  4980. return new THREE.Face3().copy( this );
  4981. }
  4982. };
  4983. // File:src/core/Face4.js
  4984. /**
  4985. * @author mrdoob / http://mrdoob.com/
  4986. */
  4987. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  4988. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  4989. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  4990. };
  4991. // File:src/core/BufferAttribute.js
  4992. /**
  4993. * @author mrdoob / http://mrdoob.com/
  4994. */
  4995. THREE.BufferAttribute = function ( array, itemSize ) {
  4996. this.uuid = THREE.Math.generateUUID();
  4997. this.array = array;
  4998. this.itemSize = itemSize;
  4999. this.version = 0;
  5000. };
  5001. THREE.BufferAttribute.prototype = {
  5002. constructor: THREE.BufferAttribute,
  5003. get length () {
  5004. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5005. return this.array.length;
  5006. },
  5007. get count() {
  5008. return this.array.length / this.itemSize;
  5009. },
  5010. set needsUpdate( value ) {
  5011. if ( value === true ) this.version ++;
  5012. },
  5013. copyAt: function ( index1, attribute, index2 ) {
  5014. index1 *= this.itemSize;
  5015. index2 *= attribute.itemSize;
  5016. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5017. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5018. }
  5019. return this;
  5020. },
  5021. copyArray: function ( array ) {
  5022. this.array.set( array );
  5023. return this;
  5024. },
  5025. copyColorsArray: function ( colors ) {
  5026. var array = this.array, offset = 0;
  5027. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5028. var color = colors[ i ];
  5029. if ( color === undefined ) {
  5030. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5031. color = new THREE.Color();
  5032. }
  5033. array[ offset ++ ] = color.r;
  5034. array[ offset ++ ] = color.g;
  5035. array[ offset ++ ] = color.b;
  5036. }
  5037. return this;
  5038. },
  5039. copyIndicesArray: function ( indices ) {
  5040. var array = this.array, offset = 0;
  5041. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5042. var index = indices[ i ];
  5043. array[ offset ++ ] = index.a;
  5044. array[ offset ++ ] = index.b;
  5045. array[ offset ++ ] = index.c;
  5046. }
  5047. return this;
  5048. },
  5049. copyVector2sArray: function ( vectors ) {
  5050. var array = this.array, offset = 0;
  5051. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5052. var vector = vectors[ i ];
  5053. if ( vector === undefined ) {
  5054. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5055. vector = new THREE.Vector2();
  5056. }
  5057. array[ offset ++ ] = vector.x;
  5058. array[ offset ++ ] = vector.y;
  5059. }
  5060. return this;
  5061. },
  5062. copyVector3sArray: function ( vectors ) {
  5063. var array = this.array, offset = 0;
  5064. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5065. var vector = vectors[ i ];
  5066. if ( vector === undefined ) {
  5067. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5068. vector = new THREE.Vector3();
  5069. }
  5070. array[ offset ++ ] = vector.x;
  5071. array[ offset ++ ] = vector.y;
  5072. array[ offset ++ ] = vector.z;
  5073. }
  5074. return this;
  5075. },
  5076. copyVector4sArray: function ( vectors ) {
  5077. var array = this.array, offset = 0;
  5078. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5079. var vector = vectors[ i ];
  5080. if ( vector === undefined ) {
  5081. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5082. vector = new THREE.Vector4();
  5083. }
  5084. array[ offset ++ ] = vector.x;
  5085. array[ offset ++ ] = vector.y;
  5086. array[ offset ++ ] = vector.z;
  5087. array[ offset ++ ] = vector.w;
  5088. }
  5089. return this;
  5090. },
  5091. set: function ( value, offset ) {
  5092. if ( offset === undefined ) offset = 0;
  5093. this.array.set( value, offset );
  5094. return this;
  5095. },
  5096. getX: function ( index ) {
  5097. return this.array[ index * this.itemSize ];
  5098. },
  5099. setX: function ( index, x ) {
  5100. this.array[ index * this.itemSize ] = x;
  5101. return this;
  5102. },
  5103. getY: function ( index ) {
  5104. return this.array[ index * this.itemSize + 1 ];
  5105. },
  5106. setY: function ( index, y ) {
  5107. this.array[ index * this.itemSize + 1 ] = y;
  5108. return this;
  5109. },
  5110. getZ: function ( index ) {
  5111. return this.array[ index * this.itemSize + 2 ];
  5112. },
  5113. setZ: function ( index, z ) {
  5114. this.array[ index * this.itemSize + 2 ] = z;
  5115. return this;
  5116. },
  5117. getW: function ( index ) {
  5118. return this.array[ index * this.itemSize + 3 ];
  5119. },
  5120. setW: function ( index, w ) {
  5121. this.array[ index * this.itemSize + 3 ] = w;
  5122. return this;
  5123. },
  5124. setXY: function ( index, x, y ) {
  5125. index *= this.itemSize;
  5126. this.array[ index + 0 ] = x;
  5127. this.array[ index + 1 ] = y;
  5128. return this;
  5129. },
  5130. setXYZ: function ( index, x, y, z ) {
  5131. index *= this.itemSize;
  5132. this.array[ index + 0 ] = x;
  5133. this.array[ index + 1 ] = y;
  5134. this.array[ index + 2 ] = z;
  5135. return this;
  5136. },
  5137. setXYZW: function ( index, x, y, z, w ) {
  5138. index *= this.itemSize;
  5139. this.array[ index + 0 ] = x;
  5140. this.array[ index + 1 ] = y;
  5141. this.array[ index + 2 ] = z;
  5142. this.array[ index + 3 ] = w;
  5143. return this;
  5144. },
  5145. clone: function () {
  5146. return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5147. }
  5148. };
  5149. //
  5150. THREE.Int8Attribute = function ( array, itemSize ) {
  5151. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5152. };
  5153. THREE.Uint8Attribute = function ( array, itemSize ) {
  5154. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5155. };
  5156. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5157. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5158. };
  5159. THREE.Int16Attribute = function ( array, itemSize ) {
  5160. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5161. };
  5162. THREE.Uint16Attribute = function ( array, itemSize ) {
  5163. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5164. };
  5165. THREE.Int32Attribute = function ( array, itemSize ) {
  5166. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5167. };
  5168. THREE.Uint32Attribute = function ( array, itemSize ) {
  5169. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5170. };
  5171. THREE.Float32Attribute = function ( array, itemSize ) {
  5172. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5173. };
  5174. THREE.Float64Attribute = function ( array, itemSize ) {
  5175. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5176. };
  5177. // File:src/core/DynamicBufferAttribute.js
  5178. /**
  5179. * @author benaadams / https://twitter.com/ben_a_adams
  5180. * @author mrdoob / http://mrdoob.com/
  5181. */
  5182. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5183. THREE.BufferAttribute.call( this, array, itemSize );
  5184. this.updateRange = { offset: 0, count: - 1 };
  5185. };
  5186. THREE.DynamicBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5187. THREE.DynamicBufferAttribute.prototype.constructor = THREE.DynamicBufferAttribute;
  5188. THREE.DynamicBufferAttribute.prototype.clone = function () {
  5189. return new THREE.DynamicBufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5190. };
  5191. // File:src/core/InstancedBufferAttribute.js
  5192. /**
  5193. * @author benaadams / https://twitter.com/ben_a_adams
  5194. */
  5195. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute, dynamic ) {
  5196. THREE.DynamicBufferAttribute.call( this, array, itemSize );
  5197. this.dynamic = dynamic || false;
  5198. this.meshPerAttribute = meshPerAttribute || 1;
  5199. };
  5200. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.DynamicBufferAttribute.prototype );
  5201. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5202. THREE.InstancedBufferAttribute.prototype.clone = function () {
  5203. return new THREE.InstancedBufferAttribute( new this.array.constructor( this.array ), this.itemSize, this.meshPerAttribute, this.dynamic );
  5204. };
  5205. // File:src/core/InterleavedBuffer.js
  5206. /**
  5207. * @author benaadams / https://twitter.com/ben_a_adams
  5208. */
  5209. THREE.InterleavedBuffer = function ( array, stride, dynamic ) {
  5210. this.uuid = THREE.Math.generateUUID();
  5211. this.array = array;
  5212. this.stride = stride;
  5213. this.version = 0;
  5214. this.dynamic = dynamic || false;
  5215. this.updateRange = { offset: 0, count: - 1 };
  5216. };
  5217. THREE.InterleavedBuffer.prototype = {
  5218. constructor: THREE.InterleavedBuffer,
  5219. get length () {
  5220. return this.array.length;
  5221. },
  5222. get count () {
  5223. return this.array.length / this.stride;
  5224. },
  5225. set needsUpdate( value ) {
  5226. if ( value === true ) this.version ++;
  5227. },
  5228. copyAt: function ( index1, attribute, index2 ) {
  5229. index1 *= this.stride;
  5230. index2 *= attribute.stride;
  5231. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5232. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5233. }
  5234. return this;
  5235. },
  5236. set: function ( value, offset ) {
  5237. if ( offset === undefined ) offset = 0;
  5238. this.array.set( value, offset );
  5239. return this;
  5240. },
  5241. clone: function () {
  5242. return new THREE.InterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic );
  5243. }
  5244. };
  5245. // File:src/core/InstancedInterleavedBuffer.js
  5246. /**
  5247. * @author benaadams / https://twitter.com/ben_a_adams
  5248. */
  5249. THREE.InstancedInterleavedBuffer = function ( array, stride, dynamic, meshPerAttribute ) {
  5250. THREE.InterleavedBuffer.call( this, array, stride, dynamic );
  5251. this.meshPerAttribute = meshPerAttribute || 1;
  5252. };
  5253. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5254. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5255. THREE.InstancedInterleavedBuffer.prototype.clone = function () {
  5256. return new THREE.InstancedInterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic, this.meshPerAttribute );
  5257. };
  5258. // File:src/core/InterleavedBufferAttribute.js
  5259. /**
  5260. * @author benaadams / https://twitter.com/ben_a_adams
  5261. */
  5262. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5263. this.uuid = THREE.Math.generateUUID();
  5264. this.data = interleavedBuffer;
  5265. this.itemSize = itemSize;
  5266. this.offset = offset;
  5267. };
  5268. THREE.InterleavedBufferAttribute.prototype = {
  5269. constructor: THREE.InterleavedBufferAttribute,
  5270. get length() {
  5271. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5272. return this.array.length;
  5273. },
  5274. get count() {
  5275. return this.data.array.length / this.data.stride;
  5276. },
  5277. setX: function ( index, x ) {
  5278. this.data.array[ index * this.data.stride + this.offset ] = x;
  5279. return this;
  5280. },
  5281. setY: function ( index, y ) {
  5282. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5283. return this;
  5284. },
  5285. setZ: function ( index, z ) {
  5286. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5287. return this;
  5288. },
  5289. setW: function ( index, w ) {
  5290. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5291. return this;
  5292. },
  5293. getX: function ( index ) {
  5294. return this.data.array[ index * this.data.stride + this.offset ];
  5295. },
  5296. getY: function ( index ) {
  5297. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5298. },
  5299. getZ: function ( index ) {
  5300. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5301. },
  5302. getW: function ( index ) {
  5303. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5304. },
  5305. setXY: function ( index, x, y ) {
  5306. index = index * this.data.stride + this.offset;
  5307. this.data.array[ index + 0 ] = x;
  5308. this.data.array[ index + 1 ] = y;
  5309. return this;
  5310. },
  5311. setXYZ: function ( index, x, y, z ) {
  5312. index = index * this.data.stride + this.offset;
  5313. this.data.array[ index + 0 ] = x;
  5314. this.data.array[ index + 1 ] = y;
  5315. this.data.array[ index + 2 ] = z;
  5316. return this;
  5317. },
  5318. setXYZW: function ( index, x, y, z, w ) {
  5319. index = index * this.data.stride + this.offset;
  5320. this.data.array[ index + 0 ] = x;
  5321. this.data.array[ index + 1 ] = y;
  5322. this.data.array[ index + 2 ] = z;
  5323. this.data.array[ index + 3 ] = w;
  5324. return this;
  5325. }
  5326. };
  5327. // File:src/core/Geometry.js
  5328. /**
  5329. * @author mrdoob / http://mrdoob.com/
  5330. * @author kile / http://kile.stravaganza.org/
  5331. * @author alteredq / http://alteredqualia.com/
  5332. * @author mikael emtinger / http://gomo.se/
  5333. * @author zz85 / http://www.lab4games.net/zz85/blog
  5334. * @author bhouston / http://exocortex.com
  5335. */
  5336. THREE.Geometry = function () {
  5337. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5338. this.uuid = THREE.Math.generateUUID();
  5339. this.name = '';
  5340. this.type = 'Geometry';
  5341. this.vertices = [];
  5342. this.colors = [];
  5343. this.faces = [];
  5344. this.faceVertexUvs = [ [] ];
  5345. this.morphTargets = [];
  5346. this.morphColors = [];
  5347. this.morphNormals = [];
  5348. this.skinWeights = [];
  5349. this.skinIndices = [];
  5350. this.lineDistances = [];
  5351. this.boundingBox = null;
  5352. this.boundingSphere = null;
  5353. this.hasTangents = false;
  5354. // update flags
  5355. this.verticesNeedUpdate = false;
  5356. this.elementsNeedUpdate = false;
  5357. this.uvsNeedUpdate = false;
  5358. this.normalsNeedUpdate = false;
  5359. this.tangentsNeedUpdate = false;
  5360. this.colorsNeedUpdate = false;
  5361. this.lineDistancesNeedUpdate = false;
  5362. };
  5363. THREE.Geometry.prototype = {
  5364. constructor: THREE.Geometry,
  5365. applyMatrix: function ( matrix ) {
  5366. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5367. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5368. var vertex = this.vertices[ i ];
  5369. vertex.applyMatrix4( matrix );
  5370. }
  5371. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5372. var face = this.faces[ i ];
  5373. face.normal.applyMatrix3( normalMatrix ).normalize();
  5374. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5375. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5376. }
  5377. }
  5378. if ( this.boundingBox !== null ) {
  5379. this.computeBoundingBox();
  5380. }
  5381. if ( this.boundingSphere !== null ) {
  5382. this.computeBoundingSphere();
  5383. }
  5384. this.verticesNeedUpdate = true;
  5385. this.normalsNeedUpdate = true;
  5386. },
  5387. fromBufferGeometry: function ( geometry ) {
  5388. var scope = this;
  5389. var attributes = geometry.attributes;
  5390. var vertices = attributes.position.array;
  5391. var indices = attributes.index !== undefined ? attributes.index.array : undefined;
  5392. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5393. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5394. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5395. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5396. var tangents = attributes.tangent !== undefined ? attributes.tangent.array : undefined;
  5397. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5398. if ( tangents !== undefined ) this.hasTangents = true;
  5399. var tempNormals = [];
  5400. var tempUVs = [];
  5401. var tempUVs2 = [];
  5402. var tempTangents = [];
  5403. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5404. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5405. if ( normals !== undefined ) {
  5406. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5407. }
  5408. if ( colors !== undefined ) {
  5409. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5410. }
  5411. if ( uvs !== undefined ) {
  5412. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5413. }
  5414. if ( uvs2 !== undefined ) {
  5415. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5416. }
  5417. if ( tangents !== undefined ) {
  5418. tempTangents.push( new THREE.Vector4( tangents[ k ], tangents[ k + 1 ], tangents[ k + 2 ], tangents[ k + 3 ] ) );
  5419. }
  5420. }
  5421. var addFace = function ( a, b, c ) {
  5422. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5423. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5424. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5425. scope.faces.push( face );
  5426. if ( uvs !== undefined ) {
  5427. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5428. }
  5429. if ( uvs2 !== undefined ) {
  5430. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5431. }
  5432. if ( tangents !== undefined ) {
  5433. face.vertexTangents.push( tempTangents[ a ].clone(), tempTangents[ b ].clone(), tempTangents[ c ].clone() );
  5434. }
  5435. };
  5436. if ( indices !== undefined ) {
  5437. var drawcalls = geometry.drawcalls;
  5438. if ( drawcalls.length > 0 ) {
  5439. for ( var i = 0; i < drawcalls.length; i ++ ) {
  5440. var drawcall = drawcalls[ i ];
  5441. var start = drawcall.start;
  5442. var count = drawcall.count;
  5443. var index = drawcall.index;
  5444. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5445. addFace( index + indices[ j ], index + indices[ j + 1 ], index + indices[ j + 2 ] );
  5446. }
  5447. }
  5448. } else {
  5449. for ( var i = 0; i < indices.length; i += 3 ) {
  5450. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5451. }
  5452. }
  5453. } else {
  5454. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5455. addFace( i, i + 1, i + 2 );
  5456. }
  5457. }
  5458. this.computeFaceNormals();
  5459. if ( geometry.boundingBox !== null ) {
  5460. this.boundingBox = geometry.boundingBox.clone();
  5461. }
  5462. if ( geometry.boundingSphere !== null ) {
  5463. this.boundingSphere = geometry.boundingSphere.clone();
  5464. }
  5465. return this;
  5466. },
  5467. center: function () {
  5468. this.computeBoundingBox();
  5469. var offset = this.boundingBox.center().negate();
  5470. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  5471. return offset;
  5472. },
  5473. normalize: function () {
  5474. this.computeBoundingSphere();
  5475. var center = this.boundingSphere.center;
  5476. var radius = this.boundingSphere.radius;
  5477. var s = radius === 0 ? 1 : 1.0 / radius;
  5478. var matrix = new THREE.Matrix4();
  5479. matrix.set(
  5480. s, 0, 0, - s * center.x,
  5481. 0, s, 0, - s * center.y,
  5482. 0, 0, s, - s * center.z,
  5483. 0, 0, 0, 1
  5484. );
  5485. this.applyMatrix( matrix );
  5486. return this;
  5487. },
  5488. computeFaceNormals: function () {
  5489. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5490. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5491. var face = this.faces[ f ];
  5492. var vA = this.vertices[ face.a ];
  5493. var vB = this.vertices[ face.b ];
  5494. var vC = this.vertices[ face.c ];
  5495. cb.subVectors( vC, vB );
  5496. ab.subVectors( vA, vB );
  5497. cb.cross( ab );
  5498. cb.normalize();
  5499. face.normal.copy( cb );
  5500. }
  5501. },
  5502. computeVertexNormals: function ( areaWeighted ) {
  5503. var v, vl, f, fl, face, vertices;
  5504. vertices = new Array( this.vertices.length );
  5505. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5506. vertices[ v ] = new THREE.Vector3();
  5507. }
  5508. if ( areaWeighted ) {
  5509. // vertex normals weighted by triangle areas
  5510. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5511. var vA, vB, vC;
  5512. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5513. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5514. face = this.faces[ f ];
  5515. vA = this.vertices[ face.a ];
  5516. vB = this.vertices[ face.b ];
  5517. vC = this.vertices[ face.c ];
  5518. cb.subVectors( vC, vB );
  5519. ab.subVectors( vA, vB );
  5520. cb.cross( ab );
  5521. vertices[ face.a ].add( cb );
  5522. vertices[ face.b ].add( cb );
  5523. vertices[ face.c ].add( cb );
  5524. }
  5525. } else {
  5526. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5527. face = this.faces[ f ];
  5528. vertices[ face.a ].add( face.normal );
  5529. vertices[ face.b ].add( face.normal );
  5530. vertices[ face.c ].add( face.normal );
  5531. }
  5532. }
  5533. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5534. vertices[ v ].normalize();
  5535. }
  5536. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5537. face = this.faces[ f ];
  5538. var vertexNormals = face.vertexNormals;
  5539. if ( vertexNormals.length === 3 ) {
  5540. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5541. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5542. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5543. } else {
  5544. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5545. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5546. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5547. }
  5548. }
  5549. },
  5550. computeMorphNormals: function () {
  5551. var i, il, f, fl, face;
  5552. // save original normals
  5553. // - create temp variables on first access
  5554. // otherwise just copy (for faster repeated calls)
  5555. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5556. face = this.faces[ f ];
  5557. if ( ! face.__originalFaceNormal ) {
  5558. face.__originalFaceNormal = face.normal.clone();
  5559. } else {
  5560. face.__originalFaceNormal.copy( face.normal );
  5561. }
  5562. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5563. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5564. if ( ! face.__originalVertexNormals[ i ] ) {
  5565. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5566. } else {
  5567. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5568. }
  5569. }
  5570. }
  5571. // use temp geometry to compute face and vertex normals for each morph
  5572. var tmpGeo = new THREE.Geometry();
  5573. tmpGeo.faces = this.faces;
  5574. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5575. // create on first access
  5576. if ( ! this.morphNormals[ i ] ) {
  5577. this.morphNormals[ i ] = {};
  5578. this.morphNormals[ i ].faceNormals = [];
  5579. this.morphNormals[ i ].vertexNormals = [];
  5580. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5581. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5582. var faceNormal, vertexNormals;
  5583. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5584. faceNormal = new THREE.Vector3();
  5585. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5586. dstNormalsFace.push( faceNormal );
  5587. dstNormalsVertex.push( vertexNormals );
  5588. }
  5589. }
  5590. var morphNormals = this.morphNormals[ i ];
  5591. // set vertices to morph target
  5592. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5593. // compute morph normals
  5594. tmpGeo.computeFaceNormals();
  5595. tmpGeo.computeVertexNormals();
  5596. // store morph normals
  5597. var faceNormal, vertexNormals;
  5598. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5599. face = this.faces[ f ];
  5600. faceNormal = morphNormals.faceNormals[ f ];
  5601. vertexNormals = morphNormals.vertexNormals[ f ];
  5602. faceNormal.copy( face.normal );
  5603. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5604. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5605. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5606. }
  5607. }
  5608. // restore original normals
  5609. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5610. face = this.faces[ f ];
  5611. face.normal = face.__originalFaceNormal;
  5612. face.vertexNormals = face.__originalVertexNormals;
  5613. }
  5614. },
  5615. computeTangents: function () {
  5616. // based on http://www.terathon.com/code/tangent.html
  5617. // tangents go to vertices
  5618. var f, fl, v, vl, i, vertexIndex,
  5619. face, uv, vA, vB, vC, uvA, uvB, uvC,
  5620. x1, x2, y1, y2, z1, z2,
  5621. s1, s2, t1, t2, r, t, test,
  5622. tan1 = [], tan2 = [],
  5623. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  5624. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  5625. n = new THREE.Vector3(), w;
  5626. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5627. tan1[ v ] = new THREE.Vector3();
  5628. tan2[ v ] = new THREE.Vector3();
  5629. }
  5630. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  5631. vA = context.vertices[ a ];
  5632. vB = context.vertices[ b ];
  5633. vC = context.vertices[ c ];
  5634. uvA = uv[ ua ];
  5635. uvB = uv[ ub ];
  5636. uvC = uv[ uc ];
  5637. x1 = vB.x - vA.x;
  5638. x2 = vC.x - vA.x;
  5639. y1 = vB.y - vA.y;
  5640. y2 = vC.y - vA.y;
  5641. z1 = vB.z - vA.z;
  5642. z2 = vC.z - vA.z;
  5643. s1 = uvB.x - uvA.x;
  5644. s2 = uvC.x - uvA.x;
  5645. t1 = uvB.y - uvA.y;
  5646. t2 = uvC.y - uvA.y;
  5647. r = 1.0 / ( s1 * t2 - s2 * t1 );
  5648. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  5649. ( t2 * y1 - t1 * y2 ) * r,
  5650. ( t2 * z1 - t1 * z2 ) * r );
  5651. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  5652. ( s1 * y2 - s2 * y1 ) * r,
  5653. ( s1 * z2 - s2 * z1 ) * r );
  5654. tan1[ a ].add( sdir );
  5655. tan1[ b ].add( sdir );
  5656. tan1[ c ].add( sdir );
  5657. tan2[ a ].add( tdir );
  5658. tan2[ b ].add( tdir );
  5659. tan2[ c ].add( tdir );
  5660. }
  5661. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5662. face = this.faces[ f ];
  5663. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  5664. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  5665. }
  5666. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  5667. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5668. face = this.faces[ f ];
  5669. for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i ++ ) {
  5670. n.copy( face.vertexNormals[ i ] );
  5671. vertexIndex = face[ faceIndex[ i ] ];
  5672. t = tan1[ vertexIndex ];
  5673. // Gram-Schmidt orthogonalize
  5674. tmp.copy( t );
  5675. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  5676. // Calculate handedness
  5677. tmp2.crossVectors( face.vertexNormals[ i ], t );
  5678. test = tmp2.dot( tan2[ vertexIndex ] );
  5679. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  5680. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  5681. }
  5682. }
  5683. this.hasTangents = true;
  5684. },
  5685. computeLineDistances: function () {
  5686. var d = 0;
  5687. var vertices = this.vertices;
  5688. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5689. if ( i > 0 ) {
  5690. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5691. }
  5692. this.lineDistances[ i ] = d;
  5693. }
  5694. },
  5695. computeBoundingBox: function () {
  5696. if ( this.boundingBox === null ) {
  5697. this.boundingBox = new THREE.Box3();
  5698. }
  5699. this.boundingBox.setFromPoints( this.vertices );
  5700. },
  5701. computeBoundingSphere: function () {
  5702. if ( this.boundingSphere === null ) {
  5703. this.boundingSphere = new THREE.Sphere();
  5704. }
  5705. this.boundingSphere.setFromPoints( this.vertices );
  5706. },
  5707. merge: function ( geometry, matrix, materialIndexOffset ) {
  5708. if ( geometry instanceof THREE.Geometry === false ) {
  5709. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5710. return;
  5711. }
  5712. var normalMatrix,
  5713. vertexOffset = this.vertices.length,
  5714. vertices1 = this.vertices,
  5715. vertices2 = geometry.vertices,
  5716. faces1 = this.faces,
  5717. faces2 = geometry.faces,
  5718. uvs1 = this.faceVertexUvs[ 0 ],
  5719. uvs2 = geometry.faceVertexUvs[ 0 ];
  5720. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5721. if ( matrix !== undefined ) {
  5722. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5723. }
  5724. // vertices
  5725. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5726. var vertex = vertices2[ i ];
  5727. var vertexCopy = vertex.clone();
  5728. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5729. vertices1.push( vertexCopy );
  5730. }
  5731. // faces
  5732. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5733. var face = faces2[ i ], faceCopy, normal, color,
  5734. faceVertexNormals = face.vertexNormals,
  5735. faceVertexColors = face.vertexColors;
  5736. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5737. faceCopy.normal.copy( face.normal );
  5738. if ( normalMatrix !== undefined ) {
  5739. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5740. }
  5741. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5742. normal = faceVertexNormals[ j ].clone();
  5743. if ( normalMatrix !== undefined ) {
  5744. normal.applyMatrix3( normalMatrix ).normalize();
  5745. }
  5746. faceCopy.vertexNormals.push( normal );
  5747. }
  5748. faceCopy.color.copy( face.color );
  5749. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5750. color = faceVertexColors[ j ];
  5751. faceCopy.vertexColors.push( color.clone() );
  5752. }
  5753. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5754. faces1.push( faceCopy );
  5755. }
  5756. // uvs
  5757. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5758. var uv = uvs2[ i ], uvCopy = [];
  5759. if ( uv === undefined ) {
  5760. continue;
  5761. }
  5762. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5763. uvCopy.push( uv[ j ].clone() );
  5764. }
  5765. uvs1.push( uvCopy );
  5766. }
  5767. },
  5768. mergeMesh: function ( mesh ) {
  5769. if ( mesh instanceof THREE.Mesh === false ) {
  5770. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5771. return;
  5772. }
  5773. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5774. this.merge( mesh.geometry, mesh.matrix );
  5775. },
  5776. /*
  5777. * Checks for duplicate vertices with hashmap.
  5778. * Duplicated vertices are removed
  5779. * and faces' vertices are updated.
  5780. */
  5781. mergeVertices: function () {
  5782. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5783. var unique = [], changes = [];
  5784. var v, key;
  5785. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5786. var precision = Math.pow( 10, precisionPoints );
  5787. var i, il, face;
  5788. var indices, j, jl;
  5789. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5790. v = this.vertices[ i ];
  5791. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5792. if ( verticesMap[ key ] === undefined ) {
  5793. verticesMap[ key ] = i;
  5794. unique.push( this.vertices[ i ] );
  5795. changes[ i ] = unique.length - 1;
  5796. } else {
  5797. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5798. changes[ i ] = changes[ verticesMap[ key ] ];
  5799. }
  5800. }
  5801. // if faces are completely degenerate after merging vertices, we
  5802. // have to remove them from the geometry.
  5803. var faceIndicesToRemove = [];
  5804. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5805. face = this.faces[ i ];
  5806. face.a = changes[ face.a ];
  5807. face.b = changes[ face.b ];
  5808. face.c = changes[ face.c ];
  5809. indices = [ face.a, face.b, face.c ];
  5810. var dupIndex = - 1;
  5811. // if any duplicate vertices are found in a Face3
  5812. // we have to remove the face as nothing can be saved
  5813. for ( var n = 0; n < 3; n ++ ) {
  5814. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5815. dupIndex = n;
  5816. faceIndicesToRemove.push( i );
  5817. break;
  5818. }
  5819. }
  5820. }
  5821. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5822. var idx = faceIndicesToRemove[ i ];
  5823. this.faces.splice( idx, 1 );
  5824. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5825. this.faceVertexUvs[ j ].splice( idx, 1 );
  5826. }
  5827. }
  5828. // Use unique set of vertices
  5829. var diff = this.vertices.length - unique.length;
  5830. this.vertices = unique;
  5831. return diff;
  5832. },
  5833. toJSON: function () {
  5834. var data = {
  5835. metadata: {
  5836. version: 4.4,
  5837. type: 'Geometry',
  5838. generator: 'Geometry.toJSON'
  5839. }
  5840. };
  5841. // standard Geometry serialization
  5842. data.uuid = this.uuid;
  5843. data.type = this.type;
  5844. if ( this.name !== '' ) data.name = this.name;
  5845. if ( this.parameters !== undefined ) {
  5846. var parameters = this.parameters;
  5847. for ( var key in parameters ) {
  5848. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5849. }
  5850. return data;
  5851. }
  5852. var vertices = [];
  5853. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5854. var vertex = this.vertices[ i ];
  5855. vertices.push( vertex.x, vertex.y, vertex.z );
  5856. }
  5857. var faces = [];
  5858. var normals = [];
  5859. var normalsHash = {};
  5860. var colors = [];
  5861. var colorsHash = {};
  5862. var uvs = [];
  5863. var uvsHash = {};
  5864. for ( var i = 0; i < this.faces.length; i ++ ) {
  5865. var face = this.faces[ i ];
  5866. var hasMaterial = false; // face.materialIndex !== undefined;
  5867. var hasFaceUv = false; // deprecated
  5868. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5869. var hasFaceNormal = face.normal.length() > 0;
  5870. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5871. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5872. var hasFaceVertexColor = face.vertexColors.length > 0;
  5873. var faceType = 0;
  5874. faceType = setBit( faceType, 0, 0 );
  5875. faceType = setBit( faceType, 1, hasMaterial );
  5876. faceType = setBit( faceType, 2, hasFaceUv );
  5877. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5878. faceType = setBit( faceType, 4, hasFaceNormal );
  5879. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5880. faceType = setBit( faceType, 6, hasFaceColor );
  5881. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5882. faces.push( faceType );
  5883. faces.push( face.a, face.b, face.c );
  5884. if ( hasFaceVertexUv ) {
  5885. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5886. faces.push(
  5887. getUvIndex( faceVertexUvs[ 0 ] ),
  5888. getUvIndex( faceVertexUvs[ 1 ] ),
  5889. getUvIndex( faceVertexUvs[ 2 ] )
  5890. );
  5891. }
  5892. if ( hasFaceNormal ) {
  5893. faces.push( getNormalIndex( face.normal ) );
  5894. }
  5895. if ( hasFaceVertexNormal ) {
  5896. var vertexNormals = face.vertexNormals;
  5897. faces.push(
  5898. getNormalIndex( vertexNormals[ 0 ] ),
  5899. getNormalIndex( vertexNormals[ 1 ] ),
  5900. getNormalIndex( vertexNormals[ 2 ] )
  5901. );
  5902. }
  5903. if ( hasFaceColor ) {
  5904. faces.push( getColorIndex( face.color ) );
  5905. }
  5906. if ( hasFaceVertexColor ) {
  5907. var vertexColors = face.vertexColors;
  5908. faces.push(
  5909. getColorIndex( vertexColors[ 0 ] ),
  5910. getColorIndex( vertexColors[ 1 ] ),
  5911. getColorIndex( vertexColors[ 2 ] )
  5912. );
  5913. }
  5914. }
  5915. function setBit( value, position, enabled ) {
  5916. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5917. }
  5918. function getNormalIndex( normal ) {
  5919. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5920. if ( normalsHash[ hash ] !== undefined ) {
  5921. return normalsHash[ hash ];
  5922. }
  5923. normalsHash[ hash ] = normals.length / 3;
  5924. normals.push( normal.x, normal.y, normal.z );
  5925. return normalsHash[ hash ];
  5926. }
  5927. function getColorIndex( color ) {
  5928. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5929. if ( colorsHash[ hash ] !== undefined ) {
  5930. return colorsHash[ hash ];
  5931. }
  5932. colorsHash[ hash ] = colors.length;
  5933. colors.push( color.getHex() );
  5934. return colorsHash[ hash ];
  5935. }
  5936. function getUvIndex( uv ) {
  5937. var hash = uv.x.toString() + uv.y.toString();
  5938. if ( uvsHash[ hash ] !== undefined ) {
  5939. return uvsHash[ hash ];
  5940. }
  5941. uvsHash[ hash ] = uvs.length / 2;
  5942. uvs.push( uv.x, uv.y );
  5943. return uvsHash[ hash ];
  5944. }
  5945. data.data = {};
  5946. data.data.vertices = vertices;
  5947. data.data.normals = normals;
  5948. if ( colors.length > 0 ) data.data.colors = colors;
  5949. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  5950. data.data.faces = faces;
  5951. return data;
  5952. },
  5953. clone: function () {
  5954. return new THREE.Geometry().copy( this );
  5955. },
  5956. copy: function ( source ) {
  5957. this.vertices = [];
  5958. this.faces = [];
  5959. this.faceVertexUvs = [ [] ];
  5960. var vertices = source.vertices;
  5961. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5962. this.vertices.push( vertices[ i ].clone() );
  5963. }
  5964. var faces = source.faces;
  5965. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  5966. this.faces.push( faces[ i ].clone() );
  5967. }
  5968. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  5969. var faceVertexUvs = source.faceVertexUvs[ i ];
  5970. if ( this.faceVertexUvs[ i ] === undefined ) {
  5971. this.faceVertexUvs[ i ] = [];
  5972. }
  5973. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  5974. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  5975. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  5976. var uv = uvs[ k ];
  5977. uvsCopy.push( uv.clone() );
  5978. }
  5979. this.faceVertexUvs[ i ].push( uvsCopy );
  5980. }
  5981. }
  5982. return this;
  5983. },
  5984. dispose: function () {
  5985. this.dispatchEvent( { type: 'dispose' } );
  5986. },
  5987. // Backwards compatibility
  5988. set groupsNeedUpdate ( value ) {
  5989. if ( value === true ) this.dispose();
  5990. }
  5991. };
  5992. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  5993. THREE.GeometryIdCount = 0;
  5994. // File:src/core/DirectGeometry.js
  5995. /**
  5996. * @author mrdoob / http://mrdoob.com/
  5997. */
  5998. THREE.DirectGeometry = function () {
  5999. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6000. this.uuid = THREE.Math.generateUUID();
  6001. this.name = '';
  6002. this.type = 'DirectGeometry';
  6003. this.indices = [];
  6004. this.vertices = [];
  6005. this.normals = [];
  6006. this.colors = [];
  6007. this.uvs = [];
  6008. this.uvs2 = [];
  6009. this.tangents = [];
  6010. this.morphTargets = {};
  6011. this.skinWeights = [];
  6012. this.skinIndices = [];
  6013. // this.lineDistances = [];
  6014. this.boundingBox = null;
  6015. this.boundingSphere = null;
  6016. // update flags
  6017. this.verticesNeedUpdate = false;
  6018. this.normalsNeedUpdate = false;
  6019. this.colorsNeedUpdate = false;
  6020. this.uvsNeedUpdate = false;
  6021. this.tangentsNeedUpdate = false;
  6022. };
  6023. THREE.DirectGeometry.prototype = {
  6024. constructor: THREE.DirectGeometry,
  6025. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6026. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6027. computeFaceNormals: function () {
  6028. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6029. return this;
  6030. },
  6031. computeVertexNormals: function () {
  6032. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6033. return this;
  6034. },
  6035. computeTangents: function () {
  6036. console.warn( 'THREE.DirectGeometry: computeTangents() is not a method of this type of geometry.' );
  6037. return this;
  6038. },
  6039. fromGeometry: function ( geometry ) {
  6040. var faces = geometry.faces;
  6041. var vertices = geometry.vertices;
  6042. var faceVertexUvs = geometry.faceVertexUvs;
  6043. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6044. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6045. var hasTangents = geometry.hasTangents;
  6046. // morphs
  6047. var morphTargets = geometry.morphTargets;
  6048. var morphTargetsLength = morphTargets.length;
  6049. if ( morphTargetsLength > 0 ) {
  6050. var morphTargetsPosition = [];
  6051. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6052. morphTargetsPosition[ i ] = [];
  6053. }
  6054. this.morphTargets.position = morphTargetsPosition;
  6055. }
  6056. var morphNormals = geometry.morphNormals;
  6057. var morphNormalsLength = morphNormals.length;
  6058. if ( morphNormalsLength > 0 ) {
  6059. var morphTargetsNormal = [];
  6060. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6061. morphTargetsNormal[ i ] = [];
  6062. }
  6063. this.morphTargets.normal = morphTargetsNormal;
  6064. }
  6065. // skins
  6066. var skinIndices = geometry.skinIndices;
  6067. var skinWeights = geometry.skinWeights;
  6068. var hasSkinIndices = skinIndices.length === vertices.length;
  6069. var hasSkinWeights = skinWeights.length === vertices.length;
  6070. //
  6071. for ( var i = 0; i < faces.length; i ++ ) {
  6072. var face = faces[ i ];
  6073. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6074. var vertexNormals = face.vertexNormals;
  6075. if ( vertexNormals.length === 3 ) {
  6076. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6077. } else {
  6078. var normal = face.normal;
  6079. this.normals.push( normal, normal, normal );
  6080. }
  6081. var vertexColors = face.vertexColors;
  6082. if ( vertexColors.length === 3 ) {
  6083. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6084. } else {
  6085. var color = face.color;
  6086. this.colors.push( color, color, color );
  6087. }
  6088. if ( hasFaceVertexUv === true ) {
  6089. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6090. if ( vertexUvs !== undefined ) {
  6091. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6092. } else {
  6093. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6094. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6095. }
  6096. }
  6097. if ( hasFaceVertexUv2 === true ) {
  6098. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6099. if ( vertexUvs !== undefined ) {
  6100. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6101. } else {
  6102. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6103. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6104. }
  6105. }
  6106. if ( hasTangents === true ) {
  6107. var vertexTangents = face.vertexTangents;
  6108. if ( vertexTangents.length === 3 ) {
  6109. this.tangents.push( vertexTangents[ 0 ], vertexTangents[ 1 ], vertexTangents[ 2 ] );
  6110. } else {
  6111. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined tangents ', i );
  6112. this.tangents.push( new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4() );
  6113. }
  6114. }
  6115. // morphs
  6116. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6117. var morphTarget = morphTargets[ j ].vertices;
  6118. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6119. }
  6120. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6121. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6122. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6123. }
  6124. // skins
  6125. if ( hasSkinIndices ) {
  6126. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6127. }
  6128. if ( hasSkinWeights ) {
  6129. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6130. }
  6131. }
  6132. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6133. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6134. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6135. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6136. this.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6137. return this;
  6138. },
  6139. dispose: function () {
  6140. this.dispatchEvent( { type: 'dispose' } );
  6141. }
  6142. };
  6143. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6144. // File:src/core/BufferGeometry.js
  6145. /**
  6146. * @author alteredq / http://alteredqualia.com/
  6147. * @author mrdoob / http://mrdoob.com/
  6148. */
  6149. THREE.BufferGeometry = function () {
  6150. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6151. this.uuid = THREE.Math.generateUUID();
  6152. this.name = '';
  6153. this.type = 'BufferGeometry';
  6154. this.attributes = {};
  6155. this.morphAttributes = {};
  6156. this.drawcalls = [];
  6157. this.boundingBox = null;
  6158. this.boundingSphere = null;
  6159. };
  6160. THREE.BufferGeometry.prototype = {
  6161. constructor: THREE.BufferGeometry,
  6162. addAttribute: function ( name, attribute ) {
  6163. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6164. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6165. this.attributes[ name ] = { array: arguments[ 1 ], itemSize: arguments[ 2 ] };
  6166. return;
  6167. }
  6168. this.attributes[ name ] = attribute;
  6169. },
  6170. getAttribute: function ( name ) {
  6171. return this.attributes[ name ];
  6172. },
  6173. removeAttribute: function ( name ) {
  6174. delete this.attributes[ name ];
  6175. },
  6176. get offsets() {
  6177. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .drawcalls.' );
  6178. return this.drawcalls;
  6179. },
  6180. addDrawCall: function ( start, count, indexOffset ) {
  6181. this.drawcalls.push( {
  6182. start: start,
  6183. count: count,
  6184. index: indexOffset !== undefined ? indexOffset : 0
  6185. } );
  6186. },
  6187. clearDrawCalls: function () {
  6188. this.drawcalls = [];
  6189. },
  6190. applyMatrix: function ( matrix ) {
  6191. var position = this.attributes.position;
  6192. if ( position !== undefined ) {
  6193. matrix.applyToVector3Array( position.array );
  6194. position.needsUpdate = true;
  6195. }
  6196. var normal = this.attributes.normal;
  6197. if ( normal !== undefined ) {
  6198. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6199. normalMatrix.applyToVector3Array( normal.array );
  6200. normal.needsUpdate = true;
  6201. }
  6202. if ( this.boundingBox !== null ) {
  6203. this.computeBoundingBox();
  6204. }
  6205. if ( this.boundingSphere !== null ) {
  6206. this.computeBoundingSphere();
  6207. }
  6208. },
  6209. center: function () {
  6210. this.computeBoundingBox();
  6211. var offset = this.boundingBox.center().negate();
  6212. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  6213. return offset;
  6214. },
  6215. setFromObject: function ( object ) {
  6216. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6217. var geometry = object.geometry;
  6218. if ( object instanceof THREE.PointCloud || object instanceof THREE.Line ) {
  6219. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6220. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6221. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6222. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6223. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6224. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6225. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6226. }
  6227. if ( geometry.boundingSphere !== null ) {
  6228. this.boundingSphere = geometry.boundingSphere.clone();
  6229. }
  6230. if ( geometry.boundingBox !== null ) {
  6231. this.boundingBox = geometry.boundingBox.clone();
  6232. }
  6233. } else if ( object instanceof THREE.Mesh ) {
  6234. if ( geometry instanceof THREE.Geometry ) {
  6235. this.fromGeometry( geometry );
  6236. }
  6237. }
  6238. return this;
  6239. },
  6240. updateFromObject: function ( object ) {
  6241. var geometry = object.geometry;
  6242. if ( object instanceof THREE.Mesh ) {
  6243. var direct = geometry.__directGeometry;
  6244. if ( direct === undefined ) {
  6245. return this.fromGeometry( geometry );
  6246. }
  6247. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6248. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6249. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6250. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6251. direct.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6252. geometry.verticesNeedUpdate = false;
  6253. geometry.normalsNeedUpdate = false;
  6254. geometry.colorsNeedUpdate = false;
  6255. geometry.uvsNeedUpdate = false;
  6256. geometry.tangentsNeedUpdate = false;
  6257. geometry = direct;
  6258. }
  6259. if ( geometry.verticesNeedUpdate === true ) {
  6260. var attribute = this.attributes.position;
  6261. if ( attribute !== undefined ) {
  6262. attribute.copyVector3sArray( geometry.vertices );
  6263. attribute.needsUpdate = true;
  6264. }
  6265. geometry.verticesNeedUpdate = false;
  6266. }
  6267. if ( geometry.normalsNeedUpdate === true ) {
  6268. var attribute = this.attributes.normal;
  6269. if ( attribute !== undefined ) {
  6270. attribute.copyVector3sArray( geometry.normals );
  6271. attribute.needsUpdate = true;
  6272. }
  6273. geometry.normalsNeedUpdate = false;
  6274. }
  6275. if ( geometry.colorsNeedUpdate === true ) {
  6276. var attribute = this.attributes.color;
  6277. if ( attribute !== undefined ) {
  6278. attribute.copyColorsArray( geometry.colors );
  6279. attribute.needsUpdate = true;
  6280. }
  6281. geometry.colorsNeedUpdate = false;
  6282. }
  6283. if ( geometry.tangentsNeedUpdate === true ) {
  6284. var attribute = this.attributes.tangent;
  6285. if ( attribute !== undefined ) {
  6286. attribute.copyVector4sArray( geometry.tangents );
  6287. attribute.needsUpdate = true;
  6288. }
  6289. geometry.tangentsNeedUpdate = false;
  6290. }
  6291. if ( geometry.lineDistancesNeedUpdate ) {
  6292. var attribute = this.attributes.lineDistance;
  6293. if ( attribute !== undefined ) {
  6294. attribute.copyArray( geometry.lineDistances );
  6295. attribute.needsUpdate = true;
  6296. }
  6297. geometry.lineDistancesNeedUpdate = false;
  6298. }
  6299. return this;
  6300. },
  6301. fromGeometry: function ( geometry ) {
  6302. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6303. return this.fromDirectGeometry( geometry.__directGeometry );
  6304. },
  6305. fromDirectGeometry: function ( geometry ) {
  6306. var positions = new Float32Array( geometry.vertices.length * 3 );
  6307. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6308. if ( geometry.normals.length > 0 ) {
  6309. var normals = new Float32Array( geometry.normals.length * 3 );
  6310. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6311. }
  6312. if ( geometry.colors.length > 0 ) {
  6313. var colors = new Float32Array( geometry.colors.length * 3 );
  6314. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6315. }
  6316. if ( geometry.uvs.length > 0 ) {
  6317. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6318. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6319. }
  6320. if ( geometry.uvs2.length > 0 ) {
  6321. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6322. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6323. }
  6324. if ( geometry.tangents.length > 0 ) {
  6325. var tangents = new Float32Array( geometry.tangents.length * 4 );
  6326. this.addAttribute( 'tangent', new THREE.BufferAttribute( tangents, 4 ).copyVector4sArray( geometry.tangents ) );
  6327. }
  6328. if ( geometry.indices.length > 0 ) {
  6329. var indices = new Uint16Array( geometry.indices.length * 3 );
  6330. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6331. }
  6332. // morphs
  6333. for ( var name in geometry.morphTargets ) {
  6334. var array = [];
  6335. var morphTargets = geometry.morphTargets[ name ];
  6336. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6337. var morphTarget = morphTargets[ i ];
  6338. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6339. array.push( attribute.copyVector3sArray( morphTarget ) );
  6340. }
  6341. this.morphAttributes[ name ] = array;
  6342. }
  6343. // skinning
  6344. if ( geometry.skinIndices.length > 0 ) {
  6345. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6346. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6347. }
  6348. if ( geometry.skinWeights.length > 0 ) {
  6349. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6350. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6351. }
  6352. //
  6353. if ( geometry.boundingSphere !== null ) {
  6354. this.boundingSphere = geometry.boundingSphere.clone();
  6355. }
  6356. if ( geometry.boundingBox !== null ) {
  6357. this.boundingBox = geometry.boundingBox.clone();
  6358. }
  6359. return this;
  6360. },
  6361. computeBoundingBox: function () {
  6362. var vector = new THREE.Vector3();
  6363. return function () {
  6364. if ( this.boundingBox === null ) {
  6365. this.boundingBox = new THREE.Box3();
  6366. }
  6367. var positions = this.attributes.position.array;
  6368. if ( positions ) {
  6369. var bb = this.boundingBox;
  6370. bb.makeEmpty();
  6371. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6372. vector.fromArray( positions, i );
  6373. bb.expandByPoint( vector );
  6374. }
  6375. }
  6376. if ( positions === undefined || positions.length === 0 ) {
  6377. this.boundingBox.min.set( 0, 0, 0 );
  6378. this.boundingBox.max.set( 0, 0, 0 );
  6379. }
  6380. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6381. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6382. }
  6383. };
  6384. }(),
  6385. computeBoundingSphere: function () {
  6386. var box = new THREE.Box3();
  6387. var vector = new THREE.Vector3();
  6388. return function () {
  6389. if ( this.boundingSphere === null ) {
  6390. this.boundingSphere = new THREE.Sphere();
  6391. }
  6392. var positions = this.attributes.position.array;
  6393. if ( positions ) {
  6394. box.makeEmpty();
  6395. var center = this.boundingSphere.center;
  6396. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6397. vector.fromArray( positions, i );
  6398. box.expandByPoint( vector );
  6399. }
  6400. box.center( center );
  6401. // hoping to find a boundingSphere with a radius smaller than the
  6402. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6403. var maxRadiusSq = 0;
  6404. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6405. vector.fromArray( positions, i );
  6406. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6407. }
  6408. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6409. if ( isNaN( this.boundingSphere.radius ) ) {
  6410. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6411. }
  6412. }
  6413. };
  6414. }(),
  6415. computeFaceNormals: function () {
  6416. // backwards compatibility
  6417. },
  6418. computeVertexNormals: function () {
  6419. var attributes = this.attributes;
  6420. if ( attributes.position ) {
  6421. var positions = attributes.position.array;
  6422. if ( attributes.normal === undefined ) {
  6423. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6424. } else {
  6425. // reset existing normals to zero
  6426. var normals = attributes.normal.array;
  6427. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6428. normals[ i ] = 0;
  6429. }
  6430. }
  6431. var normals = attributes.normal.array;
  6432. var vA, vB, vC,
  6433. pA = new THREE.Vector3(),
  6434. pB = new THREE.Vector3(),
  6435. pC = new THREE.Vector3(),
  6436. cb = new THREE.Vector3(),
  6437. ab = new THREE.Vector3();
  6438. // indexed elements
  6439. if ( attributes.index ) {
  6440. var indices = attributes.index.array;
  6441. if ( this.drawcalls.length === 0 ) {
  6442. this.addDrawCall( 0, indices.length );
  6443. }
  6444. for ( var j = 0, jl = this.drawcalls.length; j < jl; ++ j ) {
  6445. var start = this.drawcalls[ j ].start;
  6446. var count = this.drawcalls[ j ].count;
  6447. var index = this.drawcalls[ j ].index;
  6448. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6449. vA = ( index + indices[ i ] ) * 3;
  6450. vB = ( index + indices[ i + 1 ] ) * 3;
  6451. vC = ( index + indices[ i + 2 ] ) * 3;
  6452. pA.fromArray( positions, vA );
  6453. pB.fromArray( positions, vB );
  6454. pC.fromArray( positions, vC );
  6455. cb.subVectors( pC, pB );
  6456. ab.subVectors( pA, pB );
  6457. cb.cross( ab );
  6458. normals[ vA ] += cb.x;
  6459. normals[ vA + 1 ] += cb.y;
  6460. normals[ vA + 2 ] += cb.z;
  6461. normals[ vB ] += cb.x;
  6462. normals[ vB + 1 ] += cb.y;
  6463. normals[ vB + 2 ] += cb.z;
  6464. normals[ vC ] += cb.x;
  6465. normals[ vC + 1 ] += cb.y;
  6466. normals[ vC + 2 ] += cb.z;
  6467. }
  6468. }
  6469. } else {
  6470. // non-indexed elements (unconnected triangle soup)
  6471. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6472. pA.fromArray( positions, i );
  6473. pB.fromArray( positions, i + 3 );
  6474. pC.fromArray( positions, i + 6 );
  6475. cb.subVectors( pC, pB );
  6476. ab.subVectors( pA, pB );
  6477. cb.cross( ab );
  6478. normals[ i ] = cb.x;
  6479. normals[ i + 1 ] = cb.y;
  6480. normals[ i + 2 ] = cb.z;
  6481. normals[ i + 3 ] = cb.x;
  6482. normals[ i + 4 ] = cb.y;
  6483. normals[ i + 5 ] = cb.z;
  6484. normals[ i + 6 ] = cb.x;
  6485. normals[ i + 7 ] = cb.y;
  6486. normals[ i + 8 ] = cb.z;
  6487. }
  6488. }
  6489. this.normalizeNormals();
  6490. attributes.normal.needsUpdate = true;
  6491. }
  6492. },
  6493. computeTangents: function () {
  6494. // based on http://www.terathon.com/code/tangent.html
  6495. // (per vertex tangents)
  6496. if ( this.attributes.index === undefined ||
  6497. this.attributes.position === undefined ||
  6498. this.attributes.normal === undefined ||
  6499. this.attributes.uv === undefined ) {
  6500. console.warn( 'THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()' );
  6501. return;
  6502. }
  6503. var indices = this.attributes.index.array;
  6504. var positions = this.attributes.position.array;
  6505. var normals = this.attributes.normal.array;
  6506. var uvs = this.attributes.uv.array;
  6507. var nVertices = positions.length / 3;
  6508. if ( this.attributes.tangent === undefined ) {
  6509. this.addAttribute( 'tangent', new THREE.BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  6510. }
  6511. var tangents = this.attributes.tangent.array;
  6512. var tan1 = [], tan2 = [];
  6513. for ( var k = 0; k < nVertices; k ++ ) {
  6514. tan1[ k ] = new THREE.Vector3();
  6515. tan2[ k ] = new THREE.Vector3();
  6516. }
  6517. var vA = new THREE.Vector3(),
  6518. vB = new THREE.Vector3(),
  6519. vC = new THREE.Vector3(),
  6520. uvA = new THREE.Vector2(),
  6521. uvB = new THREE.Vector2(),
  6522. uvC = new THREE.Vector2(),
  6523. x1, x2, y1, y2, z1, z2,
  6524. s1, s2, t1, t2, r;
  6525. var sdir = new THREE.Vector3(), tdir = new THREE.Vector3();
  6526. function handleTriangle( a, b, c ) {
  6527. vA.fromArray( positions, a * 3 );
  6528. vB.fromArray( positions, b * 3 );
  6529. vC.fromArray( positions, c * 3 );
  6530. uvA.fromArray( uvs, a * 2 );
  6531. uvB.fromArray( uvs, b * 2 );
  6532. uvC.fromArray( uvs, c * 2 );
  6533. x1 = vB.x - vA.x;
  6534. x2 = vC.x - vA.x;
  6535. y1 = vB.y - vA.y;
  6536. y2 = vC.y - vA.y;
  6537. z1 = vB.z - vA.z;
  6538. z2 = vC.z - vA.z;
  6539. s1 = uvB.x - uvA.x;
  6540. s2 = uvC.x - uvA.x;
  6541. t1 = uvB.y - uvA.y;
  6542. t2 = uvC.y - uvA.y;
  6543. r = 1.0 / ( s1 * t2 - s2 * t1 );
  6544. sdir.set(
  6545. ( t2 * x1 - t1 * x2 ) * r,
  6546. ( t2 * y1 - t1 * y2 ) * r,
  6547. ( t2 * z1 - t1 * z2 ) * r
  6548. );
  6549. tdir.set(
  6550. ( s1 * x2 - s2 * x1 ) * r,
  6551. ( s1 * y2 - s2 * y1 ) * r,
  6552. ( s1 * z2 - s2 * z1 ) * r
  6553. );
  6554. tan1[ a ].add( sdir );
  6555. tan1[ b ].add( sdir );
  6556. tan1[ c ].add( sdir );
  6557. tan2[ a ].add( tdir );
  6558. tan2[ b ].add( tdir );
  6559. tan2[ c ].add( tdir );
  6560. }
  6561. var i, il;
  6562. var j, jl;
  6563. var iA, iB, iC;
  6564. if ( this.drawcalls.length === 0 ) {
  6565. this.addDrawCall( 0, indices.length );
  6566. }
  6567. var drawcalls = this.drawcalls;
  6568. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6569. var start = drawcalls[ j ].start;
  6570. var count = drawcalls[ j ].count;
  6571. var index = drawcalls[ j ].index;
  6572. for ( i = start, il = start + count; i < il; i += 3 ) {
  6573. iA = index + indices[ i ];
  6574. iB = index + indices[ i + 1 ];
  6575. iC = index + indices[ i + 2 ];
  6576. handleTriangle( iA, iB, iC );
  6577. }
  6578. }
  6579. var tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3();
  6580. var n = new THREE.Vector3(), n2 = new THREE.Vector3();
  6581. var w, t, test;
  6582. function handleVertex( v ) {
  6583. n.fromArray( normals, v * 3 );
  6584. n2.copy( n );
  6585. t = tan1[ v ];
  6586. // Gram-Schmidt orthogonalize
  6587. tmp.copy( t );
  6588. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6589. // Calculate handedness
  6590. tmp2.crossVectors( n2, t );
  6591. test = tmp2.dot( tan2[ v ] );
  6592. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6593. tangents[ v * 4 ] = tmp.x;
  6594. tangents[ v * 4 + 1 ] = tmp.y;
  6595. tangents[ v * 4 + 2 ] = tmp.z;
  6596. tangents[ v * 4 + 3 ] = w;
  6597. }
  6598. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6599. var start = drawcalls[ j ].start;
  6600. var count = drawcalls[ j ].count;
  6601. var index = drawcalls[ j ].index;
  6602. for ( i = start, il = start + count; i < il; i += 3 ) {
  6603. iA = index + indices[ i ];
  6604. iB = index + indices[ i + 1 ];
  6605. iC = index + indices[ i + 2 ];
  6606. handleVertex( iA );
  6607. handleVertex( iB );
  6608. handleVertex( iC );
  6609. }
  6610. }
  6611. },
  6612. /*
  6613. Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
  6614. This method will effectively rewrite the index buffer and remap all attributes to match the new indices.
  6615. WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
  6616. size - Defaults to 65535 or 4294967296 if extension OES_element_index_uint supported, but allows for larger or smaller chunks.
  6617. */
  6618. computeOffsets: function ( size ) {
  6619. if ( size === undefined ) size = THREE.BufferGeometry.MaxIndex;
  6620. var indices = this.attributes.index.array;
  6621. var vertices = this.attributes.position.array;
  6622. var facesCount = ( indices.length / 3 );
  6623. var UintArray = ( ( vertices.length / 3 ) > 65535 && THREE.BufferGeometry.MaxIndex > 65535 ) ? Uint32Array : Uint16Array;
  6624. /*
  6625. console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
  6626. console.log("Faces to process: "+(indices.length/3));
  6627. console.log("Reordering "+verticesCount+" vertices.");
  6628. */
  6629. var sortedIndices = new UintArray( indices.length );
  6630. var indexPtr = 0;
  6631. var vertexPtr = 0;
  6632. var tmpOffsets = [ { start: 0, count: 0, index: 0 } ];
  6633. var offset = tmpOffsets[ 0 ];
  6634. var duplicatedVertices = 0;
  6635. var newVerticeMaps = 0;
  6636. var faceVertices = new Int32Array( 6 );
  6637. var vertexMap = new Int32Array( vertices.length );
  6638. var revVertexMap = new Int32Array( vertices.length );
  6639. for ( var j = 0; j < vertices.length; j ++ ) {
  6640. vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1;
  6641. }
  6642. /*
  6643. Traverse every face and reorder vertices in the proper offsets of 65k.
  6644. We can have more than 'size' entries in the index buffer per offset, but only reference 'size' values.
  6645. */
  6646. for ( var findex = 0; findex < facesCount; findex ++ ) {
  6647. newVerticeMaps = 0;
  6648. for ( var vo = 0; vo < 3; vo ++ ) {
  6649. var vid = indices[ findex * 3 + vo ];
  6650. if ( vertexMap[ vid ] === - 1 ) {
  6651. //Unmapped vertex
  6652. faceVertices[ vo * 2 ] = vid;
  6653. faceVertices[ vo * 2 + 1 ] = - 1;
  6654. newVerticeMaps ++;
  6655. } else if ( vertexMap[ vid ] < offset.index ) {
  6656. //Reused vertices from previous block (duplicate)
  6657. faceVertices[ vo * 2 ] = vid;
  6658. faceVertices[ vo * 2 + 1 ] = - 1;
  6659. duplicatedVertices ++;
  6660. } else {
  6661. //Reused vertex in the current block
  6662. faceVertices[ vo * 2 ] = vid;
  6663. faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
  6664. }
  6665. }
  6666. var faceMax = vertexPtr + newVerticeMaps;
  6667. if ( faceMax > ( offset.index + size ) ) {
  6668. var new_offset = { start: indexPtr, count: 0, index: vertexPtr };
  6669. tmpOffsets.push( new_offset );
  6670. offset = new_offset;
  6671. //Re-evaluate reused vertices in light of new offset.
  6672. for ( var v = 0; v < 6; v += 2 ) {
  6673. var new_vid = faceVertices[ v + 1 ];
  6674. if ( new_vid > - 1 && new_vid < offset.index )
  6675. faceVertices[ v + 1 ] = - 1;
  6676. }
  6677. }
  6678. //Reindex the face.
  6679. for ( var v = 0; v < 6; v += 2 ) {
  6680. var vid = faceVertices[ v ];
  6681. var new_vid = faceVertices[ v + 1 ];
  6682. if ( new_vid === - 1 )
  6683. new_vid = vertexPtr ++;
  6684. vertexMap[ vid ] = new_vid;
  6685. revVertexMap[ new_vid ] = vid;
  6686. sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
  6687. offset.count ++;
  6688. }
  6689. }
  6690. /* Move all attribute values to map to the new computed indices , also expand the vertex stack to match our new vertexPtr. */
  6691. this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
  6692. this.clearDrawCalls();
  6693. for ( var i = 0; i < tmpOffsets.length; i ++ ) {
  6694. var tmpOffset = tmpOffsets[ i ];
  6695. this.addDrawCall( tmpOffset.start, tmpOffset.count, tmpOffset.index );
  6696. }
  6697. /*
  6698. var orderTime = Date.now();
  6699. console.log("Reorder time: "+(orderTime-s)+"ms");
  6700. console.log("Duplicated "+duplicatedVertices+" vertices.");
  6701. console.log("Compute Buffers time: "+(Date.now()-s)+"ms");
  6702. console.log("Draw tmpOffsets: "+tmpOffsets.length);
  6703. */
  6704. },
  6705. merge: function ( geometry, offset ) {
  6706. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6707. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6708. return;
  6709. }
  6710. if ( offset === undefined ) offset = 0;
  6711. var attributes = this.attributes;
  6712. for ( var key in attributes ) {
  6713. if ( geometry.attributes[ key ] === undefined ) continue;
  6714. var attribute1 = attributes[ key ];
  6715. var attributeArray1 = attribute1.array;
  6716. var attribute2 = geometry.attributes[ key ];
  6717. var attributeArray2 = attribute2.array;
  6718. var attributeSize = attribute2.itemSize;
  6719. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6720. attributeArray1[ j ] = attributeArray2[ i ];
  6721. }
  6722. }
  6723. return this;
  6724. },
  6725. normalizeNormals: function () {
  6726. var normals = this.attributes.normal.array;
  6727. var x, y, z, n;
  6728. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6729. x = normals[ i ];
  6730. y = normals[ i + 1 ];
  6731. z = normals[ i + 2 ];
  6732. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6733. normals[ i ] *= n;
  6734. normals[ i + 1 ] *= n;
  6735. normals[ i + 2 ] *= n;
  6736. }
  6737. },
  6738. /*
  6739. reoderBuffers:
  6740. Reorder attributes based on a new indexBuffer and indexMap.
  6741. indexBuffer - Uint16Array of the new ordered indices.
  6742. indexMap - Int32Array where the position is the new vertex ID and the value the old vertex ID for each vertex.
  6743. vertexCount - Amount of total vertices considered in this reordering (in case you want to grow the vertex stack).
  6744. */
  6745. reorderBuffers: function ( indexBuffer, indexMap, vertexCount ) {
  6746. /* Create a copy of all attributes for reordering. */
  6747. var sortedAttributes = {};
  6748. for ( var attr in this.attributes ) {
  6749. if ( attr === 'index' )
  6750. continue;
  6751. var sourceArray = this.attributes[ attr ].array;
  6752. sortedAttributes[ attr ] = new sourceArray.constructor( this.attributes[ attr ].itemSize * vertexCount );
  6753. }
  6754. /* Move attribute positions based on the new index map */
  6755. for ( var new_vid = 0; new_vid < vertexCount; new_vid ++ ) {
  6756. var vid = indexMap[ new_vid ];
  6757. for ( var attr in this.attributes ) {
  6758. if ( attr === 'index' )
  6759. continue;
  6760. var attrArray = this.attributes[ attr ].array;
  6761. var attrSize = this.attributes[ attr ].itemSize;
  6762. var sortedAttr = sortedAttributes[ attr ];
  6763. for ( var k = 0; k < attrSize; k ++ )
  6764. sortedAttr[ new_vid * attrSize + k ] = attrArray[ vid * attrSize + k ];
  6765. }
  6766. }
  6767. /* Carry the new sorted buffers locally */
  6768. this.attributes[ 'index' ].array = indexBuffer;
  6769. for ( var attr in this.attributes ) {
  6770. if ( attr === 'index' )
  6771. continue;
  6772. this.attributes[ attr ].array = sortedAttributes[ attr ];
  6773. this.attributes[ attr ].numItems = this.attributes[ attr ].itemSize * vertexCount;
  6774. }
  6775. },
  6776. toJSON: function () {
  6777. var data = {
  6778. metadata: {
  6779. version: 4.4,
  6780. type: 'BufferGeometry',
  6781. generator: 'BufferGeometry.toJSON'
  6782. }
  6783. };
  6784. // standard BufferGeometry serialization
  6785. data.uuid = this.uuid;
  6786. data.type = this.type;
  6787. if ( this.name !== '' ) data.name = this.name;
  6788. if ( this.parameters !== undefined ) {
  6789. var parameters = this.parameters;
  6790. for ( var key in parameters ) {
  6791. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6792. }
  6793. return data;
  6794. }
  6795. data.data = { attributes: {} };
  6796. var attributes = this.attributes;
  6797. var drawcalls = this.drawcalls;
  6798. var boundingSphere = this.boundingSphere;
  6799. for ( var key in attributes ) {
  6800. var attribute = attributes[ key ];
  6801. var array = Array.prototype.slice.call( attribute.array );
  6802. data.data.attributes[ key ] = {
  6803. itemSize: attribute.itemSize,
  6804. type: attribute.array.constructor.name,
  6805. array: array
  6806. };
  6807. }
  6808. if ( drawcalls.length > 0 ) {
  6809. data.data.drawcalls = JSON.parse( JSON.stringify( drawcalls ) );
  6810. }
  6811. if ( boundingSphere !== null ) {
  6812. data.data.boundingSphere = {
  6813. center: boundingSphere.center.toArray(),
  6814. radius: boundingSphere.radius
  6815. };
  6816. }
  6817. return data;
  6818. },
  6819. clone: function () {
  6820. return new THREE.BufferGeometry().copy( this );
  6821. },
  6822. copy: function ( source ) {
  6823. for ( var attr in source.attributes ) {
  6824. var sourceAttr = source.attributes[ attr ];
  6825. this.addAttribute( attr, sourceAttr.clone() );
  6826. }
  6827. for ( var i = 0, il = source.drawcalls.length; i < il; i ++ ) {
  6828. var offset = source.drawcalls[ i ];
  6829. this.addDrawCall( offset.start, offset.count, offset.index );
  6830. }
  6831. return this;
  6832. },
  6833. dispose: function () {
  6834. this.dispatchEvent( { type: 'dispose' } );
  6835. }
  6836. };
  6837. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6838. THREE.BufferGeometry.MaxIndex = 65535;
  6839. // File:src/core/InstancedBufferGeometry.js
  6840. /**
  6841. * @author benaadams / https://twitter.com/ben_a_adams
  6842. */
  6843. THREE.InstancedBufferGeometry = function () {
  6844. THREE.BufferGeometry.call( this );
  6845. this.type = 'InstancedBufferGeometry';
  6846. this.maxInstancedCount = undefined;
  6847. };
  6848. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6849. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6850. THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset, instances ) {
  6851. this.drawcalls.push( {
  6852. start: start,
  6853. count: count,
  6854. index: indexOffset !== undefined ? indexOffset : 0,
  6855. instances: instances
  6856. } );
  6857. },
  6858. THREE.InstancedBufferGeometry.prototype.clone = function () {
  6859. var geometry = new THREE.InstancedBufferGeometry();
  6860. for ( var attr in this.attributes ) {
  6861. var sourceAttr = this.attributes[ attr ];
  6862. geometry.addAttribute( attr, sourceAttr.clone() );
  6863. }
  6864. for ( var i = 0, il = this.drawcalls.length; i < il; i ++ ) {
  6865. var offset = this.drawcalls[ i ];
  6866. geometry.addDrawCall( offset.start, offset.count, offset.index, offset.instances );
  6867. }
  6868. return geometry;
  6869. };
  6870. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6871. // File:src/cameras/Camera.js
  6872. /**
  6873. * @author mrdoob / http://mrdoob.com/
  6874. * @author mikael emtinger / http://gomo.se/
  6875. * @author WestLangley / http://github.com/WestLangley
  6876. */
  6877. THREE.Camera = function () {
  6878. THREE.Object3D.call( this );
  6879. this.type = 'Camera';
  6880. this.matrixWorldInverse = new THREE.Matrix4();
  6881. this.projectionMatrix = new THREE.Matrix4();
  6882. };
  6883. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  6884. THREE.Camera.prototype.constructor = THREE.Camera;
  6885. THREE.Camera.prototype.getWorldDirection = function () {
  6886. var quaternion = new THREE.Quaternion();
  6887. return function ( optionalTarget ) {
  6888. var result = optionalTarget || new THREE.Vector3();
  6889. this.getWorldQuaternion( quaternion );
  6890. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  6891. };
  6892. }();
  6893. THREE.Camera.prototype.lookAt = function () {
  6894. // This routine does not support cameras with rotated and/or translated parent(s)
  6895. var m1 = new THREE.Matrix4();
  6896. return function ( vector ) {
  6897. m1.lookAt( this.position, vector, this.up );
  6898. this.quaternion.setFromRotationMatrix( m1 );
  6899. };
  6900. }();
  6901. THREE.Camera.prototype.clone = function () {
  6902. var camera = new THREE.Camera();
  6903. return camera.copy( this );
  6904. };
  6905. THREE.Camera.prototype.copy = function ( source ) {
  6906. THREE.Object3D.prototype.copy.call( this, source );
  6907. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  6908. this.projectionMatrix.copy( source.projectionMatrix );
  6909. return this;
  6910. };
  6911. // File:src/cameras/CubeCamera.js
  6912. /**
  6913. * Camera for rendering cube maps
  6914. * - renders scene into axis-aligned cube
  6915. *
  6916. * @author alteredq / http://alteredqualia.com/
  6917. */
  6918. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  6919. THREE.Object3D.call( this );
  6920. this.type = 'CubeCamera';
  6921. var fov = 90, aspect = 1;
  6922. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6923. cameraPX.up.set( 0, - 1, 0 );
  6924. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  6925. this.add( cameraPX );
  6926. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6927. cameraNX.up.set( 0, - 1, 0 );
  6928. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  6929. this.add( cameraNX );
  6930. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6931. cameraPY.up.set( 0, 0, 1 );
  6932. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  6933. this.add( cameraPY );
  6934. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6935. cameraNY.up.set( 0, 0, - 1 );
  6936. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  6937. this.add( cameraNY );
  6938. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6939. cameraPZ.up.set( 0, - 1, 0 );
  6940. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  6941. this.add( cameraPZ );
  6942. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6943. cameraNZ.up.set( 0, - 1, 0 );
  6944. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  6945. this.add( cameraNZ );
  6946. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  6947. this.updateCubeMap = function ( renderer, scene ) {
  6948. if ( this.parent === undefined ) this.updateMatrixWorld();
  6949. var renderTarget = this.renderTarget;
  6950. var generateMipmaps = renderTarget.generateMipmaps;
  6951. renderTarget.generateMipmaps = false;
  6952. renderTarget.activeCubeFace = 0;
  6953. renderer.render( scene, cameraPX, renderTarget );
  6954. renderTarget.activeCubeFace = 1;
  6955. renderer.render( scene, cameraNX, renderTarget );
  6956. renderTarget.activeCubeFace = 2;
  6957. renderer.render( scene, cameraPY, renderTarget );
  6958. renderTarget.activeCubeFace = 3;
  6959. renderer.render( scene, cameraNY, renderTarget );
  6960. renderTarget.activeCubeFace = 4;
  6961. renderer.render( scene, cameraPZ, renderTarget );
  6962. renderTarget.generateMipmaps = generateMipmaps;
  6963. renderTarget.activeCubeFace = 5;
  6964. renderer.render( scene, cameraNZ, renderTarget );
  6965. renderer.setRenderTarget( null );
  6966. };
  6967. };
  6968. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  6969. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  6970. // File:src/cameras/OrthographicCamera.js
  6971. /**
  6972. * @author alteredq / http://alteredqualia.com/
  6973. */
  6974. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  6975. THREE.Camera.call( this );
  6976. this.type = 'OrthographicCamera';
  6977. this.zoom = 1;
  6978. this.left = left;
  6979. this.right = right;
  6980. this.top = top;
  6981. this.bottom = bottom;
  6982. this.near = ( near !== undefined ) ? near : 0.1;
  6983. this.far = ( far !== undefined ) ? far : 2000;
  6984. this.updateProjectionMatrix();
  6985. };
  6986. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  6987. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  6988. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  6989. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  6990. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  6991. var cx = ( this.right + this.left ) / 2;
  6992. var cy = ( this.top + this.bottom ) / 2;
  6993. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  6994. };
  6995. THREE.OrthographicCamera.prototype.clone = function () {
  6996. var camera = new THREE.OrthographicCamera();
  6997. camera.copy( this );
  6998. camera.zoom = this.zoom;
  6999. camera.left = this.left;
  7000. camera.right = this.right;
  7001. camera.top = this.top;
  7002. camera.bottom = this.bottom;
  7003. camera.near = this.near;
  7004. camera.far = this.far;
  7005. return camera;
  7006. };
  7007. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  7008. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7009. data.object.zoom = this.zoom;
  7010. data.object.left = this.left;
  7011. data.object.right = this.right;
  7012. data.object.top = this.top;
  7013. data.object.bottom = this.bottom;
  7014. data.object.near = this.near;
  7015. data.object.far = this.far;
  7016. return data;
  7017. };
  7018. // File:src/cameras/PerspectiveCamera.js
  7019. /**
  7020. * @author mrdoob / http://mrdoob.com/
  7021. * @author greggman / http://games.greggman.com/
  7022. * @author zz85 / http://www.lab4games.net/zz85/blog
  7023. */
  7024. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  7025. THREE.Camera.call( this );
  7026. this.type = 'PerspectiveCamera';
  7027. this.zoom = 1;
  7028. this.fov = fov !== undefined ? fov : 50;
  7029. this.aspect = aspect !== undefined ? aspect : 1;
  7030. this.near = near !== undefined ? near : 0.1;
  7031. this.far = far !== undefined ? far : 2000;
  7032. this.updateProjectionMatrix();
  7033. };
  7034. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  7035. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  7036. /**
  7037. * Uses Focal Length (in mm) to estimate and set FOV
  7038. * 35mm (full-frame) camera is used if frame size is not specified;
  7039. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  7040. */
  7041. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  7042. if ( frameHeight === undefined ) frameHeight = 24;
  7043. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  7044. this.updateProjectionMatrix();
  7045. };
  7046. /**
  7047. * Sets an offset in a larger frustum. This is useful for multi-window or
  7048. * multi-monitor/multi-machine setups.
  7049. *
  7050. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  7051. * the monitors are in grid like this
  7052. *
  7053. * +---+---+---+
  7054. * | A | B | C |
  7055. * +---+---+---+
  7056. * | D | E | F |
  7057. * +---+---+---+
  7058. *
  7059. * then for each monitor you would call it like this
  7060. *
  7061. * var w = 1920;
  7062. * var h = 1080;
  7063. * var fullWidth = w * 3;
  7064. * var fullHeight = h * 2;
  7065. *
  7066. * --A--
  7067. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7068. * --B--
  7069. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7070. * --C--
  7071. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7072. * --D--
  7073. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7074. * --E--
  7075. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7076. * --F--
  7077. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7078. *
  7079. * Note there is no reason monitors have to be the same size or in a grid.
  7080. */
  7081. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  7082. this.fullWidth = fullWidth;
  7083. this.fullHeight = fullHeight;
  7084. this.x = x;
  7085. this.y = y;
  7086. this.width = width;
  7087. this.height = height;
  7088. this.updateProjectionMatrix();
  7089. };
  7090. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  7091. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  7092. if ( this.fullWidth ) {
  7093. var aspect = this.fullWidth / this.fullHeight;
  7094. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  7095. var bottom = - top;
  7096. var left = aspect * bottom;
  7097. var right = aspect * top;
  7098. var width = Math.abs( right - left );
  7099. var height = Math.abs( top - bottom );
  7100. this.projectionMatrix.makeFrustum(
  7101. left + this.x * width / this.fullWidth,
  7102. left + ( this.x + this.width ) * width / this.fullWidth,
  7103. top - ( this.y + this.height ) * height / this.fullHeight,
  7104. top - this.y * height / this.fullHeight,
  7105. this.near,
  7106. this.far
  7107. );
  7108. } else {
  7109. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  7110. }
  7111. };
  7112. THREE.PerspectiveCamera.prototype.clone = function () {
  7113. var camera = new THREE.PerspectiveCamera();
  7114. camera.copy( this );
  7115. camera.zoom = this.zoom;
  7116. camera.fov = this.fov;
  7117. camera.aspect = this.aspect;
  7118. camera.near = this.near;
  7119. camera.far = this.far;
  7120. return camera;
  7121. };
  7122. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  7123. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7124. data.object.zoom = this.zoom;
  7125. data.object.fov = this.fov;
  7126. data.object.aspect = this.aspect;
  7127. data.object.near = this.near;
  7128. data.object.far = this.far;
  7129. return data;
  7130. };
  7131. // File:src/lights/Light.js
  7132. /**
  7133. * @author mrdoob / http://mrdoob.com/
  7134. * @author alteredq / http://alteredqualia.com/
  7135. */
  7136. THREE.Light = function ( color ) {
  7137. THREE.Object3D.call( this );
  7138. this.type = 'Light';
  7139. this.color = new THREE.Color( color );
  7140. };
  7141. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  7142. THREE.Light.prototype.constructor = THREE.Light;
  7143. THREE.Light.prototype.clone = function () {
  7144. var light = new THREE.Light();
  7145. return light.copy( this );
  7146. };
  7147. THREE.Light.prototype.copy = function ( source ) {
  7148. THREE.Object3D.prototype.copy.call( this, source );
  7149. this.color.copy( source.color );
  7150. return this;
  7151. };
  7152. // File:src/lights/AmbientLight.js
  7153. /**
  7154. * @author mrdoob / http://mrdoob.com/
  7155. */
  7156. THREE.AmbientLight = function ( color ) {
  7157. THREE.Light.call( this, color );
  7158. this.type = 'AmbientLight';
  7159. };
  7160. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  7161. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  7162. THREE.AmbientLight.prototype.clone = function () {
  7163. var light = new THREE.AmbientLight();
  7164. light.copy( this );
  7165. return light;
  7166. };
  7167. THREE.AmbientLight.prototype.toJSON = function ( meta ) {
  7168. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7169. data.object.color = this.color.getHex();
  7170. return data;
  7171. };
  7172. // File:src/lights/AreaLight.js
  7173. /**
  7174. * @author MPanknin / http://www.redplant.de/
  7175. * @author alteredq / http://alteredqualia.com/
  7176. * @author prafullit
  7177. */
  7178. THREE.AreaLight = function ( color, intensity ) {
  7179. THREE.Light.call( this, color );
  7180. this.type = 'AreaLight';
  7181. this.normal = new THREE.Vector3( 0, - 1, 0 );
  7182. this.right = new THREE.Vector3( 1, 0, 0 );
  7183. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7184. this.width = 1.0;
  7185. this.height = 1.0;
  7186. this.constantAttenuation = 1.5;
  7187. this.linearAttenuation = 0.5;
  7188. this.quadraticAttenuation = 0.1;
  7189. };
  7190. THREE.AreaLight.prototype = Object.create( THREE.Light.prototype );
  7191. THREE.AreaLight.prototype.constructor = THREE.AreaLight;
  7192. THREE.AreaLight.prototype.clone = function () {
  7193. var light = new THREE.AreaLight();
  7194. light.copy( this );
  7195. light.normal.copy( this.normal );
  7196. light.right.copy( this.right );
  7197. light.intensity = this.intensity;
  7198. light.width = this.width;
  7199. light.height = this.height;
  7200. light.constantAttenuation = this.constantAttenuation;
  7201. light.linearAttenuation = this.linearAttenuation;
  7202. light.quadraticAttenuation = this.quadraticAttenuation;
  7203. return light;
  7204. };
  7205. THREE.AreaLight.prototype.toJSON = function ( meta ) {
  7206. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7207. data.object.color = this.color.getHex();
  7208. data.object.intensity = this.intensity;
  7209. return data;
  7210. };
  7211. // File:src/lights/DirectionalLight.js
  7212. /**
  7213. * @author mrdoob / http://mrdoob.com/
  7214. * @author alteredq / http://alteredqualia.com/
  7215. */
  7216. THREE.DirectionalLight = function ( color, intensity ) {
  7217. THREE.Light.call( this, color );
  7218. this.type = 'DirectionalLight';
  7219. this.position.set( 0, 1, 0 );
  7220. this.updateMatrix();
  7221. this.target = new THREE.Object3D();
  7222. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7223. this.castShadow = false;
  7224. this.onlyShadow = false;
  7225. //
  7226. this.shadowCameraNear = 50;
  7227. this.shadowCameraFar = 5000;
  7228. this.shadowCameraLeft = - 500;
  7229. this.shadowCameraRight = 500;
  7230. this.shadowCameraTop = 500;
  7231. this.shadowCameraBottom = - 500;
  7232. this.shadowCameraVisible = false;
  7233. this.shadowBias = 0;
  7234. this.shadowDarkness = 0.5;
  7235. this.shadowMapWidth = 512;
  7236. this.shadowMapHeight = 512;
  7237. //
  7238. this.shadowMap = null;
  7239. this.shadowMapSize = null;
  7240. this.shadowCamera = null;
  7241. this.shadowMatrix = null;
  7242. };
  7243. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  7244. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  7245. THREE.DirectionalLight.prototype.clone = function () {
  7246. var light = new THREE.DirectionalLight();
  7247. light.copy( this );
  7248. light.target = this.target.clone();
  7249. light.intensity = this.intensity;
  7250. light.castShadow = this.castShadow;
  7251. light.onlyShadow = this.onlyShadow;
  7252. //
  7253. light.shadowCameraNear = this.shadowCameraNear;
  7254. light.shadowCameraFar = this.shadowCameraFar;
  7255. light.shadowCameraLeft = this.shadowCameraLeft;
  7256. light.shadowCameraRight = this.shadowCameraRight;
  7257. light.shadowCameraTop = this.shadowCameraTop;
  7258. light.shadowCameraBottom = this.shadowCameraBottom;
  7259. light.shadowCameraVisible = this.shadowCameraVisible;
  7260. light.shadowBias = this.shadowBias;
  7261. light.shadowDarkness = this.shadowDarkness;
  7262. light.shadowMapWidth = this.shadowMapWidth;
  7263. light.shadowMapHeight = this.shadowMapHeight;
  7264. return light;
  7265. };
  7266. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  7267. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7268. data.object.color = this.color.getHex();
  7269. data.object.intensity = this.intensity;
  7270. return data;
  7271. };
  7272. // File:src/lights/HemisphereLight.js
  7273. /**
  7274. * @author alteredq / http://alteredqualia.com/
  7275. */
  7276. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  7277. THREE.Light.call( this, skyColor );
  7278. this.type = 'HemisphereLight';
  7279. this.position.set( 0, 100, 0 );
  7280. this.updateMatrix();
  7281. this.groundColor = new THREE.Color( groundColor );
  7282. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7283. };
  7284. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  7285. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  7286. THREE.HemisphereLight.prototype.clone = function () {
  7287. var light = new THREE.HemisphereLight();
  7288. light.copy( this );
  7289. light.groundColor.copy( this.groundColor );
  7290. light.intensity = this.intensity;
  7291. return light;
  7292. };
  7293. THREE.HemisphereLight.prototype.toJSON = function ( meta ) {
  7294. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7295. data.object.color = this.color.getHex();
  7296. data.object.groundColor = this.groundColor.getHex();
  7297. data.object.intensity = this.intensity;
  7298. return data;
  7299. };
  7300. // File:src/lights/PointLight.js
  7301. /**
  7302. * @author mrdoob / http://mrdoob.com/
  7303. */
  7304. THREE.PointLight = function ( color, intensity, distance, decay ) {
  7305. THREE.Light.call( this, color );
  7306. this.type = 'PointLight';
  7307. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7308. this.distance = ( distance !== undefined ) ? distance : 0;
  7309. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7310. };
  7311. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  7312. THREE.PointLight.prototype.constructor = THREE.PointLight;
  7313. THREE.PointLight.prototype.clone = function () {
  7314. var light = new THREE.PointLight();
  7315. light.copy( this );
  7316. light.intensity = this.intensity;
  7317. light.distance = this.distance;
  7318. light.decay = this.decay;
  7319. return light;
  7320. };
  7321. THREE.PointLight.prototype.toJSON = function ( meta ) {
  7322. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7323. data.object.color = this.color.getHex();
  7324. data.object.intensity = this.intensity;
  7325. data.object.distance = this.distance;
  7326. data.object.decay = this.decay;
  7327. return data;
  7328. };
  7329. // File:src/lights/SpotLight.js
  7330. /**
  7331. * @author alteredq / http://alteredqualia.com/
  7332. */
  7333. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  7334. THREE.Light.call( this, color );
  7335. this.type = 'SpotLight';
  7336. this.position.set( 0, 1, 0 );
  7337. this.updateMatrix();
  7338. this.target = new THREE.Object3D();
  7339. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7340. this.distance = ( distance !== undefined ) ? distance : 0;
  7341. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  7342. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  7343. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7344. this.castShadow = false;
  7345. this.onlyShadow = false;
  7346. //
  7347. this.shadowCameraNear = 50;
  7348. this.shadowCameraFar = 5000;
  7349. this.shadowCameraFov = 50;
  7350. this.shadowCameraVisible = false;
  7351. this.shadowBias = 0;
  7352. this.shadowDarkness = 0.5;
  7353. this.shadowMapWidth = 512;
  7354. this.shadowMapHeight = 512;
  7355. //
  7356. this.shadowMap = null;
  7357. this.shadowMapSize = null;
  7358. this.shadowCamera = null;
  7359. this.shadowMatrix = null;
  7360. };
  7361. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  7362. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  7363. THREE.SpotLight.prototype.clone = function () {
  7364. var light = new THREE.SpotLight();
  7365. light.copy( this );
  7366. light.target = this.target.clone();
  7367. light.intensity = this.intensity;
  7368. light.distance = this.distance;
  7369. light.angle = this.angle;
  7370. light.exponent = this.exponent;
  7371. light.decay = this.decay;
  7372. light.castShadow = this.castShadow;
  7373. light.onlyShadow = this.onlyShadow;
  7374. //
  7375. light.shadowCameraNear = this.shadowCameraNear;
  7376. light.shadowCameraFar = this.shadowCameraFar;
  7377. light.shadowCameraFov = this.shadowCameraFov;
  7378. light.shadowCameraVisible = this.shadowCameraVisible;
  7379. light.shadowBias = this.shadowBias;
  7380. light.shadowDarkness = this.shadowDarkness;
  7381. light.shadowMapWidth = this.shadowMapWidth;
  7382. light.shadowMapHeight = this.shadowMapHeight;
  7383. return light;
  7384. };
  7385. THREE.SpotLight.prototype.toJSON = function ( meta ) {
  7386. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7387. data.object.color = this.color.getHex();
  7388. data.object.intensity = this.intensity;
  7389. data.object.distance = this.distance;
  7390. data.object.angle = this.angle;
  7391. data.object.exponent = this.exponent;
  7392. data.object.decay = this.decay;
  7393. return data;
  7394. };
  7395. // File:src/loaders/Cache.js
  7396. /**
  7397. * @author mrdoob / http://mrdoob.com/
  7398. */
  7399. THREE.Cache = {
  7400. enabled: false,
  7401. files: {},
  7402. add: function ( key, file ) {
  7403. if ( this.enabled === false ) return;
  7404. // console.log( 'THREE.Cache', 'Adding key:', key );
  7405. this.files[ key ] = file;
  7406. },
  7407. get: function ( key ) {
  7408. if ( this.enabled === false ) return;
  7409. // console.log( 'THREE.Cache', 'Checking key:', key );
  7410. return this.files[ key ];
  7411. },
  7412. remove: function ( key ) {
  7413. delete this.files[ key ];
  7414. },
  7415. clear: function () {
  7416. this.files = {};
  7417. }
  7418. };
  7419. // File:src/loaders/Loader.js
  7420. /**
  7421. * @author alteredq / http://alteredqualia.com/
  7422. */
  7423. THREE.Loader = function () {
  7424. this.onLoadStart = function () {};
  7425. this.onLoadProgress = function () {};
  7426. this.onLoadComplete = function () {};
  7427. };
  7428. THREE.Loader.prototype = {
  7429. constructor: THREE.Loader,
  7430. crossOrigin: undefined,
  7431. extractUrlBase: function ( url ) {
  7432. var parts = url.split( '/' );
  7433. if ( parts.length === 1 ) return './';
  7434. parts.pop();
  7435. return parts.join( '/' ) + '/';
  7436. },
  7437. initMaterials: function ( materials, texturePath, crossOrigin ) {
  7438. var array = [];
  7439. for ( var i = 0; i < materials.length; ++ i ) {
  7440. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  7441. }
  7442. return array;
  7443. },
  7444. needsTangents: function ( materials ) {
  7445. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  7446. var m = materials[ i ];
  7447. if ( m instanceof THREE.ShaderMaterial ) return true;
  7448. }
  7449. return false;
  7450. },
  7451. createMaterial: ( function () {
  7452. var imageLoader;
  7453. return function createMaterial( m, texturePath, crossOrigin ) {
  7454. var scope = this;
  7455. if ( crossOrigin === undefined && scope.crossOrigin !== undefined ) crossOrigin = scope.crossOrigin;
  7456. if ( imageLoader === undefined ) imageLoader = new THREE.ImageLoader();
  7457. function nearest_pow2( n ) {
  7458. var l = Math.log( n ) / Math.LN2;
  7459. return Math.pow( 2, Math.round( l ) );
  7460. }
  7461. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  7462. var fullPath = texturePath + sourceFile;
  7463. var texture;
  7464. var loader = THREE.Loader.Handlers.get( fullPath );
  7465. if ( loader !== null ) {
  7466. texture = loader.load( fullPath );
  7467. } else {
  7468. texture = new THREE.Texture();
  7469. loader = imageLoader;
  7470. loader.setCrossOrigin( crossOrigin );
  7471. loader.load( fullPath, function ( image ) {
  7472. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  7473. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  7474. var width = nearest_pow2( image.width );
  7475. var height = nearest_pow2( image.height );
  7476. var canvas = document.createElement( 'canvas' );
  7477. canvas.width = width;
  7478. canvas.height = height;
  7479. var context = canvas.getContext( '2d' );
  7480. context.drawImage( image, 0, 0, width, height );
  7481. texture.image = canvas;
  7482. } else {
  7483. texture.image = image;
  7484. }
  7485. texture.needsUpdate = true;
  7486. } );
  7487. }
  7488. texture.sourceFile = sourceFile;
  7489. if ( repeat ) {
  7490. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  7491. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  7492. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  7493. }
  7494. if ( offset ) {
  7495. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  7496. }
  7497. if ( wrap ) {
  7498. var wrapMap = {
  7499. 'repeat': THREE.RepeatWrapping,
  7500. 'mirror': THREE.MirroredRepeatWrapping
  7501. };
  7502. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  7503. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  7504. }
  7505. if ( anisotropy ) {
  7506. texture.anisotropy = anisotropy;
  7507. }
  7508. where[ name ] = texture;
  7509. }
  7510. function rgb2hex( rgb ) {
  7511. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  7512. }
  7513. // defaults
  7514. var mtype = 'MeshLambertMaterial';
  7515. var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
  7516. // parameters from model file
  7517. if ( m.shading ) {
  7518. var shading = m.shading.toLowerCase();
  7519. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  7520. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  7521. }
  7522. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  7523. mpars.blending = THREE[ m.blending ];
  7524. }
  7525. if ( m.transparent !== undefined ) {
  7526. mpars.transparent = m.transparent;
  7527. }
  7528. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  7529. mpars.transparent = true;
  7530. }
  7531. if ( m.depthTest !== undefined ) {
  7532. mpars.depthTest = m.depthTest;
  7533. }
  7534. if ( m.depthWrite !== undefined ) {
  7535. mpars.depthWrite = m.depthWrite;
  7536. }
  7537. if ( m.visible !== undefined ) {
  7538. mpars.visible = m.visible;
  7539. }
  7540. if ( m.flipSided !== undefined ) {
  7541. mpars.side = THREE.BackSide;
  7542. }
  7543. if ( m.doubleSided !== undefined ) {
  7544. mpars.side = THREE.DoubleSide;
  7545. }
  7546. if ( m.wireframe !== undefined ) {
  7547. mpars.wireframe = m.wireframe;
  7548. }
  7549. if ( m.vertexColors !== undefined ) {
  7550. if ( m.vertexColors === 'face' ) {
  7551. mpars.vertexColors = THREE.FaceColors;
  7552. } else if ( m.vertexColors ) {
  7553. mpars.vertexColors = THREE.VertexColors;
  7554. }
  7555. }
  7556. // colors
  7557. if ( m.colorDiffuse ) {
  7558. mpars.color = rgb2hex( m.colorDiffuse );
  7559. } else if ( m.DbgColor ) {
  7560. mpars.color = m.DbgColor;
  7561. }
  7562. if ( m.colorSpecular ) {
  7563. mpars.specular = rgb2hex( m.colorSpecular );
  7564. }
  7565. if ( m.colorEmissive ) {
  7566. mpars.emissive = rgb2hex( m.colorEmissive );
  7567. }
  7568. // modifiers
  7569. if ( m.transparency !== undefined ) {
  7570. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  7571. m.opacity = m.transparency;
  7572. }
  7573. if ( m.opacity !== undefined ) {
  7574. mpars.opacity = m.opacity;
  7575. }
  7576. if ( m.specularCoef ) {
  7577. mpars.shininess = m.specularCoef;
  7578. }
  7579. // textures
  7580. if ( m.mapDiffuse && texturePath ) {
  7581. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  7582. }
  7583. if ( m.mapLight && texturePath ) {
  7584. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  7585. }
  7586. if ( m.mapAO && texturePath ) {
  7587. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  7588. }
  7589. if ( m.mapBump && texturePath ) {
  7590. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  7591. }
  7592. if ( m.mapNormal && texturePath ) {
  7593. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  7594. }
  7595. if ( m.mapSpecular && texturePath ) {
  7596. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  7597. }
  7598. if ( m.mapAlpha && texturePath ) {
  7599. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  7600. }
  7601. //
  7602. if ( m.mapBumpScale ) {
  7603. mpars.bumpScale = m.mapBumpScale;
  7604. }
  7605. if ( m.mapNormalFactor ) {
  7606. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  7607. }
  7608. var material = new THREE[ mtype ]( mpars );
  7609. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  7610. return material;
  7611. };
  7612. } )()
  7613. };
  7614. THREE.Loader.Handlers = {
  7615. handlers: [],
  7616. add: function ( regex, loader ) {
  7617. this.handlers.push( regex, loader );
  7618. },
  7619. get: function ( file ) {
  7620. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  7621. var regex = this.handlers[ i ];
  7622. var loader = this.handlers[ i + 1 ];
  7623. if ( regex.test( file ) ) {
  7624. return loader;
  7625. }
  7626. }
  7627. return null;
  7628. }
  7629. };
  7630. // File:src/loaders/XHRLoader.js
  7631. /**
  7632. * @author mrdoob / http://mrdoob.com/
  7633. */
  7634. THREE.XHRLoader = function ( manager ) {
  7635. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7636. };
  7637. THREE.XHRLoader.prototype = {
  7638. constructor: THREE.XHRLoader,
  7639. load: function ( url, onLoad, onProgress, onError ) {
  7640. var scope = this;
  7641. var cached = THREE.Cache.get( url );
  7642. if ( cached !== undefined ) {
  7643. if ( onLoad ) {
  7644. setTimeout( function () {
  7645. onLoad( cached );
  7646. }, 0 );
  7647. }
  7648. return cached;
  7649. }
  7650. var request = new XMLHttpRequest();
  7651. request.open( 'GET', url, true );
  7652. request.addEventListener( 'load', function ( event ) {
  7653. THREE.Cache.add( url, this.response );
  7654. if ( onLoad ) onLoad( this.response );
  7655. scope.manager.itemEnd( url );
  7656. }, false );
  7657. if ( onProgress !== undefined ) {
  7658. request.addEventListener( 'progress', function ( event ) {
  7659. onProgress( event );
  7660. }, false );
  7661. }
  7662. if ( onError !== undefined ) {
  7663. request.addEventListener( 'error', function ( event ) {
  7664. onError( event );
  7665. }, false );
  7666. }
  7667. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  7668. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  7669. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  7670. request.send( null );
  7671. scope.manager.itemStart( url );
  7672. return request;
  7673. },
  7674. setResponseType: function ( value ) {
  7675. this.responseType = value;
  7676. },
  7677. setCrossOrigin: function ( value ) {
  7678. this.crossOrigin = value;
  7679. },
  7680. setWithCredentials: function ( value ) {
  7681. this.withCredentials = value;
  7682. }
  7683. };
  7684. // File:src/loaders/ImageLoader.js
  7685. /**
  7686. * @author mrdoob / http://mrdoob.com/
  7687. */
  7688. THREE.ImageLoader = function ( manager ) {
  7689. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7690. };
  7691. THREE.ImageLoader.prototype = {
  7692. constructor: THREE.ImageLoader,
  7693. load: function ( url, onLoad, onProgress, onError ) {
  7694. var scope = this;
  7695. var cached = THREE.Cache.get( url );
  7696. if ( cached !== undefined ) {
  7697. if ( onLoad ) {
  7698. setTimeout( function () {
  7699. onLoad( cached );
  7700. }, 0 );
  7701. }
  7702. return cached;
  7703. }
  7704. var image = document.createElement( 'img' );
  7705. image.addEventListener( 'load', function ( event ) {
  7706. THREE.Cache.add( url, this );
  7707. if ( onLoad ) onLoad( this );
  7708. scope.manager.itemEnd( url );
  7709. }, false );
  7710. if ( onProgress !== undefined ) {
  7711. image.addEventListener( 'progress', function ( event ) {
  7712. onProgress( event );
  7713. }, false );
  7714. }
  7715. if ( onError !== undefined ) {
  7716. image.addEventListener( 'error', function ( event ) {
  7717. onError( event );
  7718. }, false );
  7719. }
  7720. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  7721. scope.manager.itemStart( url );
  7722. image.src = url;
  7723. return image;
  7724. },
  7725. setCrossOrigin: function ( value ) {
  7726. this.crossOrigin = value;
  7727. }
  7728. };
  7729. // File:src/loaders/JSONLoader.js
  7730. /**
  7731. * @author mrdoob / http://mrdoob.com/
  7732. * @author alteredq / http://alteredqualia.com/
  7733. */
  7734. THREE.JSONLoader = function ( manager ) {
  7735. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7736. this.withCredentials = false;
  7737. };
  7738. THREE.JSONLoader.prototype = {
  7739. constructor: THREE.JSONLoader,
  7740. load: function( url, onLoad, onProgress, onError ) {
  7741. var scope = this;
  7742. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  7743. var loader = new THREE.XHRLoader( this.manager );
  7744. loader.setCrossOrigin( this.crossOrigin );
  7745. loader.setWithCredentials( this.withCredentials );
  7746. loader.load( url, function ( text ) {
  7747. var json = JSON.parse( text );
  7748. var metadata = json.metadata;
  7749. if ( metadata !== undefined ) {
  7750. if ( metadata.type === 'object' ) {
  7751. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  7752. return;
  7753. }
  7754. if ( metadata.type === 'scene' ) {
  7755. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  7756. return;
  7757. }
  7758. }
  7759. var object = scope.parse( json, texturePath );
  7760. onLoad( object.geometry, object.materials );
  7761. } );
  7762. },
  7763. setCrossOrigin: function ( value ) {
  7764. this.crossOrigin = value;
  7765. },
  7766. setTexturePath: function ( value ) {
  7767. this.texturePath = value;
  7768. },
  7769. parse: function ( json, texturePath ) {
  7770. var geometry = new THREE.Geometry(),
  7771. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  7772. parseModel( scale );
  7773. parseSkin();
  7774. parseMorphing( scale );
  7775. geometry.computeFaceNormals();
  7776. geometry.computeBoundingSphere();
  7777. function parseModel( scale ) {
  7778. function isBitSet( value, position ) {
  7779. return value & ( 1 << position );
  7780. }
  7781. var i, j, fi,
  7782. offset, zLength,
  7783. colorIndex, normalIndex, uvIndex, materialIndex,
  7784. type,
  7785. isQuad,
  7786. hasMaterial,
  7787. hasFaceVertexUv,
  7788. hasFaceNormal, hasFaceVertexNormal,
  7789. hasFaceColor, hasFaceVertexColor,
  7790. vertex, face, faceA, faceB, hex, normal,
  7791. uvLayer, uv, u, v,
  7792. faces = json.faces,
  7793. vertices = json.vertices,
  7794. normals = json.normals,
  7795. colors = json.colors,
  7796. nUvLayers = 0;
  7797. if ( json.uvs !== undefined ) {
  7798. // disregard empty arrays
  7799. for ( i = 0; i < json.uvs.length; i ++ ) {
  7800. if ( json.uvs[ i ].length ) nUvLayers ++;
  7801. }
  7802. for ( i = 0; i < nUvLayers; i ++ ) {
  7803. geometry.faceVertexUvs[ i ] = [];
  7804. }
  7805. }
  7806. offset = 0;
  7807. zLength = vertices.length;
  7808. while ( offset < zLength ) {
  7809. vertex = new THREE.Vector3();
  7810. vertex.x = vertices[ offset ++ ] * scale;
  7811. vertex.y = vertices[ offset ++ ] * scale;
  7812. vertex.z = vertices[ offset ++ ] * scale;
  7813. geometry.vertices.push( vertex );
  7814. }
  7815. offset = 0;
  7816. zLength = faces.length;
  7817. while ( offset < zLength ) {
  7818. type = faces[ offset ++ ];
  7819. isQuad = isBitSet( type, 0 );
  7820. hasMaterial = isBitSet( type, 1 );
  7821. hasFaceVertexUv = isBitSet( type, 3 );
  7822. hasFaceNormal = isBitSet( type, 4 );
  7823. hasFaceVertexNormal = isBitSet( type, 5 );
  7824. hasFaceColor = isBitSet( type, 6 );
  7825. hasFaceVertexColor = isBitSet( type, 7 );
  7826. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  7827. if ( isQuad ) {
  7828. faceA = new THREE.Face3();
  7829. faceA.a = faces[ offset ];
  7830. faceA.b = faces[ offset + 1 ];
  7831. faceA.c = faces[ offset + 3 ];
  7832. faceB = new THREE.Face3();
  7833. faceB.a = faces[ offset + 1 ];
  7834. faceB.b = faces[ offset + 2 ];
  7835. faceB.c = faces[ offset + 3 ];
  7836. offset += 4;
  7837. if ( hasMaterial ) {
  7838. materialIndex = faces[ offset ++ ];
  7839. faceA.materialIndex = materialIndex;
  7840. faceB.materialIndex = materialIndex;
  7841. }
  7842. // to get face <=> uv index correspondence
  7843. fi = geometry.faces.length;
  7844. if ( hasFaceVertexUv ) {
  7845. for ( i = 0; i < nUvLayers; i ++ ) {
  7846. uvLayer = json.uvs[ i ];
  7847. geometry.faceVertexUvs[ i ][ fi ] = [];
  7848. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  7849. for ( j = 0; j < 4; j ++ ) {
  7850. uvIndex = faces[ offset ++ ];
  7851. u = uvLayer[ uvIndex * 2 ];
  7852. v = uvLayer[ uvIndex * 2 + 1 ];
  7853. uv = new THREE.Vector2( u, v );
  7854. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7855. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  7856. }
  7857. }
  7858. }
  7859. if ( hasFaceNormal ) {
  7860. normalIndex = faces[ offset ++ ] * 3;
  7861. faceA.normal.set(
  7862. normals[ normalIndex ++ ],
  7863. normals[ normalIndex ++ ],
  7864. normals[ normalIndex ]
  7865. );
  7866. faceB.normal.copy( faceA.normal );
  7867. }
  7868. if ( hasFaceVertexNormal ) {
  7869. for ( i = 0; i < 4; i ++ ) {
  7870. normalIndex = faces[ offset ++ ] * 3;
  7871. normal = new THREE.Vector3(
  7872. normals[ normalIndex ++ ],
  7873. normals[ normalIndex ++ ],
  7874. normals[ normalIndex ]
  7875. );
  7876. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  7877. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  7878. }
  7879. }
  7880. if ( hasFaceColor ) {
  7881. colorIndex = faces[ offset ++ ];
  7882. hex = colors[ colorIndex ];
  7883. faceA.color.setHex( hex );
  7884. faceB.color.setHex( hex );
  7885. }
  7886. if ( hasFaceVertexColor ) {
  7887. for ( i = 0; i < 4; i ++ ) {
  7888. colorIndex = faces[ offset ++ ];
  7889. hex = colors[ colorIndex ];
  7890. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  7891. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  7892. }
  7893. }
  7894. geometry.faces.push( faceA );
  7895. geometry.faces.push( faceB );
  7896. } else {
  7897. face = new THREE.Face3();
  7898. face.a = faces[ offset ++ ];
  7899. face.b = faces[ offset ++ ];
  7900. face.c = faces[ offset ++ ];
  7901. if ( hasMaterial ) {
  7902. materialIndex = faces[ offset ++ ];
  7903. face.materialIndex = materialIndex;
  7904. }
  7905. // to get face <=> uv index correspondence
  7906. fi = geometry.faces.length;
  7907. if ( hasFaceVertexUv ) {
  7908. for ( i = 0; i < nUvLayers; i ++ ) {
  7909. uvLayer = json.uvs[ i ];
  7910. geometry.faceVertexUvs[ i ][ fi ] = [];
  7911. for ( j = 0; j < 3; j ++ ) {
  7912. uvIndex = faces[ offset ++ ];
  7913. u = uvLayer[ uvIndex * 2 ];
  7914. v = uvLayer[ uvIndex * 2 + 1 ];
  7915. uv = new THREE.Vector2( u, v );
  7916. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7917. }
  7918. }
  7919. }
  7920. if ( hasFaceNormal ) {
  7921. normalIndex = faces[ offset ++ ] * 3;
  7922. face.normal.set(
  7923. normals[ normalIndex ++ ],
  7924. normals[ normalIndex ++ ],
  7925. normals[ normalIndex ]
  7926. );
  7927. }
  7928. if ( hasFaceVertexNormal ) {
  7929. for ( i = 0; i < 3; i ++ ) {
  7930. normalIndex = faces[ offset ++ ] * 3;
  7931. normal = new THREE.Vector3(
  7932. normals[ normalIndex ++ ],
  7933. normals[ normalIndex ++ ],
  7934. normals[ normalIndex ]
  7935. );
  7936. face.vertexNormals.push( normal );
  7937. }
  7938. }
  7939. if ( hasFaceColor ) {
  7940. colorIndex = faces[ offset ++ ];
  7941. face.color.setHex( colors[ colorIndex ] );
  7942. }
  7943. if ( hasFaceVertexColor ) {
  7944. for ( i = 0; i < 3; i ++ ) {
  7945. colorIndex = faces[ offset ++ ];
  7946. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  7947. }
  7948. }
  7949. geometry.faces.push( face );
  7950. }
  7951. }
  7952. };
  7953. function parseSkin() {
  7954. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  7955. if ( json.skinWeights ) {
  7956. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  7957. var x = json.skinWeights[ i ];
  7958. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  7959. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  7960. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  7961. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  7962. }
  7963. }
  7964. if ( json.skinIndices ) {
  7965. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  7966. var a = json.skinIndices[ i ];
  7967. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  7968. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  7969. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  7970. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  7971. }
  7972. }
  7973. geometry.bones = json.bones;
  7974. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  7975. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  7976. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  7977. }
  7978. // could change this to json.animations[0] or remove completely
  7979. geometry.animation = json.animation;
  7980. geometry.animations = json.animations;
  7981. };
  7982. function parseMorphing( scale ) {
  7983. if ( json.morphTargets !== undefined ) {
  7984. var i, l, v, vl, dstVertices, srcVertices;
  7985. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  7986. geometry.morphTargets[ i ] = {};
  7987. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  7988. geometry.morphTargets[ i ].vertices = [];
  7989. dstVertices = geometry.morphTargets[ i ].vertices;
  7990. srcVertices = json.morphTargets[ i ].vertices;
  7991. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  7992. var vertex = new THREE.Vector3();
  7993. vertex.x = srcVertices[ v ] * scale;
  7994. vertex.y = srcVertices[ v + 1 ] * scale;
  7995. vertex.z = srcVertices[ v + 2 ] * scale;
  7996. dstVertices.push( vertex );
  7997. }
  7998. }
  7999. }
  8000. if ( json.morphColors !== undefined ) {
  8001. var i, l, c, cl, dstColors, srcColors, color;
  8002. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  8003. geometry.morphColors[ i ] = {};
  8004. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  8005. geometry.morphColors[ i ].colors = [];
  8006. dstColors = geometry.morphColors[ i ].colors;
  8007. srcColors = json.morphColors[ i ].colors;
  8008. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  8009. color = new THREE.Color( 0xffaa00 );
  8010. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  8011. dstColors.push( color );
  8012. }
  8013. }
  8014. }
  8015. };
  8016. if ( json.materials === undefined || json.materials.length === 0 ) {
  8017. return { geometry: geometry };
  8018. } else {
  8019. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  8020. if ( THREE.Loader.prototype.needsTangents( materials ) ) {
  8021. geometry.computeTangents();
  8022. }
  8023. return { geometry: geometry, materials: materials };
  8024. }
  8025. }
  8026. };
  8027. // File:src/loaders/LoadingManager.js
  8028. /**
  8029. * @author mrdoob / http://mrdoob.com/
  8030. */
  8031. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  8032. var scope = this;
  8033. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  8034. this.onLoad = onLoad;
  8035. this.onProgress = onProgress;
  8036. this.onError = onError;
  8037. this.itemStart = function ( url ) {
  8038. itemsTotal ++;
  8039. if ( isLoading === false ) {
  8040. if ( scope.onStart !== undefined ) {
  8041. scope.onStart( url, itemsLoaded, itemsTotal );
  8042. }
  8043. }
  8044. isLoading = true;
  8045. };
  8046. this.itemEnd = function ( url ) {
  8047. itemsLoaded ++;
  8048. if ( scope.onProgress !== undefined ) {
  8049. scope.onProgress( url, itemsLoaded, itemsTotal );
  8050. }
  8051. if ( itemsLoaded === itemsTotal ) {
  8052. isLoading = false;
  8053. if ( scope.onLoad !== undefined ) {
  8054. scope.onLoad();
  8055. }
  8056. }
  8057. };
  8058. };
  8059. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  8060. // File:src/loaders/BufferGeometryLoader.js
  8061. /**
  8062. * @author mrdoob / http://mrdoob.com/
  8063. */
  8064. THREE.BufferGeometryLoader = function ( manager ) {
  8065. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8066. };
  8067. THREE.BufferGeometryLoader.prototype = {
  8068. constructor: THREE.BufferGeometryLoader,
  8069. load: function ( url, onLoad, onProgress, onError ) {
  8070. var scope = this;
  8071. var loader = new THREE.XHRLoader( scope.manager );
  8072. loader.setCrossOrigin( this.crossOrigin );
  8073. loader.load( url, function ( text ) {
  8074. onLoad( scope.parse( JSON.parse( text ) ) );
  8075. }, onProgress, onError );
  8076. },
  8077. setCrossOrigin: function ( value ) {
  8078. this.crossOrigin = value;
  8079. },
  8080. parse: function ( json ) {
  8081. var geometry = new THREE.BufferGeometry();
  8082. var attributes = json.data.attributes;
  8083. for ( var key in attributes ) {
  8084. var attribute = attributes[ key ];
  8085. var typedArray = new self[ attribute.type ]( attribute.array );
  8086. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  8087. }
  8088. var drawcalls = json.data.drawcalls || json.data.offsets;
  8089. if ( drawcalls !== undefined ) {
  8090. for ( var i = 0, n = drawcalls.length; i !== n; ++ i ) {
  8091. var drawcall = drawcalls[ i ];
  8092. var indexStart = drawcall.start;
  8093. var indexCount = drawcall.count;
  8094. var indexOffset = drawcall.index;
  8095. geometry.addDrawcall( indexStart, indexCount, indexOffset );
  8096. }
  8097. }
  8098. var boundingSphere = json.data.boundingSphere;
  8099. if ( boundingSphere !== undefined ) {
  8100. var center = new THREE.Vector3();
  8101. if ( boundingSphere.center !== undefined ) {
  8102. center.fromArray( boundingSphere.center );
  8103. }
  8104. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  8105. }
  8106. return geometry;
  8107. }
  8108. };
  8109. // File:src/loaders/MaterialLoader.js
  8110. /**
  8111. * @author mrdoob / http://mrdoob.com/
  8112. */
  8113. THREE.MaterialLoader = function ( manager ) {
  8114. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8115. };
  8116. THREE.MaterialLoader.prototype = {
  8117. constructor: THREE.MaterialLoader,
  8118. load: function ( url, onLoad, onProgress, onError ) {
  8119. var scope = this;
  8120. var loader = new THREE.XHRLoader( scope.manager );
  8121. loader.setCrossOrigin( this.crossOrigin );
  8122. loader.load( url, function ( text ) {
  8123. onLoad( scope.parse( JSON.parse( text ) ) );
  8124. }, onProgress, onError );
  8125. },
  8126. setCrossOrigin: function ( value ) {
  8127. this.crossOrigin = value;
  8128. },
  8129. parse: function ( json ) {
  8130. var material = new THREE[ json.type ];
  8131. if ( json.color !== undefined ) material.color.setHex( json.color );
  8132. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  8133. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  8134. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  8135. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  8136. if ( json.attributes !== undefined ) material.attributes = json.attributes;
  8137. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  8138. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  8139. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  8140. if ( json.shading !== undefined ) material.shading = json.shading;
  8141. if ( json.blending !== undefined ) material.blending = json.blending;
  8142. if ( json.side !== undefined ) material.side = json.side;
  8143. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  8144. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  8145. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  8146. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  8147. // for PointCloudMaterial
  8148. if ( json.size !== undefined ) material.size = json.size;
  8149. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  8150. if ( json.materials !== undefined ) {
  8151. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  8152. material.materials.push( this.parse( json.materials[ i ] ) );
  8153. }
  8154. }
  8155. return material;
  8156. }
  8157. };
  8158. // File:src/loaders/ObjectLoader.js
  8159. /**
  8160. * @author mrdoob / http://mrdoob.com/
  8161. */
  8162. THREE.ObjectLoader = function ( manager ) {
  8163. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8164. this.texturePath = '';
  8165. };
  8166. THREE.ObjectLoader.prototype = {
  8167. constructor: THREE.ObjectLoader,
  8168. load: function ( url, onLoad, onProgress, onError ) {
  8169. if ( this.texturePath === '' ) {
  8170. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  8171. }
  8172. var scope = this;
  8173. var loader = new THREE.XHRLoader( scope.manager );
  8174. loader.setCrossOrigin( this.crossOrigin );
  8175. loader.load( url, function ( text ) {
  8176. scope.parse( JSON.parse( text ), onLoad );
  8177. }, onProgress, onError );
  8178. },
  8179. setTexturePath: function ( value ) {
  8180. this.texturePath = value;
  8181. },
  8182. setCrossOrigin: function ( value ) {
  8183. this.crossOrigin = value;
  8184. },
  8185. parse: function ( json, onLoad ) {
  8186. var geometries = this.parseGeometries( json.geometries );
  8187. var images = this.parseImages( json.images, function () {
  8188. if ( onLoad !== undefined ) onLoad( object );
  8189. } );
  8190. var textures = this.parseTextures( json.textures, images );
  8191. var materials = this.parseMaterials( json.materials, textures );
  8192. var object = this.parseObject( json.object, geometries, materials );
  8193. if ( json.images === undefined || json.images.length === 0 ) {
  8194. if ( onLoad !== undefined ) onLoad( object );
  8195. }
  8196. return object;
  8197. },
  8198. parseGeometries: function ( json ) {
  8199. var geometries = {};
  8200. if ( json !== undefined ) {
  8201. var geometryLoader = new THREE.JSONLoader();
  8202. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  8203. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8204. var geometry;
  8205. var data = json[ i ];
  8206. switch ( data.type ) {
  8207. case 'PlaneGeometry':
  8208. case 'PlaneBufferGeometry':
  8209. geometry = new THREE[ data.type ](
  8210. data.width,
  8211. data.height,
  8212. data.widthSegments,
  8213. data.heightSegments
  8214. );
  8215. break;
  8216. case 'BoxGeometry':
  8217. case 'CubeGeometry': // backwards compatible
  8218. geometry = new THREE.BoxGeometry(
  8219. data.width,
  8220. data.height,
  8221. data.depth,
  8222. data.widthSegments,
  8223. data.heightSegments,
  8224. data.depthSegments
  8225. );
  8226. break;
  8227. case 'CircleBufferGeometry':
  8228. geometry = new THREE.CircleBufferGeometry(
  8229. data.radius,
  8230. data.segments,
  8231. data.thetaStart,
  8232. data.thetaLength
  8233. );
  8234. break;
  8235. case 'CircleGeometry':
  8236. geometry = new THREE.CircleGeometry(
  8237. data.radius,
  8238. data.segments,
  8239. data.thetaStart,
  8240. data.thetaLength
  8241. );
  8242. break;
  8243. case 'CylinderGeometry':
  8244. geometry = new THREE.CylinderGeometry(
  8245. data.radiusTop,
  8246. data.radiusBottom,
  8247. data.height,
  8248. data.radialSegments,
  8249. data.heightSegments,
  8250. data.openEnded,
  8251. data.thetaStart,
  8252. data.thetaLength
  8253. );
  8254. break;
  8255. case 'SphereGeometry':
  8256. geometry = new THREE.SphereGeometry(
  8257. data.radius,
  8258. data.widthSegments,
  8259. data.heightSegments,
  8260. data.phiStart,
  8261. data.phiLength,
  8262. data.thetaStart,
  8263. data.thetaLength
  8264. );
  8265. break;
  8266. case 'SphereBufferGeometry':
  8267. geometry = new THREE.SphereBufferGeometry(
  8268. data.radius,
  8269. data.widthSegments,
  8270. data.heightSegments,
  8271. data.phiStart,
  8272. data.phiLength,
  8273. data.thetaStart,
  8274. data.thetaLength
  8275. );
  8276. break;
  8277. case 'DodecahedronGeometry':
  8278. geometry = new THREE.DodecahedronGeometry(
  8279. data.radius,
  8280. data.detail
  8281. );
  8282. break;
  8283. case 'IcosahedronGeometry':
  8284. geometry = new THREE.IcosahedronGeometry(
  8285. data.radius,
  8286. data.detail
  8287. );
  8288. break;
  8289. case 'OctahedronGeometry':
  8290. geometry = new THREE.OctahedronGeometry(
  8291. data.radius,
  8292. data.detail
  8293. );
  8294. break;
  8295. case 'TetrahedronGeometry':
  8296. geometry = new THREE.TetrahedronGeometry(
  8297. data.radius,
  8298. data.detail
  8299. );
  8300. break;
  8301. case 'RingGeometry':
  8302. geometry = new THREE.RingGeometry(
  8303. data.innerRadius,
  8304. data.outerRadius,
  8305. data.thetaSegments,
  8306. data.phiSegments,
  8307. data.thetaStart,
  8308. data.thetaLength
  8309. );
  8310. break;
  8311. case 'TorusGeometry':
  8312. geometry = new THREE.TorusGeometry(
  8313. data.radius,
  8314. data.tube,
  8315. data.radialSegments,
  8316. data.tubularSegments,
  8317. data.arc
  8318. );
  8319. break;
  8320. case 'TorusKnotGeometry':
  8321. geometry = new THREE.TorusKnotGeometry(
  8322. data.radius,
  8323. data.tube,
  8324. data.radialSegments,
  8325. data.tubularSegments,
  8326. data.p,
  8327. data.q,
  8328. data.heightScale
  8329. );
  8330. break;
  8331. case 'BufferGeometry':
  8332. geometry = bufferGeometryLoader.parse( data );
  8333. break;
  8334. case 'Geometry':
  8335. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  8336. break;
  8337. case 'TextGeometry':
  8338. geometry = new THREE.TextGeometry(
  8339. data.text,
  8340. data.data
  8341. );
  8342. break;
  8343. }
  8344. geometry.uuid = data.uuid;
  8345. if ( data.name !== undefined ) geometry.name = data.name;
  8346. geometries[ data.uuid ] = geometry;
  8347. }
  8348. }
  8349. return geometries;
  8350. },
  8351. parseMaterials: function ( json, textures ) {
  8352. var materials = {};
  8353. if ( json !== undefined ) {
  8354. var getTexture = function ( name ) {
  8355. if ( textures[ name ] === undefined ) {
  8356. console.warn( 'THREE.ObjectLoader: Undefined texture', name );
  8357. }
  8358. return textures[ name ];
  8359. };
  8360. var loader = new THREE.MaterialLoader();
  8361. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8362. var data = json[ i ];
  8363. var material = loader.parse( data );
  8364. material.uuid = data.uuid;
  8365. if ( data.depthTest !== undefined ) material.depthTest = data.depthTest;
  8366. if ( data.depthWrite !== undefined ) material.depthWrite = data.depthWrite;
  8367. if ( data.name !== undefined ) material.name = data.name;
  8368. if ( data.map !== undefined ) material.map = getTexture( data.map );
  8369. if ( data.alphaMap !== undefined ) {
  8370. material.alphaMap = getTexture( data.alphaMap );
  8371. material.transparent = true;
  8372. }
  8373. if ( data.bumpMap !== undefined ) material.bumpMap = getTexture( data.bumpMap );
  8374. if ( data.bumpScale !== undefined ) material.bumpScale = data.bumpScale;
  8375. if ( data.normalMap !== undefined ) material.normalMap = getTexture( data.normalMap );
  8376. if ( data.normalScale ) material.normalScale = new THREE.Vector2( data.normalScale, data.normalScale );
  8377. if ( data.specularMap !== undefined ) material.specularMap = getTexture( data.specularMap );
  8378. if ( data.envMap !== undefined ) {
  8379. material.envMap = getTexture( data.envMap );
  8380. material.combine = THREE.MultiplyOperation;
  8381. }
  8382. if ( data.reflectivity ) material.reflectivity = data.reflectivity;
  8383. if ( data.lightMap !== undefined ) material.lightMap = getTexture( data.lightMap );
  8384. if ( data.lightMapIntensity !== undefined ) material.lightMapIntensity = data.lightMapIntensity;
  8385. if ( data.aoMap !== undefined ) material.aoMap = getTexture( data.aoMap );
  8386. if ( data.aoMapIntensity !== undefined ) material.aoMapIntensity = data.aoMapIntensity;
  8387. materials[ data.uuid ] = material;
  8388. }
  8389. }
  8390. return materials;
  8391. },
  8392. parseImages: function ( json, onLoad ) {
  8393. var scope = this;
  8394. var images = {};
  8395. if ( json !== undefined && json.length > 0 ) {
  8396. var manager = new THREE.LoadingManager( onLoad );
  8397. var loader = new THREE.ImageLoader( manager );
  8398. loader.setCrossOrigin( this.crossOrigin );
  8399. var loadImage = function ( url ) {
  8400. url = scope.texturePath + url;
  8401. scope.manager.itemStart( url );
  8402. return loader.load( url, function () {
  8403. scope.manager.itemEnd( url );
  8404. } );
  8405. };
  8406. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8407. var image = json[ i ];
  8408. images[ image.uuid ] = loadImage( image.url );
  8409. }
  8410. }
  8411. return images;
  8412. },
  8413. parseTextures: function ( json, images ) {
  8414. function parseConstant( value ) {
  8415. if ( typeof( value ) === 'number' ) return value;
  8416. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  8417. return THREE[ value ];
  8418. }
  8419. var textures = {};
  8420. if ( json !== undefined ) {
  8421. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8422. var data = json[ i ];
  8423. if ( data.image === undefined ) {
  8424. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  8425. }
  8426. if ( images[ data.image ] === undefined ) {
  8427. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  8428. }
  8429. var texture = new THREE.Texture( images[ data.image ] );
  8430. texture.needsUpdate = true;
  8431. texture.uuid = data.uuid;
  8432. if ( data.name !== undefined ) texture.name = data.name;
  8433. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  8434. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  8435. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  8436. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  8437. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  8438. if ( Array.isArray( data.wrap ) ) {
  8439. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  8440. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  8441. }
  8442. textures[ data.uuid ] = texture;
  8443. }
  8444. }
  8445. return textures;
  8446. },
  8447. parseObject: function () {
  8448. var matrix = new THREE.Matrix4();
  8449. return function ( data, geometries, materials ) {
  8450. var object;
  8451. var getGeometry = function ( name ) {
  8452. if ( geometries[ name ] === undefined ) {
  8453. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  8454. }
  8455. return geometries[ name ];
  8456. };
  8457. var getMaterial = function ( name ) {
  8458. if ( materials[ name ] === undefined ) {
  8459. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  8460. }
  8461. return materials[ name ];
  8462. };
  8463. switch ( data.type ) {
  8464. case 'Scene':
  8465. object = new THREE.Scene();
  8466. break;
  8467. case 'PerspectiveCamera':
  8468. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  8469. break;
  8470. case 'OrthographicCamera':
  8471. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  8472. break;
  8473. case 'AmbientLight':
  8474. object = new THREE.AmbientLight( data.color );
  8475. break;
  8476. case 'AreaLight':
  8477. object = new THREE.AreaLight( data.color, data.intensity );
  8478. break;
  8479. case 'DirectionalLight':
  8480. object = new THREE.DirectionalLight( data.color, data.intensity );
  8481. break;
  8482. case 'PointLight':
  8483. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  8484. break;
  8485. case 'SpotLight':
  8486. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  8487. break;
  8488. case 'HemisphereLight':
  8489. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  8490. break;
  8491. case 'Mesh':
  8492. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  8493. break;
  8494. case 'Line':
  8495. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  8496. break;
  8497. case 'PointCloud':
  8498. object = new THREE.PointCloud( getGeometry( data.geometry ), getMaterial( data.material ) );
  8499. break;
  8500. case 'Sprite':
  8501. object = new THREE.Sprite( getMaterial( data.material ) );
  8502. break;
  8503. case 'Group':
  8504. object = new THREE.Group();
  8505. break;
  8506. default:
  8507. object = new THREE.Object3D();
  8508. }
  8509. object.uuid = data.uuid;
  8510. if ( data.name !== undefined ) object.name = data.name;
  8511. if ( data.matrix !== undefined ) {
  8512. matrix.fromArray( data.matrix );
  8513. matrix.decompose( object.position, object.quaternion, object.scale );
  8514. } else {
  8515. if ( data.position !== undefined ) object.position.fromArray( data.position );
  8516. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  8517. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  8518. }
  8519. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  8520. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  8521. if ( data.visible !== undefined ) object.visible = data.visible;
  8522. if ( data.userData !== undefined ) object.userData = data.userData;
  8523. if ( data.children !== undefined ) {
  8524. for ( var child in data.children ) {
  8525. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  8526. }
  8527. }
  8528. return object;
  8529. }
  8530. }()
  8531. };
  8532. // File:src/loaders/TextureLoader.js
  8533. /**
  8534. * @author mrdoob / http://mrdoob.com/
  8535. */
  8536. THREE.TextureLoader = function ( manager ) {
  8537. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8538. };
  8539. THREE.TextureLoader.prototype = {
  8540. constructor: THREE.TextureLoader,
  8541. load: function ( url, onLoad, onProgress, onError ) {
  8542. var scope = this;
  8543. var loader = new THREE.ImageLoader( scope.manager );
  8544. loader.setCrossOrigin( this.crossOrigin );
  8545. loader.load( url, function ( image ) {
  8546. var texture = new THREE.Texture( image );
  8547. texture.needsUpdate = true;
  8548. if ( onLoad !== undefined ) {
  8549. onLoad( texture );
  8550. }
  8551. }, onProgress, onError );
  8552. },
  8553. setCrossOrigin: function ( value ) {
  8554. this.crossOrigin = value;
  8555. }
  8556. };
  8557. // File:src/loaders/BinaryTextureLoader.js
  8558. /**
  8559. * @author Nikos M. / https://github.com/foo123/
  8560. *
  8561. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  8562. */
  8563. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  8564. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8565. // override in sub classes
  8566. this._parser = null;
  8567. };
  8568. THREE.BinaryTextureLoader.prototype = {
  8569. constructor: THREE.BinaryTextureLoader,
  8570. load: function ( url, onLoad, onProgress, onError ) {
  8571. var scope = this;
  8572. var texture = new THREE.DataTexture();
  8573. var loader = new THREE.XHRLoader( this.manager );
  8574. loader.setCrossOrigin( this.crossOrigin );
  8575. loader.setResponseType( 'arraybuffer' );
  8576. loader.load( url, function ( buffer ) {
  8577. var texData = scope._parser( buffer );
  8578. if ( ! texData ) return;
  8579. if ( undefined !== texData.image ) {
  8580. texture.image = texData.image;
  8581. } else if ( undefined !== texData.data ) {
  8582. texture.image.width = texData.width;
  8583. texture.image.height = texData.height;
  8584. texture.image.data = texData.data;
  8585. }
  8586. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  8587. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  8588. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  8589. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  8590. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  8591. if ( undefined !== texData.format ) {
  8592. texture.format = texData.format;
  8593. }
  8594. if ( undefined !== texData.type ) {
  8595. texture.type = texData.type;
  8596. }
  8597. if ( undefined !== texData.mipmaps ) {
  8598. texture.mipmaps = texData.mipmaps;
  8599. }
  8600. if ( 1 === texData.mipmapCount ) {
  8601. texture.minFilter = THREE.LinearFilter;
  8602. }
  8603. texture.needsUpdate = true;
  8604. if ( onLoad ) onLoad( texture, texData );
  8605. }, onProgress, onError );
  8606. return texture;
  8607. },
  8608. setCrossOrigin: function ( value ) {
  8609. this.crossOrigin = value;
  8610. }
  8611. };
  8612. // File:src/loaders/CompressedTextureLoader.js
  8613. /**
  8614. * @author mrdoob / http://mrdoob.com/
  8615. *
  8616. * Abstract Base class to block based textures loader (dds, pvr, ...)
  8617. */
  8618. THREE.CompressedTextureLoader = function ( manager ) {
  8619. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8620. // override in sub classes
  8621. this._parser = null;
  8622. };
  8623. THREE.CompressedTextureLoader.prototype = {
  8624. constructor: THREE.CompressedTextureLoader,
  8625. load: function ( url, onLoad, onProgress, onError ) {
  8626. var scope = this;
  8627. var images = [];
  8628. var texture = new THREE.CompressedTexture();
  8629. texture.image = images;
  8630. var loader = new THREE.XHRLoader( this.manager );
  8631. loader.setCrossOrigin( this.crossOrigin );
  8632. loader.setResponseType( 'arraybuffer' );
  8633. if ( Array.isArray( url ) ) {
  8634. var loaded = 0;
  8635. var loadTexture = function ( i ) {
  8636. loader.load( url[ i ], function ( buffer ) {
  8637. var texDatas = scope._parser( buffer, true );
  8638. images[ i ] = {
  8639. width: texDatas.width,
  8640. height: texDatas.height,
  8641. format: texDatas.format,
  8642. mipmaps: texDatas.mipmaps
  8643. };
  8644. loaded += 1;
  8645. if ( loaded === 6 ) {
  8646. if ( texDatas.mipmapCount === 1 )
  8647. texture.minFilter = THREE.LinearFilter;
  8648. texture.format = texDatas.format;
  8649. texture.needsUpdate = true;
  8650. if ( onLoad ) onLoad( texture );
  8651. }
  8652. }, onProgress, onError );
  8653. };
  8654. for ( var i = 0, il = url.length; i < il; ++ i ) {
  8655. loadTexture( i );
  8656. }
  8657. } else {
  8658. // compressed cubemap texture stored in a single DDS file
  8659. loader.load( url, function ( buffer ) {
  8660. var texDatas = scope._parser( buffer, true );
  8661. if ( texDatas.isCubemap ) {
  8662. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  8663. for ( var f = 0; f < faces; f ++ ) {
  8664. images[ f ] = { mipmaps : [] };
  8665. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  8666. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  8667. images[ f ].format = texDatas.format;
  8668. images[ f ].width = texDatas.width;
  8669. images[ f ].height = texDatas.height;
  8670. }
  8671. }
  8672. } else {
  8673. texture.image.width = texDatas.width;
  8674. texture.image.height = texDatas.height;
  8675. texture.mipmaps = texDatas.mipmaps;
  8676. }
  8677. if ( texDatas.mipmapCount === 1 ) {
  8678. texture.minFilter = THREE.LinearFilter;
  8679. }
  8680. texture.format = texDatas.format;
  8681. texture.needsUpdate = true;
  8682. if ( onLoad ) onLoad( texture );
  8683. }, onProgress, onError );
  8684. }
  8685. return texture;
  8686. },
  8687. setCrossOrigin: function ( value ) {
  8688. this.crossOrigin = value;
  8689. }
  8690. };
  8691. // File:src/materials/Material.js
  8692. /**
  8693. * @author mrdoob / http://mrdoob.com/
  8694. * @author alteredq / http://alteredqualia.com/
  8695. */
  8696. THREE.Material = function () {
  8697. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  8698. this.uuid = THREE.Math.generateUUID();
  8699. this.name = '';
  8700. this.type = 'Material';
  8701. this.side = THREE.FrontSide;
  8702. this.opacity = 1;
  8703. this.transparent = false;
  8704. this.blending = THREE.NormalBlending;
  8705. this.blendSrc = THREE.SrcAlphaFactor;
  8706. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  8707. this.blendEquation = THREE.AddEquation;
  8708. this.blendSrcAlpha = null;
  8709. this.blendDstAlpha = null;
  8710. this.blendEquationAlpha = null;
  8711. this.depthFunc = THREE.LessEqualDepth;
  8712. this.depthTest = true;
  8713. this.depthWrite = true;
  8714. this.colorWrite = true;
  8715. this.polygonOffset = false;
  8716. this.polygonOffsetFactor = 0;
  8717. this.polygonOffsetUnits = 0;
  8718. this.alphaTest = 0;
  8719. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  8720. this.visible = true;
  8721. this._needsUpdate = true;
  8722. };
  8723. THREE.Material.prototype = {
  8724. constructor: THREE.Material,
  8725. get needsUpdate () {
  8726. return this._needsUpdate;
  8727. },
  8728. set needsUpdate ( value ) {
  8729. if ( value === true ) this.update();
  8730. this._needsUpdate = value;
  8731. },
  8732. setValues: function ( values ) {
  8733. if ( values === undefined ) return;
  8734. for ( var key in values ) {
  8735. var newValue = values[ key ];
  8736. if ( newValue === undefined ) {
  8737. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  8738. continue;
  8739. }
  8740. if ( key in this ) {
  8741. var currentValue = this[ key ];
  8742. if ( currentValue instanceof THREE.Color ) {
  8743. currentValue.set( newValue );
  8744. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  8745. currentValue.copy( newValue );
  8746. } else if ( key === 'overdraw' ) {
  8747. // ensure overdraw is backwards-compatible with legacy boolean type
  8748. this[ key ] = Number( newValue );
  8749. } else {
  8750. this[ key ] = newValue;
  8751. }
  8752. }
  8753. }
  8754. },
  8755. toJSON: function ( meta ) {
  8756. var data = {
  8757. metadata: {
  8758. version: 4.4,
  8759. type: 'Material',
  8760. generator: 'Material.toJSON'
  8761. }
  8762. };
  8763. // standard Material serialization
  8764. data.uuid = this.uuid;
  8765. data.type = this.type;
  8766. if ( this.name !== '' ) data.name = this.name;
  8767. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  8768. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  8769. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  8770. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  8771. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  8772. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  8773. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  8774. if ( this.bumpMap instanceof THREE.Texture ) {
  8775. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  8776. data.bumpScale = this.bumpScale;
  8777. }
  8778. if ( this.normalMap instanceof THREE.Texture ) {
  8779. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  8780. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  8781. }
  8782. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  8783. if ( this.envMap instanceof THREE.Texture ) {
  8784. data.envMap = this.envMap.toJSON( meta ).uuid;
  8785. data.reflectivity = this.reflectivity; // Scale behind envMap
  8786. }
  8787. if ( this.size !== undefined ) data.size = this.size;
  8788. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  8789. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  8790. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  8791. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  8792. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  8793. if ( this.opacity < 1 ) data.opacity = this.opacity;
  8794. if ( this.transparent === true ) data.transparent = this.transparent;
  8795. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  8796. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  8797. return data;
  8798. },
  8799. clone: function () {
  8800. return new THREE.Material().copy( this );
  8801. },
  8802. copy: function ( source ) {
  8803. this.name = source.name;
  8804. this.side = source.side;
  8805. this.opacity = source.opacity;
  8806. this.transparent = source.transparent;
  8807. this.blending = source.blending;
  8808. this.blendSrc = source.blendSrc;
  8809. this.blendDst = source.blendDst;
  8810. this.blendEquation = source.blendEquation;
  8811. this.blendSrcAlpha = source.blendSrcAlpha;
  8812. this.blendDstAlpha = source.blendDstAlpha;
  8813. this.blendEquationAlpha = source.blendEquationAlpha;
  8814. this.depthFunc = source.depthFunc;
  8815. this.depthTest = source.depthTest;
  8816. this.depthWrite = source.depthWrite;
  8817. this.polygonOffset = source.polygonOffset;
  8818. this.polygonOffsetFactor = source.polygonOffsetFactor;
  8819. this.polygonOffsetUnits = source.polygonOffsetUnits;
  8820. this.alphaTest = source.alphaTest;
  8821. this.overdraw = source.overdraw;
  8822. this.visible = source.visible;
  8823. return this;
  8824. },
  8825. update: function () {
  8826. this.dispatchEvent( { type: 'update' } );
  8827. },
  8828. dispose: function () {
  8829. this.dispatchEvent( { type: 'dispose' } );
  8830. }
  8831. };
  8832. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  8833. THREE.MaterialIdCount = 0;
  8834. // File:src/materials/LineBasicMaterial.js
  8835. /**
  8836. * @author mrdoob / http://mrdoob.com/
  8837. * @author alteredq / http://alteredqualia.com/
  8838. *
  8839. * parameters = {
  8840. * color: <hex>,
  8841. * opacity: <float>,
  8842. *
  8843. * blending: THREE.NormalBlending,
  8844. * depthTest: <bool>,
  8845. * depthWrite: <bool>,
  8846. *
  8847. * linewidth: <float>,
  8848. * linecap: "round",
  8849. * linejoin: "round",
  8850. *
  8851. * vertexColors: <bool>
  8852. *
  8853. * fog: <bool>
  8854. * }
  8855. */
  8856. THREE.LineBasicMaterial = function ( parameters ) {
  8857. THREE.Material.call( this );
  8858. this.type = 'LineBasicMaterial';
  8859. this.color = new THREE.Color( 0xffffff );
  8860. this.linewidth = 1;
  8861. this.linecap = 'round';
  8862. this.linejoin = 'round';
  8863. this.vertexColors = THREE.NoColors;
  8864. this.fog = true;
  8865. this.setValues( parameters );
  8866. };
  8867. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8868. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  8869. THREE.LineBasicMaterial.prototype.clone = function () {
  8870. var material = new THREE.LineBasicMaterial();
  8871. material.copy( this );
  8872. material.color.copy( this.color );
  8873. material.linewidth = this.linewidth;
  8874. material.linecap = this.linecap;
  8875. material.linejoin = this.linejoin;
  8876. material.vertexColors = this.vertexColors;
  8877. material.fog = this.fog;
  8878. return material;
  8879. };
  8880. // File:src/materials/LineDashedMaterial.js
  8881. /**
  8882. * @author alteredq / http://alteredqualia.com/
  8883. *
  8884. * parameters = {
  8885. * color: <hex>,
  8886. * opacity: <float>,
  8887. *
  8888. * blending: THREE.NormalBlending,
  8889. * depthTest: <bool>,
  8890. * depthWrite: <bool>,
  8891. *
  8892. * linewidth: <float>,
  8893. *
  8894. * scale: <float>,
  8895. * dashSize: <float>,
  8896. * gapSize: <float>,
  8897. *
  8898. * vertexColors: <bool>
  8899. *
  8900. * fog: <bool>
  8901. * }
  8902. */
  8903. THREE.LineDashedMaterial = function ( parameters ) {
  8904. THREE.Material.call( this );
  8905. this.type = 'LineDashedMaterial';
  8906. this.color = new THREE.Color( 0xffffff );
  8907. this.linewidth = 1;
  8908. this.scale = 1;
  8909. this.dashSize = 3;
  8910. this.gapSize = 1;
  8911. this.vertexColors = false;
  8912. this.fog = true;
  8913. this.setValues( parameters );
  8914. };
  8915. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  8916. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  8917. THREE.LineDashedMaterial.prototype.clone = function () {
  8918. var material = new THREE.LineDashedMaterial();
  8919. material.copy( this );
  8920. material.color.copy( this.color );
  8921. material.linewidth = this.linewidth;
  8922. material.scale = this.scale;
  8923. material.dashSize = this.dashSize;
  8924. material.gapSize = this.gapSize;
  8925. material.vertexColors = this.vertexColors;
  8926. material.fog = this.fog;
  8927. return material;
  8928. };
  8929. // File:src/materials/MeshBasicMaterial.js
  8930. /**
  8931. * @author mrdoob / http://mrdoob.com/
  8932. * @author alteredq / http://alteredqualia.com/
  8933. *
  8934. * parameters = {
  8935. * color: <hex>,
  8936. * opacity: <float>,
  8937. * map: new THREE.Texture( <Image> ),
  8938. *
  8939. * aoMap: new THREE.Texture( <Image> ),
  8940. * aoMapIntensity: <float>
  8941. *
  8942. * specularMap: new THREE.Texture( <Image> ),
  8943. *
  8944. * alphaMap: new THREE.Texture( <Image> ),
  8945. *
  8946. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8947. * combine: THREE.Multiply,
  8948. * reflectivity: <float>,
  8949. * refractionRatio: <float>,
  8950. *
  8951. * shading: THREE.SmoothShading,
  8952. * blending: THREE.NormalBlending,
  8953. * depthTest: <bool>,
  8954. * depthWrite: <bool>,
  8955. *
  8956. * wireframe: <boolean>,
  8957. * wireframeLinewidth: <float>,
  8958. *
  8959. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8960. *
  8961. * skinning: <bool>,
  8962. * morphTargets: <bool>,
  8963. *
  8964. * fog: <bool>
  8965. * }
  8966. */
  8967. THREE.MeshBasicMaterial = function ( parameters ) {
  8968. THREE.Material.call( this );
  8969. this.type = 'MeshBasicMaterial';
  8970. this.color = new THREE.Color( 0xffffff ); // emissive
  8971. this.map = null;
  8972. this.aoMap = null;
  8973. this.aoMapIntensity = 1.0;
  8974. this.specularMap = null;
  8975. this.alphaMap = null;
  8976. this.envMap = null;
  8977. this.combine = THREE.MultiplyOperation;
  8978. this.reflectivity = 1;
  8979. this.refractionRatio = 0.98;
  8980. this.fog = true;
  8981. this.shading = THREE.SmoothShading;
  8982. this.wireframe = false;
  8983. this.wireframeLinewidth = 1;
  8984. this.wireframeLinecap = 'round';
  8985. this.wireframeLinejoin = 'round';
  8986. this.vertexColors = THREE.NoColors;
  8987. this.skinning = false;
  8988. this.morphTargets = false;
  8989. this.setValues( parameters );
  8990. };
  8991. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8992. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  8993. THREE.MeshBasicMaterial.prototype.clone = function () {
  8994. var material = new THREE.MeshBasicMaterial();
  8995. material.copy( this );
  8996. material.color.copy( this.color );
  8997. material.map = this.map;
  8998. material.aoMap = this.aoMap;
  8999. material.aoMapIntensity = this.aoMapIntensity;
  9000. material.specularMap = this.specularMap;
  9001. material.alphaMap = this.alphaMap;
  9002. material.envMap = this.envMap;
  9003. material.combine = this.combine;
  9004. material.reflectivity = this.reflectivity;
  9005. material.refractionRatio = this.refractionRatio;
  9006. material.fog = this.fog;
  9007. material.shading = this.shading;
  9008. material.wireframe = this.wireframe;
  9009. material.wireframeLinewidth = this.wireframeLinewidth;
  9010. material.wireframeLinecap = this.wireframeLinecap;
  9011. material.wireframeLinejoin = this.wireframeLinejoin;
  9012. material.vertexColors = this.vertexColors;
  9013. material.skinning = this.skinning;
  9014. material.morphTargets = this.morphTargets;
  9015. return material;
  9016. };
  9017. // File:src/materials/MeshLambertMaterial.js
  9018. /**
  9019. * @author mrdoob / http://mrdoob.com/
  9020. * @author alteredq / http://alteredqualia.com/
  9021. *
  9022. * parameters = {
  9023. * color: <hex>,
  9024. * emissive: <hex>,
  9025. * opacity: <float>,
  9026. *
  9027. * map: new THREE.Texture( <Image> ),
  9028. *
  9029. * specularMap: new THREE.Texture( <Image> ),
  9030. *
  9031. * alphaMap: new THREE.Texture( <Image> ),
  9032. *
  9033. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  9034. * combine: THREE.Multiply,
  9035. * reflectivity: <float>,
  9036. * refractionRatio: <float>,
  9037. *
  9038. * shading: THREE.SmoothShading,
  9039. * blending: THREE.NormalBlending,
  9040. * depthTest: <bool>,
  9041. * depthWrite: <bool>,
  9042. *
  9043. * wireframe: <boolean>,
  9044. * wireframeLinewidth: <float>,
  9045. *
  9046. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9047. *
  9048. * skinning: <bool>,
  9049. * morphTargets: <bool>,
  9050. * morphNormals: <bool>,
  9051. *
  9052. * fog: <bool>
  9053. * }
  9054. */
  9055. THREE.MeshLambertMaterial = function ( parameters ) {
  9056. THREE.Material.call( this );
  9057. this.type = 'MeshLambertMaterial';
  9058. this.color = new THREE.Color( 0xffffff ); // diffuse
  9059. this.emissive = new THREE.Color( 0x000000 );
  9060. this.map = null;
  9061. this.specularMap = null;
  9062. this.alphaMap = null;
  9063. this.envMap = null;
  9064. this.combine = THREE.MultiplyOperation;
  9065. this.reflectivity = 1;
  9066. this.refractionRatio = 0.98;
  9067. this.fog = true;
  9068. this.shading = THREE.SmoothShading;
  9069. this.wireframe = false;
  9070. this.wireframeLinewidth = 1;
  9071. this.wireframeLinecap = 'round';
  9072. this.wireframeLinejoin = 'round';
  9073. this.vertexColors = THREE.NoColors;
  9074. this.skinning = false;
  9075. this.morphTargets = false;
  9076. this.morphNormals = false;
  9077. this.setValues( parameters );
  9078. };
  9079. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  9080. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  9081. THREE.MeshLambertMaterial.prototype.clone = function () {
  9082. var material = new THREE.MeshLambertMaterial();
  9083. material.copy( this );
  9084. material.color.copy( this.color );
  9085. material.emissive.copy( this.emissive );
  9086. material.map = this.map;
  9087. material.specularMap = this.specularMap;
  9088. material.alphaMap = this.alphaMap;
  9089. material.envMap = this.envMap;
  9090. material.combine = this.combine;
  9091. material.reflectivity = this.reflectivity;
  9092. material.refractionRatio = this.refractionRatio;
  9093. material.fog = this.fog;
  9094. material.shading = this.shading;
  9095. material.wireframe = this.wireframe;
  9096. material.wireframeLinewidth = this.wireframeLinewidth;
  9097. material.wireframeLinecap = this.wireframeLinecap;
  9098. material.wireframeLinejoin = this.wireframeLinejoin;
  9099. material.vertexColors = this.vertexColors;
  9100. material.skinning = this.skinning;
  9101. material.morphTargets = this.morphTargets;
  9102. material.morphNormals = this.morphNormals;
  9103. return material;
  9104. };
  9105. // File:src/materials/MeshPhongMaterial.js
  9106. /**
  9107. * @author mrdoob / http://mrdoob.com/
  9108. * @author alteredq / http://alteredqualia.com/
  9109. *
  9110. * parameters = {
  9111. * color: <hex>,
  9112. * emissive: <hex>,
  9113. * specular: <hex>,
  9114. * shininess: <float>,
  9115. * opacity: <float>,
  9116. *
  9117. * map: new THREE.Texture( <Image> ),
  9118. *
  9119. * lightMap: new THREE.Texture( <Image> ),
  9120. * lightMapIntensity: <float>
  9121. *
  9122. * aoMap: new THREE.Texture( <Image> ),
  9123. * aoMapIntensity: <float>
  9124. *
  9125. * emissiveMap: new THREE.Texture( <Image> ),
  9126. *
  9127. * bumpMap: new THREE.Texture( <Image> ),
  9128. * bumpScale: <float>,
  9129. *
  9130. * normalMap: new THREE.Texture( <Image> ),
  9131. * normalScale: <Vector2>,
  9132. *
  9133. * specularMap: new THREE.Texture( <Image> ),
  9134. *
  9135. * alphaMap: new THREE.Texture( <Image> ),
  9136. *
  9137. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  9138. * combine: THREE.Multiply,
  9139. * reflectivity: <float>,
  9140. * refractionRatio: <float>,
  9141. *
  9142. * shading: THREE.SmoothShading,
  9143. * blending: THREE.NormalBlending,
  9144. * depthTest: <bool>,
  9145. * depthWrite: <bool>,
  9146. *
  9147. * wireframe: <boolean>,
  9148. * wireframeLinewidth: <float>,
  9149. *
  9150. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9151. *
  9152. * skinning: <bool>,
  9153. * morphTargets: <bool>,
  9154. * morphNormals: <bool>,
  9155. *
  9156. * fog: <bool>
  9157. * }
  9158. */
  9159. THREE.MeshPhongMaterial = function ( parameters ) {
  9160. THREE.Material.call( this );
  9161. this.type = 'MeshPhongMaterial';
  9162. this.color = new THREE.Color( 0xffffff ); // diffuse
  9163. this.emissive = new THREE.Color( 0x000000 );
  9164. this.specular = new THREE.Color( 0x111111 );
  9165. this.shininess = 30;
  9166. this.metal = false;
  9167. this.map = null;
  9168. this.lightMap = null;
  9169. this.lightMapIntensity = 1.0;
  9170. this.aoMap = null;
  9171. this.aoMapIntensity = 1.0;
  9172. this.emissiveMap = null;
  9173. this.bumpMap = null;
  9174. this.bumpScale = 1;
  9175. this.normalMap = null;
  9176. this.normalScale = new THREE.Vector2( 1, 1 );
  9177. this.specularMap = null;
  9178. this.alphaMap = null;
  9179. this.envMap = null;
  9180. this.combine = THREE.MultiplyOperation;
  9181. this.reflectivity = 1;
  9182. this.refractionRatio = 0.98;
  9183. this.fog = true;
  9184. this.shading = THREE.SmoothShading;
  9185. this.wireframe = false;
  9186. this.wireframeLinewidth = 1;
  9187. this.wireframeLinecap = 'round';
  9188. this.wireframeLinejoin = 'round';
  9189. this.vertexColors = THREE.NoColors;
  9190. this.skinning = false;
  9191. this.morphTargets = false;
  9192. this.morphNormals = false;
  9193. this.setValues( parameters );
  9194. };
  9195. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  9196. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  9197. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  9198. THREE.Material.prototype.copy.call( this, source );
  9199. this.color.copy( source.color );
  9200. this.emissive.copy( source.emissive );
  9201. this.specular.copy( source.specular );
  9202. this.shininess = source.shininess;
  9203. this.metal = source.metal;
  9204. this.map = source.map;
  9205. this.lightMap = source.lightMap;
  9206. this.lightMapIntensity = source.lightMapIntensity;
  9207. this.aoMap = source.aoMap;
  9208. this.aoMapIntensity = source.aoMapIntensity;
  9209. this.emissiveMap = source.emissiveMap;
  9210. this.bumpMap = source.bumpMap;
  9211. this.bumpScale = source.bumpScale;
  9212. this.normalMap = source.normalMap;
  9213. this.normalScale.copy( source.normalScale );
  9214. this.specularMap = source.specularMap;
  9215. this.alphaMap = source.alphaMap;
  9216. this.envMap = source.envMap;
  9217. this.combine = source.combine;
  9218. this.reflectivity = source.reflectivity;
  9219. this.refractionRatio = source.refractionRatio;
  9220. this.fog = source.fog;
  9221. this.shading = source.shading;
  9222. this.wireframe = source.wireframe;
  9223. this.wireframeLinewidth = source.wireframeLinewidth;
  9224. this.wireframeLinecap = source.wireframeLinecap;
  9225. this.wireframeLinejoin = source.wireframeLinejoin;
  9226. this.vertexColors = source.vertexColors;
  9227. this.skinning = source.skinning;
  9228. this.morphTargets = source.morphTargets;
  9229. this.morphNormals = source.morphNormals;
  9230. return this;
  9231. };
  9232. THREE.MeshPhongMaterial.prototype.clone = function () {
  9233. return new THREE.MeshPhongMaterial().copy( this );
  9234. };
  9235. // File:src/materials/MeshDepthMaterial.js
  9236. /**
  9237. * @author mrdoob / http://mrdoob.com/
  9238. * @author alteredq / http://alteredqualia.com/
  9239. *
  9240. * parameters = {
  9241. * opacity: <float>,
  9242. *
  9243. * blending: THREE.NormalBlending,
  9244. * depthTest: <bool>,
  9245. * depthWrite: <bool>,
  9246. *
  9247. * wireframe: <boolean>,
  9248. * wireframeLinewidth: <float>
  9249. * }
  9250. */
  9251. THREE.MeshDepthMaterial = function ( parameters ) {
  9252. THREE.Material.call( this );
  9253. this.type = 'MeshDepthMaterial';
  9254. this.morphTargets = false;
  9255. this.wireframe = false;
  9256. this.wireframeLinewidth = 1;
  9257. this.setValues( parameters );
  9258. };
  9259. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  9260. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  9261. THREE.MeshDepthMaterial.prototype.clone = function () {
  9262. var material = new THREE.MeshDepthMaterial();
  9263. material.copy( this );
  9264. material.wireframe = this.wireframe;
  9265. material.wireframeLinewidth = this.wireframeLinewidth;
  9266. return material;
  9267. };
  9268. // File:src/materials/MeshNormalMaterial.js
  9269. /**
  9270. * @author mrdoob / http://mrdoob.com/
  9271. *
  9272. * parameters = {
  9273. * opacity: <float>,
  9274. *
  9275. * shading: THREE.FlatShading,
  9276. * blending: THREE.NormalBlending,
  9277. * depthTest: <bool>,
  9278. * depthWrite: <bool>,
  9279. *
  9280. * wireframe: <boolean>,
  9281. * wireframeLinewidth: <float>
  9282. * }
  9283. */
  9284. THREE.MeshNormalMaterial = function ( parameters ) {
  9285. THREE.Material.call( this, parameters );
  9286. this.type = 'MeshNormalMaterial';
  9287. this.wireframe = false;
  9288. this.wireframeLinewidth = 1;
  9289. this.morphTargets = false;
  9290. this.setValues( parameters );
  9291. };
  9292. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  9293. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  9294. THREE.MeshNormalMaterial.prototype.clone = function () {
  9295. var material = new THREE.MeshNormalMaterial();
  9296. material.copy( this );
  9297. material.wireframe = this.wireframe;
  9298. material.wireframeLinewidth = this.wireframeLinewidth;
  9299. return material;
  9300. };
  9301. // File:src/materials/MeshFaceMaterial.js
  9302. /**
  9303. * @author mrdoob / http://mrdoob.com/
  9304. */
  9305. THREE.MeshFaceMaterial = function ( materials ) {
  9306. this.uuid = THREE.Math.generateUUID();
  9307. this.type = 'MeshFaceMaterial';
  9308. this.materials = materials instanceof Array ? materials : [];
  9309. this.visible = true;
  9310. };
  9311. THREE.MeshFaceMaterial.prototype = {
  9312. constructor: THREE.MeshFaceMaterial,
  9313. toJSON: function () {
  9314. var output = {
  9315. metadata: {
  9316. version: 4.2,
  9317. type: 'material',
  9318. generator: 'MaterialExporter'
  9319. },
  9320. uuid: this.uuid,
  9321. type: this.type,
  9322. materials: []
  9323. };
  9324. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  9325. output.materials.push( this.materials[ i ].toJSON() );
  9326. }
  9327. output.visible = this.visible;
  9328. return output;
  9329. },
  9330. clone: function () {
  9331. var material = new THREE.MeshFaceMaterial();
  9332. for ( var i = 0; i < this.materials.length; i ++ ) {
  9333. material.materials.push( this.materials[ i ].clone() );
  9334. }
  9335. material.visible = this.visible;
  9336. return material;
  9337. }
  9338. };
  9339. // File:src/materials/PointCloudMaterial.js
  9340. /**
  9341. * @author mrdoob / http://mrdoob.com/
  9342. * @author alteredq / http://alteredqualia.com/
  9343. *
  9344. * parameters = {
  9345. * color: <hex>,
  9346. * opacity: <float>,
  9347. * map: new THREE.Texture( <Image> ),
  9348. *
  9349. * size: <float>,
  9350. * sizeAttenuation: <bool>,
  9351. *
  9352. * blending: THREE.NormalBlending,
  9353. * depthTest: <bool>,
  9354. * depthWrite: <bool>,
  9355. *
  9356. * vertexColors: <bool>,
  9357. *
  9358. * fog: <bool>
  9359. * }
  9360. */
  9361. THREE.PointCloudMaterial = function ( parameters ) {
  9362. THREE.Material.call( this );
  9363. this.type = 'PointCloudMaterial';
  9364. this.color = new THREE.Color( 0xffffff );
  9365. this.map = null;
  9366. this.size = 1;
  9367. this.sizeAttenuation = true;
  9368. this.vertexColors = THREE.NoColors;
  9369. this.fog = true;
  9370. this.setValues( parameters );
  9371. };
  9372. THREE.PointCloudMaterial.prototype = Object.create( THREE.Material.prototype );
  9373. THREE.PointCloudMaterial.prototype.constructor = THREE.PointCloudMaterial;
  9374. THREE.PointCloudMaterial.prototype.clone = function () {
  9375. var material = new THREE.PointCloudMaterial();
  9376. material.copy( this );
  9377. material.color.copy( this.color );
  9378. material.map = this.map;
  9379. material.size = this.size;
  9380. material.sizeAttenuation = this.sizeAttenuation;
  9381. material.vertexColors = this.vertexColors;
  9382. material.fog = this.fog;
  9383. return material;
  9384. };
  9385. // backwards compatibility
  9386. THREE.ParticleBasicMaterial = function ( parameters ) {
  9387. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointCloudMaterial.' );
  9388. return new THREE.PointCloudMaterial( parameters );
  9389. };
  9390. THREE.ParticleSystemMaterial = function ( parameters ) {
  9391. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointCloudMaterial.' );
  9392. return new THREE.PointCloudMaterial( parameters );
  9393. };
  9394. // File:src/materials/ShaderMaterial.js
  9395. /**
  9396. * @author alteredq / http://alteredqualia.com/
  9397. *
  9398. * parameters = {
  9399. * defines: { "label" : "value" },
  9400. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  9401. *
  9402. * fragmentShader: <string>,
  9403. * vertexShader: <string>,
  9404. *
  9405. * shading: THREE.SmoothShading,
  9406. * blending: THREE.NormalBlending,
  9407. * depthTest: <bool>,
  9408. * depthWrite: <bool>,
  9409. *
  9410. * wireframe: <boolean>,
  9411. * wireframeLinewidth: <float>,
  9412. *
  9413. * lights: <bool>,
  9414. *
  9415. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9416. *
  9417. * skinning: <bool>,
  9418. * morphTargets: <bool>,
  9419. * morphNormals: <bool>,
  9420. *
  9421. * fog: <bool>
  9422. * }
  9423. */
  9424. THREE.ShaderMaterial = function ( parameters ) {
  9425. THREE.Material.call( this );
  9426. this.type = 'ShaderMaterial';
  9427. this.defines = {};
  9428. this.uniforms = {};
  9429. this.attributes = [];
  9430. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  9431. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  9432. this.shading = THREE.SmoothShading;
  9433. this.linewidth = 1;
  9434. this.wireframe = false;
  9435. this.wireframeLinewidth = 1;
  9436. this.fog = false; // set to use scene fog
  9437. this.lights = false; // set to use scene lights
  9438. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  9439. this.skinning = false; // set to use skinning attribute streams
  9440. this.morphTargets = false; // set to use morph targets
  9441. this.morphNormals = false; // set to use morph normals
  9442. this.derivatives = false; // set to use derivatives
  9443. // When rendered geometry doesn't include these attributes but the material does,
  9444. // use these default values in WebGL. This avoids errors when buffer data is missing.
  9445. this.defaultAttributeValues = {
  9446. 'color': [ 1, 1, 1 ],
  9447. 'uv': [ 0, 0 ],
  9448. 'uv2': [ 0, 0 ]
  9449. };
  9450. this.index0AttributeName = undefined;
  9451. if ( parameters !== undefined ) {
  9452. if ( parameters.attributes !== undefined && Array.isArray( parameters.attributes ) === false ) {
  9453. console.warn( 'THREE.ShaderMaterial: attributes should now be an array of attribute names.' );
  9454. parameters.attributes = Object.keys( parameters.attributes );
  9455. }
  9456. this.setValues( parameters );
  9457. }
  9458. };
  9459. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  9460. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  9461. THREE.ShaderMaterial.prototype.clone = function () {
  9462. var material = new THREE.ShaderMaterial();
  9463. return material.copy( this );
  9464. };
  9465. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  9466. THREE.Material.prototype.copy.call( this, source );
  9467. this.fragmentShader = source.fragmentShader;
  9468. this.vertexShader = source.vertexShader;
  9469. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  9470. this.attributes = source.attributes;
  9471. this.defines = source.defines;
  9472. this.shading = source.shading;
  9473. this.wireframe = source.wireframe;
  9474. this.wireframeLinewidth = source.wireframeLinewidth;
  9475. this.fog = source.fog;
  9476. this.lights = source.lights;
  9477. this.vertexColors = source.vertexColors;
  9478. this.skinning = source.skinning;
  9479. this.morphTargets = source.morphTargets;
  9480. this.morphNormals = source.morphNormals;
  9481. return this;
  9482. };
  9483. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  9484. var data = THREE.Material.prototype.toJSON.call( this, meta );
  9485. data.uniforms = this.uniforms;
  9486. data.attributes = this.attributes;
  9487. data.vertexShader = this.vertexShader;
  9488. data.fragmentShader = this.fragmentShader;
  9489. return data;
  9490. };
  9491. // File:src/materials/RawShaderMaterial.js
  9492. /**
  9493. * @author mrdoob / http://mrdoob.com/
  9494. */
  9495. THREE.RawShaderMaterial = function ( parameters ) {
  9496. THREE.ShaderMaterial.call( this, parameters );
  9497. this.type = 'RawShaderMaterial';
  9498. };
  9499. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  9500. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  9501. THREE.RawShaderMaterial.prototype.clone = function () {
  9502. var material = new THREE.RawShaderMaterial();
  9503. material.copy( this );
  9504. return material;
  9505. };
  9506. // File:src/materials/SpriteMaterial.js
  9507. /**
  9508. * @author alteredq / http://alteredqualia.com/
  9509. *
  9510. * parameters = {
  9511. * color: <hex>,
  9512. * opacity: <float>,
  9513. * map: new THREE.Texture( <Image> ),
  9514. *
  9515. * blending: THREE.NormalBlending,
  9516. * depthTest: <bool>,
  9517. * depthWrite: <bool>,
  9518. *
  9519. * uvOffset: new THREE.Vector2(),
  9520. * uvScale: new THREE.Vector2(),
  9521. *
  9522. * fog: <bool>
  9523. * }
  9524. */
  9525. THREE.SpriteMaterial = function ( parameters ) {
  9526. THREE.Material.call( this );
  9527. this.type = 'SpriteMaterial';
  9528. this.color = new THREE.Color( 0xffffff );
  9529. this.map = null;
  9530. this.rotation = 0;
  9531. this.fog = false;
  9532. // set parameters
  9533. this.setValues( parameters );
  9534. };
  9535. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  9536. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  9537. THREE.SpriteMaterial.prototype.clone = function () {
  9538. var material = new THREE.SpriteMaterial();
  9539. material.copy( this );
  9540. material.color.copy( this.color );
  9541. material.map = this.map;
  9542. material.rotation = this.rotation;
  9543. material.fog = this.fog;
  9544. return material;
  9545. };
  9546. // File:src/textures/Texture.js
  9547. /**
  9548. * @author mrdoob / http://mrdoob.com/
  9549. * @author alteredq / http://alteredqualia.com/
  9550. * @author szimek / https://github.com/szimek/
  9551. */
  9552. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9553. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  9554. this.uuid = THREE.Math.generateUUID();
  9555. this.name = '';
  9556. this.sourceFile = '';
  9557. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  9558. this.mipmaps = [];
  9559. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  9560. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  9561. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  9562. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  9563. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  9564. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  9565. this.format = format !== undefined ? format : THREE.RGBAFormat;
  9566. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  9567. this.offset = new THREE.Vector2( 0, 0 );
  9568. this.repeat = new THREE.Vector2( 1, 1 );
  9569. this.generateMipmaps = true;
  9570. this.premultiplyAlpha = false;
  9571. this.flipY = true;
  9572. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  9573. this.version = 0;
  9574. this.onUpdate = null;
  9575. };
  9576. THREE.Texture.DEFAULT_IMAGE = undefined;
  9577. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  9578. THREE.Texture.prototype = {
  9579. constructor: THREE.Texture,
  9580. set needsUpdate ( value ) {
  9581. if ( value === true ) this.version ++;
  9582. },
  9583. clone: function () {
  9584. return new THREE.Texture().copy( this );
  9585. },
  9586. copy: function ( source ) {
  9587. this.image = source.image;
  9588. this.mipmaps = source.mipmaps.slice( 0 );
  9589. this.mapping = source.mapping;
  9590. this.wrapS = source.wrapS;
  9591. this.wrapT = source.wrapT;
  9592. this.magFilter = source.magFilter;
  9593. this.minFilter = source.minFilter;
  9594. this.anisotropy = source.anisotropy;
  9595. this.format = source.format;
  9596. this.type = source.type;
  9597. this.offset.copy( source.offset );
  9598. this.repeat.copy( source.repeat );
  9599. this.generateMipmaps = source.generateMipmaps;
  9600. this.premultiplyAlpha = source.premultiplyAlpha;
  9601. this.flipY = source.flipY;
  9602. this.unpackAlignment = source.unpackAlignment;
  9603. return this;
  9604. },
  9605. toJSON: function ( meta ) {
  9606. if ( meta.textures[ this.uuid ] !== undefined ) {
  9607. return meta.textures[ this.uuid ];
  9608. }
  9609. function getDataURL( image ) {
  9610. var canvas;
  9611. if ( image.toDataURL !== undefined ) {
  9612. canvas = image;
  9613. } else {
  9614. canvas = document.createElement( 'canvas' );
  9615. canvas.width = image.width;
  9616. canvas.height = image.height;
  9617. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  9618. }
  9619. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  9620. return canvas.toDataURL( 'image/jpeg', 0.6 );
  9621. } else {
  9622. return canvas.toDataURL( 'image/png' );
  9623. }
  9624. }
  9625. var output = {
  9626. metadata: {
  9627. version: 4.4,
  9628. type: 'Texture',
  9629. generator: 'Texture.toJSON'
  9630. },
  9631. uuid: this.uuid,
  9632. name: this.name,
  9633. mapping: this.mapping,
  9634. repeat: [ this.repeat.x, this.repeat.y ],
  9635. offset: [ this.offset.x, this.offset.y ],
  9636. wrap: [ this.wrapS, this.wrapT ],
  9637. minFilter: this.minFilter,
  9638. magFilter: this.magFilter,
  9639. anisotropy: this.anisotropy
  9640. };
  9641. if ( this.image !== undefined ) {
  9642. // TODO: Move to THREE.Image
  9643. var image = this.image;
  9644. if ( image.uuid === undefined ) {
  9645. image.uuid = THREE.Math.generateUUID(); // UGH
  9646. }
  9647. if ( meta.images[ image.uuid ] === undefined ) {
  9648. meta.images[ image.uuid ] = {
  9649. uuid: image.uuid,
  9650. url: getDataURL( image )
  9651. };
  9652. }
  9653. output.image = image.uuid;
  9654. }
  9655. meta.textures[ this.uuid ] = output;
  9656. return output;
  9657. },
  9658. dispose: function () {
  9659. this.dispatchEvent( { type: 'dispose' } );
  9660. }
  9661. };
  9662. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  9663. THREE.TextureIdCount = 0;
  9664. // File:src/textures/CubeTexture.js
  9665. /**
  9666. * @author mrdoob / http://mrdoob.com/
  9667. */
  9668. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9669. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  9670. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9671. this.images = images;
  9672. this.flipY = false;
  9673. };
  9674. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  9675. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  9676. THREE.CubeTexture.clone = function () {
  9677. var texture = new THREE.CubeTexture();
  9678. texture.copy( this );
  9679. texture.images = this.images;
  9680. return texture;
  9681. };
  9682. // File:src/textures/CompressedTexture.js
  9683. /**
  9684. * @author alteredq / http://alteredqualia.com/
  9685. */
  9686. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9687. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9688. this.image = { width: width, height: height };
  9689. this.mipmaps = mipmaps;
  9690. // no flipping for cube textures
  9691. // (also flipping doesn't work for compressed textures )
  9692. this.flipY = false;
  9693. // can't generate mipmaps for compressed textures
  9694. // mips must be embedded in DDS files
  9695. this.generateMipmaps = false;
  9696. };
  9697. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  9698. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  9699. THREE.CompressedTexture.prototype.clone = function () {
  9700. var texture = new THREE.CompressedTexture();
  9701. texture.copy( this );
  9702. return texture;
  9703. };
  9704. // File:src/textures/DataTexture.js
  9705. /**
  9706. * @author alteredq / http://alteredqualia.com/
  9707. */
  9708. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9709. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9710. this.image = { data: data, width: width, height: height };
  9711. };
  9712. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  9713. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  9714. THREE.DataTexture.prototype.clone = function () {
  9715. var texture = new THREE.DataTexture();
  9716. texture.copy( this );
  9717. return texture;
  9718. };
  9719. // File:src/textures/VideoTexture.js
  9720. /**
  9721. * @author mrdoob / http://mrdoob.com/
  9722. */
  9723. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9724. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9725. this.generateMipmaps = false;
  9726. var scope = this;
  9727. var update = function () {
  9728. requestAnimationFrame( update );
  9729. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  9730. scope.needsUpdate = true;
  9731. }
  9732. };
  9733. update();
  9734. };
  9735. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  9736. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  9737. // File:src/objects/Group.js
  9738. /**
  9739. * @author mrdoob / http://mrdoob.com/
  9740. */
  9741. THREE.Group = function () {
  9742. THREE.Object3D.call( this );
  9743. this.type = 'Group';
  9744. };
  9745. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  9746. THREE.Group.prototype.constructor = THREE.Group;
  9747. THREE.Group.prototype.clone = function () {
  9748. var group = new THREE.Group();
  9749. return group.copy( this );
  9750. };
  9751. THREE.Group.prototype.copy = function ( source ) {
  9752. THREE.Object3D.prototype.copy.call( this, source );
  9753. return this;
  9754. };
  9755. // File:src/objects/PointCloud.js
  9756. /**
  9757. * @author alteredq / http://alteredqualia.com/
  9758. */
  9759. THREE.PointCloud = function ( geometry, material ) {
  9760. THREE.Object3D.call( this );
  9761. this.type = 'PointCloud';
  9762. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9763. this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } );
  9764. };
  9765. THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype );
  9766. THREE.PointCloud.prototype.constructor = THREE.PointCloud;
  9767. THREE.PointCloud.prototype.raycast = ( function () {
  9768. var inverseMatrix = new THREE.Matrix4();
  9769. var ray = new THREE.Ray();
  9770. return function raycast( raycaster, intersects ) {
  9771. var object = this;
  9772. var geometry = object.geometry;
  9773. var threshold = raycaster.params.PointCloud.threshold;
  9774. inverseMatrix.getInverse( this.matrixWorld );
  9775. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9776. if ( geometry.boundingBox !== null ) {
  9777. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9778. return;
  9779. }
  9780. }
  9781. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  9782. var localThresholdSq = localThreshold * localThreshold;
  9783. var position = new THREE.Vector3();
  9784. var testPoint = function ( point, index ) {
  9785. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  9786. if ( rayPointDistanceSq < localThresholdSq ) {
  9787. var intersectPoint = ray.closestPointToPoint( point );
  9788. intersectPoint.applyMatrix4( object.matrixWorld );
  9789. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  9790. if ( distance < raycaster.near || distance > raycaster.far ) return;
  9791. intersects.push( {
  9792. distance: distance,
  9793. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  9794. point: intersectPoint.clone(),
  9795. index: index,
  9796. face: null,
  9797. object: object
  9798. } );
  9799. }
  9800. };
  9801. if ( geometry instanceof THREE.BufferGeometry ) {
  9802. var attributes = geometry.attributes;
  9803. var positions = attributes.position.array;
  9804. if ( attributes.index !== undefined ) {
  9805. var indices = attributes.index.array;
  9806. var offsets = geometry.drawcalls;
  9807. if ( offsets.length === 0 ) {
  9808. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9809. }
  9810. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9811. var offset = offsets[ oi ];
  9812. var start = offset.start;
  9813. var count = offset.count;
  9814. var index = offset.index;
  9815. for ( var i = start, il = start + count; i < il; i ++ ) {
  9816. var a = index + indices[ i ];
  9817. position.fromArray( positions, a * 3 );
  9818. testPoint( position, a );
  9819. }
  9820. }
  9821. } else {
  9822. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  9823. position.fromArray( positions, i * 3 );
  9824. testPoint( position, i );
  9825. }
  9826. }
  9827. } else {
  9828. var vertices = geometry.vertices;
  9829. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  9830. testPoint( vertices[ i ], i );
  9831. }
  9832. }
  9833. };
  9834. }() );
  9835. THREE.PointCloud.prototype.clone = function () {
  9836. var pointCloud = new THREE.PointCloud( this.geometry, this.material );
  9837. return pointCloud.copy( this );
  9838. };
  9839. THREE.PointCloud.prototype.copy = function ( source ) {
  9840. THREE.Object3D.prototype.copy.call( this, source );
  9841. return this;
  9842. };
  9843. THREE.PointCloud.prototype.toJSON = function ( meta ) {
  9844. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9845. // only serialize if not in meta geometries cache
  9846. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9847. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9848. }
  9849. // only serialize if not in meta materials cache
  9850. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9851. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9852. }
  9853. data.object.geometry = this.geometry.uuid;
  9854. data.object.material = this.material.uuid;
  9855. return data;
  9856. };
  9857. // Backwards compatibility
  9858. THREE.ParticleSystem = function ( geometry, material ) {
  9859. console.warn( 'THREE.ParticleSystem has been renamed to THREE.PointCloud.' );
  9860. return new THREE.PointCloud( geometry, material );
  9861. };
  9862. // File:src/objects/Line.js
  9863. /**
  9864. * @author mrdoob / http://mrdoob.com/
  9865. */
  9866. THREE.Line = function ( geometry, material, mode ) {
  9867. if ( mode === 1 ) {
  9868. console.error( 'THREE.Line: THREE.LinePieces mode has been removed. Use THREE.LineSegments instead.' );
  9869. }
  9870. THREE.Object3D.call( this );
  9871. this.type = 'Line';
  9872. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9873. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  9874. };
  9875. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  9876. THREE.Line.prototype.constructor = THREE.Line;
  9877. THREE.Line.prototype.raycast = ( function () {
  9878. var inverseMatrix = new THREE.Matrix4();
  9879. var ray = new THREE.Ray();
  9880. var sphere = new THREE.Sphere();
  9881. return function raycast( raycaster, intersects ) {
  9882. var precision = raycaster.linePrecision;
  9883. var precisionSq = precision * precision;
  9884. var geometry = this.geometry;
  9885. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9886. // Checking boundingSphere distance to ray
  9887. sphere.copy( geometry.boundingSphere );
  9888. sphere.applyMatrix4( this.matrixWorld );
  9889. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  9890. return;
  9891. }
  9892. inverseMatrix.getInverse( this.matrixWorld );
  9893. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9894. var vStart = new THREE.Vector3();
  9895. var vEnd = new THREE.Vector3();
  9896. var interSegment = new THREE.Vector3();
  9897. var interRay = new THREE.Vector3();
  9898. var step = this instanceof THREE.LineSegments ? 2 : 1;
  9899. if ( geometry instanceof THREE.BufferGeometry ) {
  9900. var attributes = geometry.attributes;
  9901. if ( attributes.index !== undefined ) {
  9902. var indices = attributes.index.array;
  9903. var positions = attributes.position.array;
  9904. var offsets = geometry.drawcalls;
  9905. if ( offsets.length === 0 ) {
  9906. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9907. }
  9908. for ( var oi = 0; oi < offsets.length; oi ++ ) {
  9909. var start = offsets[ oi ].start;
  9910. var count = offsets[ oi ].count;
  9911. var index = offsets[ oi ].index;
  9912. for ( var i = start; i < start + count - 1; i += step ) {
  9913. var a = index + indices[ i ];
  9914. var b = index + indices[ i + 1 ];
  9915. vStart.fromArray( positions, a * 3 );
  9916. vEnd.fromArray( positions, b * 3 );
  9917. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9918. if ( distSq > precisionSq ) continue;
  9919. var distance = ray.origin.distanceTo( interRay );
  9920. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9921. intersects.push( {
  9922. distance: distance,
  9923. // What do we want? intersection point on the ray or on the segment??
  9924. // point: raycaster.ray.at( distance ),
  9925. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9926. index: i,
  9927. offsetIndex: oi,
  9928. face: null,
  9929. faceIndex: null,
  9930. object: this
  9931. } );
  9932. }
  9933. }
  9934. } else {
  9935. var positions = attributes.position.array;
  9936. for ( var i = 0; i < positions.length / 3 - 1; i += step ) {
  9937. vStart.fromArray( positions, 3 * i );
  9938. vEnd.fromArray( positions, 3 * i + 3 );
  9939. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9940. if ( distSq > precisionSq ) continue;
  9941. var distance = ray.origin.distanceTo( interRay );
  9942. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9943. intersects.push( {
  9944. distance: distance,
  9945. // What do we want? intersection point on the ray or on the segment??
  9946. // point: raycaster.ray.at( distance ),
  9947. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9948. index: i,
  9949. face: null,
  9950. faceIndex: null,
  9951. object: this
  9952. } );
  9953. }
  9954. }
  9955. } else if ( geometry instanceof THREE.Geometry ) {
  9956. var vertices = geometry.vertices;
  9957. var nbVertices = vertices.length;
  9958. for ( var i = 0; i < nbVertices - 1; i += step ) {
  9959. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  9960. if ( distSq > precisionSq ) continue;
  9961. var distance = ray.origin.distanceTo( interRay );
  9962. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9963. intersects.push( {
  9964. distance: distance,
  9965. // What do we want? intersection point on the ray or on the segment??
  9966. // point: raycaster.ray.at( distance ),
  9967. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9968. index: i,
  9969. face: null,
  9970. faceIndex: null,
  9971. object: this
  9972. } );
  9973. }
  9974. }
  9975. };
  9976. }() );
  9977. THREE.Line.prototype.clone = function () {
  9978. var line = new THREE.Line( this.geometry, this.material );
  9979. return line.copy( this );
  9980. };
  9981. THREE.Line.prototype.copy = function ( source ) {
  9982. THREE.Object3D.prototype.copy.call( this, source );
  9983. return this;
  9984. };
  9985. THREE.Line.prototype.toJSON = function ( meta ) {
  9986. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9987. // only serialize if not in meta geometries cache
  9988. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9989. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9990. }
  9991. // only serialize if not in meta materials cache
  9992. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9993. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9994. }
  9995. data.object.geometry = this.geometry.uuid;
  9996. data.object.material = this.material.uuid;
  9997. return data;
  9998. };
  9999. // DEPRECATED
  10000. THREE.LineStrip = 0;
  10001. THREE.LinePieces = 1;
  10002. // File:src/objects/LineSegments.js
  10003. /**
  10004. * @author mrdoob / http://mrdoob.com/
  10005. */
  10006. THREE.LineSegments = function ( geometry, material ) {
  10007. THREE.Line.call( this, geometry, material );
  10008. this.type = 'LineSegments';
  10009. };
  10010. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  10011. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  10012. THREE.LineSegments.prototype.clone = function () {
  10013. var line = new THREE.LineSegments( this.geometry, this.material );
  10014. line.copy( this );
  10015. return line;
  10016. };
  10017. // File:src/objects/Mesh.js
  10018. /**
  10019. * @author mrdoob / http://mrdoob.com/
  10020. * @author alteredq / http://alteredqualia.com/
  10021. * @author mikael emtinger / http://gomo.se/
  10022. * @author jonobr1 / http://jonobr1.com/
  10023. */
  10024. THREE.Mesh = function ( geometry, material ) {
  10025. THREE.Object3D.call( this );
  10026. this.type = 'Mesh';
  10027. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  10028. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  10029. this.updateMorphTargets();
  10030. };
  10031. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  10032. THREE.Mesh.prototype.constructor = THREE.Mesh;
  10033. THREE.Mesh.prototype.updateMorphTargets = function () {
  10034. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  10035. this.morphTargetBase = - 1;
  10036. this.morphTargetForcedOrder = [];
  10037. this.morphTargetInfluences = [];
  10038. this.morphTargetDictionary = {};
  10039. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  10040. this.morphTargetInfluences.push( 0 );
  10041. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  10042. }
  10043. }
  10044. };
  10045. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  10046. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  10047. return this.morphTargetDictionary[ name ];
  10048. }
  10049. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  10050. return 0;
  10051. };
  10052. THREE.Mesh.prototype.raycast = ( function () {
  10053. var inverseMatrix = new THREE.Matrix4();
  10054. var ray = new THREE.Ray();
  10055. var sphere = new THREE.Sphere();
  10056. var vA = new THREE.Vector3();
  10057. var vB = new THREE.Vector3();
  10058. var vC = new THREE.Vector3();
  10059. var tempA = new THREE.Vector3();
  10060. var tempB = new THREE.Vector3();
  10061. var tempC = new THREE.Vector3();
  10062. return function raycast( raycaster, intersects ) {
  10063. var geometry = this.geometry;
  10064. var material = this.material;
  10065. if ( material === undefined ) return;
  10066. // Checking boundingSphere distance to ray
  10067. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10068. sphere.copy( geometry.boundingSphere );
  10069. sphere.applyMatrix4( this.matrixWorld );
  10070. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  10071. return;
  10072. }
  10073. // Check boundingBox before continuing
  10074. inverseMatrix.getInverse( this.matrixWorld );
  10075. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10076. if ( geometry.boundingBox !== null ) {
  10077. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  10078. return;
  10079. }
  10080. }
  10081. var a, b, c;
  10082. if ( geometry instanceof THREE.BufferGeometry ) {
  10083. var attributes = geometry.attributes;
  10084. if ( attributes.index !== undefined ) {
  10085. var indices = attributes.index.array;
  10086. var positions = attributes.position.array;
  10087. var offsets = geometry.drawcalls;
  10088. if ( offsets.length === 0 ) {
  10089. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  10090. }
  10091. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  10092. var start = offsets[ oi ].start;
  10093. var count = offsets[ oi ].count;
  10094. var index = offsets[ oi ].index;
  10095. for ( var i = start, il = start + count; i < il; i += 3 ) {
  10096. a = index + indices[ i ];
  10097. b = index + indices[ i + 1 ];
  10098. c = index + indices[ i + 2 ];
  10099. vA.fromArray( positions, a * 3 );
  10100. vB.fromArray( positions, b * 3 );
  10101. vC.fromArray( positions, c * 3 );
  10102. if ( material.side === THREE.BackSide ) {
  10103. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  10104. } else {
  10105. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  10106. }
  10107. if ( intersectionPoint === null ) continue;
  10108. intersectionPoint.applyMatrix4( this.matrixWorld );
  10109. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10110. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10111. intersects.push( {
  10112. distance: distance,
  10113. point: intersectionPoint,
  10114. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  10115. faceIndex: Math.floor( i / 3 ), // triangle number in indices buffer semantics
  10116. object: this
  10117. } );
  10118. }
  10119. }
  10120. } else {
  10121. var positions = attributes.position.array;
  10122. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  10123. vA.fromArray( positions, i );
  10124. vB.fromArray( positions, i + 3 );
  10125. vC.fromArray( positions, i + 6 );
  10126. if ( material.side === THREE.BackSide ) {
  10127. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  10128. } else {
  10129. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  10130. }
  10131. if ( intersectionPoint === null ) continue;
  10132. intersectionPoint.applyMatrix4( this.matrixWorld );
  10133. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10134. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10135. a = i / 3;
  10136. b = a + 1;
  10137. c = a + 2;
  10138. intersects.push( {
  10139. distance: distance,
  10140. point: intersectionPoint,
  10141. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  10142. index: a, // triangle number in positions buffer semantics
  10143. object: this
  10144. } );
  10145. }
  10146. }
  10147. } else if ( geometry instanceof THREE.Geometry ) {
  10148. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  10149. var materials = isFaceMaterial === true ? material.materials : null;
  10150. var vertices = geometry.vertices;
  10151. var faces = geometry.faces;
  10152. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  10153. var face = faces[ f ];
  10154. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  10155. if ( faceMaterial === undefined ) continue;
  10156. a = vertices[ face.a ];
  10157. b = vertices[ face.b ];
  10158. c = vertices[ face.c ];
  10159. if ( faceMaterial.morphTargets === true ) {
  10160. var morphTargets = geometry.morphTargets;
  10161. var morphInfluences = this.morphTargetInfluences;
  10162. vA.set( 0, 0, 0 );
  10163. vB.set( 0, 0, 0 );
  10164. vC.set( 0, 0, 0 );
  10165. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  10166. var influence = morphInfluences[ t ];
  10167. if ( influence === 0 ) continue;
  10168. var targets = morphTargets[ t ].vertices;
  10169. vA.addScaledVector( tempA.subVectors( targets[ face.a ], a ), influence );
  10170. vB.addScaledVector( tempB.subVectors( targets[ face.b ], b ), influence );
  10171. vC.addScaledVector( tempC.subVectors( targets[ face.c ], c ), influence );
  10172. }
  10173. vA.add( a );
  10174. vB.add( b );
  10175. vC.add( c );
  10176. a = vA;
  10177. b = vB;
  10178. c = vC;
  10179. }
  10180. if ( faceMaterial.side === THREE.BackSide ) {
  10181. var intersectionPoint = ray.intersectTriangle( c, b, a, true );
  10182. } else {
  10183. var intersectionPoint = ray.intersectTriangle( a, b, c, faceMaterial.side !== THREE.DoubleSide );
  10184. }
  10185. if ( intersectionPoint === null ) continue;
  10186. intersectionPoint.applyMatrix4( this.matrixWorld );
  10187. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10188. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10189. intersects.push( {
  10190. distance: distance,
  10191. point: intersectionPoint,
  10192. face: face,
  10193. faceIndex: f,
  10194. object: this
  10195. } );
  10196. }
  10197. }
  10198. };
  10199. }() );
  10200. THREE.Mesh.prototype.clone = function () {
  10201. var mesh = new THREE.Mesh( this.geometry, this.material );
  10202. return mesh.copy( this );
  10203. };
  10204. THREE.Mesh.prototype.copy = function ( source ) {
  10205. THREE.Object3D.prototype.copy.call( this, source );
  10206. return this;
  10207. };
  10208. THREE.Mesh.prototype.toJSON = function ( meta ) {
  10209. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10210. // only serialize if not in meta geometries cache
  10211. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  10212. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  10213. }
  10214. // only serialize if not in meta materials cache
  10215. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10216. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  10217. }
  10218. data.object.geometry = this.geometry.uuid;
  10219. data.object.material = this.material.uuid;
  10220. return data;
  10221. };
  10222. // File:src/objects/Bone.js
  10223. /**
  10224. * @author mikael emtinger / http://gomo.se/
  10225. * @author alteredq / http://alteredqualia.com/
  10226. * @author ikerr / http://verold.com
  10227. */
  10228. THREE.Bone = function ( skin ) {
  10229. THREE.Object3D.call( this );
  10230. this.type = 'Bone';
  10231. this.skin = skin;
  10232. };
  10233. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  10234. THREE.Bone.prototype.constructor = THREE.Bone;
  10235. THREE.Bone.prototype.clone = function () {
  10236. var bone = new THREE.Bone( this.skin );
  10237. return bone.copy( this );
  10238. };
  10239. THREE.Bone.prototype.copy = function ( source ) {
  10240. THREE.Object3D.prototype.copy.call( this, source );
  10241. this.skin = source.skin;
  10242. return this;
  10243. };
  10244. // File:src/objects/Skeleton.js
  10245. /**
  10246. * @author mikael emtinger / http://gomo.se/
  10247. * @author alteredq / http://alteredqualia.com/
  10248. * @author michael guerrero / http://realitymeltdown.com
  10249. * @author ikerr / http://verold.com
  10250. */
  10251. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  10252. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  10253. this.identityMatrix = new THREE.Matrix4();
  10254. // copy the bone array
  10255. bones = bones || [];
  10256. this.bones = bones.slice( 0 );
  10257. // create a bone texture or an array of floats
  10258. if ( this.useVertexTexture ) {
  10259. // layout (1 matrix = 4 pixels)
  10260. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  10261. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  10262. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  10263. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  10264. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  10265. var size = THREE.Math.nextPowerOfTwo( Math.sqrt( this.bones.length * 4 ) ); // 4 pixels needed for 1 matrix
  10266. if ( size === 0 ) size = 2; // Avoid creating empty texture
  10267. this.boneTextureWidth = size;
  10268. this.boneTextureHeight = size;
  10269. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  10270. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  10271. this.boneTexture.minFilter = THREE.NearestFilter;
  10272. this.boneTexture.magFilter = THREE.NearestFilter;
  10273. this.boneTexture.generateMipmaps = false;
  10274. this.boneTexture.flipY = false;
  10275. } else {
  10276. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  10277. }
  10278. // use the supplied bone inverses or calculate the inverses
  10279. if ( boneInverses === undefined ) {
  10280. this.calculateInverses();
  10281. } else {
  10282. if ( this.bones.length === boneInverses.length ) {
  10283. this.boneInverses = boneInverses.slice( 0 );
  10284. } else {
  10285. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  10286. this.boneInverses = [];
  10287. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10288. this.boneInverses.push( new THREE.Matrix4() );
  10289. }
  10290. }
  10291. }
  10292. };
  10293. THREE.Skeleton.prototype.calculateInverses = function () {
  10294. this.boneInverses = [];
  10295. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10296. var inverse = new THREE.Matrix4();
  10297. if ( this.bones[ b ] ) {
  10298. inverse.getInverse( this.bones[ b ].matrixWorld );
  10299. }
  10300. this.boneInverses.push( inverse );
  10301. }
  10302. };
  10303. THREE.Skeleton.prototype.pose = function () {
  10304. var bone;
  10305. // recover the bind-time world matrices
  10306. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10307. bone = this.bones[ b ];
  10308. if ( bone ) {
  10309. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  10310. }
  10311. }
  10312. // compute the local matrices, positions, rotations and scales
  10313. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10314. bone = this.bones[ b ];
  10315. if ( bone ) {
  10316. if ( bone.parent ) {
  10317. bone.matrix.getInverse( bone.parent.matrixWorld );
  10318. bone.matrix.multiply( bone.matrixWorld );
  10319. } else {
  10320. bone.matrix.copy( bone.matrixWorld );
  10321. }
  10322. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  10323. }
  10324. }
  10325. };
  10326. THREE.Skeleton.prototype.update = ( function () {
  10327. var offsetMatrix = new THREE.Matrix4();
  10328. return function update() {
  10329. // flatten bone matrices to array
  10330. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10331. // compute the offset between the current and the original transform
  10332. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  10333. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  10334. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  10335. }
  10336. if ( this.useVertexTexture ) {
  10337. this.boneTexture.needsUpdate = true;
  10338. }
  10339. };
  10340. } )();
  10341. THREE.Skeleton.prototype.clone = function () {
  10342. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  10343. };
  10344. // File:src/objects/SkinnedMesh.js
  10345. /**
  10346. * @author mikael emtinger / http://gomo.se/
  10347. * @author alteredq / http://alteredqualia.com/
  10348. * @author ikerr / http://verold.com
  10349. */
  10350. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  10351. THREE.Mesh.call( this, geometry, material );
  10352. this.type = 'SkinnedMesh';
  10353. this.bindMode = "attached";
  10354. this.bindMatrix = new THREE.Matrix4();
  10355. this.bindMatrixInverse = new THREE.Matrix4();
  10356. // init bones
  10357. // TODO: remove bone creation as there is no reason (other than
  10358. // convenience) for THREE.SkinnedMesh to do this.
  10359. var bones = [];
  10360. if ( this.geometry && this.geometry.bones !== undefined ) {
  10361. var bone, gbone;
  10362. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10363. gbone = this.geometry.bones[ b ];
  10364. bone = new THREE.Bone( this );
  10365. bones.push( bone );
  10366. bone.name = gbone.name;
  10367. bone.position.fromArray( gbone.pos );
  10368. bone.quaternion.fromArray( gbone.rotq );
  10369. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  10370. }
  10371. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10372. gbone = this.geometry.bones[ b ];
  10373. if ( gbone.parent !== - 1 ) {
  10374. bones[ gbone.parent ].add( bones[ b ] );
  10375. } else {
  10376. this.add( bones[ b ] );
  10377. }
  10378. }
  10379. }
  10380. this.normalizeSkinWeights();
  10381. this.updateMatrixWorld( true );
  10382. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  10383. };
  10384. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  10385. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  10386. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  10387. this.skeleton = skeleton;
  10388. if ( bindMatrix === undefined ) {
  10389. this.updateMatrixWorld( true );
  10390. this.skeleton.calculateInverses();
  10391. bindMatrix = this.matrixWorld;
  10392. }
  10393. this.bindMatrix.copy( bindMatrix );
  10394. this.bindMatrixInverse.getInverse( bindMatrix );
  10395. };
  10396. THREE.SkinnedMesh.prototype.pose = function () {
  10397. this.skeleton.pose();
  10398. };
  10399. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  10400. if ( this.geometry instanceof THREE.Geometry ) {
  10401. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  10402. var sw = this.geometry.skinWeights[ i ];
  10403. var scale = 1.0 / sw.lengthManhattan();
  10404. if ( scale !== Infinity ) {
  10405. sw.multiplyScalar( scale );
  10406. } else {
  10407. sw.set( 1 ); // this will be normalized by the shader anyway
  10408. }
  10409. }
  10410. } else {
  10411. // skinning weights assumed to be normalized for THREE.BufferGeometry
  10412. }
  10413. };
  10414. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  10415. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  10416. if ( this.bindMode === "attached" ) {
  10417. this.bindMatrixInverse.getInverse( this.matrixWorld );
  10418. } else if ( this.bindMode === "detached" ) {
  10419. this.bindMatrixInverse.getInverse( this.bindMatrix );
  10420. } else {
  10421. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  10422. }
  10423. };
  10424. THREE.SkinnedMesh.prototype.clone = function() {
  10425. var skinMesh = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
  10426. return skinMesh.copy( this );
  10427. };
  10428. THREE.SkinnedMesh.prototype.copy = function( source ) {
  10429. THREE.Mesh.prototype.copy.call( this, source );
  10430. return this;
  10431. };
  10432. // File:src/objects/MorphAnimMesh.js
  10433. /**
  10434. * @author alteredq / http://alteredqualia.com/
  10435. */
  10436. THREE.MorphAnimMesh = function ( geometry, material ) {
  10437. THREE.Mesh.call( this, geometry, material );
  10438. this.type = 'MorphAnimMesh';
  10439. // API
  10440. this.duration = 1000; // milliseconds
  10441. this.mirroredLoop = false;
  10442. this.time = 0;
  10443. // internals
  10444. this.lastKeyframe = 0;
  10445. this.currentKeyframe = 0;
  10446. this.direction = 1;
  10447. this.directionBackwards = false;
  10448. this.setFrameRange( 0, geometry.morphTargets.length - 1 );
  10449. };
  10450. THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype );
  10451. THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
  10452. THREE.MorphAnimMesh.prototype.setFrameRange = function ( start, end ) {
  10453. this.startKeyframe = start;
  10454. this.endKeyframe = end;
  10455. this.length = this.endKeyframe - this.startKeyframe + 1;
  10456. };
  10457. THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
  10458. this.direction = 1;
  10459. this.directionBackwards = false;
  10460. };
  10461. THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
  10462. this.direction = - 1;
  10463. this.directionBackwards = true;
  10464. };
  10465. THREE.MorphAnimMesh.prototype.parseAnimations = function () {
  10466. var geometry = this.geometry;
  10467. if ( ! geometry.animations ) geometry.animations = {};
  10468. var firstAnimation, animations = geometry.animations;
  10469. var pattern = /([a-z]+)_?(\d+)/;
  10470. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  10471. var morph = geometry.morphTargets[ i ];
  10472. var parts = morph.name.match( pattern );
  10473. if ( parts && parts.length > 1 ) {
  10474. var label = parts[ 1 ];
  10475. if ( ! animations[ label ] ) animations[ label ] = { start: Infinity, end: - Infinity };
  10476. var animation = animations[ label ];
  10477. if ( i < animation.start ) animation.start = i;
  10478. if ( i > animation.end ) animation.end = i;
  10479. if ( ! firstAnimation ) firstAnimation = label;
  10480. }
  10481. }
  10482. geometry.firstAnimation = firstAnimation;
  10483. };
  10484. THREE.MorphAnimMesh.prototype.setAnimationLabel = function ( label, start, end ) {
  10485. if ( ! this.geometry.animations ) this.geometry.animations = {};
  10486. this.geometry.animations[ label ] = { start: start, end: end };
  10487. };
  10488. THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  10489. var animation = this.geometry.animations[ label ];
  10490. if ( animation ) {
  10491. this.setFrameRange( animation.start, animation.end );
  10492. this.duration = 1000 * ( ( animation.end - animation.start ) / fps );
  10493. this.time = 0;
  10494. } else {
  10495. console.warn( 'THREE.MorphAnimMesh: animation[' + label + '] undefined in .playAnimation()' );
  10496. }
  10497. };
  10498. THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  10499. var frameTime = this.duration / this.length;
  10500. this.time += this.direction * delta;
  10501. if ( this.mirroredLoop ) {
  10502. if ( this.time > this.duration || this.time < 0 ) {
  10503. this.direction *= - 1;
  10504. if ( this.time > this.duration ) {
  10505. this.time = this.duration;
  10506. this.directionBackwards = true;
  10507. }
  10508. if ( this.time < 0 ) {
  10509. this.time = 0;
  10510. this.directionBackwards = false;
  10511. }
  10512. }
  10513. } else {
  10514. this.time = this.time % this.duration;
  10515. if ( this.time < 0 ) this.time += this.duration;
  10516. }
  10517. var keyframe = this.startKeyframe + THREE.Math.clamp( Math.floor( this.time / frameTime ), 0, this.length - 1 );
  10518. var influences = this.morphTargetInfluences;
  10519. if ( keyframe !== this.currentKeyframe ) {
  10520. influences[ this.lastKeyframe ] = 0;
  10521. influences[ this.currentKeyframe ] = 1;
  10522. influences[ keyframe ] = 0;
  10523. this.lastKeyframe = this.currentKeyframe;
  10524. this.currentKeyframe = keyframe;
  10525. }
  10526. var mix = ( this.time % frameTime ) / frameTime;
  10527. if ( this.directionBackwards ) {
  10528. mix = 1 - mix;
  10529. }
  10530. influences[ this.currentKeyframe ] = mix;
  10531. influences[ this.lastKeyframe ] = 1 - mix;
  10532. };
  10533. THREE.MorphAnimMesh.prototype.interpolateTargets = function ( a, b, t ) {
  10534. var influences = this.morphTargetInfluences;
  10535. for ( var i = 0, l = influences.length; i < l; i ++ ) {
  10536. influences[ i ] = 0;
  10537. }
  10538. if ( a > - 1 ) influences[ a ] = 1 - t;
  10539. if ( b > - 1 ) influences[ b ] = t;
  10540. };
  10541. THREE.MorphAnimMesh.prototype.clone = function () {
  10542. var morph = new THREE.MorphAnimMesh( this.geometry, this.material );
  10543. return morph.copy( this );
  10544. };
  10545. THREE.MorphAnimMesh.prototype.copy = function ( source ) {
  10546. this.duration = source.duration;
  10547. this.mirroredLoop = source.mirroredLoop;
  10548. this.time = source.time;
  10549. this.lastKeyframe = source.lastKeyframe;
  10550. this.currentKeyframe = source.currentKeyframe;
  10551. this.direction = source.direction;
  10552. this.directionBackwards = source.directionBackwards;
  10553. THREE.Mesh.prototype.copy.call( this, source );
  10554. return this;
  10555. };
  10556. // File:src/objects/LOD.js
  10557. /**
  10558. * @author mikael emtinger / http://gomo.se/
  10559. * @author alteredq / http://alteredqualia.com/
  10560. * @author mrdoob / http://mrdoob.com/
  10561. */
  10562. THREE.LOD = function () {
  10563. THREE.Object3D.call( this );
  10564. Object.defineProperties( this, {
  10565. levels: {
  10566. enumerable: true,
  10567. value: []
  10568. },
  10569. objects: {
  10570. get: function () {
  10571. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  10572. return this.levels;
  10573. }
  10574. }
  10575. } );
  10576. };
  10577. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  10578. THREE.LOD.prototype.constructor = THREE.LOD;
  10579. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  10580. if ( distance === undefined ) distance = 0;
  10581. distance = Math.abs( distance );
  10582. var levels = this.levels;
  10583. for ( var l = 0; l < levels.length; l ++ ) {
  10584. if ( distance < levels[ l ].distance ) {
  10585. break;
  10586. }
  10587. }
  10588. levels.splice( l, 0, { distance: distance, object: object } );
  10589. this.add( object );
  10590. };
  10591. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  10592. var levels = this.levels;
  10593. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10594. if ( distance < levels[ i ].distance ) {
  10595. break;
  10596. }
  10597. }
  10598. return levels[ i - 1 ].object;
  10599. };
  10600. THREE.LOD.prototype.raycast = ( function () {
  10601. var matrixPosition = new THREE.Vector3();
  10602. return function raycast( raycaster, intersects ) {
  10603. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10604. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  10605. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  10606. };
  10607. }() );
  10608. THREE.LOD.prototype.update = function () {
  10609. var v1 = new THREE.Vector3();
  10610. var v2 = new THREE.Vector3();
  10611. return function update( camera ) {
  10612. var levels = this.levels;
  10613. if ( levels.length > 1 ) {
  10614. v1.setFromMatrixPosition( camera.matrixWorld );
  10615. v2.setFromMatrixPosition( this.matrixWorld );
  10616. var distance = v1.distanceTo( v2 );
  10617. levels[ 0 ].object.visible = true;
  10618. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10619. if ( distance >= levels[ i ].distance ) {
  10620. levels[ i - 1 ].object.visible = false;
  10621. levels[ i ].object.visible = true;
  10622. } else {
  10623. break;
  10624. }
  10625. }
  10626. for ( ; i < l; i ++ ) {
  10627. levels[ i ].object.visible = false;
  10628. }
  10629. }
  10630. };
  10631. }();
  10632. THREE.LOD.prototype.clone = function () {
  10633. var lod = new THREE.LOD();
  10634. return lod.copy( this );
  10635. };
  10636. THREE.LOD.prototype.copy = function ( source ) {
  10637. THREE.Object3D.prototype.copy.call( this, source, false );
  10638. var levels = source.levels;
  10639. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  10640. var level = levels[ i ];
  10641. this.addLevel( level.object.clone(), level.distance );
  10642. }
  10643. return this;
  10644. };
  10645. // File:src/objects/Sprite.js
  10646. /**
  10647. * @author mikael emtinger / http://gomo.se/
  10648. * @author alteredq / http://alteredqualia.com/
  10649. */
  10650. THREE.Sprite = ( function () {
  10651. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  10652. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  10653. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  10654. var geometry = new THREE.BufferGeometry();
  10655. geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  10656. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  10657. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  10658. return function Sprite( material ) {
  10659. THREE.Object3D.call( this );
  10660. this.type = 'Sprite';
  10661. this.geometry = geometry;
  10662. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  10663. };
  10664. } )();
  10665. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  10666. THREE.Sprite.prototype.constructor = THREE.Sprite;
  10667. THREE.Sprite.prototype.raycast = ( function () {
  10668. var matrixPosition = new THREE.Vector3();
  10669. return function raycast( raycaster, intersects ) {
  10670. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10671. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  10672. var guessSizeSq = this.scale.x * this.scale.y;
  10673. if ( distanceSq > guessSizeSq ) {
  10674. return;
  10675. }
  10676. intersects.push( {
  10677. distance: Math.sqrt( distanceSq ),
  10678. point: this.position,
  10679. face: null,
  10680. object: this
  10681. } );
  10682. };
  10683. }() );
  10684. THREE.Sprite.prototype.clone = function () {
  10685. var sprite = new THREE.Sprite( this.material );
  10686. return sprite.copy( this );
  10687. };
  10688. THREE.Sprite.prototype.copy = function ( source ) {
  10689. THREE.Object3D.prototype.copy.call( this, source );
  10690. return this;
  10691. };
  10692. THREE.Sprite.prototype.toJSON = function ( meta ) {
  10693. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10694. // only serialize if not in meta materials cache
  10695. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10696. meta.materials[ this.material.uuid ] = this.material.toJSON();
  10697. }
  10698. data.object.material = this.material.uuid;
  10699. return data;
  10700. };
  10701. // Backwards compatibility
  10702. THREE.Particle = THREE.Sprite;
  10703. // File:src/objects/LensFlare.js
  10704. /**
  10705. * @author mikael emtinger / http://gomo.se/
  10706. * @author alteredq / http://alteredqualia.com/
  10707. */
  10708. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  10709. THREE.Object3D.call( this );
  10710. this.lensFlares = [];
  10711. this.positionScreen = new THREE.Vector3();
  10712. this.customUpdateCallback = undefined;
  10713. if ( texture !== undefined ) {
  10714. this.add( texture, size, distance, blending, color );
  10715. }
  10716. };
  10717. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  10718. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  10719. /*
  10720. * Add: adds another flare
  10721. */
  10722. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  10723. if ( size === undefined ) size = - 1;
  10724. if ( distance === undefined ) distance = 0;
  10725. if ( opacity === undefined ) opacity = 1;
  10726. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  10727. if ( blending === undefined ) blending = THREE.NormalBlending;
  10728. distance = Math.min( distance, Math.max( 0, distance ) );
  10729. this.lensFlares.push( {
  10730. texture: texture, // THREE.Texture
  10731. size: size, // size in pixels (-1 = use texture.width)
  10732. distance: distance, // distance (0-1) from light source (0=at light source)
  10733. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  10734. scale: 1, // scale
  10735. rotation: 0, // rotation
  10736. opacity: opacity, // opacity
  10737. color: color, // color
  10738. blending: blending // blending
  10739. } );
  10740. };
  10741. /*
  10742. * Update lens flares update positions on all flares based on the screen position
  10743. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  10744. */
  10745. THREE.LensFlare.prototype.updateLensFlares = function () {
  10746. var f, fl = this.lensFlares.length;
  10747. var flare;
  10748. var vecX = - this.positionScreen.x * 2;
  10749. var vecY = - this.positionScreen.y * 2;
  10750. for ( f = 0; f < fl; f ++ ) {
  10751. flare = this.lensFlares[ f ];
  10752. flare.x = this.positionScreen.x + vecX * flare.distance;
  10753. flare.y = this.positionScreen.y + vecY * flare.distance;
  10754. flare.wantedRotation = flare.x * Math.PI * 0.25;
  10755. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  10756. }
  10757. };
  10758. THREE.LensFlare.prototype.clone = function () {
  10759. var flare = new THREE.LensFlare();
  10760. return flare.copy( this );
  10761. };
  10762. THREE.LensFlare.prototype.copy = function ( source ) {
  10763. THREE.Object3D.prototype.copy.call( this, source );
  10764. this.positionScreen.copy( source.positionScreen );
  10765. this.customUpdateCallback = source.customUpdateCallback;
  10766. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  10767. this.lensFlares.push( source.lensFlares[ i ] );
  10768. }
  10769. return this;
  10770. };
  10771. // File:src/scenes/Scene.js
  10772. /**
  10773. * @author mrdoob / http://mrdoob.com/
  10774. */
  10775. THREE.Scene = function () {
  10776. THREE.Object3D.call( this );
  10777. this.type = 'Scene';
  10778. this.fog = null;
  10779. this.overrideMaterial = null;
  10780. this.autoUpdate = true; // checked by the renderer
  10781. };
  10782. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  10783. THREE.Scene.prototype.constructor = THREE.Scene;
  10784. THREE.Scene.prototype.clone = function () {
  10785. var scene = new THREE.Scene();
  10786. return scene.copy( this );
  10787. };
  10788. THREE.Scene.prototype.copy = function ( source ) {
  10789. THREE.Object3D.prototype.copy.call( this, source );
  10790. if ( source.fog !== null ) this.fog = source.fog.clone();
  10791. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  10792. this.autoUpdate = source.autoUpdate;
  10793. this.matrixAutoUpdate = source.matrixAutoUpdate;
  10794. return this;
  10795. };
  10796. // File:src/scenes/Fog.js
  10797. /**
  10798. * @author mrdoob / http://mrdoob.com/
  10799. * @author alteredq / http://alteredqualia.com/
  10800. */
  10801. THREE.Fog = function ( color, near, far ) {
  10802. this.name = '';
  10803. this.color = new THREE.Color( color );
  10804. this.near = ( near !== undefined ) ? near : 1;
  10805. this.far = ( far !== undefined ) ? far : 1000;
  10806. };
  10807. THREE.Fog.prototype.clone = function () {
  10808. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  10809. };
  10810. // File:src/scenes/FogExp2.js
  10811. /**
  10812. * @author mrdoob / http://mrdoob.com/
  10813. * @author alteredq / http://alteredqualia.com/
  10814. */
  10815. THREE.FogExp2 = function ( color, density ) {
  10816. this.name = '';
  10817. this.color = new THREE.Color( color );
  10818. this.density = ( density !== undefined ) ? density : 0.00025;
  10819. };
  10820. THREE.FogExp2.prototype.clone = function () {
  10821. return new THREE.FogExp2( this.color.getHex(), this.density );
  10822. };
  10823. // File:src/renderers/shaders/ShaderChunk.js
  10824. THREE.ShaderChunk = {};
  10825. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  10826. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  10827. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  10828. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  10829. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  10830. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  10831. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  10832. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  10833. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  10834. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  10835. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  10836. 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";
  10837. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  10838. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  10839. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  10840. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  10841. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  10842. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  10843. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  10844. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  10845. // File:src/renderers/shaders/ShaderChunk/common.glsl
  10846. THREE.ShaderChunk[ 'common'] = "#define PI 3.14159\n#define PI2 6.28318\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\n\nvec3 transformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );\n\n}\n\n// http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations\nvec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );\n\n}\n\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n float distance = dot( planeNormal, point - pointOnPlane );\n\n return - distance * planeNormal + point;\n\n}\n\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return sign( dot( point - pointOnPlane, planeNormal ) );\n\n}\n\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n\n}\n\nfloat calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {\n\n if ( decayExponent > 0.0 ) {\n\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\n }\n\n return 1.0;\n\n}\n\nvec3 F_Schlick( in vec3 specularColor, in float dotLH ) {\n\n return ( 1.0 - specularColor ) * pow( 1.0 - dotLH, 5.0 ) + specularColor;\n\n}\n\nfloat G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {\n\n // geometry term is (n⋅l)(n⋅v) / 4(n⋅l)(n⋅v)\n\n return 0.25;\n\n}\n\nfloat D_BlinnPhong( in float shininess, in float dotNH ) {\n\n // factor of 1/PI in distribution term omitted\n\n return ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n\n}\n\nvec3 BRDF_BlinnPhong( in vec3 specularColor, in float shininess, in vec3 normal, in vec3 lightDir, in vec3 viewDir ) {\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n //float dotNL = saturate( dot( normal, lightDir ) );\n //float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotLH = saturate( dot( lightDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, dotLH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * G * D;\n\n}\n\nvec3 inputToLinear( in vec3 a ) {\n\n #ifdef GAMMA_INPUT\n\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n\nvec3 linearToOutput( in vec3 a ) {\n\n #ifdef GAMMA_OUTPUT\n\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n";
  10847. // File:src/renderers/shaders/ShaderChunk/default_vertex.glsl
  10848. THREE.ShaderChunk[ 'default_vertex'] = "#ifdef USE_SKINNING\n\n vec4 mvPosition = modelViewMatrix * skinned;\n\n#elif defined( USE_MORPHTARGETS )\n\n vec4 mvPosition = modelViewMatrix * vec4( morphed, 1.0 );\n\n#else\n\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;\n";
  10849. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  10850. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef USE_SKINNING\n\n vec3 objectNormal = skinnedNormal.xyz;\n\n#elif defined( USE_MORPHNORMALS )\n\n vec3 objectNormal = morphedNormal;\n\n#else\n\n vec3 objectNormal = normal;\n\n#endif\n\n#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  10851. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  10852. 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";
  10853. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  10854. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  10855. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  10856. 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";
  10857. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  10858. 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";
  10859. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  10860. 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";
  10861. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  10862. 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";
  10863. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  10864. 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";
  10865. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  10866. 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";
  10867. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  10868. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  10869. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  10870. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  10871. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  10872. 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";
  10873. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  10874. THREE.ShaderChunk[ 'lights_lambert_vertex'] = "vLightFront = vec3( 0.0 );\n\n#ifdef DOUBLE_SIDED\n\n vLightBack = vec3( 0.0 );\n\n#endif\n\nvec3 normal = normalize( transformedNormal );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\n vec3 lVector = lPosition.xyz - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( lightPosition - worldPosition.xyz ) );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = transformDirection( directionalLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = transformDirection( hemisphereLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n #ifdef DOUBLE_SIDED\n\n float hemiDiffuseWeightBack = - 0.5 * dotProduct + 0.5;\n\n vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );\n\n #endif\n\n }\n\n#endif\n\nvLightFront += ambientLightColor;\n\n#ifdef DOUBLE_SIDED\n\n vLightBack += ambientLightColor;\n\n#endif\n";
  10875. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  10876. THREE.ShaderChunk[ 'lights_phong_fragment'] = "#ifndef FLAT_SHADED\n\n vec3 normal = normalize( vNormal );\n\n #ifdef DOUBLE_SIDED\n\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n\n #endif\n\n#else\n\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n\n#endif\n\n#ifdef USE_NORMALMAP\n\n normal = perturbNormal2Arb( -vViewPosition, normal );\n\n#elif defined( USE_BUMPMAP )\n\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n\n#endif\n\nvec3 viewDir = normalize( vViewPosition );\n\nvec3 totalDiffuseLight = vec3( 0.0 );\nvec3 totalSpecularLight = vec3( 0.0 );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec3 lightPosition = pointLightPosition[ i ];\n vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( lightPosition - vWorldPosition ) );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = transformDirection( directionalLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * cosineTerm;\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = transformDirection( hemisphereLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vec3 lightColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n totalDiffuseLight += lightColor;\n\n // specular (sky term only)\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * max( dotProduct, 0.0 );\n\n }\n\n#endif\n\n#ifdef METAL\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;\n\n#else\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;\n\n#endif\n";
  10877. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  10878. THREE.ShaderChunk[ 'lights_phong_pars_fragment'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\nvarying vec3 vViewPosition;\n\n#ifndef FLAT_SHADED\n\n varying vec3 vNormal;\n\n#endif\n";
  10879. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  10880. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n";
  10881. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  10882. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif";
  10883. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  10884. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  10885. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  10886. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  10887. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  10888. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n\n uniform float logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n #extension GL_EXT_frag_depth : enable\n varying float vFragDepth;\n\n #endif\n\n#endif";
  10889. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  10890. 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";
  10891. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  10892. 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";
  10893. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  10894. 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";
  10895. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  10896. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  10897. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  10898. 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";
  10899. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  10900. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  10901. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  10902. THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n\n vec3 morphedNormal = vec3( 0.0 );\n\n morphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n morphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n morphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n morphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n\n morphedNormal += normal;\n\n#endif";
  10903. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  10904. 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";
  10905. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  10906. THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n\n vec3 morphed = vec3( 0.0 );\n morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\n #ifndef USE_MORPHNORMALS\n\n morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\n #endif\n\n morphed += position;\n\n#endif";
  10907. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  10908. 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";
  10909. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  10910. THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\n\n #ifdef SHADOWMAP_DEBUG\n\n vec3 frustumColors[3];\n frustumColors[0] = vec3( 1.0, 0.5, 0.0 );\n frustumColors[1] = vec3( 0.0, 1.0, 0.8 );\n frustumColors[2] = vec3( 0.0, 0.5, 1.0 );\n\n #endif\n\n float fDepth;\n vec3 shadowColor = vec3( 1.0 );\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n\n // if ( something && something ) breaks ATI OpenGL shader compiler\n // if ( all( something, something ) ) using this instead\n\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\n bool frustumTest = all( frustumTestVec );\n\n if ( frustumTest ) {\n\n shadowCoord.z += shadowBias[ i ];\n\n #if defined( SHADOWMAP_TYPE_PCF )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n /*\n // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL\n // must enroll loop manually\n\n for ( float y = -1.25; y <= 1.25; y += 1.25 )\n for ( float x = -1.25; x <= 1.25; x += 1.25 ) {\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\n\n // doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup\n //vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );\n\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n shadow += 1.0;\n\n }\n\n shadow /= 9.0;\n\n */\n\n const float shadowDelta = 1.0 / 9.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n float dx0 = -1.25 * xPixelOffset;\n float dy0 = -1.25 * yPixelOffset;\n float dx1 = 1.25 * xPixelOffset;\n float dy1 = 1.25 * yPixelOffset;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n float dx0 = -1.0 * xPixelOffset;\n float dy0 = -1.0 * yPixelOffset;\n float dx1 = 1.0 * xPixelOffset;\n float dy1 = 1.0 * yPixelOffset;\n\n mat3 shadowKernel;\n mat3 depthKernel;\n\n depthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n depthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n depthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n depthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n depthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n depthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n depthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n depthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n depthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));\n shadowKernel[0] *= vec3(0.25);\n\n shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));\n shadowKernel[1] *= vec3(0.25);\n\n shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));\n shadowKernel[2] *= vec3(0.25);\n\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );\n\n shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );\n shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );\n\n vec4 shadowValues;\n shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );\n shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );\n shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );\n shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );\n\n shadow = dot( shadowValues, vec4( 1.0 ) );\n\n shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #else\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n\n // spot with multiple shadows is darker\n\n shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );\n\n // spot with multiple shadows has the same color as single shadow spot\n\n // shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );\n\n #endif\n\n }\n\n\n #ifdef SHADOWMAP_DEBUG\n\n if ( inFrustum ) outgoingLight *= frustumColors[ i ];\n\n #endif\n\n }\n\n outgoingLight = outgoingLight * shadowColor;\n\n#endif\n";
  10911. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  10912. THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n\n uniform sampler2D shadowMap[ MAX_SHADOWS ];\n uniform vec2 shadowMapSize[ MAX_SHADOWS ];\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform float shadowBias[ MAX_SHADOWS ];\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n float unpackDepth( const in vec4 rgba_depth ) {\n\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n float depth = dot( rgba_depth, bit_shift );\n return depth;\n\n }\n\n#endif";
  10913. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  10914. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n\n#endif";
  10915. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  10916. THREE.ShaderChunk[ 'shadowmap_vertex'] = "#ifdef USE_SHADOWMAP\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n vShadowCoord[ i ] = shadowMatrix[ i ] * worldPosition;\n\n }\n\n#endif";
  10917. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  10918. 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";
  10919. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  10920. 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";
  10921. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  10922. THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n\n #ifdef USE_MORPHTARGETS\n\n vec4 skinVertex = bindMatrix * vec4( morphed, 1.0 );\n\n #else\n\n vec4 skinVertex = bindMatrix * vec4( position, 1.0 );\n\n #endif\n\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n skinned = bindMatrixInverse * skinned;\n\n#endif\n";
  10923. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  10924. THREE.ShaderChunk[ 'skinnormal_vertex'] = "#ifdef USE_SKINNING\n\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\n #ifdef USE_MORPHNORMALS\n\n vec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );\n\n #else\n\n vec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );\n\n #endif\n\n#endif\n";
  10925. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  10926. 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";
  10927. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  10928. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  10929. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  10930. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  10931. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  10932. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  10933. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  10934. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  10935. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  10936. 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";
  10937. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  10938. 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";
  10939. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  10940. 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";
  10941. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  10942. THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\n #ifdef USE_SKINNING\n\n vec4 worldPosition = modelMatrix * skinned;\n\n #elif defined( USE_MORPHTARGETS )\n\n vec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );\n\n #else\n\n vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n\n #endif\n\n#endif\n";
  10943. // File:src/renderers/shaders/UniformsUtils.js
  10944. /**
  10945. * Uniform Utilities
  10946. */
  10947. THREE.UniformsUtils = {
  10948. merge: function ( uniforms ) {
  10949. var merged = {};
  10950. for ( var u = 0; u < uniforms.length; u ++ ) {
  10951. var tmp = this.clone( uniforms[ u ] );
  10952. for ( var p in tmp ) {
  10953. merged[ p ] = tmp[ p ];
  10954. }
  10955. }
  10956. return merged;
  10957. },
  10958. clone: function ( uniforms_src ) {
  10959. var uniforms_dst = {};
  10960. for ( var u in uniforms_src ) {
  10961. uniforms_dst[ u ] = {};
  10962. for ( var p in uniforms_src[ u ] ) {
  10963. var parameter_src = uniforms_src[ u ][ p ];
  10964. if ( parameter_src instanceof THREE.Color ||
  10965. parameter_src instanceof THREE.Vector2 ||
  10966. parameter_src instanceof THREE.Vector3 ||
  10967. parameter_src instanceof THREE.Vector4 ||
  10968. parameter_src instanceof THREE.Matrix3 ||
  10969. parameter_src instanceof THREE.Matrix4 ||
  10970. parameter_src instanceof THREE.Texture ) {
  10971. uniforms_dst[ u ][ p ] = parameter_src.clone();
  10972. } else if ( Array.isArray( parameter_src ) ) {
  10973. uniforms_dst[ u ][ p ] = parameter_src.slice();
  10974. } else {
  10975. uniforms_dst[ u ][ p ] = parameter_src;
  10976. }
  10977. }
  10978. }
  10979. return uniforms_dst;
  10980. }
  10981. };
  10982. // File:src/renderers/shaders/UniformsLib.js
  10983. /**
  10984. * Uniforms library for shared webgl shaders
  10985. */
  10986. THREE.UniformsLib = {
  10987. common: {
  10988. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10989. "opacity" : { type: "f", value: 1.0 },
  10990. "map" : { type: "t", value: null },
  10991. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10992. "specularMap" : { type: "t", value: null },
  10993. "alphaMap" : { type: "t", value: null },
  10994. "envMap" : { type: "t", value: null },
  10995. "flipEnvMap" : { type: "f", value: - 1 },
  10996. "reflectivity" : { type: "f", value: 1.0 },
  10997. "refractionRatio" : { type: "f", value: 0.98 }
  10998. },
  10999. aomap: {
  11000. "aoMap" : { type: "t", value: null },
  11001. "aoMapIntensity" : { type: "f", value: 1 },
  11002. },
  11003. lightmap: {
  11004. "lightMap" : { type: "t", value: null },
  11005. "lightMapIntensity" : { type: "f", value: 1 },
  11006. },
  11007. emissivemap: {
  11008. "emissiveMap" : { type: "t", value: null },
  11009. },
  11010. bump: {
  11011. "bumpMap" : { type: "t", value: null },
  11012. "bumpScale" : { type: "f", value: 1 }
  11013. },
  11014. normalmap: {
  11015. "normalMap" : { type: "t", value: null },
  11016. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  11017. },
  11018. fog : {
  11019. "fogDensity" : { type: "f", value: 0.00025 },
  11020. "fogNear" : { type: "f", value: 1 },
  11021. "fogFar" : { type: "f", value: 2000 },
  11022. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  11023. },
  11024. lights: {
  11025. "ambientLightColor" : { type: "fv", value: [] },
  11026. "directionalLightDirection" : { type: "fv", value: [] },
  11027. "directionalLightColor" : { type: "fv", value: [] },
  11028. "hemisphereLightDirection" : { type: "fv", value: [] },
  11029. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  11030. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  11031. "pointLightColor" : { type: "fv", value: [] },
  11032. "pointLightPosition" : { type: "fv", value: [] },
  11033. "pointLightDistance" : { type: "fv1", value: [] },
  11034. "pointLightDecay" : { type: "fv1", value: [] },
  11035. "spotLightColor" : { type: "fv", value: [] },
  11036. "spotLightPosition" : { type: "fv", value: [] },
  11037. "spotLightDirection" : { type: "fv", value: [] },
  11038. "spotLightDistance" : { type: "fv1", value: [] },
  11039. "spotLightAngleCos" : { type: "fv1", value: [] },
  11040. "spotLightExponent" : { type: "fv1", value: [] },
  11041. "spotLightDecay" : { type: "fv1", value: [] }
  11042. },
  11043. particle: {
  11044. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  11045. "opacity" : { type: "f", value: 1.0 },
  11046. "size" : { type: "f", value: 1.0 },
  11047. "scale" : { type: "f", value: 1.0 },
  11048. "map" : { type: "t", value: null },
  11049. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  11050. "fogDensity" : { type: "f", value: 0.00025 },
  11051. "fogNear" : { type: "f", value: 1 },
  11052. "fogFar" : { type: "f", value: 2000 },
  11053. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  11054. },
  11055. shadowmap: {
  11056. "shadowMap": { type: "tv", value: [] },
  11057. "shadowMapSize": { type: "v2v", value: [] },
  11058. "shadowBias" : { type: "fv1", value: [] },
  11059. "shadowDarkness": { type: "fv1", value: [] },
  11060. "shadowMatrix" : { type: "m4v", value: [] }
  11061. }
  11062. };
  11063. // File:src/renderers/shaders/ShaderLib.js
  11064. /**
  11065. * Webgl Shader Library for three.js
  11066. *
  11067. * @author alteredq / http://alteredqualia.com/
  11068. * @author mrdoob / http://mrdoob.com/
  11069. * @author mikael emtinger / http://gomo.se/
  11070. */
  11071. THREE.ShaderLib = {
  11072. 'basic': {
  11073. uniforms: THREE.UniformsUtils.merge( [
  11074. THREE.UniformsLib[ "common" ],
  11075. THREE.UniformsLib[ "aomap" ],
  11076. THREE.UniformsLib[ "fog" ],
  11077. THREE.UniformsLib[ "shadowmap" ]
  11078. ] ),
  11079. vertexShader: [
  11080. THREE.ShaderChunk[ "common" ],
  11081. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11082. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11083. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11084. THREE.ShaderChunk[ "color_pars_vertex" ],
  11085. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11086. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11087. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11088. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11089. "void main() {",
  11090. THREE.ShaderChunk[ "uv_vertex" ],
  11091. THREE.ShaderChunk[ "uv2_vertex" ],
  11092. THREE.ShaderChunk[ "color_vertex" ],
  11093. THREE.ShaderChunk[ "skinbase_vertex" ],
  11094. " #ifdef USE_ENVMAP",
  11095. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11096. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11097. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11098. " #endif",
  11099. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11100. THREE.ShaderChunk[ "skinning_vertex" ],
  11101. THREE.ShaderChunk[ "default_vertex" ],
  11102. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11103. THREE.ShaderChunk[ "worldpos_vertex" ],
  11104. THREE.ShaderChunk[ "envmap_vertex" ],
  11105. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11106. "}"
  11107. ].join( "\n" ),
  11108. fragmentShader: [
  11109. "uniform vec3 diffuse;",
  11110. "uniform float opacity;",
  11111. THREE.ShaderChunk[ "common" ],
  11112. THREE.ShaderChunk[ "color_pars_fragment" ],
  11113. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11114. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11115. THREE.ShaderChunk[ "map_pars_fragment" ],
  11116. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11117. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11118. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11119. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11120. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11121. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11122. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11123. "void main() {",
  11124. " vec3 outgoingLight = vec3( 0.0 );",
  11125. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11126. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  11127. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11128. THREE.ShaderChunk[ "map_fragment" ],
  11129. THREE.ShaderChunk[ "color_fragment" ],
  11130. THREE.ShaderChunk[ "alphamap_fragment" ],
  11131. THREE.ShaderChunk[ "alphatest_fragment" ],
  11132. THREE.ShaderChunk[ "specularmap_fragment" ],
  11133. THREE.ShaderChunk[ "aomap_fragment" ],
  11134. " outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
  11135. THREE.ShaderChunk[ "envmap_fragment" ],
  11136. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  11137. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11138. THREE.ShaderChunk[ "fog_fragment" ],
  11139. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11140. "}"
  11141. ].join( "\n" )
  11142. },
  11143. 'lambert': {
  11144. uniforms: THREE.UniformsUtils.merge( [
  11145. THREE.UniformsLib[ "common" ],
  11146. THREE.UniformsLib[ "fog" ],
  11147. THREE.UniformsLib[ "lights" ],
  11148. THREE.UniformsLib[ "shadowmap" ],
  11149. {
  11150. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  11151. }
  11152. ] ),
  11153. vertexShader: [
  11154. "#define LAMBERT",
  11155. "varying vec3 vLightFront;",
  11156. "#ifdef DOUBLE_SIDED",
  11157. " varying vec3 vLightBack;",
  11158. "#endif",
  11159. THREE.ShaderChunk[ "common" ],
  11160. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11161. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11162. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11163. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  11164. THREE.ShaderChunk[ "color_pars_vertex" ],
  11165. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11166. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11167. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11168. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11169. "void main() {",
  11170. THREE.ShaderChunk[ "uv_vertex" ],
  11171. THREE.ShaderChunk[ "uv2_vertex" ],
  11172. THREE.ShaderChunk[ "color_vertex" ],
  11173. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11174. THREE.ShaderChunk[ "skinbase_vertex" ],
  11175. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11176. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11177. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11178. THREE.ShaderChunk[ "skinning_vertex" ],
  11179. THREE.ShaderChunk[ "default_vertex" ],
  11180. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11181. THREE.ShaderChunk[ "worldpos_vertex" ],
  11182. THREE.ShaderChunk[ "envmap_vertex" ],
  11183. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  11184. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11185. "}"
  11186. ].join( "\n" ),
  11187. fragmentShader: [
  11188. "uniform vec3 diffuse;",
  11189. "uniform vec3 emissive;",
  11190. "uniform float opacity;",
  11191. "varying vec3 vLightFront;",
  11192. "#ifdef DOUBLE_SIDED",
  11193. " varying vec3 vLightBack;",
  11194. "#endif",
  11195. THREE.ShaderChunk[ "common" ],
  11196. THREE.ShaderChunk[ "color_pars_fragment" ],
  11197. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11198. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11199. THREE.ShaderChunk[ "map_pars_fragment" ],
  11200. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11201. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11202. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11203. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11204. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11205. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11206. "void main() {",
  11207. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  11208. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11209. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11210. THREE.ShaderChunk[ "map_fragment" ],
  11211. THREE.ShaderChunk[ "color_fragment" ],
  11212. THREE.ShaderChunk[ "alphamap_fragment" ],
  11213. THREE.ShaderChunk[ "alphatest_fragment" ],
  11214. THREE.ShaderChunk[ "specularmap_fragment" ],
  11215. " #ifdef DOUBLE_SIDED",
  11216. " if ( gl_FrontFacing )",
  11217. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11218. " else",
  11219. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  11220. " #else",
  11221. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11222. " #endif",
  11223. THREE.ShaderChunk[ "envmap_fragment" ],
  11224. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11225. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11226. THREE.ShaderChunk[ "fog_fragment" ],
  11227. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11228. "}"
  11229. ].join( "\n" )
  11230. },
  11231. 'phong': {
  11232. uniforms: THREE.UniformsUtils.merge( [
  11233. THREE.UniformsLib[ "common" ],
  11234. THREE.UniformsLib[ "aomap" ],
  11235. THREE.UniformsLib[ "lightmap" ],
  11236. THREE.UniformsLib[ "emissivemap" ],
  11237. THREE.UniformsLib[ "bump" ],
  11238. THREE.UniformsLib[ "normalmap" ],
  11239. THREE.UniformsLib[ "fog" ],
  11240. THREE.UniformsLib[ "lights" ],
  11241. THREE.UniformsLib[ "shadowmap" ],
  11242. {
  11243. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  11244. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  11245. "shininess": { type: "f", value: 30 }
  11246. }
  11247. ] ),
  11248. vertexShader: [
  11249. "#define PHONG",
  11250. "varying vec3 vViewPosition;",
  11251. "#ifndef FLAT_SHADED",
  11252. " varying vec3 vNormal;",
  11253. "#endif",
  11254. THREE.ShaderChunk[ "common" ],
  11255. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11256. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11257. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11258. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  11259. THREE.ShaderChunk[ "color_pars_vertex" ],
  11260. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11261. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11262. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11263. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11264. "void main() {",
  11265. THREE.ShaderChunk[ "uv_vertex" ],
  11266. THREE.ShaderChunk[ "uv2_vertex" ],
  11267. THREE.ShaderChunk[ "color_vertex" ],
  11268. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11269. THREE.ShaderChunk[ "skinbase_vertex" ],
  11270. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11271. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11272. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  11273. " vNormal = normalize( transformedNormal );",
  11274. "#endif",
  11275. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11276. THREE.ShaderChunk[ "skinning_vertex" ],
  11277. THREE.ShaderChunk[ "default_vertex" ],
  11278. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11279. " vViewPosition = - mvPosition.xyz;",
  11280. THREE.ShaderChunk[ "worldpos_vertex" ],
  11281. THREE.ShaderChunk[ "envmap_vertex" ],
  11282. THREE.ShaderChunk[ "lights_phong_vertex" ],
  11283. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11284. "}"
  11285. ].join( "\n" ),
  11286. fragmentShader: [
  11287. "#define PHONG",
  11288. "uniform vec3 diffuse;",
  11289. "uniform vec3 emissive;",
  11290. "uniform vec3 specular;",
  11291. "uniform float shininess;",
  11292. "uniform float opacity;",
  11293. THREE.ShaderChunk[ "common" ],
  11294. THREE.ShaderChunk[ "color_pars_fragment" ],
  11295. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11296. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11297. THREE.ShaderChunk[ "map_pars_fragment" ],
  11298. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11299. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11300. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  11301. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  11302. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11303. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11304. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  11305. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11306. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  11307. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  11308. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11309. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11310. "void main() {",
  11311. " vec3 outgoingLight = vec3( 0.0 );",
  11312. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11313. " vec3 totalAmbientLight = ambientLightColor;",
  11314. " vec3 totalEmissiveLight = emissive;",
  11315. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11316. THREE.ShaderChunk[ "map_fragment" ],
  11317. THREE.ShaderChunk[ "color_fragment" ],
  11318. THREE.ShaderChunk[ "alphamap_fragment" ],
  11319. THREE.ShaderChunk[ "alphatest_fragment" ],
  11320. THREE.ShaderChunk[ "specularmap_fragment" ],
  11321. THREE.ShaderChunk[ "lightmap_fragment" ],
  11322. THREE.ShaderChunk[ "aomap_fragment" ],
  11323. THREE.ShaderChunk[ "emissivemap_fragment" ],
  11324. THREE.ShaderChunk[ "lights_phong_fragment" ],
  11325. THREE.ShaderChunk[ "envmap_fragment" ],
  11326. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11327. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11328. THREE.ShaderChunk[ "fog_fragment" ],
  11329. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11330. "}"
  11331. ].join( "\n" )
  11332. },
  11333. 'particle_basic': {
  11334. uniforms: THREE.UniformsUtils.merge( [
  11335. THREE.UniformsLib[ "particle" ],
  11336. THREE.UniformsLib[ "shadowmap" ]
  11337. ] ),
  11338. vertexShader: [
  11339. "uniform float size;",
  11340. "uniform float scale;",
  11341. THREE.ShaderChunk[ "common" ],
  11342. THREE.ShaderChunk[ "color_pars_vertex" ],
  11343. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11344. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11345. "void main() {",
  11346. THREE.ShaderChunk[ "color_vertex" ],
  11347. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11348. " #ifdef USE_SIZEATTENUATION",
  11349. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  11350. " #else",
  11351. " gl_PointSize = size;",
  11352. " #endif",
  11353. " gl_Position = projectionMatrix * mvPosition;",
  11354. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11355. THREE.ShaderChunk[ "worldpos_vertex" ],
  11356. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11357. "}"
  11358. ].join( "\n" ),
  11359. fragmentShader: [
  11360. "uniform vec3 psColor;",
  11361. "uniform float opacity;",
  11362. THREE.ShaderChunk[ "common" ],
  11363. THREE.ShaderChunk[ "color_pars_fragment" ],
  11364. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  11365. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11366. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11367. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11368. "void main() {",
  11369. " vec3 outgoingLight = vec3( 0.0 );",
  11370. " vec4 diffuseColor = vec4( psColor, opacity );",
  11371. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11372. THREE.ShaderChunk[ "map_particle_fragment" ],
  11373. THREE.ShaderChunk[ "color_fragment" ],
  11374. THREE.ShaderChunk[ "alphatest_fragment" ],
  11375. " outgoingLight = diffuseColor.rgb;", // simple shader
  11376. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11377. THREE.ShaderChunk[ "fog_fragment" ],
  11378. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11379. "}"
  11380. ].join( "\n" )
  11381. },
  11382. 'dashed': {
  11383. uniforms: THREE.UniformsUtils.merge( [
  11384. THREE.UniformsLib[ "common" ],
  11385. THREE.UniformsLib[ "fog" ],
  11386. {
  11387. "scale" : { type: "f", value: 1 },
  11388. "dashSize" : { type: "f", value: 1 },
  11389. "totalSize": { type: "f", value: 2 }
  11390. }
  11391. ] ),
  11392. vertexShader: [
  11393. "uniform float scale;",
  11394. "attribute float lineDistance;",
  11395. "varying float vLineDistance;",
  11396. THREE.ShaderChunk[ "common" ],
  11397. THREE.ShaderChunk[ "color_pars_vertex" ],
  11398. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11399. "void main() {",
  11400. THREE.ShaderChunk[ "color_vertex" ],
  11401. " vLineDistance = scale * lineDistance;",
  11402. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11403. " gl_Position = projectionMatrix * mvPosition;",
  11404. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11405. "}"
  11406. ].join( "\n" ),
  11407. fragmentShader: [
  11408. "uniform vec3 diffuse;",
  11409. "uniform float opacity;",
  11410. "uniform float dashSize;",
  11411. "uniform float totalSize;",
  11412. "varying float vLineDistance;",
  11413. THREE.ShaderChunk[ "common" ],
  11414. THREE.ShaderChunk[ "color_pars_fragment" ],
  11415. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11416. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11417. "void main() {",
  11418. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  11419. " discard;",
  11420. " }",
  11421. " vec3 outgoingLight = vec3( 0.0 );",
  11422. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11423. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11424. THREE.ShaderChunk[ "color_fragment" ],
  11425. " outgoingLight = diffuseColor.rgb;", // simple shader
  11426. THREE.ShaderChunk[ "fog_fragment" ],
  11427. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11428. "}"
  11429. ].join( "\n" )
  11430. },
  11431. 'depth': {
  11432. uniforms: {
  11433. "mNear": { type: "f", value: 1.0 },
  11434. "mFar" : { type: "f", value: 2000.0 },
  11435. "opacity" : { type: "f", value: 1.0 }
  11436. },
  11437. vertexShader: [
  11438. THREE.ShaderChunk[ "common" ],
  11439. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11440. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11441. "void main() {",
  11442. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11443. THREE.ShaderChunk[ "default_vertex" ],
  11444. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11445. "}"
  11446. ].join( "\n" ),
  11447. fragmentShader: [
  11448. "uniform float mNear;",
  11449. "uniform float mFar;",
  11450. "uniform float opacity;",
  11451. THREE.ShaderChunk[ "common" ],
  11452. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11453. "void main() {",
  11454. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11455. " #ifdef USE_LOGDEPTHBUF_EXT",
  11456. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  11457. " #else",
  11458. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  11459. " #endif",
  11460. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  11461. " gl_FragColor = vec4( vec3( color ), opacity );",
  11462. "}"
  11463. ].join( "\n" )
  11464. },
  11465. 'normal': {
  11466. uniforms: {
  11467. "opacity" : { type: "f", value: 1.0 }
  11468. },
  11469. vertexShader: [
  11470. "varying vec3 vNormal;",
  11471. THREE.ShaderChunk[ "common" ],
  11472. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11473. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11474. "void main() {",
  11475. " vNormal = normalize( normalMatrix * normal );",
  11476. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11477. THREE.ShaderChunk[ "default_vertex" ],
  11478. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11479. "}"
  11480. ].join( "\n" ),
  11481. fragmentShader: [
  11482. "uniform float opacity;",
  11483. "varying vec3 vNormal;",
  11484. THREE.ShaderChunk[ "common" ],
  11485. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11486. "void main() {",
  11487. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  11488. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11489. "}"
  11490. ].join( "\n" )
  11491. },
  11492. /* -------------------------------------------------------------------------
  11493. // Cube map shader
  11494. ------------------------------------------------------------------------- */
  11495. 'cube': {
  11496. uniforms: { "tCube": { type: "t", value: null },
  11497. "tFlip": { type: "f", value: - 1 } },
  11498. vertexShader: [
  11499. "varying vec3 vWorldPosition;",
  11500. THREE.ShaderChunk[ "common" ],
  11501. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11502. "void main() {",
  11503. " vWorldPosition = transformDirection( position, modelMatrix );",
  11504. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11505. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11506. "}"
  11507. ].join( "\n" ),
  11508. fragmentShader: [
  11509. "uniform samplerCube tCube;",
  11510. "uniform float tFlip;",
  11511. "varying vec3 vWorldPosition;",
  11512. THREE.ShaderChunk[ "common" ],
  11513. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11514. "void main() {",
  11515. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11516. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11517. "}"
  11518. ].join( "\n" )
  11519. },
  11520. /* -------------------------------------------------------------------------
  11521. // Cube map shader
  11522. ------------------------------------------------------------------------- */
  11523. 'equirect': {
  11524. uniforms: { "tEquirect": { type: "t", value: null },
  11525. "tFlip": { type: "f", value: - 1 } },
  11526. vertexShader: [
  11527. "varying vec3 vWorldPosition;",
  11528. THREE.ShaderChunk[ "common" ],
  11529. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11530. "void main() {",
  11531. " vWorldPosition = transformDirection( position, modelMatrix );",
  11532. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11533. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11534. "}"
  11535. ].join( "\n" ),
  11536. fragmentShader: [
  11537. "uniform sampler2D tEquirect;",
  11538. "uniform float tFlip;",
  11539. "varying vec3 vWorldPosition;",
  11540. THREE.ShaderChunk[ "common" ],
  11541. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11542. "void main() {",
  11543. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11544. "vec3 direction = normalize( vWorldPosition );",
  11545. "vec2 sampleUV;",
  11546. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  11547. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  11548. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  11549. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11550. "}"
  11551. ].join( "\n" )
  11552. },
  11553. /* Depth encoding into RGBA texture
  11554. *
  11555. * based on SpiderGL shadow map example
  11556. * http://spidergl.org/example.php?id=6
  11557. *
  11558. * originally from
  11559. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  11560. *
  11561. * see also
  11562. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  11563. */
  11564. 'depthRGBA': {
  11565. uniforms: {},
  11566. vertexShader: [
  11567. THREE.ShaderChunk[ "common" ],
  11568. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11569. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11570. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11571. "void main() {",
  11572. THREE.ShaderChunk[ "skinbase_vertex" ],
  11573. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11574. THREE.ShaderChunk[ "skinning_vertex" ],
  11575. THREE.ShaderChunk[ "default_vertex" ],
  11576. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11577. "}"
  11578. ].join( "\n" ),
  11579. fragmentShader: [
  11580. THREE.ShaderChunk[ "common" ],
  11581. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11582. "vec4 pack_depth( const in float depth ) {",
  11583. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  11584. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  11585. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  11586. " res -= res.xxyz * bit_mask;",
  11587. " return res;",
  11588. "}",
  11589. "void main() {",
  11590. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11591. " #ifdef USE_LOGDEPTHBUF_EXT",
  11592. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  11593. " #else",
  11594. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  11595. " #endif",
  11596. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  11597. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  11598. //"gl_FragData[ 0 ] = pack_depth( z );",
  11599. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  11600. "}"
  11601. ].join( "\n" )
  11602. }
  11603. };
  11604. // File:src/renderers/WebGLRenderer.js
  11605. /**
  11606. * @author supereggbert / http://www.paulbrunt.co.uk/
  11607. * @author mrdoob / http://mrdoob.com/
  11608. * @author alteredq / http://alteredqualia.com/
  11609. * @author szimek / https://github.com/szimek/
  11610. */
  11611. THREE.WebGLRenderer = function ( parameters ) {
  11612. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  11613. parameters = parameters || {};
  11614. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  11615. _context = parameters.context !== undefined ? parameters.context : null,
  11616. _width = _canvas.width,
  11617. _height = _canvas.height,
  11618. pixelRatio = 1,
  11619. _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  11620. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  11621. _depth = parameters.depth !== undefined ? parameters.depth : true,
  11622. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  11623. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  11624. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  11625. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  11626. _logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false,
  11627. _clearColor = new THREE.Color( 0x000000 ),
  11628. _clearAlpha = 0;
  11629. var lights = [];
  11630. var opaqueObjects = [];
  11631. var transparentObjects = [];
  11632. var opaqueImmediateObjects = [];
  11633. var transparentImmediateObjects = [];
  11634. var morphInfluences = new Float32Array( 8 );
  11635. var sprites = [];
  11636. var lensFlares = [];
  11637. // public properties
  11638. this.domElement = _canvas;
  11639. this.context = null;
  11640. // clearing
  11641. this.autoClear = true;
  11642. this.autoClearColor = true;
  11643. this.autoClearDepth = true;
  11644. this.autoClearStencil = true;
  11645. // scene graph
  11646. this.sortObjects = true;
  11647. // physically based shading
  11648. this.gammaFactor = 2.0; // for backwards compatibility
  11649. this.gammaInput = false;
  11650. this.gammaOutput = false;
  11651. // morphs
  11652. this.maxMorphTargets = 8;
  11653. this.maxMorphNormals = 4;
  11654. // flags
  11655. this.autoScaleCubemaps = true;
  11656. // internal properties
  11657. var _this = this,
  11658. _programs = [],
  11659. // internal state cache
  11660. _currentProgram = null,
  11661. _currentFramebuffer = null,
  11662. _currentMaterialId = - 1,
  11663. _currentGeometryProgram = '',
  11664. _currentCamera = null,
  11665. _usedTextureUnits = 0,
  11666. _viewportX = 0,
  11667. _viewportY = 0,
  11668. _viewportWidth = _canvas.width,
  11669. _viewportHeight = _canvas.height,
  11670. _currentWidth = 0,
  11671. _currentHeight = 0,
  11672. // frustum
  11673. _frustum = new THREE.Frustum(),
  11674. // camera matrices cache
  11675. _projScreenMatrix = new THREE.Matrix4(),
  11676. _vector3 = new THREE.Vector3(),
  11677. // light arrays cache
  11678. _direction = new THREE.Vector3(),
  11679. _lightsNeedUpdate = true,
  11680. _lights = {
  11681. ambient: [ 0, 0, 0 ],
  11682. directional: { length: 0, colors: [], positions: [] },
  11683. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  11684. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  11685. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  11686. },
  11687. // info
  11688. _infoMemory = {
  11689. programs: 0,
  11690. geometries: 0,
  11691. textures: 0
  11692. },
  11693. _infoRender = {
  11694. calls: 0,
  11695. vertices: 0,
  11696. faces: 0,
  11697. points: 0
  11698. };
  11699. this.info = {
  11700. render: _infoRender,
  11701. memory: _infoMemory,
  11702. programs: _programs
  11703. };
  11704. // initialize
  11705. var _gl;
  11706. try {
  11707. var attributes = {
  11708. alpha: _alpha,
  11709. depth: _depth,
  11710. stencil: _stencil,
  11711. antialias: _antialias,
  11712. premultipliedAlpha: _premultipliedAlpha,
  11713. preserveDrawingBuffer: _preserveDrawingBuffer
  11714. };
  11715. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  11716. if ( _gl === null ) {
  11717. if ( _canvas.getContext( 'webgl' ) !== null ) {
  11718. throw 'Error creating WebGL context with your selected attributes.';
  11719. } else {
  11720. throw 'Error creating WebGL context.';
  11721. }
  11722. }
  11723. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  11724. } catch ( error ) {
  11725. console.error( 'THREE.WebGLRenderer: ' + error );
  11726. }
  11727. var state = new THREE.WebGLState( _gl, paramThreeToGL );
  11728. if ( _gl.getShaderPrecisionFormat === undefined ) {
  11729. _gl.getShaderPrecisionFormat = function () {
  11730. return {
  11731. 'rangeMin': 1,
  11732. 'rangeMax': 1,
  11733. 'precision': 1
  11734. };
  11735. }
  11736. }
  11737. var properties = new THREE.WebGLProperties();
  11738. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  11739. var extensions = new THREE.WebGLExtensions( _gl );
  11740. extensions.get( 'OES_texture_float' );
  11741. extensions.get( 'OES_texture_float_linear' );
  11742. extensions.get( 'OES_texture_half_float' );
  11743. extensions.get( 'OES_texture_half_float_linear' );
  11744. extensions.get( 'OES_standard_derivatives' );
  11745. extensions.get( 'ANGLE_instanced_arrays' );
  11746. if ( extensions.get( 'OES_element_index_uint' ) ) {
  11747. THREE.BufferGeometry.MaxIndex = 4294967296;
  11748. }
  11749. if ( _logarithmicDepthBuffer ) {
  11750. extensions.get( 'EXT_frag_depth' );
  11751. }
  11752. //
  11753. function glClearColor( r, g, b, a ) {
  11754. if ( _premultipliedAlpha === true ) {
  11755. r *= a; g *= a; b *= a;
  11756. }
  11757. _gl.clearColor( r, g, b, a );
  11758. }
  11759. function setDefaultGLState() {
  11760. state.init();
  11761. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11762. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11763. }
  11764. function resetGLState() {
  11765. _currentProgram = null;
  11766. _currentCamera = null;
  11767. _currentGeometryProgram = '';
  11768. _currentMaterialId = - 1;
  11769. _lightsNeedUpdate = true;
  11770. state.reset();
  11771. }
  11772. setDefaultGLState();
  11773. this.context = _gl;
  11774. this.extensions = extensions;
  11775. this.state = state;
  11776. // shadow map
  11777. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  11778. this.shadowMap = shadowMap;
  11779. // GPU capabilities
  11780. var _maxTextures = _gl.getParameter( _gl.MAX_TEXTURE_IMAGE_UNITS );
  11781. var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11782. var _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE );
  11783. var _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11784. var _supportsVertexTextures = _maxVertexTextures > 0;
  11785. var _supportsBoneTextures = _supportsVertexTextures && extensions.get( 'OES_texture_float' );
  11786. var _supportsInstancedArrays = extensions.get( 'ANGLE_instanced_arrays' );
  11787. //
  11788. var _vertexShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.HIGH_FLOAT );
  11789. var _vertexShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.MEDIUM_FLOAT );
  11790. var _fragmentShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.HIGH_FLOAT );
  11791. var _fragmentShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.MEDIUM_FLOAT );
  11792. var getCompressedTextureFormats = ( function () {
  11793. var array;
  11794. return function getCompressedTextureFormats() {
  11795. if ( array !== undefined ) {
  11796. return array;
  11797. }
  11798. array = [];
  11799. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) || extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  11800. var formats = _gl.getParameter( _gl.COMPRESSED_TEXTURE_FORMATS );
  11801. for ( var i = 0; i < formats.length; i ++ ) {
  11802. array.push( formats[ i ] );
  11803. }
  11804. }
  11805. return array;
  11806. };
  11807. } )();
  11808. // clamp precision to maximum available
  11809. var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
  11810. var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
  11811. if ( _precision === 'highp' && ! highpAvailable ) {
  11812. if ( mediumpAvailable ) {
  11813. _precision = 'mediump';
  11814. console.warn( 'THREE.WebGLRenderer: highp not supported, using mediump.' );
  11815. } else {
  11816. _precision = 'lowp';
  11817. console.warn( 'THREE.WebGLRenderer: highp and mediump not supported, using lowp.' );
  11818. }
  11819. }
  11820. if ( _precision === 'mediump' && ! mediumpAvailable ) {
  11821. _precision = 'lowp';
  11822. console.warn( 'THREE.WebGLRenderer: mediump not supported, using lowp.' );
  11823. }
  11824. // Plugins
  11825. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  11826. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  11827. // API
  11828. this.getContext = function () {
  11829. return _gl;
  11830. };
  11831. this.getContextAttributes = function () {
  11832. return _gl.getContextAttributes();
  11833. };
  11834. this.forceContextLoss = function () {
  11835. extensions.get( 'WEBGL_lose_context' ).loseContext();
  11836. };
  11837. this.supportsVertexTextures = function () {
  11838. return _supportsVertexTextures;
  11839. };
  11840. this.supportsInstancedArrays = function () {
  11841. return _supportsInstancedArrays;
  11842. };
  11843. this.supportsFloatTextures = function () {
  11844. return extensions.get( 'OES_texture_float' );
  11845. };
  11846. this.supportsHalfFloatTextures = function () {
  11847. return extensions.get( 'OES_texture_half_float' );
  11848. };
  11849. this.supportsStandardDerivatives = function () {
  11850. return extensions.get( 'OES_standard_derivatives' );
  11851. };
  11852. this.supportsCompressedTextureS3TC = function () {
  11853. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  11854. };
  11855. this.supportsCompressedTexturePVRTC = function () {
  11856. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  11857. };
  11858. this.supportsBlendMinMax = function () {
  11859. return extensions.get( 'EXT_blend_minmax' );
  11860. };
  11861. this.getMaxAnisotropy = ( function () {
  11862. var value;
  11863. return function getMaxAnisotropy() {
  11864. if ( value !== undefined ) return value;
  11865. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11866. if ( extension !== null ) {
  11867. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11868. } else {
  11869. value = 0;
  11870. }
  11871. return value;
  11872. }
  11873. } )();
  11874. this.getPrecision = function () {
  11875. return _precision;
  11876. };
  11877. this.getPixelRatio = function () {
  11878. return pixelRatio;
  11879. };
  11880. this.setPixelRatio = function ( value ) {
  11881. if ( value !== undefined ) pixelRatio = value;
  11882. };
  11883. this.getSize = function () {
  11884. return {
  11885. width: _width,
  11886. height: _height
  11887. };
  11888. };
  11889. this.setSize = function ( width, height, updateStyle ) {
  11890. _width = width;
  11891. _height = height;
  11892. _canvas.width = width * pixelRatio;
  11893. _canvas.height = height * pixelRatio;
  11894. if ( updateStyle !== false ) {
  11895. _canvas.style.width = width + 'px';
  11896. _canvas.style.height = height + 'px';
  11897. }
  11898. this.setViewport( 0, 0, width, height );
  11899. };
  11900. this.setViewport = function ( x, y, width, height ) {
  11901. _viewportX = x * pixelRatio;
  11902. _viewportY = y * pixelRatio;
  11903. _viewportWidth = width * pixelRatio;
  11904. _viewportHeight = height * pixelRatio;
  11905. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11906. };
  11907. this.setScissor = function ( x, y, width, height ) {
  11908. _gl.scissor(
  11909. x * pixelRatio,
  11910. y * pixelRatio,
  11911. width * pixelRatio,
  11912. height * pixelRatio
  11913. );
  11914. };
  11915. this.enableScissorTest = function ( boolean ) {
  11916. state.setScissorTest( boolean );
  11917. };
  11918. // Clearing
  11919. this.getClearColor = function () {
  11920. return _clearColor;
  11921. };
  11922. this.setClearColor = function ( color, alpha ) {
  11923. _clearColor.set( color );
  11924. _clearAlpha = alpha !== undefined ? alpha : 1;
  11925. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11926. };
  11927. this.getClearAlpha = function () {
  11928. return _clearAlpha;
  11929. };
  11930. this.setClearAlpha = function ( alpha ) {
  11931. _clearAlpha = alpha;
  11932. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11933. };
  11934. this.clear = function ( color, depth, stencil ) {
  11935. var bits = 0;
  11936. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  11937. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  11938. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  11939. _gl.clear( bits );
  11940. };
  11941. this.clearColor = function () {
  11942. _gl.clear( _gl.COLOR_BUFFER_BIT );
  11943. };
  11944. this.clearDepth = function () {
  11945. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  11946. };
  11947. this.clearStencil = function () {
  11948. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  11949. };
  11950. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  11951. this.setRenderTarget( renderTarget );
  11952. this.clear( color, depth, stencil );
  11953. };
  11954. // Reset
  11955. this.resetGLState = resetGLState;
  11956. this.dispose = function() {
  11957. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  11958. };
  11959. // Events
  11960. function onContextLost( event ) {
  11961. event.preventDefault();
  11962. resetGLState();
  11963. setDefaultGLState();
  11964. objects.clear();
  11965. properties.clear();
  11966. };
  11967. function onTextureDispose( event ) {
  11968. var texture = event.target;
  11969. texture.removeEventListener( 'dispose', onTextureDispose );
  11970. deallocateTexture( texture );
  11971. _infoMemory.textures --;
  11972. }
  11973. function onRenderTargetDispose( event ) {
  11974. var renderTarget = event.target;
  11975. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  11976. deallocateRenderTarget( renderTarget );
  11977. _infoMemory.textures --;
  11978. }
  11979. function onMaterialDispose( event ) {
  11980. var material = event.target;
  11981. material.removeEventListener( 'dispose', onMaterialDispose );
  11982. deallocateMaterial( material );
  11983. }
  11984. // Buffer deallocation
  11985. function deallocateTexture( texture ) {
  11986. var textureProperties = properties.get( texture );
  11987. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  11988. // cube texture
  11989. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  11990. } else {
  11991. // 2D texture
  11992. if ( textureProperties.__webglInit === undefined ) return;
  11993. _gl.deleteTexture( textureProperties.__webglTexture );
  11994. }
  11995. // remove all webgl properties
  11996. properties.delete( texture );
  11997. }
  11998. function deallocateRenderTarget( renderTarget ) {
  11999. var renderTargetProperties = properties.get( renderTarget );
  12000. if ( ! renderTarget || renderTargetProperties.__webglTexture === undefined ) return;
  12001. _gl.deleteTexture( renderTargetProperties.__webglTexture );
  12002. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  12003. for ( var i = 0; i < 6; i ++ ) {
  12004. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12005. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  12006. }
  12007. } else {
  12008. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12009. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  12010. }
  12011. properties.delete( renderTarget );
  12012. }
  12013. function deallocateMaterial( material ) {
  12014. releaseMaterialProgramReference( material );
  12015. properties.delete( material );
  12016. }
  12017. function releaseMaterialProgramReference( material ) {
  12018. var program = properties.get( material ).program.program;
  12019. if ( program === undefined ) return;
  12020. material.program = undefined;
  12021. for ( var i = 0, n = _programs.length; i !== n; ++ i ) {
  12022. var programInfo = _programs[ i ];
  12023. if ( programInfo.program === program ) {
  12024. var newReferenceCount = -- programInfo.usedTimes;
  12025. if ( newReferenceCount === 0 ) {
  12026. // the last meterial that has been using the program let
  12027. // go of it, so remove it from the (unordered) _programs
  12028. // set and deallocate the GL resource
  12029. var newLength = n - 1;
  12030. _programs[ i ] = _programs[ newLength ];
  12031. _programs.pop();
  12032. _gl.deleteProgram( program );
  12033. _infoMemory.programs = newLength;
  12034. }
  12035. break;
  12036. }
  12037. }
  12038. }
  12039. // Buffer rendering
  12040. this.renderBufferImmediate = function ( object, program, material ) {
  12041. state.initAttributes();
  12042. var objectProperties = properties.get( object );
  12043. if ( object.hasPositions && ! objectProperties.__webglVertexBuffer ) objectProperties.__webglVertexBuffer = _gl.createBuffer();
  12044. if ( object.hasNormals && ! objectProperties.__webglNormalBuffer ) objectProperties.__webglNormalBuffer = _gl.createBuffer();
  12045. if ( object.hasUvs && ! objectProperties.__webglUvBuffer ) objectProperties.__webglUvBuffer = _gl.createBuffer();
  12046. if ( object.hasColors && ! objectProperties.__webglColorBuffer ) objectProperties.__webglColorBuffer = _gl.createBuffer();
  12047. var attributes = program.getAttributes();
  12048. if ( object.hasPositions ) {
  12049. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglVertexBuffer );
  12050. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  12051. state.enableAttribute( attributes.position );
  12052. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  12053. }
  12054. if ( object.hasNormals ) {
  12055. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglNormalBuffer );
  12056. if ( material instanceof THREE.MeshPhongMaterial === false && material.shading === THREE.FlatShading ) {
  12057. var nx, ny, nz,
  12058. nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
  12059. normalArray,
  12060. i, il = object.count * 3;
  12061. for ( i = 0; i < il; i += 9 ) {
  12062. normalArray = object.normalArray;
  12063. nax = normalArray[ i ];
  12064. nay = normalArray[ i + 1 ];
  12065. naz = normalArray[ i + 2 ];
  12066. nbx = normalArray[ i + 3 ];
  12067. nby = normalArray[ i + 4 ];
  12068. nbz = normalArray[ i + 5 ];
  12069. ncx = normalArray[ i + 6 ];
  12070. ncy = normalArray[ i + 7 ];
  12071. ncz = normalArray[ i + 8 ];
  12072. nx = ( nax + nbx + ncx ) / 3;
  12073. ny = ( nay + nby + ncy ) / 3;
  12074. nz = ( naz + nbz + ncz ) / 3;
  12075. normalArray[ i ] = nx;
  12076. normalArray[ i + 1 ] = ny;
  12077. normalArray[ i + 2 ] = nz;
  12078. normalArray[ i + 3 ] = nx;
  12079. normalArray[ i + 4 ] = ny;
  12080. normalArray[ i + 5 ] = nz;
  12081. normalArray[ i + 6 ] = nx;
  12082. normalArray[ i + 7 ] = ny;
  12083. normalArray[ i + 8 ] = nz;
  12084. }
  12085. }
  12086. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  12087. state.enableAttribute( attributes.normal );
  12088. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  12089. }
  12090. if ( object.hasUvs && material.map ) {
  12091. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglUvBuffer );
  12092. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  12093. state.enableAttribute( attributes.uv );
  12094. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  12095. }
  12096. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  12097. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglColorBuffer );
  12098. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  12099. state.enableAttribute( attributes.color );
  12100. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  12101. }
  12102. state.disableUnusedAttributes();
  12103. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  12104. object.count = 0;
  12105. };
  12106. this.renderBufferDirect = function ( camera, lights, fog, material, object ) {
  12107. if ( material instanceof THREE.MeshFaceMaterial ) {
  12108. var materials = material.materials;
  12109. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  12110. material = materials[ i ];
  12111. if ( material === null || material.visible === false ) continue;
  12112. _this.renderBufferDirect( camera, lights, fog, material, object );
  12113. }
  12114. return;
  12115. }
  12116. setMaterial( material );
  12117. var geometry = objects.geometries.get( object );
  12118. var program = setProgram( camera, lights, fog, material, object );
  12119. var updateBuffers = false,
  12120. wireframeBit = material.wireframe ? 1 : 0,
  12121. geometryProgram = geometry.id + '_' + program.id + '_' + wireframeBit;
  12122. if ( geometryProgram !== _currentGeometryProgram ) {
  12123. _currentGeometryProgram = geometryProgram;
  12124. updateBuffers = true;
  12125. }
  12126. // morph targets
  12127. var morphTargetInfluences = object.morphTargetInfluences;
  12128. if ( morphTargetInfluences !== undefined ) {
  12129. var activeInfluences = [];
  12130. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  12131. var influence = morphTargetInfluences[ i ];
  12132. activeInfluences.push( [ influence, i ] );
  12133. }
  12134. activeInfluences.sort( numericalSort );
  12135. if ( activeInfluences.length > 8 ) {
  12136. activeInfluences.length = 8;
  12137. }
  12138. var morphAttributes = geometry.morphAttributes;
  12139. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  12140. var influence = activeInfluences[ i ];
  12141. morphInfluences[ i ] = influence[ 0 ];
  12142. if ( influence[ 0 ] !== 0 ) {
  12143. var index = influence[ 1 ];
  12144. if ( material.morphTargets === true ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  12145. if ( material.morphNormals === true ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  12146. } else {
  12147. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  12148. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  12149. }
  12150. }
  12151. var uniforms = program.getUniforms();
  12152. if ( uniforms.morphTargetInfluences !== null ) {
  12153. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  12154. }
  12155. updateBuffers = true;
  12156. }
  12157. if ( object instanceof THREE.Mesh ) {
  12158. renderMesh( material, geometry, object, program, updateBuffers );
  12159. } else if ( object instanceof THREE.Line ) {
  12160. renderLine( material, geometry, object, program, updateBuffers );
  12161. } else if ( object instanceof THREE.PointCloud ) {
  12162. renderPointCloud( material, geometry, object, program, updateBuffers );
  12163. }
  12164. };
  12165. function setupVertexAttributes( material, program, geometry, startIndex ) {
  12166. var extension;
  12167. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12168. extension = extensions.get( 'ANGLE_instanced_arrays' );
  12169. if ( extension === null ) {
  12170. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12171. return;
  12172. }
  12173. }
  12174. state.initAttributes();
  12175. var geometryAttributes = geometry.attributes;
  12176. var programAttributes = program.getAttributes();
  12177. var materialDefaultAttributeValues = material.defaultAttributeValues;
  12178. for ( var name in programAttributes ) {
  12179. var programAttribute = programAttributes[ name ];
  12180. if ( programAttribute >= 0 ) {
  12181. var geometryAttribute = geometryAttributes[ name ];
  12182. if ( geometryAttribute !== undefined ) {
  12183. state.enableAttribute( programAttribute );
  12184. var size = geometryAttribute.itemSize;
  12185. var buffer = objects.getAttributeBuffer( geometryAttribute );
  12186. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  12187. var data = geometryAttribute.data;
  12188. var stride = data.stride;
  12189. var offset = geometryAttribute.offset;
  12190. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12191. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  12192. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  12193. if ( extension === null ) {
  12194. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  12195. return;
  12196. }
  12197. extension.vertexAttribDivisorANGLE( programAttribute, data.meshPerAttribute );
  12198. if ( geometry.maxInstancedCount === undefined ) {
  12199. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  12200. }
  12201. }
  12202. } else {
  12203. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12204. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  12205. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  12206. if ( extension === null ) {
  12207. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  12208. return;
  12209. }
  12210. extension.vertexAttribDivisorANGLE( programAttribute, geometryAttribute.meshPerAttribute );
  12211. if ( geometry.maxInstancedCount === undefined ) {
  12212. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  12213. }
  12214. }
  12215. }
  12216. } else if ( materialDefaultAttributeValues !== undefined ) {
  12217. var value = materialDefaultAttributeValues[ name ];
  12218. if ( value !== undefined ) {
  12219. switch ( value.length ) {
  12220. case 2:
  12221. _gl.vertexAttrib2fv( programAttribute, value );
  12222. break;
  12223. case 3:
  12224. _gl.vertexAttrib3fv( programAttribute, value );
  12225. break;
  12226. case 4:
  12227. _gl.vertexAttrib4fv( programAttribute, value );
  12228. break;
  12229. default:
  12230. _gl.vertexAttrib1fv( programAttribute, value );
  12231. }
  12232. }
  12233. }
  12234. }
  12235. }
  12236. state.disableUnusedAttributes();
  12237. }
  12238. function renderMesh( material, geometry, object, program, updateBuffers ) {
  12239. var mode = _gl.TRIANGLES;
  12240. if ( material.wireframe === true ) {
  12241. mode = _gl.LINES;
  12242. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  12243. }
  12244. var index = geometry.attributes.index;
  12245. if ( index ) {
  12246. // indexed triangles
  12247. var type, size;
  12248. var indexBuffer = objects.getAttributeBuffer( index );
  12249. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12250. type = _gl.UNSIGNED_INT;
  12251. size = 4;
  12252. } else {
  12253. type = _gl.UNSIGNED_SHORT;
  12254. size = 2;
  12255. }
  12256. var offsets = geometry.drawcalls;
  12257. if ( offsets.length === 0 ) {
  12258. if ( updateBuffers ) {
  12259. setupVertexAttributes( material, program, geometry, 0 );
  12260. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12261. }
  12262. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12263. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12264. if ( extension === null ) {
  12265. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12266. return;
  12267. }
  12268. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount ); // Draw the instanced meshes
  12269. } else {
  12270. _gl.drawElements( mode, index.array.length, type, 0 );
  12271. }
  12272. _infoRender.calls ++;
  12273. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12274. _infoRender.faces += index.array.length / 3;
  12275. } else {
  12276. // if there is more than 1 chunk
  12277. // must set attribute pointers to use new offsets for each chunk
  12278. // even if geometry and materials didn't change
  12279. updateBuffers = true;
  12280. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12281. var startIndex = offsets[ i ].index;
  12282. if ( updateBuffers ) {
  12283. setupVertexAttributes( material, program, geometry, startIndex );
  12284. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12285. }
  12286. // render indexed triangles
  12287. if ( geometry instanceof THREE.InstancedBufferGeometry && offsets[ i ].instances > 0 ) {
  12288. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12289. if ( extension === null ) {
  12290. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12291. return;
  12292. }
  12293. extension.drawElementsInstancedANGLE( mode, offsets[ i ].count, type, offsets[ i ].start * size, offsets[ i ].count, type, offsets[ i ].instances ); // Draw the instanced meshes
  12294. } else {
  12295. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12296. }
  12297. _infoRender.calls ++;
  12298. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12299. _infoRender.faces += offsets[ i ].count / 3;
  12300. }
  12301. }
  12302. } else {
  12303. // non-indexed triangles
  12304. var offsets = geometry.drawcalls;
  12305. if ( offsets.length === 0 ) {
  12306. if ( updateBuffers ) {
  12307. setupVertexAttributes( material, program, geometry, 0 );
  12308. }
  12309. var position = geometry.attributes.position;
  12310. // render non-indexed triangles
  12311. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12312. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12313. if ( extension === null ) {
  12314. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12315. return;
  12316. }
  12317. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12318. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12319. } else {
  12320. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12321. }
  12322. } else {
  12323. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12324. _gl.drawArrays( mode, 0, position.data.count );
  12325. } else {
  12326. _gl.drawArrays( mode, 0, position.count );
  12327. }
  12328. }
  12329. _infoRender.calls ++;
  12330. _infoRender.vertices += position.count;
  12331. _infoRender.faces += position.array.length / 3;
  12332. } else {
  12333. // if there is more than 1 chunk
  12334. // must set attribute pointers to use new offsets for each chunk
  12335. // even if geometry and materials didn't change
  12336. if ( updateBuffers ) {
  12337. setupVertexAttributes( material, program, geometry, 0 );
  12338. }
  12339. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12340. // render non-indexed triangles
  12341. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12342. console.error( 'THREE.WebGLRenderer.renderMesh: cannot use drawCalls with THREE.InstancedBufferGeometry.' );
  12343. return;
  12344. } else {
  12345. _gl.drawArrays( mode, offsets[ i ].start, offsets[ i ].count );
  12346. }
  12347. _infoRender.calls ++;
  12348. _infoRender.vertices += offsets[ i ].count;
  12349. _infoRender.faces += ( offsets[ i ].count ) / 3;
  12350. }
  12351. }
  12352. }
  12353. }
  12354. function renderLine( material, geometry, object, program, updateBuffers ) {
  12355. var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
  12356. // In case user is not using Line*Material by mistake
  12357. var lineWidth = material.linewidth !== undefined ? material.linewidth : 1;
  12358. state.setLineWidth( lineWidth * pixelRatio );
  12359. var index = geometry.attributes.index;
  12360. if ( index ) {
  12361. // indexed lines
  12362. var type, size;
  12363. var indexBuffer = objects.getAttributeBuffer( index );
  12364. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12365. type = _gl.UNSIGNED_INT;
  12366. size = 4;
  12367. } else {
  12368. type = _gl.UNSIGNED_SHORT;
  12369. size = 2;
  12370. }
  12371. var offsets = geometry.drawcalls;
  12372. if ( offsets.length === 0 ) {
  12373. if ( updateBuffers ) {
  12374. setupVertexAttributes( material, program, geometry, 0 );
  12375. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12376. }
  12377. _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
  12378. _infoRender.calls ++;
  12379. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12380. } else {
  12381. // if there is more than 1 chunk
  12382. // must set attribute pointers to use new offsets for each chunk
  12383. // even if geometry and materials didn't change
  12384. if ( offsets.length > 1 ) updateBuffers = true;
  12385. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12386. var startIndex = offsets[ i ].index;
  12387. if ( updateBuffers ) {
  12388. setupVertexAttributes( material, program, geometry, startIndex );
  12389. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12390. }
  12391. // render indexed lines
  12392. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16Array
  12393. _infoRender.calls ++;
  12394. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12395. }
  12396. }
  12397. } else {
  12398. // non-indexed lines
  12399. if ( updateBuffers ) {
  12400. setupVertexAttributes( material, program, geometry, 0 );
  12401. }
  12402. var position = geometry.attributes.position;
  12403. var offsets = geometry.drawcalls;
  12404. if ( offsets.length === 0 ) {
  12405. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12406. _infoRender.calls ++;
  12407. _infoRender.vertices += position.array.length / 3;
  12408. } else {
  12409. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12410. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12411. _infoRender.calls ++;
  12412. _infoRender.vertices += offsets[ i ].count;
  12413. }
  12414. }
  12415. }
  12416. }
  12417. function renderPointCloud( material, geometry, object, program, updateBuffers ) {
  12418. var mode = _gl.POINTS;
  12419. var index = geometry.attributes.index;
  12420. if ( index ) {
  12421. // indexed points
  12422. var type, size;
  12423. var indexBuffer = objects.getAttributeBuffer( index );
  12424. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12425. type = _gl.UNSIGNED_INT;
  12426. size = 4;
  12427. } else {
  12428. type = _gl.UNSIGNED_SHORT;
  12429. size = 2;
  12430. }
  12431. var offsets = geometry.drawcalls;
  12432. if ( offsets.length === 0 ) {
  12433. if ( updateBuffers ) {
  12434. setupVertexAttributes( material, program, geometry, 0 );
  12435. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12436. }
  12437. _gl.drawElements( mode, index.array.length, type, 0 );
  12438. _infoRender.calls ++;
  12439. _infoRender.points += index.array.length;
  12440. } else {
  12441. // if there is more than 1 chunk
  12442. // must set attribute pointers to use new offsets for each chunk
  12443. // even if geometry and materials didn't change
  12444. if ( offsets.length > 1 ) updateBuffers = true;
  12445. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12446. var startIndex = offsets[ i ].index;
  12447. if ( updateBuffers ) {
  12448. setupVertexAttributes( material, program, geometry, startIndex );
  12449. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12450. }
  12451. // render indexed points
  12452. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12453. _infoRender.calls ++;
  12454. _infoRender.points += offsets[ i ].count;
  12455. }
  12456. }
  12457. } else {
  12458. // non-indexed points
  12459. if ( updateBuffers ) {
  12460. setupVertexAttributes( material, program, geometry, 0 );
  12461. }
  12462. var position = geometry.attributes.position;
  12463. var offsets = geometry.drawcalls;
  12464. if ( offsets.length === 0 ) {
  12465. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12466. _infoRender.calls ++;
  12467. _infoRender.points += position.array.length / 3;
  12468. } else {
  12469. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12470. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12471. _infoRender.calls ++;
  12472. _infoRender.points += offsets[ i ].count;
  12473. }
  12474. }
  12475. }
  12476. }
  12477. // Sorting
  12478. function numericalSort ( a, b ) {
  12479. return b[ 0 ] - a[ 0 ];
  12480. }
  12481. function painterSortStable ( a, b ) {
  12482. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12483. return a.object.renderOrder - b.object.renderOrder;
  12484. } else if ( a.object.material.id !== b.object.material.id ) {
  12485. return a.object.material.id - b.object.material.id;
  12486. } else if ( a.z !== b.z ) {
  12487. return a.z - b.z;
  12488. } else {
  12489. return a.id - b.id;
  12490. }
  12491. }
  12492. function reversePainterSortStable ( a, b ) {
  12493. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12494. return a.object.renderOrder - b.object.renderOrder;
  12495. } if ( a.z !== b.z ) {
  12496. return b.z - a.z;
  12497. } else {
  12498. return a.id - b.id;
  12499. }
  12500. }
  12501. // Rendering
  12502. this.render = function ( scene, camera, renderTarget, forceClear ) {
  12503. if ( camera instanceof THREE.Camera === false ) {
  12504. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  12505. return;
  12506. }
  12507. var fog = scene.fog;
  12508. // reset caching for this frame
  12509. _currentGeometryProgram = '';
  12510. _currentMaterialId = - 1;
  12511. _currentCamera = null;
  12512. _lightsNeedUpdate = true;
  12513. // update scene graph
  12514. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  12515. // update camera matrices and frustum
  12516. if ( camera.parent === undefined ) camera.updateMatrixWorld();
  12517. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12518. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  12519. _frustum.setFromMatrix( _projScreenMatrix );
  12520. lights.length = 0;
  12521. opaqueObjects.length = 0;
  12522. transparentObjects.length = 0;
  12523. opaqueImmediateObjects.length = 0;
  12524. transparentImmediateObjects.length = 0;
  12525. sprites.length = 0;
  12526. lensFlares.length = 0;
  12527. projectObject( scene );
  12528. if ( _this.sortObjects === true ) {
  12529. opaqueObjects.sort( painterSortStable );
  12530. transparentObjects.sort( reversePainterSortStable );
  12531. }
  12532. objects.update( opaqueObjects );
  12533. objects.update( transparentObjects );
  12534. //
  12535. shadowMap.render( scene, camera );
  12536. //
  12537. _infoRender.calls = 0;
  12538. _infoRender.vertices = 0;
  12539. _infoRender.faces = 0;
  12540. _infoRender.points = 0;
  12541. this.setRenderTarget( renderTarget );
  12542. if ( this.autoClear || forceClear ) {
  12543. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  12544. }
  12545. //
  12546. if ( scene.overrideMaterial ) {
  12547. var overrideMaterial = scene.overrideMaterial;
  12548. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  12549. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  12550. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, overrideMaterial );
  12551. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, overrideMaterial );
  12552. } else {
  12553. // opaque pass (front-to-back order)
  12554. state.setBlending( THREE.NoBlending );
  12555. renderObjects( opaqueObjects, camera, lights, fog, null );
  12556. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, null );
  12557. // transparent pass (back-to-front order)
  12558. renderObjects( transparentObjects, camera, lights, fog, null );
  12559. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, null );
  12560. }
  12561. // custom render plugins (post pass)
  12562. spritePlugin.render( scene, camera );
  12563. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  12564. // Generate mipmap if we're using any kind of mipmap filtering
  12565. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  12566. updateRenderTargetMipmap( renderTarget );
  12567. }
  12568. // Ensure depth buffer writing is enabled so it can be cleared on next render
  12569. state.setDepthTest( true );
  12570. state.setDepthWrite( true );
  12571. state.setColorWrite( true );
  12572. // _gl.finish();
  12573. };
  12574. function projectObject( object ) {
  12575. if ( object.visible === false ) return;
  12576. if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
  12577. // skip
  12578. } else {
  12579. // update Skeleton objects
  12580. if ( object instanceof THREE.SkinnedMesh ) {
  12581. object.skeleton.update();
  12582. }
  12583. objects.init( object );
  12584. if ( object instanceof THREE.Light ) {
  12585. lights.push( object );
  12586. } else if ( object instanceof THREE.Sprite ) {
  12587. sprites.push( object );
  12588. } else if ( object instanceof THREE.LensFlare ) {
  12589. lensFlares.push( object );
  12590. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  12591. var material = object.material;
  12592. if ( material.transparent ) {
  12593. transparentImmediateObjects.push( object );
  12594. } else {
  12595. opaqueImmediateObjects.push( object );
  12596. }
  12597. } else {
  12598. var webglObject = objects.objects[ object.id ];
  12599. if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  12600. var material = object.material;
  12601. if ( material !== null && material.visible === true ) {
  12602. if ( properties.get( material ) ) {
  12603. material.program = properties.get( material ).program;
  12604. }
  12605. if ( material.transparent ) {
  12606. transparentObjects.push( webglObject );
  12607. } else {
  12608. opaqueObjects.push( webglObject );
  12609. }
  12610. if ( _this.sortObjects === true ) {
  12611. _vector3.setFromMatrixPosition( object.matrixWorld );
  12612. _vector3.applyProjection( _projScreenMatrix );
  12613. webglObject.z = _vector3.z;
  12614. }
  12615. }
  12616. }
  12617. }
  12618. }
  12619. var children = object.children;
  12620. for ( var i = 0, l = children.length; i < l; i ++ ) {
  12621. projectObject( children[ i ] );
  12622. }
  12623. }
  12624. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  12625. var material = overrideMaterial;
  12626. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12627. var webglObject = renderList[ i ];
  12628. var object = webglObject.object;
  12629. setupMatrices( object, camera );
  12630. if ( overrideMaterial === null ) material = object.material;
  12631. _this.renderBufferDirect( camera, lights, fog, material, object );
  12632. }
  12633. }
  12634. function renderObjectsImmediate( renderList, camera, lights, fog, overrideMaterial ) {
  12635. var material = overrideMaterial;
  12636. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12637. var object = renderList[ i ];
  12638. setupMatrices( object, camera );
  12639. if ( object.visible === true ) {
  12640. if ( overrideMaterial === null ) material = object.material;
  12641. _this.renderImmediateObject( camera, lights, fog, material, object );
  12642. }
  12643. }
  12644. }
  12645. this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
  12646. setMaterial( material );
  12647. var program = setProgram( camera, lights, fog, material, object );
  12648. _currentGeometryProgram = '';
  12649. object.render( function ( object ) {
  12650. _this.renderBufferImmediate( object, program, material );
  12651. } );
  12652. };
  12653. // Materials
  12654. var shaderIDs = {
  12655. MeshDepthMaterial: 'depth',
  12656. MeshNormalMaterial: 'normal',
  12657. MeshBasicMaterial: 'basic',
  12658. MeshLambertMaterial: 'lambert',
  12659. MeshPhongMaterial: 'phong',
  12660. LineBasicMaterial: 'basic',
  12661. LineDashedMaterial: 'dashed',
  12662. PointCloudMaterial: 'particle_basic'
  12663. };
  12664. function initMaterial( material, lights, fog, object ) {
  12665. var materialProperties = properties.get( material );
  12666. var shaderID = shaderIDs[ material.type ];
  12667. // heuristics to create shader parameters according to lights in the scene
  12668. // (not to blow over maxLights budget)
  12669. var maxLightCount = allocateLights( lights );
  12670. var maxShadows = allocateShadows( lights );
  12671. var maxBones = allocateBones( object );
  12672. var parameters = {
  12673. precision: _precision,
  12674. supportsVertexTextures: _supportsVertexTextures,
  12675. map: !! material.map,
  12676. envMap: !! material.envMap,
  12677. envMapMode: material.envMap && material.envMap.mapping,
  12678. lightMap: !! material.lightMap,
  12679. aoMap: !! material.aoMap,
  12680. emissiveMap: !! material.emissiveMap,
  12681. bumpMap: !! material.bumpMap,
  12682. normalMap: !! material.normalMap,
  12683. specularMap: !! material.specularMap,
  12684. alphaMap: !! material.alphaMap,
  12685. combine: material.combine,
  12686. vertexColors: material.vertexColors,
  12687. fog: fog,
  12688. useFog: material.fog,
  12689. fogExp: fog instanceof THREE.FogExp2,
  12690. flatShading: material.shading === THREE.FlatShading,
  12691. sizeAttenuation: material.sizeAttenuation,
  12692. logarithmicDepthBuffer: _logarithmicDepthBuffer,
  12693. skinning: material.skinning,
  12694. maxBones: maxBones,
  12695. useVertexTexture: _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  12696. morphTargets: material.morphTargets,
  12697. morphNormals: material.morphNormals,
  12698. maxMorphTargets: _this.maxMorphTargets,
  12699. maxMorphNormals: _this.maxMorphNormals,
  12700. maxDirLights: maxLightCount.directional,
  12701. maxPointLights: maxLightCount.point,
  12702. maxSpotLights: maxLightCount.spot,
  12703. maxHemiLights: maxLightCount.hemi,
  12704. maxShadows: maxShadows,
  12705. shadowMapEnabled: shadowMap.enabled && object.receiveShadow && maxShadows > 0,
  12706. shadowMapType: shadowMap.type,
  12707. shadowMapDebug: shadowMap.debug,
  12708. alphaTest: material.alphaTest,
  12709. metal: material.metal,
  12710. doubleSided: material.side === THREE.DoubleSide,
  12711. flipSided: material.side === THREE.BackSide
  12712. };
  12713. // Generate code
  12714. var chunks = [];
  12715. if ( shaderID ) {
  12716. chunks.push( shaderID );
  12717. } else {
  12718. chunks.push( material.fragmentShader );
  12719. chunks.push( material.vertexShader );
  12720. }
  12721. if ( material.defines !== undefined ) {
  12722. for ( var name in material.defines ) {
  12723. chunks.push( name );
  12724. chunks.push( material.defines[ name ] );
  12725. }
  12726. }
  12727. for ( var name in parameters ) {
  12728. chunks.push( name );
  12729. chunks.push( parameters[ name ] );
  12730. }
  12731. var code = chunks.join();
  12732. var programChange = true;
  12733. if ( ! materialProperties.program ) {
  12734. // new material
  12735. material.addEventListener( 'dispose', onMaterialDispose );
  12736. } else if ( materialProperties.program.code !== code ) {
  12737. // changed glsl or parameters
  12738. releaseMaterialProgramReference( material );
  12739. } else if ( shaderID !== undefined ) {
  12740. // same glsl and uniform list
  12741. return;
  12742. } else {
  12743. // only rebuild uniform list
  12744. programChange = false;
  12745. }
  12746. if ( shaderID ) {
  12747. var shader = THREE.ShaderLib[ shaderID ];
  12748. materialProperties.__webglShader = {
  12749. name: material.type,
  12750. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  12751. vertexShader: shader.vertexShader,
  12752. fragmentShader: shader.fragmentShader
  12753. };
  12754. } else {
  12755. materialProperties.__webglShader = {
  12756. name: material.type,
  12757. uniforms: material.uniforms,
  12758. vertexShader: material.vertexShader,
  12759. fragmentShader: material.fragmentShader
  12760. };
  12761. }
  12762. var program;
  12763. // Check if code has been already compiled
  12764. for ( var p = 0, pl = _programs.length; p < pl; p ++ ) {
  12765. var programInfo = _programs[ p ];
  12766. if ( programInfo.code === code ) {
  12767. program = programInfo;
  12768. if ( programChange ) {
  12769. program.usedTimes ++;
  12770. }
  12771. break;
  12772. }
  12773. }
  12774. if ( program === undefined ) {
  12775. material.__webglShader = materialProperties.__webglShader;
  12776. program = new THREE.WebGLProgram( _this, code, material, parameters );
  12777. _programs.push( program );
  12778. _infoMemory.programs = _programs.length;
  12779. }
  12780. materialProperties.program = program;
  12781. var attributes = program.getAttributes();
  12782. if ( material.morphTargets ) {
  12783. material.numSupportedMorphTargets = 0;
  12784. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  12785. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  12786. material.numSupportedMorphTargets ++;
  12787. }
  12788. }
  12789. }
  12790. if ( material.morphNormals ) {
  12791. material.numSupportedMorphNormals = 0;
  12792. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  12793. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  12794. material.numSupportedMorphNormals ++;
  12795. }
  12796. }
  12797. }
  12798. materialProperties.uniformsList = [];
  12799. var uniformLocations = materialProperties.program.getUniforms();
  12800. for ( var u in materialProperties.__webglShader.uniforms ) {
  12801. var location = uniformLocations[ u ];
  12802. if ( location ) {
  12803. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  12804. }
  12805. }
  12806. }
  12807. function setMaterial( material ) {
  12808. setMaterialFaces( material );
  12809. if ( material.transparent === true ) {
  12810. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  12811. } else {
  12812. state.setBlending( THREE.NoBlending );
  12813. }
  12814. state.setDepthFunc( material.depthFunc );
  12815. state.setDepthTest( material.depthTest );
  12816. state.setDepthWrite( material.depthWrite );
  12817. state.setColorWrite( material.colorWrite );
  12818. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12819. }
  12820. function setMaterialFaces( material ) {
  12821. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  12822. state.setFlipSided( material.side === THREE.BackSide );
  12823. }
  12824. function setProgram( camera, lights, fog, material, object ) {
  12825. _usedTextureUnits = 0;
  12826. var materialProperties = properties.get( material );
  12827. if ( material.needsUpdate || ! materialProperties.program ) {
  12828. initMaterial( material, lights, fog, object );
  12829. material.needsUpdate = false;
  12830. }
  12831. var refreshProgram = false;
  12832. var refreshMaterial = false;
  12833. var refreshLights = false;
  12834. var program = materialProperties.program,
  12835. p_uniforms = program.getUniforms(),
  12836. m_uniforms = materialProperties.__webglShader.uniforms;
  12837. if ( program.id !== _currentProgram ) {
  12838. _gl.useProgram( program.program );
  12839. _currentProgram = program.id;
  12840. refreshProgram = true;
  12841. refreshMaterial = true;
  12842. refreshLights = true;
  12843. }
  12844. if ( material.id !== _currentMaterialId ) {
  12845. if ( _currentMaterialId === - 1 ) refreshLights = true;
  12846. _currentMaterialId = material.id;
  12847. refreshMaterial = true;
  12848. }
  12849. if ( refreshProgram || camera !== _currentCamera ) {
  12850. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  12851. if ( _logarithmicDepthBuffer ) {
  12852. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  12853. }
  12854. if ( camera !== _currentCamera ) _currentCamera = camera;
  12855. // load material specific uniforms
  12856. // (shader material also gets them for the sake of genericity)
  12857. if ( material instanceof THREE.ShaderMaterial ||
  12858. material instanceof THREE.MeshPhongMaterial ||
  12859. material.envMap ) {
  12860. if ( p_uniforms.cameraPosition !== undefined ) {
  12861. _vector3.setFromMatrixPosition( camera.matrixWorld );
  12862. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  12863. }
  12864. }
  12865. if ( material instanceof THREE.MeshPhongMaterial ||
  12866. material instanceof THREE.MeshLambertMaterial ||
  12867. material instanceof THREE.MeshBasicMaterial ||
  12868. material instanceof THREE.ShaderMaterial ||
  12869. material.skinning ) {
  12870. if ( p_uniforms.viewMatrix !== undefined ) {
  12871. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  12872. }
  12873. }
  12874. }
  12875. // skinning uniforms must be set even if material didn't change
  12876. // auto-setting of texture unit for bone texture must go before other textures
  12877. // not sure why, but otherwise weird things happen
  12878. if ( material.skinning ) {
  12879. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  12880. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  12881. }
  12882. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  12883. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  12884. }
  12885. if ( _supportsBoneTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  12886. if ( p_uniforms.boneTexture !== undefined ) {
  12887. var textureUnit = getTextureUnit();
  12888. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  12889. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  12890. }
  12891. if ( p_uniforms.boneTextureWidth !== undefined ) {
  12892. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  12893. }
  12894. if ( p_uniforms.boneTextureHeight !== undefined ) {
  12895. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  12896. }
  12897. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  12898. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  12899. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  12900. }
  12901. }
  12902. }
  12903. if ( refreshMaterial ) {
  12904. // refresh uniforms common to several materials
  12905. if ( fog && material.fog ) {
  12906. refreshUniformsFog( m_uniforms, fog );
  12907. }
  12908. if ( material instanceof THREE.MeshPhongMaterial ||
  12909. material instanceof THREE.MeshLambertMaterial ||
  12910. material.lights ) {
  12911. if ( _lightsNeedUpdate ) {
  12912. refreshLights = true;
  12913. setupLights( lights );
  12914. _lightsNeedUpdate = false;
  12915. }
  12916. if ( refreshLights ) {
  12917. refreshUniformsLights( m_uniforms, _lights );
  12918. markUniformsLightsNeedsUpdate( m_uniforms, true );
  12919. } else {
  12920. markUniformsLightsNeedsUpdate( m_uniforms, false );
  12921. }
  12922. }
  12923. if ( material instanceof THREE.MeshBasicMaterial ||
  12924. material instanceof THREE.MeshLambertMaterial ||
  12925. material instanceof THREE.MeshPhongMaterial ) {
  12926. refreshUniformsCommon( m_uniforms, material );
  12927. }
  12928. // refresh single material specific uniforms
  12929. if ( material instanceof THREE.LineBasicMaterial ) {
  12930. refreshUniformsLine( m_uniforms, material );
  12931. } else if ( material instanceof THREE.LineDashedMaterial ) {
  12932. refreshUniformsLine( m_uniforms, material );
  12933. refreshUniformsDash( m_uniforms, material );
  12934. } else if ( material instanceof THREE.PointCloudMaterial ) {
  12935. refreshUniformsParticle( m_uniforms, material );
  12936. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  12937. refreshUniformsPhong( m_uniforms, material );
  12938. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  12939. refreshUniformsLambert( m_uniforms, material );
  12940. } else if ( material instanceof THREE.MeshBasicMaterial ) {
  12941. refreshUniformsBasic( m_uniforms, material );
  12942. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  12943. m_uniforms.mNear.value = camera.near;
  12944. m_uniforms.mFar.value = camera.far;
  12945. m_uniforms.opacity.value = material.opacity;
  12946. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  12947. m_uniforms.opacity.value = material.opacity;
  12948. }
  12949. if ( object.receiveShadow && ! material._shadowPass ) {
  12950. refreshUniformsShadow( m_uniforms, lights );
  12951. }
  12952. // load common uniforms
  12953. loadUniformsGeneric( materialProperties.uniformsList );
  12954. }
  12955. loadUniformsMatrices( p_uniforms, object );
  12956. if ( p_uniforms.modelMatrix !== undefined ) {
  12957. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  12958. }
  12959. return program;
  12960. }
  12961. // Uniforms (refresh uniforms objects)
  12962. function refreshUniformsCommon ( uniforms, material ) {
  12963. uniforms.opacity.value = material.opacity;
  12964. uniforms.diffuse.value = material.color;
  12965. uniforms.map.value = material.map;
  12966. uniforms.specularMap.value = material.specularMap;
  12967. uniforms.alphaMap.value = material.alphaMap;
  12968. if ( material.bumpMap ) {
  12969. uniforms.bumpMap.value = material.bumpMap;
  12970. uniforms.bumpScale.value = material.bumpScale;
  12971. }
  12972. if ( material.normalMap ) {
  12973. uniforms.normalMap.value = material.normalMap;
  12974. uniforms.normalScale.value.copy( material.normalScale );
  12975. }
  12976. // uv repeat and offset setting priorities
  12977. // 1. color map
  12978. // 2. specular map
  12979. // 3. normal map
  12980. // 4. bump map
  12981. // 5. alpha map
  12982. // 6. emissive map
  12983. var uvScaleMap;
  12984. if ( material.map ) {
  12985. uvScaleMap = material.map;
  12986. } else if ( material.specularMap ) {
  12987. uvScaleMap = material.specularMap;
  12988. } else if ( material.normalMap ) {
  12989. uvScaleMap = material.normalMap;
  12990. } else if ( material.bumpMap ) {
  12991. uvScaleMap = material.bumpMap;
  12992. } else if ( material.alphaMap ) {
  12993. uvScaleMap = material.alphaMap;
  12994. } else if ( material.emissiveMap ) {
  12995. uvScaleMap = material.emissiveMap;
  12996. }
  12997. if ( uvScaleMap !== undefined ) {
  12998. var offset = uvScaleMap.offset;
  12999. var repeat = uvScaleMap.repeat;
  13000. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13001. }
  13002. uniforms.envMap.value = material.envMap;
  13003. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  13004. uniforms.reflectivity.value = material.reflectivity;
  13005. uniforms.refractionRatio.value = material.refractionRatio;
  13006. }
  13007. function refreshUniformsLine ( uniforms, material ) {
  13008. uniforms.diffuse.value = material.color;
  13009. uniforms.opacity.value = material.opacity;
  13010. }
  13011. function refreshUniformsDash ( uniforms, material ) {
  13012. uniforms.dashSize.value = material.dashSize;
  13013. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13014. uniforms.scale.value = material.scale;
  13015. }
  13016. function refreshUniformsParticle ( uniforms, material ) {
  13017. uniforms.psColor.value = material.color;
  13018. uniforms.opacity.value = material.opacity;
  13019. uniforms.size.value = material.size;
  13020. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  13021. uniforms.map.value = material.map;
  13022. if ( material.map !== null ) {
  13023. var offset = material.map.offset;
  13024. var repeat = material.map.repeat;
  13025. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13026. }
  13027. }
  13028. function refreshUniformsFog ( uniforms, fog ) {
  13029. uniforms.fogColor.value = fog.color;
  13030. if ( fog instanceof THREE.Fog ) {
  13031. uniforms.fogNear.value = fog.near;
  13032. uniforms.fogFar.value = fog.far;
  13033. } else if ( fog instanceof THREE.FogExp2 ) {
  13034. uniforms.fogDensity.value = fog.density;
  13035. }
  13036. }
  13037. function refreshUniformsPhong ( uniforms, material ) {
  13038. uniforms.shininess.value = material.shininess;
  13039. uniforms.emissive.value = material.emissive;
  13040. uniforms.specular.value = material.specular;
  13041. uniforms.lightMap.value = material.lightMap;
  13042. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13043. uniforms.aoMap.value = material.aoMap;
  13044. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13045. uniforms.emissiveMap.value = material.emissiveMap;
  13046. }
  13047. function refreshUniformsLambert ( uniforms, material ) {
  13048. uniforms.emissive.value = material.emissive;
  13049. }
  13050. function refreshUniformsBasic ( uniforms, material ) {
  13051. uniforms.aoMap.value = material.aoMap;
  13052. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13053. }
  13054. function refreshUniformsLights ( uniforms, lights ) {
  13055. uniforms.ambientLightColor.value = lights.ambient;
  13056. uniforms.directionalLightColor.value = lights.directional.colors;
  13057. uniforms.directionalLightDirection.value = lights.directional.positions;
  13058. uniforms.pointLightColor.value = lights.point.colors;
  13059. uniforms.pointLightPosition.value = lights.point.positions;
  13060. uniforms.pointLightDistance.value = lights.point.distances;
  13061. uniforms.pointLightDecay.value = lights.point.decays;
  13062. uniforms.spotLightColor.value = lights.spot.colors;
  13063. uniforms.spotLightPosition.value = lights.spot.positions;
  13064. uniforms.spotLightDistance.value = lights.spot.distances;
  13065. uniforms.spotLightDirection.value = lights.spot.directions;
  13066. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  13067. uniforms.spotLightExponent.value = lights.spot.exponents;
  13068. uniforms.spotLightDecay.value = lights.spot.decays;
  13069. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  13070. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  13071. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  13072. }
  13073. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13074. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  13075. uniforms.ambientLightColor.needsUpdate = value;
  13076. uniforms.directionalLightColor.needsUpdate = value;
  13077. uniforms.directionalLightDirection.needsUpdate = value;
  13078. uniforms.pointLightColor.needsUpdate = value;
  13079. uniforms.pointLightPosition.needsUpdate = value;
  13080. uniforms.pointLightDistance.needsUpdate = value;
  13081. uniforms.pointLightDecay.needsUpdate = value;
  13082. uniforms.spotLightColor.needsUpdate = value;
  13083. uniforms.spotLightPosition.needsUpdate = value;
  13084. uniforms.spotLightDistance.needsUpdate = value;
  13085. uniforms.spotLightDirection.needsUpdate = value;
  13086. uniforms.spotLightAngleCos.needsUpdate = value;
  13087. uniforms.spotLightExponent.needsUpdate = value;
  13088. uniforms.spotLightDecay.needsUpdate = value;
  13089. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  13090. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  13091. uniforms.hemisphereLightDirection.needsUpdate = value;
  13092. }
  13093. function refreshUniformsShadow ( uniforms, lights ) {
  13094. if ( uniforms.shadowMatrix ) {
  13095. var j = 0;
  13096. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  13097. var light = lights[ i ];
  13098. if ( ! light.castShadow ) continue;
  13099. if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight ) ) {
  13100. uniforms.shadowMap.value[ j ] = light.shadowMap;
  13101. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  13102. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  13103. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  13104. uniforms.shadowBias.value[ j ] = light.shadowBias;
  13105. j ++;
  13106. }
  13107. }
  13108. }
  13109. }
  13110. // Uniforms (load to GPU)
  13111. function loadUniformsMatrices ( uniforms, object ) {
  13112. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
  13113. if ( uniforms.normalMatrix ) {
  13114. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
  13115. }
  13116. }
  13117. function getTextureUnit() {
  13118. var textureUnit = _usedTextureUnits;
  13119. if ( textureUnit >= _maxTextures ) {
  13120. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + _maxTextures );
  13121. }
  13122. _usedTextureUnits += 1;
  13123. return textureUnit;
  13124. }
  13125. function loadUniformsGeneric ( uniforms ) {
  13126. var texture, textureUnit, offset;
  13127. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  13128. var uniform = uniforms[ j ][ 0 ];
  13129. // needsUpdate property is not added to all uniforms.
  13130. if ( uniform.needsUpdate === false ) continue;
  13131. var type = uniform.type;
  13132. var value = uniform.value;
  13133. var location = uniforms[ j ][ 1 ];
  13134. switch ( type ) {
  13135. case '1i':
  13136. _gl.uniform1i( location, value );
  13137. break;
  13138. case '1f':
  13139. _gl.uniform1f( location, value );
  13140. break;
  13141. case '2f':
  13142. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  13143. break;
  13144. case '3f':
  13145. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  13146. break;
  13147. case '4f':
  13148. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  13149. break;
  13150. case '1iv':
  13151. _gl.uniform1iv( location, value );
  13152. break;
  13153. case '3iv':
  13154. _gl.uniform3iv( location, value );
  13155. break;
  13156. case '1fv':
  13157. _gl.uniform1fv( location, value );
  13158. break;
  13159. case '2fv':
  13160. _gl.uniform2fv( location, value );
  13161. break;
  13162. case '3fv':
  13163. _gl.uniform3fv( location, value );
  13164. break;
  13165. case '4fv':
  13166. _gl.uniform4fv( location, value );
  13167. break;
  13168. case 'Matrix3fv':
  13169. _gl.uniformMatrix3fv( location, false, value );
  13170. break;
  13171. case 'Matrix4fv':
  13172. _gl.uniformMatrix4fv( location, false, value );
  13173. break;
  13174. //
  13175. case 'i':
  13176. // single integer
  13177. _gl.uniform1i( location, value );
  13178. break;
  13179. case 'f':
  13180. // single float
  13181. _gl.uniform1f( location, value );
  13182. break;
  13183. case 'v2':
  13184. // single THREE.Vector2
  13185. _gl.uniform2f( location, value.x, value.y );
  13186. break;
  13187. case 'v3':
  13188. // single THREE.Vector3
  13189. _gl.uniform3f( location, value.x, value.y, value.z );
  13190. break;
  13191. case 'v4':
  13192. // single THREE.Vector4
  13193. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  13194. break;
  13195. case 'c':
  13196. // single THREE.Color
  13197. _gl.uniform3f( location, value.r, value.g, value.b );
  13198. break;
  13199. case 'iv1':
  13200. // flat array of integers (JS or typed array)
  13201. _gl.uniform1iv( location, value );
  13202. break;
  13203. case 'iv':
  13204. // flat array of integers with 3 x N size (JS or typed array)
  13205. _gl.uniform3iv( location, value );
  13206. break;
  13207. case 'fv1':
  13208. // flat array of floats (JS or typed array)
  13209. _gl.uniform1fv( location, value );
  13210. break;
  13211. case 'fv':
  13212. // flat array of floats with 3 x N size (JS or typed array)
  13213. _gl.uniform3fv( location, value );
  13214. break;
  13215. case 'v2v':
  13216. // array of THREE.Vector2
  13217. if ( uniform._array === undefined ) {
  13218. uniform._array = new Float32Array( 2 * value.length );
  13219. }
  13220. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13221. offset = i * 2;
  13222. uniform._array[ offset + 0 ] = value[ i ].x;
  13223. uniform._array[ offset + 1 ] = value[ i ].y;
  13224. }
  13225. _gl.uniform2fv( location, uniform._array );
  13226. break;
  13227. case 'v3v':
  13228. // array of THREE.Vector3
  13229. if ( uniform._array === undefined ) {
  13230. uniform._array = new Float32Array( 3 * value.length );
  13231. }
  13232. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13233. offset = i * 3;
  13234. uniform._array[ offset + 0 ] = value[ i ].x;
  13235. uniform._array[ offset + 1 ] = value[ i ].y;
  13236. uniform._array[ offset + 2 ] = value[ i ].z;
  13237. }
  13238. _gl.uniform3fv( location, uniform._array );
  13239. break;
  13240. case 'v4v':
  13241. // array of THREE.Vector4
  13242. if ( uniform._array === undefined ) {
  13243. uniform._array = new Float32Array( 4 * value.length );
  13244. }
  13245. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13246. offset = i * 4;
  13247. uniform._array[ offset + 0 ] = value[ i ].x;
  13248. uniform._array[ offset + 1 ] = value[ i ].y;
  13249. uniform._array[ offset + 2 ] = value[ i ].z;
  13250. uniform._array[ offset + 3 ] = value[ i ].w;
  13251. }
  13252. _gl.uniform4fv( location, uniform._array );
  13253. break;
  13254. case 'm3':
  13255. // single THREE.Matrix3
  13256. _gl.uniformMatrix3fv( location, false, value.elements );
  13257. break;
  13258. case 'm3v':
  13259. // array of THREE.Matrix3
  13260. if ( uniform._array === undefined ) {
  13261. uniform._array = new Float32Array( 9 * value.length );
  13262. }
  13263. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13264. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  13265. }
  13266. _gl.uniformMatrix3fv( location, false, uniform._array );
  13267. break;
  13268. case 'm4':
  13269. // single THREE.Matrix4
  13270. _gl.uniformMatrix4fv( location, false, value.elements );
  13271. break;
  13272. case 'm4v':
  13273. // array of THREE.Matrix4
  13274. if ( uniform._array === undefined ) {
  13275. uniform._array = new Float32Array( 16 * value.length );
  13276. }
  13277. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13278. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  13279. }
  13280. _gl.uniformMatrix4fv( location, false, uniform._array );
  13281. break;
  13282. case 't':
  13283. // single THREE.Texture (2d or cube)
  13284. texture = value;
  13285. textureUnit = getTextureUnit();
  13286. _gl.uniform1i( location, textureUnit );
  13287. if ( ! texture ) continue;
  13288. if ( texture instanceof THREE.CubeTexture ||
  13289. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13290. // CompressedTexture can have Array in image :/
  13291. setCubeTexture( texture, textureUnit );
  13292. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  13293. setCubeTextureDynamic( texture, textureUnit );
  13294. } else {
  13295. _this.setTexture( texture, textureUnit );
  13296. }
  13297. break;
  13298. case 'tv':
  13299. // array of THREE.Texture (2d)
  13300. if ( uniform._array === undefined ) {
  13301. uniform._array = [];
  13302. }
  13303. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13304. uniform._array[ i ] = getTextureUnit();
  13305. }
  13306. _gl.uniform1iv( location, uniform._array );
  13307. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13308. texture = uniform.value[ i ];
  13309. textureUnit = uniform._array[ i ];
  13310. if ( ! texture ) continue;
  13311. _this.setTexture( texture, textureUnit );
  13312. }
  13313. break;
  13314. default:
  13315. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  13316. }
  13317. }
  13318. }
  13319. function setupMatrices( object, camera ) {
  13320. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13321. object._normalMatrix.getNormalMatrix( object._modelViewMatrix );
  13322. }
  13323. function setColorLinear( array, offset, color, intensity ) {
  13324. array[ offset + 0 ] = color.r * intensity;
  13325. array[ offset + 1 ] = color.g * intensity;
  13326. array[ offset + 2 ] = color.b * intensity;
  13327. }
  13328. function setupLights ( lights ) {
  13329. var l, ll, light,
  13330. r = 0, g = 0, b = 0,
  13331. color, skyColor, groundColor,
  13332. intensity,
  13333. distance,
  13334. zlights = _lights,
  13335. dirColors = zlights.directional.colors,
  13336. dirPositions = zlights.directional.positions,
  13337. pointColors = zlights.point.colors,
  13338. pointPositions = zlights.point.positions,
  13339. pointDistances = zlights.point.distances,
  13340. pointDecays = zlights.point.decays,
  13341. spotColors = zlights.spot.colors,
  13342. spotPositions = zlights.spot.positions,
  13343. spotDistances = zlights.spot.distances,
  13344. spotDirections = zlights.spot.directions,
  13345. spotAnglesCos = zlights.spot.anglesCos,
  13346. spotExponents = zlights.spot.exponents,
  13347. spotDecays = zlights.spot.decays,
  13348. hemiSkyColors = zlights.hemi.skyColors,
  13349. hemiGroundColors = zlights.hemi.groundColors,
  13350. hemiPositions = zlights.hemi.positions,
  13351. dirLength = 0,
  13352. pointLength = 0,
  13353. spotLength = 0,
  13354. hemiLength = 0,
  13355. dirCount = 0,
  13356. pointCount = 0,
  13357. spotCount = 0,
  13358. hemiCount = 0,
  13359. dirOffset = 0,
  13360. pointOffset = 0,
  13361. spotOffset = 0,
  13362. hemiOffset = 0;
  13363. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  13364. light = lights[ l ];
  13365. if ( light.onlyShadow ) continue;
  13366. color = light.color;
  13367. intensity = light.intensity;
  13368. distance = light.distance;
  13369. if ( light instanceof THREE.AmbientLight ) {
  13370. if ( ! light.visible ) continue;
  13371. r += color.r;
  13372. g += color.g;
  13373. b += color.b;
  13374. } else if ( light instanceof THREE.DirectionalLight ) {
  13375. dirCount += 1;
  13376. if ( ! light.visible ) continue;
  13377. _direction.setFromMatrixPosition( light.matrixWorld );
  13378. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13379. _direction.sub( _vector3 );
  13380. _direction.normalize();
  13381. dirOffset = dirLength * 3;
  13382. dirPositions[ dirOffset + 0 ] = _direction.x;
  13383. dirPositions[ dirOffset + 1 ] = _direction.y;
  13384. dirPositions[ dirOffset + 2 ] = _direction.z;
  13385. setColorLinear( dirColors, dirOffset, color, intensity );
  13386. dirLength += 1;
  13387. } else if ( light instanceof THREE.PointLight ) {
  13388. pointCount += 1;
  13389. if ( ! light.visible ) continue;
  13390. pointOffset = pointLength * 3;
  13391. setColorLinear( pointColors, pointOffset, color, intensity );
  13392. _vector3.setFromMatrixPosition( light.matrixWorld );
  13393. pointPositions[ pointOffset + 0 ] = _vector3.x;
  13394. pointPositions[ pointOffset + 1 ] = _vector3.y;
  13395. pointPositions[ pointOffset + 2 ] = _vector3.z;
  13396. // distance is 0 if decay is 0, because there is no attenuation at all.
  13397. pointDistances[ pointLength ] = distance;
  13398. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13399. pointLength += 1;
  13400. } else if ( light instanceof THREE.SpotLight ) {
  13401. spotCount += 1;
  13402. if ( ! light.visible ) continue;
  13403. spotOffset = spotLength * 3;
  13404. setColorLinear( spotColors, spotOffset, color, intensity );
  13405. _direction.setFromMatrixPosition( light.matrixWorld );
  13406. spotPositions[ spotOffset + 0 ] = _direction.x;
  13407. spotPositions[ spotOffset + 1 ] = _direction.y;
  13408. spotPositions[ spotOffset + 2 ] = _direction.z;
  13409. spotDistances[ spotLength ] = distance;
  13410. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13411. _direction.sub( _vector3 );
  13412. _direction.normalize();
  13413. spotDirections[ spotOffset + 0 ] = _direction.x;
  13414. spotDirections[ spotOffset + 1 ] = _direction.y;
  13415. spotDirections[ spotOffset + 2 ] = _direction.z;
  13416. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  13417. spotExponents[ spotLength ] = light.exponent;
  13418. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13419. spotLength += 1;
  13420. } else if ( light instanceof THREE.HemisphereLight ) {
  13421. hemiCount += 1;
  13422. if ( ! light.visible ) continue;
  13423. _direction.setFromMatrixPosition( light.matrixWorld );
  13424. _direction.normalize();
  13425. hemiOffset = hemiLength * 3;
  13426. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  13427. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  13428. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  13429. skyColor = light.color;
  13430. groundColor = light.groundColor;
  13431. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  13432. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  13433. hemiLength += 1;
  13434. }
  13435. }
  13436. // null eventual remains from removed lights
  13437. // (this is to avoid if in shader)
  13438. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  13439. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  13440. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  13441. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  13442. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  13443. zlights.directional.length = dirLength;
  13444. zlights.point.length = pointLength;
  13445. zlights.spot.length = spotLength;
  13446. zlights.hemi.length = hemiLength;
  13447. zlights.ambient[ 0 ] = r;
  13448. zlights.ambient[ 1 ] = g;
  13449. zlights.ambient[ 2 ] = b;
  13450. }
  13451. // GL state setting
  13452. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  13453. if ( cullFace === THREE.CullFaceNone ) {
  13454. state.disable( _gl.CULL_FACE );
  13455. } else {
  13456. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  13457. _gl.frontFace( _gl.CW );
  13458. } else {
  13459. _gl.frontFace( _gl.CCW );
  13460. }
  13461. if ( cullFace === THREE.CullFaceBack ) {
  13462. _gl.cullFace( _gl.BACK );
  13463. } else if ( cullFace === THREE.CullFaceFront ) {
  13464. _gl.cullFace( _gl.FRONT );
  13465. } else {
  13466. _gl.cullFace( _gl.FRONT_AND_BACK );
  13467. }
  13468. state.enable( _gl.CULL_FACE );
  13469. }
  13470. };
  13471. // Textures
  13472. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  13473. var extension;
  13474. if ( isImagePowerOfTwo ) {
  13475. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  13476. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  13477. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  13478. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  13479. } else {
  13480. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  13481. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  13482. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  13483. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  13484. }
  13485. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  13486. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  13487. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13488. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  13489. }
  13490. }
  13491. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13492. if ( extension && texture.type !== THREE.FloatType && texture.type !== THREE.HalfFloatType ) {
  13493. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13494. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  13495. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13496. }
  13497. }
  13498. }
  13499. function uploadTexture( textureProperties, texture, slot ) {
  13500. if ( textureProperties.__webglInit === undefined ) {
  13501. textureProperties.__webglInit = true;
  13502. texture.__webglInit = true;
  13503. texture.addEventListener( 'dispose', onTextureDispose );
  13504. textureProperties.__webglTexture = _gl.createTexture();
  13505. _infoMemory.textures ++;
  13506. }
  13507. state.activeTexture( _gl.TEXTURE0 + slot );
  13508. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13509. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13510. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  13511. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  13512. texture.image = clampToMaxSize( texture.image, _maxTextureSize );
  13513. var image = texture.image,
  13514. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13515. glFormat = paramThreeToGL( texture.format ),
  13516. glType = paramThreeToGL( texture.type );
  13517. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  13518. var mipmap, mipmaps = texture.mipmaps;
  13519. if ( texture instanceof THREE.DataTexture ) {
  13520. // use manually created mipmaps if available
  13521. // if there are no manual mipmaps
  13522. // set 0 level mipmap and then use GL to generate other mipmap levels
  13523. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13524. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13525. mipmap = mipmaps[ i ];
  13526. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13527. }
  13528. texture.generateMipmaps = false;
  13529. } else {
  13530. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13531. }
  13532. } else if ( texture instanceof THREE.CompressedTexture ) {
  13533. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13534. mipmap = mipmaps[ i ];
  13535. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13536. if ( getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  13537. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13538. } else {
  13539. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  13540. }
  13541. } else {
  13542. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13543. }
  13544. }
  13545. } else {
  13546. // regular Texture (image, video, canvas)
  13547. // use manually created mipmaps if available
  13548. // if there are no manual mipmaps
  13549. // set 0 level mipmap and then use GL to generate other mipmap levels
  13550. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13551. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13552. mipmap = mipmaps[ i ];
  13553. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  13554. }
  13555. texture.generateMipmaps = false;
  13556. } else {
  13557. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  13558. }
  13559. }
  13560. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13561. textureProperties.__version = texture.version;
  13562. if ( texture.onUpdate ) texture.onUpdate( texture );
  13563. }
  13564. this.setTexture = function ( texture, slot ) {
  13565. var textureProperties = properties.get( texture );
  13566. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13567. var image = texture.image;
  13568. if ( image === undefined ) {
  13569. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  13570. return;
  13571. }
  13572. if ( image.complete === false ) {
  13573. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  13574. return;
  13575. }
  13576. uploadTexture( textureProperties, texture, slot );
  13577. return;
  13578. }
  13579. state.activeTexture( _gl.TEXTURE0 + slot );
  13580. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13581. };
  13582. function clampToMaxSize ( image, maxSize ) {
  13583. if ( image.width > maxSize || image.height > maxSize ) {
  13584. // Warning: Scaling through the canvas will only work with images that use
  13585. // premultiplied alpha.
  13586. var scale = maxSize / Math.max( image.width, image.height );
  13587. var canvas = document.createElement( 'canvas' );
  13588. canvas.width = Math.floor( image.width * scale );
  13589. canvas.height = Math.floor( image.height * scale );
  13590. var context = canvas.getContext( '2d' );
  13591. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  13592. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  13593. return canvas;
  13594. }
  13595. return image;
  13596. }
  13597. function setCubeTexture ( texture, slot ) {
  13598. var textureProperties = properties.get( texture );
  13599. if ( texture.image.length === 6 ) {
  13600. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13601. if ( ! textureProperties.__image__webglTextureCube ) {
  13602. texture.addEventListener( 'dispose', onTextureDispose );
  13603. textureProperties.__image__webglTextureCube = _gl.createTexture();
  13604. _infoMemory.textures ++;
  13605. }
  13606. state.activeTexture( _gl.TEXTURE0 + slot );
  13607. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13608. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13609. var isCompressed = texture instanceof THREE.CompressedTexture;
  13610. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  13611. var cubeImage = [];
  13612. for ( var i = 0; i < 6; i ++ ) {
  13613. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  13614. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
  13615. } else {
  13616. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13617. }
  13618. }
  13619. var image = cubeImage[ 0 ],
  13620. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13621. glFormat = paramThreeToGL( texture.format ),
  13622. glType = paramThreeToGL( texture.type );
  13623. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  13624. for ( var i = 0; i < 6; i ++ ) {
  13625. if ( ! isCompressed ) {
  13626. if ( isDataTexture ) {
  13627. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13628. } else {
  13629. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  13630. }
  13631. } else {
  13632. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  13633. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  13634. mipmap = mipmaps[ j ];
  13635. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13636. if ( getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  13637. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13638. } else {
  13639. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  13640. }
  13641. } else {
  13642. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13643. }
  13644. }
  13645. }
  13646. }
  13647. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  13648. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13649. }
  13650. textureProperties.__version = texture.version;
  13651. if ( texture.onUpdate ) texture.onUpdate( texture );
  13652. } else {
  13653. state.activeTexture( _gl.TEXTURE0 + slot );
  13654. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13655. }
  13656. }
  13657. }
  13658. function setCubeTextureDynamic ( texture, slot ) {
  13659. state.activeTexture( _gl.TEXTURE0 + slot );
  13660. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  13661. }
  13662. // Render targets
  13663. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  13664. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13665. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget ).__webglTexture, 0 );
  13666. }
  13667. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  13668. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  13669. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13670. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  13671. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13672. /* For some reason this is not working. Defaulting to RGBA4.
  13673. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13674. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  13675. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13676. */
  13677. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13678. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  13679. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13680. } else {
  13681. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  13682. }
  13683. }
  13684. this.setRenderTarget = function ( renderTarget ) {
  13685. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  13686. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13687. var renderTargetProperties = properties.get( renderTarget );
  13688. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  13689. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  13690. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13691. renderTargetProperties.__webglTexture = _gl.createTexture();
  13692. _infoMemory.textures ++;
  13693. // Setup texture, create render and frame buffers
  13694. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  13695. glFormat = paramThreeToGL( renderTarget.format ),
  13696. glType = paramThreeToGL( renderTarget.type );
  13697. if ( isCube ) {
  13698. renderTargetProperties.__webglFramebuffer = [];
  13699. renderTargetProperties.__webglRenderbuffer = [];
  13700. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTargetProperties.__webglTexture );
  13701. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  13702. for ( var i = 0; i < 6; i ++ ) {
  13703. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13704. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  13705. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13706. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  13707. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  13708. }
  13709. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13710. } else {
  13711. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13712. if ( renderTarget.shareDepthFrom ) {
  13713. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  13714. } else {
  13715. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  13716. }
  13717. state.bindTexture( _gl.TEXTURE_2D, renderTargetProperties.__webglTexture );
  13718. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  13719. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13720. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  13721. if ( renderTarget.shareDepthFrom ) {
  13722. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13723. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13724. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13725. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13726. }
  13727. } else {
  13728. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  13729. }
  13730. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13731. }
  13732. // Release everything
  13733. if ( isCube ) {
  13734. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13735. } else {
  13736. state.bindTexture( _gl.TEXTURE_2D, null );
  13737. }
  13738. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  13739. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  13740. }
  13741. var framebuffer, width, height, vx, vy;
  13742. if ( renderTarget ) {
  13743. var renderTargetProperties = properties.get( renderTarget );
  13744. if ( isCube ) {
  13745. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  13746. } else {
  13747. framebuffer = renderTargetProperties.__webglFramebuffer;
  13748. }
  13749. width = renderTarget.width;
  13750. height = renderTarget.height;
  13751. vx = 0;
  13752. vy = 0;
  13753. } else {
  13754. framebuffer = null;
  13755. width = _viewportWidth;
  13756. height = _viewportHeight;
  13757. vx = _viewportX;
  13758. vy = _viewportY;
  13759. }
  13760. if ( framebuffer !== _currentFramebuffer ) {
  13761. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13762. _gl.viewport( vx, vy, width, height );
  13763. _currentFramebuffer = framebuffer;
  13764. }
  13765. _currentWidth = width;
  13766. _currentHeight = height;
  13767. };
  13768. this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {
  13769. if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
  13770. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13771. return;
  13772. }
  13773. if ( properties.get( renderTarget ).__webglFramebuffer ) {
  13774. if ( renderTarget.format !== THREE.RGBAFormat ) {
  13775. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA format. readPixels can read only RGBA format.' );
  13776. return;
  13777. }
  13778. var restore = false;
  13779. if ( properties.get( renderTarget ).__webglFramebuffer !== _currentFramebuffer ) {
  13780. _gl.bindFramebuffer( _gl.FRAMEBUFFER, properties.get( renderTarget ).__webglFramebuffer );
  13781. restore = true;
  13782. }
  13783. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13784. _gl.readPixels( x, y, width, height, _gl.RGBA, _gl.UNSIGNED_BYTE, buffer );
  13785. } else {
  13786. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13787. }
  13788. if ( restore ) {
  13789. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13790. }
  13791. }
  13792. };
  13793. function updateRenderTargetMipmap ( renderTarget ) {
  13794. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13795. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( renderTarget ).__webglTexture );
  13796. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13797. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13798. } else {
  13799. state.bindTexture( _gl.TEXTURE_2D, properties.get( renderTarget ).__webglTexture );
  13800. _gl.generateMipmap( _gl.TEXTURE_2D );
  13801. state.bindTexture( _gl.TEXTURE_2D, null );
  13802. }
  13803. }
  13804. // Fallback filters for non-power-of-2 textures
  13805. function filterFallback ( f ) {
  13806. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  13807. return _gl.NEAREST;
  13808. }
  13809. return _gl.LINEAR;
  13810. }
  13811. // Map three.js constants to WebGL constants
  13812. function paramThreeToGL ( p ) {
  13813. var extension;
  13814. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  13815. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  13816. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  13817. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  13818. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  13819. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  13820. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  13821. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  13822. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  13823. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  13824. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13825. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13826. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  13827. if ( p === THREE.ByteType ) return _gl.BYTE;
  13828. if ( p === THREE.ShortType ) return _gl.SHORT;
  13829. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  13830. if ( p === THREE.IntType ) return _gl.INT;
  13831. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  13832. if ( p === THREE.FloatType ) return _gl.FLOAT;
  13833. extension = extensions.get( 'OES_texture_half_float' );
  13834. if ( extension !== null ) {
  13835. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  13836. }
  13837. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  13838. if ( p === THREE.RGBFormat ) return _gl.RGB;
  13839. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  13840. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  13841. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  13842. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  13843. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  13844. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  13845. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  13846. if ( p === THREE.OneFactor ) return _gl.ONE;
  13847. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  13848. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  13849. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  13850. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  13851. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  13852. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  13853. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  13854. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  13855. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  13856. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13857. if ( extension !== null ) {
  13858. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13859. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13860. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13861. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13862. }
  13863. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13864. if ( extension !== null ) {
  13865. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13866. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13867. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13868. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13869. }
  13870. extension = extensions.get( 'EXT_blend_minmax' );
  13871. if ( extension !== null ) {
  13872. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  13873. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  13874. }
  13875. return 0;
  13876. }
  13877. // Allocations
  13878. function allocateBones ( object ) {
  13879. if ( _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  13880. return 1024;
  13881. } else {
  13882. // default for when object is not specified
  13883. // ( for example when prebuilding shader to be used with multiple objects )
  13884. //
  13885. // - leave some extra space for other uniforms
  13886. // - limit here is ANGLE's 254 max uniform vectors
  13887. // (up to 54 should be safe)
  13888. var nVertexUniforms = _gl.getParameter( _gl.MAX_VERTEX_UNIFORM_VECTORS );
  13889. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  13890. var maxBones = nVertexMatrices;
  13891. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  13892. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  13893. if ( maxBones < object.skeleton.bones.length ) {
  13894. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  13895. }
  13896. }
  13897. return maxBones;
  13898. }
  13899. }
  13900. function allocateLights( lights ) {
  13901. var dirLights = 0;
  13902. var pointLights = 0;
  13903. var spotLights = 0;
  13904. var hemiLights = 0;
  13905. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13906. var light = lights[ l ];
  13907. if ( light.onlyShadow || light.visible === false ) continue;
  13908. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  13909. if ( light instanceof THREE.PointLight ) pointLights ++;
  13910. if ( light instanceof THREE.SpotLight ) spotLights ++;
  13911. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  13912. }
  13913. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  13914. }
  13915. function allocateShadows( lights ) {
  13916. var maxShadows = 0;
  13917. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13918. var light = lights[ l ];
  13919. if ( ! light.castShadow ) continue;
  13920. if ( light instanceof THREE.SpotLight ) maxShadows ++;
  13921. if ( light instanceof THREE.DirectionalLight ) maxShadows ++;
  13922. }
  13923. return maxShadows;
  13924. }
  13925. // DEPRECATED
  13926. this.initMaterial = function () {
  13927. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  13928. };
  13929. this.addPrePlugin = function () {
  13930. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  13931. };
  13932. this.addPostPlugin = function () {
  13933. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  13934. };
  13935. this.updateShadowMap = function () {
  13936. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  13937. };
  13938. Object.defineProperties( this, {
  13939. shadowMapEnabled: {
  13940. get: function () {
  13941. return shadowMap.enabled;
  13942. },
  13943. set: function ( value ) {
  13944. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  13945. shadowMap.enabled = value;
  13946. }
  13947. },
  13948. shadowMapType: {
  13949. get: function () {
  13950. return shadowMap.type;
  13951. },
  13952. set: function ( value ) {
  13953. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  13954. shadowMap.type = value;
  13955. }
  13956. },
  13957. shadowMapCullFace: {
  13958. get: function () {
  13959. return shadowMap.cullFace;
  13960. },
  13961. set: function ( value ) {
  13962. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  13963. shadowMap.cullFace = value;
  13964. }
  13965. },
  13966. shadowMapDebug: {
  13967. get: function () {
  13968. return shadowMap.debug;
  13969. },
  13970. set: function ( value ) {
  13971. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  13972. shadowMap.debug = value;
  13973. }
  13974. }
  13975. } );
  13976. };
  13977. // File:src/renderers/WebGLRenderTarget.js
  13978. /**
  13979. * @author szimek / https://github.com/szimek/
  13980. * @author alteredq / http://alteredqualia.com/
  13981. */
  13982. THREE.WebGLRenderTarget = function ( width, height, options ) {
  13983. this.uuid = THREE.Math.generateUUID();
  13984. this.width = width;
  13985. this.height = height;
  13986. options = options || {};
  13987. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  13988. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  13989. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  13990. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  13991. this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
  13992. this.offset = new THREE.Vector2( 0, 0 );
  13993. this.repeat = new THREE.Vector2( 1, 1 );
  13994. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  13995. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  13996. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  13997. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  13998. this.generateMipmaps = true;
  13999. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  14000. };
  14001. THREE.WebGLRenderTarget.prototype = {
  14002. constructor: THREE.WebGLRenderTarget,
  14003. setSize: function ( width, height ) {
  14004. if ( this.width !== width || this.height !== height ) {
  14005. this.width = width;
  14006. this.height = height;
  14007. this.dispose();
  14008. }
  14009. },
  14010. copy: function ( source ) {
  14011. this.width = source.width;
  14012. this.height = source.height;
  14013. this.wrapS = source.wrapS;
  14014. this.wrapT = source.wrapT;
  14015. this.magFilter = source.magFilter;
  14016. this.minFilter = source.minFilter;
  14017. this.anisotropy = source.anisotropy;
  14018. this.offset.copy( source.offset );
  14019. this.repeat.copy( source.repeat );
  14020. this.format = source.format;
  14021. this.type = source.type;
  14022. this.depthBuffer = source.depthBuffer;
  14023. this.stencilBuffer = source.stencilBuffer;
  14024. this.generateMipmaps = source.generateMipmaps;
  14025. this.shareDepthFrom = source.shareDepthFrom;
  14026. return this;
  14027. },
  14028. clone: function () {
  14029. return new THREE.WebGLRenderTarget().copy( this );
  14030. },
  14031. dispose: function () {
  14032. this.dispatchEvent( { type: 'dispose' } );
  14033. }
  14034. };
  14035. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  14036. // File:src/renderers/WebGLRenderTargetCube.js
  14037. /**
  14038. * @author alteredq / http://alteredqualia.com
  14039. */
  14040. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  14041. THREE.WebGLRenderTarget.call( this, width, height, options );
  14042. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  14043. };
  14044. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  14045. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  14046. // File:src/renderers/webgl/WebGLExtensions.js
  14047. /**
  14048. * @author mrdoob / http://mrdoob.com/
  14049. */
  14050. THREE.WebGLExtensions = function ( gl ) {
  14051. var extensions = {};
  14052. this.get = function ( name ) {
  14053. if ( extensions[ name ] !== undefined ) {
  14054. return extensions[ name ];
  14055. }
  14056. var extension;
  14057. switch ( name ) {
  14058. case 'EXT_texture_filter_anisotropic':
  14059. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  14060. break;
  14061. case 'WEBGL_compressed_texture_s3tc':
  14062. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  14063. break;
  14064. case 'WEBGL_compressed_texture_pvrtc':
  14065. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  14066. break;
  14067. default:
  14068. extension = gl.getExtension( name );
  14069. }
  14070. if ( extension === null ) {
  14071. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  14072. }
  14073. extensions[ name ] = extension;
  14074. return extension;
  14075. };
  14076. };
  14077. // File:src/renderers/webgl/WebGLGeometries.js
  14078. /**
  14079. * @author mrdoob / http://mrdoob.com/
  14080. */
  14081. THREE.WebGLGeometries = function ( gl, properties, info ) {
  14082. var geometries = {};
  14083. this.get = function ( object ) {
  14084. var geometry = object.geometry;
  14085. if ( geometries[ geometry.id ] !== undefined ) {
  14086. return geometries[ geometry.id ];
  14087. }
  14088. geometry.addEventListener( 'dispose', onGeometryDispose );
  14089. if ( geometry instanceof THREE.BufferGeometry ) {
  14090. geometries[ geometry.id ] = geometry;
  14091. } else if ( geometry instanceof THREE.Geometry ) {
  14092. if ( geometry._bufferGeometry === undefined ) {
  14093. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  14094. }
  14095. geometries[ geometry.id ] = geometry._bufferGeometry;
  14096. }
  14097. info.memory.geometries ++;
  14098. return geometries[ geometry.id ];
  14099. };
  14100. function onGeometryDispose( event ) {
  14101. var geometry = event.target;
  14102. var buffergeometry = geometries[ geometry.id ];
  14103. for ( var name in buffergeometry.attributes ) {
  14104. var attribute = buffergeometry.attributes[ name ];
  14105. var buffer = getAttributeBuffer( attribute );
  14106. if ( buffer !== undefined ) {
  14107. gl.deleteBuffer( buffer );
  14108. removeAttributeBuffer( attribute );
  14109. }
  14110. }
  14111. geometry.removeEventListener( 'dispose', onGeometryDispose );
  14112. delete geometries[ geometry.id ];
  14113. info.memory.geometries --;
  14114. }
  14115. function getAttributeBuffer( attribute ) {
  14116. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14117. return properties.get( attribute.data ).__webglBuffer;
  14118. }
  14119. return properties.get( attribute ).__webglBuffer;
  14120. }
  14121. function removeAttributeBuffer( attribute ) {
  14122. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14123. properties.delete( attribute.data );
  14124. } else {
  14125. properties.delete( attribute );
  14126. }
  14127. }
  14128. };
  14129. // File:src/renderers/webgl/WebGLObjects.js
  14130. /**
  14131. * @author mrdoob / http://mrdoob.com/
  14132. */
  14133. THREE.WebGLObjects = function ( gl, properties, info ) {
  14134. var objects = {};
  14135. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  14136. //
  14137. function onObjectRemoved( event ) {
  14138. var object = event.target;
  14139. object.traverse( function ( child ) {
  14140. child.removeEventListener( 'remove', onObjectRemoved );
  14141. removeObject( child );
  14142. } );
  14143. }
  14144. function removeObject( object ) {
  14145. if ( object instanceof THREE.Mesh ||
  14146. object instanceof THREE.PointCloud ||
  14147. object instanceof THREE.Line ) {
  14148. delete objects[ object.id ];
  14149. }
  14150. delete object._modelViewMatrix;
  14151. delete object._normalMatrix;
  14152. properties.delete( object );
  14153. }
  14154. //
  14155. this.objects = objects;
  14156. this.geometries = geometries;
  14157. this.init = function ( object ) {
  14158. var objectProperties = properties.get( object );
  14159. if ( objectProperties.__webglInit === undefined ) {
  14160. objectProperties.__webglInit = true;
  14161. object._modelViewMatrix = new THREE.Matrix4();
  14162. object._normalMatrix = new THREE.Matrix3();
  14163. object.addEventListener( 'removed', onObjectRemoved );
  14164. }
  14165. if ( objectProperties.__webglActive === undefined ) {
  14166. objectProperties.__webglActive = true;
  14167. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
  14168. objects[ object.id ] = {
  14169. id: object.id,
  14170. object: object,
  14171. z: 0
  14172. };
  14173. }
  14174. }
  14175. };
  14176. function updateObject( object ) {
  14177. var geometry = geometries.get( object );
  14178. if ( object.geometry instanceof THREE.Geometry ) {
  14179. geometry.updateFromObject( object );
  14180. }
  14181. var attributes = geometry.attributes;
  14182. for ( var name in attributes ) {
  14183. updateAttribute( attributes[ name ], name );
  14184. }
  14185. // morph targets
  14186. var morphAttributes = geometry.morphAttributes;
  14187. for ( var name in morphAttributes ) {
  14188. var array = morphAttributes[ name ];
  14189. for ( var i = 0, l = array.length; i < l; i ++ ) {
  14190. updateAttribute( array[ i ], i );
  14191. }
  14192. }
  14193. }
  14194. function updateAttribute( attribute, name ) {
  14195. var bufferType = ( name === 'index' ) ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
  14196. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  14197. var attributeProperties = properties.get( data );
  14198. if ( attributeProperties.__webglBuffer === undefined ) {
  14199. createBuffer( attributeProperties, data, bufferType );
  14200. } else if ( attributeProperties.version !== data.version ) {
  14201. updateBuffer( attributeProperties, data, bufferType );
  14202. }
  14203. }
  14204. function createBuffer( attributeProperties, data, bufferType ) {
  14205. attributeProperties.__webglBuffer = gl.createBuffer();
  14206. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14207. var usage = gl.STATIC_DRAW;
  14208. if ( data instanceof THREE.DynamicBufferAttribute
  14209. || ( data instanceof THREE.InstancedBufferAttribute && data.dynamic === true )
  14210. || ( data instanceof THREE.InterleavedBuffer && data.dynamic === true ) ) {
  14211. usage = gl.DYNAMIC_DRAW;
  14212. }
  14213. gl.bufferData( bufferType, data.array, usage );
  14214. attributeProperties.version = data.version;
  14215. }
  14216. function updateBuffer( attributeProperties, data, bufferType ) {
  14217. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14218. if ( data.updateRange === undefined || data.updateRange.count === - 1 ) {
  14219. // Not using update ranges
  14220. gl.bufferSubData( bufferType, 0, data.array );
  14221. } else if ( data.updateRange.count === 0 ) {
  14222. console.error( 'THREE.WebGLObjects.updateBuffer: using updateRange for THREE.DynamicBufferAttribute and marked as needsUpdate but count is 0, ensure you are using set methods or updating manually.' );
  14223. } else {
  14224. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  14225. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  14226. data.updateRange.count = 0; // reset range
  14227. }
  14228. attributeProperties.version = data.version;
  14229. }
  14230. // returns the webgl buffer for a specified attribute
  14231. this.getAttributeBuffer = function ( attribute ) {
  14232. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14233. return properties.get( attribute.data ).__webglBuffer;
  14234. }
  14235. return properties.get( attribute ).__webglBuffer;
  14236. };
  14237. this.update = function ( renderList ) {
  14238. for ( var i = 0, ul = renderList.length; i < ul; i ++ ) {
  14239. updateObject( renderList[ i ].object );
  14240. }
  14241. };
  14242. this.clear = function () {
  14243. objects = {};
  14244. };
  14245. };
  14246. // File:src/renderers/webgl/WebGLProgram.js
  14247. THREE.WebGLProgram = ( function () {
  14248. var programIdCount = 0;
  14249. function generateDefines( defines ) {
  14250. var chunks = [];
  14251. for ( var name in defines ) {
  14252. var value = defines[ name ];
  14253. if ( value === false ) continue;
  14254. chunks.push( '#define ' + name + ' ' + value );
  14255. }
  14256. return chunks.join( '\n' );
  14257. }
  14258. function fetchUniformLocations( gl, program, identifiers ) {
  14259. var uniforms = {};
  14260. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  14261. for ( var i = 0; i < n; i ++ ) {
  14262. var info = gl.getActiveUniform( program, i );
  14263. var name = info.name;
  14264. var location = gl.getUniformLocation( program, name );
  14265. // console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  14266. var suffixPos = name.lastIndexOf( '[0]' );
  14267. if ( suffixPos !== - 1 && suffixPos === name.length - 3 ) {
  14268. uniforms[ name.substr( 0, suffixPos ) ] = location;
  14269. }
  14270. uniforms[ name ] = location;
  14271. }
  14272. return uniforms;
  14273. }
  14274. function fetchAttributeLocations( gl, program, identifiers ) {
  14275. var attributes = {};
  14276. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  14277. for ( var i = 0; i < n; i ++ ) {
  14278. var info = gl.getActiveAttrib( program, i );
  14279. var name = info.name;
  14280. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  14281. attributes[ name ] = gl.getAttribLocation( program, name );
  14282. }
  14283. return attributes;
  14284. }
  14285. function filterEmptyLine( string ) {
  14286. return string !== '';
  14287. }
  14288. return function WebGLProgram( renderer, code, material, parameters ) {
  14289. var gl = renderer.context;
  14290. var defines = material.defines;
  14291. var vertexShader = material.__webglShader.vertexShader;
  14292. var fragmentShader = material.__webglShader.fragmentShader;
  14293. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  14294. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  14295. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  14296. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  14297. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  14298. }
  14299. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14300. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  14301. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14302. if ( parameters.envMap ) {
  14303. switch ( material.envMap.mapping ) {
  14304. case THREE.CubeReflectionMapping:
  14305. case THREE.CubeRefractionMapping:
  14306. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14307. break;
  14308. case THREE.EquirectangularReflectionMapping:
  14309. case THREE.EquirectangularRefractionMapping:
  14310. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  14311. break;
  14312. case THREE.SphericalReflectionMapping:
  14313. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  14314. break;
  14315. }
  14316. switch ( material.envMap.mapping ) {
  14317. case THREE.CubeRefractionMapping:
  14318. case THREE.EquirectangularRefractionMapping:
  14319. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  14320. break;
  14321. }
  14322. switch ( material.combine ) {
  14323. case THREE.MultiplyOperation:
  14324. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14325. break;
  14326. case THREE.MixOperation:
  14327. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  14328. break;
  14329. case THREE.AddOperation:
  14330. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  14331. break;
  14332. }
  14333. }
  14334. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  14335. // console.log( 'building new program ' );
  14336. //
  14337. var customDefines = generateDefines( defines );
  14338. //
  14339. var program = gl.createProgram();
  14340. var prefixVertex, prefixFragment;
  14341. if ( material instanceof THREE.RawShaderMaterial ) {
  14342. prefixVertex = '';
  14343. prefixFragment = '';
  14344. } else {
  14345. prefixVertex = [
  14346. 'precision ' + parameters.precision + ' float;',
  14347. 'precision ' + parameters.precision + ' int;',
  14348. '#define SHADER_NAME ' + material.__webglShader.name,
  14349. customDefines,
  14350. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  14351. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14352. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14353. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14354. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14355. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14356. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14357. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14358. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14359. '#define MAX_BONES ' + parameters.maxBones,
  14360. parameters.map ? '#define USE_MAP' : '',
  14361. parameters.envMap ? '#define USE_ENVMAP' : '',
  14362. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14363. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14364. parameters.aoMap ? '#define USE_AOMAP' : '',
  14365. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14366. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14367. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14368. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14369. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14370. parameters.vertexColors ? '#define USE_COLOR' : '',
  14371. parameters.flatShading ? '#define FLAT_SHADED' : '',
  14372. parameters.skinning ? '#define USE_SKINNING' : '',
  14373. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  14374. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  14375. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  14376. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14377. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14378. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14379. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14380. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14381. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  14382. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14383. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14384. 'uniform mat4 modelMatrix;',
  14385. 'uniform mat4 modelViewMatrix;',
  14386. 'uniform mat4 projectionMatrix;',
  14387. 'uniform mat4 viewMatrix;',
  14388. 'uniform mat3 normalMatrix;',
  14389. 'uniform vec3 cameraPosition;',
  14390. 'attribute vec3 position;',
  14391. 'attribute vec3 normal;',
  14392. 'attribute vec2 uv;',
  14393. '#ifdef USE_COLOR',
  14394. ' attribute vec3 color;',
  14395. '#endif',
  14396. '#ifdef USE_MORPHTARGETS',
  14397. ' attribute vec3 morphTarget0;',
  14398. ' attribute vec3 morphTarget1;',
  14399. ' attribute vec3 morphTarget2;',
  14400. ' attribute vec3 morphTarget3;',
  14401. ' #ifdef USE_MORPHNORMALS',
  14402. ' attribute vec3 morphNormal0;',
  14403. ' attribute vec3 morphNormal1;',
  14404. ' attribute vec3 morphNormal2;',
  14405. ' attribute vec3 morphNormal3;',
  14406. ' #else',
  14407. ' attribute vec3 morphTarget4;',
  14408. ' attribute vec3 morphTarget5;',
  14409. ' attribute vec3 morphTarget6;',
  14410. ' attribute vec3 morphTarget7;',
  14411. ' #endif',
  14412. '#endif',
  14413. '#ifdef USE_SKINNING',
  14414. ' attribute vec4 skinIndex;',
  14415. ' attribute vec4 skinWeight;',
  14416. '#endif',
  14417. '\n'
  14418. ].filter( filterEmptyLine ).join( '\n' );
  14419. prefixFragment = [
  14420. ( parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  14421. 'precision ' + parameters.precision + ' float;',
  14422. 'precision ' + parameters.precision + ' int;',
  14423. '#define SHADER_NAME ' + material.__webglShader.name,
  14424. customDefines,
  14425. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14426. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14427. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14428. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14429. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14430. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  14431. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14432. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14433. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14434. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  14435. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  14436. parameters.map ? '#define USE_MAP' : '',
  14437. parameters.envMap ? '#define USE_ENVMAP' : '',
  14438. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  14439. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14440. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  14441. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14442. parameters.aoMap ? '#define USE_AOMAP' : '',
  14443. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14444. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14445. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14446. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14447. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14448. parameters.vertexColors ? '#define USE_COLOR' : '',
  14449. parameters.flatShading ? '#define FLAT_SHADED' : '',
  14450. parameters.metal ? '#define METAL' : '',
  14451. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14452. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14453. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14454. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14455. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14456. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14457. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14458. 'uniform mat4 viewMatrix;',
  14459. 'uniform vec3 cameraPosition;',
  14460. '\n'
  14461. ].filter( filterEmptyLine ).join( '\n' );
  14462. }
  14463. var vertexGlsl = prefixVertex + vertexShader;
  14464. var fragmentGlsl = prefixFragment + fragmentShader;
  14465. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  14466. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  14467. gl.attachShader( program, glVertexShader );
  14468. gl.attachShader( program, glFragmentShader );
  14469. // Force a particular attribute to index 0.
  14470. if ( material.index0AttributeName !== undefined ) {
  14471. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  14472. } else if ( parameters.morphTargets === true ) {
  14473. // programs with morphTargets displace position out of attribute 0
  14474. gl.bindAttribLocation( program, 0, 'position' );
  14475. }
  14476. gl.linkProgram( program );
  14477. var programLog = gl.getProgramInfoLog( program );
  14478. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  14479. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  14480. var runnable = true;
  14481. var haveDiagnostics = true;
  14482. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  14483. runnable = false;
  14484. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  14485. } else if ( programLog !== '' ) {
  14486. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  14487. } else if ( vertexLog === '' || fragmentLog === '' ) {
  14488. haveDiagnostics = false;
  14489. }
  14490. if ( haveDiagnostics ) {
  14491. this.diagnostics = {
  14492. runnable: runnable,
  14493. material: material,
  14494. programLog: programLog,
  14495. vertexShader: {
  14496. log: vertexLog,
  14497. prefix: prefixVertex
  14498. },
  14499. fragmentShader: {
  14500. log: fragmentLog,
  14501. prefix: prefixFragment
  14502. }
  14503. };
  14504. }
  14505. // clean up
  14506. gl.deleteShader( glVertexShader );
  14507. gl.deleteShader( glFragmentShader );
  14508. // set up caching for uniform locations
  14509. var cachedUniforms;
  14510. this.getUniforms = function() {
  14511. if ( cachedUniforms === undefined ) {
  14512. cachedUniforms = fetchUniformLocations( gl, program );
  14513. }
  14514. return cachedUniforms;
  14515. };
  14516. // set up caching for attribute locations
  14517. var cachedAttributes;
  14518. this.getAttributes = function() {
  14519. if ( cachedAttributes === undefined ) {
  14520. cachedAttributes = fetchAttributeLocations( gl, program );
  14521. }
  14522. return cachedAttributes;
  14523. };
  14524. // DEPRECATED
  14525. Object.defineProperties( this, {
  14526. uniforms: {
  14527. get: function() {
  14528. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  14529. return this.getUniforms();
  14530. }
  14531. },
  14532. attributes: {
  14533. get: function() {
  14534. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  14535. return this.getAttributes();
  14536. }
  14537. }
  14538. } );
  14539. //
  14540. this.id = programIdCount ++;
  14541. this.code = code;
  14542. this.usedTimes = 1;
  14543. this.program = program;
  14544. this.vertexShader = glVertexShader;
  14545. this.fragmentShader = glFragmentShader;
  14546. return this;
  14547. };
  14548. } )();
  14549. // File:src/renderers/webgl/WebGLProperties.js
  14550. /**
  14551. * @author fordacious / fordacious.github.io
  14552. */
  14553. THREE.WebGLProperties = function () {
  14554. var properties = {};
  14555. this.get = function ( object ) {
  14556. var uuid = object.uuid;
  14557. var map = properties[ uuid ];
  14558. if ( map === undefined ) {
  14559. map = {};
  14560. properties[ uuid ] = map;
  14561. }
  14562. return map;
  14563. };
  14564. this.delete = function ( object ) {
  14565. delete properties[ object.uuid ];
  14566. };
  14567. this.clear = function () {
  14568. properties = {};
  14569. };
  14570. };
  14571. // File:src/renderers/webgl/WebGLShader.js
  14572. THREE.WebGLShader = ( function () {
  14573. var addLineNumbers = function ( string ) {
  14574. var lines = string.split( '\n' );
  14575. for ( var i = 0; i < lines.length; i ++ ) {
  14576. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  14577. }
  14578. return lines.join( '\n' );
  14579. };
  14580. return function WebGLShader( gl, type, string ) {
  14581. var shader = gl.createShader( type );
  14582. gl.shaderSource( shader, string );
  14583. gl.compileShader( shader );
  14584. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  14585. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  14586. }
  14587. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  14588. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  14589. }
  14590. // --enable-privileged-webgl-extension
  14591. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  14592. return shader;
  14593. };
  14594. } )();
  14595. // File:src/renderers/webgl/WebGLShadowMap.js
  14596. /**
  14597. * @author alteredq / http://alteredqualia.com/
  14598. * @author mrdoob / http://mrdoob.com/
  14599. */
  14600. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  14601. var _gl = _renderer.context,
  14602. _state = _renderer.state,
  14603. _frustum = new THREE.Frustum(),
  14604. _projScreenMatrix = new THREE.Matrix4(),
  14605. _min = new THREE.Vector3(),
  14606. _max = new THREE.Vector3(),
  14607. _matrixPosition = new THREE.Vector3(),
  14608. _renderList = [];
  14609. // init
  14610. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  14611. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  14612. var _depthMaterial = new THREE.ShaderMaterial( {
  14613. uniforms: depthUniforms,
  14614. vertexShader: depthShader.vertexShader,
  14615. fragmentShader: depthShader.fragmentShader
  14616. } );
  14617. var _depthMaterialMorph = new THREE.ShaderMaterial( {
  14618. uniforms: depthUniforms,
  14619. vertexShader: depthShader.vertexShader,
  14620. fragmentShader: depthShader.fragmentShader,
  14621. morphTargets: true
  14622. } );
  14623. var _depthMaterialSkin = new THREE.ShaderMaterial( {
  14624. uniforms: depthUniforms,
  14625. vertexShader: depthShader.vertexShader,
  14626. fragmentShader: depthShader.fragmentShader,
  14627. skinning: true
  14628. } );
  14629. var _depthMaterialMorphSkin = new THREE.ShaderMaterial( {
  14630. uniforms: depthUniforms,
  14631. vertexShader: depthShader.vertexShader,
  14632. fragmentShader: depthShader.fragmentShader,
  14633. morphTargets: true,
  14634. skinning: true
  14635. } );
  14636. _depthMaterial._shadowPass = true;
  14637. _depthMaterialMorph._shadowPass = true;
  14638. _depthMaterialSkin._shadowPass = true;
  14639. _depthMaterialMorphSkin._shadowPass = true;
  14640. //
  14641. var scope = this;
  14642. this.enabled = false;
  14643. this.autoUpdate = true;
  14644. this.needsUpdate = false;
  14645. this.type = THREE.PCFShadowMap;
  14646. this.cullFace = THREE.CullFaceFront;
  14647. this.render = function ( scene, camera ) {
  14648. if ( scope.enabled === false ) return;
  14649. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  14650. // set GL state for depth map
  14651. _gl.clearColor( 1, 1, 1, 1 );
  14652. _state.disable( _gl.BLEND );
  14653. _state.enable( _gl.CULL_FACE );
  14654. _gl.frontFace( _gl.CCW );
  14655. if ( scope.cullFace === THREE.CullFaceFront ) {
  14656. _gl.cullFace( _gl.FRONT );
  14657. } else {
  14658. _gl.cullFace( _gl.BACK );
  14659. }
  14660. _state.setDepthTest( true );
  14661. // render depth map
  14662. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  14663. var light = _lights[ i ];
  14664. if ( ! light.castShadow ) continue;
  14665. if ( ! light.shadowMap ) {
  14666. var shadowFilter = THREE.LinearFilter;
  14667. if ( scope.type === THREE.PCFSoftShadowMap ) {
  14668. shadowFilter = THREE.NearestFilter;
  14669. }
  14670. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  14671. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  14672. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  14673. light.shadowMatrix = new THREE.Matrix4();
  14674. }
  14675. if ( ! light.shadowCamera ) {
  14676. if ( light instanceof THREE.SpotLight ) {
  14677. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  14678. } else if ( light instanceof THREE.DirectionalLight ) {
  14679. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  14680. } else {
  14681. console.error( "THREE.ShadowMapPlugin: Unsupported light type for shadow", light );
  14682. continue;
  14683. }
  14684. scene.add( light.shadowCamera );
  14685. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14686. }
  14687. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  14688. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  14689. scene.add( light.cameraHelper );
  14690. }
  14691. var shadowMap = light.shadowMap;
  14692. var shadowMatrix = light.shadowMatrix;
  14693. var shadowCamera = light.shadowCamera;
  14694. //
  14695. shadowCamera.position.setFromMatrixPosition( light.matrixWorld );
  14696. _matrixPosition.setFromMatrixPosition( light.target.matrixWorld );
  14697. shadowCamera.lookAt( _matrixPosition );
  14698. shadowCamera.updateMatrixWorld();
  14699. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  14700. //
  14701. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  14702. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  14703. // compute shadow matrix
  14704. shadowMatrix.set(
  14705. 0.5, 0.0, 0.0, 0.5,
  14706. 0.0, 0.5, 0.0, 0.5,
  14707. 0.0, 0.0, 0.5, 0.5,
  14708. 0.0, 0.0, 0.0, 1.0
  14709. );
  14710. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  14711. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  14712. // update camera matrices and frustum
  14713. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  14714. _frustum.setFromMatrix( _projScreenMatrix );
  14715. // render shadow map
  14716. _renderer.setRenderTarget( shadowMap );
  14717. _renderer.clear();
  14718. // set object matrices & frustum culling
  14719. _renderList.length = 0;
  14720. projectObject( scene, shadowCamera );
  14721. // render regular objects
  14722. var webglObject, object, material;
  14723. var objectMaterial, useMorphing, useSkinning;
  14724. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  14725. webglObject = _renderList[ j ];
  14726. object = webglObject.object;
  14727. objectMaterial = object.material;
  14728. if ( objectMaterial instanceof THREE.MeshFaceMaterial ) {
  14729. // For the moment just ignore objects that have multiple materials with different animation methods
  14730. // Only the first material will be taken into account for deciding which depth material to use for shadow maps
  14731. objectMaterial = object.material.materials[ 0 ];
  14732. if ( objectMaterial === null || objectMaterial.visible === false ) continue;
  14733. }
  14734. useMorphing = object.geometry.morphTargets !== undefined && object.geometry.morphTargets.length > 0 && objectMaterial.morphTargets;
  14735. useSkinning = object instanceof THREE.SkinnedMesh && objectMaterial.skinning;
  14736. if ( object.customDepthMaterial ) {
  14737. material = object.customDepthMaterial;
  14738. } else if ( useSkinning ) {
  14739. material = useMorphing ? _depthMaterialMorphSkin : _depthMaterialSkin;
  14740. } else if ( useMorphing ) {
  14741. material = _depthMaterialMorph;
  14742. } else {
  14743. material = _depthMaterial;
  14744. }
  14745. _renderer.renderBufferDirect( shadowCamera, _lights, null, material, object );
  14746. }
  14747. }
  14748. // restore GL state
  14749. var clearColor = _renderer.getClearColor(),
  14750. clearAlpha = _renderer.getClearAlpha();
  14751. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  14752. _state.enable( _gl.BLEND );
  14753. if ( scope.cullFace === THREE.CullFaceFront ) {
  14754. _gl.cullFace( _gl.BACK );
  14755. }
  14756. _renderer.resetGLState();
  14757. scope.needsUpdate = false;
  14758. };
  14759. function projectObject( object, camera ) {
  14760. if ( object.visible === false ) return;
  14761. var webglObject = _objects.objects[ object.id ];
  14762. if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  14763. var material = object.material;
  14764. if ( material !== null && material.visible === true ) {
  14765. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14766. _renderList.push( webglObject );
  14767. }
  14768. }
  14769. var children = object.children;
  14770. for ( var i = 0, l = children.length; i < l; i ++ ) {
  14771. projectObject( children[ i ], camera );
  14772. }
  14773. }
  14774. };
  14775. // File:src/renderers/webgl/WebGLState.js
  14776. /**
  14777. * @author mrdoob / http://mrdoob.com/
  14778. */
  14779. THREE.WebGLState = function ( gl, paramThreeToGL ) {
  14780. var _this = this;
  14781. var newAttributes = new Uint8Array( 16 );
  14782. var enabledAttributes = new Uint8Array( 16 );
  14783. var capabilities = {};
  14784. var currentBlending = null;
  14785. var currentBlendEquation = null;
  14786. var currentBlendSrc = null;
  14787. var currentBlendDst = null;
  14788. var currentBlendEquationAlpha = null;
  14789. var currentBlendSrcAlpha = null;
  14790. var currentBlendDstAlpha = null;
  14791. var currentDepthFunc = null;
  14792. var currentDepthWrite = null;
  14793. var currentColorWrite = null;
  14794. var currentFlipSided = null;
  14795. var currentLineWidth = null;
  14796. var currentPolygonOffsetFactor = null;
  14797. var currentPolygonOffsetUnits = null;
  14798. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14799. var currentTextureSlot = undefined;
  14800. var currentBoundTextures = {};
  14801. this.init = function () {
  14802. gl.clearColor( 0, 0, 0, 1 );
  14803. gl.clearDepth( 1 );
  14804. gl.clearStencil( 0 );
  14805. this.enable( gl.DEPTH_TEST );
  14806. gl.depthFunc( gl.LEQUAL );
  14807. gl.frontFace( gl.CCW );
  14808. gl.cullFace( gl.BACK );
  14809. this.enable( gl.CULL_FACE );
  14810. this.enable( gl.BLEND );
  14811. gl.blendEquation( gl.FUNC_ADD );
  14812. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  14813. };
  14814. this.initAttributes = function () {
  14815. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  14816. newAttributes[ i ] = 0;
  14817. }
  14818. };
  14819. this.enableAttribute = function ( attribute ) {
  14820. newAttributes[ attribute ] = 1;
  14821. if ( enabledAttributes[ attribute ] === 0 ) {
  14822. gl.enableVertexAttribArray( attribute );
  14823. enabledAttributes[ attribute ] = 1;
  14824. }
  14825. };
  14826. this.disableUnusedAttributes = function () {
  14827. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  14828. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  14829. gl.disableVertexAttribArray( i );
  14830. enabledAttributes[ i ] = 0;
  14831. }
  14832. }
  14833. };
  14834. this.enable = function ( id ) {
  14835. if ( capabilities[ id ] !== true ) {
  14836. gl.enable( id );
  14837. capabilities[ id ] = true;
  14838. }
  14839. };
  14840. this.disable = function ( id ) {
  14841. if ( capabilities[ id ] !== false ) {
  14842. gl.disable( id );
  14843. capabilities[ id ] = false;
  14844. }
  14845. };
  14846. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  14847. if ( blending !== currentBlending ) {
  14848. if ( blending === THREE.NoBlending ) {
  14849. this.disable( gl.BLEND );
  14850. } else if ( blending === THREE.AdditiveBlending ) {
  14851. this.enable( gl.BLEND );
  14852. gl.blendEquation( gl.FUNC_ADD );
  14853. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  14854. } else if ( blending === THREE.SubtractiveBlending ) {
  14855. // TODO: Find blendFuncSeparate() combination
  14856. this.enable( gl.BLEND );
  14857. gl.blendEquation( gl.FUNC_ADD );
  14858. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  14859. } else if ( blending === THREE.MultiplyBlending ) {
  14860. // TODO: Find blendFuncSeparate() combination
  14861. this.enable( gl.BLEND );
  14862. gl.blendEquation( gl.FUNC_ADD );
  14863. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  14864. } else if ( blending === THREE.CustomBlending ) {
  14865. this.enable( gl.BLEND );
  14866. } else {
  14867. this.enable( gl.BLEND );
  14868. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  14869. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  14870. }
  14871. currentBlending = blending;
  14872. }
  14873. if ( blending === THREE.CustomBlending ) {
  14874. blendEquationAlpha = blendEquationAlpha || blendEquation;
  14875. blendSrcAlpha = blendSrcAlpha || blendSrc;
  14876. blendDstAlpha = blendDstAlpha || blendDst;
  14877. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  14878. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  14879. currentBlendEquation = blendEquation;
  14880. currentBlendEquationAlpha = blendEquationAlpha;
  14881. }
  14882. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  14883. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  14884. currentBlendSrc = blendSrc;
  14885. currentBlendDst = blendDst;
  14886. currentBlendSrcAlpha = blendSrcAlpha;
  14887. currentBlendDstAlpha = blendDstAlpha;
  14888. }
  14889. } else {
  14890. currentBlendEquation = null;
  14891. currentBlendSrc = null;
  14892. currentBlendDst = null;
  14893. currentBlendEquationAlpha = null;
  14894. currentBlendSrcAlpha = null;
  14895. currentBlendDstAlpha = null;
  14896. }
  14897. };
  14898. this.setDepthFunc = function ( depthFunc ) {
  14899. if ( currentDepthFunc !== depthFunc ) {
  14900. if ( depthFunc ) {
  14901. switch ( depthFunc ) {
  14902. case THREE.NeverDepth:
  14903. gl.depthFunc( gl.NEVER );
  14904. break;
  14905. case THREE.AlwaysDepth:
  14906. gl.depthFunc( gl.ALWAYS );
  14907. break;
  14908. case THREE.LessDepth:
  14909. gl.depthFunc( gl.LESS );
  14910. break;
  14911. case THREE.LessEqualDepth:
  14912. gl.depthFunc( gl.LEQUAL );
  14913. break;
  14914. case THREE.EqualDepth:
  14915. gl.depthFunc( gl.EQUAL );
  14916. break;
  14917. case THREE.GreaterEqualDepth:
  14918. gl.depthFunc( gl.GEQUAL );
  14919. break;
  14920. case THREE.GreaterDepth:
  14921. gl.depthFunc( gl.GREATER );
  14922. break;
  14923. case THREE.NotEqualDepth:
  14924. gl.depthFunc( gl.NOTEQUAL );
  14925. break;
  14926. default:
  14927. gl.depthFunc( gl.LEQUAL );
  14928. }
  14929. } else {
  14930. gl.depthFunc( gl.LEQUAL );
  14931. }
  14932. currentDepthFunc = depthFunc;
  14933. }
  14934. };
  14935. this.setDepthTest = function ( depthTest ) {
  14936. if ( depthTest ) {
  14937. this.enable( gl.DEPTH_TEST );
  14938. } else {
  14939. this.disable( gl.DEPTH_TEST );
  14940. }
  14941. };
  14942. this.setDepthWrite = function ( depthWrite ) {
  14943. if ( currentDepthWrite !== depthWrite ) {
  14944. gl.depthMask( depthWrite );
  14945. currentDepthWrite = depthWrite;
  14946. }
  14947. };
  14948. this.setColorWrite = function ( colorWrite ) {
  14949. if ( currentColorWrite !== colorWrite ) {
  14950. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  14951. currentColorWrite = colorWrite;
  14952. }
  14953. };
  14954. this.setFlipSided = function ( flipSided ) {
  14955. if ( currentFlipSided !== flipSided ) {
  14956. if ( flipSided ) {
  14957. gl.frontFace( gl.CW );
  14958. } else {
  14959. gl.frontFace( gl.CCW );
  14960. }
  14961. currentFlipSided = flipSided;
  14962. }
  14963. };
  14964. this.setLineWidth = function ( width ) {
  14965. if ( width !== currentLineWidth ) {
  14966. gl.lineWidth( width );
  14967. currentLineWidth = width;
  14968. }
  14969. };
  14970. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  14971. if ( polygonOffset ) {
  14972. this.enable( gl.POLYGON_OFFSET_FILL );
  14973. } else {
  14974. this.disable( gl.POLYGON_OFFSET_FILL );
  14975. }
  14976. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  14977. gl.polygonOffset( factor, units );
  14978. currentPolygonOffsetFactor = factor;
  14979. currentPolygonOffsetUnits = units;
  14980. }
  14981. };
  14982. this.setScissorTest = function ( scissorTest ) {
  14983. if ( scissorTest ) {
  14984. this.enable( gl.SCISSOR_TEST );
  14985. } else {
  14986. this.disable( gl.SCISSOR_TEST );
  14987. }
  14988. };
  14989. // texture
  14990. this.activeTexture = function ( webglSlot ) {
  14991. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  14992. if ( currentTextureSlot !== webglSlot ) {
  14993. gl.activeTexture( webglSlot );
  14994. currentTextureSlot = webglSlot;
  14995. }
  14996. }
  14997. this.bindTexture = function ( webglType, webglTexture ) {
  14998. if ( currentTextureSlot === undefined ) {
  14999. _this.activeTexture();
  15000. }
  15001. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  15002. if ( boundTexture === undefined ) {
  15003. boundTexture = { type: undefined, texture: undefined };
  15004. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  15005. }
  15006. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  15007. gl.bindTexture( webglType, webglTexture );
  15008. boundTexture.type = webglType;
  15009. boundTexture.texture = webglTexture;
  15010. }
  15011. };
  15012. this.compressedTexImage2D = function () {
  15013. try {
  15014. gl.compressedTexImage2D.apply( gl, arguments );
  15015. } catch ( error ) {
  15016. console.error( error );
  15017. }
  15018. };
  15019. this.texImage2D = function () {
  15020. try {
  15021. gl.texImage2D.apply( gl, arguments );
  15022. } catch ( error ) {
  15023. console.error( error );
  15024. }
  15025. };
  15026. //
  15027. this.reset = function () {
  15028. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  15029. if ( enabledAttributes[ i ] === 1 ) {
  15030. gl.disableVertexAttribArray( i );
  15031. enabledAttributes[ i ] = 0;
  15032. }
  15033. }
  15034. capabilities = {};
  15035. currentBlending = null;
  15036. currentDepthWrite = null;
  15037. currentColorWrite = null;
  15038. currentFlipSided = null;
  15039. };
  15040. };
  15041. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  15042. /**
  15043. * @author mikael emtinger / http://gomo.se/
  15044. * @author alteredq / http://alteredqualia.com/
  15045. */
  15046. THREE.LensFlarePlugin = function ( renderer, flares ) {
  15047. var gl = renderer.context;
  15048. var state = renderer.state;
  15049. var vertexBuffer, elementBuffer;
  15050. var program, attributes, uniforms;
  15051. var hasVertexTexture;
  15052. var tempTexture, occlusionTexture;
  15053. var init = function () {
  15054. var vertices = new Float32Array( [
  15055. - 1, - 1, 0, 0,
  15056. 1, - 1, 1, 0,
  15057. 1, 1, 1, 1,
  15058. - 1, 1, 0, 1
  15059. ] );
  15060. var faces = new Uint16Array( [
  15061. 0, 1, 2,
  15062. 0, 2, 3
  15063. ] );
  15064. // buffers
  15065. vertexBuffer = gl.createBuffer();
  15066. elementBuffer = gl.createBuffer();
  15067. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15068. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15069. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15070. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15071. // textures
  15072. tempTexture = gl.createTexture();
  15073. occlusionTexture = gl.createTexture();
  15074. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15075. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  15076. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15077. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15078. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15079. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15080. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15081. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  15082. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15083. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15084. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15085. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15086. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  15087. var shader;
  15088. if ( hasVertexTexture ) {
  15089. shader = {
  15090. vertexShader: [
  15091. "uniform lowp int renderType;",
  15092. "uniform vec3 screenPosition;",
  15093. "uniform vec2 scale;",
  15094. "uniform float rotation;",
  15095. "uniform sampler2D occlusionMap;",
  15096. "attribute vec2 position;",
  15097. "attribute vec2 uv;",
  15098. "varying vec2 vUV;",
  15099. "varying float vVisibility;",
  15100. "void main() {",
  15101. "vUV = uv;",
  15102. "vec2 pos = position;",
  15103. "if( renderType == 2 ) {",
  15104. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  15105. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  15106. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  15107. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  15108. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  15109. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  15110. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  15111. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  15112. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  15113. "vVisibility = visibility.r / 9.0;",
  15114. "vVisibility *= 1.0 - visibility.g / 9.0;",
  15115. "vVisibility *= visibility.b / 9.0;",
  15116. "vVisibility *= 1.0 - visibility.a / 9.0;",
  15117. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15118. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15119. "}",
  15120. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15121. "}"
  15122. ].join( "\n" ),
  15123. fragmentShader: [
  15124. "uniform lowp int renderType;",
  15125. "uniform sampler2D map;",
  15126. "uniform float opacity;",
  15127. "uniform vec3 color;",
  15128. "varying vec2 vUV;",
  15129. "varying float vVisibility;",
  15130. "void main() {",
  15131. // pink square
  15132. "if( renderType == 0 ) {",
  15133. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  15134. // restore
  15135. "} else if( renderType == 1 ) {",
  15136. "gl_FragColor = texture2D( map, vUV );",
  15137. // flare
  15138. "} else {",
  15139. "vec4 texture = texture2D( map, vUV );",
  15140. "texture.a *= opacity * vVisibility;",
  15141. "gl_FragColor = texture;",
  15142. "gl_FragColor.rgb *= color;",
  15143. "}",
  15144. "}"
  15145. ].join( "\n" )
  15146. };
  15147. } else {
  15148. shader = {
  15149. vertexShader: [
  15150. "uniform lowp int renderType;",
  15151. "uniform vec3 screenPosition;",
  15152. "uniform vec2 scale;",
  15153. "uniform float rotation;",
  15154. "attribute vec2 position;",
  15155. "attribute vec2 uv;",
  15156. "varying vec2 vUV;",
  15157. "void main() {",
  15158. "vUV = uv;",
  15159. "vec2 pos = position;",
  15160. "if( renderType == 2 ) {",
  15161. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15162. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15163. "}",
  15164. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15165. "}"
  15166. ].join( "\n" ),
  15167. fragmentShader: [
  15168. "precision mediump float;",
  15169. "uniform lowp int renderType;",
  15170. "uniform sampler2D map;",
  15171. "uniform sampler2D occlusionMap;",
  15172. "uniform float opacity;",
  15173. "uniform vec3 color;",
  15174. "varying vec2 vUV;",
  15175. "void main() {",
  15176. // pink square
  15177. "if( renderType == 0 ) {",
  15178. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  15179. // restore
  15180. "} else if( renderType == 1 ) {",
  15181. "gl_FragColor = texture2D( map, vUV );",
  15182. // flare
  15183. "} else {",
  15184. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  15185. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  15186. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  15187. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  15188. "visibility = ( 1.0 - visibility / 4.0 );",
  15189. "vec4 texture = texture2D( map, vUV );",
  15190. "texture.a *= opacity * visibility;",
  15191. "gl_FragColor = texture;",
  15192. "gl_FragColor.rgb *= color;",
  15193. "}",
  15194. "}"
  15195. ].join( "\n" )
  15196. };
  15197. }
  15198. program = createProgram( shader );
  15199. attributes = {
  15200. vertex: gl.getAttribLocation ( program, "position" ),
  15201. uv: gl.getAttribLocation ( program, "uv" )
  15202. };
  15203. uniforms = {
  15204. renderType: gl.getUniformLocation( program, "renderType" ),
  15205. map: gl.getUniformLocation( program, "map" ),
  15206. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  15207. opacity: gl.getUniformLocation( program, "opacity" ),
  15208. color: gl.getUniformLocation( program, "color" ),
  15209. scale: gl.getUniformLocation( program, "scale" ),
  15210. rotation: gl.getUniformLocation( program, "rotation" ),
  15211. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  15212. };
  15213. };
  15214. /*
  15215. * Render lens flares
  15216. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  15217. * reads these back and calculates occlusion.
  15218. */
  15219. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  15220. if ( flares.length === 0 ) return;
  15221. var tempPosition = new THREE.Vector3();
  15222. var invAspect = viewportHeight / viewportWidth,
  15223. halfViewportWidth = viewportWidth * 0.5,
  15224. halfViewportHeight = viewportHeight * 0.5;
  15225. var size = 16 / viewportHeight,
  15226. scale = new THREE.Vector2( size * invAspect, size );
  15227. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  15228. screenPositionPixels = new THREE.Vector2( 1, 1 );
  15229. if ( program === undefined ) {
  15230. init();
  15231. }
  15232. gl.useProgram( program );
  15233. state.initAttributes();
  15234. state.enableAttribute( attributes.vertex );
  15235. state.enableAttribute( attributes.uv );
  15236. state.disableUnusedAttributes();
  15237. // loop through all lens flares to update their occlusion and positions
  15238. // setup gl and common used attribs/uniforms
  15239. gl.uniform1i( uniforms.occlusionMap, 0 );
  15240. gl.uniform1i( uniforms.map, 1 );
  15241. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15242. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  15243. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15244. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15245. state.disable( gl.CULL_FACE );
  15246. gl.depthMask( false );
  15247. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  15248. size = 16 / viewportHeight;
  15249. scale.set( size * invAspect, size );
  15250. // calc object screen position
  15251. var flare = flares[ i ];
  15252. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  15253. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  15254. tempPosition.applyProjection( camera.projectionMatrix );
  15255. // setup arrays for gl programs
  15256. screenPosition.copy( tempPosition );
  15257. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  15258. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  15259. // screen cull
  15260. if ( hasVertexTexture || (
  15261. screenPositionPixels.x > 0 &&
  15262. screenPositionPixels.x < viewportWidth &&
  15263. screenPositionPixels.y > 0 &&
  15264. screenPositionPixels.y < viewportHeight ) ) {
  15265. // save current RGB to temp texture
  15266. state.activeTexture( gl.TEXTURE0 );
  15267. state.bindTexture( gl.TEXTURE_2D, null );
  15268. state.activeTexture( gl.TEXTURE1 );
  15269. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15270. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15271. // render pink quad
  15272. gl.uniform1i( uniforms.renderType, 0 );
  15273. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15274. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15275. state.disable( gl.BLEND );
  15276. state.enable( gl.DEPTH_TEST );
  15277. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15278. // copy result to occlusionMap
  15279. state.activeTexture( gl.TEXTURE0 );
  15280. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15281. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15282. // restore graphics
  15283. gl.uniform1i( uniforms.renderType, 1 );
  15284. state.disable( gl.DEPTH_TEST );
  15285. state.activeTexture( gl.TEXTURE1 );
  15286. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15287. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15288. // update object positions
  15289. flare.positionScreen.copy( screenPosition );
  15290. if ( flare.customUpdateCallback ) {
  15291. flare.customUpdateCallback( flare );
  15292. } else {
  15293. flare.updateLensFlares();
  15294. }
  15295. // render flares
  15296. gl.uniform1i( uniforms.renderType, 2 );
  15297. state.enable( gl.BLEND );
  15298. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  15299. var sprite = flare.lensFlares[ j ];
  15300. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  15301. screenPosition.x = sprite.x;
  15302. screenPosition.y = sprite.y;
  15303. screenPosition.z = sprite.z;
  15304. size = sprite.size * sprite.scale / viewportHeight;
  15305. scale.x = size * invAspect;
  15306. scale.y = size;
  15307. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15308. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15309. gl.uniform1f( uniforms.rotation, sprite.rotation );
  15310. gl.uniform1f( uniforms.opacity, sprite.opacity );
  15311. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  15312. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  15313. renderer.setTexture( sprite.texture, 1 );
  15314. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15315. }
  15316. }
  15317. }
  15318. }
  15319. // restore gl
  15320. state.enable( gl.CULL_FACE );
  15321. state.enable( gl.DEPTH_TEST );
  15322. gl.depthMask( true );
  15323. renderer.resetGLState();
  15324. };
  15325. function createProgram ( shader ) {
  15326. var program = gl.createProgram();
  15327. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15328. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15329. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  15330. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  15331. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  15332. gl.compileShader( fragmentShader );
  15333. gl.compileShader( vertexShader );
  15334. gl.attachShader( program, fragmentShader );
  15335. gl.attachShader( program, vertexShader );
  15336. gl.linkProgram( program );
  15337. return program;
  15338. }
  15339. };
  15340. // File:src/renderers/webgl/plugins/SpritePlugin.js
  15341. /**
  15342. * @author mikael emtinger / http://gomo.se/
  15343. * @author alteredq / http://alteredqualia.com/
  15344. */
  15345. THREE.SpritePlugin = function ( renderer, sprites ) {
  15346. var gl = renderer.context;
  15347. var state = renderer.state;
  15348. var vertexBuffer, elementBuffer;
  15349. var program, attributes, uniforms;
  15350. var texture;
  15351. // decompose matrixWorld
  15352. var spritePosition = new THREE.Vector3();
  15353. var spriteRotation = new THREE.Quaternion();
  15354. var spriteScale = new THREE.Vector3();
  15355. var init = function () {
  15356. var vertices = new Float32Array( [
  15357. - 0.5, - 0.5, 0, 0,
  15358. 0.5, - 0.5, 1, 0,
  15359. 0.5, 0.5, 1, 1,
  15360. - 0.5, 0.5, 0, 1
  15361. ] );
  15362. var faces = new Uint16Array( [
  15363. 0, 1, 2,
  15364. 0, 2, 3
  15365. ] );
  15366. vertexBuffer = gl.createBuffer();
  15367. elementBuffer = gl.createBuffer();
  15368. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15369. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15370. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15371. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15372. program = createProgram();
  15373. attributes = {
  15374. position: gl.getAttribLocation ( program, 'position' ),
  15375. uv: gl.getAttribLocation ( program, 'uv' )
  15376. };
  15377. uniforms = {
  15378. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  15379. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  15380. rotation: gl.getUniformLocation( program, 'rotation' ),
  15381. scale: gl.getUniformLocation( program, 'scale' ),
  15382. color: gl.getUniformLocation( program, 'color' ),
  15383. map: gl.getUniformLocation( program, 'map' ),
  15384. opacity: gl.getUniformLocation( program, 'opacity' ),
  15385. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  15386. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  15387. fogType: gl.getUniformLocation( program, 'fogType' ),
  15388. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  15389. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  15390. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  15391. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  15392. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  15393. };
  15394. var canvas = document.createElement( 'canvas' );
  15395. canvas.width = 8;
  15396. canvas.height = 8;
  15397. var context = canvas.getContext( '2d' );
  15398. context.fillStyle = 'white';
  15399. context.fillRect( 0, 0, 8, 8 );
  15400. texture = new THREE.Texture( canvas );
  15401. texture.needsUpdate = true;
  15402. };
  15403. this.render = function ( scene, camera ) {
  15404. if ( sprites.length === 0 ) return;
  15405. // setup gl
  15406. if ( program === undefined ) {
  15407. init();
  15408. }
  15409. gl.useProgram( program );
  15410. state.initAttributes();
  15411. state.enableAttribute( attributes.position );
  15412. state.enableAttribute( attributes.uv );
  15413. state.disableUnusedAttributes();
  15414. state.disable( gl.CULL_FACE );
  15415. state.enable( gl.BLEND );
  15416. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15417. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  15418. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15419. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15420. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15421. state.activeTexture( gl.TEXTURE0 );
  15422. gl.uniform1i( uniforms.map, 0 );
  15423. var oldFogType = 0;
  15424. var sceneFogType = 0;
  15425. var fog = scene.fog;
  15426. if ( fog ) {
  15427. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  15428. if ( fog instanceof THREE.Fog ) {
  15429. gl.uniform1f( uniforms.fogNear, fog.near );
  15430. gl.uniform1f( uniforms.fogFar, fog.far );
  15431. gl.uniform1i( uniforms.fogType, 1 );
  15432. oldFogType = 1;
  15433. sceneFogType = 1;
  15434. } else if ( fog instanceof THREE.FogExp2 ) {
  15435. gl.uniform1f( uniforms.fogDensity, fog.density );
  15436. gl.uniform1i( uniforms.fogType, 2 );
  15437. oldFogType = 2;
  15438. sceneFogType = 2;
  15439. }
  15440. } else {
  15441. gl.uniform1i( uniforms.fogType, 0 );
  15442. oldFogType = 0;
  15443. sceneFogType = 0;
  15444. }
  15445. // update positions and sort
  15446. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15447. var sprite = sprites[ i ];
  15448. sprite._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  15449. sprite.z = - sprite._modelViewMatrix.elements[ 14 ];
  15450. }
  15451. sprites.sort( painterSortStable );
  15452. // render all sprites
  15453. var scale = [];
  15454. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15455. var sprite = sprites[ i ];
  15456. var material = sprite.material;
  15457. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  15458. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
  15459. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  15460. scale[ 0 ] = spriteScale.x;
  15461. scale[ 1 ] = spriteScale.y;
  15462. var fogType = 0;
  15463. if ( scene.fog && material.fog ) {
  15464. fogType = sceneFogType;
  15465. }
  15466. if ( oldFogType !== fogType ) {
  15467. gl.uniform1i( uniforms.fogType, fogType );
  15468. oldFogType = fogType;
  15469. }
  15470. if ( material.map !== null ) {
  15471. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  15472. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  15473. } else {
  15474. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  15475. gl.uniform2f( uniforms.uvScale, 1, 1 );
  15476. }
  15477. gl.uniform1f( uniforms.opacity, material.opacity );
  15478. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  15479. gl.uniform1f( uniforms.rotation, material.rotation );
  15480. gl.uniform2fv( uniforms.scale, scale );
  15481. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  15482. state.setDepthTest( material.depthTest );
  15483. state.setDepthWrite( material.depthWrite );
  15484. if ( material.map && material.map.image && material.map.image.width ) {
  15485. renderer.setTexture( material.map, 0 );
  15486. } else {
  15487. renderer.setTexture( texture, 0 );
  15488. }
  15489. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15490. }
  15491. // restore gl
  15492. state.enable( gl.CULL_FACE );
  15493. renderer.resetGLState();
  15494. };
  15495. function createProgram () {
  15496. var program = gl.createProgram();
  15497. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15498. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15499. gl.shaderSource( vertexShader, [
  15500. 'precision ' + renderer.getPrecision() + ' float;',
  15501. 'uniform mat4 modelViewMatrix;',
  15502. 'uniform mat4 projectionMatrix;',
  15503. 'uniform float rotation;',
  15504. 'uniform vec2 scale;',
  15505. 'uniform vec2 uvOffset;',
  15506. 'uniform vec2 uvScale;',
  15507. 'attribute vec2 position;',
  15508. 'attribute vec2 uv;',
  15509. 'varying vec2 vUV;',
  15510. 'void main() {',
  15511. 'vUV = uvOffset + uv * uvScale;',
  15512. 'vec2 alignedPosition = position * scale;',
  15513. 'vec2 rotatedPosition;',
  15514. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  15515. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  15516. 'vec4 finalPosition;',
  15517. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  15518. 'finalPosition.xy += rotatedPosition;',
  15519. 'finalPosition = projectionMatrix * finalPosition;',
  15520. 'gl_Position = finalPosition;',
  15521. '}'
  15522. ].join( '\n' ) );
  15523. gl.shaderSource( fragmentShader, [
  15524. 'precision ' + renderer.getPrecision() + ' float;',
  15525. 'uniform vec3 color;',
  15526. 'uniform sampler2D map;',
  15527. 'uniform float opacity;',
  15528. 'uniform int fogType;',
  15529. 'uniform vec3 fogColor;',
  15530. 'uniform float fogDensity;',
  15531. 'uniform float fogNear;',
  15532. 'uniform float fogFar;',
  15533. 'uniform float alphaTest;',
  15534. 'varying vec2 vUV;',
  15535. 'void main() {',
  15536. 'vec4 texture = texture2D( map, vUV );',
  15537. 'if ( texture.a < alphaTest ) discard;',
  15538. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  15539. 'if ( fogType > 0 ) {',
  15540. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  15541. 'float fogFactor = 0.0;',
  15542. 'if ( fogType == 1 ) {',
  15543. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  15544. '} else {',
  15545. 'const float LOG2 = 1.442695;',
  15546. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  15547. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  15548. '}',
  15549. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  15550. '}',
  15551. '}'
  15552. ].join( '\n' ) );
  15553. gl.compileShader( vertexShader );
  15554. gl.compileShader( fragmentShader );
  15555. gl.attachShader( program, vertexShader );
  15556. gl.attachShader( program, fragmentShader );
  15557. gl.linkProgram( program );
  15558. return program;
  15559. }
  15560. function painterSortStable ( a, b ) {
  15561. if ( a.z !== b.z ) {
  15562. return b.z - a.z;
  15563. } else {
  15564. return b.id - a.id;
  15565. }
  15566. }
  15567. };
  15568. // File:src/extras/GeometryUtils.js
  15569. /**
  15570. * @author mrdoob / http://mrdoob.com/
  15571. */
  15572. THREE.GeometryUtils = {
  15573. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  15574. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  15575. var matrix;
  15576. if ( geometry2 instanceof THREE.Mesh ) {
  15577. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  15578. matrix = geometry2.matrix;
  15579. geometry2 = geometry2.geometry;
  15580. }
  15581. geometry1.merge( geometry2, matrix, materialIndexOffset );
  15582. },
  15583. center: function ( geometry ) {
  15584. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  15585. return geometry.center();
  15586. }
  15587. };
  15588. // File:src/extras/ImageUtils.js
  15589. /**
  15590. * @author alteredq / http://alteredqualia.com/
  15591. * @author mrdoob / http://mrdoob.com/
  15592. * @author Daosheng Mu / https://github.com/DaoshengMu/
  15593. */
  15594. THREE.ImageUtils = {
  15595. crossOrigin: undefined,
  15596. loadTexture: function ( url, mapping, onLoad, onError ) {
  15597. var loader = new THREE.ImageLoader();
  15598. loader.crossOrigin = this.crossOrigin;
  15599. var texture = new THREE.Texture( undefined, mapping );
  15600. loader.load( url, function ( image ) {
  15601. texture.image = image;
  15602. texture.needsUpdate = true;
  15603. if ( onLoad ) onLoad( texture );
  15604. }, undefined, function ( event ) {
  15605. if ( onError ) onError( event );
  15606. } );
  15607. texture.sourceFile = url;
  15608. return texture;
  15609. },
  15610. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  15611. var images = [];
  15612. var loader = new THREE.ImageLoader();
  15613. loader.crossOrigin = this.crossOrigin;
  15614. var texture = new THREE.CubeTexture( images, mapping );
  15615. var loaded = 0;
  15616. var loadTexture = function ( i ) {
  15617. loader.load( array[ i ], function ( image ) {
  15618. texture.images[ i ] = image;
  15619. loaded += 1;
  15620. if ( loaded === 6 ) {
  15621. texture.needsUpdate = true;
  15622. if ( onLoad ) onLoad( texture );
  15623. }
  15624. }, undefined, onError );
  15625. };
  15626. for ( var i = 0, il = array.length; i < il; ++ i ) {
  15627. loadTexture( i );
  15628. }
  15629. return texture;
  15630. },
  15631. loadCompressedTexture: function () {
  15632. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  15633. },
  15634. loadCompressedTextureCube: function () {
  15635. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  15636. },
  15637. getNormalMap: function ( image, depth ) {
  15638. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  15639. var cross = function ( a, b ) {
  15640. 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 ] ];
  15641. };
  15642. var subtract = function ( a, b ) {
  15643. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  15644. };
  15645. var normalize = function ( a ) {
  15646. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  15647. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  15648. };
  15649. depth = depth | 1;
  15650. var width = image.width;
  15651. var height = image.height;
  15652. var canvas = document.createElement( 'canvas' );
  15653. canvas.width = width;
  15654. canvas.height = height;
  15655. var context = canvas.getContext( '2d' );
  15656. context.drawImage( image, 0, 0 );
  15657. var data = context.getImageData( 0, 0, width, height ).data;
  15658. var imageData = context.createImageData( width, height );
  15659. var output = imageData.data;
  15660. for ( var x = 0; x < width; x ++ ) {
  15661. for ( var y = 0; y < height; y ++ ) {
  15662. var ly = y - 1 < 0 ? 0 : y - 1;
  15663. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  15664. var lx = x - 1 < 0 ? 0 : x - 1;
  15665. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  15666. var points = [];
  15667. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  15668. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  15669. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  15670. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  15671. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  15672. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  15673. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  15674. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  15675. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  15676. var normals = [];
  15677. var num_points = points.length;
  15678. for ( var i = 0; i < num_points; i ++ ) {
  15679. var v1 = points[ i ];
  15680. var v2 = points[ ( i + 1 ) % num_points ];
  15681. v1 = subtract( v1, origin );
  15682. v2 = subtract( v2, origin );
  15683. normals.push( normalize( cross( v1, v2 ) ) );
  15684. }
  15685. var normal = [ 0, 0, 0 ];
  15686. for ( var i = 0; i < normals.length; i ++ ) {
  15687. normal[ 0 ] += normals[ i ][ 0 ];
  15688. normal[ 1 ] += normals[ i ][ 1 ];
  15689. normal[ 2 ] += normals[ i ][ 2 ];
  15690. }
  15691. normal[ 0 ] /= normals.length;
  15692. normal[ 1 ] /= normals.length;
  15693. normal[ 2 ] /= normals.length;
  15694. var idx = ( y * width + x ) * 4;
  15695. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15696. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15697. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  15698. output[ idx + 3 ] = 255;
  15699. }
  15700. }
  15701. context.putImageData( imageData, 0, 0 );
  15702. return canvas;
  15703. },
  15704. generateDataTexture: function ( width, height, color ) {
  15705. var size = width * height;
  15706. var data = new Uint8Array( 3 * size );
  15707. var r = Math.floor( color.r * 255 );
  15708. var g = Math.floor( color.g * 255 );
  15709. var b = Math.floor( color.b * 255 );
  15710. for ( var i = 0; i < size; i ++ ) {
  15711. data[ i * 3 ] = r;
  15712. data[ i * 3 + 1 ] = g;
  15713. data[ i * 3 + 2 ] = b;
  15714. }
  15715. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  15716. texture.needsUpdate = true;
  15717. return texture;
  15718. }
  15719. };
  15720. // File:src/extras/SceneUtils.js
  15721. /**
  15722. * @author alteredq / http://alteredqualia.com/
  15723. */
  15724. THREE.SceneUtils = {
  15725. createMultiMaterialObject: function ( geometry, materials ) {
  15726. var group = new THREE.Object3D();
  15727. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  15728. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  15729. }
  15730. return group;
  15731. },
  15732. detach: function ( child, parent, scene ) {
  15733. child.applyMatrix( parent.matrixWorld );
  15734. parent.remove( child );
  15735. scene.add( child );
  15736. },
  15737. attach: function ( child, scene, parent ) {
  15738. var matrixWorldInverse = new THREE.Matrix4();
  15739. matrixWorldInverse.getInverse( parent.matrixWorld );
  15740. child.applyMatrix( matrixWorldInverse );
  15741. scene.remove( child );
  15742. parent.add( child );
  15743. }
  15744. };
  15745. // File:src/extras/FontUtils.js
  15746. /**
  15747. * @author zz85 / http://www.lab4games.net/zz85/blog
  15748. * @author alteredq / http://alteredqualia.com/
  15749. *
  15750. * For Text operations in three.js (See TextGeometry)
  15751. *
  15752. * It uses techniques used in:
  15753. *
  15754. * Triangulation ported from AS3
  15755. * Simple Polygon Triangulation
  15756. * http://actionsnippet.com/?p=1462
  15757. *
  15758. * A Method to triangulate shapes with holes
  15759. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  15760. *
  15761. */
  15762. THREE.FontUtils = {
  15763. faces: {},
  15764. // Just for now. face[weight][style]
  15765. face: 'helvetiker',
  15766. weight: 'normal',
  15767. style: 'normal',
  15768. size: 150,
  15769. divisions: 10,
  15770. getFace: function () {
  15771. try {
  15772. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  15773. } catch ( e ) {
  15774. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  15775. }
  15776. },
  15777. loadFace: function ( data ) {
  15778. var family = data.familyName.toLowerCase();
  15779. var ThreeFont = this;
  15780. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  15781. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  15782. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15783. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15784. return data;
  15785. },
  15786. drawText: function ( text ) {
  15787. // RenderText
  15788. var i,
  15789. face = this.getFace(),
  15790. scale = this.size / face.resolution,
  15791. offset = 0,
  15792. chars = String( text ).split( '' ),
  15793. length = chars.length;
  15794. var fontPaths = [];
  15795. for ( i = 0; i < length; i ++ ) {
  15796. var path = new THREE.Path();
  15797. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  15798. offset += ret.offset;
  15799. fontPaths.push( ret.path );
  15800. }
  15801. // get the width
  15802. var width = offset / 2;
  15803. //
  15804. // for ( p = 0; p < allPts.length; p++ ) {
  15805. //
  15806. // allPts[ p ].x -= width;
  15807. //
  15808. // }
  15809. //var extract = this.extractPoints( allPts, characterPts );
  15810. //extract.contour = allPts;
  15811. //extract.paths = fontPaths;
  15812. //extract.offset = width;
  15813. return { paths: fontPaths, offset: width };
  15814. },
  15815. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  15816. var pts = [];
  15817. var i, i2, divisions,
  15818. outline, action, length,
  15819. scaleX, scaleY,
  15820. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  15821. laste,
  15822. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  15823. if ( ! glyph ) return;
  15824. if ( glyph.o ) {
  15825. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  15826. length = outline.length;
  15827. scaleX = scale;
  15828. scaleY = scale;
  15829. for ( i = 0; i < length; ) {
  15830. action = outline[ i ++ ];
  15831. //console.log( action );
  15832. switch ( action ) {
  15833. case 'm':
  15834. // Move To
  15835. x = outline[ i ++ ] * scaleX + offset;
  15836. y = outline[ i ++ ] * scaleY;
  15837. path.moveTo( x, y );
  15838. break;
  15839. case 'l':
  15840. // Line To
  15841. x = outline[ i ++ ] * scaleX + offset;
  15842. y = outline[ i ++ ] * scaleY;
  15843. path.lineTo( x, y );
  15844. break;
  15845. case 'q':
  15846. // QuadraticCurveTo
  15847. cpx = outline[ i ++ ] * scaleX + offset;
  15848. cpy = outline[ i ++ ] * scaleY;
  15849. cpx1 = outline[ i ++ ] * scaleX + offset;
  15850. cpy1 = outline[ i ++ ] * scaleY;
  15851. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  15852. laste = pts[ pts.length - 1 ];
  15853. if ( laste ) {
  15854. cpx0 = laste.x;
  15855. cpy0 = laste.y;
  15856. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15857. var t = i2 / divisions;
  15858. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  15859. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  15860. }
  15861. }
  15862. break;
  15863. case 'b':
  15864. // Cubic Bezier Curve
  15865. cpx = outline[ i ++ ] * scaleX + offset;
  15866. cpy = outline[ i ++ ] * scaleY;
  15867. cpx1 = outline[ i ++ ] * scaleX + offset;
  15868. cpy1 = outline[ i ++ ] * scaleY;
  15869. cpx2 = outline[ i ++ ] * scaleX + offset;
  15870. cpy2 = outline[ i ++ ] * scaleY;
  15871. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  15872. laste = pts[ pts.length - 1 ];
  15873. if ( laste ) {
  15874. cpx0 = laste.x;
  15875. cpy0 = laste.y;
  15876. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15877. var t = i2 / divisions;
  15878. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  15879. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  15880. }
  15881. }
  15882. break;
  15883. }
  15884. }
  15885. }
  15886. return { offset: glyph.ha * scale, path: path };
  15887. }
  15888. };
  15889. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  15890. // Parameters
  15891. parameters = parameters || {};
  15892. var size = parameters.size !== undefined ? parameters.size : 100;
  15893. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  15894. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  15895. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  15896. var style = parameters.style !== undefined ? parameters.style : 'normal';
  15897. THREE.FontUtils.size = size;
  15898. THREE.FontUtils.divisions = curveSegments;
  15899. THREE.FontUtils.face = font;
  15900. THREE.FontUtils.weight = weight;
  15901. THREE.FontUtils.style = style;
  15902. // Get a Font data json object
  15903. var data = THREE.FontUtils.drawText( text );
  15904. var paths = data.paths;
  15905. var shapes = [];
  15906. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  15907. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  15908. }
  15909. return shapes;
  15910. };
  15911. /**
  15912. * This code is a quick port of code written in C++ which was submitted to
  15913. * flipcode.com by John W. Ratcliff // July 22, 2000
  15914. * See original code and more information here:
  15915. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  15916. *
  15917. * ported to actionscript by Zevan Rosser
  15918. * www.actionsnippet.com
  15919. *
  15920. * ported to javascript by Joshua Koo
  15921. * http://www.lab4games.net/zz85/blog
  15922. *
  15923. */
  15924. ( function ( namespace ) {
  15925. var EPSILON = 0.0000000001;
  15926. // takes in an contour array and returns
  15927. var process = function ( contour, indices ) {
  15928. var n = contour.length;
  15929. if ( n < 3 ) return null;
  15930. var result = [],
  15931. verts = [],
  15932. vertIndices = [];
  15933. /* we want a counter-clockwise polygon in verts */
  15934. var u, v, w;
  15935. if ( area( contour ) > 0.0 ) {
  15936. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  15937. } else {
  15938. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  15939. }
  15940. var nv = n;
  15941. /* remove nv - 2 vertices, creating 1 triangle every time */
  15942. var count = 2 * nv; /* error detection */
  15943. for ( v = nv - 1; nv > 2; ) {
  15944. /* if we loop, it is probably a non-simple polygon */
  15945. if ( ( count -- ) <= 0 ) {
  15946. //** Triangulate: ERROR - probable bad polygon!
  15947. //throw ( "Warning, unable to triangulate polygon!" );
  15948. //return null;
  15949. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  15950. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  15951. if ( indices ) return vertIndices;
  15952. return result;
  15953. }
  15954. /* three consecutive vertices in current polygon, <u,v,w> */
  15955. u = v; if ( nv <= u ) u = 0; /* previous */
  15956. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  15957. w = v + 1; if ( nv <= w ) w = 0; /* next */
  15958. if ( snip( contour, u, v, w, nv, verts ) ) {
  15959. var a, b, c, s, t;
  15960. /* true names of the vertices */
  15961. a = verts[ u ];
  15962. b = verts[ v ];
  15963. c = verts[ w ];
  15964. /* output Triangle */
  15965. result.push( [ contour[ a ],
  15966. contour[ b ],
  15967. contour[ c ] ] );
  15968. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  15969. /* remove v from the remaining polygon */
  15970. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  15971. verts[ s ] = verts[ t ];
  15972. }
  15973. nv --;
  15974. /* reset error detection counter */
  15975. count = 2 * nv;
  15976. }
  15977. }
  15978. if ( indices ) return vertIndices;
  15979. return result;
  15980. };
  15981. // calculate area of the contour polygon
  15982. var area = function ( contour ) {
  15983. var n = contour.length;
  15984. var a = 0.0;
  15985. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  15986. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  15987. }
  15988. return a * 0.5;
  15989. };
  15990. var snip = function ( contour, u, v, w, n, verts ) {
  15991. var p;
  15992. var ax, ay, bx, by;
  15993. var cx, cy, px, py;
  15994. ax = contour[ verts[ u ] ].x;
  15995. ay = contour[ verts[ u ] ].y;
  15996. bx = contour[ verts[ v ] ].x;
  15997. by = contour[ verts[ v ] ].y;
  15998. cx = contour[ verts[ w ] ].x;
  15999. cy = contour[ verts[ w ] ].y;
  16000. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  16001. var aX, aY, bX, bY, cX, cY;
  16002. var apx, apy, bpx, bpy, cpx, cpy;
  16003. var cCROSSap, bCROSScp, aCROSSbp;
  16004. aX = cx - bx; aY = cy - by;
  16005. bX = ax - cx; bY = ay - cy;
  16006. cX = bx - ax; cY = by - ay;
  16007. for ( p = 0; p < n; p ++ ) {
  16008. px = contour[ verts[ p ] ].x;
  16009. py = contour[ verts[ p ] ].y;
  16010. if ( ( ( px === ax ) && ( py === ay ) ) ||
  16011. ( ( px === bx ) && ( py === by ) ) ||
  16012. ( ( px === cx ) && ( py === cy ) ) ) continue;
  16013. apx = px - ax; apy = py - ay;
  16014. bpx = px - bx; bpy = py - by;
  16015. cpx = px - cx; cpy = py - cy;
  16016. // see if p is inside triangle abc
  16017. aCROSSbp = aX * bpy - aY * bpx;
  16018. cCROSSap = cX * apy - cY * apx;
  16019. bCROSScp = bX * cpy - bY * cpx;
  16020. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  16021. }
  16022. return true;
  16023. };
  16024. namespace.Triangulate = process;
  16025. namespace.Triangulate.area = area;
  16026. return namespace;
  16027. } )( THREE.FontUtils );
  16028. // To use the typeface.js face files, hook up the API
  16029. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  16030. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  16031. // File:src/extras/audio/Audio.js
  16032. /**
  16033. * @author mrdoob / http://mrdoob.com/
  16034. */
  16035. THREE.Audio = function ( listener ) {
  16036. THREE.Object3D.call( this );
  16037. this.type = 'Audio';
  16038. this.context = listener.context;
  16039. this.source = this.context.createBufferSource();
  16040. this.source.onended = this.onEnded.bind( this );
  16041. this.gain = this.context.createGain();
  16042. this.gain.connect( this.context.destination );
  16043. this.panner = this.context.createPanner();
  16044. this.panner.connect( this.gain );
  16045. this.autoplay = false;
  16046. this.startTime = 0;
  16047. this.playbackRate = 1;
  16048. this.isPlaying = false;
  16049. };
  16050. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  16051. THREE.Audio.prototype.constructor = THREE.Audio;
  16052. THREE.Audio.prototype.load = function ( file ) {
  16053. var scope = this;
  16054. var request = new XMLHttpRequest();
  16055. request.open( 'GET', file, true );
  16056. request.responseType = 'arraybuffer';
  16057. request.onload = function ( e ) {
  16058. scope.context.decodeAudioData( this.response, function ( buffer ) {
  16059. scope.source.buffer = buffer;
  16060. if ( scope.autoplay ) scope.play();
  16061. } );
  16062. };
  16063. request.send();
  16064. return this;
  16065. };
  16066. THREE.Audio.prototype.play = function () {
  16067. if ( this.isPlaying === true ) {
  16068. console.warn( 'THREE.Audio: Audio is already playing.' );
  16069. return;
  16070. }
  16071. var source = this.context.createBufferSource();
  16072. source.buffer = this.source.buffer;
  16073. source.loop = this.source.loop;
  16074. source.onended = this.source.onended;
  16075. source.start( 0, this.startTime );
  16076. source.playbackRate.value = this.playbackRate;
  16077. this.isPlaying = true;
  16078. this.source = source;
  16079. this.connect();
  16080. };
  16081. THREE.Audio.prototype.pause = function () {
  16082. this.source.stop();
  16083. this.startTime = this.context.currentTime;
  16084. };
  16085. THREE.Audio.prototype.stop = function () {
  16086. this.source.stop();
  16087. this.startTime = 0;
  16088. };
  16089. THREE.Audio.prototype.connect = function () {
  16090. if ( this.filter !== undefined ) {
  16091. this.source.connect( this.filter );
  16092. this.filter.connect( this.panner );
  16093. } else {
  16094. this.source.connect( this.panner );
  16095. }
  16096. };
  16097. THREE.Audio.prototype.disconnect = function () {
  16098. if ( this.filter !== undefined ) {
  16099. this.source.disconnect( this.filter );
  16100. this.filter.disconnect( this.panner );
  16101. } else {
  16102. this.source.disconnect( this.panner );
  16103. }
  16104. };
  16105. THREE.Audio.prototype.setFilter = function ( value ) {
  16106. if ( this.isPlaying === true ) {
  16107. this.disconnect();
  16108. this.filter = value;
  16109. this.connect();
  16110. } else {
  16111. this.filter = value;
  16112. }
  16113. };
  16114. THREE.Audio.prototype.getFilter = function () {
  16115. return this.filter;
  16116. };
  16117. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  16118. this.playbackRate = value;
  16119. if ( this.isPlaying === true ) {
  16120. this.source.playbackRate.value = this.playbackRate;
  16121. }
  16122. };
  16123. THREE.Audio.prototype.getPlaybackRate = function () {
  16124. return this.playbackRate;
  16125. };
  16126. THREE.Audio.prototype.onEnded = function() {
  16127. this.isPlaying = false;
  16128. };
  16129. THREE.Audio.prototype.setLoop = function ( value ) {
  16130. this.source.loop = value;
  16131. };
  16132. THREE.Audio.prototype.getLoop = function () {
  16133. return this.source.loop;
  16134. };
  16135. THREE.Audio.prototype.setRefDistance = function ( value ) {
  16136. this.panner.refDistance = value;
  16137. };
  16138. THREE.Audio.prototype.getRefDistance = function () {
  16139. return this.panner.refDistance;
  16140. };
  16141. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  16142. this.panner.rolloffFactor = value;
  16143. };
  16144. THREE.Audio.prototype.getRolloffFactor = function () {
  16145. return this.panner.rolloffFactor;
  16146. };
  16147. THREE.Audio.prototype.setVolume = function ( value ) {
  16148. this.gain.gain.value = value;
  16149. };
  16150. THREE.Audio.prototype.getVolume = function () {
  16151. return this.gain.gain.value;
  16152. };
  16153. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  16154. var position = new THREE.Vector3();
  16155. return function updateMatrixWorld( force ) {
  16156. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16157. position.setFromMatrixPosition( this.matrixWorld );
  16158. this.panner.setPosition( position.x, position.y, position.z );
  16159. };
  16160. } )();
  16161. // File:src/extras/audio/AudioListener.js
  16162. /**
  16163. * @author mrdoob / http://mrdoob.com/
  16164. */
  16165. THREE.AudioListener = function () {
  16166. THREE.Object3D.call( this );
  16167. this.type = 'AudioListener';
  16168. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  16169. };
  16170. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  16171. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  16172. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  16173. var position = new THREE.Vector3();
  16174. var quaternion = new THREE.Quaternion();
  16175. var scale = new THREE.Vector3();
  16176. var orientation = new THREE.Vector3();
  16177. return function updateMatrixWorld( force ) {
  16178. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16179. var listener = this.context.listener;
  16180. var up = this.up;
  16181. this.matrixWorld.decompose( position, quaternion, scale );
  16182. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  16183. listener.setPosition( position.x, position.y, position.z );
  16184. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  16185. };
  16186. } )();
  16187. // File:src/extras/core/Curve.js
  16188. /**
  16189. * @author zz85 / http://www.lab4games.net/zz85/blog
  16190. * Extensible curve object
  16191. *
  16192. * Some common of Curve methods
  16193. * .getPoint(t), getTangent(t)
  16194. * .getPointAt(u), getTagentAt(u)
  16195. * .getPoints(), .getSpacedPoints()
  16196. * .getLength()
  16197. * .updateArcLengths()
  16198. *
  16199. * This following classes subclasses THREE.Curve:
  16200. *
  16201. * -- 2d classes --
  16202. * THREE.LineCurve
  16203. * THREE.QuadraticBezierCurve
  16204. * THREE.CubicBezierCurve
  16205. * THREE.SplineCurve
  16206. * THREE.ArcCurve
  16207. * THREE.EllipseCurve
  16208. *
  16209. * -- 3d classes --
  16210. * THREE.LineCurve3
  16211. * THREE.QuadraticBezierCurve3
  16212. * THREE.CubicBezierCurve3
  16213. * THREE.SplineCurve3
  16214. * THREE.ClosedSplineCurve3
  16215. *
  16216. * A series of curves can be represented as a THREE.CurvePath
  16217. *
  16218. **/
  16219. /**************************************************************
  16220. * Abstract Curve base class
  16221. **************************************************************/
  16222. THREE.Curve = function () {
  16223. };
  16224. // Virtual base class method to overwrite and implement in subclasses
  16225. // - t [0 .. 1]
  16226. THREE.Curve.prototype.getPoint = function ( t ) {
  16227. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  16228. return null;
  16229. };
  16230. // Get point at relative position in curve according to arc length
  16231. // - u [0 .. 1]
  16232. THREE.Curve.prototype.getPointAt = function ( u ) {
  16233. var t = this.getUtoTmapping( u );
  16234. return this.getPoint( t );
  16235. };
  16236. // Get sequence of points using getPoint( t )
  16237. THREE.Curve.prototype.getPoints = function ( divisions ) {
  16238. if ( ! divisions ) divisions = 5;
  16239. var d, pts = [];
  16240. for ( d = 0; d <= divisions; d ++ ) {
  16241. pts.push( this.getPoint( d / divisions ) );
  16242. }
  16243. return pts;
  16244. };
  16245. // Get sequence of points using getPointAt( u )
  16246. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  16247. if ( ! divisions ) divisions = 5;
  16248. var d, pts = [];
  16249. for ( d = 0; d <= divisions; d ++ ) {
  16250. pts.push( this.getPointAt( d / divisions ) );
  16251. }
  16252. return pts;
  16253. };
  16254. // Get total curve arc length
  16255. THREE.Curve.prototype.getLength = function () {
  16256. var lengths = this.getLengths();
  16257. return lengths[ lengths.length - 1 ];
  16258. };
  16259. // Get list of cumulative segment lengths
  16260. THREE.Curve.prototype.getLengths = function ( divisions ) {
  16261. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  16262. if ( this.cacheArcLengths
  16263. && ( this.cacheArcLengths.length === divisions + 1 )
  16264. && ! this.needsUpdate ) {
  16265. //console.log( "cached", this.cacheArcLengths );
  16266. return this.cacheArcLengths;
  16267. }
  16268. this.needsUpdate = false;
  16269. var cache = [];
  16270. var current, last = this.getPoint( 0 );
  16271. var p, sum = 0;
  16272. cache.push( 0 );
  16273. for ( p = 1; p <= divisions; p ++ ) {
  16274. current = this.getPoint ( p / divisions );
  16275. sum += current.distanceTo( last );
  16276. cache.push( sum );
  16277. last = current;
  16278. }
  16279. this.cacheArcLengths = cache;
  16280. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  16281. };
  16282. THREE.Curve.prototype.updateArcLengths = function() {
  16283. this.needsUpdate = true;
  16284. this.getLengths();
  16285. };
  16286. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  16287. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  16288. var arcLengths = this.getLengths();
  16289. var i = 0, il = arcLengths.length;
  16290. var targetArcLength; // The targeted u distance value to get
  16291. if ( distance ) {
  16292. targetArcLength = distance;
  16293. } else {
  16294. targetArcLength = u * arcLengths[ il - 1 ];
  16295. }
  16296. //var time = Date.now();
  16297. // binary search for the index with largest value smaller than target u distance
  16298. var low = 0, high = il - 1, comparison;
  16299. while ( low <= high ) {
  16300. 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
  16301. comparison = arcLengths[ i ] - targetArcLength;
  16302. if ( comparison < 0 ) {
  16303. low = i + 1;
  16304. } else if ( comparison > 0 ) {
  16305. high = i - 1;
  16306. } else {
  16307. high = i;
  16308. break;
  16309. // DONE
  16310. }
  16311. }
  16312. i = high;
  16313. //console.log('b' , i, low, high, Date.now()- time);
  16314. if ( arcLengths[ i ] === targetArcLength ) {
  16315. var t = i / ( il - 1 );
  16316. return t;
  16317. }
  16318. // we could get finer grain at lengths, or use simple interpolation between two points
  16319. var lengthBefore = arcLengths[ i ];
  16320. var lengthAfter = arcLengths[ i + 1 ];
  16321. var segmentLength = lengthAfter - lengthBefore;
  16322. // determine where we are between the 'before' and 'after' points
  16323. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  16324. // add that fractional amount to t
  16325. var t = ( i + segmentFraction ) / ( il - 1 );
  16326. return t;
  16327. };
  16328. // Returns a unit vector tangent at t
  16329. // In case any sub curve does not implement its tangent derivation,
  16330. // 2 points a small delta apart will be used to find its gradient
  16331. // which seems to give a reasonable approximation
  16332. THREE.Curve.prototype.getTangent = function( t ) {
  16333. var delta = 0.0001;
  16334. var t1 = t - delta;
  16335. var t2 = t + delta;
  16336. // Capping in case of danger
  16337. if ( t1 < 0 ) t1 = 0;
  16338. if ( t2 > 1 ) t2 = 1;
  16339. var pt1 = this.getPoint( t1 );
  16340. var pt2 = this.getPoint( t2 );
  16341. var vec = pt2.clone().sub( pt1 );
  16342. return vec.normalize();
  16343. };
  16344. THREE.Curve.prototype.getTangentAt = function ( u ) {
  16345. var t = this.getUtoTmapping( u );
  16346. return this.getTangent( t );
  16347. };
  16348. /**************************************************************
  16349. * Utils
  16350. **************************************************************/
  16351. THREE.Curve.Utils = {
  16352. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  16353. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  16354. },
  16355. // Puay Bing, thanks for helping with this derivative!
  16356. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  16357. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  16358. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  16359. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  16360. 3 * t * t * p3;
  16361. },
  16362. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  16363. // To check if my formulas are correct
  16364. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  16365. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  16366. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  16367. var h11 = 3 * t * t - 2 * t; // t3 − t2
  16368. return h00 + h10 + h01 + h11;
  16369. },
  16370. // Catmull-Rom
  16371. interpolate: function( p0, p1, p2, p3, t ) {
  16372. var v0 = ( p2 - p0 ) * 0.5;
  16373. var v1 = ( p3 - p1 ) * 0.5;
  16374. var t2 = t * t;
  16375. var t3 = t * t2;
  16376. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  16377. }
  16378. };
  16379. // TODO: Transformation for Curves?
  16380. /**************************************************************
  16381. * 3D Curves
  16382. **************************************************************/
  16383. // A Factory method for creating new curve subclasses
  16384. THREE.Curve.create = function ( constructor, getPointFunc ) {
  16385. constructor.prototype = Object.create( THREE.Curve.prototype );
  16386. constructor.prototype.constructor = constructor;
  16387. constructor.prototype.getPoint = getPointFunc;
  16388. return constructor;
  16389. };
  16390. // File:src/extras/core/CurvePath.js
  16391. /**
  16392. * @author zz85 / http://www.lab4games.net/zz85/blog
  16393. *
  16394. **/
  16395. /**************************************************************
  16396. * Curved Path - a curve path is simply a array of connected
  16397. * curves, but retains the api of a curve
  16398. **************************************************************/
  16399. THREE.CurvePath = function () {
  16400. this.curves = [];
  16401. this.bends = [];
  16402. this.autoClose = false; // Automatically closes the path
  16403. };
  16404. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  16405. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  16406. THREE.CurvePath.prototype.add = function ( curve ) {
  16407. this.curves.push( curve );
  16408. };
  16409. THREE.CurvePath.prototype.checkConnection = function() {
  16410. // TODO
  16411. // If the ending of curve is not connected to the starting
  16412. // or the next curve, then, this is not a real path
  16413. };
  16414. THREE.CurvePath.prototype.closePath = function() {
  16415. // TODO Test
  16416. // and verify for vector3 (needs to implement equals)
  16417. // Add a line curve if start and end of lines are not connected
  16418. var startPoint = this.curves[ 0 ].getPoint( 0 );
  16419. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  16420. if ( ! startPoint.equals( endPoint ) ) {
  16421. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  16422. }
  16423. };
  16424. // To get accurate point with reference to
  16425. // entire path distance at time t,
  16426. // following has to be done:
  16427. // 1. Length of each sub path have to be known
  16428. // 2. Locate and identify type of curve
  16429. // 3. Get t for the curve
  16430. // 4. Return curve.getPointAt(t')
  16431. THREE.CurvePath.prototype.getPoint = function( t ) {
  16432. var d = t * this.getLength();
  16433. var curveLengths = this.getCurveLengths();
  16434. var i = 0, diff, curve;
  16435. // To think about boundaries points.
  16436. while ( i < curveLengths.length ) {
  16437. if ( curveLengths[ i ] >= d ) {
  16438. diff = curveLengths[ i ] - d;
  16439. curve = this.curves[ i ];
  16440. var u = 1 - diff / curve.getLength();
  16441. return curve.getPointAt( u );
  16442. }
  16443. i ++;
  16444. }
  16445. return null;
  16446. // loop where sum != 0, sum > d , sum+1 <d
  16447. };
  16448. /*
  16449. THREE.CurvePath.prototype.getTangent = function( t ) {
  16450. };*/
  16451. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  16452. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  16453. // getPoint() depends on getLength
  16454. THREE.CurvePath.prototype.getLength = function() {
  16455. var lens = this.getCurveLengths();
  16456. return lens[ lens.length - 1 ];
  16457. };
  16458. // Compute lengths and cache them
  16459. // We cannot overwrite getLengths() because UtoT mapping uses it.
  16460. THREE.CurvePath.prototype.getCurveLengths = function() {
  16461. // We use cache values if curves and cache array are same length
  16462. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  16463. return this.cacheLengths;
  16464. }
  16465. // Get length of sub-curve
  16466. // Push sums into cached array
  16467. var lengths = [], sums = 0;
  16468. var i, il = this.curves.length;
  16469. for ( i = 0; i < il; i ++ ) {
  16470. sums += this.curves[ i ].getLength();
  16471. lengths.push( sums );
  16472. }
  16473. this.cacheLengths = lengths;
  16474. return lengths;
  16475. };
  16476. // Returns min and max coordinates
  16477. THREE.CurvePath.prototype.getBoundingBox = function () {
  16478. var points = this.getPoints();
  16479. var maxX, maxY, maxZ;
  16480. var minX, minY, minZ;
  16481. maxX = maxY = Number.NEGATIVE_INFINITY;
  16482. minX = minY = Number.POSITIVE_INFINITY;
  16483. var p, i, il, sum;
  16484. var v3 = points[ 0 ] instanceof THREE.Vector3;
  16485. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  16486. for ( i = 0, il = points.length; i < il; i ++ ) {
  16487. p = points[ i ];
  16488. if ( p.x > maxX ) maxX = p.x;
  16489. else if ( p.x < minX ) minX = p.x;
  16490. if ( p.y > maxY ) maxY = p.y;
  16491. else if ( p.y < minY ) minY = p.y;
  16492. if ( v3 ) {
  16493. if ( p.z > maxZ ) maxZ = p.z;
  16494. else if ( p.z < minZ ) minZ = p.z;
  16495. }
  16496. sum.add( p );
  16497. }
  16498. var ret = {
  16499. minX: minX,
  16500. minY: minY,
  16501. maxX: maxX,
  16502. maxY: maxY
  16503. };
  16504. if ( v3 ) {
  16505. ret.maxZ = maxZ;
  16506. ret.minZ = minZ;
  16507. }
  16508. return ret;
  16509. };
  16510. /**************************************************************
  16511. * Create Geometries Helpers
  16512. **************************************************************/
  16513. /// Generate geometry from path points (for Line or Points objects)
  16514. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  16515. var pts = this.getPoints( divisions, true );
  16516. return this.createGeometry( pts );
  16517. };
  16518. // Generate geometry from equidistant sampling along the path
  16519. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  16520. var pts = this.getSpacedPoints( divisions, true );
  16521. return this.createGeometry( pts );
  16522. };
  16523. THREE.CurvePath.prototype.createGeometry = function( points ) {
  16524. var geometry = new THREE.Geometry();
  16525. for ( var i = 0; i < points.length; i ++ ) {
  16526. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0 ) );
  16527. }
  16528. return geometry;
  16529. };
  16530. /**************************************************************
  16531. * Bend / Wrap Helper Methods
  16532. **************************************************************/
  16533. // Wrap path / Bend modifiers?
  16534. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  16535. this.bends.push( bendpath );
  16536. };
  16537. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  16538. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  16539. var i, il;
  16540. if ( ! bends ) {
  16541. bends = this.bends;
  16542. }
  16543. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16544. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16545. }
  16546. return oldPts;
  16547. };
  16548. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  16549. var oldPts = this.getSpacedPoints( segments );
  16550. var i, il;
  16551. if ( ! bends ) {
  16552. bends = this.bends;
  16553. }
  16554. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16555. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16556. }
  16557. return oldPts;
  16558. };
  16559. // This returns getPoints() bend/wrapped around the contour of a path.
  16560. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  16561. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  16562. var bounds = this.getBoundingBox();
  16563. var i, il, p, oldX, oldY, xNorm;
  16564. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  16565. p = oldPts[ i ];
  16566. oldX = p.x;
  16567. oldY = p.y;
  16568. xNorm = oldX / bounds.maxX;
  16569. // If using actual distance, for length > path, requires line extrusions
  16570. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  16571. xNorm = path.getUtoTmapping( xNorm, oldX );
  16572. // check for out of bounds?
  16573. var pathPt = path.getPoint( xNorm );
  16574. var normal = path.getTangent( xNorm );
  16575. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  16576. p.x = pathPt.x + normal.x;
  16577. p.y = pathPt.y + normal.y;
  16578. }
  16579. return oldPts;
  16580. };
  16581. // File:src/extras/core/Path.js
  16582. /**
  16583. * @author zz85 / http://www.lab4games.net/zz85/blog
  16584. * Creates free form 2d path using series of points, lines or curves.
  16585. *
  16586. **/
  16587. THREE.Path = function ( points ) {
  16588. THREE.CurvePath.call( this );
  16589. this.actions = [];
  16590. if ( points ) {
  16591. this.fromPoints( points );
  16592. }
  16593. };
  16594. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  16595. THREE.Path.prototype.constructor = THREE.Path;
  16596. THREE.PathActions = {
  16597. MOVE_TO: 'moveTo',
  16598. LINE_TO: 'lineTo',
  16599. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  16600. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  16601. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  16602. ARC: 'arc', // Circle
  16603. ELLIPSE: 'ellipse'
  16604. };
  16605. // TODO Clean up PATH API
  16606. // Create path using straight lines to connect all points
  16607. // - vectors: array of Vector2
  16608. THREE.Path.prototype.fromPoints = function ( vectors ) {
  16609. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  16610. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  16611. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  16612. }
  16613. };
  16614. // startPath() endPath()?
  16615. THREE.Path.prototype.moveTo = function ( x, y ) {
  16616. var args = Array.prototype.slice.call( arguments );
  16617. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  16618. };
  16619. THREE.Path.prototype.lineTo = function ( x, y ) {
  16620. var args = Array.prototype.slice.call( arguments );
  16621. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16622. var x0 = lastargs[ lastargs.length - 2 ];
  16623. var y0 = lastargs[ lastargs.length - 1 ];
  16624. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  16625. this.curves.push( curve );
  16626. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  16627. };
  16628. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  16629. var args = Array.prototype.slice.call( arguments );
  16630. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16631. var x0 = lastargs[ lastargs.length - 2 ];
  16632. var y0 = lastargs[ lastargs.length - 1 ];
  16633. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  16634. new THREE.Vector2( aCPx, aCPy ),
  16635. new THREE.Vector2( aX, aY ) );
  16636. this.curves.push( curve );
  16637. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  16638. };
  16639. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  16640. aCP2x, aCP2y,
  16641. aX, aY ) {
  16642. var args = Array.prototype.slice.call( arguments );
  16643. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16644. var x0 = lastargs[ lastargs.length - 2 ];
  16645. var y0 = lastargs[ lastargs.length - 1 ];
  16646. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  16647. new THREE.Vector2( aCP1x, aCP1y ),
  16648. new THREE.Vector2( aCP2x, aCP2y ),
  16649. new THREE.Vector2( aX, aY ) );
  16650. this.curves.push( curve );
  16651. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  16652. };
  16653. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  16654. var args = Array.prototype.slice.call( arguments );
  16655. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16656. var x0 = lastargs[ lastargs.length - 2 ];
  16657. var y0 = lastargs[ lastargs.length - 1 ];
  16658. //---
  16659. var npts = [ new THREE.Vector2( x0, y0 ) ];
  16660. Array.prototype.push.apply( npts, pts );
  16661. var curve = new THREE.SplineCurve( npts );
  16662. this.curves.push( curve );
  16663. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  16664. };
  16665. // FUTURE: Change the API or follow canvas API?
  16666. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  16667. aStartAngle, aEndAngle, aClockwise ) {
  16668. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16669. var x0 = lastargs[ lastargs.length - 2 ];
  16670. var y0 = lastargs[ lastargs.length - 1 ];
  16671. this.absarc( aX + x0, aY + y0, aRadius,
  16672. aStartAngle, aEndAngle, aClockwise );
  16673. };
  16674. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  16675. aStartAngle, aEndAngle, aClockwise ) {
  16676. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  16677. };
  16678. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  16679. aStartAngle, aEndAngle, aClockwise ) {
  16680. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16681. var x0 = lastargs[ lastargs.length - 2 ];
  16682. var y0 = lastargs[ lastargs.length - 1 ];
  16683. this.absellipse( aX + x0, aY + y0, xRadius, yRadius,
  16684. aStartAngle, aEndAngle, aClockwise );
  16685. };
  16686. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  16687. aStartAngle, aEndAngle, aClockwise ) {
  16688. var args = Array.prototype.slice.call( arguments );
  16689. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  16690. aStartAngle, aEndAngle, aClockwise );
  16691. this.curves.push( curve );
  16692. var lastPoint = curve.getPoint( 1 );
  16693. args.push( lastPoint.x );
  16694. args.push( lastPoint.y );
  16695. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  16696. };
  16697. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  16698. if ( ! divisions ) divisions = 40;
  16699. var points = [];
  16700. for ( var i = 0; i < divisions; i ++ ) {
  16701. points.push( this.getPoint( i / divisions ) );
  16702. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  16703. }
  16704. // if ( closedPath ) {
  16705. //
  16706. // points.push( points[ 0 ] );
  16707. //
  16708. // }
  16709. return points;
  16710. };
  16711. /* Return an array of vectors based on contour of the path */
  16712. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  16713. if ( this.useSpacedPoints ) {
  16714. return this.getSpacedPoints( divisions, closedPath );
  16715. }
  16716. divisions = divisions || 12;
  16717. var points = [];
  16718. var i, il, item, action, args;
  16719. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  16720. laste, j,
  16721. t, tx, ty;
  16722. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  16723. item = this.actions[ i ];
  16724. action = item.action;
  16725. args = item.args;
  16726. switch ( action ) {
  16727. case THREE.PathActions.MOVE_TO:
  16728. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16729. break;
  16730. case THREE.PathActions.LINE_TO:
  16731. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16732. break;
  16733. case THREE.PathActions.QUADRATIC_CURVE_TO:
  16734. cpx = args[ 2 ];
  16735. cpy = args[ 3 ];
  16736. cpx1 = args[ 0 ];
  16737. cpy1 = args[ 1 ];
  16738. if ( points.length > 0 ) {
  16739. laste = points[ points.length - 1 ];
  16740. cpx0 = laste.x;
  16741. cpy0 = laste.y;
  16742. } else {
  16743. laste = this.actions[ i - 1 ].args;
  16744. cpx0 = laste[ laste.length - 2 ];
  16745. cpy0 = laste[ laste.length - 1 ];
  16746. }
  16747. for ( j = 1; j <= divisions; j ++ ) {
  16748. t = j / divisions;
  16749. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  16750. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  16751. points.push( new THREE.Vector2( tx, ty ) );
  16752. }
  16753. break;
  16754. case THREE.PathActions.BEZIER_CURVE_TO:
  16755. cpx = args[ 4 ];
  16756. cpy = args[ 5 ];
  16757. cpx1 = args[ 0 ];
  16758. cpy1 = args[ 1 ];
  16759. cpx2 = args[ 2 ];
  16760. cpy2 = args[ 3 ];
  16761. if ( points.length > 0 ) {
  16762. laste = points[ points.length - 1 ];
  16763. cpx0 = laste.x;
  16764. cpy0 = laste.y;
  16765. } else {
  16766. laste = this.actions[ i - 1 ].args;
  16767. cpx0 = laste[ laste.length - 2 ];
  16768. cpy0 = laste[ laste.length - 1 ];
  16769. }
  16770. for ( j = 1; j <= divisions; j ++ ) {
  16771. t = j / divisions;
  16772. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  16773. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  16774. points.push( new THREE.Vector2( tx, ty ) );
  16775. }
  16776. break;
  16777. case THREE.PathActions.CSPLINE_THRU:
  16778. laste = this.actions[ i - 1 ].args;
  16779. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  16780. var spts = [ last ];
  16781. var n = divisions * args[ 0 ].length;
  16782. spts = spts.concat( args[ 0 ] );
  16783. var spline = new THREE.SplineCurve( spts );
  16784. for ( j = 1; j <= n; j ++ ) {
  16785. points.push( spline.getPointAt( j / n ) );
  16786. }
  16787. break;
  16788. case THREE.PathActions.ARC:
  16789. var aX = args[ 0 ], aY = args[ 1 ],
  16790. aRadius = args[ 2 ],
  16791. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  16792. aClockwise = !! args[ 5 ];
  16793. var deltaAngle = aEndAngle - aStartAngle;
  16794. var angle;
  16795. var tdivisions = divisions * 2;
  16796. for ( j = 1; j <= tdivisions; j ++ ) {
  16797. t = j / tdivisions;
  16798. if ( ! aClockwise ) {
  16799. t = 1 - t;
  16800. }
  16801. angle = aStartAngle + t * deltaAngle;
  16802. tx = aX + aRadius * Math.cos( angle );
  16803. ty = aY + aRadius * Math.sin( angle );
  16804. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16805. points.push( new THREE.Vector2( tx, ty ) );
  16806. }
  16807. //console.log(points);
  16808. break;
  16809. case THREE.PathActions.ELLIPSE:
  16810. var aX = args[ 0 ], aY = args[ 1 ],
  16811. xRadius = args[ 2 ],
  16812. yRadius = args[ 3 ],
  16813. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  16814. aClockwise = !! args[ 6 ];
  16815. var deltaAngle = aEndAngle - aStartAngle;
  16816. var angle;
  16817. var tdivisions = divisions * 2;
  16818. for ( j = 1; j <= tdivisions; j ++ ) {
  16819. t = j / tdivisions;
  16820. if ( ! aClockwise ) {
  16821. t = 1 - t;
  16822. }
  16823. angle = aStartAngle + t * deltaAngle;
  16824. tx = aX + xRadius * Math.cos( angle );
  16825. ty = aY + yRadius * Math.sin( angle );
  16826. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16827. points.push( new THREE.Vector2( tx, ty ) );
  16828. }
  16829. //console.log(points);
  16830. break;
  16831. } // end switch
  16832. }
  16833. // Normalize to remove the closing point by default.
  16834. var lastPoint = points[ points.length - 1 ];
  16835. var EPSILON = 0.0000000001;
  16836. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < EPSILON &&
  16837. Math.abs( lastPoint.y - points[ 0 ].y ) < EPSILON )
  16838. points.splice( points.length - 1, 1 );
  16839. if ( closedPath ) {
  16840. points.push( points[ 0 ] );
  16841. }
  16842. return points;
  16843. };
  16844. //
  16845. // Breaks path into shapes
  16846. //
  16847. // Assumptions (if parameter isCCW==true the opposite holds):
  16848. // - solid shapes are defined clockwise (CW)
  16849. // - holes are defined counterclockwise (CCW)
  16850. //
  16851. // If parameter noHoles==true:
  16852. // - all subPaths are regarded as solid shapes
  16853. // - definition order CW/CCW has no relevance
  16854. //
  16855. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  16856. function extractSubpaths( inActions ) {
  16857. var i, il, item, action, args;
  16858. var subPaths = [], lastPath = new THREE.Path();
  16859. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  16860. item = inActions[ i ];
  16861. args = item.args;
  16862. action = item.action;
  16863. if ( action === THREE.PathActions.MOVE_TO ) {
  16864. if ( lastPath.actions.length !== 0 ) {
  16865. subPaths.push( lastPath );
  16866. lastPath = new THREE.Path();
  16867. }
  16868. }
  16869. lastPath[ action ].apply( lastPath, args );
  16870. }
  16871. if ( lastPath.actions.length !== 0 ) {
  16872. subPaths.push( lastPath );
  16873. }
  16874. // console.log(subPaths);
  16875. return subPaths;
  16876. }
  16877. function toShapesNoHoles( inSubpaths ) {
  16878. var shapes = [];
  16879. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  16880. var tmpPath = inSubpaths[ i ];
  16881. var tmpShape = new THREE.Shape();
  16882. tmpShape.actions = tmpPath.actions;
  16883. tmpShape.curves = tmpPath.curves;
  16884. shapes.push( tmpShape );
  16885. }
  16886. //console.log("shape", shapes);
  16887. return shapes;
  16888. }
  16889. function isPointInsidePolygon( inPt, inPolygon ) {
  16890. var EPSILON = 0.0000000001;
  16891. var polyLen = inPolygon.length;
  16892. // inPt on polygon contour => immediate success or
  16893. // toggling of inside/outside at every single! intersection point of an edge
  16894. // with the horizontal line through inPt, left of inPt
  16895. // not counting lowerY endpoints of edges and whole edges on that line
  16896. var inside = false;
  16897. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  16898. var edgeLowPt = inPolygon[ p ];
  16899. var edgeHighPt = inPolygon[ q ];
  16900. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  16901. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  16902. if ( Math.abs( edgeDy ) > EPSILON ) {
  16903. // not parallel
  16904. if ( edgeDy < 0 ) {
  16905. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  16906. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  16907. }
  16908. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  16909. if ( inPt.y === edgeLowPt.y ) {
  16910. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  16911. // continue; // no intersection or edgeLowPt => doesn't count !!!
  16912. } else {
  16913. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  16914. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  16915. if ( perpEdge < 0 ) continue;
  16916. inside = ! inside; // true intersection left of inPt
  16917. }
  16918. } else {
  16919. // parallel or collinear
  16920. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  16921. // edge lies on the same horizontal line as inPt
  16922. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  16923. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  16924. // continue;
  16925. }
  16926. }
  16927. return inside;
  16928. }
  16929. var subPaths = extractSubpaths( this.actions );
  16930. if ( subPaths.length === 0 ) return [];
  16931. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  16932. var solid, tmpPath, tmpShape, shapes = [];
  16933. if ( subPaths.length === 1 ) {
  16934. tmpPath = subPaths[ 0 ];
  16935. tmpShape = new THREE.Shape();
  16936. tmpShape.actions = tmpPath.actions;
  16937. tmpShape.curves = tmpPath.curves;
  16938. shapes.push( tmpShape );
  16939. return shapes;
  16940. }
  16941. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  16942. holesFirst = isCCW ? ! holesFirst : holesFirst;
  16943. // console.log("Holes first", holesFirst);
  16944. var betterShapeHoles = [];
  16945. var newShapes = [];
  16946. var newShapeHoles = [];
  16947. var mainIdx = 0;
  16948. var tmpPoints;
  16949. newShapes[ mainIdx ] = undefined;
  16950. newShapeHoles[ mainIdx ] = [];
  16951. var i, il;
  16952. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  16953. tmpPath = subPaths[ i ];
  16954. tmpPoints = tmpPath.getPoints();
  16955. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  16956. solid = isCCW ? ! solid : solid;
  16957. if ( solid ) {
  16958. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  16959. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  16960. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  16961. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  16962. if ( holesFirst ) mainIdx ++;
  16963. newShapeHoles[ mainIdx ] = [];
  16964. //console.log('cw', i);
  16965. } else {
  16966. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  16967. //console.log('ccw', i);
  16968. }
  16969. }
  16970. // only Holes? -> probably all Shapes with wrong orientation
  16971. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  16972. if ( newShapes.length > 1 ) {
  16973. var ambiguous = false;
  16974. var toChange = [];
  16975. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  16976. betterShapeHoles[ sIdx ] = [];
  16977. }
  16978. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  16979. var sho = newShapeHoles[ sIdx ];
  16980. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  16981. var ho = sho[ hIdx ];
  16982. var hole_unassigned = true;
  16983. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  16984. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  16985. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  16986. if ( hole_unassigned ) {
  16987. hole_unassigned = false;
  16988. betterShapeHoles[ s2Idx ].push( ho );
  16989. } else {
  16990. ambiguous = true;
  16991. }
  16992. }
  16993. }
  16994. if ( hole_unassigned ) {
  16995. betterShapeHoles[ sIdx ].push( ho );
  16996. }
  16997. }
  16998. }
  16999. // console.log("ambiguous: ", ambiguous);
  17000. if ( toChange.length > 0 ) {
  17001. // console.log("to change: ", toChange);
  17002. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  17003. }
  17004. }
  17005. var tmpHoles, j, jl;
  17006. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  17007. tmpShape = newShapes[ i ].s;
  17008. shapes.push( tmpShape );
  17009. tmpHoles = newShapeHoles[ i ];
  17010. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  17011. tmpShape.holes.push( tmpHoles[ j ].h );
  17012. }
  17013. }
  17014. //console.log("shape", shapes);
  17015. return shapes;
  17016. };
  17017. // File:src/extras/core/Shape.js
  17018. /**
  17019. * @author zz85 / http://www.lab4games.net/zz85/blog
  17020. * Defines a 2d shape plane using paths.
  17021. **/
  17022. // STEP 1 Create a path.
  17023. // STEP 2 Turn path into shape.
  17024. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  17025. // STEP 3a - Extract points from each shape, turn to vertices
  17026. // STEP 3b - Triangulate each shape, add faces.
  17027. THREE.Shape = function () {
  17028. THREE.Path.apply( this, arguments );
  17029. this.holes = [];
  17030. };
  17031. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  17032. THREE.Shape.prototype.constructor = THREE.Shape;
  17033. // Convenience method to return ExtrudeGeometry
  17034. THREE.Shape.prototype.extrude = function ( options ) {
  17035. var extruded = new THREE.ExtrudeGeometry( this, options );
  17036. return extruded;
  17037. };
  17038. // Convenience method to return ShapeGeometry
  17039. THREE.Shape.prototype.makeGeometry = function ( options ) {
  17040. var geometry = new THREE.ShapeGeometry( this, options );
  17041. return geometry;
  17042. };
  17043. // Get points of holes
  17044. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  17045. var i, il = this.holes.length, holesPts = [];
  17046. for ( i = 0; i < il; i ++ ) {
  17047. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  17048. }
  17049. return holesPts;
  17050. };
  17051. // Get points of holes (spaced by regular distance)
  17052. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  17053. var i, il = this.holes.length, holesPts = [];
  17054. for ( i = 0; i < il; i ++ ) {
  17055. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  17056. }
  17057. return holesPts;
  17058. };
  17059. // Get points of shape and holes (keypoints based on segments parameter)
  17060. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  17061. return {
  17062. shape: this.getTransformedPoints( divisions ),
  17063. holes: this.getPointsHoles( divisions )
  17064. };
  17065. };
  17066. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  17067. if ( this.useSpacedPoints ) {
  17068. return this.extractAllSpacedPoints( divisions );
  17069. }
  17070. return this.extractAllPoints( divisions );
  17071. };
  17072. //
  17073. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  17074. //
  17075. // return {
  17076. //
  17077. // shape: this.transform( bend, divisions ),
  17078. // holes: this.getPointsHoles( divisions, bend )
  17079. //
  17080. // };
  17081. //
  17082. // };
  17083. // Get points of shape and holes (spaced by regular distance)
  17084. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  17085. return {
  17086. shape: this.getTransformedSpacedPoints( divisions ),
  17087. holes: this.getSpacedPointsHoles( divisions )
  17088. };
  17089. };
  17090. /**************************************************************
  17091. * Utils
  17092. **************************************************************/
  17093. THREE.Shape.Utils = {
  17094. triangulateShape: function ( contour, holes ) {
  17095. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  17096. // inOtherPt needs to be collinear to the inSegment
  17097. if ( inSegPt1.x !== inSegPt2.x ) {
  17098. if ( inSegPt1.x < inSegPt2.x ) {
  17099. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  17100. } else {
  17101. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  17102. }
  17103. } else {
  17104. if ( inSegPt1.y < inSegPt2.y ) {
  17105. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  17106. } else {
  17107. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  17108. }
  17109. }
  17110. }
  17111. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  17112. var EPSILON = 0.0000000001;
  17113. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  17114. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  17115. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  17116. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  17117. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  17118. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  17119. if ( Math.abs( limit ) > EPSILON ) {
  17120. // not parallel
  17121. var perpSeg2;
  17122. if ( limit > 0 ) {
  17123. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  17124. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17125. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  17126. } else {
  17127. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  17128. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17129. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  17130. }
  17131. // i.e. to reduce rounding errors
  17132. // intersection at endpoint of segment#1?
  17133. if ( perpSeg2 === 0 ) {
  17134. if ( ( inExcludeAdjacentSegs ) &&
  17135. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17136. return [ inSeg1Pt1 ];
  17137. }
  17138. if ( perpSeg2 === limit ) {
  17139. if ( ( inExcludeAdjacentSegs ) &&
  17140. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17141. return [ inSeg1Pt2 ];
  17142. }
  17143. // intersection at endpoint of segment#2?
  17144. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  17145. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  17146. // return real intersection point
  17147. var factorSeg1 = perpSeg2 / limit;
  17148. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  17149. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  17150. } else {
  17151. // parallel or collinear
  17152. if ( ( perpSeg1 !== 0 ) ||
  17153. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  17154. // they are collinear or degenerate
  17155. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  17156. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  17157. // both segments are points
  17158. if ( seg1Pt && seg2Pt ) {
  17159. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  17160. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  17161. return [ inSeg1Pt1 ]; // they are the same point
  17162. }
  17163. // segment#1 is a single point
  17164. if ( seg1Pt ) {
  17165. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  17166. return [ inSeg1Pt1 ];
  17167. }
  17168. // segment#2 is a single point
  17169. if ( seg2Pt ) {
  17170. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  17171. return [ inSeg2Pt1 ];
  17172. }
  17173. // they are collinear segments, which might overlap
  17174. var seg1min, seg1max, seg1minVal, seg1maxVal;
  17175. var seg2min, seg2max, seg2minVal, seg2maxVal;
  17176. if ( seg1dx !== 0 ) {
  17177. // the segments are NOT on a vertical line
  17178. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  17179. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  17180. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  17181. } else {
  17182. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  17183. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  17184. }
  17185. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  17186. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  17187. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  17188. } else {
  17189. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  17190. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  17191. }
  17192. } else {
  17193. // the segments are on a vertical line
  17194. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  17195. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  17196. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  17197. } else {
  17198. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  17199. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  17200. }
  17201. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  17202. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  17203. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  17204. } else {
  17205. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  17206. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  17207. }
  17208. }
  17209. if ( seg1minVal <= seg2minVal ) {
  17210. if ( seg1maxVal < seg2minVal ) return [];
  17211. if ( seg1maxVal === seg2minVal ) {
  17212. if ( inExcludeAdjacentSegs ) return [];
  17213. return [ seg2min ];
  17214. }
  17215. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  17216. return [ seg2min, seg2max ];
  17217. } else {
  17218. if ( seg1minVal > seg2maxVal ) return [];
  17219. if ( seg1minVal === seg2maxVal ) {
  17220. if ( inExcludeAdjacentSegs ) return [];
  17221. return [ seg1min ];
  17222. }
  17223. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  17224. return [ seg1min, seg2max ];
  17225. }
  17226. }
  17227. }
  17228. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  17229. // The order of legs is important
  17230. var EPSILON = 0.0000000001;
  17231. // translation of all points, so that Vertex is at (0,0)
  17232. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  17233. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  17234. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  17235. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  17236. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  17237. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  17238. if ( Math.abs( from2toAngle ) > EPSILON ) {
  17239. // angle != 180 deg.
  17240. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  17241. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  17242. if ( from2toAngle > 0 ) {
  17243. // main angle < 180 deg.
  17244. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  17245. } else {
  17246. // main angle > 180 deg.
  17247. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  17248. }
  17249. } else {
  17250. // angle == 180 deg.
  17251. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  17252. return ( from2otherAngle > 0 );
  17253. }
  17254. }
  17255. function removeHoles( contour, holes ) {
  17256. var shape = contour.concat(); // work on this shape
  17257. var hole;
  17258. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  17259. // Check if hole point lies within angle around shape point
  17260. var lastShapeIdx = shape.length - 1;
  17261. var prevShapeIdx = inShapeIdx - 1;
  17262. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  17263. var nextShapeIdx = inShapeIdx + 1;
  17264. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  17265. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  17266. if ( ! insideAngle ) {
  17267. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  17268. return false;
  17269. }
  17270. // Check if shape point lies within angle around hole point
  17271. var lastHoleIdx = hole.length - 1;
  17272. var prevHoleIdx = inHoleIdx - 1;
  17273. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  17274. var nextHoleIdx = inHoleIdx + 1;
  17275. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  17276. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  17277. if ( ! insideAngle ) {
  17278. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  17279. return false;
  17280. }
  17281. return true;
  17282. }
  17283. function intersectsShapeEdge( inShapePt, inHolePt ) {
  17284. // checks for intersections with shape edges
  17285. var sIdx, nextIdx, intersection;
  17286. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  17287. nextIdx = sIdx + 1; nextIdx %= shape.length;
  17288. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  17289. if ( intersection.length > 0 ) return true;
  17290. }
  17291. return false;
  17292. }
  17293. var indepHoles = [];
  17294. function intersectsHoleEdge( inShapePt, inHolePt ) {
  17295. // checks for intersections with hole edges
  17296. var ihIdx, chkHole,
  17297. hIdx, nextIdx, intersection;
  17298. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  17299. chkHole = holes[ indepHoles[ ihIdx ]];
  17300. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  17301. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  17302. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  17303. if ( intersection.length > 0 ) return true;
  17304. }
  17305. }
  17306. return false;
  17307. }
  17308. var holeIndex, shapeIndex,
  17309. shapePt, holePt,
  17310. holeIdx, cutKey, failedCuts = [],
  17311. tmpShape1, tmpShape2,
  17312. tmpHole1, tmpHole2;
  17313. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17314. indepHoles.push( h );
  17315. }
  17316. var minShapeIndex = 0;
  17317. var counter = indepHoles.length * 2;
  17318. while ( indepHoles.length > 0 ) {
  17319. counter --;
  17320. if ( counter < 0 ) {
  17321. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  17322. break;
  17323. }
  17324. // search for shape-vertex and hole-vertex,
  17325. // which can be connected without intersections
  17326. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  17327. shapePt = shape[ shapeIndex ];
  17328. holeIndex = - 1;
  17329. // search for hole which can be reached without intersections
  17330. for ( var h = 0; h < indepHoles.length; h ++ ) {
  17331. holeIdx = indepHoles[ h ];
  17332. // prevent multiple checks
  17333. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  17334. if ( failedCuts[ cutKey ] !== undefined ) continue;
  17335. hole = holes[ holeIdx ];
  17336. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  17337. holePt = hole[ h2 ];
  17338. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  17339. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17340. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17341. holeIndex = h2;
  17342. indepHoles.splice( h, 1 );
  17343. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17344. tmpShape2 = shape.slice( shapeIndex );
  17345. tmpHole1 = hole.slice( holeIndex );
  17346. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17347. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17348. minShapeIndex = shapeIndex;
  17349. // Debug only, to show the selected cuts
  17350. // glob_CutLines.push( [ shapePt, holePt ] );
  17351. break;
  17352. }
  17353. if ( holeIndex >= 0 ) break; // hole-vertex found
  17354. failedCuts[ cutKey ] = true; // remember failure
  17355. }
  17356. if ( holeIndex >= 0 ) break; // hole-vertex found
  17357. }
  17358. }
  17359. return shape; /* shape with no holes */
  17360. }
  17361. var i, il, f, face,
  17362. key, index,
  17363. allPointsMap = {};
  17364. // 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.
  17365. var allpoints = contour.concat();
  17366. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17367. Array.prototype.push.apply( allpoints, holes[ h ] );
  17368. }
  17369. //console.log( "allpoints",allpoints, allpoints.length );
  17370. // prepare all points map
  17371. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17372. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  17373. if ( allPointsMap[ key ] !== undefined ) {
  17374. console.warn( "THREE.Shape: Duplicate point", key );
  17375. }
  17376. allPointsMap[ key ] = i;
  17377. }
  17378. // remove holes by cutting paths to holes and adding them to the shape
  17379. var shapeWithoutHoles = removeHoles( contour, holes );
  17380. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17381. //console.log( "triangles",triangles, triangles.length );
  17382. // check all face vertices against all points map
  17383. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17384. face = triangles[ i ];
  17385. for ( f = 0; f < 3; f ++ ) {
  17386. key = face[ f ].x + ":" + face[ f ].y;
  17387. index = allPointsMap[ key ];
  17388. if ( index !== undefined ) {
  17389. face[ f ] = index;
  17390. }
  17391. }
  17392. }
  17393. return triangles.concat();
  17394. },
  17395. isClockWise: function ( pts ) {
  17396. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  17397. },
  17398. // Bezier Curves formulas obtained from
  17399. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  17400. // Quad Bezier Functions
  17401. b2p0: function ( t, p ) {
  17402. var k = 1 - t;
  17403. return k * k * p;
  17404. },
  17405. b2p1: function ( t, p ) {
  17406. return 2 * ( 1 - t ) * t * p;
  17407. },
  17408. b2p2: function ( t, p ) {
  17409. return t * t * p;
  17410. },
  17411. b2: function ( t, p0, p1, p2 ) {
  17412. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  17413. },
  17414. // Cubic Bezier Functions
  17415. b3p0: function ( t, p ) {
  17416. var k = 1 - t;
  17417. return k * k * k * p;
  17418. },
  17419. b3p1: function ( t, p ) {
  17420. var k = 1 - t;
  17421. return 3 * k * k * t * p;
  17422. },
  17423. b3p2: function ( t, p ) {
  17424. var k = 1 - t;
  17425. return 3 * k * t * t * p;
  17426. },
  17427. b3p3: function ( t, p ) {
  17428. return t * t * t * p;
  17429. },
  17430. b3: function ( t, p0, p1, p2, p3 ) {
  17431. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  17432. }
  17433. };
  17434. // File:src/extras/curves/LineCurve.js
  17435. /**************************************************************
  17436. * Line
  17437. **************************************************************/
  17438. THREE.LineCurve = function ( v1, v2 ) {
  17439. this.v1 = v1;
  17440. this.v2 = v2;
  17441. };
  17442. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  17443. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  17444. THREE.LineCurve.prototype.getPoint = function ( t ) {
  17445. var point = this.v2.clone().sub( this.v1 );
  17446. point.multiplyScalar( t ).add( this.v1 );
  17447. return point;
  17448. };
  17449. // Line curve is linear, so we can overwrite default getPointAt
  17450. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  17451. return this.getPoint( u );
  17452. };
  17453. THREE.LineCurve.prototype.getTangent = function( t ) {
  17454. var tangent = this.v2.clone().sub( this.v1 );
  17455. return tangent.normalize();
  17456. };
  17457. // File:src/extras/curves/QuadraticBezierCurve.js
  17458. /**************************************************************
  17459. * Quadratic Bezier curve
  17460. **************************************************************/
  17461. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  17462. this.v0 = v0;
  17463. this.v1 = v1;
  17464. this.v2 = v2;
  17465. };
  17466. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17467. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  17468. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  17469. var vector = new THREE.Vector2();
  17470. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17471. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17472. return vector;
  17473. };
  17474. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  17475. var vector = new THREE.Vector2();
  17476. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  17477. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  17478. // returns unit vector
  17479. return vector.normalize();
  17480. };
  17481. // File:src/extras/curves/CubicBezierCurve.js
  17482. /**************************************************************
  17483. * Cubic Bezier curve
  17484. **************************************************************/
  17485. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  17486. this.v0 = v0;
  17487. this.v1 = v1;
  17488. this.v2 = v2;
  17489. this.v3 = v3;
  17490. };
  17491. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17492. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  17493. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  17494. var tx, ty;
  17495. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17496. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17497. return new THREE.Vector2( tx, ty );
  17498. };
  17499. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  17500. var tx, ty;
  17501. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17502. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17503. var tangent = new THREE.Vector2( tx, ty );
  17504. tangent.normalize();
  17505. return tangent;
  17506. };
  17507. // File:src/extras/curves/SplineCurve.js
  17508. /**************************************************************
  17509. * Spline curve
  17510. **************************************************************/
  17511. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  17512. this.points = ( points == undefined ) ? [] : points;
  17513. };
  17514. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  17515. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  17516. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  17517. var points = this.points;
  17518. var point = ( points.length - 1 ) * t;
  17519. var intPoint = Math.floor( point );
  17520. var weight = point - intPoint;
  17521. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  17522. var point1 = points[ intPoint ];
  17523. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17524. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17525. var vector = new THREE.Vector2();
  17526. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17527. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17528. return vector;
  17529. };
  17530. // File:src/extras/curves/EllipseCurve.js
  17531. /**************************************************************
  17532. * Ellipse curve
  17533. **************************************************************/
  17534. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise ) {
  17535. this.aX = aX;
  17536. this.aY = aY;
  17537. this.xRadius = xRadius;
  17538. this.yRadius = yRadius;
  17539. this.aStartAngle = aStartAngle;
  17540. this.aEndAngle = aEndAngle;
  17541. this.aClockwise = aClockwise;
  17542. };
  17543. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  17544. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  17545. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  17546. var deltaAngle = this.aEndAngle - this.aStartAngle;
  17547. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  17548. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  17549. var angle;
  17550. if ( this.aClockwise === true ) {
  17551. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  17552. } else {
  17553. angle = this.aStartAngle + t * deltaAngle;
  17554. }
  17555. var vector = new THREE.Vector2();
  17556. vector.x = this.aX + this.xRadius * Math.cos( angle );
  17557. vector.y = this.aY + this.yRadius * Math.sin( angle );
  17558. return vector;
  17559. };
  17560. // File:src/extras/curves/ArcCurve.js
  17561. /**************************************************************
  17562. * Arc curve
  17563. **************************************************************/
  17564. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17565. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17566. };
  17567. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  17568. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  17569. // File:src/extras/curves/LineCurve3.js
  17570. /**************************************************************
  17571. * Line3D
  17572. **************************************************************/
  17573. THREE.LineCurve3 = THREE.Curve.create(
  17574. function ( v1, v2 ) {
  17575. this.v1 = v1;
  17576. this.v2 = v2;
  17577. },
  17578. function ( t ) {
  17579. var vector = new THREE.Vector3();
  17580. vector.subVectors( this.v2, this.v1 ); // diff
  17581. vector.multiplyScalar( t );
  17582. vector.add( this.v1 );
  17583. return vector;
  17584. }
  17585. );
  17586. // File:src/extras/curves/QuadraticBezierCurve3.js
  17587. /**************************************************************
  17588. * Quadratic Bezier 3D curve
  17589. **************************************************************/
  17590. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  17591. function ( v0, v1, v2 ) {
  17592. this.v0 = v0;
  17593. this.v1 = v1;
  17594. this.v2 = v2;
  17595. },
  17596. function ( t ) {
  17597. var vector = new THREE.Vector3();
  17598. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17599. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17600. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  17601. return vector;
  17602. }
  17603. );
  17604. // File:src/extras/curves/CubicBezierCurve3.js
  17605. /**************************************************************
  17606. * Cubic Bezier 3D curve
  17607. **************************************************************/
  17608. THREE.CubicBezierCurve3 = THREE.Curve.create(
  17609. function ( v0, v1, v2, v3 ) {
  17610. this.v0 = v0;
  17611. this.v1 = v1;
  17612. this.v2 = v2;
  17613. this.v3 = v3;
  17614. },
  17615. function ( t ) {
  17616. var vector = new THREE.Vector3();
  17617. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17618. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17619. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  17620. return vector;
  17621. }
  17622. );
  17623. // File:src/extras/curves/SplineCurve3.js
  17624. /**************************************************************
  17625. * Spline 3D curve
  17626. **************************************************************/
  17627. THREE.SplineCurve3 = THREE.Curve.create(
  17628. function ( points /* array of Vector3 */ ) {
  17629. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  17630. this.points = ( points == undefined ) ? [] : points;
  17631. },
  17632. function ( t ) {
  17633. var points = this.points;
  17634. var point = ( points.length - 1 ) * t;
  17635. var intPoint = Math.floor( point );
  17636. var weight = point - intPoint;
  17637. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  17638. var point1 = points[ intPoint ];
  17639. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17640. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17641. var vector = new THREE.Vector3();
  17642. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17643. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17644. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17645. return vector;
  17646. }
  17647. );
  17648. // File:src/extras/curves/CatmullRomCurve3.js
  17649. /**
  17650. * @author zz85 https://github.com/zz85
  17651. *
  17652. * Centripetal CatmullRom Curve - which is useful for avoiding
  17653. * cusps and self-intersections in non-uniform catmull rom curves.
  17654. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  17655. *
  17656. * curve.type accepts centripetal(default), chordal and catmullrom
  17657. * curve.tension is used for catmullrom which defaults to 0.5
  17658. */
  17659. THREE.CatmullRomCurve3 = ( function() {
  17660. var
  17661. tmp = new THREE.Vector3(),
  17662. px = new CubicPoly(),
  17663. py = new CubicPoly(),
  17664. pz = new CubicPoly();
  17665. /*
  17666. Based on an optimized c++ solution in
  17667. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  17668. - http://ideone.com/NoEbVM
  17669. This CubicPoly class could be used for reusing some variables and calculations,
  17670. but for three.js curve use, it could be possible inlined and flatten into a single function call
  17671. which can be placed in CurveUtils.
  17672. */
  17673. function CubicPoly() {
  17674. }
  17675. /*
  17676. * Compute coefficients for a cubic polynomial
  17677. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  17678. * such that
  17679. * p(0) = x0, p(1) = x1
  17680. * and
  17681. * p'(0) = t0, p'(1) = t1.
  17682. */
  17683. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  17684. this.c0 = x0;
  17685. this.c1 = t0;
  17686. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  17687. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  17688. };
  17689. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  17690. // compute tangents when parameterized in [t1,t2]
  17691. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  17692. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  17693. // rescale tangents for parametrization in [0,1]
  17694. t1 *= dt1;
  17695. t2 *= dt1;
  17696. // initCubicPoly
  17697. this.init( x1, x2, t1, t2 );
  17698. };
  17699. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  17700. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  17701. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  17702. };
  17703. CubicPoly.prototype.calc = function( t ) {
  17704. var t2 = t * t;
  17705. var t3 = t2 * t;
  17706. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  17707. };
  17708. // Subclass Three.js curve
  17709. return THREE.Curve.create(
  17710. function ( p /* array of Vector3 */ ) {
  17711. this.points = p || [];
  17712. },
  17713. function ( t ) {
  17714. var points = this.points,
  17715. point, intPoint, weight, l;
  17716. l = points.length;
  17717. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  17718. point = ( l - 1 ) * t;
  17719. intPoint = Math.floor( point );
  17720. weight = point - intPoint;
  17721. if ( weight === 0 && intPoint === l - 1 ) {
  17722. intPoint = l - 2;
  17723. weight = 1;
  17724. }
  17725. var p0, p1, p2, p3;
  17726. if ( intPoint === 0 ) {
  17727. // extrapolate first point
  17728. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  17729. p0 = tmp;
  17730. } else {
  17731. p0 = points[ intPoint - 1 ];
  17732. }
  17733. p1 = points[ intPoint ];
  17734. p2 = points[ intPoint + 1 ];
  17735. if ( intPoint + 2 < l ) {
  17736. p3 = points[ intPoint + 2 ]
  17737. } else {
  17738. // extrapolate last point
  17739. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  17740. p3 = tmp;
  17741. }
  17742. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  17743. // init Centripetal / Chordal Catmull-Rom
  17744. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  17745. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  17746. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  17747. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  17748. // safety check for repeated points
  17749. if ( dt1 < 1e-4 ) dt1 = 1.0;
  17750. if ( dt0 < 1e-4 ) dt0 = dt1;
  17751. if ( dt2 < 1e-4 ) dt2 = dt1;
  17752. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  17753. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  17754. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  17755. } else if ( this.type === 'catmullrom' ) {
  17756. var tension = this.tension !== undefined ? this.tension : 0.5;
  17757. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  17758. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  17759. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  17760. }
  17761. var v = new THREE.Vector3(
  17762. px.calc( weight ),
  17763. py.calc( weight ),
  17764. pz.calc( weight )
  17765. );
  17766. return v;
  17767. }
  17768. );
  17769. } )();
  17770. // File:src/extras/curves/ClosedSplineCurve3.js
  17771. /**************************************************************
  17772. * Closed Spline 3D curve
  17773. **************************************************************/
  17774. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  17775. function ( points /* array of Vector3 */ ) {
  17776. this.points = ( points == undefined ) ? [] : points;
  17777. },
  17778. function ( t ) {
  17779. var points = this.points;
  17780. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  17781. var intPoint = Math.floor( point );
  17782. var weight = point - intPoint;
  17783. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  17784. var point0 = points[ ( intPoint - 1 ) % points.length ];
  17785. var point1 = points[ ( intPoint ) % points.length ];
  17786. var point2 = points[ ( intPoint + 1 ) % points.length ];
  17787. var point3 = points[ ( intPoint + 2 ) % points.length ];
  17788. var vector = new THREE.Vector3();
  17789. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17790. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17791. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17792. return vector;
  17793. }
  17794. );
  17795. // File:src/extras/animation/AnimationHandler.js
  17796. /**
  17797. * @author mikael emtinger / http://gomo.se/
  17798. */
  17799. THREE.AnimationHandler = {
  17800. LINEAR: 0,
  17801. CATMULLROM: 1,
  17802. CATMULLROM_FORWARD: 2,
  17803. //
  17804. add: function () {
  17805. console.warn( 'THREE.AnimationHandler.add() has been deprecated.' );
  17806. },
  17807. get: function () {
  17808. console.warn( 'THREE.AnimationHandler.get() has been deprecated.' );
  17809. },
  17810. remove: function () {
  17811. console.warn( 'THREE.AnimationHandler.remove() has been deprecated.' );
  17812. },
  17813. //
  17814. animations: [],
  17815. init: function ( data ) {
  17816. if ( data.initialized === true ) return data;
  17817. // loop through all keys
  17818. for ( var h = 0; h < data.hierarchy.length; h ++ ) {
  17819. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17820. // remove minus times
  17821. if ( data.hierarchy[ h ].keys[ k ].time < 0 ) {
  17822. data.hierarchy[ h ].keys[ k ].time = 0;
  17823. }
  17824. // create quaternions
  17825. if ( data.hierarchy[ h ].keys[ k ].rot !== undefined &&
  17826. ! ( data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion ) ) {
  17827. var quat = data.hierarchy[ h ].keys[ k ].rot;
  17828. data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion().fromArray( quat );
  17829. }
  17830. }
  17831. // prepare morph target keys
  17832. if ( data.hierarchy[ h ].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
  17833. // get all used
  17834. var usedMorphTargets = {};
  17835. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17836. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17837. var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
  17838. usedMorphTargets[ morphTargetName ] = - 1;
  17839. }
  17840. }
  17841. data.hierarchy[ h ].usedMorphTargets = usedMorphTargets;
  17842. // set all used on all frames
  17843. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17844. var influences = {};
  17845. for ( var morphTargetName in usedMorphTargets ) {
  17846. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17847. if ( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
  17848. influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
  17849. break;
  17850. }
  17851. }
  17852. if ( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
  17853. influences[ morphTargetName ] = 0;
  17854. }
  17855. }
  17856. data.hierarchy[ h ].keys[ k ].morphTargetsInfluences = influences;
  17857. }
  17858. }
  17859. // remove all keys that are on the same time
  17860. for ( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17861. if ( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
  17862. data.hierarchy[ h ].keys.splice( k, 1 );
  17863. k --;
  17864. }
  17865. }
  17866. // set index
  17867. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17868. data.hierarchy[ h ].keys[ k ].index = k;
  17869. }
  17870. }
  17871. data.initialized = true;
  17872. return data;
  17873. },
  17874. parse: function ( root ) {
  17875. var parseRecurseHierarchy = function ( root, hierarchy ) {
  17876. hierarchy.push( root );
  17877. for ( var c = 0; c < root.children.length; c ++ )
  17878. parseRecurseHierarchy( root.children[ c ], hierarchy );
  17879. };
  17880. // setup hierarchy
  17881. var hierarchy = [];
  17882. if ( root instanceof THREE.SkinnedMesh ) {
  17883. for ( var b = 0; b < root.skeleton.bones.length; b ++ ) {
  17884. hierarchy.push( root.skeleton.bones[ b ] );
  17885. }
  17886. } else {
  17887. parseRecurseHierarchy( root, hierarchy );
  17888. }
  17889. return hierarchy;
  17890. },
  17891. play: function ( animation ) {
  17892. if ( this.animations.indexOf( animation ) === - 1 ) {
  17893. this.animations.push( animation );
  17894. }
  17895. },
  17896. stop: function ( animation ) {
  17897. var index = this.animations.indexOf( animation );
  17898. if ( index !== - 1 ) {
  17899. this.animations.splice( index, 1 );
  17900. }
  17901. },
  17902. update: function ( deltaTimeMS ) {
  17903. for ( var i = 0; i < this.animations.length; i ++ ) {
  17904. this.animations[ i ].resetBlendWeights( );
  17905. }
  17906. for ( var i = 0; i < this.animations.length; i ++ ) {
  17907. this.animations[ i ].update( deltaTimeMS );
  17908. }
  17909. }
  17910. };
  17911. // File:src/extras/animation/Animation.js
  17912. /**
  17913. * @author mikael emtinger / http://gomo.se/
  17914. * @author mrdoob / http://mrdoob.com/
  17915. * @author alteredq / http://alteredqualia.com/
  17916. */
  17917. THREE.Animation = function ( root, data ) {
  17918. this.root = root;
  17919. this.data = THREE.AnimationHandler.init( data );
  17920. this.hierarchy = THREE.AnimationHandler.parse( root );
  17921. this.currentTime = 0;
  17922. this.timeScale = 1;
  17923. this.isPlaying = false;
  17924. this.loop = true;
  17925. this.weight = 0;
  17926. this.interpolationType = THREE.AnimationHandler.LINEAR;
  17927. };
  17928. THREE.Animation.prototype = {
  17929. constructor: THREE.Animation,
  17930. keyTypes: [ "pos", "rot", "scl" ],
  17931. play: function ( startTime, weight ) {
  17932. this.currentTime = startTime !== undefined ? startTime : 0;
  17933. this.weight = weight !== undefined ? weight : 1;
  17934. this.isPlaying = true;
  17935. this.reset();
  17936. THREE.AnimationHandler.play( this );
  17937. },
  17938. stop: function() {
  17939. this.isPlaying = false;
  17940. THREE.AnimationHandler.stop( this );
  17941. },
  17942. reset: function () {
  17943. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17944. var object = this.hierarchy[ h ];
  17945. if ( object.animationCache === undefined ) {
  17946. object.animationCache = {
  17947. animations: {},
  17948. blending: {
  17949. positionWeight: 0.0,
  17950. quaternionWeight: 0.0,
  17951. scaleWeight: 0.0
  17952. }
  17953. };
  17954. }
  17955. var name = this.data.name;
  17956. var animations = object.animationCache.animations;
  17957. var animationCache = animations[ name ];
  17958. if ( animationCache === undefined ) {
  17959. animationCache = {
  17960. prevKey: { pos: 0, rot: 0, scl: 0 },
  17961. nextKey: { pos: 0, rot: 0, scl: 0 },
  17962. originalMatrix: object.matrix
  17963. };
  17964. animations[ name ] = animationCache;
  17965. }
  17966. // Get keys to match our current time
  17967. for ( var t = 0; t < 3; t ++ ) {
  17968. var type = this.keyTypes[ t ];
  17969. var prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  17970. var nextKey = this.getNextKeyWith( type, h, 1 );
  17971. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  17972. prevKey = nextKey;
  17973. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  17974. }
  17975. animationCache.prevKey[ type ] = prevKey;
  17976. animationCache.nextKey[ type ] = nextKey;
  17977. }
  17978. }
  17979. },
  17980. resetBlendWeights: function () {
  17981. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17982. var object = this.hierarchy[ h ];
  17983. var animationCache = object.animationCache;
  17984. if ( animationCache !== undefined ) {
  17985. var blending = animationCache.blending;
  17986. blending.positionWeight = 0.0;
  17987. blending.quaternionWeight = 0.0;
  17988. blending.scaleWeight = 0.0;
  17989. }
  17990. }
  17991. },
  17992. update: ( function() {
  17993. var points = [];
  17994. var target = new THREE.Vector3();
  17995. var newVector = new THREE.Vector3();
  17996. var newQuat = new THREE.Quaternion();
  17997. // Catmull-Rom spline
  17998. var interpolateCatmullRom = function ( points, scale ) {
  17999. var c = [], v3 = [],
  18000. point, intPoint, weight, w2, w3,
  18001. pa, pb, pc, pd;
  18002. point = ( points.length - 1 ) * scale;
  18003. intPoint = Math.floor( point );
  18004. weight = point - intPoint;
  18005. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  18006. c[ 1 ] = intPoint;
  18007. c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
  18008. c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
  18009. pa = points[ c[ 0 ] ];
  18010. pb = points[ c[ 1 ] ];
  18011. pc = points[ c[ 2 ] ];
  18012. pd = points[ c[ 3 ] ];
  18013. w2 = weight * weight;
  18014. w3 = weight * w2;
  18015. v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
  18016. v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
  18017. v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
  18018. return v3;
  18019. };
  18020. var interpolate = function ( p0, p1, p2, p3, t, t2, t3 ) {
  18021. var v0 = ( p2 - p0 ) * 0.5,
  18022. v1 = ( p3 - p1 ) * 0.5;
  18023. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  18024. };
  18025. return function ( delta ) {
  18026. if ( this.isPlaying === false ) return;
  18027. this.currentTime += delta * this.timeScale;
  18028. if ( this.weight === 0 )
  18029. return;
  18030. //
  18031. var duration = this.data.length;
  18032. if ( this.currentTime > duration || this.currentTime < 0 ) {
  18033. if ( this.loop ) {
  18034. this.currentTime %= duration;
  18035. if ( this.currentTime < 0 )
  18036. this.currentTime += duration;
  18037. this.reset();
  18038. } else {
  18039. this.stop();
  18040. }
  18041. }
  18042. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18043. var object = this.hierarchy[ h ];
  18044. var animationCache = object.animationCache.animations[ this.data.name ];
  18045. var blending = object.animationCache.blending;
  18046. // loop through pos/rot/scl
  18047. for ( var t = 0; t < 3; t ++ ) {
  18048. // get keys
  18049. var type = this.keyTypes[ t ];
  18050. var prevKey = animationCache.prevKey[ type ];
  18051. var nextKey = animationCache.nextKey[ type ];
  18052. if ( ( this.timeScale > 0 && nextKey.time <= this.currentTime ) ||
  18053. ( this.timeScale < 0 && prevKey.time >= this.currentTime ) ) {
  18054. prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  18055. nextKey = this.getNextKeyWith( type, h, 1 );
  18056. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18057. prevKey = nextKey;
  18058. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  18059. }
  18060. animationCache.prevKey[ type ] = prevKey;
  18061. animationCache.nextKey[ type ] = nextKey;
  18062. }
  18063. var scale = ( this.currentTime - prevKey.time ) / ( nextKey.time - prevKey.time );
  18064. var prevXYZ = prevKey[ type ];
  18065. var nextXYZ = nextKey[ type ];
  18066. if ( scale < 0 ) scale = 0;
  18067. if ( scale > 1 ) scale = 1;
  18068. // interpolate
  18069. if ( type === "pos" ) {
  18070. if ( this.interpolationType === THREE.AnimationHandler.LINEAR ) {
  18071. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18072. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18073. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18074. // blend
  18075. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  18076. object.position.lerp( newVector, proportionalWeight );
  18077. blending.positionWeight += this.weight;
  18078. } else if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18079. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18080. points[ 0 ] = this.getPrevKeyWith( "pos", h, prevKey.index - 1 )[ "pos" ];
  18081. points[ 1 ] = prevXYZ;
  18082. points[ 2 ] = nextXYZ;
  18083. points[ 3 ] = this.getNextKeyWith( "pos", h, nextKey.index + 1 )[ "pos" ];
  18084. scale = scale * 0.33 + 0.33;
  18085. var currentPoint = interpolateCatmullRom( points, scale );
  18086. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  18087. blending.positionWeight += this.weight;
  18088. // blend
  18089. var vector = object.position;
  18090. vector.x = vector.x + ( currentPoint[ 0 ] - vector.x ) * proportionalWeight;
  18091. vector.y = vector.y + ( currentPoint[ 1 ] - vector.y ) * proportionalWeight;
  18092. vector.z = vector.z + ( currentPoint[ 2 ] - vector.z ) * proportionalWeight;
  18093. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18094. var forwardPoint = interpolateCatmullRom( points, scale * 1.01 );
  18095. target.set( forwardPoint[ 0 ], forwardPoint[ 1 ], forwardPoint[ 2 ] );
  18096. target.sub( vector );
  18097. target.y = 0;
  18098. target.normalize();
  18099. var angle = Math.atan2( target.x, target.z );
  18100. object.rotation.set( 0, angle, 0 );
  18101. }
  18102. }
  18103. } else if ( type === "rot" ) {
  18104. THREE.Quaternion.slerp( prevXYZ, nextXYZ, newQuat, scale );
  18105. // Avoid paying the cost of an additional slerp if we don't have to
  18106. if ( blending.quaternionWeight === 0 ) {
  18107. object.quaternion.copy( newQuat );
  18108. blending.quaternionWeight = this.weight;
  18109. } else {
  18110. var proportionalWeight = this.weight / ( this.weight + blending.quaternionWeight );
  18111. THREE.Quaternion.slerp( object.quaternion, newQuat, object.quaternion, proportionalWeight );
  18112. blending.quaternionWeight += this.weight;
  18113. }
  18114. } else if ( type === "scl" ) {
  18115. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18116. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18117. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18118. var proportionalWeight = this.weight / ( this.weight + blending.scaleWeight );
  18119. object.scale.lerp( newVector, proportionalWeight );
  18120. blending.scaleWeight += this.weight;
  18121. }
  18122. }
  18123. }
  18124. return true;
  18125. };
  18126. } )(),
  18127. getNextKeyWith: function ( type, h, key ) {
  18128. var keys = this.data.hierarchy[ h ].keys;
  18129. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18130. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18131. key = key < keys.length - 1 ? key : keys.length - 1;
  18132. } else {
  18133. key = key % keys.length;
  18134. }
  18135. for ( ; key < keys.length; key ++ ) {
  18136. if ( keys[ key ][ type ] !== undefined ) {
  18137. return keys[ key ];
  18138. }
  18139. }
  18140. return this.data.hierarchy[ h ].keys[ 0 ];
  18141. },
  18142. getPrevKeyWith: function ( type, h, key ) {
  18143. var keys = this.data.hierarchy[ h ].keys;
  18144. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18145. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18146. key = key > 0 ? key : 0;
  18147. } else {
  18148. key = key >= 0 ? key : key + keys.length;
  18149. }
  18150. for ( ; key >= 0; key -- ) {
  18151. if ( keys[ key ][ type ] !== undefined ) {
  18152. return keys[ key ];
  18153. }
  18154. }
  18155. return this.data.hierarchy[ h ].keys[ keys.length - 1 ];
  18156. }
  18157. };
  18158. // File:src/extras/animation/KeyFrameAnimation.js
  18159. /**
  18160. * @author mikael emtinger / http://gomo.se/
  18161. * @author mrdoob / http://mrdoob.com/
  18162. * @author alteredq / http://alteredqualia.com/
  18163. * @author khang duong
  18164. * @author erik kitson
  18165. */
  18166. THREE.KeyFrameAnimation = function ( data ) {
  18167. this.root = data.node;
  18168. this.data = THREE.AnimationHandler.init( data );
  18169. this.hierarchy = THREE.AnimationHandler.parse( this.root );
  18170. this.currentTime = 0;
  18171. this.timeScale = 0.001;
  18172. this.isPlaying = false;
  18173. this.isPaused = true;
  18174. this.loop = true;
  18175. // initialize to first keyframes
  18176. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18177. var keys = this.data.hierarchy[ h ].keys,
  18178. sids = this.data.hierarchy[ h ].sids,
  18179. obj = this.hierarchy[ h ];
  18180. if ( keys.length && sids ) {
  18181. for ( var s = 0; s < sids.length; s ++ ) {
  18182. var sid = sids[ s ],
  18183. next = this.getNextKeyWith( sid, h, 0 );
  18184. if ( next ) {
  18185. next.apply( sid );
  18186. }
  18187. }
  18188. obj.matrixAutoUpdate = false;
  18189. this.data.hierarchy[ h ].node.updateMatrix();
  18190. obj.matrixWorldNeedsUpdate = true;
  18191. }
  18192. }
  18193. };
  18194. THREE.KeyFrameAnimation.prototype = {
  18195. constructor: THREE.KeyFrameAnimation,
  18196. play: function ( startTime ) {
  18197. this.currentTime = startTime !== undefined ? startTime : 0;
  18198. if ( this.isPlaying === false ) {
  18199. this.isPlaying = true;
  18200. // reset key cache
  18201. var h, hl = this.hierarchy.length,
  18202. object,
  18203. node;
  18204. for ( h = 0; h < hl; h ++ ) {
  18205. object = this.hierarchy[ h ];
  18206. node = this.data.hierarchy[ h ];
  18207. if ( node.animationCache === undefined ) {
  18208. node.animationCache = {};
  18209. node.animationCache.prevKey = null;
  18210. node.animationCache.nextKey = null;
  18211. node.animationCache.originalMatrix = object.matrix;
  18212. }
  18213. var keys = this.data.hierarchy[ h ].keys;
  18214. if ( keys.length ) {
  18215. node.animationCache.prevKey = keys[ 0 ];
  18216. node.animationCache.nextKey = keys[ 1 ];
  18217. this.startTime = Math.min( keys[ 0 ].time, this.startTime );
  18218. this.endTime = Math.max( keys[ keys.length - 1 ].time, this.endTime );
  18219. }
  18220. }
  18221. this.update( 0 );
  18222. }
  18223. this.isPaused = false;
  18224. THREE.AnimationHandler.play( this );
  18225. },
  18226. stop: function () {
  18227. this.isPlaying = false;
  18228. this.isPaused = false;
  18229. THREE.AnimationHandler.stop( this );
  18230. // reset JIT matrix and remove cache
  18231. for ( var h = 0; h < this.data.hierarchy.length; h ++ ) {
  18232. var obj = this.hierarchy[ h ];
  18233. var node = this.data.hierarchy[ h ];
  18234. if ( node.animationCache !== undefined ) {
  18235. var original = node.animationCache.originalMatrix;
  18236. original.copy( obj.matrix );
  18237. obj.matrix = original;
  18238. delete node.animationCache;
  18239. }
  18240. }
  18241. },
  18242. update: function ( delta ) {
  18243. if ( this.isPlaying === false ) return;
  18244. this.currentTime += delta * this.timeScale;
  18245. //
  18246. var duration = this.data.length;
  18247. if ( this.loop === true && this.currentTime > duration ) {
  18248. this.currentTime %= duration;
  18249. }
  18250. this.currentTime = Math.min( this.currentTime, duration );
  18251. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18252. var object = this.hierarchy[ h ];
  18253. var node = this.data.hierarchy[ h ];
  18254. var keys = node.keys,
  18255. animationCache = node.animationCache;
  18256. if ( keys.length ) {
  18257. var prevKey = animationCache.prevKey;
  18258. var nextKey = animationCache.nextKey;
  18259. if ( nextKey.time <= this.currentTime ) {
  18260. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18261. prevKey = nextKey;
  18262. nextKey = keys[ prevKey.index + 1 ];
  18263. }
  18264. animationCache.prevKey = prevKey;
  18265. animationCache.nextKey = nextKey;
  18266. }
  18267. if ( nextKey.time >= this.currentTime ) {
  18268. prevKey.interpolate( nextKey, this.currentTime );
  18269. } else {
  18270. prevKey.interpolate( nextKey, nextKey.time );
  18271. }
  18272. this.data.hierarchy[ h ].node.updateMatrix();
  18273. object.matrixWorldNeedsUpdate = true;
  18274. }
  18275. }
  18276. },
  18277. getNextKeyWith: function ( sid, h, key ) {
  18278. var keys = this.data.hierarchy[ h ].keys;
  18279. key = key % keys.length;
  18280. for ( ; key < keys.length; key ++ ) {
  18281. if ( keys[ key ].hasTarget( sid ) ) {
  18282. return keys[ key ];
  18283. }
  18284. }
  18285. return keys[ 0 ];
  18286. },
  18287. getPrevKeyWith: function ( sid, h, key ) {
  18288. var keys = this.data.hierarchy[ h ].keys;
  18289. key = key >= 0 ? key : key + keys.length;
  18290. for ( ; key >= 0; key -- ) {
  18291. if ( keys[ key ].hasTarget( sid ) ) {
  18292. return keys[ key ];
  18293. }
  18294. }
  18295. return keys[ keys.length - 1 ];
  18296. }
  18297. };
  18298. // File:src/extras/animation/MorphAnimation.js
  18299. /**
  18300. * @author mrdoob / http://mrdoob.com
  18301. * @author willy-vvu / http://willy-vvu.github.io
  18302. */
  18303. THREE.MorphAnimation = function ( mesh ) {
  18304. this.mesh = mesh;
  18305. this.frames = mesh.morphTargetInfluences.length;
  18306. this.currentTime = 0;
  18307. this.duration = 1000;
  18308. this.loop = true;
  18309. this.lastFrame = 0;
  18310. this.currentFrame = 0;
  18311. this.isPlaying = false;
  18312. };
  18313. THREE.MorphAnimation.prototype = {
  18314. constructor: THREE.MorphAnimation,
  18315. play: function () {
  18316. this.isPlaying = true;
  18317. },
  18318. pause: function () {
  18319. this.isPlaying = false;
  18320. },
  18321. update: function ( delta ) {
  18322. if ( this.isPlaying === false ) return;
  18323. this.currentTime += delta;
  18324. if ( this.loop === true && this.currentTime > this.duration ) {
  18325. this.currentTime %= this.duration;
  18326. }
  18327. this.currentTime = Math.min( this.currentTime, this.duration );
  18328. var frameTime = this.duration / this.frames;
  18329. var frame = Math.floor( this.currentTime / frameTime );
  18330. var influences = this.mesh.morphTargetInfluences;
  18331. if ( frame !== this.currentFrame ) {
  18332. influences[ this.lastFrame ] = 0;
  18333. influences[ this.currentFrame ] = 1;
  18334. influences[ frame ] = 0;
  18335. this.lastFrame = this.currentFrame;
  18336. this.currentFrame = frame;
  18337. }
  18338. var mix = ( this.currentTime % frameTime ) / frameTime;
  18339. influences[ frame ] = mix;
  18340. influences[ this.lastFrame ] = 1 - mix;
  18341. }
  18342. };
  18343. // File:src/extras/geometries/BoxGeometry.js
  18344. /**
  18345. * @author mrdoob / http://mrdoob.com/
  18346. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  18347. */
  18348. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  18349. THREE.Geometry.call( this );
  18350. this.type = 'BoxGeometry';
  18351. this.parameters = {
  18352. width: width,
  18353. height: height,
  18354. depth: depth,
  18355. widthSegments: widthSegments,
  18356. heightSegments: heightSegments,
  18357. depthSegments: depthSegments
  18358. };
  18359. this.widthSegments = widthSegments || 1;
  18360. this.heightSegments = heightSegments || 1;
  18361. this.depthSegments = depthSegments || 1;
  18362. var scope = this;
  18363. var width_half = width / 2;
  18364. var height_half = height / 2;
  18365. var depth_half = depth / 2;
  18366. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  18367. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  18368. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  18369. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  18370. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  18371. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  18372. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  18373. var w, ix, iy,
  18374. gridX = scope.widthSegments,
  18375. gridY = scope.heightSegments,
  18376. width_half = width / 2,
  18377. height_half = height / 2,
  18378. offset = scope.vertices.length;
  18379. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  18380. w = 'z';
  18381. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  18382. w = 'y';
  18383. gridY = scope.depthSegments;
  18384. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  18385. w = 'x';
  18386. gridX = scope.depthSegments;
  18387. }
  18388. var gridX1 = gridX + 1,
  18389. gridY1 = gridY + 1,
  18390. segment_width = width / gridX,
  18391. segment_height = height / gridY,
  18392. normal = new THREE.Vector3();
  18393. normal[ w ] = depth > 0 ? 1 : - 1;
  18394. for ( iy = 0; iy < gridY1; iy ++ ) {
  18395. for ( ix = 0; ix < gridX1; ix ++ ) {
  18396. var vector = new THREE.Vector3();
  18397. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  18398. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  18399. vector[ w ] = depth;
  18400. scope.vertices.push( vector );
  18401. }
  18402. }
  18403. for ( iy = 0; iy < gridY; iy ++ ) {
  18404. for ( ix = 0; ix < gridX; ix ++ ) {
  18405. var a = ix + gridX1 * iy;
  18406. var b = ix + gridX1 * ( iy + 1 );
  18407. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  18408. var d = ( ix + 1 ) + gridX1 * iy;
  18409. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  18410. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  18411. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  18412. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  18413. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  18414. face.normal.copy( normal );
  18415. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18416. face.materialIndex = materialIndex;
  18417. scope.faces.push( face );
  18418. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  18419. face = new THREE.Face3( b + offset, c + offset, d + offset );
  18420. face.normal.copy( normal );
  18421. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18422. face.materialIndex = materialIndex;
  18423. scope.faces.push( face );
  18424. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  18425. }
  18426. }
  18427. }
  18428. this.mergeVertices();
  18429. };
  18430. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18431. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  18432. THREE.BoxGeometry.prototype.clone = function () {
  18433. var geometry = new THREE.BoxGeometry(
  18434. this.parameters.width,
  18435. this.parameters.height,
  18436. this.parameters.depth,
  18437. this.parameters.widthSegments,
  18438. this.parameters.heightSegments,
  18439. this.parameters.depthSegments
  18440. );
  18441. return geometry;
  18442. };
  18443. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  18444. // File:src/extras/geometries/CircleGeometry.js
  18445. /**
  18446. * @author hughes
  18447. */
  18448. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18449. THREE.Geometry.call( this );
  18450. this.type = 'CircleGeometry';
  18451. this.parameters = {
  18452. radius: radius,
  18453. segments: segments,
  18454. thetaStart: thetaStart,
  18455. thetaLength: thetaLength
  18456. };
  18457. radius = radius || 50;
  18458. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18459. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18460. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18461. var i, uvs = [],
  18462. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  18463. this.vertices.push( center );
  18464. uvs.push( centerUV );
  18465. for ( i = 0; i <= segments; i ++ ) {
  18466. var vertex = new THREE.Vector3();
  18467. var segment = thetaStart + i / segments * thetaLength;
  18468. vertex.x = radius * Math.cos( segment );
  18469. vertex.y = radius * Math.sin( segment );
  18470. this.vertices.push( vertex );
  18471. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  18472. }
  18473. var n = new THREE.Vector3( 0, 0, 1 );
  18474. for ( i = 1; i <= segments; i ++ ) {
  18475. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  18476. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  18477. }
  18478. this.computeFaceNormals();
  18479. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18480. };
  18481. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18482. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  18483. THREE.CircleGeometry.prototype.clone = function () {
  18484. var geometry = new THREE.CircleGeometry(
  18485. this.parameters.radius,
  18486. this.parameters.segments,
  18487. this.parameters.thetaStart,
  18488. this.parameters.thetaLength
  18489. );
  18490. return geometry;
  18491. };
  18492. // File:src/extras/geometries/CircleBufferGeometry.js
  18493. /**
  18494. * @author benaadams / https://twitter.com/ben_a_adams
  18495. */
  18496. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18497. THREE.BufferGeometry.call( this );
  18498. this.type = 'CircleBufferGeometry';
  18499. this.parameters = {
  18500. radius: radius,
  18501. segments: segments,
  18502. thetaStart: thetaStart,
  18503. thetaLength: thetaLength
  18504. };
  18505. radius = radius || 50;
  18506. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18507. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18508. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18509. var vertices = segments + 2;
  18510. var positions = new Float32Array( vertices * 3 );
  18511. var normals = new Float32Array( vertices * 3 );
  18512. var uvs = new Float32Array( vertices * 2 );
  18513. // center data is already zero, but need to set a few extras
  18514. normals[ 3 ] = 1.0;
  18515. uvs[ 0 ] = 0.5;
  18516. uvs[ 1 ] = 0.5;
  18517. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  18518. var segment = thetaStart + s / segments * thetaLength;
  18519. positions[ i ] = radius * Math.cos( segment );
  18520. positions[ i + 1 ] = radius * Math.sin( segment );
  18521. normals[ i + 2 ] = 1; // normal z
  18522. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  18523. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  18524. }
  18525. var indices = [];
  18526. for ( var i = 1; i <= segments; i ++ ) {
  18527. indices.push( i );
  18528. indices.push( i + 1 );
  18529. indices.push( 0 );
  18530. }
  18531. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  18532. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  18533. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  18534. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  18535. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18536. };
  18537. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18538. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  18539. THREE.CircleBufferGeometry.prototype.clone = function () {
  18540. var geometry = new THREE.CircleBufferGeometry(
  18541. this.parameters.radius,
  18542. this.parameters.segments,
  18543. this.parameters.thetaStart,
  18544. this.parameters.thetaLength
  18545. );
  18546. geometry.copy( this );
  18547. return geometry;
  18548. };
  18549. // File:src/extras/geometries/CylinderGeometry.js
  18550. /**
  18551. * @author mrdoob / http://mrdoob.com/
  18552. */
  18553. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18554. THREE.Geometry.call( this );
  18555. this.type = 'CylinderGeometry';
  18556. this.parameters = {
  18557. radiusTop: radiusTop,
  18558. radiusBottom: radiusBottom,
  18559. height: height,
  18560. radialSegments: radialSegments,
  18561. heightSegments: heightSegments,
  18562. openEnded: openEnded,
  18563. thetaStart: thetaStart,
  18564. thetaLength: thetaLength
  18565. };
  18566. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  18567. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  18568. height = height !== undefined ? height : 100;
  18569. radialSegments = radialSegments || 8;
  18570. heightSegments = heightSegments || 1;
  18571. openEnded = openEnded !== undefined ? openEnded : false;
  18572. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18573. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  18574. var heightHalf = height / 2;
  18575. var x, y, vertices = [], uvs = [];
  18576. for ( y = 0; y <= heightSegments; y ++ ) {
  18577. var verticesRow = [];
  18578. var uvsRow = [];
  18579. var v = y / heightSegments;
  18580. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18581. for ( x = 0; x <= radialSegments; x ++ ) {
  18582. var u = x / radialSegments;
  18583. var vertex = new THREE.Vector3();
  18584. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  18585. vertex.y = - v * height + heightHalf;
  18586. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  18587. this.vertices.push( vertex );
  18588. verticesRow.push( this.vertices.length - 1 );
  18589. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  18590. }
  18591. vertices.push( verticesRow );
  18592. uvs.push( uvsRow );
  18593. }
  18594. var tanTheta = ( radiusBottom - radiusTop ) / height;
  18595. var na, nb;
  18596. for ( x = 0; x < radialSegments; x ++ ) {
  18597. if ( radiusTop !== 0 ) {
  18598. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  18599. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  18600. } else {
  18601. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  18602. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  18603. }
  18604. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  18605. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  18606. for ( y = 0; y < heightSegments; y ++ ) {
  18607. var v1 = vertices[ y ][ x ];
  18608. var v2 = vertices[ y + 1 ][ x ];
  18609. var v3 = vertices[ y + 1 ][ x + 1 ];
  18610. var v4 = vertices[ y ][ x + 1 ];
  18611. var n1 = na.clone();
  18612. var n2 = na.clone();
  18613. var n3 = nb.clone();
  18614. var n4 = nb.clone();
  18615. var uv1 = uvs[ y ][ x ].clone();
  18616. var uv2 = uvs[ y + 1 ][ x ].clone();
  18617. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  18618. var uv4 = uvs[ y ][ x + 1 ].clone();
  18619. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  18620. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  18621. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  18622. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  18623. }
  18624. }
  18625. // top cap
  18626. if ( openEnded === false && radiusTop > 0 ) {
  18627. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  18628. for ( x = 0; x < radialSegments; x ++ ) {
  18629. var v1 = vertices[ 0 ][ x ];
  18630. var v2 = vertices[ 0 ][ x + 1 ];
  18631. var v3 = this.vertices.length - 1;
  18632. var n1 = new THREE.Vector3( 0, 1, 0 );
  18633. var n2 = new THREE.Vector3( 0, 1, 0 );
  18634. var n3 = new THREE.Vector3( 0, 1, 0 );
  18635. var uv1 = uvs[ 0 ][ x ].clone();
  18636. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  18637. var uv3 = new THREE.Vector2( uv2.x, 0 );
  18638. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18639. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18640. }
  18641. }
  18642. // bottom cap
  18643. if ( openEnded === false && radiusBottom > 0 ) {
  18644. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  18645. for ( x = 0; x < radialSegments; x ++ ) {
  18646. var v1 = vertices[ heightSegments ][ x + 1 ];
  18647. var v2 = vertices[ heightSegments ][ x ];
  18648. var v3 = this.vertices.length - 1;
  18649. var n1 = new THREE.Vector3( 0, - 1, 0 );
  18650. var n2 = new THREE.Vector3( 0, - 1, 0 );
  18651. var n3 = new THREE.Vector3( 0, - 1, 0 );
  18652. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  18653. var uv2 = uvs[ heightSegments ][ x ].clone();
  18654. var uv3 = new THREE.Vector2( uv2.x, 1 );
  18655. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18656. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18657. }
  18658. }
  18659. this.computeFaceNormals();
  18660. };
  18661. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18662. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  18663. THREE.CylinderGeometry.prototype.clone = function () {
  18664. var geometry = new THREE.CylinderGeometry(
  18665. this.parameters.radiusTop,
  18666. this.parameters.radiusBottom,
  18667. this.parameters.height,
  18668. this.parameters.radialSegments,
  18669. this.parameters.heightSegments,
  18670. this.parameters.openEnded,
  18671. this.parameters.thetaStart,
  18672. this.parameters.thetaLength
  18673. );
  18674. return geometry;
  18675. };
  18676. // File:src/extras/geometries/EdgesGeometry.js
  18677. /**
  18678. * @author WestLangley / http://github.com/WestLangley
  18679. */
  18680. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  18681. THREE.BufferGeometry.call( this );
  18682. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18683. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  18684. var edge = [ 0, 0 ], hash = {};
  18685. var sortFunction = function ( a, b ) {
  18686. return a - b;
  18687. };
  18688. var keys = [ 'a', 'b', 'c' ];
  18689. var geometry2;
  18690. if ( geometry instanceof THREE.BufferGeometry ) {
  18691. geometry2 = new THREE.Geometry();
  18692. geometry2.fromBufferGeometry( geometry );
  18693. } else {
  18694. geometry2 = geometry.clone();
  18695. }
  18696. geometry2.mergeVertices();
  18697. geometry2.computeFaceNormals();
  18698. var vertices = geometry2.vertices;
  18699. var faces = geometry2.faces;
  18700. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18701. var face = faces[ i ];
  18702. for ( var j = 0; j < 3; j ++ ) {
  18703. edge[ 0 ] = face[ keys[ j ] ];
  18704. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  18705. edge.sort( sortFunction );
  18706. var key = edge.toString();
  18707. if ( hash[ key ] === undefined ) {
  18708. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  18709. } else {
  18710. hash[ key ].face2 = i;
  18711. }
  18712. }
  18713. }
  18714. var coords = [];
  18715. for ( var key in hash ) {
  18716. var h = hash[ key ];
  18717. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  18718. var vertex = vertices[ h.vert1 ];
  18719. coords.push( vertex.x );
  18720. coords.push( vertex.y );
  18721. coords.push( vertex.z );
  18722. vertex = vertices[ h.vert2 ];
  18723. coords.push( vertex.x );
  18724. coords.push( vertex.y );
  18725. coords.push( vertex.z );
  18726. }
  18727. }
  18728. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  18729. };
  18730. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18731. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  18732. // File:src/extras/geometries/ExtrudeGeometry.js
  18733. /**
  18734. * @author zz85 / http://www.lab4games.net/zz85/blog
  18735. *
  18736. * Creates extruded geometry from a path shape.
  18737. *
  18738. * parameters = {
  18739. *
  18740. * curveSegments: <int>, // number of points on the curves
  18741. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18742. * amount: <int>, // Depth to extrude the shape
  18743. *
  18744. * bevelEnabled: <bool>, // turn on bevel
  18745. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18746. * bevelSize: <float>, // how far from shape outline is bevel
  18747. * bevelSegments: <int>, // number of bevel layers
  18748. *
  18749. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  18750. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  18751. *
  18752. * uvGenerator: <Object> // object that provides UV generator functions
  18753. *
  18754. * }
  18755. **/
  18756. THREE.ExtrudeGeometry = function ( shapes, options ) {
  18757. if ( typeof( shapes ) === "undefined" ) {
  18758. shapes = [];
  18759. return;
  18760. }
  18761. THREE.Geometry.call( this );
  18762. this.type = 'ExtrudeGeometry';
  18763. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18764. this.addShapeList( shapes, options );
  18765. this.computeFaceNormals();
  18766. // can't really use automatic vertex normals
  18767. // as then front and back sides get smoothed too
  18768. // should do separate smoothing just for sides
  18769. //this.computeVertexNormals();
  18770. //console.log( "took", ( Date.now() - startTime ) );
  18771. };
  18772. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18773. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  18774. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  18775. var sl = shapes.length;
  18776. for ( var s = 0; s < sl; s ++ ) {
  18777. var shape = shapes[ s ];
  18778. this.addShape( shape, options );
  18779. }
  18780. };
  18781. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  18782. var amount = options.amount !== undefined ? options.amount : 100;
  18783. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  18784. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  18785. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18786. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  18787. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18788. var steps = options.steps !== undefined ? options.steps : 1;
  18789. var extrudePath = options.extrudePath;
  18790. var extrudePts, extrudeByPath = false;
  18791. // Use default WorldUVGenerator if no UV generators are specified.
  18792. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  18793. var splineTube, binormal, normal, position2;
  18794. if ( extrudePath ) {
  18795. extrudePts = extrudePath.getSpacedPoints( steps );
  18796. extrudeByPath = true;
  18797. bevelEnabled = false; // bevels not supported for path extrusion
  18798. // SETUP TNB variables
  18799. // Reuse TNB from TubeGeomtry for now.
  18800. // TODO1 - have a .isClosed in spline?
  18801. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  18802. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18803. binormal = new THREE.Vector3();
  18804. normal = new THREE.Vector3();
  18805. position2 = new THREE.Vector3();
  18806. }
  18807. // Safeguards if bevels are not enabled
  18808. if ( ! bevelEnabled ) {
  18809. bevelSegments = 0;
  18810. bevelThickness = 0;
  18811. bevelSize = 0;
  18812. }
  18813. // Variables initialization
  18814. var ahole, h, hl; // looping of holes
  18815. var scope = this;
  18816. var shapesOffset = this.vertices.length;
  18817. var shapePoints = shape.extractPoints( curveSegments );
  18818. var vertices = shapePoints.shape;
  18819. var holes = shapePoints.holes;
  18820. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  18821. if ( reverse ) {
  18822. vertices = vertices.reverse();
  18823. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18824. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18825. ahole = holes[ h ];
  18826. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  18827. holes[ h ] = ahole.reverse();
  18828. }
  18829. }
  18830. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  18831. }
  18832. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  18833. /* Vertices */
  18834. var contour = vertices; // vertices has all points but contour has only points of circumference
  18835. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18836. ahole = holes[ h ];
  18837. vertices = vertices.concat( ahole );
  18838. }
  18839. function scalePt2 ( pt, vec, size ) {
  18840. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18841. return vec.clone().multiplyScalar( size ).add( pt );
  18842. }
  18843. var b, bs, t, z,
  18844. vert, vlen = vertices.length,
  18845. face, flen = faces.length;
  18846. // Find directions for point movement
  18847. function getBevelVec( inPt, inPrev, inNext ) {
  18848. var EPSILON = 0.0000000001;
  18849. // computes for inPt the corresponding point inPt' on a new contour
  18850. // shifted by 1 unit (length of normalized vector) to the left
  18851. // if we walk along contour clockwise, this new contour is outside the old one
  18852. //
  18853. // inPt' is the intersection of the two lines parallel to the two
  18854. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18855. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  18856. // good reading for geometry algorithms (here: line-line intersection)
  18857. // http://geomalgorithms.com/a05-_intersect-1.html
  18858. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  18859. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  18860. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18861. // check for collinear edges
  18862. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18863. if ( Math.abs( collinear0 ) > EPSILON ) {
  18864. // not collinear
  18865. // length of vectors for normalizing
  18866. var v_prev_len = Math.sqrt( v_prev_lensq );
  18867. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18868. // shift adjacent points by unit vectors to the left
  18869. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18870. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18871. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18872. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18873. // scaling factor for v_prev to intersection point
  18874. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18875. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18876. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18877. // vector from inPt to intersection point
  18878. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18879. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18880. // Don't normalize!, otherwise sharp corners become ugly
  18881. // but prevent crazy spikes
  18882. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18883. if ( v_trans_lensq <= 2 ) {
  18884. return new THREE.Vector2( v_trans_x, v_trans_y );
  18885. } else {
  18886. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18887. }
  18888. } else {
  18889. // handle special case of collinear edges
  18890. var direction_eq = false; // assumes: opposite
  18891. if ( v_prev_x > EPSILON ) {
  18892. if ( v_next_x > EPSILON ) {
  18893. direction_eq = true;
  18894. }
  18895. } else {
  18896. if ( v_prev_x < - EPSILON ) {
  18897. if ( v_next_x < - EPSILON ) {
  18898. direction_eq = true;
  18899. }
  18900. } else {
  18901. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  18902. direction_eq = true;
  18903. }
  18904. }
  18905. }
  18906. if ( direction_eq ) {
  18907. // console.log("Warning: lines are a straight sequence");
  18908. v_trans_x = - v_prev_y;
  18909. v_trans_y = v_prev_x;
  18910. shrink_by = Math.sqrt( v_prev_lensq );
  18911. } else {
  18912. // console.log("Warning: lines are a straight spike");
  18913. v_trans_x = v_prev_x;
  18914. v_trans_y = v_prev_y;
  18915. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18916. }
  18917. }
  18918. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18919. }
  18920. var contourMovements = [];
  18921. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18922. if ( j === il ) j = 0;
  18923. if ( k === il ) k = 0;
  18924. // (j)---(i)---(k)
  18925. // console.log('i,j,k', i, j , k)
  18926. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18927. }
  18928. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  18929. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18930. ahole = holes[ h ];
  18931. oneHoleMovements = [];
  18932. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18933. if ( j === il ) j = 0;
  18934. if ( k === il ) k = 0;
  18935. // (j)---(i)---(k)
  18936. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18937. }
  18938. holesMovements.push( oneHoleMovements );
  18939. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18940. }
  18941. // Loop bevelSegments, 1 for the front, 1 for the back
  18942. for ( b = 0; b < bevelSegments; b ++ ) {
  18943. //for ( b = bevelSegments; b > 0; b -- ) {
  18944. t = b / bevelSegments;
  18945. z = bevelThickness * ( 1 - t );
  18946. //z = bevelThickness * t;
  18947. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  18948. //bs = bevelSize * t; // linear
  18949. // contract shape
  18950. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18951. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18952. v( vert.x, vert.y, - z );
  18953. }
  18954. // expand holes
  18955. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18956. ahole = holes[ h ];
  18957. oneHoleMovements = holesMovements[ h ];
  18958. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18959. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18960. v( vert.x, vert.y, - z );
  18961. }
  18962. }
  18963. }
  18964. bs = bevelSize;
  18965. // Back facing vertices
  18966. for ( i = 0; i < vlen; i ++ ) {
  18967. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18968. if ( ! extrudeByPath ) {
  18969. v( vert.x, vert.y, 0 );
  18970. } else {
  18971. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  18972. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  18973. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  18974. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  18975. v( position2.x, position2.y, position2.z );
  18976. }
  18977. }
  18978. // Add stepped vertices...
  18979. // Including front facing vertices
  18980. var s;
  18981. for ( s = 1; s <= steps; s ++ ) {
  18982. for ( i = 0; i < vlen; i ++ ) {
  18983. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18984. if ( ! extrudeByPath ) {
  18985. v( vert.x, vert.y, amount / steps * s );
  18986. } else {
  18987. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  18988. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  18989. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  18990. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  18991. v( position2.x, position2.y, position2.z );
  18992. }
  18993. }
  18994. }
  18995. // Add bevel segments planes
  18996. //for ( b = 1; b <= bevelSegments; b ++ ) {
  18997. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  18998. t = b / bevelSegments;
  18999. z = bevelThickness * ( 1 - t );
  19000. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  19001. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  19002. // contract shape
  19003. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19004. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19005. v( vert.x, vert.y, amount + z );
  19006. }
  19007. // expand holes
  19008. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19009. ahole = holes[ h ];
  19010. oneHoleMovements = holesMovements[ h ];
  19011. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19012. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19013. if ( ! extrudeByPath ) {
  19014. v( vert.x, vert.y, amount + z );
  19015. } else {
  19016. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19017. }
  19018. }
  19019. }
  19020. }
  19021. /* Faces */
  19022. // Top and bottom faces
  19023. buildLidFaces();
  19024. // Sides faces
  19025. buildSideFaces();
  19026. ///// Internal functions
  19027. function buildLidFaces() {
  19028. if ( bevelEnabled ) {
  19029. var layer = 0; // steps + 1
  19030. var offset = vlen * layer;
  19031. // Bottom faces
  19032. for ( i = 0; i < flen; i ++ ) {
  19033. face = faces[ i ];
  19034. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19035. }
  19036. layer = steps + bevelSegments * 2;
  19037. offset = vlen * layer;
  19038. // Top faces
  19039. for ( i = 0; i < flen; i ++ ) {
  19040. face = faces[ i ];
  19041. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19042. }
  19043. } else {
  19044. // Bottom faces
  19045. for ( i = 0; i < flen; i ++ ) {
  19046. face = faces[ i ];
  19047. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19048. }
  19049. // Top faces
  19050. for ( i = 0; i < flen; i ++ ) {
  19051. face = faces[ i ];
  19052. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19053. }
  19054. }
  19055. }
  19056. // Create faces for the z-sides of the shape
  19057. function buildSideFaces() {
  19058. var layeroffset = 0;
  19059. sidewalls( contour, layeroffset );
  19060. layeroffset += contour.length;
  19061. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19062. ahole = holes[ h ];
  19063. sidewalls( ahole, layeroffset );
  19064. //, true
  19065. layeroffset += ahole.length;
  19066. }
  19067. }
  19068. function sidewalls( contour, layeroffset ) {
  19069. var j, k;
  19070. i = contour.length;
  19071. while ( -- i >= 0 ) {
  19072. j = i;
  19073. k = i - 1;
  19074. if ( k < 0 ) k = contour.length - 1;
  19075. //console.log('b', i,j, i-1, k,vertices.length);
  19076. var s = 0, sl = steps + bevelSegments * 2;
  19077. for ( s = 0; s < sl; s ++ ) {
  19078. var slen1 = vlen * s;
  19079. var slen2 = vlen * ( s + 1 );
  19080. var a = layeroffset + j + slen1,
  19081. b = layeroffset + k + slen1,
  19082. c = layeroffset + k + slen2,
  19083. d = layeroffset + j + slen2;
  19084. f4( a, b, c, d, contour, s, sl, j, k );
  19085. }
  19086. }
  19087. }
  19088. function v( x, y, z ) {
  19089. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  19090. }
  19091. function f3( a, b, c ) {
  19092. a += shapesOffset;
  19093. b += shapesOffset;
  19094. c += shapesOffset;
  19095. scope.faces.push( new THREE.Face3( a, b, c ) );
  19096. var uvs = uvgen.generateTopUV( scope, a, b, c );
  19097. scope.faceVertexUvs[ 0 ].push( uvs );
  19098. }
  19099. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  19100. a += shapesOffset;
  19101. b += shapesOffset;
  19102. c += shapesOffset;
  19103. d += shapesOffset;
  19104. scope.faces.push( new THREE.Face3( a, b, d ) );
  19105. scope.faces.push( new THREE.Face3( b, c, d ) );
  19106. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  19107. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  19108. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  19109. }
  19110. };
  19111. THREE.ExtrudeGeometry.WorldUVGenerator = {
  19112. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  19113. var vertices = geometry.vertices;
  19114. var a = vertices[ indexA ];
  19115. var b = vertices[ indexB ];
  19116. var c = vertices[ indexC ];
  19117. return [
  19118. new THREE.Vector2( a.x, a.y ),
  19119. new THREE.Vector2( b.x, b.y ),
  19120. new THREE.Vector2( c.x, c.y )
  19121. ];
  19122. },
  19123. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  19124. var vertices = geometry.vertices;
  19125. var a = vertices[ indexA ];
  19126. var b = vertices[ indexB ];
  19127. var c = vertices[ indexC ];
  19128. var d = vertices[ indexD ];
  19129. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  19130. return [
  19131. new THREE.Vector2( a.x, 1 - a.z ),
  19132. new THREE.Vector2( b.x, 1 - b.z ),
  19133. new THREE.Vector2( c.x, 1 - c.z ),
  19134. new THREE.Vector2( d.x, 1 - d.z )
  19135. ];
  19136. } else {
  19137. return [
  19138. new THREE.Vector2( a.y, 1 - a.z ),
  19139. new THREE.Vector2( b.y, 1 - b.z ),
  19140. new THREE.Vector2( c.y, 1 - c.z ),
  19141. new THREE.Vector2( d.y, 1 - d.z )
  19142. ];
  19143. }
  19144. }
  19145. };
  19146. // File:src/extras/geometries/ShapeGeometry.js
  19147. /**
  19148. * @author jonobr1 / http://jonobr1.com
  19149. *
  19150. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19151. * ExtrudeGeometry.
  19152. *
  19153. * parameters = {
  19154. *
  19155. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19156. *
  19157. * material: <int> // material index for front and back faces
  19158. * uvGenerator: <Object> // object that provides UV generator functions
  19159. *
  19160. * }
  19161. **/
  19162. THREE.ShapeGeometry = function ( shapes, options ) {
  19163. THREE.Geometry.call( this );
  19164. this.type = 'ShapeGeometry';
  19165. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19166. this.addShapeList( shapes, options );
  19167. this.computeFaceNormals();
  19168. };
  19169. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19170. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19171. /**
  19172. * Add an array of shapes to THREE.ShapeGeometry.
  19173. */
  19174. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19175. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19176. this.addShape( shapes[ i ], options );
  19177. }
  19178. return this;
  19179. };
  19180. /**
  19181. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19182. */
  19183. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19184. if ( options === undefined ) options = {};
  19185. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19186. var material = options.material;
  19187. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19188. //
  19189. var i, l, hole;
  19190. var shapesOffset = this.vertices.length;
  19191. var shapePoints = shape.extractPoints( curveSegments );
  19192. var vertices = shapePoints.shape;
  19193. var holes = shapePoints.holes;
  19194. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19195. if ( reverse ) {
  19196. vertices = vertices.reverse();
  19197. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19198. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19199. hole = holes[ i ];
  19200. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19201. holes[ i ] = hole.reverse();
  19202. }
  19203. }
  19204. reverse = false;
  19205. }
  19206. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19207. // Vertices
  19208. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19209. hole = holes[ i ];
  19210. vertices = vertices.concat( hole );
  19211. }
  19212. //
  19213. var vert, vlen = vertices.length;
  19214. var face, flen = faces.length;
  19215. for ( i = 0; i < vlen; i ++ ) {
  19216. vert = vertices[ i ];
  19217. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19218. }
  19219. for ( i = 0; i < flen; i ++ ) {
  19220. face = faces[ i ];
  19221. var a = face[ 0 ] + shapesOffset;
  19222. var b = face[ 1 ] + shapesOffset;
  19223. var c = face[ 2 ] + shapesOffset;
  19224. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19225. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19226. }
  19227. };
  19228. // File:src/extras/geometries/LatheGeometry.js
  19229. /**
  19230. * @author astrodud / http://astrodud.isgreat.org/
  19231. * @author zz85 / https://github.com/zz85
  19232. * @author bhouston / http://exocortex.com
  19233. */
  19234. // points - to create a closed torus, one must use a set of points
  19235. // like so: [ a, b, c, d, a ], see first is the same as last.
  19236. // segments - the number of circumference segments to create
  19237. // phiStart - the starting radian
  19238. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19239. // 2*pi is a closed lathe, less than 2PI is a portion.
  19240. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19241. THREE.Geometry.call( this );
  19242. this.type = 'LatheGeometry';
  19243. this.parameters = {
  19244. points: points,
  19245. segments: segments,
  19246. phiStart: phiStart,
  19247. phiLength: phiLength
  19248. };
  19249. segments = segments || 12;
  19250. phiStart = phiStart || 0;
  19251. phiLength = phiLength || 2 * Math.PI;
  19252. var inversePointLength = 1.0 / ( points.length - 1 );
  19253. var inverseSegments = 1.0 / segments;
  19254. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19255. var phi = phiStart + i * inverseSegments * phiLength;
  19256. var c = Math.cos( phi ),
  19257. s = Math.sin( phi );
  19258. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19259. var pt = points[ j ];
  19260. var vertex = new THREE.Vector3();
  19261. vertex.x = c * pt.x - s * pt.y;
  19262. vertex.y = s * pt.x + c * pt.y;
  19263. vertex.z = pt.z;
  19264. this.vertices.push( vertex );
  19265. }
  19266. }
  19267. var np = points.length;
  19268. for ( var i = 0, il = segments; i < il; i ++ ) {
  19269. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19270. var base = j + np * i;
  19271. var a = base;
  19272. var b = base + np;
  19273. var c = base + 1 + np;
  19274. var d = base + 1;
  19275. var u0 = i * inverseSegments;
  19276. var v0 = j * inversePointLength;
  19277. var u1 = u0 + inverseSegments;
  19278. var v1 = v0 + inversePointLength;
  19279. this.faces.push( new THREE.Face3( a, b, d ) );
  19280. this.faceVertexUvs[ 0 ].push( [
  19281. new THREE.Vector2( u0, v0 ),
  19282. new THREE.Vector2( u1, v0 ),
  19283. new THREE.Vector2( u0, v1 )
  19284. ] );
  19285. this.faces.push( new THREE.Face3( b, c, d ) );
  19286. this.faceVertexUvs[ 0 ].push( [
  19287. new THREE.Vector2( u1, v0 ),
  19288. new THREE.Vector2( u1, v1 ),
  19289. new THREE.Vector2( u0, v1 )
  19290. ] );
  19291. }
  19292. }
  19293. this.mergeVertices();
  19294. this.computeFaceNormals();
  19295. this.computeVertexNormals();
  19296. };
  19297. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19298. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19299. // File:src/extras/geometries/PlaneGeometry.js
  19300. /**
  19301. * @author mrdoob / http://mrdoob.com/
  19302. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19303. */
  19304. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19305. THREE.Geometry.call( this );
  19306. this.type = 'PlaneGeometry';
  19307. this.parameters = {
  19308. width: width,
  19309. height: height,
  19310. widthSegments: widthSegments,
  19311. heightSegments: heightSegments
  19312. };
  19313. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  19314. };
  19315. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19316. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  19317. THREE.PlaneGeometry.prototype.clone = function () {
  19318. var geometry = new THREE.PlaneGeometry(
  19319. this.parameters.width,
  19320. this.parameters.height,
  19321. this.parameters.widthSegments,
  19322. this.parameters.heightSegments
  19323. );
  19324. return geometry;
  19325. };
  19326. // File:src/extras/geometries/PlaneBufferGeometry.js
  19327. /**
  19328. * @author mrdoob / http://mrdoob.com/
  19329. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19330. */
  19331. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  19332. THREE.BufferGeometry.call( this );
  19333. this.type = 'PlaneBufferGeometry';
  19334. this.parameters = {
  19335. width: width,
  19336. height: height,
  19337. widthSegments: widthSegments,
  19338. heightSegments: heightSegments
  19339. };
  19340. var width_half = width / 2;
  19341. var height_half = height / 2;
  19342. var gridX = Math.floor( widthSegments ) || 1;
  19343. var gridY = Math.floor( heightSegments ) || 1;
  19344. var gridX1 = gridX + 1;
  19345. var gridY1 = gridY + 1;
  19346. var segment_width = width / gridX;
  19347. var segment_height = height / gridY;
  19348. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  19349. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  19350. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  19351. var offset = 0;
  19352. var offset2 = 0;
  19353. for ( var iy = 0; iy < gridY1; iy ++ ) {
  19354. var y = iy * segment_height - height_half;
  19355. for ( var ix = 0; ix < gridX1; ix ++ ) {
  19356. var x = ix * segment_width - width_half;
  19357. vertices[ offset ] = x;
  19358. vertices[ offset + 1 ] = - y;
  19359. normals[ offset + 2 ] = 1;
  19360. uvs[ offset2 ] = ix / gridX;
  19361. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  19362. offset += 3;
  19363. offset2 += 2;
  19364. }
  19365. }
  19366. offset = 0;
  19367. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  19368. for ( var iy = 0; iy < gridY; iy ++ ) {
  19369. for ( var ix = 0; ix < gridX; ix ++ ) {
  19370. var a = ix + gridX1 * iy;
  19371. var b = ix + gridX1 * ( iy + 1 );
  19372. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19373. var d = ( ix + 1 ) + gridX1 * iy;
  19374. indices[ offset ] = a;
  19375. indices[ offset + 1 ] = b;
  19376. indices[ offset + 2 ] = d;
  19377. indices[ offset + 3 ] = b;
  19378. indices[ offset + 4 ] = c;
  19379. indices[ offset + 5 ] = d;
  19380. offset += 6;
  19381. }
  19382. }
  19383. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  19384. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  19385. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19386. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19387. };
  19388. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19389. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  19390. THREE.PlaneBufferGeometry.prototype.clone = function () {
  19391. var geometry = new THREE.PlaneBufferGeometry(
  19392. this.parameters.width,
  19393. this.parameters.height,
  19394. this.parameters.widthSegments,
  19395. this.parameters.heightSegments
  19396. );
  19397. geometry.copy( this );
  19398. return geometry;
  19399. };
  19400. // File:src/extras/geometries/RingGeometry.js
  19401. /**
  19402. * @author Kaleb Murphy
  19403. */
  19404. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19405. THREE.Geometry.call( this );
  19406. this.type = 'RingGeometry';
  19407. this.parameters = {
  19408. innerRadius: innerRadius,
  19409. outerRadius: outerRadius,
  19410. thetaSegments: thetaSegments,
  19411. phiSegments: phiSegments,
  19412. thetaStart: thetaStart,
  19413. thetaLength: thetaLength
  19414. };
  19415. innerRadius = innerRadius || 0;
  19416. outerRadius = outerRadius || 50;
  19417. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19418. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19419. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19420. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  19421. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19422. for ( i = 0; i < phiSegments + 1; i ++ ) {
  19423. // concentric circles inside ring
  19424. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  19425. // number of segments per circle
  19426. var vertex = new THREE.Vector3();
  19427. var segment = thetaStart + o / thetaSegments * thetaLength;
  19428. vertex.x = radius * Math.cos( segment );
  19429. vertex.y = radius * Math.sin( segment );
  19430. this.vertices.push( vertex );
  19431. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  19432. }
  19433. radius += radiusStep;
  19434. }
  19435. var n = new THREE.Vector3( 0, 0, 1 );
  19436. for ( i = 0; i < phiSegments; i ++ ) {
  19437. // concentric circles inside ring
  19438. var thetaSegment = i * ( thetaSegments + 1 );
  19439. for ( o = 0; o < thetaSegments ; o ++ ) {
  19440. // number of segments per circle
  19441. var segment = o + thetaSegment;
  19442. var v1 = segment;
  19443. var v2 = segment + thetaSegments + 1;
  19444. var v3 = segment + thetaSegments + 2;
  19445. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19446. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  19447. v1 = segment;
  19448. v2 = segment + thetaSegments + 2;
  19449. v3 = segment + 1;
  19450. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19451. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  19452. }
  19453. }
  19454. this.computeFaceNormals();
  19455. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19456. };
  19457. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19458. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  19459. THREE.RingGeometry.prototype.clone = function () {
  19460. var geometry = new THREE.RingGeometry(
  19461. this.parameters.innerRadius,
  19462. this.parameters.outerRadius,
  19463. this.parameters.thetaSegments,
  19464. this.parameters.phiSegments,
  19465. this.parameters.thetaStart,
  19466. this.parameters.thetaLength
  19467. );
  19468. return geometry;
  19469. };
  19470. // File:src/extras/geometries/SphereGeometry.js
  19471. /**
  19472. * @author mrdoob / http://mrdoob.com/
  19473. */
  19474. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19475. console.log( 'THREE.SphereGeometry: Consider using THREE.SphereBufferGeometry for lower memory footprint.' );
  19476. THREE.Geometry.call( this );
  19477. this.type = 'SphereGeometry';
  19478. this.parameters = {
  19479. radius: radius,
  19480. widthSegments: widthSegments,
  19481. heightSegments: heightSegments,
  19482. phiStart: phiStart,
  19483. phiLength: phiLength,
  19484. thetaStart: thetaStart,
  19485. thetaLength: thetaLength
  19486. };
  19487. radius = radius || 50;
  19488. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19489. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19490. phiStart = phiStart !== undefined ? phiStart : 0;
  19491. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19492. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19493. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19494. var x, y, vertices = [], uvs = [];
  19495. for ( y = 0; y <= heightSegments; y ++ ) {
  19496. var verticesRow = [];
  19497. var uvsRow = [];
  19498. for ( x = 0; x <= widthSegments; x ++ ) {
  19499. var u = x / widthSegments;
  19500. var v = y / heightSegments;
  19501. var vertex = new THREE.Vector3();
  19502. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19503. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19504. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19505. this.vertices.push( vertex );
  19506. verticesRow.push( this.vertices.length - 1 );
  19507. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19508. }
  19509. vertices.push( verticesRow );
  19510. uvs.push( uvsRow );
  19511. }
  19512. for ( y = 0; y < heightSegments; y ++ ) {
  19513. for ( x = 0; x < widthSegments; x ++ ) {
  19514. var v1 = vertices[ y ][ x + 1 ];
  19515. var v2 = vertices[ y ][ x ];
  19516. var v3 = vertices[ y + 1 ][ x ];
  19517. var v4 = vertices[ y + 1 ][ x + 1 ];
  19518. var n1 = this.vertices[ v1 ].clone().normalize();
  19519. var n2 = this.vertices[ v2 ].clone().normalize();
  19520. var n3 = this.vertices[ v3 ].clone().normalize();
  19521. var n4 = this.vertices[ v4 ].clone().normalize();
  19522. var uv1 = uvs[ y ][ x + 1 ].clone();
  19523. var uv2 = uvs[ y ][ x ].clone();
  19524. var uv3 = uvs[ y + 1 ][ x ].clone();
  19525. var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
  19526. if ( Math.abs( this.vertices[ v1 ].y ) === radius ) {
  19527. uv1.x = ( uv1.x + uv2.x ) / 2;
  19528. this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
  19529. this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
  19530. } else if ( Math.abs( this.vertices[ v3 ].y ) === radius ) {
  19531. uv3.x = ( uv3.x + uv4.x ) / 2;
  19532. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  19533. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19534. } else {
  19535. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19536. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19537. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19538. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19539. }
  19540. }
  19541. }
  19542. this.computeFaceNormals();
  19543. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19544. };
  19545. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19546. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  19547. THREE.SphereGeometry.prototype.clone = function () {
  19548. var geometry = new THREE.SphereGeometry(
  19549. this.parameters.radius,
  19550. this.parameters.widthSegments,
  19551. this.parameters.heightSegments,
  19552. this.parameters.phiStart,
  19553. this.parameters.phiLength,
  19554. this.parameters.thetaStart,
  19555. this.parameters.thetaLength
  19556. );
  19557. return geometry;
  19558. };
  19559. // File:src/extras/geometries/SphereBufferGeometry.js
  19560. /**
  19561. * @author benaadams / https://twitter.com/ben_a_adams
  19562. * based on THREE.SphereGeometry
  19563. */
  19564. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19565. THREE.BufferGeometry.call( this );
  19566. this.type = 'SphereBufferGeometry';
  19567. this.parameters = {
  19568. radius: radius,
  19569. widthSegments: widthSegments,
  19570. heightSegments: heightSegments,
  19571. phiStart: phiStart,
  19572. phiLength: phiLength,
  19573. thetaStart: thetaStart,
  19574. thetaLength: thetaLength
  19575. };
  19576. radius = radius || 50;
  19577. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19578. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19579. phiStart = phiStart !== undefined ? phiStart : 0;
  19580. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19581. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19582. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19583. var thetaEnd = thetaStart + thetaLength;
  19584. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  19585. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19586. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19587. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  19588. var index = 0, vertices = [], normal = new THREE.Vector3();
  19589. for ( var y = 0; y <= heightSegments; y ++ ) {
  19590. var verticesRow = [];
  19591. var v = y / heightSegments;
  19592. for ( var x = 0; x <= widthSegments; x ++ ) {
  19593. var u = x / widthSegments;
  19594. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19595. var py = radius * Math.cos( thetaStart + v * thetaLength );
  19596. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19597. normal.set( px, py, pz ).normalize();
  19598. positions.setXYZ( index, px, py, pz );
  19599. normals.setXYZ( index, normal.x, normal.y, normal.z );
  19600. uvs.setXY( index, u, 1 - v );
  19601. verticesRow.push( index );
  19602. index ++;
  19603. }
  19604. vertices.push( verticesRow );
  19605. }
  19606. var indices = [];
  19607. for ( var y = 0; y < heightSegments; y ++ ) {
  19608. for ( var x = 0; x < widthSegments; x ++ ) {
  19609. var v1 = vertices[ y ][ x + 1 ];
  19610. var v2 = vertices[ y ][ x ];
  19611. var v3 = vertices[ y + 1 ][ x ];
  19612. var v4 = vertices[ y + 1 ][ x + 1 ];
  19613. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  19614. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  19615. }
  19616. }
  19617. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19618. this.addAttribute( 'position', positions );
  19619. this.addAttribute( 'normal', normals );
  19620. this.addAttribute( 'uv', uvs );
  19621. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19622. };
  19623. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19624. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  19625. THREE.SphereBufferGeometry.prototype.clone = function () {
  19626. var geometry = new THREE.SphereBufferGeometry(
  19627. this.parameters.radius,
  19628. this.parameters.widthSegments,
  19629. this.parameters.heightSegments,
  19630. this.parameters.phiStart,
  19631. this.parameters.phiLength,
  19632. this.parameters.thetaStart,
  19633. this.parameters.thetaLength
  19634. );
  19635. geometry.copy( this );
  19636. return geometry;
  19637. };
  19638. // File:src/extras/geometries/TextGeometry.js
  19639. /**
  19640. * @author zz85 / http://www.lab4games.net/zz85/blog
  19641. * @author alteredq / http://alteredqualia.com/
  19642. *
  19643. * For creating 3D text geometry in three.js
  19644. *
  19645. * Text = 3D Text
  19646. *
  19647. * parameters = {
  19648. * size: <float>, // size of the text
  19649. * height: <float>, // thickness to extrude text
  19650. * curveSegments: <int>, // number of points on the curves
  19651. *
  19652. * font: <string>, // font name
  19653. * weight: <string>, // font weight (normal, bold)
  19654. * style: <string>, // font style (normal, italics)
  19655. *
  19656. * bevelEnabled: <bool>, // turn on bevel
  19657. * bevelThickness: <float>, // how deep into text bevel goes
  19658. * bevelSize: <float>, // how far from text outline is bevel
  19659. * }
  19660. *
  19661. */
  19662. /* Usage Examples
  19663. // TextGeometry wrapper
  19664. var text3d = new TextGeometry( text, options );
  19665. // Complete manner
  19666. var textShapes = THREE.FontUtils.generateShapes( text, options );
  19667. var text3d = new ExtrudeGeometry( textShapes, options );
  19668. */
  19669. THREE.TextGeometry = function ( text, parameters ) {
  19670. parameters = parameters || {};
  19671. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  19672. // translate parameters to ExtrudeGeometry API
  19673. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  19674. // defaults
  19675. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19676. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19677. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19678. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  19679. this.type = 'TextGeometry';
  19680. };
  19681. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  19682. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  19683. // File:src/extras/geometries/TorusGeometry.js
  19684. /**
  19685. * @author oosmoxiecode
  19686. * @author mrdoob / http://mrdoob.com/
  19687. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  19688. */
  19689. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  19690. THREE.Geometry.call( this );
  19691. this.type = 'TorusGeometry';
  19692. this.parameters = {
  19693. radius: radius,
  19694. tube: tube,
  19695. radialSegments: radialSegments,
  19696. tubularSegments: tubularSegments,
  19697. arc: arc
  19698. };
  19699. radius = radius || 100;
  19700. tube = tube || 40;
  19701. radialSegments = radialSegments || 8;
  19702. tubularSegments = tubularSegments || 6;
  19703. arc = arc || Math.PI * 2;
  19704. var center = new THREE.Vector3(), uvs = [], normals = [];
  19705. for ( var j = 0; j <= radialSegments; j ++ ) {
  19706. for ( var i = 0; i <= tubularSegments; i ++ ) {
  19707. var u = i / tubularSegments * arc;
  19708. var v = j / radialSegments * Math.PI * 2;
  19709. center.x = radius * Math.cos( u );
  19710. center.y = radius * Math.sin( u );
  19711. var vertex = new THREE.Vector3();
  19712. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  19713. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  19714. vertex.z = tube * Math.sin( v );
  19715. this.vertices.push( vertex );
  19716. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  19717. normals.push( vertex.clone().sub( center ).normalize() );
  19718. }
  19719. }
  19720. for ( var j = 1; j <= radialSegments; j ++ ) {
  19721. for ( var i = 1; i <= tubularSegments; i ++ ) {
  19722. var a = ( tubularSegments + 1 ) * j + i - 1;
  19723. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  19724. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  19725. var d = ( tubularSegments + 1 ) * j + i;
  19726. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  19727. this.faces.push( face );
  19728. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  19729. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  19730. this.faces.push( face );
  19731. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  19732. }
  19733. }
  19734. this.computeFaceNormals();
  19735. };
  19736. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19737. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  19738. THREE.TorusGeometry.prototype.clone = function () {
  19739. var geometry = new THREE.TorusGeometry(
  19740. this.parameters.radius,
  19741. this.parameters.tube,
  19742. this.parameters.radialSegments,
  19743. this.parameters.tubularSegments,
  19744. this.parameters.arc
  19745. );
  19746. return geometry;
  19747. };
  19748. // File:src/extras/geometries/TorusKnotGeometry.js
  19749. /**
  19750. * @author oosmoxiecode
  19751. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  19752. */
  19753. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  19754. THREE.Geometry.call( this );
  19755. this.type = 'TorusKnotGeometry';
  19756. this.parameters = {
  19757. radius: radius,
  19758. tube: tube,
  19759. radialSegments: radialSegments,
  19760. tubularSegments: tubularSegments,
  19761. p: p,
  19762. q: q,
  19763. heightScale: heightScale
  19764. };
  19765. radius = radius || 100;
  19766. tube = tube || 40;
  19767. radialSegments = radialSegments || 64;
  19768. tubularSegments = tubularSegments || 8;
  19769. p = p || 2;
  19770. q = q || 3;
  19771. heightScale = heightScale || 1;
  19772. var grid = new Array( radialSegments );
  19773. var tang = new THREE.Vector3();
  19774. var n = new THREE.Vector3();
  19775. var bitan = new THREE.Vector3();
  19776. for ( var i = 0; i < radialSegments; ++ i ) {
  19777. grid[ i ] = new Array( tubularSegments );
  19778. var u = i / radialSegments * 2 * p * Math.PI;
  19779. var p1 = getPos( u, q, p, radius, heightScale );
  19780. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  19781. tang.subVectors( p2, p1 );
  19782. n.addVectors( p2, p1 );
  19783. bitan.crossVectors( tang, n );
  19784. n.crossVectors( bitan, tang );
  19785. bitan.normalize();
  19786. n.normalize();
  19787. for ( var j = 0; j < tubularSegments; ++ j ) {
  19788. var v = j / tubularSegments * 2 * Math.PI;
  19789. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19790. var cy = tube * Math.sin( v );
  19791. var pos = new THREE.Vector3();
  19792. pos.x = p1.x + cx * n.x + cy * bitan.x;
  19793. pos.y = p1.y + cx * n.y + cy * bitan.y;
  19794. pos.z = p1.z + cx * n.z + cy * bitan.z;
  19795. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  19796. }
  19797. }
  19798. for ( var i = 0; i < radialSegments; ++ i ) {
  19799. for ( var j = 0; j < tubularSegments; ++ j ) {
  19800. var ip = ( i + 1 ) % radialSegments;
  19801. var jp = ( j + 1 ) % tubularSegments;
  19802. var a = grid[ i ][ j ];
  19803. var b = grid[ ip ][ j ];
  19804. var c = grid[ ip ][ jp ];
  19805. var d = grid[ i ][ jp ];
  19806. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  19807. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  19808. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  19809. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  19810. this.faces.push( new THREE.Face3( a, b, d ) );
  19811. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19812. this.faces.push( new THREE.Face3( b, c, d ) );
  19813. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19814. }
  19815. }
  19816. this.computeFaceNormals();
  19817. this.computeVertexNormals();
  19818. function getPos( u, in_q, in_p, radius, heightScale ) {
  19819. var cu = Math.cos( u );
  19820. var su = Math.sin( u );
  19821. var quOverP = in_q / in_p * u;
  19822. var cs = Math.cos( quOverP );
  19823. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  19824. var ty = radius * ( 2 + cs ) * su * 0.5;
  19825. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  19826. return new THREE.Vector3( tx, ty, tz );
  19827. }
  19828. };
  19829. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19830. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  19831. THREE.TorusKnotGeometry.prototype.clone = function () {
  19832. var geometry = new THREE.TorusKnotGeometry(
  19833. this.parameters.radius,
  19834. this.parameters.tube,
  19835. this.parameters.radialSegments,
  19836. this.parameters.tubularSegments,
  19837. this.parameters.p,
  19838. this.parameters.q,
  19839. this.parameters.heightScale
  19840. );
  19841. return geometry;
  19842. };
  19843. // File:src/extras/geometries/TubeGeometry.js
  19844. /**
  19845. * @author WestLangley / https://github.com/WestLangley
  19846. * @author zz85 / https://github.com/zz85
  19847. * @author miningold / https://github.com/miningold
  19848. * @author jonobr1 / https://github.com/jonobr1
  19849. *
  19850. * Modified from the TorusKnotGeometry by @oosmoxiecode
  19851. *
  19852. * Creates a tube which extrudes along a 3d spline
  19853. *
  19854. * Uses parallel transport frames as described in
  19855. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  19856. */
  19857. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  19858. THREE.Geometry.call( this );
  19859. this.type = 'TubeGeometry';
  19860. this.parameters = {
  19861. path: path,
  19862. segments: segments,
  19863. radius: radius,
  19864. radialSegments: radialSegments,
  19865. closed: closed
  19866. };
  19867. segments = segments || 64;
  19868. radius = radius || 1;
  19869. radialSegments = radialSegments || 8;
  19870. closed = closed || false;
  19871. taper = taper || THREE.TubeGeometry.NoTaper;
  19872. var grid = [];
  19873. var scope = this,
  19874. tangent,
  19875. normal,
  19876. binormal,
  19877. numpoints = segments + 1,
  19878. u, v, r,
  19879. cx, cy,
  19880. pos, pos2 = new THREE.Vector3(),
  19881. i, j,
  19882. ip, jp,
  19883. a, b, c, d,
  19884. uva, uvb, uvc, uvd;
  19885. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  19886. tangents = frames.tangents,
  19887. normals = frames.normals,
  19888. binormals = frames.binormals;
  19889. // proxy internals
  19890. this.tangents = tangents;
  19891. this.normals = normals;
  19892. this.binormals = binormals;
  19893. function vert( x, y, z ) {
  19894. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  19895. }
  19896. // construct the grid
  19897. for ( i = 0; i < numpoints; i ++ ) {
  19898. grid[ i ] = [];
  19899. u = i / ( numpoints - 1 );
  19900. pos = path.getPointAt( u );
  19901. tangent = tangents[ i ];
  19902. normal = normals[ i ];
  19903. binormal = binormals[ i ];
  19904. r = radius * taper( u );
  19905. for ( j = 0; j < radialSegments; j ++ ) {
  19906. v = j / radialSegments * 2 * Math.PI;
  19907. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19908. cy = r * Math.sin( v );
  19909. pos2.copy( pos );
  19910. pos2.x += cx * normal.x + cy * binormal.x;
  19911. pos2.y += cx * normal.y + cy * binormal.y;
  19912. pos2.z += cx * normal.z + cy * binormal.z;
  19913. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  19914. }
  19915. }
  19916. // construct the mesh
  19917. for ( i = 0; i < segments; i ++ ) {
  19918. for ( j = 0; j < radialSegments; j ++ ) {
  19919. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  19920. jp = ( j + 1 ) % radialSegments;
  19921. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  19922. b = grid[ ip ][ j ];
  19923. c = grid[ ip ][ jp ];
  19924. d = grid[ i ][ jp ];
  19925. uva = new THREE.Vector2( i / segments, j / radialSegments );
  19926. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  19927. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  19928. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  19929. this.faces.push( new THREE.Face3( a, b, d ) );
  19930. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19931. this.faces.push( new THREE.Face3( b, c, d ) );
  19932. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19933. }
  19934. }
  19935. this.computeFaceNormals();
  19936. this.computeVertexNormals();
  19937. };
  19938. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19939. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  19940. THREE.TubeGeometry.NoTaper = function ( u ) {
  19941. return 1;
  19942. };
  19943. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  19944. return Math.sin( Math.PI * u );
  19945. };
  19946. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  19947. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  19948. var normal = new THREE.Vector3(),
  19949. tangents = [],
  19950. normals = [],
  19951. binormals = [],
  19952. vec = new THREE.Vector3(),
  19953. mat = new THREE.Matrix4(),
  19954. numpoints = segments + 1,
  19955. theta,
  19956. epsilon = 0.0001,
  19957. smallest,
  19958. tx, ty, tz,
  19959. i, u;
  19960. // expose internals
  19961. this.tangents = tangents;
  19962. this.normals = normals;
  19963. this.binormals = binormals;
  19964. // compute the tangent vectors for each segment on the path
  19965. for ( i = 0; i < numpoints; i ++ ) {
  19966. u = i / ( numpoints - 1 );
  19967. tangents[ i ] = path.getTangentAt( u );
  19968. tangents[ i ].normalize();
  19969. }
  19970. initialNormal3();
  19971. /*
  19972. function initialNormal1(lastBinormal) {
  19973. // fixed start binormal. Has dangers of 0 vectors
  19974. normals[ 0 ] = new THREE.Vector3();
  19975. binormals[ 0 ] = new THREE.Vector3();
  19976. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  19977. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  19978. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  19979. }
  19980. function initialNormal2() {
  19981. // This uses the Frenet-Serret formula for deriving binormal
  19982. var t2 = path.getTangentAt( epsilon );
  19983. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  19984. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  19985. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  19986. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  19987. }
  19988. */
  19989. function initialNormal3() {
  19990. // select an initial normal vector perpendicular to the first tangent vector,
  19991. // and in the direction of the smallest tangent xyz component
  19992. normals[ 0 ] = new THREE.Vector3();
  19993. binormals[ 0 ] = new THREE.Vector3();
  19994. smallest = Number.MAX_VALUE;
  19995. tx = Math.abs( tangents[ 0 ].x );
  19996. ty = Math.abs( tangents[ 0 ].y );
  19997. tz = Math.abs( tangents[ 0 ].z );
  19998. if ( tx <= smallest ) {
  19999. smallest = tx;
  20000. normal.set( 1, 0, 0 );
  20001. }
  20002. if ( ty <= smallest ) {
  20003. smallest = ty;
  20004. normal.set( 0, 1, 0 );
  20005. }
  20006. if ( tz <= smallest ) {
  20007. normal.set( 0, 0, 1 );
  20008. }
  20009. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20010. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20011. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20012. }
  20013. // compute the slowly-varying normal and binormal vectors for each segment on the path
  20014. for ( i = 1; i < numpoints; i ++ ) {
  20015. normals[ i ] = normals[ i - 1 ].clone();
  20016. binormals[ i ] = binormals[ i - 1 ].clone();
  20017. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20018. if ( vec.length() > epsilon ) {
  20019. vec.normalize();
  20020. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20021. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20022. }
  20023. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20024. }
  20025. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20026. if ( closed ) {
  20027. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  20028. theta /= ( numpoints - 1 );
  20029. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  20030. theta = - theta;
  20031. }
  20032. for ( i = 1; i < numpoints; i ++ ) {
  20033. // twist a little...
  20034. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20035. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20036. }
  20037. }
  20038. };
  20039. // File:src/extras/geometries/PolyhedronGeometry.js
  20040. /**
  20041. * @author clockworkgeek / https://github.com/clockworkgeek
  20042. * @author timothypratley / https://github.com/timothypratley
  20043. * @author WestLangley / http://github.com/WestLangley
  20044. */
  20045. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  20046. THREE.Geometry.call( this );
  20047. this.type = 'PolyhedronGeometry';
  20048. this.parameters = {
  20049. vertices: vertices,
  20050. indices: indices,
  20051. radius: radius,
  20052. detail: detail
  20053. };
  20054. radius = radius || 1;
  20055. detail = detail || 0;
  20056. var that = this;
  20057. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  20058. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  20059. }
  20060. var p = this.vertices;
  20061. var faces = [];
  20062. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  20063. var v1 = p[ indices[ i ] ];
  20064. var v2 = p[ indices[ i + 1 ] ];
  20065. var v3 = p[ indices[ i + 2 ] ];
  20066. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  20067. }
  20068. var centroid = new THREE.Vector3();
  20069. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20070. subdivide( faces[ i ], detail );
  20071. }
  20072. // Handle case when face straddles the seam
  20073. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  20074. var uvs = this.faceVertexUvs[ 0 ][ i ];
  20075. var x0 = uvs[ 0 ].x;
  20076. var x1 = uvs[ 1 ].x;
  20077. var x2 = uvs[ 2 ].x;
  20078. var max = Math.max( x0, Math.max( x1, x2 ) );
  20079. var min = Math.min( x0, Math.min( x1, x2 ) );
  20080. if ( max > 0.9 && min < 0.1 ) {
  20081. // 0.9 is somewhat arbitrary
  20082. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  20083. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  20084. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  20085. }
  20086. }
  20087. // Apply radius
  20088. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  20089. this.vertices[ i ].multiplyScalar( radius );
  20090. }
  20091. // Merge vertices
  20092. this.mergeVertices();
  20093. this.computeFaceNormals();
  20094. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20095. // Project vector onto sphere's surface
  20096. function prepare( vector ) {
  20097. var vertex = vector.normalize().clone();
  20098. vertex.index = that.vertices.push( vertex ) - 1;
  20099. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  20100. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  20101. var v = inclination( vector ) / Math.PI + 0.5;
  20102. vertex.uv = new THREE.Vector2( u, 1 - v );
  20103. return vertex;
  20104. }
  20105. // Approximate a curved face with recursively sub-divided triangles.
  20106. function make( v1, v2, v3 ) {
  20107. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  20108. that.faces.push( face );
  20109. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  20110. var azi = azimuth( centroid );
  20111. that.faceVertexUvs[ 0 ].push( [
  20112. correctUV( v1.uv, v1, azi ),
  20113. correctUV( v2.uv, v2, azi ),
  20114. correctUV( v3.uv, v3, azi )
  20115. ] );
  20116. }
  20117. // Analytically subdivide a face to the required detail level.
  20118. function subdivide( face, detail ) {
  20119. var cols = Math.pow( 2, detail );
  20120. var a = prepare( that.vertices[ face.a ] );
  20121. var b = prepare( that.vertices[ face.b ] );
  20122. var c = prepare( that.vertices[ face.c ] );
  20123. var v = [];
  20124. // Construct all of the vertices for this subdivision.
  20125. for ( var i = 0 ; i <= cols; i ++ ) {
  20126. v[ i ] = [];
  20127. var aj = prepare( a.clone().lerp( c, i / cols ) );
  20128. var bj = prepare( b.clone().lerp( c, i / cols ) );
  20129. var rows = cols - i;
  20130. for ( var j = 0; j <= rows; j ++ ) {
  20131. if ( j === 0 && i === cols ) {
  20132. v[ i ][ j ] = aj;
  20133. } else {
  20134. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  20135. }
  20136. }
  20137. }
  20138. // Construct all of the faces.
  20139. for ( var i = 0; i < cols ; i ++ ) {
  20140. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  20141. var k = Math.floor( j / 2 );
  20142. if ( j % 2 === 0 ) {
  20143. make(
  20144. v[ i ][ k + 1 ],
  20145. v[ i + 1 ][ k ],
  20146. v[ i ][ k ]
  20147. );
  20148. } else {
  20149. make(
  20150. v[ i ][ k + 1 ],
  20151. v[ i + 1 ][ k + 1 ],
  20152. v[ i + 1 ][ k ]
  20153. );
  20154. }
  20155. }
  20156. }
  20157. }
  20158. // Angle around the Y axis, counter-clockwise when looking from above.
  20159. function azimuth( vector ) {
  20160. return Math.atan2( vector.z, - vector.x );
  20161. }
  20162. // Angle above the XZ plane.
  20163. function inclination( vector ) {
  20164. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  20165. }
  20166. // Texture fixing helper. Spheres have some odd behaviours.
  20167. function correctUV( uv, vector, azimuth ) {
  20168. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  20169. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  20170. return uv.clone();
  20171. }
  20172. };
  20173. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20174. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  20175. THREE.PolyhedronGeometry.prototype.clone = function () {
  20176. var geometry = new THREE.PolyhedronGeometry(
  20177. this.parameters.vertices,
  20178. this.parameters.indices,
  20179. this.parameters.radius,
  20180. this.parameters.detail
  20181. );
  20182. return geometry.copy( this );
  20183. };
  20184. THREE.PolyhedronGeometry.prototype.copy = function ( source ) {
  20185. THREE.Geometry.prototype.copy.call( this, source );
  20186. return this;
  20187. };
  20188. // File:src/extras/geometries/DodecahedronGeometry.js
  20189. /**
  20190. * @author Abe Pazos / https://hamoid.com
  20191. */
  20192. THREE.DodecahedronGeometry = function ( radius, detail ) {
  20193. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20194. var r = 1 / t;
  20195. var vertices = [
  20196. // (±1, ±1, ±1)
  20197. - 1, - 1, - 1, - 1, - 1, 1,
  20198. - 1, 1, - 1, - 1, 1, 1,
  20199. 1, - 1, - 1, 1, - 1, 1,
  20200. 1, 1, - 1, 1, 1, 1,
  20201. // (0, ±1/φ, ±φ)
  20202. 0, - r, - t, 0, - r, t,
  20203. 0, r, - t, 0, r, t,
  20204. // (±1/φ, ±φ, 0)
  20205. - r, - t, 0, - r, t, 0,
  20206. r, - t, 0, r, t, 0,
  20207. // (±φ, 0, ±1/φ)
  20208. - t, 0, - r, t, 0, - r,
  20209. - t, 0, r, t, 0, r
  20210. ];
  20211. var indices = [
  20212. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  20213. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  20214. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  20215. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  20216. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  20217. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  20218. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  20219. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  20220. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  20221. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  20222. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  20223. 1, 12, 14, 1, 14, 5, 1, 5, 9
  20224. ];
  20225. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20226. this.type = 'DodecahedronGeometry';
  20227. this.parameters = {
  20228. radius: radius,
  20229. detail: detail
  20230. };
  20231. };
  20232. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20233. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  20234. THREE.DodecahedronGeometry.prototype.clone = function () {
  20235. var geometry = new THREE.DodecahedronGeometry(
  20236. this.parameters.radius,
  20237. this.parameters.detail
  20238. );
  20239. geometry.copy( this );
  20240. return geometry;
  20241. };
  20242. // File:src/extras/geometries/IcosahedronGeometry.js
  20243. /**
  20244. * @author timothypratley / https://github.com/timothypratley
  20245. */
  20246. THREE.IcosahedronGeometry = function ( radius, detail ) {
  20247. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20248. var vertices = [
  20249. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20250. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20251. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20252. ];
  20253. var indices = [
  20254. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20255. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20256. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20257. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20258. ];
  20259. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20260. this.type = 'IcosahedronGeometry';
  20261. this.parameters = {
  20262. radius: radius,
  20263. detail: detail
  20264. };
  20265. };
  20266. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20267. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20268. THREE.IcosahedronGeometry.prototype.clone = function () {
  20269. var geometry = new THREE.IcosahedronGeometry(
  20270. this.parameters.radius,
  20271. this.parameters.detail
  20272. );
  20273. geometry.copy( this );
  20274. return geometry;
  20275. };
  20276. // File:src/extras/geometries/OctahedronGeometry.js
  20277. /**
  20278. * @author timothypratley / https://github.com/timothypratley
  20279. */
  20280. THREE.OctahedronGeometry = function ( radius, detail ) {
  20281. var vertices = [
  20282. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  20283. ];
  20284. var indices = [
  20285. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20286. ];
  20287. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20288. this.type = 'OctahedronGeometry';
  20289. this.parameters = {
  20290. radius: radius,
  20291. detail: detail
  20292. };
  20293. };
  20294. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20295. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20296. THREE.OctahedronGeometry.prototype.clone = function () {
  20297. var geometry = new THREE.OctahedronGeometry(
  20298. this.parameters.radius,
  20299. this.parameters.detail
  20300. );
  20301. geometry.copy( this );
  20302. return geometry;
  20303. };
  20304. // File:src/extras/geometries/TetrahedronGeometry.js
  20305. /**
  20306. * @author timothypratley / https://github.com/timothypratley
  20307. */
  20308. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20309. var vertices = [
  20310. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20311. ];
  20312. var indices = [
  20313. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20314. ];
  20315. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20316. this.type = 'TetrahedronGeometry';
  20317. this.parameters = {
  20318. radius: radius,
  20319. detail: detail
  20320. };
  20321. };
  20322. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20323. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20324. THREE.TetrahedronGeometry.prototype.clone = function () {
  20325. var geometry = new THREE.TetrahedronGeometry(
  20326. this.parameters.radius,
  20327. this.parameters.detail
  20328. );
  20329. geometry.copy( this );
  20330. return geometry;
  20331. };
  20332. // File:src/extras/geometries/ParametricGeometry.js
  20333. /**
  20334. * @author zz85 / https://github.com/zz85
  20335. * Parametric Surfaces Geometry
  20336. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20337. *
  20338. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20339. *
  20340. */
  20341. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20342. THREE.Geometry.call( this );
  20343. this.type = 'ParametricGeometry';
  20344. this.parameters = {
  20345. func: func,
  20346. slices: slices,
  20347. stacks: stacks
  20348. };
  20349. var verts = this.vertices;
  20350. var faces = this.faces;
  20351. var uvs = this.faceVertexUvs[ 0 ];
  20352. var i, j, p;
  20353. var u, v;
  20354. var sliceCount = slices + 1;
  20355. for ( i = 0; i <= stacks; i ++ ) {
  20356. v = i / stacks;
  20357. for ( j = 0; j <= slices; j ++ ) {
  20358. u = j / slices;
  20359. p = func( u, v );
  20360. verts.push( p );
  20361. }
  20362. }
  20363. var a, b, c, d;
  20364. var uva, uvb, uvc, uvd;
  20365. for ( i = 0; i < stacks; i ++ ) {
  20366. for ( j = 0; j < slices; j ++ ) {
  20367. a = i * sliceCount + j;
  20368. b = i * sliceCount + j + 1;
  20369. c = ( i + 1 ) * sliceCount + j + 1;
  20370. d = ( i + 1 ) * sliceCount + j;
  20371. uva = new THREE.Vector2( j / slices, i / stacks );
  20372. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  20373. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  20374. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  20375. faces.push( new THREE.Face3( a, b, d ) );
  20376. uvs.push( [ uva, uvb, uvd ] );
  20377. faces.push( new THREE.Face3( b, c, d ) );
  20378. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  20379. }
  20380. }
  20381. // console.log(this);
  20382. // magic bullet
  20383. // var diff = this.mergeVertices();
  20384. // console.log('removed ', diff, ' vertices by merging');
  20385. this.computeFaceNormals();
  20386. this.computeVertexNormals();
  20387. };
  20388. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20389. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  20390. // File:src/extras/geometries/WireframeGeometry.js
  20391. /**
  20392. * @author mrdoob / http://mrdoob.com/
  20393. */
  20394. THREE.WireframeGeometry = function ( geometry ) {
  20395. THREE.BufferGeometry.call( this );
  20396. var edge = [ 0, 0 ], hash = {};
  20397. var sortFunction = function ( a, b ) {
  20398. return a - b;
  20399. };
  20400. var keys = [ 'a', 'b', 'c' ];
  20401. if ( geometry instanceof THREE.Geometry ) {
  20402. var vertices = geometry.vertices;
  20403. var faces = geometry.faces;
  20404. var numEdges = 0;
  20405. // allocate maximal size
  20406. var edges = new Uint32Array( 6 * faces.length );
  20407. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20408. var face = faces[ i ];
  20409. for ( var j = 0; j < 3; j ++ ) {
  20410. edge[ 0 ] = face[ keys[ j ] ];
  20411. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  20412. edge.sort( sortFunction );
  20413. var key = edge.toString();
  20414. if ( hash[ key ] === undefined ) {
  20415. edges[ 2 * numEdges ] = edge[ 0 ];
  20416. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20417. hash[ key ] = true;
  20418. numEdges ++;
  20419. }
  20420. }
  20421. }
  20422. var coords = new Float32Array( numEdges * 2 * 3 );
  20423. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20424. for ( var j = 0; j < 2; j ++ ) {
  20425. var vertex = vertices[ edges [ 2 * i + j ] ];
  20426. var index = 6 * i + 3 * j;
  20427. coords[ index + 0 ] = vertex.x;
  20428. coords[ index + 1 ] = vertex.y;
  20429. coords[ index + 2 ] = vertex.z;
  20430. }
  20431. }
  20432. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20433. } else if ( geometry instanceof THREE.BufferGeometry ) {
  20434. if ( geometry.attributes.index !== undefined ) {
  20435. // Indexed BufferGeometry
  20436. var vertices = geometry.attributes.position;
  20437. var indices = geometry.attributes.index.array;
  20438. var drawcalls = geometry.drawcalls;
  20439. var numEdges = 0;
  20440. if ( drawcalls.length === 0 ) {
  20441. drawcalls = [ { count : indices.length, index : 0, start : 0 } ];
  20442. }
  20443. // allocate maximal size
  20444. var edges = new Uint32Array( 2 * indices.length );
  20445. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  20446. var start = drawcalls[ o ].start;
  20447. var count = drawcalls[ o ].count;
  20448. var index = drawcalls[ o ].index;
  20449. for ( var i = start, il = start + count; i < il; i += 3 ) {
  20450. for ( var j = 0; j < 3; j ++ ) {
  20451. edge[ 0 ] = index + indices[ i + j ];
  20452. edge[ 1 ] = index + indices[ i + ( j + 1 ) % 3 ];
  20453. edge.sort( sortFunction );
  20454. var key = edge.toString();
  20455. if ( hash[ key ] === undefined ) {
  20456. edges[ 2 * numEdges ] = edge[ 0 ];
  20457. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20458. hash[ key ] = true;
  20459. numEdges ++;
  20460. }
  20461. }
  20462. }
  20463. }
  20464. var coords = new Float32Array( numEdges * 2 * 3 );
  20465. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20466. for ( var j = 0; j < 2; j ++ ) {
  20467. var index = 6 * i + 3 * j;
  20468. var index2 = edges[ 2 * i + j ];
  20469. coords[ index + 0 ] = vertices.getX( index2 );
  20470. coords[ index + 1 ] = vertices.getY( index2 );
  20471. coords[ index + 2 ] = vertices.getZ( index2 );
  20472. }
  20473. }
  20474. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20475. } else {
  20476. // non-indexed BufferGeometry
  20477. var vertices = geometry.attributes.position.array;
  20478. var numEdges = vertices.length / 3;
  20479. var numTris = numEdges / 3;
  20480. var coords = new Float32Array( numEdges * 2 * 3 );
  20481. for ( var i = 0, l = numTris; i < l; i ++ ) {
  20482. for ( var j = 0; j < 3; j ++ ) {
  20483. var index = 18 * i + 6 * j;
  20484. var index1 = 9 * i + 3 * j;
  20485. coords[ index + 0 ] = vertices[ index1 ];
  20486. coords[ index + 1 ] = vertices[ index1 + 1 ];
  20487. coords[ index + 2 ] = vertices[ index1 + 2 ];
  20488. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  20489. coords[ index + 3 ] = vertices[ index2 ];
  20490. coords[ index + 4 ] = vertices[ index2 + 1 ];
  20491. coords[ index + 5 ] = vertices[ index2 + 2 ];
  20492. }
  20493. }
  20494. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20495. }
  20496. }
  20497. };
  20498. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20499. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  20500. // File:src/extras/helpers/AxisHelper.js
  20501. /**
  20502. * @author sroucheray / http://sroucheray.org/
  20503. * @author mrdoob / http://mrdoob.com/
  20504. */
  20505. THREE.AxisHelper = function ( size ) {
  20506. size = size || 1;
  20507. var vertices = new Float32Array( [
  20508. 0, 0, 0, size, 0, 0,
  20509. 0, 0, 0, 0, size, 0,
  20510. 0, 0, 0, 0, 0, size
  20511. ] );
  20512. var colors = new Float32Array( [
  20513. 1, 0, 0, 1, 0.6, 0,
  20514. 0, 1, 0, 0.6, 1, 0,
  20515. 0, 0, 1, 0, 0.6, 1
  20516. ] );
  20517. var geometry = new THREE.BufferGeometry();
  20518. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20519. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  20520. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20521. THREE.LineSegments.call( this, geometry, material );
  20522. };
  20523. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20524. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  20525. // File:src/extras/helpers/ArrowHelper.js
  20526. /**
  20527. * @author WestLangley / http://github.com/WestLangley
  20528. * @author zz85 / http://github.com/zz85
  20529. * @author bhouston / http://exocortex.com
  20530. *
  20531. * Creates an arrow for visualizing directions
  20532. *
  20533. * Parameters:
  20534. * dir - Vector3
  20535. * origin - Vector3
  20536. * length - Number
  20537. * color - color in hex value
  20538. * headLength - Number
  20539. * headWidth - Number
  20540. */
  20541. THREE.ArrowHelper = ( function () {
  20542. var lineGeometry = new THREE.Geometry();
  20543. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  20544. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  20545. coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  20546. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  20547. // dir is assumed to be normalized
  20548. THREE.Object3D.call( this );
  20549. if ( color === undefined ) color = 0xffff00;
  20550. if ( length === undefined ) length = 1;
  20551. if ( headLength === undefined ) headLength = 0.2 * length;
  20552. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20553. this.position.copy( origin );
  20554. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  20555. this.line.matrixAutoUpdate = false;
  20556. this.add( this.line );
  20557. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  20558. this.cone.matrixAutoUpdate = false;
  20559. this.add( this.cone );
  20560. this.setDirection( dir );
  20561. this.setLength( length, headLength, headWidth );
  20562. }
  20563. }() );
  20564. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  20565. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  20566. THREE.ArrowHelper.prototype.setDirection = ( function () {
  20567. var axis = new THREE.Vector3();
  20568. var radians;
  20569. return function setDirection( dir ) {
  20570. // dir is assumed to be normalized
  20571. if ( dir.y > 0.99999 ) {
  20572. this.quaternion.set( 0, 0, 0, 1 );
  20573. } else if ( dir.y < - 0.99999 ) {
  20574. this.quaternion.set( 1, 0, 0, 0 );
  20575. } else {
  20576. axis.set( dir.z, 0, - dir.x ).normalize();
  20577. radians = Math.acos( dir.y );
  20578. this.quaternion.setFromAxisAngle( axis, radians );
  20579. }
  20580. };
  20581. }() );
  20582. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  20583. if ( headLength === undefined ) headLength = 0.2 * length;
  20584. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20585. this.line.scale.set( 1, length - headLength, 1 );
  20586. this.line.updateMatrix();
  20587. this.cone.scale.set( headWidth, headLength, headWidth );
  20588. this.cone.position.y = length;
  20589. this.cone.updateMatrix();
  20590. };
  20591. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  20592. this.line.material.color.set( color );
  20593. this.cone.material.color.set( color );
  20594. };
  20595. // File:src/extras/helpers/BoxHelper.js
  20596. /**
  20597. * @author mrdoob / http://mrdoob.com/
  20598. */
  20599. THREE.BoxHelper = function ( object ) {
  20600. var geometry = new THREE.BufferGeometry();
  20601. geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( 72 ), 3 ) );
  20602. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  20603. if ( object !== undefined ) {
  20604. this.update( object );
  20605. }
  20606. };
  20607. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20608. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  20609. THREE.BoxHelper.prototype.update = ( function () {
  20610. var box = new THREE.Box3();
  20611. return function ( object ) {
  20612. box.setFromObject( object );
  20613. if ( box.empty() ) return;
  20614. var min = box.min;
  20615. var max = box.max;
  20616. /*
  20617. 5____4
  20618. 1/___0/|
  20619. | 6__|_7
  20620. 2/___3/
  20621. 0: max.x, max.y, max.z
  20622. 1: min.x, max.y, max.z
  20623. 2: min.x, min.y, max.z
  20624. 3: max.x, min.y, max.z
  20625. 4: max.x, max.y, min.z
  20626. 5: min.x, max.y, min.z
  20627. 6: min.x, min.y, min.z
  20628. 7: max.x, min.y, min.z
  20629. */
  20630. var vertices = this.geometry.attributes.position.array;
  20631. vertices[ 0 ] = max.x; vertices[ 1 ] = max.y; vertices[ 2 ] = max.z;
  20632. vertices[ 3 ] = min.x; vertices[ 4 ] = max.y; vertices[ 5 ] = max.z;
  20633. vertices[ 6 ] = min.x; vertices[ 7 ] = max.y; vertices[ 8 ] = max.z;
  20634. vertices[ 9 ] = min.x; vertices[ 10 ] = min.y; vertices[ 11 ] = max.z;
  20635. vertices[ 12 ] = min.x; vertices[ 13 ] = min.y; vertices[ 14 ] = max.z;
  20636. vertices[ 15 ] = max.x; vertices[ 16 ] = min.y; vertices[ 17 ] = max.z;
  20637. vertices[ 18 ] = max.x; vertices[ 19 ] = min.y; vertices[ 20 ] = max.z;
  20638. vertices[ 21 ] = max.x; vertices[ 22 ] = max.y; vertices[ 23 ] = max.z;
  20639. //
  20640. vertices[ 24 ] = max.x; vertices[ 25 ] = max.y; vertices[ 26 ] = min.z;
  20641. vertices[ 27 ] = min.x; vertices[ 28 ] = max.y; vertices[ 29 ] = min.z;
  20642. vertices[ 30 ] = min.x; vertices[ 31 ] = max.y; vertices[ 32 ] = min.z;
  20643. vertices[ 33 ] = min.x; vertices[ 34 ] = min.y; vertices[ 35 ] = min.z;
  20644. vertices[ 36 ] = min.x; vertices[ 37 ] = min.y; vertices[ 38 ] = min.z;
  20645. vertices[ 39 ] = max.x; vertices[ 40 ] = min.y; vertices[ 41 ] = min.z;
  20646. vertices[ 42 ] = max.x; vertices[ 43 ] = min.y; vertices[ 44 ] = min.z;
  20647. vertices[ 45 ] = max.x; vertices[ 46 ] = max.y; vertices[ 47 ] = min.z;
  20648. //
  20649. vertices[ 48 ] = max.x; vertices[ 49 ] = max.y; vertices[ 50 ] = max.z;
  20650. vertices[ 51 ] = max.x; vertices[ 52 ] = max.y; vertices[ 53 ] = min.z;
  20651. vertices[ 54 ] = min.x; vertices[ 55 ] = max.y; vertices[ 56 ] = max.z;
  20652. vertices[ 57 ] = min.x; vertices[ 58 ] = max.y; vertices[ 59 ] = min.z;
  20653. vertices[ 60 ] = min.x; vertices[ 61 ] = min.y; vertices[ 62 ] = max.z;
  20654. vertices[ 63 ] = min.x; vertices[ 64 ] = min.y; vertices[ 65 ] = min.z;
  20655. vertices[ 66 ] = max.x; vertices[ 67 ] = min.y; vertices[ 68 ] = max.z;
  20656. vertices[ 69 ] = max.x; vertices[ 70 ] = min.y; vertices[ 71 ] = min.z;
  20657. this.geometry.attributes.position.needsUpdate = true;
  20658. this.geometry.computeBoundingSphere();
  20659. }
  20660. } )();
  20661. // File:src/extras/helpers/BoundingBoxHelper.js
  20662. /**
  20663. * @author WestLangley / http://github.com/WestLangley
  20664. */
  20665. // a helper to show the world-axis-aligned bounding box for an object
  20666. THREE.BoundingBoxHelper = function ( object, hex ) {
  20667. var color = ( hex !== undefined ) ? hex : 0x888888;
  20668. this.object = object;
  20669. this.box = new THREE.Box3();
  20670. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  20671. };
  20672. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  20673. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  20674. THREE.BoundingBoxHelper.prototype.update = function () {
  20675. this.box.setFromObject( this.object );
  20676. this.box.size( this.scale );
  20677. this.box.center( this.position );
  20678. };
  20679. // File:src/extras/helpers/CameraHelper.js
  20680. /**
  20681. * @author alteredq / http://alteredqualia.com/
  20682. *
  20683. * - shows frustum, line of sight and up of the camera
  20684. * - suitable for fast updates
  20685. * - based on frustum visualization in lightgl.js shadowmap example
  20686. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  20687. */
  20688. THREE.CameraHelper = function ( camera ) {
  20689. var geometry = new THREE.Geometry();
  20690. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  20691. var pointMap = {};
  20692. // colors
  20693. var hexFrustum = 0xffaa00;
  20694. var hexCone = 0xff0000;
  20695. var hexUp = 0x00aaff;
  20696. var hexTarget = 0xffffff;
  20697. var hexCross = 0x333333;
  20698. // near
  20699. addLine( "n1", "n2", hexFrustum );
  20700. addLine( "n2", "n4", hexFrustum );
  20701. addLine( "n4", "n3", hexFrustum );
  20702. addLine( "n3", "n1", hexFrustum );
  20703. // far
  20704. addLine( "f1", "f2", hexFrustum );
  20705. addLine( "f2", "f4", hexFrustum );
  20706. addLine( "f4", "f3", hexFrustum );
  20707. addLine( "f3", "f1", hexFrustum );
  20708. // sides
  20709. addLine( "n1", "f1", hexFrustum );
  20710. addLine( "n2", "f2", hexFrustum );
  20711. addLine( "n3", "f3", hexFrustum );
  20712. addLine( "n4", "f4", hexFrustum );
  20713. // cone
  20714. addLine( "p", "n1", hexCone );
  20715. addLine( "p", "n2", hexCone );
  20716. addLine( "p", "n3", hexCone );
  20717. addLine( "p", "n4", hexCone );
  20718. // up
  20719. addLine( "u1", "u2", hexUp );
  20720. addLine( "u2", "u3", hexUp );
  20721. addLine( "u3", "u1", hexUp );
  20722. // target
  20723. addLine( "c", "t", hexTarget );
  20724. addLine( "p", "c", hexCross );
  20725. // cross
  20726. addLine( "cn1", "cn2", hexCross );
  20727. addLine( "cn3", "cn4", hexCross );
  20728. addLine( "cf1", "cf2", hexCross );
  20729. addLine( "cf3", "cf4", hexCross );
  20730. function addLine( a, b, hex ) {
  20731. addPoint( a, hex );
  20732. addPoint( b, hex );
  20733. }
  20734. function addPoint( id, hex ) {
  20735. geometry.vertices.push( new THREE.Vector3() );
  20736. geometry.colors.push( new THREE.Color( hex ) );
  20737. if ( pointMap[ id ] === undefined ) {
  20738. pointMap[ id ] = [];
  20739. }
  20740. pointMap[ id ].push( geometry.vertices.length - 1 );
  20741. }
  20742. THREE.LineSegments.call( this, geometry, material );
  20743. this.camera = camera;
  20744. this.matrix = camera.matrixWorld;
  20745. this.matrixAutoUpdate = false;
  20746. this.pointMap = pointMap;
  20747. this.update();
  20748. };
  20749. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20750. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  20751. THREE.CameraHelper.prototype.update = function () {
  20752. var geometry, pointMap;
  20753. var vector = new THREE.Vector3();
  20754. var camera = new THREE.Camera();
  20755. var setPoint = function ( point, x, y, z ) {
  20756. vector.set( x, y, z ).unproject( camera );
  20757. var points = pointMap[ point ];
  20758. if ( points !== undefined ) {
  20759. for ( var i = 0, il = points.length; i < il; i ++ ) {
  20760. geometry.vertices[ points[ i ] ].copy( vector );
  20761. }
  20762. }
  20763. };
  20764. return function () {
  20765. geometry = this.geometry;
  20766. pointMap = this.pointMap;
  20767. var w = 1, h = 1;
  20768. // we need just camera projection matrix
  20769. // world matrix must be identity
  20770. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  20771. // center / target
  20772. setPoint( "c", 0, 0, - 1 );
  20773. setPoint( "t", 0, 0, 1 );
  20774. // near
  20775. setPoint( "n1", - w, - h, - 1 );
  20776. setPoint( "n2", w, - h, - 1 );
  20777. setPoint( "n3", - w, h, - 1 );
  20778. setPoint( "n4", w, h, - 1 );
  20779. // far
  20780. setPoint( "f1", - w, - h, 1 );
  20781. setPoint( "f2", w, - h, 1 );
  20782. setPoint( "f3", - w, h, 1 );
  20783. setPoint( "f4", w, h, 1 );
  20784. // up
  20785. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  20786. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  20787. setPoint( "u3", 0, h * 2, - 1 );
  20788. // cross
  20789. setPoint( "cf1", - w, 0, 1 );
  20790. setPoint( "cf2", w, 0, 1 );
  20791. setPoint( "cf3", 0, - h, 1 );
  20792. setPoint( "cf4", 0, h, 1 );
  20793. setPoint( "cn1", - w, 0, - 1 );
  20794. setPoint( "cn2", w, 0, - 1 );
  20795. setPoint( "cn3", 0, - h, - 1 );
  20796. setPoint( "cn4", 0, h, - 1 );
  20797. geometry.verticesNeedUpdate = true;
  20798. };
  20799. }();
  20800. // File:src/extras/helpers/DirectionalLightHelper.js
  20801. /**
  20802. * @author alteredq / http://alteredqualia.com/
  20803. * @author mrdoob / http://mrdoob.com/
  20804. * @author WestLangley / http://github.com/WestLangley
  20805. */
  20806. THREE.DirectionalLightHelper = function ( light, size ) {
  20807. THREE.Object3D.call( this );
  20808. this.light = light;
  20809. this.light.updateMatrixWorld();
  20810. this.matrix = light.matrixWorld;
  20811. this.matrixAutoUpdate = false;
  20812. size = size || 1;
  20813. var geometry = new THREE.Geometry();
  20814. geometry.vertices.push(
  20815. new THREE.Vector3( - size, size, 0 ),
  20816. new THREE.Vector3( size, size, 0 ),
  20817. new THREE.Vector3( size, - size, 0 ),
  20818. new THREE.Vector3( - size, - size, 0 ),
  20819. new THREE.Vector3( - size, size, 0 )
  20820. );
  20821. var material = new THREE.LineBasicMaterial( { fog: false } );
  20822. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20823. this.lightPlane = new THREE.Line( geometry, material );
  20824. this.add( this.lightPlane );
  20825. geometry = new THREE.Geometry();
  20826. geometry.vertices.push(
  20827. new THREE.Vector3(),
  20828. new THREE.Vector3()
  20829. );
  20830. material = new THREE.LineBasicMaterial( { fog: false } );
  20831. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20832. this.targetLine = new THREE.Line( geometry, material );
  20833. this.add( this.targetLine );
  20834. this.update();
  20835. };
  20836. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20837. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  20838. THREE.DirectionalLightHelper.prototype.dispose = function () {
  20839. this.lightPlane.geometry.dispose();
  20840. this.lightPlane.material.dispose();
  20841. this.targetLine.geometry.dispose();
  20842. this.targetLine.material.dispose();
  20843. };
  20844. THREE.DirectionalLightHelper.prototype.update = function () {
  20845. var v1 = new THREE.Vector3();
  20846. var v2 = new THREE.Vector3();
  20847. var v3 = new THREE.Vector3();
  20848. return function () {
  20849. v1.setFromMatrixPosition( this.light.matrixWorld );
  20850. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  20851. v3.subVectors( v2, v1 );
  20852. this.lightPlane.lookAt( v3 );
  20853. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20854. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  20855. this.targetLine.geometry.verticesNeedUpdate = true;
  20856. this.targetLine.material.color.copy( this.lightPlane.material.color );
  20857. };
  20858. }();
  20859. // File:src/extras/helpers/EdgesHelper.js
  20860. /**
  20861. * @author WestLangley / http://github.com/WestLangley
  20862. * @param object THREE.Mesh whose geometry will be used
  20863. * @param hex line color
  20864. * @param thresholdAngle the minimum angle (in degrees),
  20865. * between the face normals of adjacent faces,
  20866. * that is required to render an edge. A value of 10 means
  20867. * an edge is only rendered if the angle is at least 10 degrees.
  20868. */
  20869. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  20870. var color = ( hex !== undefined ) ? hex : 0xffffff;
  20871. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  20872. this.matrix = object.matrixWorld;
  20873. this.matrixAutoUpdate = false;
  20874. };
  20875. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20876. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  20877. // File:src/extras/helpers/FaceNormalsHelper.js
  20878. /**
  20879. * @author mrdoob / http://mrdoob.com/
  20880. * @author WestLangley / http://github.com/WestLangley
  20881. */
  20882. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  20883. // FaceNormalsHelper only supports THREE.Geometry
  20884. this.object = object;
  20885. this.size = ( size !== undefined ) ? size : 1;
  20886. var color = ( hex !== undefined ) ? hex : 0xffff00;
  20887. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20888. //
  20889. var nNormals = 0;
  20890. var objGeometry = this.object.geometry;
  20891. if ( objGeometry instanceof THREE.Geometry ) {
  20892. nNormals = objGeometry.faces.length;
  20893. } else {
  20894. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  20895. }
  20896. //
  20897. var geometry = new THREE.BufferGeometry();
  20898. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  20899. geometry.addAttribute( 'position', positions );
  20900. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20901. //
  20902. this.matrixAutoUpdate = false;
  20903. this.normalMatrix = new THREE.Matrix3();
  20904. this.update();
  20905. };
  20906. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20907. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  20908. THREE.FaceNormalsHelper.prototype.update = ( function () {
  20909. var v1 = new THREE.Vector3();
  20910. var v2 = new THREE.Vector3();
  20911. return function update() {
  20912. this.object.updateMatrixWorld( true );
  20913. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  20914. var matrixWorld = this.object.matrixWorld;
  20915. var position = this.geometry.attributes.position;
  20916. //
  20917. var objGeometry = this.object.geometry;
  20918. var vertices = objGeometry.vertices;
  20919. var faces = objGeometry.faces;
  20920. var idx = 0;
  20921. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20922. var face = faces[ i ];
  20923. var normal = face.normal;
  20924. v1.copy( vertices[ face.a ] )
  20925. .add( vertices[ face.b ] )
  20926. .add( vertices[ face.c ] )
  20927. .divideScalar( 3 )
  20928. .applyMatrix4( matrixWorld );
  20929. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  20930. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20931. idx = idx + 1;
  20932. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20933. idx = idx + 1;
  20934. }
  20935. position.needsUpdate = true;
  20936. return this;
  20937. }
  20938. }() );
  20939. // File:src/extras/helpers/GridHelper.js
  20940. /**
  20941. * @author mrdoob / http://mrdoob.com/
  20942. */
  20943. THREE.GridHelper = function ( size, step ) {
  20944. var geometry = new THREE.Geometry();
  20945. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20946. this.color1 = new THREE.Color( 0x444444 );
  20947. this.color2 = new THREE.Color( 0x888888 );
  20948. for ( var i = - size; i <= size; i += step ) {
  20949. geometry.vertices.push(
  20950. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  20951. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  20952. );
  20953. var color = i === 0 ? this.color1 : this.color2;
  20954. geometry.colors.push( color, color, color, color );
  20955. }
  20956. THREE.LineSegments.call( this, geometry, material );
  20957. };
  20958. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20959. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  20960. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  20961. this.color1.set( colorCenterLine );
  20962. this.color2.set( colorGrid );
  20963. this.geometry.colorsNeedUpdate = true;
  20964. };
  20965. // File:src/extras/helpers/HemisphereLightHelper.js
  20966. /**
  20967. * @author alteredq / http://alteredqualia.com/
  20968. * @author mrdoob / http://mrdoob.com/
  20969. */
  20970. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  20971. THREE.Object3D.call( this );
  20972. this.light = light;
  20973. this.light.updateMatrixWorld();
  20974. this.matrix = light.matrixWorld;
  20975. this.matrixAutoUpdate = false;
  20976. this.colors = [ new THREE.Color(), new THREE.Color() ];
  20977. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  20978. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  20979. for ( var i = 0, il = 8; i < il; i ++ ) {
  20980. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  20981. }
  20982. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  20983. this.lightSphere = new THREE.Mesh( geometry, material );
  20984. this.add( this.lightSphere );
  20985. this.update();
  20986. };
  20987. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20988. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  20989. THREE.HemisphereLightHelper.prototype.dispose = function () {
  20990. this.lightSphere.geometry.dispose();
  20991. this.lightSphere.material.dispose();
  20992. };
  20993. THREE.HemisphereLightHelper.prototype.update = function () {
  20994. var vector = new THREE.Vector3();
  20995. return function () {
  20996. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  20997. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  20998. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  20999. this.lightSphere.geometry.colorsNeedUpdate = true;
  21000. }
  21001. }();
  21002. // File:src/extras/helpers/PointLightHelper.js
  21003. /**
  21004. * @author alteredq / http://alteredqualia.com/
  21005. * @author mrdoob / http://mrdoob.com/
  21006. */
  21007. THREE.PointLightHelper = function ( light, sphereSize ) {
  21008. this.light = light;
  21009. this.light.updateMatrixWorld();
  21010. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21011. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21012. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21013. THREE.Mesh.call( this, geometry, material );
  21014. this.matrix = this.light.matrixWorld;
  21015. this.matrixAutoUpdate = false;
  21016. /*
  21017. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21018. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21019. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21020. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21021. var d = light.distance;
  21022. if ( d === 0.0 ) {
  21023. this.lightDistance.visible = false;
  21024. } else {
  21025. this.lightDistance.scale.set( d, d, d );
  21026. }
  21027. this.add( this.lightDistance );
  21028. */
  21029. };
  21030. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  21031. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  21032. THREE.PointLightHelper.prototype.dispose = function () {
  21033. this.geometry.dispose();
  21034. this.material.dispose();
  21035. };
  21036. THREE.PointLightHelper.prototype.update = function () {
  21037. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21038. /*
  21039. var d = this.light.distance;
  21040. if ( d === 0.0 ) {
  21041. this.lightDistance.visible = false;
  21042. } else {
  21043. this.lightDistance.visible = true;
  21044. this.lightDistance.scale.set( d, d, d );
  21045. }
  21046. */
  21047. };
  21048. // File:src/extras/helpers/SkeletonHelper.js
  21049. /**
  21050. * @author Sean Griffin / http://twitter.com/sgrif
  21051. * @author Michael Guerrero / http://realitymeltdown.com
  21052. * @author mrdoob / http://mrdoob.com/
  21053. * @author ikerr / http://verold.com
  21054. */
  21055. THREE.SkeletonHelper = function ( object ) {
  21056. this.bones = this.getBoneList( object );
  21057. var geometry = new THREE.Geometry();
  21058. for ( var i = 0; i < this.bones.length; i ++ ) {
  21059. var bone = this.bones[ i ];
  21060. if ( bone.parent instanceof THREE.Bone ) {
  21061. geometry.vertices.push( new THREE.Vector3() );
  21062. geometry.vertices.push( new THREE.Vector3() );
  21063. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  21064. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  21065. }
  21066. }
  21067. geometry.dynamic = true;
  21068. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  21069. THREE.LineSegments.call( this, geometry, material );
  21070. this.root = object;
  21071. this.matrix = object.matrixWorld;
  21072. this.matrixAutoUpdate = false;
  21073. this.update();
  21074. };
  21075. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21076. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  21077. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  21078. var boneList = [];
  21079. if ( object instanceof THREE.Bone ) {
  21080. boneList.push( object );
  21081. }
  21082. for ( var i = 0; i < object.children.length; i ++ ) {
  21083. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  21084. }
  21085. return boneList;
  21086. };
  21087. THREE.SkeletonHelper.prototype.update = function () {
  21088. var geometry = this.geometry;
  21089. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  21090. var boneMatrix = new THREE.Matrix4();
  21091. var j = 0;
  21092. for ( var i = 0; i < this.bones.length; i ++ ) {
  21093. var bone = this.bones[ i ];
  21094. if ( bone.parent instanceof THREE.Bone ) {
  21095. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  21096. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  21097. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  21098. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  21099. j += 2;
  21100. }
  21101. }
  21102. geometry.verticesNeedUpdate = true;
  21103. geometry.computeBoundingSphere();
  21104. };
  21105. // File:src/extras/helpers/SpotLightHelper.js
  21106. /**
  21107. * @author alteredq / http://alteredqualia.com/
  21108. * @author mrdoob / http://mrdoob.com/
  21109. * @author WestLangley / http://github.com/WestLangley
  21110. */
  21111. THREE.SpotLightHelper = function ( light ) {
  21112. THREE.Object3D.call( this );
  21113. this.light = light;
  21114. this.light.updateMatrixWorld();
  21115. this.matrix = light.matrixWorld;
  21116. this.matrixAutoUpdate = false;
  21117. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  21118. geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  21119. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  21120. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21121. this.cone = new THREE.Mesh( geometry, material );
  21122. this.add( this.cone );
  21123. this.update();
  21124. };
  21125. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21126. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  21127. THREE.SpotLightHelper.prototype.dispose = function () {
  21128. this.cone.geometry.dispose();
  21129. this.cone.material.dispose();
  21130. };
  21131. THREE.SpotLightHelper.prototype.update = function () {
  21132. var vector = new THREE.Vector3();
  21133. var vector2 = new THREE.Vector3();
  21134. return function () {
  21135. var coneLength = this.light.distance ? this.light.distance : 10000;
  21136. var coneWidth = coneLength * Math.tan( this.light.angle );
  21137. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21138. vector.setFromMatrixPosition( this.light.matrixWorld );
  21139. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  21140. this.cone.lookAt( vector2.sub( vector ) );
  21141. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21142. };
  21143. }();
  21144. // File:src/extras/helpers/VertexNormalsHelper.js
  21145. /**
  21146. * @author mrdoob / http://mrdoob.com/
  21147. * @author WestLangley / http://github.com/WestLangley
  21148. */
  21149. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  21150. this.object = object;
  21151. this.size = ( size !== undefined ) ? size : 1;
  21152. var color = ( hex !== undefined ) ? hex : 0xff0000;
  21153. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21154. //
  21155. var nNormals = 0;
  21156. var objGeometry = this.object.geometry;
  21157. if ( objGeometry instanceof THREE.Geometry ) {
  21158. nNormals = objGeometry.faces.length * 3;
  21159. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21160. nNormals = objGeometry.attributes.normal.count
  21161. }
  21162. //
  21163. var geometry = new THREE.BufferGeometry();
  21164. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21165. geometry.addAttribute( 'position', positions );
  21166. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21167. //
  21168. this.matrixAutoUpdate = false;
  21169. this.normalMatrix = new THREE.Matrix3();
  21170. this.update();
  21171. };
  21172. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21173. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  21174. THREE.VertexNormalsHelper.prototype.update = ( function () {
  21175. var v1 = new THREE.Vector3();
  21176. var v2 = new THREE.Vector3();
  21177. return function update() {
  21178. var keys = [ 'a', 'b', 'c' ];
  21179. this.object.updateMatrixWorld( true );
  21180. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21181. var matrixWorld = this.object.matrixWorld;
  21182. var position = this.geometry.attributes.position;
  21183. //
  21184. var objGeometry = this.object.geometry;
  21185. if ( objGeometry instanceof THREE.Geometry ) {
  21186. var vertices = objGeometry.vertices;
  21187. var faces = objGeometry.faces;
  21188. var idx = 0;
  21189. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21190. var face = faces[ i ];
  21191. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  21192. var vertex = vertices[ face[ keys[ j ] ] ];
  21193. var normal = face.vertexNormals[ j ];
  21194. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21195. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21196. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21197. idx = idx + 1;
  21198. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21199. idx = idx + 1;
  21200. }
  21201. }
  21202. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21203. var objPos = objGeometry.attributes.position;
  21204. var objNorm = objGeometry.attributes.normal;
  21205. var idx = 0;
  21206. // for simplicity, ignore index and drawcalls, and render every normal
  21207. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21208. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21209. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  21210. v2.applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21211. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21212. idx = idx + 1;
  21213. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21214. idx = idx + 1;
  21215. }
  21216. }
  21217. position.needsUpdate = true;
  21218. return this;
  21219. }
  21220. }() );
  21221. // File:src/extras/helpers/VertexTangentsHelper.js
  21222. /**
  21223. * @author mrdoob / http://mrdoob.com/
  21224. * @author WestLangley / http://github.com/WestLangley
  21225. */
  21226. THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
  21227. this.object = object;
  21228. this.size = ( size !== undefined ) ? size : 1;
  21229. var color = ( hex !== undefined ) ? hex : 0x0000ff;
  21230. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21231. //
  21232. var nTangents = 0;
  21233. var objGeometry = this.object.geometry;
  21234. if ( objGeometry instanceof THREE.Geometry ) {
  21235. nTangents = objGeometry.faces.length * 3;
  21236. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21237. nTangents = objGeometry.attributes.tangent.count
  21238. }
  21239. //
  21240. var geometry = new THREE.BufferGeometry();
  21241. var positions = new THREE.Float32Attribute( nTangents * 2 * 3, 3 );
  21242. geometry.addAttribute( 'position', positions );
  21243. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21244. //
  21245. this.matrixAutoUpdate = false;
  21246. this.update();
  21247. };
  21248. THREE.VertexTangentsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21249. THREE.VertexTangentsHelper.prototype.constructor = THREE.VertexTangentsHelper;
  21250. THREE.VertexTangentsHelper.prototype.update = ( function ( object ) {
  21251. var v1 = new THREE.Vector3();
  21252. var v2 = new THREE.Vector3();
  21253. return function() {
  21254. var keys = [ 'a', 'b', 'c' ];
  21255. this.object.updateMatrixWorld( true );
  21256. var matrixWorld = this.object.matrixWorld;
  21257. var position = this.geometry.attributes.position;
  21258. //
  21259. var objGeometry = this.object.geometry;
  21260. if ( objGeometry instanceof THREE.Geometry ) {
  21261. var vertices = objGeometry.vertices;
  21262. var faces = objGeometry.faces;
  21263. var idx = 0;
  21264. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21265. var face = faces[ i ];
  21266. for ( var j = 0, jl = face.vertexTangents.length; j < jl; j ++ ) {
  21267. var vertex = vertices[ face[ keys[ j ] ] ];
  21268. var tangent = face.vertexTangents[ j ];
  21269. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21270. v2.set( tangent.x, tangent.y, tangent.z ); // tangent.w used for bitangents only
  21271. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  21272. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21273. idx = idx + 1;
  21274. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21275. idx = idx + 1;
  21276. }
  21277. }
  21278. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21279. var objPos = objGeometry.attributes.position;
  21280. var objTan = objGeometry.attributes.tangent;
  21281. var idx = 0;
  21282. // for simplicity, ignore index and drawcalls, and render every tangent
  21283. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21284. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21285. v2.set( objTan.getX( j ), objTan.getY( j ), objTan.getZ( j ) ); // tangent.w used for bitangents only
  21286. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  21287. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21288. idx = idx + 1;
  21289. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21290. idx = idx + 1;
  21291. }
  21292. }
  21293. position.needsUpdate = true;
  21294. return this;
  21295. }
  21296. }() );
  21297. // File:src/extras/helpers/WireframeHelper.js
  21298. /**
  21299. * @author mrdoob / http://mrdoob.com/
  21300. */
  21301. THREE.WireframeHelper = function ( object, hex ) {
  21302. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21303. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21304. this.matrix = object.matrixWorld;
  21305. this.matrixAutoUpdate = false;
  21306. };
  21307. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21308. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21309. // File:src/extras/objects/ImmediateRenderObject.js
  21310. /**
  21311. * @author alteredq / http://alteredqualia.com/
  21312. */
  21313. THREE.ImmediateRenderObject = function () {
  21314. THREE.Object3D.call( this );
  21315. this.render = function ( renderCallback ) {};
  21316. };
  21317. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21318. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21319. // File:src/extras/objects/MorphBlendMesh.js
  21320. /**
  21321. * @author alteredq / http://alteredqualia.com/
  21322. */
  21323. THREE.MorphBlendMesh = function( geometry, material ) {
  21324. THREE.Mesh.call( this, geometry, material );
  21325. this.animationsMap = {};
  21326. this.animationsList = [];
  21327. // prepare default animation
  21328. // (all frames played together in 1 second)
  21329. var numFrames = this.geometry.morphTargets.length;
  21330. var name = "__default";
  21331. var startFrame = 0;
  21332. var endFrame = numFrames - 1;
  21333. var fps = numFrames / 1;
  21334. this.createAnimation( name, startFrame, endFrame, fps );
  21335. this.setAnimationWeight( name, 1 );
  21336. };
  21337. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21338. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21339. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21340. var animation = {
  21341. startFrame: start,
  21342. endFrame: end,
  21343. length: end - start + 1,
  21344. fps: fps,
  21345. duration: ( end - start ) / fps,
  21346. lastFrame: 0,
  21347. currentFrame: 0,
  21348. active: false,
  21349. time: 0,
  21350. direction: 1,
  21351. weight: 1,
  21352. directionBackwards: false,
  21353. mirroredLoop: false
  21354. };
  21355. this.animationsMap[ name ] = animation;
  21356. this.animationsList.push( animation );
  21357. };
  21358. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21359. var pattern = /([a-z]+)_?(\d+)/;
  21360. var firstAnimation, frameRanges = {};
  21361. var geometry = this.geometry;
  21362. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21363. var morph = geometry.morphTargets[ i ];
  21364. var chunks = morph.name.match( pattern );
  21365. if ( chunks && chunks.length > 1 ) {
  21366. var name = chunks[ 1 ];
  21367. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21368. var range = frameRanges[ name ];
  21369. if ( i < range.start ) range.start = i;
  21370. if ( i > range.end ) range.end = i;
  21371. if ( ! firstAnimation ) firstAnimation = name;
  21372. }
  21373. }
  21374. for ( var name in frameRanges ) {
  21375. var range = frameRanges[ name ];
  21376. this.createAnimation( name, range.start, range.end, fps );
  21377. }
  21378. this.firstAnimation = firstAnimation;
  21379. };
  21380. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21381. var animation = this.animationsMap[ name ];
  21382. if ( animation ) {
  21383. animation.direction = 1;
  21384. animation.directionBackwards = false;
  21385. }
  21386. };
  21387. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21388. var animation = this.animationsMap[ name ];
  21389. if ( animation ) {
  21390. animation.direction = - 1;
  21391. animation.directionBackwards = true;
  21392. }
  21393. };
  21394. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21395. var animation = this.animationsMap[ name ];
  21396. if ( animation ) {
  21397. animation.fps = fps;
  21398. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21399. }
  21400. };
  21401. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21402. var animation = this.animationsMap[ name ];
  21403. if ( animation ) {
  21404. animation.duration = duration;
  21405. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21406. }
  21407. };
  21408. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21409. var animation = this.animationsMap[ name ];
  21410. if ( animation ) {
  21411. animation.weight = weight;
  21412. }
  21413. };
  21414. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21415. var animation = this.animationsMap[ name ];
  21416. if ( animation ) {
  21417. animation.time = time;
  21418. }
  21419. };
  21420. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21421. var time = 0;
  21422. var animation = this.animationsMap[ name ];
  21423. if ( animation ) {
  21424. time = animation.time;
  21425. }
  21426. return time;
  21427. };
  21428. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21429. var duration = - 1;
  21430. var animation = this.animationsMap[ name ];
  21431. if ( animation ) {
  21432. duration = animation.duration;
  21433. }
  21434. return duration;
  21435. };
  21436. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21437. var animation = this.animationsMap[ name ];
  21438. if ( animation ) {
  21439. animation.time = 0;
  21440. animation.active = true;
  21441. } else {
  21442. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21443. }
  21444. };
  21445. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21446. var animation = this.animationsMap[ name ];
  21447. if ( animation ) {
  21448. animation.active = false;
  21449. }
  21450. };
  21451. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  21452. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  21453. var animation = this.animationsList[ i ];
  21454. if ( ! animation.active ) continue;
  21455. var frameTime = animation.duration / animation.length;
  21456. animation.time += animation.direction * delta;
  21457. if ( animation.mirroredLoop ) {
  21458. if ( animation.time > animation.duration || animation.time < 0 ) {
  21459. animation.direction *= - 1;
  21460. if ( animation.time > animation.duration ) {
  21461. animation.time = animation.duration;
  21462. animation.directionBackwards = true;
  21463. }
  21464. if ( animation.time < 0 ) {
  21465. animation.time = 0;
  21466. animation.directionBackwards = false;
  21467. }
  21468. }
  21469. } else {
  21470. animation.time = animation.time % animation.duration;
  21471. if ( animation.time < 0 ) animation.time += animation.duration;
  21472. }
  21473. var keyframe = animation.startFrame + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  21474. var weight = animation.weight;
  21475. if ( keyframe !== animation.currentFrame ) {
  21476. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  21477. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  21478. this.morphTargetInfluences[ keyframe ] = 0;
  21479. animation.lastFrame = animation.currentFrame;
  21480. animation.currentFrame = keyframe;
  21481. }
  21482. var mix = ( animation.time % frameTime ) / frameTime;
  21483. if ( animation.directionBackwards ) mix = 1 - mix;
  21484. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  21485. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  21486. }
  21487. };
粤ICP备19079148号