three.js 814 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '73dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. // polyfills
  13. if ( self.requestAnimationFrame === undefined || self.cancelAnimationFrame === undefined ) {
  14. // Missing in Android stock browser.
  15. ( function () {
  16. var lastTime = 0;
  17. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  18. for ( var x = 0; x < vendors.length && ! self.requestAnimationFrame; ++ x ) {
  19. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  20. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  21. }
  22. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  23. self.requestAnimationFrame = function ( callback ) {
  24. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  25. var id = self.setTimeout( function () {
  26. callback( currTime + timeToCall );
  27. }, timeToCall );
  28. lastTime = currTime + timeToCall;
  29. return id;
  30. };
  31. }
  32. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  33. self.cancelAnimationFrame = function ( id ) {
  34. self.clearTimeout( id );
  35. };
  36. }
  37. } )();
  38. }
  39. //
  40. if ( self.performance === undefined ) {
  41. self.performance = {};
  42. }
  43. if ( self.performance.now === undefined ) {
  44. ( function () {
  45. var start = Date.now();
  46. self.performance.now = function () {
  47. return Date.now() - start;
  48. }
  49. } )();
  50. }
  51. if ( Math.sign === undefined ) {
  52. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  53. Math.sign = function ( x ) {
  54. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  55. };
  56. }
  57. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  58. // Missing in IE9-11.
  59. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  60. Object.defineProperty( Function.prototype, 'name', {
  61. get: function () {
  62. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  63. }
  64. } );
  65. }
  66. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  67. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  68. // GL STATE CONSTANTS
  69. THREE.CullFaceNone = 0;
  70. THREE.CullFaceBack = 1;
  71. THREE.CullFaceFront = 2;
  72. THREE.CullFaceFrontBack = 3;
  73. THREE.FrontFaceDirectionCW = 0;
  74. THREE.FrontFaceDirectionCCW = 1;
  75. // SHADOWING TYPES
  76. THREE.BasicShadowMap = 0;
  77. THREE.PCFShadowMap = 1;
  78. THREE.PCFSoftShadowMap = 2;
  79. // MATERIAL CONSTANTS
  80. // side
  81. THREE.FrontSide = 0;
  82. THREE.BackSide = 1;
  83. THREE.DoubleSide = 2;
  84. // shading
  85. THREE.FlatShading = 1;
  86. THREE.SmoothShading = 2;
  87. // colors
  88. THREE.NoColors = 0;
  89. THREE.FaceColors = 1;
  90. THREE.VertexColors = 2;
  91. // blending modes
  92. THREE.NoBlending = 0;
  93. THREE.NormalBlending = 1;
  94. THREE.AdditiveBlending = 2;
  95. THREE.SubtractiveBlending = 3;
  96. THREE.MultiplyBlending = 4;
  97. THREE.CustomBlending = 5;
  98. // custom blending equations
  99. // (numbers start from 100 not to clash with other
  100. // mappings to OpenGL constants defined in Texture.js)
  101. THREE.AddEquation = 100;
  102. THREE.SubtractEquation = 101;
  103. THREE.ReverseSubtractEquation = 102;
  104. THREE.MinEquation = 103;
  105. THREE.MaxEquation = 104;
  106. // custom blending destination factors
  107. THREE.ZeroFactor = 200;
  108. THREE.OneFactor = 201;
  109. THREE.SrcColorFactor = 202;
  110. THREE.OneMinusSrcColorFactor = 203;
  111. THREE.SrcAlphaFactor = 204;
  112. THREE.OneMinusSrcAlphaFactor = 205;
  113. THREE.DstAlphaFactor = 206;
  114. THREE.OneMinusDstAlphaFactor = 207;
  115. // custom blending source factors
  116. //THREE.ZeroFactor = 200;
  117. //THREE.OneFactor = 201;
  118. //THREE.SrcAlphaFactor = 204;
  119. //THREE.OneMinusSrcAlphaFactor = 205;
  120. //THREE.DstAlphaFactor = 206;
  121. //THREE.OneMinusDstAlphaFactor = 207;
  122. THREE.DstColorFactor = 208;
  123. THREE.OneMinusDstColorFactor = 209;
  124. THREE.SrcAlphaSaturateFactor = 210;
  125. // depth modes
  126. THREE.NeverDepth = 0;
  127. THREE.AlwaysDepth = 1;
  128. THREE.LessDepth = 2;
  129. THREE.LessEqualDepth = 3;
  130. THREE.EqualDepth = 4;
  131. THREE.GreaterEqualDepth = 5;
  132. THREE.GreaterDepth = 6;
  133. THREE.NotEqualDepth = 7;
  134. // TEXTURE CONSTANTS
  135. THREE.MultiplyOperation = 0;
  136. THREE.MixOperation = 1;
  137. THREE.AddOperation = 2;
  138. // Mapping modes
  139. THREE.UVMapping = 300;
  140. THREE.CubeReflectionMapping = 301;
  141. THREE.CubeRefractionMapping = 302;
  142. THREE.EquirectangularReflectionMapping = 303;
  143. THREE.EquirectangularRefractionMapping = 304;
  144. THREE.SphericalReflectionMapping = 305;
  145. // Wrapping modes
  146. THREE.RepeatWrapping = 1000;
  147. THREE.ClampToEdgeWrapping = 1001;
  148. THREE.MirroredRepeatWrapping = 1002;
  149. // Filters
  150. THREE.NearestFilter = 1003;
  151. THREE.NearestMipMapNearestFilter = 1004;
  152. THREE.NearestMipMapLinearFilter = 1005;
  153. THREE.LinearFilter = 1006;
  154. THREE.LinearMipMapNearestFilter = 1007;
  155. THREE.LinearMipMapLinearFilter = 1008;
  156. // Data types
  157. THREE.UnsignedByteType = 1009;
  158. THREE.ByteType = 1010;
  159. THREE.ShortType = 1011;
  160. THREE.UnsignedShortType = 1012;
  161. THREE.IntType = 1013;
  162. THREE.UnsignedIntType = 1014;
  163. THREE.FloatType = 1015;
  164. THREE.HalfFloatType = 1025;
  165. // Pixel types
  166. //THREE.UnsignedByteType = 1009;
  167. THREE.UnsignedShort4444Type = 1016;
  168. THREE.UnsignedShort5551Type = 1017;
  169. THREE.UnsignedShort565Type = 1018;
  170. // Pixel formats
  171. THREE.AlphaFormat = 1019;
  172. THREE.RGBFormat = 1020;
  173. THREE.RGBAFormat = 1021;
  174. THREE.LuminanceFormat = 1022;
  175. THREE.LuminanceAlphaFormat = 1023;
  176. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  177. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  178. // DDS / ST3C Compressed texture formats
  179. THREE.RGB_S3TC_DXT1_Format = 2001;
  180. THREE.RGBA_S3TC_DXT1_Format = 2002;
  181. THREE.RGBA_S3TC_DXT3_Format = 2003;
  182. THREE.RGBA_S3TC_DXT5_Format = 2004;
  183. // PVRTC compressed texture formats
  184. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  185. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  186. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  187. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  188. // Loop styles for AnimationAction
  189. THREE.LoopOnce = 2200;
  190. THREE.LoopRepeat = 2201;
  191. THREE.LoopPingPong = 2202;
  192. // DEPRECATED
  193. THREE.Projector = function () {
  194. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  195. this.projectVector = function ( vector, camera ) {
  196. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  197. vector.project( camera );
  198. };
  199. this.unprojectVector = function ( vector, camera ) {
  200. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  201. vector.unproject( camera );
  202. };
  203. this.pickingRay = function ( vector, camera ) {
  204. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  205. };
  206. };
  207. THREE.CanvasRenderer = function () {
  208. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  209. this.domElement = document.createElement( 'canvas' );
  210. this.clear = function () {};
  211. this.render = function () {};
  212. this.setClearColor = function () {};
  213. this.setSize = function () {};
  214. };
  215. // File:src/math/Color.js
  216. /**
  217. * @author mrdoob / http://mrdoob.com/
  218. */
  219. THREE.Color = function ( color ) {
  220. if ( arguments.length === 3 ) {
  221. return this.fromArray( arguments );
  222. }
  223. return this.set( color );
  224. };
  225. THREE.Color.prototype = {
  226. constructor: THREE.Color,
  227. r: 1, g: 1, b: 1,
  228. set: function ( value ) {
  229. if ( value instanceof THREE.Color ) {
  230. this.copy( value );
  231. } else if ( typeof value === 'number' ) {
  232. this.setHex( value );
  233. } else if ( typeof value === 'string' ) {
  234. this.setStyle( value );
  235. }
  236. return this;
  237. },
  238. setHex: function ( hex ) {
  239. hex = Math.floor( hex );
  240. this.r = ( hex >> 16 & 255 ) / 255;
  241. this.g = ( hex >> 8 & 255 ) / 255;
  242. this.b = ( hex & 255 ) / 255;
  243. return this;
  244. },
  245. setRGB: function ( r, g, b ) {
  246. this.r = r;
  247. this.g = g;
  248. this.b = b;
  249. return this;
  250. },
  251. setHSL: function () {
  252. function hue2rgb( p, q, t ) {
  253. if ( t < 0 ) t += 1;
  254. if ( t > 1 ) t -= 1;
  255. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  256. if ( t < 1 / 2 ) return q;
  257. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  258. return p;
  259. }
  260. return function ( h, s, l ) {
  261. // h,s,l ranges are in 0.0 - 1.0
  262. h = THREE.Math.euclideanModulo( h, 1 );
  263. s = THREE.Math.clamp( s, 0, 1 );
  264. l = THREE.Math.clamp( l, 0, 1 );
  265. if ( s === 0 ) {
  266. this.r = this.g = this.b = l;
  267. } else {
  268. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  269. var q = ( 2 * l ) - p;
  270. this.r = hue2rgb( q, p, h + 1 / 3 );
  271. this.g = hue2rgb( q, p, h );
  272. this.b = hue2rgb( q, p, h - 1 / 3 );
  273. }
  274. return this;
  275. };
  276. }(),
  277. setStyle: function ( style ) {
  278. function parseAlpha( strAlpha ) {
  279. var alpha = parseFloat( strAlpha );
  280. if ( alpha < 1 ) {
  281. console.warn( 'THREE.Color: Alpha component of color ' + style + ' will be ignored.' );
  282. }
  283. return alpha;
  284. }
  285. var m;
  286. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  287. // rgb / hsl
  288. var color;
  289. var name = m[ 1 ];
  290. var components = m[ 2 ];
  291. switch ( name ) {
  292. case 'rgb':
  293. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*$/.exec( components ) ) {
  294. // rgb(255,0,0)
  295. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  296. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  297. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  298. return this;
  299. }
  300. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  301. // rgb(100%,0%,0%)
  302. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  303. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  304. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  305. return this;
  306. }
  307. break;
  308. case 'rgba':
  309. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  310. // rgba(255,0,0,0.5)
  311. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  312. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  313. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  314. parseAlpha( color[ 4 ] );
  315. return this;
  316. }
  317. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  318. // rgba(100%,0%,0%,0.5)
  319. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  320. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  321. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  322. parseAlpha( color[ 4 ] );
  323. return this;
  324. }
  325. break;
  326. case 'hsl':
  327. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  328. // hsl(120,50%,50%)
  329. var h = parseFloat( color[ 1 ] );
  330. var s = parseInt( color[ 2 ], 10 ) / 100;
  331. var l = parseInt( color[ 3 ], 10 ) / 100;
  332. return this.setHSL( h, s, l );
  333. }
  334. break;
  335. case 'hsla':
  336. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  337. // hsla(120,50%,50%,0.5)
  338. var h = parseFloat( color[ 1 ] );
  339. var s = parseInt( color[ 2 ], 10 ) / 100;
  340. var l = parseInt( color[ 3 ], 10 ) / 100;
  341. parseAlpha( color[ 4 ] );
  342. return this.setHSL( h, s, l );
  343. }
  344. break;
  345. }
  346. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  347. // hex color
  348. var hex = m[ 1 ];
  349. var size = hex.length;
  350. if ( size === 3 ) {
  351. // #ff0
  352. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  353. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  354. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  355. return this;
  356. } else if ( size === 6 ) {
  357. // #ff0000
  358. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  359. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  360. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  361. return this;
  362. }
  363. }
  364. if ( style && style.length > 0 ) {
  365. // color keywords
  366. var hex = THREE.ColorKeywords[ style ];
  367. if ( hex !== undefined ) {
  368. // red
  369. this.setHex( hex );
  370. } else {
  371. // unknown color
  372. console.warn( 'THREE.Color: Unknown color ' + style );
  373. }
  374. }
  375. return this;
  376. },
  377. clone: function () {
  378. return new this.constructor( this.r, this.g, this.b );
  379. },
  380. copy: function ( color ) {
  381. this.r = color.r;
  382. this.g = color.g;
  383. this.b = color.b;
  384. return this;
  385. },
  386. copyGammaToLinear: function ( color, gammaFactor ) {
  387. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  388. this.r = Math.pow( color.r, gammaFactor );
  389. this.g = Math.pow( color.g, gammaFactor );
  390. this.b = Math.pow( color.b, gammaFactor );
  391. return this;
  392. },
  393. copyLinearToGamma: function ( color, gammaFactor ) {
  394. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  395. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  396. this.r = Math.pow( color.r, safeInverse );
  397. this.g = Math.pow( color.g, safeInverse );
  398. this.b = Math.pow( color.b, safeInverse );
  399. return this;
  400. },
  401. convertGammaToLinear: function () {
  402. var r = this.r, g = this.g, b = this.b;
  403. this.r = r * r;
  404. this.g = g * g;
  405. this.b = b * b;
  406. return this;
  407. },
  408. convertLinearToGamma: function () {
  409. this.r = Math.sqrt( this.r );
  410. this.g = Math.sqrt( this.g );
  411. this.b = Math.sqrt( this.b );
  412. return this;
  413. },
  414. getHex: function () {
  415. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  416. },
  417. getHexString: function () {
  418. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  419. },
  420. getHSL: function ( optionalTarget ) {
  421. // h,s,l ranges are in 0.0 - 1.0
  422. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  423. var r = this.r, g = this.g, b = this.b;
  424. var max = Math.max( r, g, b );
  425. var min = Math.min( r, g, b );
  426. var hue, saturation;
  427. var lightness = ( min + max ) / 2.0;
  428. if ( min === max ) {
  429. hue = 0;
  430. saturation = 0;
  431. } else {
  432. var delta = max - min;
  433. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  434. switch ( max ) {
  435. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  436. case g: hue = ( b - r ) / delta + 2; break;
  437. case b: hue = ( r - g ) / delta + 4; break;
  438. }
  439. hue /= 6;
  440. }
  441. hsl.h = hue;
  442. hsl.s = saturation;
  443. hsl.l = lightness;
  444. return hsl;
  445. },
  446. getStyle: function () {
  447. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  448. },
  449. offsetHSL: function ( h, s, l ) {
  450. var hsl = this.getHSL();
  451. hsl.h += h; hsl.s += s; hsl.l += l;
  452. this.setHSL( hsl.h, hsl.s, hsl.l );
  453. return this;
  454. },
  455. add: function ( color ) {
  456. this.r += color.r;
  457. this.g += color.g;
  458. this.b += color.b;
  459. return this;
  460. },
  461. addColors: function ( color1, color2 ) {
  462. this.r = color1.r + color2.r;
  463. this.g = color1.g + color2.g;
  464. this.b = color1.b + color2.b;
  465. return this;
  466. },
  467. addScalar: function ( s ) {
  468. this.r += s;
  469. this.g += s;
  470. this.b += s;
  471. return this;
  472. },
  473. multiply: function ( color ) {
  474. this.r *= color.r;
  475. this.g *= color.g;
  476. this.b *= color.b;
  477. return this;
  478. },
  479. multiplyScalar: function ( s ) {
  480. this.r *= s;
  481. this.g *= s;
  482. this.b *= s;
  483. return this;
  484. },
  485. lerp: function ( color, alpha ) {
  486. this.r += ( color.r - this.r ) * alpha;
  487. this.g += ( color.g - this.g ) * alpha;
  488. this.b += ( color.b - this.b ) * alpha;
  489. return this;
  490. },
  491. equals: function ( c ) {
  492. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  493. },
  494. fromArray: function ( array ) {
  495. this.r = array[ 0 ];
  496. this.g = array[ 1 ];
  497. this.b = array[ 2 ];
  498. return this;
  499. },
  500. toArray: function ( array, offset ) {
  501. if ( array === undefined ) array = [];
  502. if ( offset === undefined ) offset = 0;
  503. array[ offset ] = this.r;
  504. array[ offset + 1 ] = this.g;
  505. array[ offset + 2 ] = this.b;
  506. return array;
  507. }
  508. };
  509. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  510. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  511. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  512. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  513. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  514. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  515. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  516. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  517. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  518. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  519. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  520. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  521. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  522. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  523. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  524. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  525. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  526. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  527. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  528. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  529. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  530. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  531. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  532. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  533. // File:src/math/Quaternion.js
  534. /**
  535. * @author mikael emtinger / http://gomo.se/
  536. * @author alteredq / http://alteredqualia.com/
  537. * @author WestLangley / http://github.com/WestLangley
  538. * @author bhouston / http://clara.io
  539. */
  540. THREE.Quaternion = function ( x, y, z, w ) {
  541. this._x = x || 0;
  542. this._y = y || 0;
  543. this._z = z || 0;
  544. this._w = ( w !== undefined ) ? w : 1;
  545. };
  546. THREE.Quaternion.prototype = {
  547. constructor: THREE.Quaternion,
  548. get x () {
  549. return this._x;
  550. },
  551. set x ( value ) {
  552. this._x = value;
  553. this.onChangeCallback();
  554. },
  555. get y () {
  556. return this._y;
  557. },
  558. set y ( value ) {
  559. this._y = value;
  560. this.onChangeCallback();
  561. },
  562. get z () {
  563. return this._z;
  564. },
  565. set z ( value ) {
  566. this._z = value;
  567. this.onChangeCallback();
  568. },
  569. get w () {
  570. return this._w;
  571. },
  572. set w ( value ) {
  573. this._w = value;
  574. this.onChangeCallback();
  575. },
  576. set: function ( x, y, z, w ) {
  577. this._x = x;
  578. this._y = y;
  579. this._z = z;
  580. this._w = w;
  581. this.onChangeCallback();
  582. return this;
  583. },
  584. clone: function () {
  585. return new this.constructor( this._x, this._y, this._z, this._w );
  586. },
  587. copy: function ( quaternion ) {
  588. this._x = quaternion.x;
  589. this._y = quaternion.y;
  590. this._z = quaternion.z;
  591. this._w = quaternion.w;
  592. this.onChangeCallback();
  593. return this;
  594. },
  595. setFromEuler: function ( euler, update ) {
  596. if ( euler instanceof THREE.Euler === false ) {
  597. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  598. }
  599. // http://www.mathworks.com/matlabcentral/fileexchange/
  600. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  601. // content/SpinCalc.m
  602. var c1 = Math.cos( euler._x / 2 );
  603. var c2 = Math.cos( euler._y / 2 );
  604. var c3 = Math.cos( euler._z / 2 );
  605. var s1 = Math.sin( euler._x / 2 );
  606. var s2 = Math.sin( euler._y / 2 );
  607. var s3 = Math.sin( euler._z / 2 );
  608. var order = euler.order;
  609. if ( order === 'XYZ' ) {
  610. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  611. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  612. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  613. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  614. } else if ( order === 'YXZ' ) {
  615. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  616. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  617. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  618. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  619. } else if ( order === 'ZXY' ) {
  620. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  621. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  622. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  623. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  624. } else if ( order === 'ZYX' ) {
  625. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  626. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  627. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  628. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  629. } else if ( order === 'YZX' ) {
  630. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  631. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  632. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  633. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  634. } else if ( order === 'XZY' ) {
  635. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  636. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  637. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  638. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  639. }
  640. if ( update !== false ) this.onChangeCallback();
  641. return this;
  642. },
  643. setFromAxisAngle: function ( axis, angle ) {
  644. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  645. // assumes axis is normalized
  646. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  647. this._x = axis.x * s;
  648. this._y = axis.y * s;
  649. this._z = axis.z * s;
  650. this._w = Math.cos( halfAngle );
  651. this.onChangeCallback();
  652. return this;
  653. },
  654. setFromRotationMatrix: function ( m ) {
  655. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  656. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  657. var te = m.elements,
  658. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  659. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  660. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  661. trace = m11 + m22 + m33,
  662. s;
  663. if ( trace > 0 ) {
  664. s = 0.5 / Math.sqrt( trace + 1.0 );
  665. this._w = 0.25 / s;
  666. this._x = ( m32 - m23 ) * s;
  667. this._y = ( m13 - m31 ) * s;
  668. this._z = ( m21 - m12 ) * s;
  669. } else if ( m11 > m22 && m11 > m33 ) {
  670. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  671. this._w = ( m32 - m23 ) / s;
  672. this._x = 0.25 * s;
  673. this._y = ( m12 + m21 ) / s;
  674. this._z = ( m13 + m31 ) / s;
  675. } else if ( m22 > m33 ) {
  676. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  677. this._w = ( m13 - m31 ) / s;
  678. this._x = ( m12 + m21 ) / s;
  679. this._y = 0.25 * s;
  680. this._z = ( m23 + m32 ) / s;
  681. } else {
  682. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  683. this._w = ( m21 - m12 ) / s;
  684. this._x = ( m13 + m31 ) / s;
  685. this._y = ( m23 + m32 ) / s;
  686. this._z = 0.25 * s;
  687. }
  688. this.onChangeCallback();
  689. return this;
  690. },
  691. setFromUnitVectors: function () {
  692. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  693. // assumes direction vectors vFrom and vTo are normalized
  694. var v1, r;
  695. var EPS = 0.000001;
  696. return function ( vFrom, vTo ) {
  697. if ( v1 === undefined ) v1 = new THREE.Vector3();
  698. r = vFrom.dot( vTo ) + 1;
  699. if ( r < EPS ) {
  700. r = 0;
  701. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  702. v1.set( - vFrom.y, vFrom.x, 0 );
  703. } else {
  704. v1.set( 0, - vFrom.z, vFrom.y );
  705. }
  706. } else {
  707. v1.crossVectors( vFrom, vTo );
  708. }
  709. this._x = v1.x;
  710. this._y = v1.y;
  711. this._z = v1.z;
  712. this._w = r;
  713. this.normalize();
  714. return this;
  715. }
  716. }(),
  717. inverse: function () {
  718. this.conjugate().normalize();
  719. return this;
  720. },
  721. conjugate: function () {
  722. this._x *= - 1;
  723. this._y *= - 1;
  724. this._z *= - 1;
  725. this.onChangeCallback();
  726. return this;
  727. },
  728. dot: function ( v ) {
  729. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  730. },
  731. lengthSq: function () {
  732. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  733. },
  734. length: function () {
  735. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  736. },
  737. normalize: function () {
  738. var l = this.length();
  739. if ( l === 0 ) {
  740. this._x = 0;
  741. this._y = 0;
  742. this._z = 0;
  743. this._w = 1;
  744. } else {
  745. l = 1 / l;
  746. this._x = this._x * l;
  747. this._y = this._y * l;
  748. this._z = this._z * l;
  749. this._w = this._w * l;
  750. }
  751. this.onChangeCallback();
  752. return this;
  753. },
  754. multiply: function ( q, p ) {
  755. if ( p !== undefined ) {
  756. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  757. return this.multiplyQuaternions( q, p );
  758. }
  759. return this.multiplyQuaternions( this, q );
  760. },
  761. multiplyQuaternions: function ( a, b ) {
  762. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  763. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  764. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  765. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  766. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  767. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  768. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  769. this.onChangeCallback();
  770. return this;
  771. },
  772. multiplyVector3: function ( vector ) {
  773. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  774. return vector.applyQuaternion( this );
  775. },
  776. slerp: function ( qb, t ) {
  777. if ( t === 0 ) return this;
  778. if ( t === 1 ) return this.copy( qb );
  779. var x = this._x, y = this._y, z = this._z, w = this._w;
  780. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  781. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  782. if ( cosHalfTheta < 0 ) {
  783. this._w = - qb._w;
  784. this._x = - qb._x;
  785. this._y = - qb._y;
  786. this._z = - qb._z;
  787. cosHalfTheta = - cosHalfTheta;
  788. } else {
  789. this.copy( qb );
  790. }
  791. if ( cosHalfTheta >= 1.0 ) {
  792. this._w = w;
  793. this._x = x;
  794. this._y = y;
  795. this._z = z;
  796. return this;
  797. }
  798. var halfTheta = Math.acos( cosHalfTheta );
  799. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  800. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  801. this._w = 0.5 * ( w + this._w );
  802. this._x = 0.5 * ( x + this._x );
  803. this._y = 0.5 * ( y + this._y );
  804. this._z = 0.5 * ( z + this._z );
  805. return this;
  806. }
  807. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  808. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  809. this._w = ( w * ratioA + this._w * ratioB );
  810. this._x = ( x * ratioA + this._x * ratioB );
  811. this._y = ( y * ratioA + this._y * ratioB );
  812. this._z = ( z * ratioA + this._z * ratioB );
  813. this.onChangeCallback();
  814. return this;
  815. },
  816. equals: function ( quaternion ) {
  817. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  818. },
  819. fromArray: function ( array, offset ) {
  820. if ( offset === undefined ) offset = 0;
  821. this._x = array[ offset ];
  822. this._y = array[ offset + 1 ];
  823. this._z = array[ offset + 2 ];
  824. this._w = array[ offset + 3 ];
  825. this.onChangeCallback();
  826. return this;
  827. },
  828. toArray: function ( array, offset ) {
  829. if ( array === undefined ) array = [];
  830. if ( offset === undefined ) offset = 0;
  831. array[ offset ] = this._x;
  832. array[ offset + 1 ] = this._y;
  833. array[ offset + 2 ] = this._z;
  834. array[ offset + 3 ] = this._w;
  835. return array;
  836. },
  837. onChange: function ( callback ) {
  838. this.onChangeCallback = callback;
  839. return this;
  840. },
  841. onChangeCallback: function () {}
  842. };
  843. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  844. return qm.copy( qa ).slerp( qb, t );
  845. };
  846. // File:src/math/Vector2.js
  847. /**
  848. * @author mrdoob / http://mrdoob.com/
  849. * @author philogb / http://blog.thejit.org/
  850. * @author egraether / http://egraether.com/
  851. * @author zz85 / http://www.lab4games.net/zz85/blog
  852. */
  853. THREE.Vector2 = function ( x, y ) {
  854. this.x = x || 0;
  855. this.y = y || 0;
  856. };
  857. THREE.Vector2.prototype = {
  858. constructor: THREE.Vector2,
  859. set: function ( x, y ) {
  860. this.x = x;
  861. this.y = y;
  862. return this;
  863. },
  864. setX: function ( x ) {
  865. this.x = x;
  866. return this;
  867. },
  868. setY: function ( y ) {
  869. this.y = y;
  870. return this;
  871. },
  872. setComponent: function ( index, value ) {
  873. switch ( index ) {
  874. case 0: this.x = value; break;
  875. case 1: this.y = value; break;
  876. default: throw new Error( 'index is out of range: ' + index );
  877. }
  878. },
  879. getComponent: function ( index ) {
  880. switch ( index ) {
  881. case 0: return this.x;
  882. case 1: return this.y;
  883. default: throw new Error( 'index is out of range: ' + index );
  884. }
  885. },
  886. clone: function () {
  887. return new this.constructor( this.x, this.y );
  888. },
  889. copy: function ( v ) {
  890. this.x = v.x;
  891. this.y = v.y;
  892. return this;
  893. },
  894. add: function ( v, w ) {
  895. if ( w !== undefined ) {
  896. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  897. return this.addVectors( v, w );
  898. }
  899. this.x += v.x;
  900. this.y += v.y;
  901. return this;
  902. },
  903. addScalar: function ( s ) {
  904. this.x += s;
  905. this.y += s;
  906. return this;
  907. },
  908. addVectors: function ( a, b ) {
  909. this.x = a.x + b.x;
  910. this.y = a.y + b.y;
  911. return this;
  912. },
  913. addScaledVector: function ( v, s ) {
  914. this.x += v.x * s;
  915. this.y += v.y * s;
  916. return this;
  917. },
  918. sub: function ( v, w ) {
  919. if ( w !== undefined ) {
  920. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  921. return this.subVectors( v, w );
  922. }
  923. this.x -= v.x;
  924. this.y -= v.y;
  925. return this;
  926. },
  927. subScalar: function ( s ) {
  928. this.x -= s;
  929. this.y -= s;
  930. return this;
  931. },
  932. subVectors: function ( a, b ) {
  933. this.x = a.x - b.x;
  934. this.y = a.y - b.y;
  935. return this;
  936. },
  937. multiply: function ( v ) {
  938. this.x *= v.x;
  939. this.y *= v.y;
  940. return this;
  941. },
  942. multiplyScalar: function ( s ) {
  943. this.x *= s;
  944. this.y *= s;
  945. return this;
  946. },
  947. divide: function ( v ) {
  948. this.x /= v.x;
  949. this.y /= v.y;
  950. return this;
  951. },
  952. divideScalar: function ( scalar ) {
  953. if ( scalar !== 0 ) {
  954. var invScalar = 1 / scalar;
  955. this.x *= invScalar;
  956. this.y *= invScalar;
  957. } else {
  958. this.x = 0;
  959. this.y = 0;
  960. }
  961. return this;
  962. },
  963. min: function ( v ) {
  964. if ( this.x > v.x ) {
  965. this.x = v.x;
  966. }
  967. if ( this.y > v.y ) {
  968. this.y = v.y;
  969. }
  970. return this;
  971. },
  972. max: function ( v ) {
  973. if ( this.x < v.x ) {
  974. this.x = v.x;
  975. }
  976. if ( this.y < v.y ) {
  977. this.y = v.y;
  978. }
  979. return this;
  980. },
  981. clamp: function ( min, max ) {
  982. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  983. if ( this.x < min.x ) {
  984. this.x = min.x;
  985. } else if ( this.x > max.x ) {
  986. this.x = max.x;
  987. }
  988. if ( this.y < min.y ) {
  989. this.y = min.y;
  990. } else if ( this.y > max.y ) {
  991. this.y = max.y;
  992. }
  993. return this;
  994. },
  995. clampScalar: function () {
  996. var min, max;
  997. return function clampScalar( minVal, maxVal ) {
  998. if ( min === undefined ) {
  999. min = new THREE.Vector2();
  1000. max = new THREE.Vector2();
  1001. }
  1002. min.set( minVal, minVal );
  1003. max.set( maxVal, maxVal );
  1004. return this.clamp( min, max );
  1005. };
  1006. }(),
  1007. floor: function () {
  1008. this.x = Math.floor( this.x );
  1009. this.y = Math.floor( this.y );
  1010. return this;
  1011. },
  1012. ceil: function () {
  1013. this.x = Math.ceil( this.x );
  1014. this.y = Math.ceil( this.y );
  1015. return this;
  1016. },
  1017. round: function () {
  1018. this.x = Math.round( this.x );
  1019. this.y = Math.round( this.y );
  1020. return this;
  1021. },
  1022. roundToZero: function () {
  1023. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1024. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1025. return this;
  1026. },
  1027. negate: function () {
  1028. this.x = - this.x;
  1029. this.y = - this.y;
  1030. return this;
  1031. },
  1032. dot: function ( v ) {
  1033. return this.x * v.x + this.y * v.y;
  1034. },
  1035. lengthSq: function () {
  1036. return this.x * this.x + this.y * this.y;
  1037. },
  1038. length: function () {
  1039. return Math.sqrt( this.x * this.x + this.y * this.y );
  1040. },
  1041. lengthManhattan: function() {
  1042. return Math.abs( this.x ) + Math.abs( this.y );
  1043. },
  1044. normalize: function () {
  1045. return this.divideScalar( this.length() );
  1046. },
  1047. distanceTo: function ( v ) {
  1048. return Math.sqrt( this.distanceToSquared( v ) );
  1049. },
  1050. distanceToSquared: function ( v ) {
  1051. var dx = this.x - v.x, dy = this.y - v.y;
  1052. return dx * dx + dy * dy;
  1053. },
  1054. setLength: function ( l ) {
  1055. var oldLength = this.length();
  1056. if ( oldLength !== 0 && l !== oldLength ) {
  1057. this.multiplyScalar( l / oldLength );
  1058. }
  1059. return this;
  1060. },
  1061. lerp: function ( v, alpha ) {
  1062. this.x += ( v.x - this.x ) * alpha;
  1063. this.y += ( v.y - this.y ) * alpha;
  1064. return this;
  1065. },
  1066. lerpVectors: function ( v1, v2, alpha ) {
  1067. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1068. return this;
  1069. },
  1070. equals: function ( v ) {
  1071. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1072. },
  1073. fromArray: function ( array, offset ) {
  1074. if ( offset === undefined ) offset = 0;
  1075. this.x = array[ offset ];
  1076. this.y = array[ offset + 1 ];
  1077. return this;
  1078. },
  1079. toArray: function ( array, offset ) {
  1080. if ( array === undefined ) array = [];
  1081. if ( offset === undefined ) offset = 0;
  1082. array[ offset ] = this.x;
  1083. array[ offset + 1 ] = this.y;
  1084. return array;
  1085. },
  1086. fromAttribute: function ( attribute, index, offset ) {
  1087. if ( offset === undefined ) offset = 0;
  1088. index = index * attribute.itemSize + offset;
  1089. this.x = attribute.array[ index ];
  1090. this.y = attribute.array[ index + 1 ];
  1091. return this;
  1092. }
  1093. };
  1094. // File:src/math/Vector3.js
  1095. /**
  1096. * @author mrdoob / http://mrdoob.com/
  1097. * @author *kile / http://kile.stravaganza.org/
  1098. * @author philogb / http://blog.thejit.org/
  1099. * @author mikael emtinger / http://gomo.se/
  1100. * @author egraether / http://egraether.com/
  1101. * @author WestLangley / http://github.com/WestLangley
  1102. */
  1103. THREE.Vector3 = function ( x, y, z ) {
  1104. this.x = x || 0;
  1105. this.y = y || 0;
  1106. this.z = z || 0;
  1107. };
  1108. THREE.Vector3.prototype = {
  1109. constructor: THREE.Vector3,
  1110. set: function ( x, y, z ) {
  1111. this.x = x;
  1112. this.y = y;
  1113. this.z = z;
  1114. return this;
  1115. },
  1116. setX: function ( x ) {
  1117. this.x = x;
  1118. return this;
  1119. },
  1120. setY: function ( y ) {
  1121. this.y = y;
  1122. return this;
  1123. },
  1124. setZ: function ( z ) {
  1125. this.z = z;
  1126. return this;
  1127. },
  1128. setComponent: function ( index, value ) {
  1129. switch ( index ) {
  1130. case 0: this.x = value; break;
  1131. case 1: this.y = value; break;
  1132. case 2: this.z = value; break;
  1133. default: throw new Error( 'index is out of range: ' + index );
  1134. }
  1135. },
  1136. getComponent: function ( index ) {
  1137. switch ( index ) {
  1138. case 0: return this.x;
  1139. case 1: return this.y;
  1140. case 2: return this.z;
  1141. default: throw new Error( 'index is out of range: ' + index );
  1142. }
  1143. },
  1144. clone: function () {
  1145. return new this.constructor( this.x, this.y, this.z );
  1146. },
  1147. copy: function ( v ) {
  1148. this.x = v.x;
  1149. this.y = v.y;
  1150. this.z = v.z;
  1151. return this;
  1152. },
  1153. add: function ( v, w ) {
  1154. if ( w !== undefined ) {
  1155. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1156. return this.addVectors( v, w );
  1157. }
  1158. this.x += v.x;
  1159. this.y += v.y;
  1160. this.z += v.z;
  1161. return this;
  1162. },
  1163. addScalar: function ( s ) {
  1164. this.x += s;
  1165. this.y += s;
  1166. this.z += s;
  1167. return this;
  1168. },
  1169. addVectors: function ( a, b ) {
  1170. this.x = a.x + b.x;
  1171. this.y = a.y + b.y;
  1172. this.z = a.z + b.z;
  1173. return this;
  1174. },
  1175. addScaledVector: function ( v, s ) {
  1176. this.x += v.x * s;
  1177. this.y += v.y * s;
  1178. this.z += v.z * s;
  1179. return this;
  1180. },
  1181. sub: function ( v, w ) {
  1182. if ( w !== undefined ) {
  1183. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1184. return this.subVectors( v, w );
  1185. }
  1186. this.x -= v.x;
  1187. this.y -= v.y;
  1188. this.z -= v.z;
  1189. return this;
  1190. },
  1191. subScalar: function ( s ) {
  1192. this.x -= s;
  1193. this.y -= s;
  1194. this.z -= s;
  1195. return this;
  1196. },
  1197. subVectors: 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. multiply: function ( v, w ) {
  1204. if ( w !== undefined ) {
  1205. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1206. return this.multiplyVectors( v, w );
  1207. }
  1208. this.x *= v.x;
  1209. this.y *= v.y;
  1210. this.z *= v.z;
  1211. return this;
  1212. },
  1213. multiplyScalar: function ( scalar ) {
  1214. this.x *= scalar;
  1215. this.y *= scalar;
  1216. this.z *= scalar;
  1217. return this;
  1218. },
  1219. multiplyVectors: function ( a, b ) {
  1220. this.x = a.x * b.x;
  1221. this.y = a.y * b.y;
  1222. this.z = a.z * b.z;
  1223. return this;
  1224. },
  1225. applyEuler: function () {
  1226. var quaternion;
  1227. return function applyEuler( euler ) {
  1228. if ( euler instanceof THREE.Euler === false ) {
  1229. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1230. }
  1231. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1232. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1233. return this;
  1234. };
  1235. }(),
  1236. applyAxisAngle: function () {
  1237. var quaternion;
  1238. return function applyAxisAngle( axis, angle ) {
  1239. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1240. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1241. return this;
  1242. };
  1243. }(),
  1244. applyMatrix3: function ( m ) {
  1245. var x = this.x;
  1246. var y = this.y;
  1247. var z = this.z;
  1248. var e = m.elements;
  1249. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1250. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1251. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1252. return this;
  1253. },
  1254. applyMatrix4: function ( m ) {
  1255. // input: THREE.Matrix4 affine matrix
  1256. var x = this.x, y = this.y, z = this.z;
  1257. var e = m.elements;
  1258. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1259. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1260. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1261. return this;
  1262. },
  1263. applyProjection: function ( m ) {
  1264. // input: THREE.Matrix4 projection matrix
  1265. var x = this.x, y = this.y, z = this.z;
  1266. var e = m.elements;
  1267. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1268. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1269. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1270. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1271. return this;
  1272. },
  1273. applyQuaternion: function ( q ) {
  1274. var x = this.x;
  1275. var y = this.y;
  1276. var z = this.z;
  1277. var qx = q.x;
  1278. var qy = q.y;
  1279. var qz = q.z;
  1280. var qw = q.w;
  1281. // calculate quat * vector
  1282. var ix = qw * x + qy * z - qz * y;
  1283. var iy = qw * y + qz * x - qx * z;
  1284. var iz = qw * z + qx * y - qy * x;
  1285. var iw = - qx * x - qy * y - qz * z;
  1286. // calculate result * inverse quat
  1287. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1288. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1289. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1290. return this;
  1291. },
  1292. project: function () {
  1293. var matrix;
  1294. return function project( camera ) {
  1295. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1296. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1297. return this.applyProjection( matrix );
  1298. };
  1299. }(),
  1300. unproject: function () {
  1301. var matrix;
  1302. return function unproject( camera ) {
  1303. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1304. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1305. return this.applyProjection( matrix );
  1306. };
  1307. }(),
  1308. transformDirection: function ( m ) {
  1309. // input: THREE.Matrix4 affine matrix
  1310. // vector interpreted as a direction
  1311. var x = this.x, y = this.y, z = this.z;
  1312. var e = m.elements;
  1313. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1314. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1315. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1316. this.normalize();
  1317. return this;
  1318. },
  1319. divide: function ( v ) {
  1320. this.x /= v.x;
  1321. this.y /= v.y;
  1322. this.z /= v.z;
  1323. return this;
  1324. },
  1325. divideScalar: function ( scalar ) {
  1326. if ( scalar !== 0 ) {
  1327. var invScalar = 1 / scalar;
  1328. this.x *= invScalar;
  1329. this.y *= invScalar;
  1330. this.z *= invScalar;
  1331. } else {
  1332. this.x = 0;
  1333. this.y = 0;
  1334. this.z = 0;
  1335. }
  1336. return this;
  1337. },
  1338. min: function ( v ) {
  1339. if ( this.x > v.x ) {
  1340. this.x = v.x;
  1341. }
  1342. if ( this.y > v.y ) {
  1343. this.y = v.y;
  1344. }
  1345. if ( this.z > v.z ) {
  1346. this.z = v.z;
  1347. }
  1348. return this;
  1349. },
  1350. max: function ( v ) {
  1351. if ( this.x < v.x ) {
  1352. this.x = v.x;
  1353. }
  1354. if ( this.y < v.y ) {
  1355. this.y = v.y;
  1356. }
  1357. if ( this.z < v.z ) {
  1358. this.z = v.z;
  1359. }
  1360. return this;
  1361. },
  1362. clamp: function ( min, max ) {
  1363. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1364. if ( this.x < min.x ) {
  1365. this.x = min.x;
  1366. } else if ( this.x > max.x ) {
  1367. this.x = max.x;
  1368. }
  1369. if ( this.y < min.y ) {
  1370. this.y = min.y;
  1371. } else if ( this.y > max.y ) {
  1372. this.y = max.y;
  1373. }
  1374. if ( this.z < min.z ) {
  1375. this.z = min.z;
  1376. } else if ( this.z > max.z ) {
  1377. this.z = max.z;
  1378. }
  1379. return this;
  1380. },
  1381. clampScalar: function () {
  1382. var min, max;
  1383. return function clampScalar( minVal, maxVal ) {
  1384. if ( min === undefined ) {
  1385. min = new THREE.Vector3();
  1386. max = new THREE.Vector3();
  1387. }
  1388. min.set( minVal, minVal, minVal );
  1389. max.set( maxVal, maxVal, maxVal );
  1390. return this.clamp( min, max );
  1391. };
  1392. }(),
  1393. floor: function () {
  1394. this.x = Math.floor( this.x );
  1395. this.y = Math.floor( this.y );
  1396. this.z = Math.floor( this.z );
  1397. return this;
  1398. },
  1399. ceil: function () {
  1400. this.x = Math.ceil( this.x );
  1401. this.y = Math.ceil( this.y );
  1402. this.z = Math.ceil( this.z );
  1403. return this;
  1404. },
  1405. round: function () {
  1406. this.x = Math.round( this.x );
  1407. this.y = Math.round( this.y );
  1408. this.z = Math.round( this.z );
  1409. return this;
  1410. },
  1411. roundToZero: function () {
  1412. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1413. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1414. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1415. return this;
  1416. },
  1417. negate: function () {
  1418. this.x = - this.x;
  1419. this.y = - this.y;
  1420. this.z = - this.z;
  1421. return this;
  1422. },
  1423. dot: function ( v ) {
  1424. return this.x * v.x + this.y * v.y + this.z * v.z;
  1425. },
  1426. lengthSq: function () {
  1427. return this.x * this.x + this.y * this.y + this.z * this.z;
  1428. },
  1429. length: function () {
  1430. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1431. },
  1432. lengthManhattan: function () {
  1433. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1434. },
  1435. normalize: function () {
  1436. return this.divideScalar( this.length() );
  1437. },
  1438. setLength: function ( l ) {
  1439. var oldLength = this.length();
  1440. if ( oldLength !== 0 && l !== oldLength ) {
  1441. this.multiplyScalar( l / oldLength );
  1442. }
  1443. return this;
  1444. },
  1445. lerp: function ( v, alpha ) {
  1446. this.x += ( v.x - this.x ) * alpha;
  1447. this.y += ( v.y - this.y ) * alpha;
  1448. this.z += ( v.z - this.z ) * alpha;
  1449. return this;
  1450. },
  1451. lerpVectors: function ( v1, v2, alpha ) {
  1452. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1453. return this;
  1454. },
  1455. cross: function ( v, w ) {
  1456. if ( w !== undefined ) {
  1457. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1458. return this.crossVectors( v, w );
  1459. }
  1460. var x = this.x, y = this.y, z = this.z;
  1461. this.x = y * v.z - z * v.y;
  1462. this.y = z * v.x - x * v.z;
  1463. this.z = x * v.y - y * v.x;
  1464. return this;
  1465. },
  1466. crossVectors: function ( a, b ) {
  1467. var ax = a.x, ay = a.y, az = a.z;
  1468. var bx = b.x, by = b.y, bz = b.z;
  1469. this.x = ay * bz - az * by;
  1470. this.y = az * bx - ax * bz;
  1471. this.z = ax * by - ay * bx;
  1472. return this;
  1473. },
  1474. projectOnVector: function () {
  1475. var v1, dot;
  1476. return function projectOnVector( vector ) {
  1477. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1478. v1.copy( vector ).normalize();
  1479. dot = this.dot( v1 );
  1480. return this.copy( v1 ).multiplyScalar( dot );
  1481. };
  1482. }(),
  1483. projectOnPlane: function () {
  1484. var v1;
  1485. return function projectOnPlane( planeNormal ) {
  1486. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1487. v1.copy( this ).projectOnVector( planeNormal );
  1488. return this.sub( v1 );
  1489. }
  1490. }(),
  1491. reflect: function () {
  1492. // reflect incident vector off plane orthogonal to normal
  1493. // normal is assumed to have unit length
  1494. var v1;
  1495. return function reflect( normal ) {
  1496. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1497. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1498. }
  1499. }(),
  1500. angleTo: function ( v ) {
  1501. var theta = this.dot( v ) / ( this.length() * v.length() );
  1502. // clamp, to handle numerical problems
  1503. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1504. },
  1505. distanceTo: function ( v ) {
  1506. return Math.sqrt( this.distanceToSquared( v ) );
  1507. },
  1508. distanceToSquared: function ( v ) {
  1509. var dx = this.x - v.x;
  1510. var dy = this.y - v.y;
  1511. var dz = this.z - v.z;
  1512. return dx * dx + dy * dy + dz * dz;
  1513. },
  1514. setEulerFromRotationMatrix: function ( m, order ) {
  1515. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1516. },
  1517. setEulerFromQuaternion: function ( q, order ) {
  1518. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1519. },
  1520. getPositionFromMatrix: function ( m ) {
  1521. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1522. return this.setFromMatrixPosition( m );
  1523. },
  1524. getScaleFromMatrix: function ( m ) {
  1525. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1526. return this.setFromMatrixScale( m );
  1527. },
  1528. getColumnFromMatrix: function ( index, matrix ) {
  1529. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1530. return this.setFromMatrixColumn( index, matrix );
  1531. },
  1532. setFromMatrixPosition: function ( m ) {
  1533. this.x = m.elements[ 12 ];
  1534. this.y = m.elements[ 13 ];
  1535. this.z = m.elements[ 14 ];
  1536. return this;
  1537. },
  1538. setFromMatrixScale: function ( m ) {
  1539. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1540. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1541. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1542. this.x = sx;
  1543. this.y = sy;
  1544. this.z = sz;
  1545. return this;
  1546. },
  1547. setFromMatrixColumn: function ( index, matrix ) {
  1548. var offset = index * 4;
  1549. var me = matrix.elements;
  1550. this.x = me[ offset ];
  1551. this.y = me[ offset + 1 ];
  1552. this.z = me[ offset + 2 ];
  1553. return this;
  1554. },
  1555. equals: function ( v ) {
  1556. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1557. },
  1558. fromArray: function ( array, offset ) {
  1559. if ( offset === undefined ) offset = 0;
  1560. this.x = array[ offset ];
  1561. this.y = array[ offset + 1 ];
  1562. this.z = array[ offset + 2 ];
  1563. return this;
  1564. },
  1565. toArray: function ( array, offset ) {
  1566. if ( array === undefined ) array = [];
  1567. if ( offset === undefined ) offset = 0;
  1568. array[ offset ] = this.x;
  1569. array[ offset + 1 ] = this.y;
  1570. array[ offset + 2 ] = this.z;
  1571. return array;
  1572. },
  1573. fromAttribute: function ( attribute, index, offset ) {
  1574. if ( offset === undefined ) offset = 0;
  1575. index = index * attribute.itemSize + offset;
  1576. this.x = attribute.array[ index ];
  1577. this.y = attribute.array[ index + 1 ];
  1578. this.z = attribute.array[ index + 2 ];
  1579. return this;
  1580. }
  1581. };
  1582. // File:src/math/Vector4.js
  1583. /**
  1584. * @author supereggbert / http://www.paulbrunt.co.uk/
  1585. * @author philogb / http://blog.thejit.org/
  1586. * @author mikael emtinger / http://gomo.se/
  1587. * @author egraether / http://egraether.com/
  1588. * @author WestLangley / http://github.com/WestLangley
  1589. */
  1590. THREE.Vector4 = function ( x, y, z, w ) {
  1591. this.x = x || 0;
  1592. this.y = y || 0;
  1593. this.z = z || 0;
  1594. this.w = ( w !== undefined ) ? w : 1;
  1595. };
  1596. THREE.Vector4.prototype = {
  1597. constructor: THREE.Vector4,
  1598. set: function ( x, y, z, w ) {
  1599. this.x = x;
  1600. this.y = y;
  1601. this.z = z;
  1602. this.w = w;
  1603. return this;
  1604. },
  1605. setX: function ( x ) {
  1606. this.x = x;
  1607. return this;
  1608. },
  1609. setY: function ( y ) {
  1610. this.y = y;
  1611. return this;
  1612. },
  1613. setZ: function ( z ) {
  1614. this.z = z;
  1615. return this;
  1616. },
  1617. setW: function ( w ) {
  1618. this.w = w;
  1619. return this;
  1620. },
  1621. setComponent: function ( index, value ) {
  1622. switch ( index ) {
  1623. case 0: this.x = value; break;
  1624. case 1: this.y = value; break;
  1625. case 2: this.z = value; break;
  1626. case 3: this.w = value; break;
  1627. default: throw new Error( 'index is out of range: ' + index );
  1628. }
  1629. },
  1630. getComponent: function ( index ) {
  1631. switch ( index ) {
  1632. case 0: return this.x;
  1633. case 1: return this.y;
  1634. case 2: return this.z;
  1635. case 3: return this.w;
  1636. default: throw new Error( 'index is out of range: ' + index );
  1637. }
  1638. },
  1639. clone: function () {
  1640. return new this.constructor( this.x, this.y, this.z, this.w );
  1641. },
  1642. copy: function ( v ) {
  1643. this.x = v.x;
  1644. this.y = v.y;
  1645. this.z = v.z;
  1646. this.w = ( v.w !== undefined ) ? v.w : 1;
  1647. return this;
  1648. },
  1649. add: function ( v, w ) {
  1650. if ( w !== undefined ) {
  1651. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1652. return this.addVectors( v, w );
  1653. }
  1654. this.x += v.x;
  1655. this.y += v.y;
  1656. this.z += v.z;
  1657. this.w += v.w;
  1658. return this;
  1659. },
  1660. addScalar: function ( s ) {
  1661. this.x += s;
  1662. this.y += s;
  1663. this.z += s;
  1664. this.w += s;
  1665. return this;
  1666. },
  1667. addVectors: function ( a, b ) {
  1668. this.x = a.x + b.x;
  1669. this.y = a.y + b.y;
  1670. this.z = a.z + b.z;
  1671. this.w = a.w + b.w;
  1672. return this;
  1673. },
  1674. addScaledVector: function ( v, s ) {
  1675. this.x += v.x * s;
  1676. this.y += v.y * s;
  1677. this.z += v.z * s;
  1678. this.w += v.w * s;
  1679. return this;
  1680. },
  1681. sub: function ( v, w ) {
  1682. if ( w !== undefined ) {
  1683. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1684. return this.subVectors( v, w );
  1685. }
  1686. this.x -= v.x;
  1687. this.y -= v.y;
  1688. this.z -= v.z;
  1689. this.w -= v.w;
  1690. return this;
  1691. },
  1692. subScalar: function ( s ) {
  1693. this.x -= s;
  1694. this.y -= s;
  1695. this.z -= s;
  1696. this.w -= s;
  1697. return this;
  1698. },
  1699. subVectors: function ( a, b ) {
  1700. this.x = a.x - b.x;
  1701. this.y = a.y - b.y;
  1702. this.z = a.z - b.z;
  1703. this.w = a.w - b.w;
  1704. return this;
  1705. },
  1706. multiplyScalar: function ( scalar ) {
  1707. this.x *= scalar;
  1708. this.y *= scalar;
  1709. this.z *= scalar;
  1710. this.w *= scalar;
  1711. return this;
  1712. },
  1713. applyMatrix4: function ( m ) {
  1714. var x = this.x;
  1715. var y = this.y;
  1716. var z = this.z;
  1717. var w = this.w;
  1718. var e = m.elements;
  1719. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1720. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1721. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1722. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1723. return this;
  1724. },
  1725. divideScalar: function ( scalar ) {
  1726. if ( scalar !== 0 ) {
  1727. var invScalar = 1 / scalar;
  1728. this.x *= invScalar;
  1729. this.y *= invScalar;
  1730. this.z *= invScalar;
  1731. this.w *= invScalar;
  1732. } else {
  1733. this.x = 0;
  1734. this.y = 0;
  1735. this.z = 0;
  1736. this.w = 1;
  1737. }
  1738. return this;
  1739. },
  1740. setAxisAngleFromQuaternion: function ( q ) {
  1741. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1742. // q is assumed to be normalized
  1743. this.w = 2 * Math.acos( q.w );
  1744. var s = Math.sqrt( 1 - q.w * q.w );
  1745. if ( s < 0.0001 ) {
  1746. this.x = 1;
  1747. this.y = 0;
  1748. this.z = 0;
  1749. } else {
  1750. this.x = q.x / s;
  1751. this.y = q.y / s;
  1752. this.z = q.z / s;
  1753. }
  1754. return this;
  1755. },
  1756. setAxisAngleFromRotationMatrix: function ( m ) {
  1757. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1758. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1759. var angle, x, y, z, // variables for result
  1760. epsilon = 0.01, // margin to allow for rounding errors
  1761. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1762. te = m.elements,
  1763. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1764. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1765. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1766. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1767. && ( Math.abs( m13 - m31 ) < epsilon )
  1768. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1769. // singularity found
  1770. // first check for identity matrix which must have +1 for all terms
  1771. // in leading diagonal and zero in other terms
  1772. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1773. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1774. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1775. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1776. // this singularity is identity matrix so angle = 0
  1777. this.set( 1, 0, 0, 0 );
  1778. return this; // zero angle, arbitrary axis
  1779. }
  1780. // otherwise this singularity is angle = 180
  1781. angle = Math.PI;
  1782. var xx = ( m11 + 1 ) / 2;
  1783. var yy = ( m22 + 1 ) / 2;
  1784. var zz = ( m33 + 1 ) / 2;
  1785. var xy = ( m12 + m21 ) / 4;
  1786. var xz = ( m13 + m31 ) / 4;
  1787. var yz = ( m23 + m32 ) / 4;
  1788. if ( ( xx > yy ) && ( xx > zz ) ) {
  1789. // m11 is the largest diagonal term
  1790. if ( xx < epsilon ) {
  1791. x = 0;
  1792. y = 0.707106781;
  1793. z = 0.707106781;
  1794. } else {
  1795. x = Math.sqrt( xx );
  1796. y = xy / x;
  1797. z = xz / x;
  1798. }
  1799. } else if ( yy > zz ) {
  1800. // m22 is the largest diagonal term
  1801. if ( yy < epsilon ) {
  1802. x = 0.707106781;
  1803. y = 0;
  1804. z = 0.707106781;
  1805. } else {
  1806. y = Math.sqrt( yy );
  1807. x = xy / y;
  1808. z = yz / y;
  1809. }
  1810. } else {
  1811. // m33 is the largest diagonal term so base result on this
  1812. if ( zz < epsilon ) {
  1813. x = 0.707106781;
  1814. y = 0.707106781;
  1815. z = 0;
  1816. } else {
  1817. z = Math.sqrt( zz );
  1818. x = xz / z;
  1819. y = yz / z;
  1820. }
  1821. }
  1822. this.set( x, y, z, angle );
  1823. return this; // return 180 deg rotation
  1824. }
  1825. // as we have reached here there are no singularities so we can handle normally
  1826. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1827. + ( m13 - m31 ) * ( m13 - m31 )
  1828. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1829. if ( Math.abs( s ) < 0.001 ) s = 1;
  1830. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1831. // caught by singularity test above, but I've left it in just in case
  1832. this.x = ( m32 - m23 ) / s;
  1833. this.y = ( m13 - m31 ) / s;
  1834. this.z = ( m21 - m12 ) / s;
  1835. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1836. return this;
  1837. },
  1838. min: function ( v ) {
  1839. if ( this.x > v.x ) {
  1840. this.x = v.x;
  1841. }
  1842. if ( this.y > v.y ) {
  1843. this.y = v.y;
  1844. }
  1845. if ( this.z > v.z ) {
  1846. this.z = v.z;
  1847. }
  1848. if ( this.w > v.w ) {
  1849. this.w = v.w;
  1850. }
  1851. return this;
  1852. },
  1853. max: function ( v ) {
  1854. if ( this.x < v.x ) {
  1855. this.x = v.x;
  1856. }
  1857. if ( this.y < v.y ) {
  1858. this.y = v.y;
  1859. }
  1860. if ( this.z < v.z ) {
  1861. this.z = v.z;
  1862. }
  1863. if ( this.w < v.w ) {
  1864. this.w = v.w;
  1865. }
  1866. return this;
  1867. },
  1868. clamp: function ( min, max ) {
  1869. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1870. if ( this.x < min.x ) {
  1871. this.x = min.x;
  1872. } else if ( this.x > max.x ) {
  1873. this.x = max.x;
  1874. }
  1875. if ( this.y < min.y ) {
  1876. this.y = min.y;
  1877. } else if ( this.y > max.y ) {
  1878. this.y = max.y;
  1879. }
  1880. if ( this.z < min.z ) {
  1881. this.z = min.z;
  1882. } else if ( this.z > max.z ) {
  1883. this.z = max.z;
  1884. }
  1885. if ( this.w < min.w ) {
  1886. this.w = min.w;
  1887. } else if ( this.w > max.w ) {
  1888. this.w = max.w;
  1889. }
  1890. return this;
  1891. },
  1892. clampScalar: function () {
  1893. var min, max;
  1894. return function clampScalar( minVal, maxVal ) {
  1895. if ( min === undefined ) {
  1896. min = new THREE.Vector4();
  1897. max = new THREE.Vector4();
  1898. }
  1899. min.set( minVal, minVal, minVal, minVal );
  1900. max.set( maxVal, maxVal, maxVal, maxVal );
  1901. return this.clamp( min, max );
  1902. };
  1903. }(),
  1904. floor: function () {
  1905. this.x = Math.floor( this.x );
  1906. this.y = Math.floor( this.y );
  1907. this.z = Math.floor( this.z );
  1908. this.w = Math.floor( this.w );
  1909. return this;
  1910. },
  1911. ceil: function () {
  1912. this.x = Math.ceil( this.x );
  1913. this.y = Math.ceil( this.y );
  1914. this.z = Math.ceil( this.z );
  1915. this.w = Math.ceil( this.w );
  1916. return this;
  1917. },
  1918. round: function () {
  1919. this.x = Math.round( this.x );
  1920. this.y = Math.round( this.y );
  1921. this.z = Math.round( this.z );
  1922. this.w = Math.round( this.w );
  1923. return this;
  1924. },
  1925. roundToZero: function () {
  1926. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1927. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1928. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1929. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1930. return this;
  1931. },
  1932. negate: function () {
  1933. this.x = - this.x;
  1934. this.y = - this.y;
  1935. this.z = - this.z;
  1936. this.w = - this.w;
  1937. return this;
  1938. },
  1939. dot: function ( v ) {
  1940. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1941. },
  1942. lengthSq: function () {
  1943. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1944. },
  1945. length: function () {
  1946. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1947. },
  1948. lengthManhattan: function () {
  1949. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1950. },
  1951. normalize: function () {
  1952. return this.divideScalar( this.length() );
  1953. },
  1954. setLength: function ( l ) {
  1955. var oldLength = this.length();
  1956. if ( oldLength !== 0 && l !== oldLength ) {
  1957. this.multiplyScalar( l / oldLength );
  1958. }
  1959. return this;
  1960. },
  1961. lerp: function ( v, alpha ) {
  1962. this.x += ( v.x - this.x ) * alpha;
  1963. this.y += ( v.y - this.y ) * alpha;
  1964. this.z += ( v.z - this.z ) * alpha;
  1965. this.w += ( v.w - this.w ) * alpha;
  1966. return this;
  1967. },
  1968. lerpVectors: function ( v1, v2, alpha ) {
  1969. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1970. return this;
  1971. },
  1972. equals: function ( v ) {
  1973. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1974. },
  1975. fromArray: function ( array, offset ) {
  1976. if ( offset === undefined ) offset = 0;
  1977. this.x = array[ offset ];
  1978. this.y = array[ offset + 1 ];
  1979. this.z = array[ offset + 2 ];
  1980. this.w = array[ offset + 3 ];
  1981. return this;
  1982. },
  1983. toArray: function ( array, offset ) {
  1984. if ( array === undefined ) array = [];
  1985. if ( offset === undefined ) offset = 0;
  1986. array[ offset ] = this.x;
  1987. array[ offset + 1 ] = this.y;
  1988. array[ offset + 2 ] = this.z;
  1989. array[ offset + 3 ] = this.w;
  1990. return array;
  1991. },
  1992. fromAttribute: function ( attribute, index, offset ) {
  1993. if ( offset === undefined ) offset = 0;
  1994. index = index * attribute.itemSize + offset;
  1995. this.x = attribute.array[ index ];
  1996. this.y = attribute.array[ index + 1 ];
  1997. this.z = attribute.array[ index + 2 ];
  1998. this.w = attribute.array[ index + 3 ];
  1999. return this;
  2000. }
  2001. };
  2002. // File:src/math/Euler.js
  2003. /**
  2004. * @author mrdoob / http://mrdoob.com/
  2005. * @author WestLangley / http://github.com/WestLangley
  2006. * @author bhouston / http://clara.io
  2007. */
  2008. THREE.Euler = function ( x, y, z, order ) {
  2009. this._x = x || 0;
  2010. this._y = y || 0;
  2011. this._z = z || 0;
  2012. this._order = order || THREE.Euler.DefaultOrder;
  2013. };
  2014. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2015. THREE.Euler.DefaultOrder = 'XYZ';
  2016. THREE.Euler.prototype = {
  2017. constructor: THREE.Euler,
  2018. get x () {
  2019. return this._x;
  2020. },
  2021. set x ( value ) {
  2022. this._x = value;
  2023. this.onChangeCallback();
  2024. },
  2025. get y () {
  2026. return this._y;
  2027. },
  2028. set y ( value ) {
  2029. this._y = value;
  2030. this.onChangeCallback();
  2031. },
  2032. get z () {
  2033. return this._z;
  2034. },
  2035. set z ( value ) {
  2036. this._z = value;
  2037. this.onChangeCallback();
  2038. },
  2039. get order () {
  2040. return this._order;
  2041. },
  2042. set order ( value ) {
  2043. this._order = value;
  2044. this.onChangeCallback();
  2045. },
  2046. set: function ( x, y, z, order ) {
  2047. this._x = x;
  2048. this._y = y;
  2049. this._z = z;
  2050. this._order = order || this._order;
  2051. this.onChangeCallback();
  2052. return this;
  2053. },
  2054. clone: function () {
  2055. return new this.constructor( this._x, this._y, this._z, this._order);
  2056. },
  2057. copy: function ( euler ) {
  2058. this._x = euler._x;
  2059. this._y = euler._y;
  2060. this._z = euler._z;
  2061. this._order = euler._order;
  2062. this.onChangeCallback();
  2063. return this;
  2064. },
  2065. setFromRotationMatrix: function ( m, order, update ) {
  2066. var clamp = THREE.Math.clamp;
  2067. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2068. var te = m.elements;
  2069. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2070. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2071. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2072. order = order || this._order;
  2073. if ( order === 'XYZ' ) {
  2074. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2075. if ( Math.abs( m13 ) < 0.99999 ) {
  2076. this._x = Math.atan2( - m23, m33 );
  2077. this._z = Math.atan2( - m12, m11 );
  2078. } else {
  2079. this._x = Math.atan2( m32, m22 );
  2080. this._z = 0;
  2081. }
  2082. } else if ( order === 'YXZ' ) {
  2083. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2084. if ( Math.abs( m23 ) < 0.99999 ) {
  2085. this._y = Math.atan2( m13, m33 );
  2086. this._z = Math.atan2( m21, m22 );
  2087. } else {
  2088. this._y = Math.atan2( - m31, m11 );
  2089. this._z = 0;
  2090. }
  2091. } else if ( order === 'ZXY' ) {
  2092. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2093. if ( Math.abs( m32 ) < 0.99999 ) {
  2094. this._y = Math.atan2( - m31, m33 );
  2095. this._z = Math.atan2( - m12, m22 );
  2096. } else {
  2097. this._y = 0;
  2098. this._z = Math.atan2( m21, m11 );
  2099. }
  2100. } else if ( order === 'ZYX' ) {
  2101. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2102. if ( Math.abs( m31 ) < 0.99999 ) {
  2103. this._x = Math.atan2( m32, m33 );
  2104. this._z = Math.atan2( m21, m11 );
  2105. } else {
  2106. this._x = 0;
  2107. this._z = Math.atan2( - m12, m22 );
  2108. }
  2109. } else if ( order === 'YZX' ) {
  2110. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2111. if ( Math.abs( m21 ) < 0.99999 ) {
  2112. this._x = Math.atan2( - m23, m22 );
  2113. this._y = Math.atan2( - m31, m11 );
  2114. } else {
  2115. this._x = 0;
  2116. this._y = Math.atan2( m13, m33 );
  2117. }
  2118. } else if ( order === 'XZY' ) {
  2119. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2120. if ( Math.abs( m12 ) < 0.99999 ) {
  2121. this._x = Math.atan2( m32, m22 );
  2122. this._y = Math.atan2( m13, m11 );
  2123. } else {
  2124. this._x = Math.atan2( - m23, m33 );
  2125. this._y = 0;
  2126. }
  2127. } else {
  2128. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2129. }
  2130. this._order = order;
  2131. if ( update !== false ) this.onChangeCallback();
  2132. return this;
  2133. },
  2134. setFromQuaternion: function () {
  2135. var matrix;
  2136. return function ( q, order, update ) {
  2137. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2138. matrix.makeRotationFromQuaternion( q );
  2139. this.setFromRotationMatrix( matrix, order, update );
  2140. return this;
  2141. };
  2142. }(),
  2143. setFromVector3: function ( v, order ) {
  2144. return this.set( v.x, v.y, v.z, order || this._order );
  2145. },
  2146. reorder: function () {
  2147. // WARNING: this discards revolution information -bhouston
  2148. var q = new THREE.Quaternion();
  2149. return function ( newOrder ) {
  2150. q.setFromEuler( this );
  2151. this.setFromQuaternion( q, newOrder );
  2152. };
  2153. }(),
  2154. equals: function ( euler ) {
  2155. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2156. },
  2157. fromArray: function ( array ) {
  2158. this._x = array[ 0 ];
  2159. this._y = array[ 1 ];
  2160. this._z = array[ 2 ];
  2161. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2162. this.onChangeCallback();
  2163. return this;
  2164. },
  2165. toArray: function ( array, offset ) {
  2166. if ( array === undefined ) array = [];
  2167. if ( offset === undefined ) offset = 0;
  2168. array[ offset ] = this._x;
  2169. array[ offset + 1 ] = this._y;
  2170. array[ offset + 2 ] = this._z;
  2171. array[ offset + 3 ] = this._order;
  2172. return array;
  2173. },
  2174. toVector3: function ( optionalResult ) {
  2175. if ( optionalResult ) {
  2176. return optionalResult.set( this._x, this._y, this._z );
  2177. } else {
  2178. return new THREE.Vector3( this._x, this._y, this._z );
  2179. }
  2180. },
  2181. onChange: function ( callback ) {
  2182. this.onChangeCallback = callback;
  2183. return this;
  2184. },
  2185. onChangeCallback: function () {}
  2186. };
  2187. // File:src/math/Line3.js
  2188. /**
  2189. * @author bhouston / http://clara.io
  2190. */
  2191. THREE.Line3 = function ( start, end ) {
  2192. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2193. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2194. };
  2195. THREE.Line3.prototype = {
  2196. constructor: THREE.Line3,
  2197. set: function ( start, end ) {
  2198. this.start.copy( start );
  2199. this.end.copy( end );
  2200. return this;
  2201. },
  2202. clone: function () {
  2203. return new this.constructor().copy( this );
  2204. },
  2205. copy: function ( line ) {
  2206. this.start.copy( line.start );
  2207. this.end.copy( line.end );
  2208. return this;
  2209. },
  2210. center: function ( optionalTarget ) {
  2211. var result = optionalTarget || new THREE.Vector3();
  2212. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2213. },
  2214. delta: function ( optionalTarget ) {
  2215. var result = optionalTarget || new THREE.Vector3();
  2216. return result.subVectors( this.end, this.start );
  2217. },
  2218. distanceSq: function () {
  2219. return this.start.distanceToSquared( this.end );
  2220. },
  2221. distance: function () {
  2222. return this.start.distanceTo( this.end );
  2223. },
  2224. at: function ( t, optionalTarget ) {
  2225. var result = optionalTarget || new THREE.Vector3();
  2226. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2227. },
  2228. closestPointToPointParameter: function () {
  2229. var startP = new THREE.Vector3();
  2230. var startEnd = new THREE.Vector3();
  2231. return function ( point, clampToLine ) {
  2232. startP.subVectors( point, this.start );
  2233. startEnd.subVectors( this.end, this.start );
  2234. var startEnd2 = startEnd.dot( startEnd );
  2235. var startEnd_startP = startEnd.dot( startP );
  2236. var t = startEnd_startP / startEnd2;
  2237. if ( clampToLine ) {
  2238. t = THREE.Math.clamp( t, 0, 1 );
  2239. }
  2240. return t;
  2241. };
  2242. }(),
  2243. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2244. var t = this.closestPointToPointParameter( point, clampToLine );
  2245. var result = optionalTarget || new THREE.Vector3();
  2246. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2247. },
  2248. applyMatrix4: function ( matrix ) {
  2249. this.start.applyMatrix4( matrix );
  2250. this.end.applyMatrix4( matrix );
  2251. return this;
  2252. },
  2253. equals: function ( line ) {
  2254. return line.start.equals( this.start ) && line.end.equals( this.end );
  2255. }
  2256. };
  2257. // File:src/math/Box2.js
  2258. /**
  2259. * @author bhouston / http://clara.io
  2260. */
  2261. THREE.Box2 = function ( min, max ) {
  2262. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2263. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2264. };
  2265. THREE.Box2.prototype = {
  2266. constructor: THREE.Box2,
  2267. set: function ( min, max ) {
  2268. this.min.copy( min );
  2269. this.max.copy( max );
  2270. return this;
  2271. },
  2272. setFromPoints: function ( points ) {
  2273. this.makeEmpty();
  2274. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2275. this.expandByPoint( points[ i ] )
  2276. }
  2277. return this;
  2278. },
  2279. setFromCenterAndSize: function () {
  2280. var v1 = new THREE.Vector2();
  2281. return function ( center, size ) {
  2282. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2283. this.min.copy( center ).sub( halfSize );
  2284. this.max.copy( center ).add( halfSize );
  2285. return this;
  2286. };
  2287. }(),
  2288. clone: function () {
  2289. return new this.constructor().copy( this );
  2290. },
  2291. copy: function ( box ) {
  2292. this.min.copy( box.min );
  2293. this.max.copy( box.max );
  2294. return this;
  2295. },
  2296. makeEmpty: function () {
  2297. this.min.x = this.min.y = Infinity;
  2298. this.max.x = this.max.y = - Infinity;
  2299. return this;
  2300. },
  2301. empty: function () {
  2302. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2303. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2304. },
  2305. center: function ( optionalTarget ) {
  2306. var result = optionalTarget || new THREE.Vector2();
  2307. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2308. },
  2309. size: function ( optionalTarget ) {
  2310. var result = optionalTarget || new THREE.Vector2();
  2311. return result.subVectors( this.max, this.min );
  2312. },
  2313. expandByPoint: function ( point ) {
  2314. this.min.min( point );
  2315. this.max.max( point );
  2316. return this;
  2317. },
  2318. expandByVector: function ( vector ) {
  2319. this.min.sub( vector );
  2320. this.max.add( vector );
  2321. return this;
  2322. },
  2323. expandByScalar: function ( scalar ) {
  2324. this.min.addScalar( - scalar );
  2325. this.max.addScalar( scalar );
  2326. return this;
  2327. },
  2328. containsPoint: function ( point ) {
  2329. if ( point.x < this.min.x || point.x > this.max.x ||
  2330. point.y < this.min.y || point.y > this.max.y ) {
  2331. return false;
  2332. }
  2333. return true;
  2334. },
  2335. containsBox: function ( box ) {
  2336. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2337. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2338. return true;
  2339. }
  2340. return false;
  2341. },
  2342. getParameter: function ( point, optionalTarget ) {
  2343. // This can potentially have a divide by zero if the box
  2344. // has a size dimension of 0.
  2345. var result = optionalTarget || new THREE.Vector2();
  2346. return result.set(
  2347. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2348. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2349. );
  2350. },
  2351. isIntersectionBox: function ( box ) {
  2352. // using 6 splitting planes to rule out intersections.
  2353. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2354. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2355. return false;
  2356. }
  2357. return true;
  2358. },
  2359. clampPoint: function ( point, optionalTarget ) {
  2360. var result = optionalTarget || new THREE.Vector2();
  2361. return result.copy( point ).clamp( this.min, this.max );
  2362. },
  2363. distanceToPoint: function () {
  2364. var v1 = new THREE.Vector2();
  2365. return function ( point ) {
  2366. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2367. return clampedPoint.sub( point ).length();
  2368. };
  2369. }(),
  2370. intersect: function ( box ) {
  2371. this.min.max( box.min );
  2372. this.max.min( box.max );
  2373. return this;
  2374. },
  2375. union: function ( box ) {
  2376. this.min.min( box.min );
  2377. this.max.max( box.max );
  2378. return this;
  2379. },
  2380. translate: function ( offset ) {
  2381. this.min.add( offset );
  2382. this.max.add( offset );
  2383. return this;
  2384. },
  2385. equals: function ( box ) {
  2386. return box.min.equals( this.min ) && box.max.equals( this.max );
  2387. }
  2388. };
  2389. // File:src/math/Box3.js
  2390. /**
  2391. * @author bhouston / http://clara.io
  2392. * @author WestLangley / http://github.com/WestLangley
  2393. */
  2394. THREE.Box3 = function ( min, max ) {
  2395. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2396. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2397. };
  2398. THREE.Box3.prototype = {
  2399. constructor: THREE.Box3,
  2400. set: function ( min, max ) {
  2401. this.min.copy( min );
  2402. this.max.copy( max );
  2403. return this;
  2404. },
  2405. setFromPoints: function ( points ) {
  2406. this.makeEmpty();
  2407. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2408. this.expandByPoint( points[ i ] );
  2409. }
  2410. return this;
  2411. },
  2412. setFromCenterAndSize: function () {
  2413. var v1 = new THREE.Vector3();
  2414. return function ( center, size ) {
  2415. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2416. this.min.copy( center ).sub( halfSize );
  2417. this.max.copy( center ).add( halfSize );
  2418. return this;
  2419. };
  2420. }(),
  2421. setFromObject: function () {
  2422. // Computes the world-axis-aligned bounding box of an object (including its children),
  2423. // accounting for both the object's, and children's, world transforms
  2424. var v1 = new THREE.Vector3();
  2425. return function ( object ) {
  2426. var scope = this;
  2427. object.updateMatrixWorld( true );
  2428. this.makeEmpty();
  2429. object.traverse( function ( node ) {
  2430. var geometry = node.geometry;
  2431. if ( geometry !== undefined ) {
  2432. if ( geometry instanceof THREE.Geometry ) {
  2433. var vertices = geometry.vertices;
  2434. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2435. v1.copy( vertices[ i ] );
  2436. v1.applyMatrix4( node.matrixWorld );
  2437. scope.expandByPoint( v1 );
  2438. }
  2439. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2440. var positions = geometry.attributes[ 'position' ].array;
  2441. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2442. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2443. v1.applyMatrix4( node.matrixWorld );
  2444. scope.expandByPoint( v1 );
  2445. }
  2446. }
  2447. }
  2448. } );
  2449. return this;
  2450. };
  2451. }(),
  2452. clone: function () {
  2453. return new this.constructor().copy( this );
  2454. },
  2455. copy: function ( box ) {
  2456. this.min.copy( box.min );
  2457. this.max.copy( box.max );
  2458. return this;
  2459. },
  2460. makeEmpty: function () {
  2461. this.min.x = this.min.y = this.min.z = Infinity;
  2462. this.max.x = this.max.y = this.max.z = - Infinity;
  2463. return this;
  2464. },
  2465. empty: function () {
  2466. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2467. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2468. },
  2469. center: function ( optionalTarget ) {
  2470. var result = optionalTarget || new THREE.Vector3();
  2471. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2472. },
  2473. size: function ( optionalTarget ) {
  2474. var result = optionalTarget || new THREE.Vector3();
  2475. return result.subVectors( this.max, this.min );
  2476. },
  2477. expandByPoint: function ( point ) {
  2478. this.min.min( point );
  2479. this.max.max( point );
  2480. return this;
  2481. },
  2482. expandByVector: function ( vector ) {
  2483. this.min.sub( vector );
  2484. this.max.add( vector );
  2485. return this;
  2486. },
  2487. expandByScalar: function ( scalar ) {
  2488. this.min.addScalar( - scalar );
  2489. this.max.addScalar( scalar );
  2490. return this;
  2491. },
  2492. containsPoint: function ( point ) {
  2493. if ( point.x < this.min.x || point.x > this.max.x ||
  2494. point.y < this.min.y || point.y > this.max.y ||
  2495. point.z < this.min.z || point.z > this.max.z ) {
  2496. return false;
  2497. }
  2498. return true;
  2499. },
  2500. containsBox: function ( box ) {
  2501. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2502. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2503. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2504. return true;
  2505. }
  2506. return false;
  2507. },
  2508. getParameter: function ( point, optionalTarget ) {
  2509. // This can potentially have a divide by zero if the box
  2510. // has a size dimension of 0.
  2511. var result = optionalTarget || new THREE.Vector3();
  2512. return result.set(
  2513. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2514. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2515. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2516. );
  2517. },
  2518. isIntersectionBox: function ( box ) {
  2519. // using 6 splitting planes to rule out intersections.
  2520. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2521. box.max.y < this.min.y || box.min.y > this.max.y ||
  2522. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2523. return false;
  2524. }
  2525. return true;
  2526. },
  2527. clampPoint: function ( point, optionalTarget ) {
  2528. var result = optionalTarget || new THREE.Vector3();
  2529. return result.copy( point ).clamp( this.min, this.max );
  2530. },
  2531. distanceToPoint: function () {
  2532. var v1 = new THREE.Vector3();
  2533. return function ( point ) {
  2534. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2535. return clampedPoint.sub( point ).length();
  2536. };
  2537. }(),
  2538. getBoundingSphere: function () {
  2539. var v1 = new THREE.Vector3();
  2540. return function ( optionalTarget ) {
  2541. var result = optionalTarget || new THREE.Sphere();
  2542. result.center = this.center();
  2543. result.radius = this.size( v1 ).length() * 0.5;
  2544. return result;
  2545. };
  2546. }(),
  2547. intersect: function ( box ) {
  2548. this.min.max( box.min );
  2549. this.max.min( box.max );
  2550. return this;
  2551. },
  2552. union: function ( box ) {
  2553. this.min.min( box.min );
  2554. this.max.max( box.max );
  2555. return this;
  2556. },
  2557. applyMatrix4: function () {
  2558. var points = [
  2559. new THREE.Vector3(),
  2560. new THREE.Vector3(),
  2561. new THREE.Vector3(),
  2562. new THREE.Vector3(),
  2563. new THREE.Vector3(),
  2564. new THREE.Vector3(),
  2565. new THREE.Vector3(),
  2566. new THREE.Vector3()
  2567. ];
  2568. return function ( matrix ) {
  2569. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2570. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2571. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2572. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2573. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2574. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2575. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2576. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2577. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2578. this.makeEmpty();
  2579. this.setFromPoints( points );
  2580. return this;
  2581. };
  2582. }(),
  2583. translate: function ( offset ) {
  2584. this.min.add( offset );
  2585. this.max.add( offset );
  2586. return this;
  2587. },
  2588. equals: function ( box ) {
  2589. return box.min.equals( this.min ) && box.max.equals( this.max );
  2590. }
  2591. };
  2592. // File:src/math/Matrix3.js
  2593. /**
  2594. * @author alteredq / http://alteredqualia.com/
  2595. * @author WestLangley / http://github.com/WestLangley
  2596. * @author bhouston / http://clara.io
  2597. */
  2598. THREE.Matrix3 = function () {
  2599. this.elements = new Float32Array( [
  2600. 1, 0, 0,
  2601. 0, 1, 0,
  2602. 0, 0, 1
  2603. ] );
  2604. if ( arguments.length > 0 ) {
  2605. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2606. }
  2607. };
  2608. THREE.Matrix3.prototype = {
  2609. constructor: THREE.Matrix3,
  2610. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2611. var te = this.elements;
  2612. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2613. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2614. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2615. return this;
  2616. },
  2617. identity: function () {
  2618. this.set(
  2619. 1, 0, 0,
  2620. 0, 1, 0,
  2621. 0, 0, 1
  2622. );
  2623. return this;
  2624. },
  2625. clone: function () {
  2626. return new this.constructor().fromArray( this.elements );
  2627. },
  2628. copy: function ( m ) {
  2629. var me = m.elements;
  2630. this.set(
  2631. me[ 0 ], me[ 3 ], me[ 6 ],
  2632. me[ 1 ], me[ 4 ], me[ 7 ],
  2633. me[ 2 ], me[ 5 ], me[ 8 ]
  2634. );
  2635. return this;
  2636. },
  2637. multiplyVector3: function ( vector ) {
  2638. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2639. return vector.applyMatrix3( this );
  2640. },
  2641. multiplyVector3Array: function ( a ) {
  2642. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2643. return this.applyToVector3Array( a );
  2644. },
  2645. applyToVector3Array: function () {
  2646. var v1;
  2647. return function ( array, offset, length ) {
  2648. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2649. if ( offset === undefined ) offset = 0;
  2650. if ( length === undefined ) length = array.length;
  2651. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2652. v1.fromArray( array, j );
  2653. v1.applyMatrix3( this );
  2654. v1.toArray( array, j );
  2655. }
  2656. return array;
  2657. };
  2658. }(),
  2659. applyToBuffer: function () {
  2660. var v1;
  2661. return function applyToBuffer( buffer, offset, length ) {
  2662. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2663. if ( offset === undefined ) offset = 0;
  2664. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2665. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2666. v1.x = buffer.getX( j );
  2667. v1.y = buffer.getY( j );
  2668. v1.z = buffer.getZ( j );
  2669. v1.applyMatrix3( this );
  2670. buffer.setXYZ( v1.x, v1.y, v1.z );
  2671. }
  2672. return buffer;
  2673. };
  2674. }(),
  2675. multiplyScalar: function ( s ) {
  2676. var te = this.elements;
  2677. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2678. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2679. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2680. return this;
  2681. },
  2682. determinant: function () {
  2683. var te = this.elements;
  2684. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2685. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2686. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2687. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2688. },
  2689. getInverse: function ( matrix, throwOnInvertible ) {
  2690. // input: THREE.Matrix4
  2691. // ( based on http://code.google.com/p/webgl-mjs/ )
  2692. var me = matrix.elements;
  2693. var te = this.elements;
  2694. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2695. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2696. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2697. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2698. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2699. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2700. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2701. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2702. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2703. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2704. // no inverse
  2705. if ( det === 0 ) {
  2706. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2707. if ( throwOnInvertible || false ) {
  2708. throw new Error( msg );
  2709. } else {
  2710. console.warn( msg );
  2711. }
  2712. this.identity();
  2713. return this;
  2714. }
  2715. this.multiplyScalar( 1.0 / det );
  2716. return this;
  2717. },
  2718. transpose: function () {
  2719. var tmp, m = this.elements;
  2720. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2721. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2722. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2723. return this;
  2724. },
  2725. flattenToArrayOffset: function ( array, offset ) {
  2726. var te = this.elements;
  2727. array[ offset ] = te[ 0 ];
  2728. array[ offset + 1 ] = te[ 1 ];
  2729. array[ offset + 2 ] = te[ 2 ];
  2730. array[ offset + 3 ] = te[ 3 ];
  2731. array[ offset + 4 ] = te[ 4 ];
  2732. array[ offset + 5 ] = te[ 5 ];
  2733. array[ offset + 6 ] = te[ 6 ];
  2734. array[ offset + 7 ] = te[ 7 ];
  2735. array[ offset + 8 ] = te[ 8 ];
  2736. return array;
  2737. },
  2738. getNormalMatrix: function ( m ) {
  2739. // input: THREE.Matrix4
  2740. this.getInverse( m ).transpose();
  2741. return this;
  2742. },
  2743. transposeIntoArray: function ( r ) {
  2744. var m = this.elements;
  2745. r[ 0 ] = m[ 0 ];
  2746. r[ 1 ] = m[ 3 ];
  2747. r[ 2 ] = m[ 6 ];
  2748. r[ 3 ] = m[ 1 ];
  2749. r[ 4 ] = m[ 4 ];
  2750. r[ 5 ] = m[ 7 ];
  2751. r[ 6 ] = m[ 2 ];
  2752. r[ 7 ] = m[ 5 ];
  2753. r[ 8 ] = m[ 8 ];
  2754. return this;
  2755. },
  2756. fromArray: function ( array ) {
  2757. this.elements.set( array );
  2758. return this;
  2759. },
  2760. toArray: function () {
  2761. var te = this.elements;
  2762. return [
  2763. te[ 0 ], te[ 1 ], te[ 2 ],
  2764. te[ 3 ], te[ 4 ], te[ 5 ],
  2765. te[ 6 ], te[ 7 ], te[ 8 ]
  2766. ];
  2767. }
  2768. };
  2769. // File:src/math/Matrix4.js
  2770. /**
  2771. * @author mrdoob / http://mrdoob.com/
  2772. * @author supereggbert / http://www.paulbrunt.co.uk/
  2773. * @author philogb / http://blog.thejit.org/
  2774. * @author jordi_ros / http://plattsoft.com
  2775. * @author D1plo1d / http://github.com/D1plo1d
  2776. * @author alteredq / http://alteredqualia.com/
  2777. * @author mikael emtinger / http://gomo.se/
  2778. * @author timknip / http://www.floorplanner.com/
  2779. * @author bhouston / http://clara.io
  2780. * @author WestLangley / http://github.com/WestLangley
  2781. */
  2782. THREE.Matrix4 = function () {
  2783. this.elements = new Float32Array( [
  2784. 1, 0, 0, 0,
  2785. 0, 1, 0, 0,
  2786. 0, 0, 1, 0,
  2787. 0, 0, 0, 1
  2788. ] );
  2789. if ( arguments.length > 0 ) {
  2790. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2791. }
  2792. };
  2793. THREE.Matrix4.prototype = {
  2794. constructor: THREE.Matrix4,
  2795. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2796. var te = this.elements;
  2797. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2798. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2799. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2800. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2801. return this;
  2802. },
  2803. identity: function () {
  2804. this.set(
  2805. 1, 0, 0, 0,
  2806. 0, 1, 0, 0,
  2807. 0, 0, 1, 0,
  2808. 0, 0, 0, 1
  2809. );
  2810. return this;
  2811. },
  2812. clone: function () {
  2813. return new THREE.Matrix4().fromArray( this.elements );
  2814. },
  2815. copy: function ( m ) {
  2816. this.elements.set( m.elements );
  2817. return this;
  2818. },
  2819. extractPosition: function ( m ) {
  2820. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2821. return this.copyPosition( m );
  2822. },
  2823. copyPosition: function ( m ) {
  2824. var te = this.elements;
  2825. var me = m.elements;
  2826. te[ 12 ] = me[ 12 ];
  2827. te[ 13 ] = me[ 13 ];
  2828. te[ 14 ] = me[ 14 ];
  2829. return this;
  2830. },
  2831. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2832. var te = this.elements;
  2833. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2834. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2835. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2836. return this;
  2837. },
  2838. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2839. this.set(
  2840. xAxis.x, yAxis.x, zAxis.x, 0,
  2841. xAxis.y, yAxis.y, zAxis.y, 0,
  2842. xAxis.z, yAxis.z, zAxis.z, 0,
  2843. 0, 0, 0, 1
  2844. );
  2845. return this;
  2846. },
  2847. extractRotation: function () {
  2848. var v1;
  2849. return function ( m ) {
  2850. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2851. var te = this.elements;
  2852. var me = m.elements;
  2853. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2854. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2855. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2856. te[ 0 ] = me[ 0 ] * scaleX;
  2857. te[ 1 ] = me[ 1 ] * scaleX;
  2858. te[ 2 ] = me[ 2 ] * scaleX;
  2859. te[ 4 ] = me[ 4 ] * scaleY;
  2860. te[ 5 ] = me[ 5 ] * scaleY;
  2861. te[ 6 ] = me[ 6 ] * scaleY;
  2862. te[ 8 ] = me[ 8 ] * scaleZ;
  2863. te[ 9 ] = me[ 9 ] * scaleZ;
  2864. te[ 10 ] = me[ 10 ] * scaleZ;
  2865. return this;
  2866. };
  2867. }(),
  2868. makeRotationFromEuler: function ( euler ) {
  2869. if ( euler instanceof THREE.Euler === false ) {
  2870. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2871. }
  2872. var te = this.elements;
  2873. var x = euler.x, y = euler.y, z = euler.z;
  2874. var a = Math.cos( x ), b = Math.sin( x );
  2875. var c = Math.cos( y ), d = Math.sin( y );
  2876. var e = Math.cos( z ), f = Math.sin( z );
  2877. if ( euler.order === 'XYZ' ) {
  2878. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2879. te[ 0 ] = c * e;
  2880. te[ 4 ] = - c * f;
  2881. te[ 8 ] = d;
  2882. te[ 1 ] = af + be * d;
  2883. te[ 5 ] = ae - bf * d;
  2884. te[ 9 ] = - b * c;
  2885. te[ 2 ] = bf - ae * d;
  2886. te[ 6 ] = be + af * d;
  2887. te[ 10 ] = a * c;
  2888. } else if ( euler.order === 'YXZ' ) {
  2889. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2890. te[ 0 ] = ce + df * b;
  2891. te[ 4 ] = de * b - cf;
  2892. te[ 8 ] = a * d;
  2893. te[ 1 ] = a * f;
  2894. te[ 5 ] = a * e;
  2895. te[ 9 ] = - b;
  2896. te[ 2 ] = cf * b - de;
  2897. te[ 6 ] = df + ce * b;
  2898. te[ 10 ] = a * c;
  2899. } else if ( euler.order === 'ZXY' ) {
  2900. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2901. te[ 0 ] = ce - df * b;
  2902. te[ 4 ] = - a * f;
  2903. te[ 8 ] = de + cf * b;
  2904. te[ 1 ] = cf + de * b;
  2905. te[ 5 ] = a * e;
  2906. te[ 9 ] = df - ce * b;
  2907. te[ 2 ] = - a * d;
  2908. te[ 6 ] = b;
  2909. te[ 10 ] = a * c;
  2910. } else if ( euler.order === 'ZYX' ) {
  2911. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2912. te[ 0 ] = c * e;
  2913. te[ 4 ] = be * d - af;
  2914. te[ 8 ] = ae * d + bf;
  2915. te[ 1 ] = c * f;
  2916. te[ 5 ] = bf * d + ae;
  2917. te[ 9 ] = af * d - be;
  2918. te[ 2 ] = - d;
  2919. te[ 6 ] = b * c;
  2920. te[ 10 ] = a * c;
  2921. } else if ( euler.order === 'YZX' ) {
  2922. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2923. te[ 0 ] = c * e;
  2924. te[ 4 ] = bd - ac * f;
  2925. te[ 8 ] = bc * f + ad;
  2926. te[ 1 ] = f;
  2927. te[ 5 ] = a * e;
  2928. te[ 9 ] = - b * e;
  2929. te[ 2 ] = - d * e;
  2930. te[ 6 ] = ad * f + bc;
  2931. te[ 10 ] = ac - bd * f;
  2932. } else if ( euler.order === 'XZY' ) {
  2933. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2934. te[ 0 ] = c * e;
  2935. te[ 4 ] = - f;
  2936. te[ 8 ] = d * e;
  2937. te[ 1 ] = ac * f + bd;
  2938. te[ 5 ] = a * e;
  2939. te[ 9 ] = ad * f - bc;
  2940. te[ 2 ] = bc * f - ad;
  2941. te[ 6 ] = b * e;
  2942. te[ 10 ] = bd * f + ac;
  2943. }
  2944. // last column
  2945. te[ 3 ] = 0;
  2946. te[ 7 ] = 0;
  2947. te[ 11 ] = 0;
  2948. // bottom row
  2949. te[ 12 ] = 0;
  2950. te[ 13 ] = 0;
  2951. te[ 14 ] = 0;
  2952. te[ 15 ] = 1;
  2953. return this;
  2954. },
  2955. setRotationFromQuaternion: function ( q ) {
  2956. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2957. return this.makeRotationFromQuaternion( q );
  2958. },
  2959. makeRotationFromQuaternion: function ( q ) {
  2960. var te = this.elements;
  2961. var x = q.x, y = q.y, z = q.z, w = q.w;
  2962. var x2 = x + x, y2 = y + y, z2 = z + z;
  2963. var xx = x * x2, xy = x * y2, xz = x * z2;
  2964. var yy = y * y2, yz = y * z2, zz = z * z2;
  2965. var wx = w * x2, wy = w * y2, wz = w * z2;
  2966. te[ 0 ] = 1 - ( yy + zz );
  2967. te[ 4 ] = xy - wz;
  2968. te[ 8 ] = xz + wy;
  2969. te[ 1 ] = xy + wz;
  2970. te[ 5 ] = 1 - ( xx + zz );
  2971. te[ 9 ] = yz - wx;
  2972. te[ 2 ] = xz - wy;
  2973. te[ 6 ] = yz + wx;
  2974. te[ 10 ] = 1 - ( xx + yy );
  2975. // last column
  2976. te[ 3 ] = 0;
  2977. te[ 7 ] = 0;
  2978. te[ 11 ] = 0;
  2979. // bottom row
  2980. te[ 12 ] = 0;
  2981. te[ 13 ] = 0;
  2982. te[ 14 ] = 0;
  2983. te[ 15 ] = 1;
  2984. return this;
  2985. },
  2986. lookAt: function () {
  2987. var x, y, z;
  2988. return function ( eye, target, up ) {
  2989. if ( x === undefined ) x = new THREE.Vector3();
  2990. if ( y === undefined ) y = new THREE.Vector3();
  2991. if ( z === undefined ) z = new THREE.Vector3();
  2992. var te = this.elements;
  2993. z.subVectors( eye, target ).normalize();
  2994. if ( z.length() === 0 ) {
  2995. z.z = 1;
  2996. }
  2997. x.crossVectors( up, z ).normalize();
  2998. if ( x.length() === 0 ) {
  2999. z.x += 0.0001;
  3000. x.crossVectors( up, z ).normalize();
  3001. }
  3002. y.crossVectors( z, x );
  3003. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3004. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3005. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3006. return this;
  3007. };
  3008. }(),
  3009. multiply: function ( m, n ) {
  3010. if ( n !== undefined ) {
  3011. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3012. return this.multiplyMatrices( m, n );
  3013. }
  3014. return this.multiplyMatrices( this, m );
  3015. },
  3016. multiplyMatrices: function ( a, b ) {
  3017. var ae = a.elements;
  3018. var be = b.elements;
  3019. var te = this.elements;
  3020. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3021. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3022. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3023. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3024. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3025. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3026. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3027. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3028. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3029. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3030. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3031. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3032. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3033. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3034. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3035. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3036. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3037. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3038. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3039. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3040. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3041. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3042. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3043. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3044. return this;
  3045. },
  3046. multiplyToArray: function ( a, b, r ) {
  3047. var te = this.elements;
  3048. this.multiplyMatrices( a, b );
  3049. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3050. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3051. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3052. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3053. return this;
  3054. },
  3055. multiplyScalar: function ( s ) {
  3056. var te = this.elements;
  3057. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3058. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3059. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3060. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3061. return this;
  3062. },
  3063. multiplyVector3: function ( vector ) {
  3064. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  3065. return vector.applyProjection( this );
  3066. },
  3067. multiplyVector4: function ( vector ) {
  3068. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3069. return vector.applyMatrix4( this );
  3070. },
  3071. multiplyVector3Array: function ( a ) {
  3072. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  3073. return this.applyToVector3Array( a );
  3074. },
  3075. applyToVector3Array: function () {
  3076. var v1;
  3077. return function ( array, offset, length ) {
  3078. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3079. if ( offset === undefined ) offset = 0;
  3080. if ( length === undefined ) length = array.length;
  3081. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3082. v1.fromArray( array, j );
  3083. v1.applyMatrix4( this );
  3084. v1.toArray( array, j );
  3085. }
  3086. return array;
  3087. };
  3088. }(),
  3089. applyToBuffer: function () {
  3090. var v1;
  3091. return function applyToBuffer( buffer, offset, length ) {
  3092. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3093. if ( offset === undefined ) offset = 0;
  3094. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3095. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3096. v1.x = buffer.getX( j );
  3097. v1.y = buffer.getY( j );
  3098. v1.z = buffer.getZ( j );
  3099. v1.applyMatrix4( this );
  3100. buffer.setXYZ( v1.x, v1.y, v1.z );
  3101. }
  3102. return buffer;
  3103. };
  3104. }(),
  3105. rotateAxis: function ( v ) {
  3106. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3107. v.transformDirection( this );
  3108. },
  3109. crossVector: function ( vector ) {
  3110. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3111. return vector.applyMatrix4( this );
  3112. },
  3113. determinant: function () {
  3114. var te = this.elements;
  3115. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3116. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3117. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3118. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3119. //TODO: make this more efficient
  3120. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3121. return (
  3122. n41 * (
  3123. + n14 * n23 * n32
  3124. - n13 * n24 * n32
  3125. - n14 * n22 * n33
  3126. + n12 * n24 * n33
  3127. + n13 * n22 * n34
  3128. - n12 * n23 * n34
  3129. ) +
  3130. n42 * (
  3131. + n11 * n23 * n34
  3132. - n11 * n24 * n33
  3133. + n14 * n21 * n33
  3134. - n13 * n21 * n34
  3135. + n13 * n24 * n31
  3136. - n14 * n23 * n31
  3137. ) +
  3138. n43 * (
  3139. + n11 * n24 * n32
  3140. - n11 * n22 * n34
  3141. - n14 * n21 * n32
  3142. + n12 * n21 * n34
  3143. + n14 * n22 * n31
  3144. - n12 * n24 * n31
  3145. ) +
  3146. n44 * (
  3147. - n13 * n22 * n31
  3148. - n11 * n23 * n32
  3149. + n11 * n22 * n33
  3150. + n13 * n21 * n32
  3151. - n12 * n21 * n33
  3152. + n12 * n23 * n31
  3153. )
  3154. );
  3155. },
  3156. transpose: function () {
  3157. var te = this.elements;
  3158. var tmp;
  3159. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3160. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3161. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3162. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3163. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3164. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3165. return this;
  3166. },
  3167. flattenToArrayOffset: function ( array, offset ) {
  3168. var te = this.elements;
  3169. array[ offset ] = te[ 0 ];
  3170. array[ offset + 1 ] = te[ 1 ];
  3171. array[ offset + 2 ] = te[ 2 ];
  3172. array[ offset + 3 ] = te[ 3 ];
  3173. array[ offset + 4 ] = te[ 4 ];
  3174. array[ offset + 5 ] = te[ 5 ];
  3175. array[ offset + 6 ] = te[ 6 ];
  3176. array[ offset + 7 ] = te[ 7 ];
  3177. array[ offset + 8 ] = te[ 8 ];
  3178. array[ offset + 9 ] = te[ 9 ];
  3179. array[ offset + 10 ] = te[ 10 ];
  3180. array[ offset + 11 ] = te[ 11 ];
  3181. array[ offset + 12 ] = te[ 12 ];
  3182. array[ offset + 13 ] = te[ 13 ];
  3183. array[ offset + 14 ] = te[ 14 ];
  3184. array[ offset + 15 ] = te[ 15 ];
  3185. return array;
  3186. },
  3187. getPosition: function () {
  3188. var v1;
  3189. return function () {
  3190. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3191. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3192. var te = this.elements;
  3193. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3194. };
  3195. }(),
  3196. setPosition: function ( v ) {
  3197. var te = this.elements;
  3198. te[ 12 ] = v.x;
  3199. te[ 13 ] = v.y;
  3200. te[ 14 ] = v.z;
  3201. return this;
  3202. },
  3203. getInverse: function ( m, throwOnInvertible ) {
  3204. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3205. var te = this.elements;
  3206. var me = m.elements;
  3207. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3208. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3209. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3210. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3211. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3212. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3213. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3214. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3215. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3216. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3217. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3218. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3219. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3220. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3221. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3222. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3223. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3224. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3225. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3226. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3227. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3228. if ( det === 0 ) {
  3229. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3230. if ( throwOnInvertible || false ) {
  3231. throw new Error( msg );
  3232. } else {
  3233. console.warn( msg );
  3234. }
  3235. this.identity();
  3236. return this;
  3237. }
  3238. this.multiplyScalar( 1 / det );
  3239. return this;
  3240. },
  3241. translate: function ( v ) {
  3242. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3243. },
  3244. rotateX: function ( angle ) {
  3245. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3246. },
  3247. rotateY: function ( angle ) {
  3248. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3249. },
  3250. rotateZ: function ( angle ) {
  3251. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3252. },
  3253. rotateByAxis: function ( axis, angle ) {
  3254. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3255. },
  3256. scale: function ( v ) {
  3257. var te = this.elements;
  3258. var x = v.x, y = v.y, z = v.z;
  3259. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3260. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3261. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3262. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3263. return this;
  3264. },
  3265. getMaxScaleOnAxis: function () {
  3266. var te = this.elements;
  3267. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3268. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3269. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3270. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3271. },
  3272. makeTranslation: function ( x, y, z ) {
  3273. this.set(
  3274. 1, 0, 0, x,
  3275. 0, 1, 0, y,
  3276. 0, 0, 1, z,
  3277. 0, 0, 0, 1
  3278. );
  3279. return this;
  3280. },
  3281. makeRotationX: function ( theta ) {
  3282. var c = Math.cos( theta ), s = Math.sin( theta );
  3283. this.set(
  3284. 1, 0, 0, 0,
  3285. 0, c, - s, 0,
  3286. 0, s, c, 0,
  3287. 0, 0, 0, 1
  3288. );
  3289. return this;
  3290. },
  3291. makeRotationY: function ( theta ) {
  3292. var c = Math.cos( theta ), s = Math.sin( theta );
  3293. this.set(
  3294. c, 0, s, 0,
  3295. 0, 1, 0, 0,
  3296. - s, 0, c, 0,
  3297. 0, 0, 0, 1
  3298. );
  3299. return this;
  3300. },
  3301. makeRotationZ: function ( theta ) {
  3302. var c = Math.cos( theta ), s = Math.sin( theta );
  3303. this.set(
  3304. c, - s, 0, 0,
  3305. s, c, 0, 0,
  3306. 0, 0, 1, 0,
  3307. 0, 0, 0, 1
  3308. );
  3309. return this;
  3310. },
  3311. makeRotationAxis: function ( axis, angle ) {
  3312. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3313. var c = Math.cos( angle );
  3314. var s = Math.sin( angle );
  3315. var t = 1 - c;
  3316. var x = axis.x, y = axis.y, z = axis.z;
  3317. var tx = t * x, ty = t * y;
  3318. this.set(
  3319. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3320. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3321. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3322. 0, 0, 0, 1
  3323. );
  3324. return this;
  3325. },
  3326. makeScale: function ( x, y, z ) {
  3327. this.set(
  3328. x, 0, 0, 0,
  3329. 0, y, 0, 0,
  3330. 0, 0, z, 0,
  3331. 0, 0, 0, 1
  3332. );
  3333. return this;
  3334. },
  3335. compose: function ( position, quaternion, scale ) {
  3336. this.makeRotationFromQuaternion( quaternion );
  3337. this.scale( scale );
  3338. this.setPosition( position );
  3339. return this;
  3340. },
  3341. decompose: function () {
  3342. var vector, matrix;
  3343. return function ( position, quaternion, scale ) {
  3344. if ( vector === undefined ) vector = new THREE.Vector3();
  3345. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3346. var te = this.elements;
  3347. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3348. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3349. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3350. // if determine is negative, we need to invert one scale
  3351. var det = this.determinant();
  3352. if ( det < 0 ) {
  3353. sx = - sx;
  3354. }
  3355. position.x = te[ 12 ];
  3356. position.y = te[ 13 ];
  3357. position.z = te[ 14 ];
  3358. // scale the rotation part
  3359. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3360. var invSX = 1 / sx;
  3361. var invSY = 1 / sy;
  3362. var invSZ = 1 / sz;
  3363. matrix.elements[ 0 ] *= invSX;
  3364. matrix.elements[ 1 ] *= invSX;
  3365. matrix.elements[ 2 ] *= invSX;
  3366. matrix.elements[ 4 ] *= invSY;
  3367. matrix.elements[ 5 ] *= invSY;
  3368. matrix.elements[ 6 ] *= invSY;
  3369. matrix.elements[ 8 ] *= invSZ;
  3370. matrix.elements[ 9 ] *= invSZ;
  3371. matrix.elements[ 10 ] *= invSZ;
  3372. quaternion.setFromRotationMatrix( matrix );
  3373. scale.x = sx;
  3374. scale.y = sy;
  3375. scale.z = sz;
  3376. return this;
  3377. };
  3378. }(),
  3379. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3380. var te = this.elements;
  3381. var x = 2 * near / ( right - left );
  3382. var y = 2 * near / ( top - bottom );
  3383. var a = ( right + left ) / ( right - left );
  3384. var b = ( top + bottom ) / ( top - bottom );
  3385. var c = - ( far + near ) / ( far - near );
  3386. var d = - 2 * far * near / ( far - near );
  3387. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3388. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3389. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3390. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3391. return this;
  3392. },
  3393. makePerspective: function ( fov, aspect, near, far ) {
  3394. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3395. var ymin = - ymax;
  3396. var xmin = ymin * aspect;
  3397. var xmax = ymax * aspect;
  3398. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3399. },
  3400. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3401. var te = this.elements;
  3402. var w = right - left;
  3403. var h = top - bottom;
  3404. var p = far - near;
  3405. var x = ( right + left ) / w;
  3406. var y = ( top + bottom ) / h;
  3407. var z = ( far + near ) / p;
  3408. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3409. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3410. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3411. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3412. return this;
  3413. },
  3414. equals: function ( matrix ) {
  3415. var te = this.elements;
  3416. var me = matrix.elements;
  3417. for ( var i = 0; i < 16; i ++ ) {
  3418. if ( te[ i ] !== me[ i ] ) return false;
  3419. }
  3420. return true;
  3421. },
  3422. fromArray: function ( array ) {
  3423. this.elements.set( array );
  3424. return this;
  3425. },
  3426. toArray: function () {
  3427. var te = this.elements;
  3428. return [
  3429. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3430. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3431. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3432. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3433. ];
  3434. }
  3435. };
  3436. // File:src/math/Ray.js
  3437. /**
  3438. * @author bhouston / http://clara.io
  3439. */
  3440. THREE.Ray = function ( origin, direction ) {
  3441. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3442. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3443. };
  3444. THREE.Ray.prototype = {
  3445. constructor: THREE.Ray,
  3446. set: function ( origin, direction ) {
  3447. this.origin.copy( origin );
  3448. this.direction.copy( direction );
  3449. return this;
  3450. },
  3451. clone: function () {
  3452. return new this.constructor().copy( this );
  3453. },
  3454. copy: function ( ray ) {
  3455. this.origin.copy( ray.origin );
  3456. this.direction.copy( ray.direction );
  3457. return this;
  3458. },
  3459. at: function ( t, optionalTarget ) {
  3460. var result = optionalTarget || new THREE.Vector3();
  3461. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3462. },
  3463. recast: function () {
  3464. var v1 = new THREE.Vector3();
  3465. return function ( t ) {
  3466. this.origin.copy( this.at( t, v1 ) );
  3467. return this;
  3468. };
  3469. }(),
  3470. closestPointToPoint: function ( point, optionalTarget ) {
  3471. var result = optionalTarget || new THREE.Vector3();
  3472. result.subVectors( point, this.origin );
  3473. var directionDistance = result.dot( this.direction );
  3474. if ( directionDistance < 0 ) {
  3475. return result.copy( this.origin );
  3476. }
  3477. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3478. },
  3479. distanceToPoint: function ( point ) {
  3480. return Math.sqrt( this.distanceSqToPoint( point ) );
  3481. },
  3482. distanceSqToPoint: function () {
  3483. var v1 = new THREE.Vector3();
  3484. return function ( point ) {
  3485. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3486. // point behind the ray
  3487. if ( directionDistance < 0 ) {
  3488. return this.origin.distanceToSquared( point );
  3489. }
  3490. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3491. return v1.distanceToSquared( point );
  3492. };
  3493. }(),
  3494. distanceSqToSegment: function () {
  3495. var segCenter = new THREE.Vector3();
  3496. var segDir = new THREE.Vector3();
  3497. var diff = new THREE.Vector3();
  3498. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3499. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3500. // It returns the min distance between the ray and the segment
  3501. // defined by v0 and v1
  3502. // It can also set two optional targets :
  3503. // - The closest point on the ray
  3504. // - The closest point on the segment
  3505. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3506. segDir.copy( v1 ).sub( v0 ).normalize();
  3507. diff.copy( this.origin ).sub( segCenter );
  3508. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3509. var a01 = - this.direction.dot( segDir );
  3510. var b0 = diff.dot( this.direction );
  3511. var b1 = - diff.dot( segDir );
  3512. var c = diff.lengthSq();
  3513. var det = Math.abs( 1 - a01 * a01 );
  3514. var s0, s1, sqrDist, extDet;
  3515. if ( det > 0 ) {
  3516. // The ray and segment are not parallel.
  3517. s0 = a01 * b1 - b0;
  3518. s1 = a01 * b0 - b1;
  3519. extDet = segExtent * det;
  3520. if ( s0 >= 0 ) {
  3521. if ( s1 >= - extDet ) {
  3522. if ( s1 <= extDet ) {
  3523. // region 0
  3524. // Minimum at interior points of ray and segment.
  3525. var invDet = 1 / det;
  3526. s0 *= invDet;
  3527. s1 *= invDet;
  3528. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3529. } else {
  3530. // region 1
  3531. s1 = segExtent;
  3532. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3533. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3534. }
  3535. } else {
  3536. // region 5
  3537. s1 = - segExtent;
  3538. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3539. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3540. }
  3541. } else {
  3542. if ( s1 <= - extDet ) {
  3543. // region 4
  3544. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3545. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3546. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3547. } else if ( s1 <= extDet ) {
  3548. // region 3
  3549. s0 = 0;
  3550. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3551. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3552. } else {
  3553. // region 2
  3554. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3555. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3556. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3557. }
  3558. }
  3559. } else {
  3560. // Ray and segment are parallel.
  3561. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3562. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3563. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3564. }
  3565. if ( optionalPointOnRay ) {
  3566. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3567. }
  3568. if ( optionalPointOnSegment ) {
  3569. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3570. }
  3571. return sqrDist;
  3572. };
  3573. }(),
  3574. isIntersectionSphere: function ( sphere ) {
  3575. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3576. },
  3577. intersectSphere: function () {
  3578. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3579. var v1 = new THREE.Vector3();
  3580. return function ( sphere, optionalTarget ) {
  3581. v1.subVectors( sphere.center, this.origin );
  3582. var tca = v1.dot( this.direction );
  3583. var d2 = v1.dot( v1 ) - tca * tca;
  3584. var radius2 = sphere.radius * sphere.radius;
  3585. if ( d2 > radius2 ) return null;
  3586. var thc = Math.sqrt( radius2 - d2 );
  3587. // t0 = first intersect point - entrance on front of sphere
  3588. var t0 = tca - thc;
  3589. // t1 = second intersect point - exit point on back of sphere
  3590. var t1 = tca + thc;
  3591. // test to see if both t0 and t1 are behind the ray - if so, return null
  3592. if ( t0 < 0 && t1 < 0 ) return null;
  3593. // test to see if t0 is behind the ray:
  3594. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3595. // in order to always return an intersect point that is in front of the ray.
  3596. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3597. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3598. return this.at( t0, optionalTarget );
  3599. }
  3600. }(),
  3601. isIntersectionPlane: function ( plane ) {
  3602. // check if the ray lies on the plane first
  3603. var distToPoint = plane.distanceToPoint( this.origin );
  3604. if ( distToPoint === 0 ) {
  3605. return true;
  3606. }
  3607. var denominator = plane.normal.dot( this.direction );
  3608. if ( denominator * distToPoint < 0 ) {
  3609. return true;
  3610. }
  3611. // ray origin is behind the plane (and is pointing behind it)
  3612. return false;
  3613. },
  3614. distanceToPlane: function ( plane ) {
  3615. var denominator = plane.normal.dot( this.direction );
  3616. if ( denominator === 0 ) {
  3617. // line is coplanar, return origin
  3618. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3619. return 0;
  3620. }
  3621. // Null is preferable to undefined since undefined means.... it is undefined
  3622. return null;
  3623. }
  3624. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3625. // Return if the ray never intersects the plane
  3626. return t >= 0 ? t : null;
  3627. },
  3628. intersectPlane: function ( plane, optionalTarget ) {
  3629. var t = this.distanceToPlane( plane );
  3630. if ( t === null ) {
  3631. return null;
  3632. }
  3633. return this.at( t, optionalTarget );
  3634. },
  3635. isIntersectionBox: function () {
  3636. var v = new THREE.Vector3();
  3637. return function ( box ) {
  3638. return this.intersectBox( box, v ) !== null;
  3639. };
  3640. }(),
  3641. intersectBox: function ( box, optionalTarget ) {
  3642. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3643. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3644. var invdirx = 1 / this.direction.x,
  3645. invdiry = 1 / this.direction.y,
  3646. invdirz = 1 / this.direction.z;
  3647. var origin = this.origin;
  3648. if ( invdirx >= 0 ) {
  3649. tmin = ( box.min.x - origin.x ) * invdirx;
  3650. tmax = ( box.max.x - origin.x ) * invdirx;
  3651. } else {
  3652. tmin = ( box.max.x - origin.x ) * invdirx;
  3653. tmax = ( box.min.x - origin.x ) * invdirx;
  3654. }
  3655. if ( invdiry >= 0 ) {
  3656. tymin = ( box.min.y - origin.y ) * invdiry;
  3657. tymax = ( box.max.y - origin.y ) * invdiry;
  3658. } else {
  3659. tymin = ( box.max.y - origin.y ) * invdiry;
  3660. tymax = ( box.min.y - origin.y ) * invdiry;
  3661. }
  3662. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3663. // These lines also handle the case where tmin or tmax is NaN
  3664. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3665. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3666. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3667. if ( invdirz >= 0 ) {
  3668. tzmin = ( box.min.z - origin.z ) * invdirz;
  3669. tzmax = ( box.max.z - origin.z ) * invdirz;
  3670. } else {
  3671. tzmin = ( box.max.z - origin.z ) * invdirz;
  3672. tzmax = ( box.min.z - origin.z ) * invdirz;
  3673. }
  3674. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3675. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3676. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3677. //return point closest to the ray (positive side)
  3678. if ( tmax < 0 ) return null;
  3679. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3680. },
  3681. intersectTriangle: function () {
  3682. // Compute the offset origin, edges, and normal.
  3683. var diff = new THREE.Vector3();
  3684. var edge1 = new THREE.Vector3();
  3685. var edge2 = new THREE.Vector3();
  3686. var normal = new THREE.Vector3();
  3687. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3688. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3689. edge1.subVectors( b, a );
  3690. edge2.subVectors( c, a );
  3691. normal.crossVectors( edge1, edge2 );
  3692. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3693. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3694. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3695. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3696. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3697. var DdN = this.direction.dot( normal );
  3698. var sign;
  3699. if ( DdN > 0 ) {
  3700. if ( backfaceCulling ) return null;
  3701. sign = 1;
  3702. } else if ( DdN < 0 ) {
  3703. sign = - 1;
  3704. DdN = - DdN;
  3705. } else {
  3706. return null;
  3707. }
  3708. diff.subVectors( this.origin, a );
  3709. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3710. // b1 < 0, no intersection
  3711. if ( DdQxE2 < 0 ) {
  3712. return null;
  3713. }
  3714. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3715. // b2 < 0, no intersection
  3716. if ( DdE1xQ < 0 ) {
  3717. return null;
  3718. }
  3719. // b1+b2 > 1, no intersection
  3720. if ( DdQxE2 + DdE1xQ > DdN ) {
  3721. return null;
  3722. }
  3723. // Line intersects triangle, check if ray does.
  3724. var QdN = - sign * diff.dot( normal );
  3725. // t < 0, no intersection
  3726. if ( QdN < 0 ) {
  3727. return null;
  3728. }
  3729. // Ray intersects triangle.
  3730. return this.at( QdN / DdN, optionalTarget );
  3731. };
  3732. }(),
  3733. applyMatrix4: function ( matrix4 ) {
  3734. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3735. this.origin.applyMatrix4( matrix4 );
  3736. this.direction.sub( this.origin );
  3737. this.direction.normalize();
  3738. return this;
  3739. },
  3740. equals: function ( ray ) {
  3741. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3742. }
  3743. };
  3744. // File:src/math/Sphere.js
  3745. /**
  3746. * @author bhouston / http://clara.io
  3747. * @author mrdoob / http://mrdoob.com/
  3748. */
  3749. THREE.Sphere = function ( center, radius ) {
  3750. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3751. this.radius = ( radius !== undefined ) ? radius : 0;
  3752. };
  3753. THREE.Sphere.prototype = {
  3754. constructor: THREE.Sphere,
  3755. set: function ( center, radius ) {
  3756. this.center.copy( center );
  3757. this.radius = radius;
  3758. return this;
  3759. },
  3760. setFromPoints: function () {
  3761. var box = new THREE.Box3();
  3762. return function ( points, optionalCenter ) {
  3763. var center = this.center;
  3764. if ( optionalCenter !== undefined ) {
  3765. center.copy( optionalCenter );
  3766. } else {
  3767. box.setFromPoints( points ).center( center );
  3768. }
  3769. var maxRadiusSq = 0;
  3770. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3771. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3772. }
  3773. this.radius = Math.sqrt( maxRadiusSq );
  3774. return this;
  3775. };
  3776. }(),
  3777. clone: function () {
  3778. return new this.constructor().copy( this );
  3779. },
  3780. copy: function ( sphere ) {
  3781. this.center.copy( sphere.center );
  3782. this.radius = sphere.radius;
  3783. return this;
  3784. },
  3785. empty: function () {
  3786. return ( this.radius <= 0 );
  3787. },
  3788. containsPoint: function ( point ) {
  3789. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3790. },
  3791. distanceToPoint: function ( point ) {
  3792. return ( point.distanceTo( this.center ) - this.radius );
  3793. },
  3794. intersectsSphere: function ( sphere ) {
  3795. var radiusSum = this.radius + sphere.radius;
  3796. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3797. },
  3798. clampPoint: function ( point, optionalTarget ) {
  3799. var deltaLengthSq = this.center.distanceToSquared( point );
  3800. var result = optionalTarget || new THREE.Vector3();
  3801. result.copy( point );
  3802. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3803. result.sub( this.center ).normalize();
  3804. result.multiplyScalar( this.radius ).add( this.center );
  3805. }
  3806. return result;
  3807. },
  3808. getBoundingBox: function ( optionalTarget ) {
  3809. var box = optionalTarget || new THREE.Box3();
  3810. box.set( this.center, this.center );
  3811. box.expandByScalar( this.radius );
  3812. return box;
  3813. },
  3814. applyMatrix4: function ( matrix ) {
  3815. this.center.applyMatrix4( matrix );
  3816. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3817. return this;
  3818. },
  3819. translate: function ( offset ) {
  3820. this.center.add( offset );
  3821. return this;
  3822. },
  3823. equals: function ( sphere ) {
  3824. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3825. }
  3826. };
  3827. // File:src/math/Frustum.js
  3828. /**
  3829. * @author mrdoob / http://mrdoob.com/
  3830. * @author alteredq / http://alteredqualia.com/
  3831. * @author bhouston / http://clara.io
  3832. */
  3833. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3834. this.planes = [
  3835. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3836. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3837. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3838. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3839. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3840. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3841. ];
  3842. };
  3843. THREE.Frustum.prototype = {
  3844. constructor: THREE.Frustum,
  3845. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3846. var planes = this.planes;
  3847. planes[ 0 ].copy( p0 );
  3848. planes[ 1 ].copy( p1 );
  3849. planes[ 2 ].copy( p2 );
  3850. planes[ 3 ].copy( p3 );
  3851. planes[ 4 ].copy( p4 );
  3852. planes[ 5 ].copy( p5 );
  3853. return this;
  3854. },
  3855. clone: function () {
  3856. return new this.constructor().copy( this );
  3857. },
  3858. copy: function ( frustum ) {
  3859. var planes = this.planes;
  3860. for ( var i = 0; i < 6; i ++ ) {
  3861. planes[ i ].copy( frustum.planes[ i ] );
  3862. }
  3863. return this;
  3864. },
  3865. setFromMatrix: function ( m ) {
  3866. var planes = this.planes;
  3867. var me = m.elements;
  3868. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3869. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3870. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3871. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3872. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3873. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3874. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3875. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3876. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3877. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3878. return this;
  3879. },
  3880. intersectsObject: function () {
  3881. var sphere = new THREE.Sphere();
  3882. return function ( object ) {
  3883. var geometry = object.geometry;
  3884. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3885. sphere.copy( geometry.boundingSphere );
  3886. sphere.applyMatrix4( object.matrixWorld );
  3887. return this.intersectsSphere( sphere );
  3888. };
  3889. }(),
  3890. intersectsSphere: function ( sphere ) {
  3891. var planes = this.planes;
  3892. var center = sphere.center;
  3893. var negRadius = - sphere.radius;
  3894. for ( var i = 0; i < 6; i ++ ) {
  3895. var distance = planes[ i ].distanceToPoint( center );
  3896. if ( distance < negRadius ) {
  3897. return false;
  3898. }
  3899. }
  3900. return true;
  3901. },
  3902. intersectsBox: function () {
  3903. var p1 = new THREE.Vector3(),
  3904. p2 = new THREE.Vector3();
  3905. return function ( box ) {
  3906. var planes = this.planes;
  3907. for ( var i = 0; i < 6 ; i ++ ) {
  3908. var plane = planes[ i ];
  3909. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3910. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3911. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3912. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3913. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3914. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3915. var d1 = plane.distanceToPoint( p1 );
  3916. var d2 = plane.distanceToPoint( p2 );
  3917. // if both outside plane, no intersection
  3918. if ( d1 < 0 && d2 < 0 ) {
  3919. return false;
  3920. }
  3921. }
  3922. return true;
  3923. };
  3924. }(),
  3925. containsPoint: function ( point ) {
  3926. var planes = this.planes;
  3927. for ( var i = 0; i < 6; i ++ ) {
  3928. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3929. return false;
  3930. }
  3931. }
  3932. return true;
  3933. }
  3934. };
  3935. // File:src/math/Plane.js
  3936. /**
  3937. * @author bhouston / http://clara.io
  3938. */
  3939. THREE.Plane = function ( normal, constant ) {
  3940. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3941. this.constant = ( constant !== undefined ) ? constant : 0;
  3942. };
  3943. THREE.Plane.prototype = {
  3944. constructor: THREE.Plane,
  3945. set: function ( normal, constant ) {
  3946. this.normal.copy( normal );
  3947. this.constant = constant;
  3948. return this;
  3949. },
  3950. setComponents: function ( x, y, z, w ) {
  3951. this.normal.set( x, y, z );
  3952. this.constant = w;
  3953. return this;
  3954. },
  3955. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3956. this.normal.copy( normal );
  3957. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3958. return this;
  3959. },
  3960. setFromCoplanarPoints: function () {
  3961. var v1 = new THREE.Vector3();
  3962. var v2 = new THREE.Vector3();
  3963. return function ( a, b, c ) {
  3964. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3965. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3966. this.setFromNormalAndCoplanarPoint( normal, a );
  3967. return this;
  3968. };
  3969. }(),
  3970. clone: function () {
  3971. return new this.constructor().copy( this );
  3972. },
  3973. copy: function ( plane ) {
  3974. this.normal.copy( plane.normal );
  3975. this.constant = plane.constant;
  3976. return this;
  3977. },
  3978. normalize: function () {
  3979. // Note: will lead to a divide by zero if the plane is invalid.
  3980. var inverseNormalLength = 1.0 / this.normal.length();
  3981. this.normal.multiplyScalar( inverseNormalLength );
  3982. this.constant *= inverseNormalLength;
  3983. return this;
  3984. },
  3985. negate: function () {
  3986. this.constant *= - 1;
  3987. this.normal.negate();
  3988. return this;
  3989. },
  3990. distanceToPoint: function ( point ) {
  3991. return this.normal.dot( point ) + this.constant;
  3992. },
  3993. distanceToSphere: function ( sphere ) {
  3994. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3995. },
  3996. projectPoint: function ( point, optionalTarget ) {
  3997. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3998. },
  3999. orthoPoint: function ( point, optionalTarget ) {
  4000. var perpendicularMagnitude = this.distanceToPoint( point );
  4001. var result = optionalTarget || new THREE.Vector3();
  4002. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  4003. },
  4004. isIntersectionLine: function ( line ) {
  4005. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4006. var startSign = this.distanceToPoint( line.start );
  4007. var endSign = this.distanceToPoint( line.end );
  4008. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4009. },
  4010. intersectLine: function () {
  4011. var v1 = new THREE.Vector3();
  4012. return function ( line, optionalTarget ) {
  4013. var result = optionalTarget || new THREE.Vector3();
  4014. var direction = line.delta( v1 );
  4015. var denominator = this.normal.dot( direction );
  4016. if ( denominator === 0 ) {
  4017. // line is coplanar, return origin
  4018. if ( this.distanceToPoint( line.start ) === 0 ) {
  4019. return result.copy( line.start );
  4020. }
  4021. // Unsure if this is the correct method to handle this case.
  4022. return undefined;
  4023. }
  4024. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4025. if ( t < 0 || t > 1 ) {
  4026. return undefined;
  4027. }
  4028. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4029. };
  4030. }(),
  4031. coplanarPoint: function ( optionalTarget ) {
  4032. var result = optionalTarget || new THREE.Vector3();
  4033. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4034. },
  4035. applyMatrix4: function () {
  4036. var v1 = new THREE.Vector3();
  4037. var v2 = new THREE.Vector3();
  4038. var m1 = new THREE.Matrix3();
  4039. return function ( matrix, optionalNormalMatrix ) {
  4040. // compute new normal based on theory here:
  4041. // http://www.songho.ca/opengl/gl_normaltransform.html
  4042. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4043. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4044. var newCoplanarPoint = this.coplanarPoint( v2 );
  4045. newCoplanarPoint.applyMatrix4( matrix );
  4046. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4047. return this;
  4048. };
  4049. }(),
  4050. translate: function ( offset ) {
  4051. this.constant = this.constant - offset.dot( this.normal );
  4052. return this;
  4053. },
  4054. equals: function ( plane ) {
  4055. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4056. }
  4057. };
  4058. // File:src/math/Math.js
  4059. /**
  4060. * @author alteredq / http://alteredqualia.com/
  4061. * @author mrdoob / http://mrdoob.com/
  4062. */
  4063. THREE.Math = {
  4064. generateUUID: function () {
  4065. // http://www.broofa.com/Tools/Math.uuid.htm
  4066. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4067. var uuid = new Array( 36 );
  4068. var rnd = 0, r;
  4069. return function () {
  4070. for ( var i = 0; i < 36; i ++ ) {
  4071. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4072. uuid[ i ] = '-';
  4073. } else if ( i === 14 ) {
  4074. uuid[ i ] = '4';
  4075. } else {
  4076. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4077. r = rnd & 0xf;
  4078. rnd = rnd >> 4;
  4079. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4080. }
  4081. }
  4082. return uuid.join( '' );
  4083. };
  4084. }(),
  4085. // Clamp value to range <a, b>
  4086. clamp: function ( x, a, b ) {
  4087. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  4088. },
  4089. // Clamp value to range <a, inf)
  4090. clampBottom: function ( x, a ) {
  4091. return x < a ? a : x;
  4092. },
  4093. // compute euclidian modulo of m % n
  4094. // https://en.wikipedia.org/wiki/Modulo_operation
  4095. euclideanModulo: function ( n, m ) {
  4096. return ( ( n % m ) + m ) % m;
  4097. },
  4098. // Linear mapping from range <a1, a2> to range <b1, b2>
  4099. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4100. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4101. },
  4102. // http://en.wikipedia.org/wiki/Smoothstep
  4103. smoothstep: function ( x, min, max ) {
  4104. if ( x <= min ) return 0;
  4105. if ( x >= max ) return 1;
  4106. x = ( x - min ) / ( max - min );
  4107. return x * x * ( 3 - 2 * x );
  4108. },
  4109. smootherstep: function ( x, min, max ) {
  4110. if ( x <= min ) return 0;
  4111. if ( x >= max ) return 1;
  4112. x = ( x - min ) / ( max - min );
  4113. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4114. },
  4115. // Random float from <0, 1> with 16 bits of randomness
  4116. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4117. random16: function () {
  4118. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4119. },
  4120. // Random integer from <low, high> interval
  4121. randInt: function ( low, high ) {
  4122. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4123. },
  4124. // Random float from <low, high> interval
  4125. randFloat: function ( low, high ) {
  4126. return low + Math.random() * ( high - low );
  4127. },
  4128. // Random float from <-range/2, range/2> interval
  4129. randFloatSpread: function ( range ) {
  4130. return range * ( 0.5 - Math.random() );
  4131. },
  4132. degToRad: function () {
  4133. var degreeToRadiansFactor = Math.PI / 180;
  4134. return function ( degrees ) {
  4135. return degrees * degreeToRadiansFactor;
  4136. };
  4137. }(),
  4138. radToDeg: function () {
  4139. var radianToDegreesFactor = 180 / Math.PI;
  4140. return function ( radians ) {
  4141. return radians * radianToDegreesFactor;
  4142. };
  4143. }(),
  4144. isPowerOfTwo: function ( value ) {
  4145. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4146. },
  4147. nextPowerOfTwo: function ( value ) {
  4148. value --;
  4149. value |= value >> 1;
  4150. value |= value >> 2;
  4151. value |= value >> 4;
  4152. value |= value >> 8;
  4153. value |= value >> 16;
  4154. value ++;
  4155. return value;
  4156. }
  4157. };
  4158. // File:src/math/Spline.js
  4159. /**
  4160. * Spline from Tween.js, slightly optimized (and trashed)
  4161. * http://sole.github.com/tween.js/examples/05_spline.html
  4162. *
  4163. * @author mrdoob / http://mrdoob.com/
  4164. * @author alteredq / http://alteredqualia.com/
  4165. */
  4166. THREE.Spline = function ( points ) {
  4167. this.points = points;
  4168. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4169. point, intPoint, weight, w2, w3,
  4170. pa, pb, pc, pd;
  4171. this.initFromArray = function ( a ) {
  4172. this.points = [];
  4173. for ( var i = 0; i < a.length; i ++ ) {
  4174. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4175. }
  4176. };
  4177. this.getPoint = function ( k ) {
  4178. point = ( this.points.length - 1 ) * k;
  4179. intPoint = Math.floor( point );
  4180. weight = point - intPoint;
  4181. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4182. c[ 1 ] = intPoint;
  4183. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4184. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4185. pa = this.points[ c[ 0 ] ];
  4186. pb = this.points[ c[ 1 ] ];
  4187. pc = this.points[ c[ 2 ] ];
  4188. pd = this.points[ c[ 3 ] ];
  4189. w2 = weight * weight;
  4190. w3 = weight * w2;
  4191. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4192. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4193. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4194. return v3;
  4195. };
  4196. this.getControlPointsArray = function () {
  4197. var i, p, l = this.points.length,
  4198. coords = [];
  4199. for ( i = 0; i < l; i ++ ) {
  4200. p = this.points[ i ];
  4201. coords[ i ] = [ p.x, p.y, p.z ];
  4202. }
  4203. return coords;
  4204. };
  4205. // approximate length by summing linear segments
  4206. this.getLength = function ( nSubDivisions ) {
  4207. var i, index, nSamples, position,
  4208. point = 0, intPoint = 0, oldIntPoint = 0,
  4209. oldPosition = new THREE.Vector3(),
  4210. tmpVec = new THREE.Vector3(),
  4211. chunkLengths = [],
  4212. totalLength = 0;
  4213. // first point has 0 length
  4214. chunkLengths[ 0 ] = 0;
  4215. if ( ! nSubDivisions ) nSubDivisions = 100;
  4216. nSamples = this.points.length * nSubDivisions;
  4217. oldPosition.copy( this.points[ 0 ] );
  4218. for ( i = 1; i < nSamples; i ++ ) {
  4219. index = i / nSamples;
  4220. position = this.getPoint( index );
  4221. tmpVec.copy( position );
  4222. totalLength += tmpVec.distanceTo( oldPosition );
  4223. oldPosition.copy( position );
  4224. point = ( this.points.length - 1 ) * index;
  4225. intPoint = Math.floor( point );
  4226. if ( intPoint !== oldIntPoint ) {
  4227. chunkLengths[ intPoint ] = totalLength;
  4228. oldIntPoint = intPoint;
  4229. }
  4230. }
  4231. // last point ends with total length
  4232. chunkLengths[ chunkLengths.length ] = totalLength;
  4233. return { chunks: chunkLengths, total: totalLength };
  4234. };
  4235. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4236. var i, j,
  4237. index, indexCurrent, indexNext,
  4238. realDistance,
  4239. sampling, position,
  4240. newpoints = [],
  4241. tmpVec = new THREE.Vector3(),
  4242. sl = this.getLength();
  4243. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4244. for ( i = 1; i < this.points.length; i ++ ) {
  4245. //tmpVec.copy( this.points[ i - 1 ] );
  4246. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4247. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4248. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4249. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4250. indexNext = i / ( this.points.length - 1 );
  4251. for ( j = 1; j < sampling - 1; j ++ ) {
  4252. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4253. position = this.getPoint( index );
  4254. newpoints.push( tmpVec.copy( position ).clone() );
  4255. }
  4256. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4257. }
  4258. this.points = newpoints;
  4259. };
  4260. // Catmull-Rom
  4261. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4262. var v0 = ( p2 - p0 ) * 0.5,
  4263. v1 = ( p3 - p1 ) * 0.5;
  4264. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4265. }
  4266. };
  4267. // File:src/math/Triangle.js
  4268. /**
  4269. * @author bhouston / http://clara.io
  4270. * @author mrdoob / http://mrdoob.com/
  4271. */
  4272. THREE.Triangle = function ( a, b, c ) {
  4273. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4274. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4275. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4276. };
  4277. THREE.Triangle.normal = function () {
  4278. var v0 = new THREE.Vector3();
  4279. return function ( a, b, c, optionalTarget ) {
  4280. var result = optionalTarget || new THREE.Vector3();
  4281. result.subVectors( c, b );
  4282. v0.subVectors( a, b );
  4283. result.cross( v0 );
  4284. var resultLengthSq = result.lengthSq();
  4285. if ( resultLengthSq > 0 ) {
  4286. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4287. }
  4288. return result.set( 0, 0, 0 );
  4289. };
  4290. }();
  4291. // static/instance method to calculate barycentric coordinates
  4292. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4293. THREE.Triangle.barycoordFromPoint = function () {
  4294. var v0 = new THREE.Vector3();
  4295. var v1 = new THREE.Vector3();
  4296. var v2 = new THREE.Vector3();
  4297. return function ( point, a, b, c, optionalTarget ) {
  4298. v0.subVectors( c, a );
  4299. v1.subVectors( b, a );
  4300. v2.subVectors( point, a );
  4301. var dot00 = v0.dot( v0 );
  4302. var dot01 = v0.dot( v1 );
  4303. var dot02 = v0.dot( v2 );
  4304. var dot11 = v1.dot( v1 );
  4305. var dot12 = v1.dot( v2 );
  4306. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4307. var result = optionalTarget || new THREE.Vector3();
  4308. // collinear or singular triangle
  4309. if ( denom === 0 ) {
  4310. // arbitrary location outside of triangle?
  4311. // not sure if this is the best idea, maybe should be returning undefined
  4312. return result.set( - 2, - 1, - 1 );
  4313. }
  4314. var invDenom = 1 / denom;
  4315. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4316. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4317. // barycentric coordinates must always sum to 1
  4318. return result.set( 1 - u - v, v, u );
  4319. };
  4320. }();
  4321. THREE.Triangle.containsPoint = function () {
  4322. var v1 = new THREE.Vector3();
  4323. return function ( point, a, b, c ) {
  4324. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4325. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4326. };
  4327. }();
  4328. THREE.Triangle.prototype = {
  4329. constructor: THREE.Triangle,
  4330. set: function ( a, b, c ) {
  4331. this.a.copy( a );
  4332. this.b.copy( b );
  4333. this.c.copy( c );
  4334. return this;
  4335. },
  4336. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4337. this.a.copy( points[ i0 ] );
  4338. this.b.copy( points[ i1 ] );
  4339. this.c.copy( points[ i2 ] );
  4340. return this;
  4341. },
  4342. clone: function () {
  4343. return new this.constructor().copy( this );
  4344. },
  4345. copy: function ( triangle ) {
  4346. this.a.copy( triangle.a );
  4347. this.b.copy( triangle.b );
  4348. this.c.copy( triangle.c );
  4349. return this;
  4350. },
  4351. area: function () {
  4352. var v0 = new THREE.Vector3();
  4353. var v1 = new THREE.Vector3();
  4354. return function () {
  4355. v0.subVectors( this.c, this.b );
  4356. v1.subVectors( this.a, this.b );
  4357. return v0.cross( v1 ).length() * 0.5;
  4358. };
  4359. }(),
  4360. midpoint: function ( optionalTarget ) {
  4361. var result = optionalTarget || new THREE.Vector3();
  4362. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4363. },
  4364. normal: function ( optionalTarget ) {
  4365. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4366. },
  4367. plane: function ( optionalTarget ) {
  4368. var result = optionalTarget || new THREE.Plane();
  4369. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4370. },
  4371. barycoordFromPoint: function ( point, optionalTarget ) {
  4372. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4373. },
  4374. containsPoint: function ( point ) {
  4375. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4376. },
  4377. equals: function ( triangle ) {
  4378. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4379. }
  4380. };
  4381. // File:src/core/Clock.js
  4382. /**
  4383. * @author alteredq / http://alteredqualia.com/
  4384. */
  4385. THREE.Clock = function ( autoStart ) {
  4386. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4387. this.startTime = 0;
  4388. this.oldTime = 0;
  4389. this.elapsedTime = 0;
  4390. this.running = false;
  4391. };
  4392. THREE.Clock.prototype = {
  4393. constructor: THREE.Clock,
  4394. start: function () {
  4395. this.startTime = self.performance.now();
  4396. this.oldTime = this.startTime;
  4397. this.running = true;
  4398. },
  4399. stop: function () {
  4400. this.getElapsedTime();
  4401. this.running = false;
  4402. },
  4403. getElapsedTime: function () {
  4404. this.getDelta();
  4405. return this.elapsedTime;
  4406. },
  4407. getDelta: function () {
  4408. var diff = 0;
  4409. if ( this.autoStart && ! this.running ) {
  4410. this.start();
  4411. }
  4412. if ( this.running ) {
  4413. var newTime = self.performance.now();
  4414. diff = 0.001 * ( newTime - this.oldTime );
  4415. this.oldTime = newTime;
  4416. this.elapsedTime += diff;
  4417. }
  4418. return diff;
  4419. }
  4420. };
  4421. // File:src/core/EventDispatcher.js
  4422. /**
  4423. * https://github.com/mrdoob/eventdispatcher.js/
  4424. */
  4425. THREE.EventDispatcher = function () {};
  4426. THREE.EventDispatcher.prototype = {
  4427. constructor: THREE.EventDispatcher,
  4428. apply: function ( object ) {
  4429. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4430. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4431. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4432. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4433. },
  4434. addEventListener: function ( type, listener ) {
  4435. if ( this._listeners === undefined ) this._listeners = {};
  4436. var listeners = this._listeners;
  4437. if ( listeners[ type ] === undefined ) {
  4438. listeners[ type ] = [];
  4439. }
  4440. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4441. listeners[ type ].push( listener );
  4442. }
  4443. },
  4444. hasEventListener: function ( type, listener ) {
  4445. if ( this._listeners === undefined ) return false;
  4446. var listeners = this._listeners;
  4447. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4448. return true;
  4449. }
  4450. return false;
  4451. },
  4452. removeEventListener: function ( type, listener ) {
  4453. if ( this._listeners === undefined ) return;
  4454. var listeners = this._listeners;
  4455. var listenerArray = listeners[ type ];
  4456. if ( listenerArray !== undefined ) {
  4457. var index = listenerArray.indexOf( listener );
  4458. if ( index !== - 1 ) {
  4459. listenerArray.splice( index, 1 );
  4460. }
  4461. }
  4462. },
  4463. dispatchEvent: function ( event ) {
  4464. if ( this._listeners === undefined ) return;
  4465. var listeners = this._listeners;
  4466. var listenerArray = listeners[ event.type ];
  4467. if ( listenerArray !== undefined ) {
  4468. event.target = this;
  4469. var array = [];
  4470. var length = listenerArray.length;
  4471. for ( var i = 0; i < length; i ++ ) {
  4472. array[ i ] = listenerArray[ i ];
  4473. }
  4474. for ( var i = 0; i < length; i ++ ) {
  4475. array[ i ].call( this, event );
  4476. }
  4477. }
  4478. }
  4479. };
  4480. // File:src/core/Raycaster.js
  4481. /**
  4482. * @author mrdoob / http://mrdoob.com/
  4483. * @author bhouston / http://clara.io/
  4484. * @author stephomi / http://stephaneginier.com/
  4485. */
  4486. ( function ( THREE ) {
  4487. THREE.Raycaster = function ( origin, direction, near, far ) {
  4488. this.ray = new THREE.Ray( origin, direction );
  4489. // direction is assumed to be normalized (for accurate distance calculations)
  4490. this.near = near || 0;
  4491. this.far = far || Infinity;
  4492. this.params = {
  4493. Mesh: {},
  4494. Line: {},
  4495. LOD: {},
  4496. Points: { threshold: 1 },
  4497. Sprite: {}
  4498. };
  4499. Object.defineProperties( this.params, {
  4500. PointCloud: {
  4501. get: function () {
  4502. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4503. return this.Points;
  4504. }
  4505. }
  4506. } );
  4507. };
  4508. function descSort( a, b ) {
  4509. return a.distance - b.distance;
  4510. }
  4511. function intersectObject( object, raycaster, intersects, recursive ) {
  4512. if ( object.visible === false ) return;
  4513. object.raycast( raycaster, intersects );
  4514. if ( recursive === true ) {
  4515. var children = object.children;
  4516. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4517. intersectObject( children[ i ], raycaster, intersects, true );
  4518. }
  4519. }
  4520. }
  4521. //
  4522. THREE.Raycaster.prototype = {
  4523. constructor: THREE.Raycaster,
  4524. linePrecision: 1,
  4525. set: function ( origin, direction ) {
  4526. // direction is assumed to be normalized (for accurate distance calculations)
  4527. this.ray.set( origin, direction );
  4528. },
  4529. setFromCamera: function ( coords, camera ) {
  4530. if ( camera instanceof THREE.PerspectiveCamera ) {
  4531. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4532. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4533. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4534. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4535. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4536. } else {
  4537. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4538. }
  4539. },
  4540. intersectObject: function ( object, recursive ) {
  4541. var intersects = [];
  4542. intersectObject( object, this, intersects, recursive );
  4543. intersects.sort( descSort );
  4544. return intersects;
  4545. },
  4546. intersectObjects: function ( objects, recursive ) {
  4547. var intersects = [];
  4548. if ( Array.isArray( objects ) === false ) {
  4549. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4550. return intersects;
  4551. }
  4552. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4553. intersectObject( objects[ i ], this, intersects, recursive );
  4554. }
  4555. intersects.sort( descSort );
  4556. return intersects;
  4557. }
  4558. };
  4559. }( THREE ) );
  4560. // File:src/core/Object3D.js
  4561. /**
  4562. * @author mrdoob / http://mrdoob.com/
  4563. * @author mikael emtinger / http://gomo.se/
  4564. * @author alteredq / http://alteredqualia.com/
  4565. * @author WestLangley / http://github.com/WestLangley
  4566. * @author elephantatwork / www.elephantatwork.ch
  4567. */
  4568. THREE.Object3D = function () {
  4569. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4570. this.uuid = THREE.Math.generateUUID();
  4571. this.name = '';
  4572. this.type = 'Object3D';
  4573. this.parent = null;
  4574. this.children = [];
  4575. this.up = THREE.Object3D.DefaultUp.clone();
  4576. var position = new THREE.Vector3();
  4577. var rotation = new THREE.Euler();
  4578. var quaternion = new THREE.Quaternion();
  4579. var scale = new THREE.Vector3( 1, 1, 1 );
  4580. function onRotationChange() {
  4581. quaternion.setFromEuler( rotation, false );
  4582. }
  4583. function onQuaternionChange() {
  4584. rotation.setFromQuaternion( quaternion, undefined, false );
  4585. }
  4586. rotation.onChange( onRotationChange );
  4587. quaternion.onChange( onQuaternionChange );
  4588. Object.defineProperties( this, {
  4589. position: {
  4590. enumerable: true,
  4591. value: position
  4592. },
  4593. rotation: {
  4594. enumerable: true,
  4595. value: rotation
  4596. },
  4597. quaternion: {
  4598. enumerable: true,
  4599. value: quaternion
  4600. },
  4601. scale: {
  4602. enumerable: true,
  4603. value: scale
  4604. },
  4605. modelViewMatrix: {
  4606. value: new THREE.Matrix4()
  4607. },
  4608. normalMatrix: {
  4609. value: new THREE.Matrix3()
  4610. }
  4611. } );
  4612. this.rotationAutoUpdate = true;
  4613. this.matrix = new THREE.Matrix4();
  4614. this.matrixWorld = new THREE.Matrix4();
  4615. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4616. this.matrixWorldNeedsUpdate = false;
  4617. this.visible = true;
  4618. this.castShadow = false;
  4619. this.receiveShadow = false;
  4620. this.frustumCulled = true;
  4621. this.renderOrder = 0;
  4622. this.userData = {};
  4623. };
  4624. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4625. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4626. THREE.Object3D.prototype = {
  4627. constructor: THREE.Object3D,
  4628. get eulerOrder () {
  4629. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  4630. return this.rotation.order;
  4631. },
  4632. set eulerOrder ( value ) {
  4633. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  4634. this.rotation.order = value;
  4635. },
  4636. get useQuaternion () {
  4637. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4638. },
  4639. set useQuaternion ( value ) {
  4640. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4641. },
  4642. set renderDepth ( value ) {
  4643. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4644. },
  4645. //
  4646. applyMatrix: function ( matrix ) {
  4647. this.matrix.multiplyMatrices( matrix, this.matrix );
  4648. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4649. },
  4650. setRotationFromAxisAngle: function ( axis, angle ) {
  4651. // assumes axis is normalized
  4652. this.quaternion.setFromAxisAngle( axis, angle );
  4653. },
  4654. setRotationFromEuler: function ( euler ) {
  4655. this.quaternion.setFromEuler( euler, true );
  4656. },
  4657. setRotationFromMatrix: function ( m ) {
  4658. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4659. this.quaternion.setFromRotationMatrix( m );
  4660. },
  4661. setRotationFromQuaternion: function ( q ) {
  4662. // assumes q is normalized
  4663. this.quaternion.copy( q );
  4664. },
  4665. rotateOnAxis: function () {
  4666. // rotate object on axis in object space
  4667. // axis is assumed to be normalized
  4668. var q1 = new THREE.Quaternion();
  4669. return function ( axis, angle ) {
  4670. q1.setFromAxisAngle( axis, angle );
  4671. this.quaternion.multiply( q1 );
  4672. return this;
  4673. };
  4674. }(),
  4675. rotateX: function () {
  4676. var v1 = new THREE.Vector3( 1, 0, 0 );
  4677. return function ( angle ) {
  4678. return this.rotateOnAxis( v1, angle );
  4679. };
  4680. }(),
  4681. rotateY: function () {
  4682. var v1 = new THREE.Vector3( 0, 1, 0 );
  4683. return function ( angle ) {
  4684. return this.rotateOnAxis( v1, angle );
  4685. };
  4686. }(),
  4687. rotateZ: function () {
  4688. var v1 = new THREE.Vector3( 0, 0, 1 );
  4689. return function ( angle ) {
  4690. return this.rotateOnAxis( v1, angle );
  4691. };
  4692. }(),
  4693. translateOnAxis: function () {
  4694. // translate object by distance along axis in object space
  4695. // axis is assumed to be normalized
  4696. var v1 = new THREE.Vector3();
  4697. return function ( axis, distance ) {
  4698. v1.copy( axis ).applyQuaternion( this.quaternion );
  4699. this.position.add( v1.multiplyScalar( distance ) );
  4700. return this;
  4701. };
  4702. }(),
  4703. translate: function ( distance, axis ) {
  4704. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4705. return this.translateOnAxis( axis, distance );
  4706. },
  4707. translateX: function () {
  4708. var v1 = new THREE.Vector3( 1, 0, 0 );
  4709. return function ( distance ) {
  4710. return this.translateOnAxis( v1, distance );
  4711. };
  4712. }(),
  4713. translateY: function () {
  4714. var v1 = new THREE.Vector3( 0, 1, 0 );
  4715. return function ( distance ) {
  4716. return this.translateOnAxis( v1, distance );
  4717. };
  4718. }(),
  4719. translateZ: function () {
  4720. var v1 = new THREE.Vector3( 0, 0, 1 );
  4721. return function ( distance ) {
  4722. return this.translateOnAxis( v1, distance );
  4723. };
  4724. }(),
  4725. localToWorld: function ( vector ) {
  4726. return vector.applyMatrix4( this.matrixWorld );
  4727. },
  4728. worldToLocal: function () {
  4729. var m1 = new THREE.Matrix4();
  4730. return function ( vector ) {
  4731. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4732. };
  4733. }(),
  4734. lookAt: function () {
  4735. // This routine does not support objects with rotated and/or translated parent(s)
  4736. var m1 = new THREE.Matrix4();
  4737. return function ( vector ) {
  4738. m1.lookAt( vector, this.position, this.up );
  4739. this.quaternion.setFromRotationMatrix( m1 );
  4740. };
  4741. }(),
  4742. add: function ( object ) {
  4743. if ( arguments.length > 1 ) {
  4744. for ( var i = 0; i < arguments.length; i ++ ) {
  4745. this.add( arguments[ i ] );
  4746. }
  4747. return this;
  4748. }
  4749. if ( object === this ) {
  4750. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4751. return this;
  4752. }
  4753. if ( object instanceof THREE.Object3D ) {
  4754. if ( object.parent !== null ) {
  4755. object.parent.remove( object );
  4756. }
  4757. object.parent = this;
  4758. object.dispatchEvent( { type: 'added' } );
  4759. this.children.push( object );
  4760. } else {
  4761. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4762. }
  4763. return this;
  4764. },
  4765. remove: function ( object ) {
  4766. if ( arguments.length > 1 ) {
  4767. for ( var i = 0; i < arguments.length; i ++ ) {
  4768. this.remove( arguments[ i ] );
  4769. }
  4770. }
  4771. var index = this.children.indexOf( object );
  4772. if ( index !== - 1 ) {
  4773. object.parent = null;
  4774. object.dispatchEvent( { type: 'removed' } );
  4775. this.children.splice( index, 1 );
  4776. }
  4777. },
  4778. getChildByName: function ( name ) {
  4779. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4780. return this.getObjectByName( name );
  4781. },
  4782. getObjectById: function ( id ) {
  4783. return this.getObjectByProperty( 'id', id );
  4784. },
  4785. getObjectByName: function ( name ) {
  4786. return this.getObjectByProperty( 'name', name );
  4787. },
  4788. getObjectByProperty: function ( name, value ) {
  4789. if ( this[ name ] === value ) return this;
  4790. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4791. var child = this.children[ i ];
  4792. var object = child.getObjectByProperty( name, value );
  4793. if ( object !== undefined ) {
  4794. return object;
  4795. }
  4796. }
  4797. return undefined;
  4798. },
  4799. getWorldPosition: function ( optionalTarget ) {
  4800. var result = optionalTarget || new THREE.Vector3();
  4801. this.updateMatrixWorld( true );
  4802. return result.setFromMatrixPosition( this.matrixWorld );
  4803. },
  4804. getWorldQuaternion: function () {
  4805. var position = new THREE.Vector3();
  4806. var scale = new THREE.Vector3();
  4807. return function ( optionalTarget ) {
  4808. var result = optionalTarget || new THREE.Quaternion();
  4809. this.updateMatrixWorld( true );
  4810. this.matrixWorld.decompose( position, result, scale );
  4811. return result;
  4812. };
  4813. }(),
  4814. getWorldRotation: function () {
  4815. var quaternion = new THREE.Quaternion();
  4816. return function ( optionalTarget ) {
  4817. var result = optionalTarget || new THREE.Euler();
  4818. this.getWorldQuaternion( quaternion );
  4819. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4820. };
  4821. }(),
  4822. getWorldScale: function () {
  4823. var position = new THREE.Vector3();
  4824. var quaternion = new THREE.Quaternion();
  4825. return function ( optionalTarget ) {
  4826. var result = optionalTarget || new THREE.Vector3();
  4827. this.updateMatrixWorld( true );
  4828. this.matrixWorld.decompose( position, quaternion, result );
  4829. return result;
  4830. };
  4831. }(),
  4832. getWorldDirection: function () {
  4833. var quaternion = new THREE.Quaternion();
  4834. return function ( optionalTarget ) {
  4835. var result = optionalTarget || new THREE.Vector3();
  4836. this.getWorldQuaternion( quaternion );
  4837. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4838. };
  4839. }(),
  4840. raycast: function () {},
  4841. traverse: function ( callback ) {
  4842. callback( this );
  4843. var children = this.children;
  4844. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4845. children[ i ].traverse( callback );
  4846. }
  4847. },
  4848. traverseVisible: function ( callback ) {
  4849. if ( this.visible === false ) return;
  4850. callback( this );
  4851. var children = this.children;
  4852. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4853. children[ i ].traverseVisible( callback );
  4854. }
  4855. },
  4856. traverseAncestors: function ( callback ) {
  4857. var parent = this.parent;
  4858. if ( parent !== null ) {
  4859. callback( parent );
  4860. parent.traverseAncestors( callback );
  4861. }
  4862. },
  4863. updateMatrix: function () {
  4864. this.matrix.compose( this.position, this.quaternion, this.scale );
  4865. this.matrixWorldNeedsUpdate = true;
  4866. },
  4867. updateMatrixWorld: function ( force ) {
  4868. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4869. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4870. if ( this.parent === null ) {
  4871. this.matrixWorld.copy( this.matrix );
  4872. } else {
  4873. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4874. }
  4875. this.matrixWorldNeedsUpdate = false;
  4876. force = true;
  4877. }
  4878. // update children
  4879. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4880. this.children[ i ].updateMatrixWorld( force );
  4881. }
  4882. },
  4883. toJSON: function ( meta ) {
  4884. var isRootObject = ( meta === undefined );
  4885. var output = {};
  4886. // meta is a hash used to collect geometries, materials.
  4887. // not providing it implies that this is the root object
  4888. // being serialized.
  4889. if ( isRootObject ) {
  4890. // initialize meta obj
  4891. meta = {
  4892. geometries: {},
  4893. materials: {},
  4894. textures: {},
  4895. images: {}
  4896. };
  4897. output.metadata = {
  4898. version: 4.4,
  4899. type: 'Object',
  4900. generator: 'Object3D.toJSON'
  4901. };
  4902. }
  4903. // standard Object3D serialization
  4904. var object = {};
  4905. object.uuid = this.uuid;
  4906. object.type = this.type;
  4907. if ( this.name !== '' ) object.name = this.name;
  4908. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  4909. if ( this.visible !== true ) object.visible = this.visible;
  4910. object.matrix = this.matrix.toArray();
  4911. //
  4912. if ( this.geometry !== undefined ) {
  4913. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  4914. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  4915. }
  4916. object.geometry = this.geometry.uuid;
  4917. }
  4918. if ( this.material !== undefined ) {
  4919. if ( meta.materials[ this.material.uuid ] === undefined ) {
  4920. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  4921. }
  4922. object.material = this.material.uuid;
  4923. }
  4924. //
  4925. if ( this.children.length > 0 ) {
  4926. object.children = [];
  4927. for ( var i = 0; i < this.children.length; i ++ ) {
  4928. object.children.push( this.children[ i ].toJSON( meta ).object );
  4929. }
  4930. }
  4931. if ( isRootObject ) {
  4932. var geometries = extractFromCache( meta.geometries );
  4933. var materials = extractFromCache( meta.materials );
  4934. var textures = extractFromCache( meta.textures );
  4935. var images = extractFromCache( meta.images );
  4936. if ( geometries.length > 0 ) output.geometries = geometries;
  4937. if ( materials.length > 0 ) output.materials = materials;
  4938. if ( textures.length > 0 ) output.textures = textures;
  4939. if ( images.length > 0 ) output.images = images;
  4940. }
  4941. output.object = object;
  4942. return output;
  4943. // extract data from the cache hash
  4944. // remove metadata on each item
  4945. // and return as array
  4946. function extractFromCache ( cache ) {
  4947. var values = [];
  4948. for ( var key in cache ) {
  4949. var data = cache[ key ];
  4950. delete data.metadata;
  4951. values.push( data );
  4952. }
  4953. return values;
  4954. }
  4955. },
  4956. clone: function ( recursive ) {
  4957. return new this.constructor().copy( this, recursive );
  4958. },
  4959. copy: function ( source, recursive ) {
  4960. if ( recursive === undefined ) recursive = true;
  4961. this.name = source.name;
  4962. this.up.copy( source.up );
  4963. this.position.copy( source.position );
  4964. this.quaternion.copy( source.quaternion );
  4965. this.scale.copy( source.scale );
  4966. this.rotationAutoUpdate = source.rotationAutoUpdate;
  4967. this.matrix.copy( source.matrix );
  4968. this.matrixWorld.copy( source.matrixWorld );
  4969. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4970. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4971. this.visible = source.visible;
  4972. this.castShadow = source.castShadow;
  4973. this.receiveShadow = source.receiveShadow;
  4974. this.frustumCulled = source.frustumCulled;
  4975. this.renderOrder = source.renderOrder;
  4976. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4977. if ( recursive === true ) {
  4978. for ( var i = 0; i < source.children.length; i ++ ) {
  4979. var child = source.children[ i ];
  4980. this.add( child.clone() );
  4981. }
  4982. }
  4983. return this;
  4984. }
  4985. };
  4986. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4987. THREE.Object3DIdCount = 0;
  4988. // File:src/core/Face3.js
  4989. /**
  4990. * @author mrdoob / http://mrdoob.com/
  4991. * @author alteredq / http://alteredqualia.com/
  4992. */
  4993. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  4994. this.a = a;
  4995. this.b = b;
  4996. this.c = c;
  4997. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4998. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4999. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5000. this.vertexColors = Array.isArray( color ) ? color : [];
  5001. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5002. };
  5003. THREE.Face3.prototype = {
  5004. constructor: THREE.Face3,
  5005. clone: function () {
  5006. return new this.constructor().copy( this );
  5007. },
  5008. copy: function ( source ) {
  5009. this.a = source.a;
  5010. this.b = source.b;
  5011. this.c = source.c;
  5012. this.normal.copy( source.normal );
  5013. this.color.copy( source.color );
  5014. this.materialIndex = source.materialIndex;
  5015. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5016. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5017. }
  5018. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5019. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5020. }
  5021. return this;
  5022. }
  5023. };
  5024. // File:src/core/Face4.js
  5025. /**
  5026. * @author mrdoob / http://mrdoob.com/
  5027. */
  5028. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  5029. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  5030. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  5031. };
  5032. // File:src/core/BufferAttribute.js
  5033. /**
  5034. * @author mrdoob / http://mrdoob.com/
  5035. */
  5036. THREE.BufferAttribute = function ( array, itemSize ) {
  5037. this.uuid = THREE.Math.generateUUID();
  5038. this.array = array;
  5039. this.itemSize = itemSize;
  5040. this.dynamic = false;
  5041. this.updateRange = { offset: 0, count: - 1 };
  5042. this.version = 0;
  5043. };
  5044. THREE.BufferAttribute.prototype = {
  5045. constructor: THREE.BufferAttribute,
  5046. get length() {
  5047. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5048. return this.array.length;
  5049. },
  5050. get count() {
  5051. return this.array.length / this.itemSize;
  5052. },
  5053. set needsUpdate( value ) {
  5054. if ( value === true ) this.version ++;
  5055. },
  5056. setDynamic: function ( value ) {
  5057. this.dynamic = value;
  5058. return this;
  5059. },
  5060. copy: function ( source ) {
  5061. this.array = new source.array.constructor( source.array );
  5062. this.itemSize = source.itemSize;
  5063. this.dynamic = source.dynamic;
  5064. return this;
  5065. },
  5066. copyAt: function ( index1, attribute, index2 ) {
  5067. index1 *= this.itemSize;
  5068. index2 *= attribute.itemSize;
  5069. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5070. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5071. }
  5072. return this;
  5073. },
  5074. copyArray: function ( array ) {
  5075. this.array.set( array );
  5076. return this;
  5077. },
  5078. copyColorsArray: function ( colors ) {
  5079. var array = this.array, offset = 0;
  5080. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5081. var color = colors[ i ];
  5082. if ( color === undefined ) {
  5083. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5084. color = new THREE.Color();
  5085. }
  5086. array[ offset ++ ] = color.r;
  5087. array[ offset ++ ] = color.g;
  5088. array[ offset ++ ] = color.b;
  5089. }
  5090. return this;
  5091. },
  5092. copyIndicesArray: function ( indices ) {
  5093. var array = this.array, offset = 0;
  5094. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5095. var index = indices[ i ];
  5096. array[ offset ++ ] = index.a;
  5097. array[ offset ++ ] = index.b;
  5098. array[ offset ++ ] = index.c;
  5099. }
  5100. return this;
  5101. },
  5102. copyVector2sArray: function ( vectors ) {
  5103. var array = this.array, offset = 0;
  5104. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5105. var vector = vectors[ i ];
  5106. if ( vector === undefined ) {
  5107. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5108. vector = new THREE.Vector2();
  5109. }
  5110. array[ offset ++ ] = vector.x;
  5111. array[ offset ++ ] = vector.y;
  5112. }
  5113. return this;
  5114. },
  5115. copyVector3sArray: function ( vectors ) {
  5116. var array = this.array, offset = 0;
  5117. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5118. var vector = vectors[ i ];
  5119. if ( vector === undefined ) {
  5120. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5121. vector = new THREE.Vector3();
  5122. }
  5123. array[ offset ++ ] = vector.x;
  5124. array[ offset ++ ] = vector.y;
  5125. array[ offset ++ ] = vector.z;
  5126. }
  5127. return this;
  5128. },
  5129. copyVector4sArray: function ( vectors ) {
  5130. var array = this.array, offset = 0;
  5131. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5132. var vector = vectors[ i ];
  5133. if ( vector === undefined ) {
  5134. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5135. vector = new THREE.Vector4();
  5136. }
  5137. array[ offset ++ ] = vector.x;
  5138. array[ offset ++ ] = vector.y;
  5139. array[ offset ++ ] = vector.z;
  5140. array[ offset ++ ] = vector.w;
  5141. }
  5142. return this;
  5143. },
  5144. set: function ( value, offset ) {
  5145. if ( offset === undefined ) offset = 0;
  5146. this.array.set( value, offset );
  5147. return this;
  5148. },
  5149. getX: function ( index ) {
  5150. return this.array[ index * this.itemSize ];
  5151. },
  5152. setX: function ( index, x ) {
  5153. this.array[ index * this.itemSize ] = x;
  5154. return this;
  5155. },
  5156. getY: function ( index ) {
  5157. return this.array[ index * this.itemSize + 1 ];
  5158. },
  5159. setY: function ( index, y ) {
  5160. this.array[ index * this.itemSize + 1 ] = y;
  5161. return this;
  5162. },
  5163. getZ: function ( index ) {
  5164. return this.array[ index * this.itemSize + 2 ];
  5165. },
  5166. setZ: function ( index, z ) {
  5167. this.array[ index * this.itemSize + 2 ] = z;
  5168. return this;
  5169. },
  5170. getW: function ( index ) {
  5171. return this.array[ index * this.itemSize + 3 ];
  5172. },
  5173. setW: function ( index, w ) {
  5174. this.array[ index * this.itemSize + 3 ] = w;
  5175. return this;
  5176. },
  5177. setXY: function ( index, x, y ) {
  5178. index *= this.itemSize;
  5179. this.array[ index + 0 ] = x;
  5180. this.array[ index + 1 ] = y;
  5181. return this;
  5182. },
  5183. setXYZ: function ( index, x, y, z ) {
  5184. index *= this.itemSize;
  5185. this.array[ index + 0 ] = x;
  5186. this.array[ index + 1 ] = y;
  5187. this.array[ index + 2 ] = z;
  5188. return this;
  5189. },
  5190. setXYZW: function ( index, x, y, z, w ) {
  5191. index *= this.itemSize;
  5192. this.array[ index + 0 ] = x;
  5193. this.array[ index + 1 ] = y;
  5194. this.array[ index + 2 ] = z;
  5195. this.array[ index + 3 ] = w;
  5196. return this;
  5197. },
  5198. clone: function () {
  5199. return new this.constructor().copy( this );
  5200. }
  5201. };
  5202. //
  5203. THREE.Int8Attribute = function ( array, itemSize ) {
  5204. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5205. };
  5206. THREE.Uint8Attribute = function ( array, itemSize ) {
  5207. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5208. };
  5209. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5210. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5211. };
  5212. THREE.Int16Attribute = function ( array, itemSize ) {
  5213. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5214. };
  5215. THREE.Uint16Attribute = function ( array, itemSize ) {
  5216. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5217. };
  5218. THREE.Int32Attribute = function ( array, itemSize ) {
  5219. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5220. };
  5221. THREE.Uint32Attribute = function ( array, itemSize ) {
  5222. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5223. };
  5224. THREE.Float32Attribute = function ( array, itemSize ) {
  5225. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5226. };
  5227. THREE.Float64Attribute = function ( array, itemSize ) {
  5228. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5229. };
  5230. // Deprecated
  5231. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5232. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5233. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5234. };
  5235. // File:src/core/InstancedBufferAttribute.js
  5236. /**
  5237. * @author benaadams / https://twitter.com/ben_a_adams
  5238. */
  5239. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5240. THREE.BufferAttribute.call( this, array, itemSize );
  5241. this.meshPerAttribute = meshPerAttribute || 1;
  5242. };
  5243. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5244. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5245. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5246. THREE.BufferAttribute.prototype.copy.call( this, source );
  5247. this.meshPerAttribute = source.meshPerAttribute;
  5248. return this;
  5249. };
  5250. // File:src/core/InterleavedBuffer.js
  5251. /**
  5252. * @author benaadams / https://twitter.com/ben_a_adams
  5253. */
  5254. THREE.InterleavedBuffer = function ( array, stride ) {
  5255. this.uuid = THREE.Math.generateUUID();
  5256. this.array = array;
  5257. this.stride = stride;
  5258. this.dynamic = false;
  5259. this.updateRange = { offset: 0, count: - 1 };
  5260. this.version = 0;
  5261. };
  5262. THREE.InterleavedBuffer.prototype = {
  5263. constructor: THREE.InterleavedBuffer,
  5264. get length () {
  5265. return this.array.length;
  5266. },
  5267. get count () {
  5268. return this.array.length / this.stride;
  5269. },
  5270. set needsUpdate( value ) {
  5271. if ( value === true ) this.version ++;
  5272. },
  5273. setDynamic: function ( value ) {
  5274. this.dynamic = value;
  5275. return this;
  5276. },
  5277. copy: function ( source ) {
  5278. this.array = new source.array.constructor( source.array );
  5279. this.stride = source.stride;
  5280. this.dynamic = source.dynamic;
  5281. },
  5282. copyAt: function ( index1, attribute, index2 ) {
  5283. index1 *= this.stride;
  5284. index2 *= attribute.stride;
  5285. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5286. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5287. }
  5288. return this;
  5289. },
  5290. set: function ( value, offset ) {
  5291. if ( offset === undefined ) offset = 0;
  5292. this.array.set( value, offset );
  5293. return this;
  5294. },
  5295. clone: function () {
  5296. return new this.constructor().copy( this );
  5297. }
  5298. };
  5299. // File:src/core/InstancedInterleavedBuffer.js
  5300. /**
  5301. * @author benaadams / https://twitter.com/ben_a_adams
  5302. */
  5303. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5304. THREE.InterleavedBuffer.call( this, array, stride );
  5305. this.meshPerAttribute = meshPerAttribute || 1;
  5306. };
  5307. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5308. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5309. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5310. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5311. this.meshPerAttribute = source.meshPerAttribute;
  5312. return this;
  5313. };
  5314. // File:src/core/InterleavedBufferAttribute.js
  5315. /**
  5316. * @author benaadams / https://twitter.com/ben_a_adams
  5317. */
  5318. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5319. this.uuid = THREE.Math.generateUUID();
  5320. this.data = interleavedBuffer;
  5321. this.itemSize = itemSize;
  5322. this.offset = offset;
  5323. };
  5324. THREE.InterleavedBufferAttribute.prototype = {
  5325. constructor: THREE.InterleavedBufferAttribute,
  5326. get length() {
  5327. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5328. return this.array.length;
  5329. },
  5330. get count() {
  5331. return this.data.array.length / this.data.stride;
  5332. },
  5333. setX: function ( index, x ) {
  5334. this.data.array[ index * this.data.stride + this.offset ] = x;
  5335. return this;
  5336. },
  5337. setY: function ( index, y ) {
  5338. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5339. return this;
  5340. },
  5341. setZ: function ( index, z ) {
  5342. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5343. return this;
  5344. },
  5345. setW: function ( index, w ) {
  5346. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5347. return this;
  5348. },
  5349. getX: function ( index ) {
  5350. return this.data.array[ index * this.data.stride + this.offset ];
  5351. },
  5352. getY: function ( index ) {
  5353. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5354. },
  5355. getZ: function ( index ) {
  5356. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5357. },
  5358. getW: function ( index ) {
  5359. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5360. },
  5361. setXY: function ( index, x, y ) {
  5362. index = index * this.data.stride + this.offset;
  5363. this.data.array[ index + 0 ] = x;
  5364. this.data.array[ index + 1 ] = y;
  5365. return this;
  5366. },
  5367. setXYZ: function ( index, x, y, z ) {
  5368. index = index * this.data.stride + this.offset;
  5369. this.data.array[ index + 0 ] = x;
  5370. this.data.array[ index + 1 ] = y;
  5371. this.data.array[ index + 2 ] = z;
  5372. return this;
  5373. },
  5374. setXYZW: function ( index, x, y, z, w ) {
  5375. index = index * this.data.stride + this.offset;
  5376. this.data.array[ index + 0 ] = x;
  5377. this.data.array[ index + 1 ] = y;
  5378. this.data.array[ index + 2 ] = z;
  5379. this.data.array[ index + 3 ] = w;
  5380. return this;
  5381. }
  5382. };
  5383. // File:src/core/Geometry.js
  5384. /**
  5385. * @author mrdoob / http://mrdoob.com/
  5386. * @author kile / http://kile.stravaganza.org/
  5387. * @author alteredq / http://alteredqualia.com/
  5388. * @author mikael emtinger / http://gomo.se/
  5389. * @author zz85 / http://www.lab4games.net/zz85/blog
  5390. * @author bhouston / http://clara.io
  5391. */
  5392. THREE.Geometry = function () {
  5393. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5394. this.uuid = THREE.Math.generateUUID();
  5395. this.name = '';
  5396. this.type = 'Geometry';
  5397. this.vertices = [];
  5398. this.colors = [];
  5399. this.faces = [];
  5400. this.faceVertexUvs = [ [] ];
  5401. this.morphTargets = [];
  5402. this.morphColors = [];
  5403. this.morphNormals = [];
  5404. this.skinWeights = [];
  5405. this.skinIndices = [];
  5406. this.lineDistances = [];
  5407. this.boundingBox = null;
  5408. this.boundingSphere = null;
  5409. // update flags
  5410. this.verticesNeedUpdate = false;
  5411. this.elementsNeedUpdate = false;
  5412. this.uvsNeedUpdate = false;
  5413. this.normalsNeedUpdate = false;
  5414. this.colorsNeedUpdate = false;
  5415. this.lineDistancesNeedUpdate = false;
  5416. this.groupsNeedUpdate = false;
  5417. };
  5418. THREE.Geometry.prototype = {
  5419. constructor: THREE.Geometry,
  5420. applyMatrix: function ( matrix ) {
  5421. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5422. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5423. var vertex = this.vertices[ i ];
  5424. vertex.applyMatrix4( matrix );
  5425. }
  5426. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5427. var face = this.faces[ i ];
  5428. face.normal.applyMatrix3( normalMatrix ).normalize();
  5429. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5430. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5431. }
  5432. }
  5433. if ( this.boundingBox !== null ) {
  5434. this.computeBoundingBox();
  5435. }
  5436. if ( this.boundingSphere !== null ) {
  5437. this.computeBoundingSphere();
  5438. }
  5439. this.verticesNeedUpdate = true;
  5440. this.normalsNeedUpdate = true;
  5441. },
  5442. rotateX: function () {
  5443. // rotate geometry around world x-axis
  5444. var m1;
  5445. return function rotateX( angle ) {
  5446. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5447. m1.makeRotationX( angle );
  5448. this.applyMatrix( m1 );
  5449. return this;
  5450. };
  5451. }(),
  5452. rotateY: function () {
  5453. // rotate geometry around world y-axis
  5454. var m1;
  5455. return function rotateY( angle ) {
  5456. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5457. m1.makeRotationY( angle );
  5458. this.applyMatrix( m1 );
  5459. return this;
  5460. };
  5461. }(),
  5462. rotateZ: function () {
  5463. // rotate geometry around world z-axis
  5464. var m1;
  5465. return function rotateZ( angle ) {
  5466. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5467. m1.makeRotationZ( angle );
  5468. this.applyMatrix( m1 );
  5469. return this;
  5470. };
  5471. }(),
  5472. translate: function () {
  5473. // translate geometry
  5474. var m1;
  5475. return function translate( x, y, z ) {
  5476. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5477. m1.makeTranslation( x, y, z );
  5478. this.applyMatrix( m1 );
  5479. return this;
  5480. };
  5481. }(),
  5482. scale: function () {
  5483. // scale geometry
  5484. var m1;
  5485. return function scale( x, y, z ) {
  5486. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5487. m1.makeScale( x, y, z );
  5488. this.applyMatrix( m1 );
  5489. return this;
  5490. };
  5491. }(),
  5492. lookAt: function () {
  5493. var obj;
  5494. return function lookAt( vector ) {
  5495. if ( obj === undefined ) obj = new THREE.Object3D();
  5496. obj.lookAt( vector );
  5497. obj.updateMatrix();
  5498. this.applyMatrix( obj.matrix );
  5499. };
  5500. }(),
  5501. fromBufferGeometry: function ( geometry ) {
  5502. var scope = this;
  5503. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5504. var attributes = geometry.attributes;
  5505. var vertices = attributes.position.array;
  5506. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5507. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5508. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5509. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5510. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5511. var tempNormals = [];
  5512. var tempUVs = [];
  5513. var tempUVs2 = [];
  5514. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5515. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5516. if ( normals !== undefined ) {
  5517. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5518. }
  5519. if ( colors !== undefined ) {
  5520. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5521. }
  5522. if ( uvs !== undefined ) {
  5523. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5524. }
  5525. if ( uvs2 !== undefined ) {
  5526. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5527. }
  5528. }
  5529. function addFace( a, b, c ) {
  5530. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5531. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5532. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5533. scope.faces.push( face );
  5534. if ( uvs !== undefined ) {
  5535. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5536. }
  5537. if ( uvs2 !== undefined ) {
  5538. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5539. }
  5540. };
  5541. if ( indices !== undefined ) {
  5542. var groups = geometry.groups;
  5543. if ( groups.length > 0 ) {
  5544. for ( var i = 0; i < groups.length; i ++ ) {
  5545. var group = groups[ i ];
  5546. var start = group.start;
  5547. var count = group.count;
  5548. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5549. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5550. }
  5551. }
  5552. } else {
  5553. for ( var i = 0; i < indices.length; i += 3 ) {
  5554. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5555. }
  5556. }
  5557. } else {
  5558. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5559. addFace( i, i + 1, i + 2 );
  5560. }
  5561. }
  5562. this.computeFaceNormals();
  5563. if ( geometry.boundingBox !== null ) {
  5564. this.boundingBox = geometry.boundingBox.clone();
  5565. }
  5566. if ( geometry.boundingSphere !== null ) {
  5567. this.boundingSphere = geometry.boundingSphere.clone();
  5568. }
  5569. return this;
  5570. },
  5571. center: function () {
  5572. this.computeBoundingBox();
  5573. var offset = this.boundingBox.center().negate();
  5574. this.translate( offset.x, offset.y, offset.z );
  5575. return offset;
  5576. },
  5577. normalize: function () {
  5578. this.computeBoundingSphere();
  5579. var center = this.boundingSphere.center;
  5580. var radius = this.boundingSphere.radius;
  5581. var s = radius === 0 ? 1 : 1.0 / radius;
  5582. var matrix = new THREE.Matrix4();
  5583. matrix.set(
  5584. s, 0, 0, - s * center.x,
  5585. 0, s, 0, - s * center.y,
  5586. 0, 0, s, - s * center.z,
  5587. 0, 0, 0, 1
  5588. );
  5589. this.applyMatrix( matrix );
  5590. return this;
  5591. },
  5592. computeFaceNormals: function () {
  5593. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5594. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5595. var face = this.faces[ f ];
  5596. var vA = this.vertices[ face.a ];
  5597. var vB = this.vertices[ face.b ];
  5598. var vC = this.vertices[ face.c ];
  5599. cb.subVectors( vC, vB );
  5600. ab.subVectors( vA, vB );
  5601. cb.cross( ab );
  5602. cb.normalize();
  5603. face.normal.copy( cb );
  5604. }
  5605. },
  5606. computeVertexNormals: function ( areaWeighted ) {
  5607. var v, vl, f, fl, face, vertices;
  5608. vertices = new Array( this.vertices.length );
  5609. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5610. vertices[ v ] = new THREE.Vector3();
  5611. }
  5612. if ( areaWeighted ) {
  5613. // vertex normals weighted by triangle areas
  5614. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5615. var vA, vB, vC;
  5616. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5617. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5618. face = this.faces[ f ];
  5619. vA = this.vertices[ face.a ];
  5620. vB = this.vertices[ face.b ];
  5621. vC = this.vertices[ face.c ];
  5622. cb.subVectors( vC, vB );
  5623. ab.subVectors( vA, vB );
  5624. cb.cross( ab );
  5625. vertices[ face.a ].add( cb );
  5626. vertices[ face.b ].add( cb );
  5627. vertices[ face.c ].add( cb );
  5628. }
  5629. } else {
  5630. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5631. face = this.faces[ f ];
  5632. vertices[ face.a ].add( face.normal );
  5633. vertices[ face.b ].add( face.normal );
  5634. vertices[ face.c ].add( face.normal );
  5635. }
  5636. }
  5637. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5638. vertices[ v ].normalize();
  5639. }
  5640. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5641. face = this.faces[ f ];
  5642. var vertexNormals = face.vertexNormals;
  5643. if ( vertexNormals.length === 3 ) {
  5644. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5645. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5646. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5647. } else {
  5648. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5649. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5650. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5651. }
  5652. }
  5653. },
  5654. computeMorphNormals: function () {
  5655. var i, il, f, fl, face;
  5656. // save original normals
  5657. // - create temp variables on first access
  5658. // otherwise just copy (for faster repeated calls)
  5659. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5660. face = this.faces[ f ];
  5661. if ( ! face.__originalFaceNormal ) {
  5662. face.__originalFaceNormal = face.normal.clone();
  5663. } else {
  5664. face.__originalFaceNormal.copy( face.normal );
  5665. }
  5666. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5667. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5668. if ( ! face.__originalVertexNormals[ i ] ) {
  5669. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5670. } else {
  5671. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5672. }
  5673. }
  5674. }
  5675. // use temp geometry to compute face and vertex normals for each morph
  5676. var tmpGeo = new THREE.Geometry();
  5677. tmpGeo.faces = this.faces;
  5678. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5679. // create on first access
  5680. if ( ! this.morphNormals[ i ] ) {
  5681. this.morphNormals[ i ] = {};
  5682. this.morphNormals[ i ].faceNormals = [];
  5683. this.morphNormals[ i ].vertexNormals = [];
  5684. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5685. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5686. var faceNormal, vertexNormals;
  5687. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5688. faceNormal = new THREE.Vector3();
  5689. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5690. dstNormalsFace.push( faceNormal );
  5691. dstNormalsVertex.push( vertexNormals );
  5692. }
  5693. }
  5694. var morphNormals = this.morphNormals[ i ];
  5695. // set vertices to morph target
  5696. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5697. // compute morph normals
  5698. tmpGeo.computeFaceNormals();
  5699. tmpGeo.computeVertexNormals();
  5700. // store morph normals
  5701. var faceNormal, vertexNormals;
  5702. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5703. face = this.faces[ f ];
  5704. faceNormal = morphNormals.faceNormals[ f ];
  5705. vertexNormals = morphNormals.vertexNormals[ f ];
  5706. faceNormal.copy( face.normal );
  5707. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5708. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5709. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5710. }
  5711. }
  5712. // restore original normals
  5713. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5714. face = this.faces[ f ];
  5715. face.normal = face.__originalFaceNormal;
  5716. face.vertexNormals = face.__originalVertexNormals;
  5717. }
  5718. },
  5719. computeTangents: function () {
  5720. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  5721. },
  5722. computeLineDistances: function () {
  5723. var d = 0;
  5724. var vertices = this.vertices;
  5725. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5726. if ( i > 0 ) {
  5727. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5728. }
  5729. this.lineDistances[ i ] = d;
  5730. }
  5731. },
  5732. computeBoundingBox: function () {
  5733. if ( this.boundingBox === null ) {
  5734. this.boundingBox = new THREE.Box3();
  5735. }
  5736. this.boundingBox.setFromPoints( this.vertices );
  5737. },
  5738. computeBoundingSphere: function () {
  5739. if ( this.boundingSphere === null ) {
  5740. this.boundingSphere = new THREE.Sphere();
  5741. }
  5742. this.boundingSphere.setFromPoints( this.vertices );
  5743. },
  5744. merge: function ( geometry, matrix, materialIndexOffset ) {
  5745. if ( geometry instanceof THREE.Geometry === false ) {
  5746. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5747. return;
  5748. }
  5749. var normalMatrix,
  5750. vertexOffset = this.vertices.length,
  5751. vertices1 = this.vertices,
  5752. vertices2 = geometry.vertices,
  5753. faces1 = this.faces,
  5754. faces2 = geometry.faces,
  5755. uvs1 = this.faceVertexUvs[ 0 ],
  5756. uvs2 = geometry.faceVertexUvs[ 0 ];
  5757. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5758. if ( matrix !== undefined ) {
  5759. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5760. }
  5761. // vertices
  5762. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5763. var vertex = vertices2[ i ];
  5764. var vertexCopy = vertex.clone();
  5765. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5766. vertices1.push( vertexCopy );
  5767. }
  5768. // faces
  5769. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5770. var face = faces2[ i ], faceCopy, normal, color,
  5771. faceVertexNormals = face.vertexNormals,
  5772. faceVertexColors = face.vertexColors;
  5773. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5774. faceCopy.normal.copy( face.normal );
  5775. if ( normalMatrix !== undefined ) {
  5776. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5777. }
  5778. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5779. normal = faceVertexNormals[ j ].clone();
  5780. if ( normalMatrix !== undefined ) {
  5781. normal.applyMatrix3( normalMatrix ).normalize();
  5782. }
  5783. faceCopy.vertexNormals.push( normal );
  5784. }
  5785. faceCopy.color.copy( face.color );
  5786. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5787. color = faceVertexColors[ j ];
  5788. faceCopy.vertexColors.push( color.clone() );
  5789. }
  5790. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5791. faces1.push( faceCopy );
  5792. }
  5793. // uvs
  5794. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5795. var uv = uvs2[ i ], uvCopy = [];
  5796. if ( uv === undefined ) {
  5797. continue;
  5798. }
  5799. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5800. uvCopy.push( uv[ j ].clone() );
  5801. }
  5802. uvs1.push( uvCopy );
  5803. }
  5804. },
  5805. mergeMesh: function ( mesh ) {
  5806. if ( mesh instanceof THREE.Mesh === false ) {
  5807. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5808. return;
  5809. }
  5810. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5811. this.merge( mesh.geometry, mesh.matrix );
  5812. },
  5813. /*
  5814. * Checks for duplicate vertices with hashmap.
  5815. * Duplicated vertices are removed
  5816. * and faces' vertices are updated.
  5817. */
  5818. mergeVertices: function () {
  5819. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5820. var unique = [], changes = [];
  5821. var v, key;
  5822. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5823. var precision = Math.pow( 10, precisionPoints );
  5824. var i, il, face;
  5825. var indices, j, jl;
  5826. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5827. v = this.vertices[ i ];
  5828. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5829. if ( verticesMap[ key ] === undefined ) {
  5830. verticesMap[ key ] = i;
  5831. unique.push( this.vertices[ i ] );
  5832. changes[ i ] = unique.length - 1;
  5833. } else {
  5834. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5835. changes[ i ] = changes[ verticesMap[ key ] ];
  5836. }
  5837. }
  5838. // if faces are completely degenerate after merging vertices, we
  5839. // have to remove them from the geometry.
  5840. var faceIndicesToRemove = [];
  5841. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5842. face = this.faces[ i ];
  5843. face.a = changes[ face.a ];
  5844. face.b = changes[ face.b ];
  5845. face.c = changes[ face.c ];
  5846. indices = [ face.a, face.b, face.c ];
  5847. var dupIndex = - 1;
  5848. // if any duplicate vertices are found in a Face3
  5849. // we have to remove the face as nothing can be saved
  5850. for ( var n = 0; n < 3; n ++ ) {
  5851. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5852. dupIndex = n;
  5853. faceIndicesToRemove.push( i );
  5854. break;
  5855. }
  5856. }
  5857. }
  5858. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5859. var idx = faceIndicesToRemove[ i ];
  5860. this.faces.splice( idx, 1 );
  5861. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5862. this.faceVertexUvs[ j ].splice( idx, 1 );
  5863. }
  5864. }
  5865. // Use unique set of vertices
  5866. var diff = this.vertices.length - unique.length;
  5867. this.vertices = unique;
  5868. return diff;
  5869. },
  5870. sortFacesByMaterialIndex: function () {
  5871. var faces = this.faces;
  5872. var length = faces.length;
  5873. // tag faces
  5874. for ( var i = 0; i < length; i ++ ) {
  5875. faces[ i ]._id = i;
  5876. }
  5877. // sort faces
  5878. function materialIndexSort( a, b ) {
  5879. return a.materialIndex - b.materialIndex;
  5880. }
  5881. faces.sort( materialIndexSort );
  5882. // sort uvs
  5883. var uvs1 = this.faceVertexUvs[ 0 ];
  5884. var uvs2 = this.faceVertexUvs[ 1 ];
  5885. var newUvs1, newUvs2;
  5886. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5887. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5888. for ( var i = 0; i < length; i ++ ) {
  5889. var id = faces[ i ]._id;
  5890. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5891. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5892. }
  5893. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5894. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5895. },
  5896. toJSON: function () {
  5897. var data = {
  5898. metadata: {
  5899. version: 4.4,
  5900. type: 'Geometry',
  5901. generator: 'Geometry.toJSON'
  5902. }
  5903. };
  5904. // standard Geometry serialization
  5905. data.uuid = this.uuid;
  5906. data.type = this.type;
  5907. if ( this.name !== '' ) data.name = this.name;
  5908. if ( this.parameters !== undefined ) {
  5909. var parameters = this.parameters;
  5910. for ( var key in parameters ) {
  5911. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5912. }
  5913. return data;
  5914. }
  5915. var vertices = [];
  5916. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5917. var vertex = this.vertices[ i ];
  5918. vertices.push( vertex.x, vertex.y, vertex.z );
  5919. }
  5920. var faces = [];
  5921. var normals = [];
  5922. var normalsHash = {};
  5923. var colors = [];
  5924. var colorsHash = {};
  5925. var uvs = [];
  5926. var uvsHash = {};
  5927. for ( var i = 0; i < this.faces.length; i ++ ) {
  5928. var face = this.faces[ i ];
  5929. var hasMaterial = false; // face.materialIndex !== undefined;
  5930. var hasFaceUv = false; // deprecated
  5931. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5932. var hasFaceNormal = face.normal.length() > 0;
  5933. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5934. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5935. var hasFaceVertexColor = face.vertexColors.length > 0;
  5936. var faceType = 0;
  5937. faceType = setBit( faceType, 0, 0 );
  5938. faceType = setBit( faceType, 1, hasMaterial );
  5939. faceType = setBit( faceType, 2, hasFaceUv );
  5940. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5941. faceType = setBit( faceType, 4, hasFaceNormal );
  5942. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5943. faceType = setBit( faceType, 6, hasFaceColor );
  5944. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5945. faces.push( faceType );
  5946. faces.push( face.a, face.b, face.c );
  5947. if ( hasFaceVertexUv ) {
  5948. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5949. faces.push(
  5950. getUvIndex( faceVertexUvs[ 0 ] ),
  5951. getUvIndex( faceVertexUvs[ 1 ] ),
  5952. getUvIndex( faceVertexUvs[ 2 ] )
  5953. );
  5954. }
  5955. if ( hasFaceNormal ) {
  5956. faces.push( getNormalIndex( face.normal ) );
  5957. }
  5958. if ( hasFaceVertexNormal ) {
  5959. var vertexNormals = face.vertexNormals;
  5960. faces.push(
  5961. getNormalIndex( vertexNormals[ 0 ] ),
  5962. getNormalIndex( vertexNormals[ 1 ] ),
  5963. getNormalIndex( vertexNormals[ 2 ] )
  5964. );
  5965. }
  5966. if ( hasFaceColor ) {
  5967. faces.push( getColorIndex( face.color ) );
  5968. }
  5969. if ( hasFaceVertexColor ) {
  5970. var vertexColors = face.vertexColors;
  5971. faces.push(
  5972. getColorIndex( vertexColors[ 0 ] ),
  5973. getColorIndex( vertexColors[ 1 ] ),
  5974. getColorIndex( vertexColors[ 2 ] )
  5975. );
  5976. }
  5977. }
  5978. function setBit( value, position, enabled ) {
  5979. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5980. }
  5981. function getNormalIndex( normal ) {
  5982. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5983. if ( normalsHash[ hash ] !== undefined ) {
  5984. return normalsHash[ hash ];
  5985. }
  5986. normalsHash[ hash ] = normals.length / 3;
  5987. normals.push( normal.x, normal.y, normal.z );
  5988. return normalsHash[ hash ];
  5989. }
  5990. function getColorIndex( color ) {
  5991. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5992. if ( colorsHash[ hash ] !== undefined ) {
  5993. return colorsHash[ hash ];
  5994. }
  5995. colorsHash[ hash ] = colors.length;
  5996. colors.push( color.getHex() );
  5997. return colorsHash[ hash ];
  5998. }
  5999. function getUvIndex( uv ) {
  6000. var hash = uv.x.toString() + uv.y.toString();
  6001. if ( uvsHash[ hash ] !== undefined ) {
  6002. return uvsHash[ hash ];
  6003. }
  6004. uvsHash[ hash ] = uvs.length / 2;
  6005. uvs.push( uv.x, uv.y );
  6006. return uvsHash[ hash ];
  6007. }
  6008. data.data = {};
  6009. data.data.vertices = vertices;
  6010. data.data.normals = normals;
  6011. if ( colors.length > 0 ) data.data.colors = colors;
  6012. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6013. data.data.faces = faces;
  6014. return data;
  6015. },
  6016. clone: function () {
  6017. return new this.constructor().copy( this );
  6018. },
  6019. copy: function ( source ) {
  6020. this.vertices = [];
  6021. this.faces = [];
  6022. this.faceVertexUvs = [ [] ];
  6023. var vertices = source.vertices;
  6024. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6025. this.vertices.push( vertices[ i ].clone() );
  6026. }
  6027. var faces = source.faces;
  6028. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6029. this.faces.push( faces[ i ].clone() );
  6030. }
  6031. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6032. var faceVertexUvs = source.faceVertexUvs[ i ];
  6033. if ( this.faceVertexUvs[ i ] === undefined ) {
  6034. this.faceVertexUvs[ i ] = [];
  6035. }
  6036. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6037. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6038. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6039. var uv = uvs[ k ];
  6040. uvsCopy.push( uv.clone() );
  6041. }
  6042. this.faceVertexUvs[ i ].push( uvsCopy );
  6043. }
  6044. }
  6045. return this;
  6046. },
  6047. dispose: function () {
  6048. this.dispatchEvent( { type: 'dispose' } );
  6049. }
  6050. };
  6051. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6052. THREE.GeometryIdCount = 0;
  6053. // File:src/core/DirectGeometry.js
  6054. /**
  6055. * @author mrdoob / http://mrdoob.com/
  6056. */
  6057. THREE.DirectGeometry = function () {
  6058. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6059. this.uuid = THREE.Math.generateUUID();
  6060. this.name = '';
  6061. this.type = 'DirectGeometry';
  6062. this.indices = [];
  6063. this.vertices = [];
  6064. this.normals = [];
  6065. this.colors = [];
  6066. this.uvs = [];
  6067. this.uvs2 = [];
  6068. this.groups = [];
  6069. this.morphTargets = {};
  6070. this.skinWeights = [];
  6071. this.skinIndices = [];
  6072. // this.lineDistances = [];
  6073. this.boundingBox = null;
  6074. this.boundingSphere = null;
  6075. // update flags
  6076. this.verticesNeedUpdate = false;
  6077. this.normalsNeedUpdate = false;
  6078. this.colorsNeedUpdate = false;
  6079. this.uvsNeedUpdate = false;
  6080. this.groupsNeedUpdate = false;
  6081. };
  6082. THREE.DirectGeometry.prototype = {
  6083. constructor: THREE.DirectGeometry,
  6084. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6085. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6086. computeFaceNormals: function () {
  6087. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6088. },
  6089. computeVertexNormals: function () {
  6090. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6091. },
  6092. computeGroups: function ( geometry ) {
  6093. var group;
  6094. var groups = [];
  6095. var materialIndex;
  6096. var faces = geometry.faces;
  6097. for ( var i = 0; i < faces.length; i ++ ) {
  6098. var face = faces[ i ];
  6099. // materials
  6100. if ( face.materialIndex !== materialIndex ) {
  6101. materialIndex = face.materialIndex;
  6102. if ( group !== undefined ) {
  6103. group.count = ( i * 3 ) - group.start;
  6104. groups.push( group );
  6105. }
  6106. group = {
  6107. start: i * 3,
  6108. materialIndex: materialIndex
  6109. };
  6110. }
  6111. }
  6112. if ( group !== undefined ) {
  6113. group.count = ( i * 3 ) - group.start;
  6114. groups.push( group );
  6115. }
  6116. this.groups = groups;
  6117. },
  6118. fromGeometry: function ( geometry ) {
  6119. var faces = geometry.faces;
  6120. var vertices = geometry.vertices;
  6121. var faceVertexUvs = geometry.faceVertexUvs;
  6122. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6123. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6124. // morphs
  6125. var morphTargets = geometry.morphTargets;
  6126. var morphTargetsLength = morphTargets.length;
  6127. if ( morphTargetsLength > 0 ) {
  6128. var morphTargetsPosition = [];
  6129. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6130. morphTargetsPosition[ i ] = [];
  6131. }
  6132. this.morphTargets.position = morphTargetsPosition;
  6133. }
  6134. var morphNormals = geometry.morphNormals;
  6135. var morphNormalsLength = morphNormals.length;
  6136. if ( morphNormalsLength > 0 ) {
  6137. var morphTargetsNormal = [];
  6138. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6139. morphTargetsNormal[ i ] = [];
  6140. }
  6141. this.morphTargets.normal = morphTargetsNormal;
  6142. }
  6143. // skins
  6144. var skinIndices = geometry.skinIndices;
  6145. var skinWeights = geometry.skinWeights;
  6146. var hasSkinIndices = skinIndices.length === vertices.length;
  6147. var hasSkinWeights = skinWeights.length === vertices.length;
  6148. //
  6149. for ( var i = 0; i < faces.length; i ++ ) {
  6150. var face = faces[ i ];
  6151. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6152. var vertexNormals = face.vertexNormals;
  6153. if ( vertexNormals.length === 3 ) {
  6154. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6155. } else {
  6156. var normal = face.normal;
  6157. this.normals.push( normal, normal, normal );
  6158. }
  6159. var vertexColors = face.vertexColors;
  6160. if ( vertexColors.length === 3 ) {
  6161. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6162. } else {
  6163. var color = face.color;
  6164. this.colors.push( color, color, color );
  6165. }
  6166. if ( hasFaceVertexUv === true ) {
  6167. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6168. if ( vertexUvs !== undefined ) {
  6169. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6170. } else {
  6171. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6172. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6173. }
  6174. }
  6175. if ( hasFaceVertexUv2 === true ) {
  6176. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6177. if ( vertexUvs !== undefined ) {
  6178. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6179. } else {
  6180. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6181. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6182. }
  6183. }
  6184. // morphs
  6185. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6186. var morphTarget = morphTargets[ j ].vertices;
  6187. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6188. }
  6189. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6190. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6191. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6192. }
  6193. // skins
  6194. if ( hasSkinIndices ) {
  6195. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6196. }
  6197. if ( hasSkinWeights ) {
  6198. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6199. }
  6200. }
  6201. this.computeGroups( geometry );
  6202. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6203. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6204. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6205. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6206. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6207. return this;
  6208. },
  6209. dispose: function () {
  6210. this.dispatchEvent( { type: 'dispose' } );
  6211. }
  6212. };
  6213. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6214. // File:src/core/BufferGeometry.js
  6215. /**
  6216. * @author alteredq / http://alteredqualia.com/
  6217. * @author mrdoob / http://mrdoob.com/
  6218. */
  6219. THREE.BufferGeometry = function () {
  6220. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6221. this.uuid = THREE.Math.generateUUID();
  6222. this.name = '';
  6223. this.type = 'BufferGeometry';
  6224. this.index = null;
  6225. this.attributes = {};
  6226. this.morphAttributes = {};
  6227. this.groups = [];
  6228. this.boundingBox = null;
  6229. this.boundingSphere = null;
  6230. this.drawRange = { start: 0, count: Infinity };
  6231. };
  6232. THREE.BufferGeometry.prototype = {
  6233. constructor: THREE.BufferGeometry,
  6234. addIndex: function ( index ) {
  6235. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  6236. this.setIndex( index );
  6237. },
  6238. getIndex: function () {
  6239. return this.index;
  6240. },
  6241. setIndex: function ( index ) {
  6242. this.index = index;
  6243. },
  6244. addAttribute: function ( name, attribute ) {
  6245. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6246. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6247. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6248. return;
  6249. }
  6250. if ( name === 'index' ) {
  6251. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6252. this.setIndex( attribute );
  6253. return;
  6254. }
  6255. this.attributes[ name ] = attribute;
  6256. },
  6257. getAttribute: function ( name ) {
  6258. return this.attributes[ name ];
  6259. },
  6260. removeAttribute: function ( name ) {
  6261. delete this.attributes[ name ];
  6262. },
  6263. get drawcalls() {
  6264. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  6265. return this.groups;
  6266. },
  6267. get offsets() {
  6268. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  6269. return this.groups;
  6270. },
  6271. addDrawCall: function ( start, count, indexOffset ) {
  6272. if ( indexOffset !== undefined ) {
  6273. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  6274. }
  6275. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  6276. this.addGroup( start, count );
  6277. },
  6278. clearDrawCalls: function () {
  6279. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  6280. this.clearGroups();
  6281. },
  6282. addGroup: function ( start, count, materialIndex ) {
  6283. this.groups.push( {
  6284. start: start,
  6285. count: count,
  6286. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6287. } );
  6288. },
  6289. clearGroups: function () {
  6290. this.groups = [];
  6291. },
  6292. setDrawRange: function ( start, count ) {
  6293. this.drawRange.start = start;
  6294. this.drawRange.count = count;
  6295. },
  6296. applyMatrix: function ( matrix ) {
  6297. var position = this.attributes.position;
  6298. if ( position !== undefined ) {
  6299. matrix.applyToVector3Array( position.array );
  6300. position.needsUpdate = true;
  6301. }
  6302. var normal = this.attributes.normal;
  6303. if ( normal !== undefined ) {
  6304. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6305. normalMatrix.applyToVector3Array( normal.array );
  6306. normal.needsUpdate = true;
  6307. }
  6308. if ( this.boundingBox !== null ) {
  6309. this.computeBoundingBox();
  6310. }
  6311. if ( this.boundingSphere !== null ) {
  6312. this.computeBoundingSphere();
  6313. }
  6314. },
  6315. rotateX: function () {
  6316. // rotate geometry around world x-axis
  6317. var m1;
  6318. return function rotateX( angle ) {
  6319. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6320. m1.makeRotationX( angle );
  6321. this.applyMatrix( m1 );
  6322. return this;
  6323. };
  6324. }(),
  6325. rotateY: function () {
  6326. // rotate geometry around world y-axis
  6327. var m1;
  6328. return function rotateY( angle ) {
  6329. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6330. m1.makeRotationY( angle );
  6331. this.applyMatrix( m1 );
  6332. return this;
  6333. };
  6334. }(),
  6335. rotateZ: function () {
  6336. // rotate geometry around world z-axis
  6337. var m1;
  6338. return function rotateZ( angle ) {
  6339. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6340. m1.makeRotationZ( angle );
  6341. this.applyMatrix( m1 );
  6342. return this;
  6343. };
  6344. }(),
  6345. translate: function () {
  6346. // translate geometry
  6347. var m1;
  6348. return function translate( x, y, z ) {
  6349. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6350. m1.makeTranslation( x, y, z );
  6351. this.applyMatrix( m1 );
  6352. return this;
  6353. };
  6354. }(),
  6355. scale: function () {
  6356. // scale geometry
  6357. var m1;
  6358. return function scale( x, y, z ) {
  6359. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6360. m1.makeScale( x, y, z );
  6361. this.applyMatrix( m1 );
  6362. return this;
  6363. };
  6364. }(),
  6365. lookAt: function () {
  6366. var obj;
  6367. return function lookAt( vector ) {
  6368. if ( obj === undefined ) obj = new THREE.Object3D();
  6369. obj.lookAt( vector );
  6370. obj.updateMatrix();
  6371. this.applyMatrix( obj.matrix );
  6372. };
  6373. }(),
  6374. center: function () {
  6375. this.computeBoundingBox();
  6376. var offset = this.boundingBox.center().negate();
  6377. this.translate( offset.x, offset.y, offset.z );
  6378. return offset;
  6379. },
  6380. setFromObject: function ( object ) {
  6381. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6382. var geometry = object.geometry;
  6383. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6384. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6385. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6386. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6387. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6388. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6389. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6390. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6391. }
  6392. if ( geometry.boundingSphere !== null ) {
  6393. this.boundingSphere = geometry.boundingSphere.clone();
  6394. }
  6395. if ( geometry.boundingBox !== null ) {
  6396. this.boundingBox = geometry.boundingBox.clone();
  6397. }
  6398. } else if ( object instanceof THREE.Mesh ) {
  6399. if ( geometry instanceof THREE.Geometry ) {
  6400. this.fromGeometry( geometry );
  6401. }
  6402. }
  6403. return this;
  6404. },
  6405. updateFromObject: function ( object ) {
  6406. var geometry = object.geometry;
  6407. if ( object instanceof THREE.Mesh ) {
  6408. var direct = geometry.__directGeometry;
  6409. if ( direct === undefined ) {
  6410. return this.fromGeometry( geometry );
  6411. }
  6412. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6413. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6414. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6415. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6416. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6417. geometry.verticesNeedUpdate = false;
  6418. geometry.normalsNeedUpdate = false;
  6419. geometry.colorsNeedUpdate = false;
  6420. geometry.uvsNeedUpdate = false;
  6421. geometry.groupsNeedUpdate = false;
  6422. geometry = direct;
  6423. }
  6424. if ( geometry.verticesNeedUpdate === true ) {
  6425. var attribute = this.attributes.position;
  6426. if ( attribute !== undefined ) {
  6427. attribute.copyVector3sArray( geometry.vertices );
  6428. attribute.needsUpdate = true;
  6429. }
  6430. geometry.verticesNeedUpdate = false;
  6431. }
  6432. if ( geometry.normalsNeedUpdate === true ) {
  6433. var attribute = this.attributes.normal;
  6434. if ( attribute !== undefined ) {
  6435. attribute.copyVector3sArray( geometry.normals );
  6436. attribute.needsUpdate = true;
  6437. }
  6438. geometry.normalsNeedUpdate = false;
  6439. }
  6440. if ( geometry.colorsNeedUpdate === true ) {
  6441. var attribute = this.attributes.color;
  6442. if ( attribute !== undefined ) {
  6443. attribute.copyColorsArray( geometry.colors );
  6444. attribute.needsUpdate = true;
  6445. }
  6446. geometry.colorsNeedUpdate = false;
  6447. }
  6448. if ( geometry.uvsNeedUpdate ) {
  6449. var attribute = this.attributes.uv;
  6450. if ( attribute !== undefined ) {
  6451. attribute.copyVector2sArray( geometry.uvs );
  6452. attribute.needsUpdate = true;
  6453. }
  6454. geometry.uvsNeedUpdate = false;
  6455. }
  6456. if ( geometry.lineDistancesNeedUpdate ) {
  6457. var attribute = this.attributes.lineDistance;
  6458. if ( attribute !== undefined ) {
  6459. attribute.copyArray( geometry.lineDistances );
  6460. attribute.needsUpdate = true;
  6461. }
  6462. geometry.lineDistancesNeedUpdate = false;
  6463. }
  6464. if ( geometry.groupsNeedUpdate ) {
  6465. geometry.computeGroups( object.geometry );
  6466. this.groups = geometry.groups;
  6467. geometry.groupsNeedUpdate = false;
  6468. }
  6469. return this;
  6470. },
  6471. fromGeometry: function ( geometry ) {
  6472. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6473. return this.fromDirectGeometry( geometry.__directGeometry );
  6474. },
  6475. fromDirectGeometry: function ( geometry ) {
  6476. var positions = new Float32Array( geometry.vertices.length * 3 );
  6477. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6478. if ( geometry.normals.length > 0 ) {
  6479. var normals = new Float32Array( geometry.normals.length * 3 );
  6480. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6481. }
  6482. if ( geometry.colors.length > 0 ) {
  6483. var colors = new Float32Array( geometry.colors.length * 3 );
  6484. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6485. }
  6486. if ( geometry.uvs.length > 0 ) {
  6487. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6488. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6489. }
  6490. if ( geometry.uvs2.length > 0 ) {
  6491. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6492. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6493. }
  6494. if ( geometry.indices.length > 0 ) {
  6495. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6496. var indices = new TypeArray( geometry.indices.length * 3 );
  6497. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6498. }
  6499. // groups
  6500. this.groups = geometry.groups;
  6501. // morphs
  6502. for ( var name in geometry.morphTargets ) {
  6503. var array = [];
  6504. var morphTargets = geometry.morphTargets[ name ];
  6505. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6506. var morphTarget = morphTargets[ i ];
  6507. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6508. array.push( attribute.copyVector3sArray( morphTarget ) );
  6509. }
  6510. this.morphAttributes[ name ] = array;
  6511. }
  6512. // skinning
  6513. if ( geometry.skinIndices.length > 0 ) {
  6514. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6515. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6516. }
  6517. if ( geometry.skinWeights.length > 0 ) {
  6518. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6519. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6520. }
  6521. //
  6522. if ( geometry.boundingSphere !== null ) {
  6523. this.boundingSphere = geometry.boundingSphere.clone();
  6524. }
  6525. if ( geometry.boundingBox !== null ) {
  6526. this.boundingBox = geometry.boundingBox.clone();
  6527. }
  6528. return this;
  6529. },
  6530. computeBoundingBox: function () {
  6531. var vector = new THREE.Vector3();
  6532. return function () {
  6533. if ( this.boundingBox === null ) {
  6534. this.boundingBox = new THREE.Box3();
  6535. }
  6536. var positions = this.attributes.position.array;
  6537. if ( positions ) {
  6538. var bb = this.boundingBox;
  6539. bb.makeEmpty();
  6540. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6541. vector.fromArray( positions, i );
  6542. bb.expandByPoint( vector );
  6543. }
  6544. }
  6545. if ( positions === undefined || positions.length === 0 ) {
  6546. this.boundingBox.min.set( 0, 0, 0 );
  6547. this.boundingBox.max.set( 0, 0, 0 );
  6548. }
  6549. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6550. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6551. }
  6552. };
  6553. }(),
  6554. computeBoundingSphere: function () {
  6555. var box = new THREE.Box3();
  6556. var vector = new THREE.Vector3();
  6557. return function () {
  6558. if ( this.boundingSphere === null ) {
  6559. this.boundingSphere = new THREE.Sphere();
  6560. }
  6561. var positions = this.attributes.position.array;
  6562. if ( positions ) {
  6563. box.makeEmpty();
  6564. var center = this.boundingSphere.center;
  6565. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6566. vector.fromArray( positions, i );
  6567. box.expandByPoint( vector );
  6568. }
  6569. box.center( center );
  6570. // hoping to find a boundingSphere with a radius smaller than the
  6571. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6572. var maxRadiusSq = 0;
  6573. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6574. vector.fromArray( positions, i );
  6575. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6576. }
  6577. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6578. if ( isNaN( this.boundingSphere.radius ) ) {
  6579. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6580. }
  6581. }
  6582. };
  6583. }(),
  6584. computeFaceNormals: function () {
  6585. // backwards compatibility
  6586. },
  6587. computeVertexNormals: function () {
  6588. var index = this.index;
  6589. var attributes = this.attributes;
  6590. var groups = this.groups;
  6591. if ( attributes.position ) {
  6592. var positions = attributes.position.array;
  6593. if ( attributes.normal === undefined ) {
  6594. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6595. } else {
  6596. // reset existing normals to zero
  6597. var normals = attributes.normal.array;
  6598. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6599. normals[ i ] = 0;
  6600. }
  6601. }
  6602. var normals = attributes.normal.array;
  6603. var vA, vB, vC,
  6604. pA = new THREE.Vector3(),
  6605. pB = new THREE.Vector3(),
  6606. pC = new THREE.Vector3(),
  6607. cb = new THREE.Vector3(),
  6608. ab = new THREE.Vector3();
  6609. // indexed elements
  6610. if ( index ) {
  6611. var indices = index.array;
  6612. if ( groups.length === 0 ) {
  6613. this.addGroup( 0, indices.length );
  6614. }
  6615. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6616. var group = groups[ j ];
  6617. var start = group.start;
  6618. var count = group.count;
  6619. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6620. vA = indices[ i + 0 ] * 3;
  6621. vB = indices[ i + 1 ] * 3;
  6622. vC = indices[ i + 2 ] * 3;
  6623. pA.fromArray( positions, vA );
  6624. pB.fromArray( positions, vB );
  6625. pC.fromArray( positions, vC );
  6626. cb.subVectors( pC, pB );
  6627. ab.subVectors( pA, pB );
  6628. cb.cross( ab );
  6629. normals[ vA ] += cb.x;
  6630. normals[ vA + 1 ] += cb.y;
  6631. normals[ vA + 2 ] += cb.z;
  6632. normals[ vB ] += cb.x;
  6633. normals[ vB + 1 ] += cb.y;
  6634. normals[ vB + 2 ] += cb.z;
  6635. normals[ vC ] += cb.x;
  6636. normals[ vC + 1 ] += cb.y;
  6637. normals[ vC + 2 ] += cb.z;
  6638. }
  6639. }
  6640. } else {
  6641. // non-indexed elements (unconnected triangle soup)
  6642. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6643. pA.fromArray( positions, i );
  6644. pB.fromArray( positions, i + 3 );
  6645. pC.fromArray( positions, i + 6 );
  6646. cb.subVectors( pC, pB );
  6647. ab.subVectors( pA, pB );
  6648. cb.cross( ab );
  6649. normals[ i ] = cb.x;
  6650. normals[ i + 1 ] = cb.y;
  6651. normals[ i + 2 ] = cb.z;
  6652. normals[ i + 3 ] = cb.x;
  6653. normals[ i + 4 ] = cb.y;
  6654. normals[ i + 5 ] = cb.z;
  6655. normals[ i + 6 ] = cb.x;
  6656. normals[ i + 7 ] = cb.y;
  6657. normals[ i + 8 ] = cb.z;
  6658. }
  6659. }
  6660. this.normalizeNormals();
  6661. attributes.normal.needsUpdate = true;
  6662. }
  6663. },
  6664. computeTangents: function () {
  6665. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  6666. },
  6667. computeOffsets: function ( size ) {
  6668. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.')
  6669. },
  6670. merge: function ( geometry, offset ) {
  6671. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6672. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6673. return;
  6674. }
  6675. if ( offset === undefined ) offset = 0;
  6676. var attributes = this.attributes;
  6677. for ( var key in attributes ) {
  6678. if ( geometry.attributes[ key ] === undefined ) continue;
  6679. var attribute1 = attributes[ key ];
  6680. var attributeArray1 = attribute1.array;
  6681. var attribute2 = geometry.attributes[ key ];
  6682. var attributeArray2 = attribute2.array;
  6683. var attributeSize = attribute2.itemSize;
  6684. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6685. attributeArray1[ j ] = attributeArray2[ i ];
  6686. }
  6687. }
  6688. return this;
  6689. },
  6690. normalizeNormals: function () {
  6691. var normals = this.attributes.normal.array;
  6692. var x, y, z, n;
  6693. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6694. x = normals[ i ];
  6695. y = normals[ i + 1 ];
  6696. z = normals[ i + 2 ];
  6697. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6698. normals[ i ] *= n;
  6699. normals[ i + 1 ] *= n;
  6700. normals[ i + 2 ] *= n;
  6701. }
  6702. },
  6703. toJSON: function () {
  6704. var data = {
  6705. metadata: {
  6706. version: 4.4,
  6707. type: 'BufferGeometry',
  6708. generator: 'BufferGeometry.toJSON'
  6709. }
  6710. };
  6711. // standard BufferGeometry serialization
  6712. data.uuid = this.uuid;
  6713. data.type = this.type;
  6714. if ( this.name !== '' ) data.name = this.name;
  6715. if ( this.parameters !== undefined ) {
  6716. var parameters = this.parameters;
  6717. for ( var key in parameters ) {
  6718. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6719. }
  6720. return data;
  6721. }
  6722. data.data = { attributes: {} };
  6723. var index = this.index;
  6724. if ( index !== null ) {
  6725. var array = Array.prototype.slice.call( index.array );
  6726. data.data.index = {
  6727. type: index.array.constructor.name,
  6728. array: array
  6729. };
  6730. }
  6731. var attributes = this.attributes;
  6732. for ( var key in attributes ) {
  6733. var attribute = attributes[ key ];
  6734. var array = Array.prototype.slice.call( attribute.array );
  6735. data.data.attributes[ key ] = {
  6736. itemSize: attribute.itemSize,
  6737. type: attribute.array.constructor.name,
  6738. array: array
  6739. };
  6740. }
  6741. var groups = this.groups;
  6742. if ( groups.length > 0 ) {
  6743. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6744. }
  6745. var boundingSphere = this.boundingSphere;
  6746. if ( boundingSphere !== null ) {
  6747. data.data.boundingSphere = {
  6748. center: boundingSphere.center.toArray(),
  6749. radius: boundingSphere.radius
  6750. };
  6751. }
  6752. return data;
  6753. },
  6754. clone: function () {
  6755. return new this.constructor().copy( this );
  6756. },
  6757. copy: function ( source ) {
  6758. var index = source.index;
  6759. if ( index !== null ) {
  6760. this.setIndex( index.clone() );
  6761. }
  6762. var attributes = source.attributes;
  6763. for ( var name in attributes ) {
  6764. var attribute = attributes[ name ];
  6765. this.addAttribute( name, attribute.clone() );
  6766. }
  6767. var groups = source.groups;
  6768. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6769. var group = groups[ i ];
  6770. this.addGroup( group.start, group.count );
  6771. }
  6772. return this;
  6773. },
  6774. dispose: function () {
  6775. this.dispatchEvent( { type: 'dispose' } );
  6776. }
  6777. };
  6778. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6779. THREE.BufferGeometry.MaxIndex = 65535;
  6780. // File:src/core/InstancedBufferGeometry.js
  6781. /**
  6782. * @author benaadams / https://twitter.com/ben_a_adams
  6783. */
  6784. THREE.InstancedBufferGeometry = function () {
  6785. THREE.BufferGeometry.call( this );
  6786. this.type = 'InstancedBufferGeometry';
  6787. this.maxInstancedCount = undefined;
  6788. };
  6789. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6790. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6791. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  6792. this.groups.push( {
  6793. start: start,
  6794. count: count,
  6795. instances: instances
  6796. } );
  6797. };
  6798. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  6799. var index = source.index;
  6800. if ( index !== null ) {
  6801. this.setIndex( index.clone() );
  6802. }
  6803. var attributes = source.attributes;
  6804. for ( var name in attributes ) {
  6805. var attribute = attributes[ name ];
  6806. this.addAttribute( name, attribute.clone() );
  6807. }
  6808. var groups = source.groups;
  6809. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6810. var group = groups[ i ];
  6811. this.addGroup( group.start, group.count, group.instances );
  6812. }
  6813. return this;
  6814. };
  6815. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6816. // File:src/animation/AnimationAction.js
  6817. /**
  6818. *
  6819. * A clip that has been explicitly scheduled.
  6820. *
  6821. * @author Ben Houston / http://clara.io/
  6822. * @author David Sarno / http://lighthaus.us/
  6823. */
  6824. THREE.AnimationAction = function ( clip, startTime, timeScale, weight, loop ) {
  6825. if ( clip === undefined ) throw new Error( 'clip is null' );
  6826. this.clip = clip;
  6827. this.localRoot = null;
  6828. this.startTime = startTime || 0;
  6829. this.timeScale = timeScale || 1;
  6830. this.weight = weight || 1;
  6831. this.loop = loop || THREE.LoopRepeat;
  6832. this.loopCount = 0;
  6833. this.enabled = true; // allow for easy disabling of the action.
  6834. this.actionTime = - this.startTime;
  6835. this.clipTime = 0;
  6836. this.propertyBindings = [];
  6837. };
  6838. /*
  6839. THREE.LoopOnce = 2200;
  6840. THREE.LoopRepeat = 2201;
  6841. THREE.LoopPingPing = 2202;
  6842. */
  6843. THREE.AnimationAction.prototype = {
  6844. constructor: THREE.AnimationAction,
  6845. setLocalRoot: function( localRoot ) {
  6846. this.localRoot = localRoot;
  6847. return this;
  6848. },
  6849. updateTime: function( clipDeltaTime ) {
  6850. var previousClipTime = this.clipTime;
  6851. var previousLoopCount = this.loopCount;
  6852. var previousActionTime = this.actionTime;
  6853. var duration = this.clip.duration;
  6854. this.actionTime = this.actionTime + clipDeltaTime;
  6855. if ( this.loop === THREE.LoopOnce ) {
  6856. this.loopCount = 0;
  6857. this.clipTime = Math.min( Math.max( this.actionTime, 0 ), duration );
  6858. // if time is changed since last time, see if we have hit a start/end limit
  6859. if ( this.clipTime !== previousClipTime ) {
  6860. if ( this.clipTime === duration ) {
  6861. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: 1 } );
  6862. } else if ( this.clipTime === 0 ) {
  6863. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: -1 } );
  6864. }
  6865. }
  6866. return this.clipTime;
  6867. }
  6868. this.loopCount = Math.floor( this.actionTime / duration );
  6869. var newClipTime = this.actionTime - this.loopCount * duration;
  6870. newClipTime = newClipTime % duration;
  6871. // if we are ping pong looping, ensure that we go backwards when appropriate
  6872. if ( this.loop == THREE.LoopPingPong ) {
  6873. if ( Math.abs( this.loopCount % 2 ) === 1 ) {
  6874. newClipTime = duration - newClipTime;
  6875. }
  6876. }
  6877. this.clipTime = newClipTime;
  6878. if ( this.loopCount !== previousLoopCount ) {
  6879. this.mixer.dispatchEvent( { type: 'loop', action: this, loopDelta: ( this.loopCount - this.loopCount ) } );
  6880. }
  6881. return this.clipTime;
  6882. },
  6883. syncWith: function( action ) {
  6884. this.actionTime = action.actionTime;
  6885. this.timeScale = action.timeScale;
  6886. return this;
  6887. },
  6888. warpToDuration: function( duration ) {
  6889. this.timeScale = this.clip.duration / duration;
  6890. return this;
  6891. },
  6892. init: function( time ) {
  6893. this.clipTime = time - this.startTime;
  6894. return this;
  6895. },
  6896. update: function( clipDeltaTime ) {
  6897. this.updateTime( clipDeltaTime );
  6898. var clipResults = this.clip.getAt( this.clipTime );
  6899. return clipResults;
  6900. },
  6901. getTimeScaleAt: function( time ) {
  6902. if ( this.timeScale.getAt ) {
  6903. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6904. return this.timeScale.getAt( time );
  6905. }
  6906. return this.timeScale;
  6907. },
  6908. getWeightAt: function( time ) {
  6909. if ( this.weight.getAt ) {
  6910. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6911. return this.weight.getAt( time );
  6912. }
  6913. return this.weight;
  6914. }
  6915. };
  6916. // File:src/animation/AnimationClip.js
  6917. /**
  6918. *
  6919. * Reusable set of Tracks that represent an animation.
  6920. *
  6921. * @author Ben Houston / http://clara.io/
  6922. * @author David Sarno / http://lighthaus.us/
  6923. */
  6924. THREE.AnimationClip = function ( name, duration, tracks ) {
  6925. this.name = name;
  6926. this.tracks = tracks;
  6927. this.duration = ( duration !== undefined ) ? duration : -1;
  6928. // this means it should figure out its duration by scanning the tracks
  6929. if ( this.duration < 0 ) {
  6930. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6931. var track = this.tracks[i];
  6932. this.duration = Math.max( track.keys[ track.keys.length - 1 ].time );
  6933. }
  6934. }
  6935. // maybe only do these on demand, as doing them here could potentially slow down loading
  6936. // but leaving these here during development as this ensures a lot of testing of these functions
  6937. this.trim();
  6938. this.optimize();
  6939. this.results = [];
  6940. };
  6941. THREE.AnimationClip.prototype = {
  6942. constructor: THREE.AnimationClip,
  6943. getAt: function( clipTime ) {
  6944. clipTime = Math.max( 0, Math.min( clipTime, this.duration ) );
  6945. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6946. var track = this.tracks[ i ];
  6947. this.results[ i ] = track.getAt( clipTime );
  6948. }
  6949. return this.results;
  6950. },
  6951. trim: function() {
  6952. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6953. this.tracks[ i ].trim( 0, this.duration );
  6954. }
  6955. return this;
  6956. },
  6957. optimize: function() {
  6958. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6959. this.tracks[ i ].optimize();
  6960. }
  6961. return this;
  6962. }
  6963. };
  6964. THREE.AnimationClip.CreateFromMorphTargetSequence = function( name, morphTargetSequence, fps ) {
  6965. var numMorphTargets = morphTargetSequence.length;
  6966. var tracks = [];
  6967. for ( var i = 0; i < numMorphTargets; i ++ ) {
  6968. var keys = [];
  6969. keys.push( { time: ( i + numMorphTargets - 1 ) % numMorphTargets, value: 0 } );
  6970. keys.push( { time: i, value: 1 } );
  6971. keys.push( { time: ( i + 1 ) % numMorphTargets, value: 0 } );
  6972. keys.sort( THREE.KeyframeTrack.keyComparer );
  6973. // if there is a key at the first frame, duplicate it as the last frame as well for perfect loop.
  6974. if ( keys[0].time === 0 ) {
  6975. keys.push( {
  6976. time: numMorphTargets,
  6977. value: keys[0].value
  6978. });
  6979. }
  6980. tracks.push( new THREE.NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetSequence[i].name + ']', keys ).scale( 1.0 / fps ) );
  6981. }
  6982. return new THREE.AnimationClip( name, -1, tracks );
  6983. };
  6984. THREE.AnimationClip.findByName = function( clipArray, name ) {
  6985. for ( var i = 0; i < clipArray.length; i ++ ) {
  6986. if ( clipArray[i].name === name ) {
  6987. return clipArray[i];
  6988. }
  6989. }
  6990. return null;
  6991. };
  6992. THREE.AnimationClip.CreateClipsFromMorphTargetSequences = function( morphTargets, fps ) {
  6993. var animationToMorphTargets = {};
  6994. // tested with https://regex101.com/ on trick sequences such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  6995. var pattern = /^([\w-]*?)([\d]+)$/;
  6996. // sort morph target names into animation groups based patterns like Walk_001, Walk_002, Run_001, Run_002
  6997. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  6998. var morphTarget = morphTargets[ i ];
  6999. var parts = morphTarget.name.match( pattern );
  7000. if ( parts && parts.length > 1 ) {
  7001. var name = parts[ 1 ];
  7002. var animationMorphTargets = animationToMorphTargets[ name ];
  7003. if ( ! animationMorphTargets ) {
  7004. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7005. }
  7006. animationMorphTargets.push( morphTarget );
  7007. }
  7008. }
  7009. var clips = [];
  7010. for ( var name in animationToMorphTargets ) {
  7011. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7012. }
  7013. return clips;
  7014. };
  7015. // parse the standard JSON format for clips
  7016. THREE.AnimationClip.parse = function( json ) {
  7017. var tracks = [];
  7018. for ( var i = 0; i < json.tracks.length; i ++ ) {
  7019. tracks.push( THREE.KeyframeTrack.parse( json.tracks[i] ).scale( 1.0 / json.fps ) );
  7020. }
  7021. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7022. };
  7023. // parse the animation.hierarchy format
  7024. THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
  7025. if ( ! animation ) {
  7026. console.error( " no animation in JSONLoader data" );
  7027. return null;
  7028. }
  7029. var convertTrack = function( trackName, animationKeys, propertyName, trackType, animationKeyToValueFunc ) {
  7030. var keys = [];
  7031. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7032. var animationKey = animationKeys[k];
  7033. if ( animationKey[propertyName] !== undefined ) {
  7034. keys.push( { time: animationKey.time, value: animationKeyToValueFunc( animationKey ) } );
  7035. }
  7036. }
  7037. // only return track if there are actually keys.
  7038. if ( keys.length > 0 ) {
  7039. return new trackType( trackName, keys );
  7040. }
  7041. return null;
  7042. };
  7043. var tracks = [];
  7044. var clipName = animation.name || 'default';
  7045. var duration = animation.length || -1; // automatic length determination in AnimationClip.
  7046. var fps = animation.fps || 30;
  7047. var hierarchyTracks = animation.hierarchy || [];
  7048. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7049. var animationKeys = hierarchyTracks[ h ].keys;
  7050. // skip empty tracks
  7051. if ( ! animationKeys || animationKeys.length == 0 ) {
  7052. continue;
  7053. }
  7054. // process morph targets in a way exactly compatible with AnimationHandler.init( animation )
  7055. if ( animationKeys[0].morphTargets ) {
  7056. // figure out all morph targets used in this track
  7057. var morphTargetNames = {};
  7058. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7059. if ( animationKeys[k].morphTargets ) {
  7060. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7061. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7062. }
  7063. }
  7064. }
  7065. // create a track for each morph target with all zero morphTargetInfluences except for the keys in which the morphTarget is named.
  7066. for ( var morphTargetName in morphTargetNames ) {
  7067. var keys = [];
  7068. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7069. var animationKey = animationKeys[k];
  7070. keys.push( {
  7071. time: animationKey.time,
  7072. value: (( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7073. });
  7074. }
  7075. tracks.push( new THREE.NumberKeyframeTrack( nodeName + '.morphTargetInfluence[' + morphTargetName + ']', keys ) );
  7076. }
  7077. duration = morphTargetNames.length * ( fps || 1.0 );
  7078. } else {
  7079. var boneName = nodeName + '.bones[' + bones[ h ].name + ']';
  7080. // track contains positions...
  7081. var positionTrack = convertTrack( boneName + '.position', animationKeys, 'pos', THREE.VectorKeyframeTrack, function( animationKey ) {
  7082. return new THREE.Vector3().fromArray( animationKey.pos )
  7083. } );
  7084. if ( positionTrack ) tracks.push( positionTrack );
  7085. // track contains quaternions...
  7086. var quaternionTrack = convertTrack( boneName + '.quaternion', animationKeys, 'rot', THREE.QuaternionKeyframeTrack, function( animationKey ) {
  7087. if ( animationKey.rot.slerp ) {
  7088. return animationKey.rot.clone();
  7089. } else {
  7090. return new THREE.Quaternion().fromArray( animationKey.rot );
  7091. }
  7092. } );
  7093. if ( quaternionTrack ) tracks.push( quaternionTrack );
  7094. // track contains quaternions...
  7095. var scaleTrack = convertTrack( boneName + '.scale', animationKeys, 'scl', THREE.VectorKeyframeTrack, function( animationKey ) {
  7096. return new THREE.Vector3().fromArray( animationKey.scl )
  7097. } );
  7098. if ( scaleTrack ) tracks.push( scaleTrack );
  7099. }
  7100. }
  7101. if ( tracks.length === 0 ) {
  7102. return null;
  7103. }
  7104. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7105. return clip;
  7106. };
  7107. // File:src/animation/AnimationMixer.js
  7108. /**
  7109. *
  7110. * Mixes together the AnimationClips scheduled by AnimationActions and applies them to the root and subtree
  7111. *
  7112. *
  7113. * @author Ben Houston / http://clara.io/
  7114. * @author David Sarno / http://lighthaus.us/
  7115. */
  7116. THREE.AnimationMixer = function( root ) {
  7117. this.root = root;
  7118. this.time = 0;
  7119. this.timeScale = 1.0;
  7120. this.actions = [];
  7121. this.propertyBindingMap = {};
  7122. };
  7123. THREE.AnimationMixer.prototype = {
  7124. constructor: THREE.AnimationMixer,
  7125. addAction: function( action ) {
  7126. // TODO: check for duplicate action names? Or provide each action with a UUID?
  7127. this.actions.push( action );
  7128. action.init( this.time );
  7129. action.mixer = this;
  7130. var tracks = action.clip.tracks;
  7131. var root = action.localRoot || this.root;
  7132. for ( var i = 0; i < tracks.length; i ++ ) {
  7133. var track = tracks[ i ];
  7134. var propertyBindingKey = root.uuid + '-' + track.name;
  7135. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7136. if ( propertyBinding === undefined ) {
  7137. propertyBinding = new THREE.PropertyBinding( root, track.name );
  7138. this.propertyBindingMap[ propertyBindingKey ] = propertyBinding;
  7139. }
  7140. // push in the same order as the tracks.
  7141. action.propertyBindings.push( propertyBinding );
  7142. // track usages of shared property bindings, because if we leave too many around, the mixer can get slow
  7143. propertyBinding.referenceCount += 1;
  7144. }
  7145. },
  7146. removeAllActions: function() {
  7147. for ( var i = 0; i < this.actions.length; i ++ ) {
  7148. this.actions[i].mixer = null;
  7149. }
  7150. // unbind all property bindings
  7151. for ( var properyBindingKey in this.propertyBindingMap ) {
  7152. this.propertyBindingMap[ properyBindingKey ].unbind();
  7153. }
  7154. this.actions = [];
  7155. this.propertyBindingMap = {};
  7156. return this;
  7157. },
  7158. removeAction: function( action ) {
  7159. var index = this.actions.indexOf( action );
  7160. if ( index !== - 1 ) {
  7161. this.actions.splice( index, 1 );
  7162. action.mixer = null;
  7163. }
  7164. // remove unused property bindings because if we leave them around the mixer can get slow
  7165. var root = action.localRoot || this.root;
  7166. var tracks = action.clip.tracks;
  7167. for ( var i = 0; i < tracks.length; i ++ ) {
  7168. var track = tracks[ i ];
  7169. var propertyBindingKey = root.uuid + '-' + track.name;
  7170. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7171. propertyBinding.referenceCount -= 1;
  7172. if ( propertyBinding.referenceCount <= 0 ) {
  7173. propertyBinding.unbind();
  7174. delete this.propertyBindingMap[ propertyBindingKey ];
  7175. }
  7176. }
  7177. return this;
  7178. },
  7179. // can be optimized if needed
  7180. findActionByName: function( name ) {
  7181. for ( var i = 0; i < this.actions.length; i ++ ) {
  7182. if ( this.actions[i].name === name ) return this.actions[i];
  7183. }
  7184. return null;
  7185. },
  7186. play: function( action, optionalFadeInDuration ) {
  7187. action.startTime = this.time;
  7188. this.addAction( action );
  7189. return this;
  7190. },
  7191. fadeOut: function( action, duration ) {
  7192. var keys = [];
  7193. keys.push( { time: this.time, value: 1 } );
  7194. keys.push( { time: this.time + duration, value: 0 } );
  7195. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7196. return this;
  7197. },
  7198. fadeIn: function( action, duration ) {
  7199. var keys = [];
  7200. keys.push( { time: this.time, value: 0 } );
  7201. keys.push( { time: this.time + duration, value: 1 } );
  7202. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7203. return this;
  7204. },
  7205. warp: function( action, startTimeScale, endTimeScale, duration ) {
  7206. var keys = [];
  7207. keys.push( { time: this.time, value: startTimeScale } );
  7208. keys.push( { time: this.time + duration, value: endTimeScale } );
  7209. action.timeScale = new THREE.NumberKeyframeTrack( "timeScale", keys );
  7210. return this;
  7211. },
  7212. crossFade: function( fadeOutAction, fadeInAction, duration, warp ) {
  7213. this.fadeOut( fadeOutAction, duration );
  7214. this.fadeIn( fadeInAction, duration );
  7215. if ( warp ) {
  7216. var startEndRatio = fadeOutAction.clip.duration / fadeInAction.clip.duration;
  7217. var endStartRatio = 1.0 / startEndRatio;
  7218. this.warp( fadeOutAction, 1.0, startEndRatio, duration );
  7219. this.warp( fadeInAction, endStartRatio, 1.0, duration );
  7220. }
  7221. return this;
  7222. },
  7223. update: function( deltaTime ) {
  7224. var mixerDeltaTime = deltaTime * this.timeScale;
  7225. this.time += mixerDeltaTime;
  7226. for ( var i = 0; i < this.actions.length; i ++ ) {
  7227. var action = this.actions[i];
  7228. var weight = action.getWeightAt( this.time );
  7229. var actionTimeScale = action.getTimeScaleAt( this.time );
  7230. var actionDeltaTime = mixerDeltaTime * actionTimeScale;
  7231. var actionResults = action.update( actionDeltaTime );
  7232. if ( action.weight <= 0 || ! action.enabled ) continue;
  7233. for ( var j = 0; j < actionResults.length; j ++ ) {
  7234. var name = action.clip.tracks[j].name;
  7235. action.propertyBindings[ j ].accumulate( actionResults[j], weight );
  7236. }
  7237. }
  7238. // apply to nodes
  7239. for ( var propertyBindingKey in this.propertyBindingMap ) {
  7240. this.propertyBindingMap[ propertyBindingKey ].apply();
  7241. }
  7242. return this;
  7243. }
  7244. };
  7245. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7246. // File:src/animation/AnimationUtils.js
  7247. /**
  7248. * @author Ben Houston / http://clara.io/
  7249. * @author David Sarno / http://lighthaus.us/
  7250. */
  7251. THREE.AnimationUtils = {
  7252. getEqualsFunc: function( exemplarValue ) {
  7253. if ( exemplarValue.equals ) {
  7254. return function equals_object( a, b ) {
  7255. return a.equals( b );
  7256. }
  7257. }
  7258. return function equals_primitive( a, b ) {
  7259. return ( a === b );
  7260. };
  7261. },
  7262. clone: function( exemplarValue ) {
  7263. var typeName = typeof exemplarValue;
  7264. if ( typeName === "object" ) {
  7265. if ( exemplarValue.clone ) {
  7266. return exemplarValue.clone();
  7267. }
  7268. console.error( "can not figure out how to copy exemplarValue", exemplarValue );
  7269. }
  7270. return exemplarValue;
  7271. },
  7272. lerp: function( a, b, alpha, interTrack ) {
  7273. var lerpFunc = THREE.AnimationUtils.getLerpFunc( a, interTrack );
  7274. return lerpFunc( a, b, alpha );
  7275. },
  7276. lerp_object: function( a, b, alpha ) {
  7277. return a.lerp( b, alpha );
  7278. },
  7279. slerp_object: function( a, b, alpha ) {
  7280. return a.slerp( b, alpha );
  7281. },
  7282. lerp_number: function( a, b, alpha ) {
  7283. return a * ( 1 - alpha ) + b * alpha;
  7284. },
  7285. lerp_boolean: function( a, b, alpha ) {
  7286. return ( alpha < 0.5 ) ? a : b;
  7287. },
  7288. lerp_boolean_immediate: function( a, b, alpha ) {
  7289. return a;
  7290. },
  7291. lerp_string: function( a, b, alpha ) {
  7292. return ( alpha < 0.5 ) ? a : b;
  7293. },
  7294. lerp_string_immediate: function( a, b, alpha ) {
  7295. return a;
  7296. },
  7297. // NOTE: this is an accumulator function that modifies the first argument (e.g. a). This is to minimize memory alocations.
  7298. getLerpFunc: function( exemplarValue, interTrack ) {
  7299. if ( exemplarValue === undefined || exemplarValue === null ) throw new Error( "examplarValue is null" );
  7300. var typeName = typeof exemplarValue;
  7301. switch( typeName ) {
  7302. case "object":
  7303. if ( exemplarValue.lerp ) {
  7304. return THREE.AnimationUtils.lerp_object;
  7305. }
  7306. if ( exemplarValue.slerp ) {
  7307. return THREE.AnimationUtils.slerp_object;
  7308. }
  7309. break;
  7310. case "number":
  7311. return THREE.AnimationUtils.lerp_number;
  7312. case "boolean":
  7313. if ( interTrack ) {
  7314. return THREE.AnimationUtils.lerp_boolean;
  7315. } else {
  7316. return THREE.AnimationUtils.lerp_boolean_immediate;
  7317. }
  7318. case "string":
  7319. if ( interTrack ) {
  7320. return THREE.AnimationUtils.lerp_string;
  7321. } else {
  7322. return THREE.AnimationUtils.lerp_string_immediate;
  7323. }
  7324. }
  7325. }
  7326. };
  7327. // File:src/animation/KeyframeTrack.js
  7328. /**
  7329. *
  7330. * A Track that returns a keyframe interpolated value, currently linearly interpolated
  7331. *
  7332. * @author Ben Houston / http://clara.io/
  7333. * @author David Sarno / http://lighthaus.us/
  7334. */
  7335. THREE.KeyframeTrack = function ( name, keys ) {
  7336. if ( name === undefined ) throw new Error( "track name is undefined" );
  7337. if ( keys === undefined || keys.length === 0 ) throw new Error( "no keys in track named " + name );
  7338. this.name = name;
  7339. this.keys = keys; // time in seconds, value as value
  7340. // the index of the last result, used as a starting point for local search.
  7341. this.lastIndex = 0;
  7342. this.validate();
  7343. this.optimize();
  7344. };
  7345. THREE.KeyframeTrack.prototype = {
  7346. constructor: THREE.KeyframeTrack,
  7347. getAt: function( time ) {
  7348. // this can not go higher than this.keys.length.
  7349. while( ( this.lastIndex < this.keys.length ) && ( time >= this.keys[this.lastIndex].time ) ) {
  7350. this.lastIndex ++;
  7351. };
  7352. // this can not go lower than 0.
  7353. while( ( this.lastIndex > 0 ) && ( time < this.keys[this.lastIndex - 1].time ) ) {
  7354. this.lastIndex --;
  7355. }
  7356. if ( this.lastIndex >= this.keys.length ) {
  7357. this.setResult( this.keys[ this.keys.length - 1 ].value );
  7358. return this.result;
  7359. }
  7360. if ( this.lastIndex === 0 ) {
  7361. this.setResult( this.keys[ 0 ].value );
  7362. return this.result;
  7363. }
  7364. var prevKey = this.keys[ this.lastIndex - 1 ];
  7365. this.setResult( prevKey.value );
  7366. // if true, means that prev/current keys are identical, thus no interpolation required.
  7367. if ( prevKey.constantToNext ) {
  7368. return this.result;
  7369. }
  7370. // linear interpolation to start with
  7371. var currentKey = this.keys[ this.lastIndex ];
  7372. var alpha = ( time - prevKey.time ) / ( currentKey.time - prevKey.time );
  7373. this.result = this.lerpValues( this.result, currentKey.value, alpha );
  7374. return this.result;
  7375. },
  7376. // move all keyframes either forwards or backwards in time
  7377. shift: function( timeOffset ) {
  7378. if ( timeOffset !== 0.0 ) {
  7379. for ( var i = 0; i < this.keys.length; i ++ ) {
  7380. this.keys[i].time += timeOffset;
  7381. }
  7382. }
  7383. return this;
  7384. },
  7385. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  7386. scale: function( timeScale ) {
  7387. if ( timeScale !== 1.0 ) {
  7388. for ( var i = 0; i < this.keys.length; i ++ ) {
  7389. this.keys[i].time *= timeScale;
  7390. }
  7391. }
  7392. return this;
  7393. },
  7394. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  7395. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  7396. trim: function( startTime, endTime ) {
  7397. var firstKeysToRemove = 0;
  7398. for ( var i = 1; i < this.keys.length; i ++ ) {
  7399. if ( this.keys[i] <= startTime ) {
  7400. firstKeysToRemove ++;
  7401. }
  7402. }
  7403. var lastKeysToRemove = 0;
  7404. for ( var i = this.keys.length - 2; i > 0; i ++ ) {
  7405. if ( this.keys[i] >= endTime ) {
  7406. lastKeysToRemove ++;
  7407. } else {
  7408. break;
  7409. }
  7410. }
  7411. // remove last keys first because it doesn't affect the position of the first keys (the otherway around doesn't work as easily)
  7412. if ( ( firstKeysToRemove + lastKeysToRemove ) > 0 ) {
  7413. this.keys = this.keys.splice( firstKeysToRemove, this.keys.length - lastKeysToRemove - firstKeysToRemove );;
  7414. }
  7415. return this;
  7416. },
  7417. /* NOTE: This is commented out because we really shouldn't have to handle unsorted key lists
  7418. Tracks with out of order keys should be considered to be invalid. - bhouston
  7419. sort: function() {
  7420. this.keys.sort( THREE.KeyframeTrack.keyComparer );
  7421. return this;
  7422. },*/
  7423. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  7424. // One could eventually ensure that all key.values in a track are all of the same type (otherwise interpolation makes no sense.)
  7425. validate: function() {
  7426. var prevKey = null;
  7427. if ( this.keys.length === 0 ) {
  7428. console.error( " track is empty, no keys", this );
  7429. return;
  7430. }
  7431. for ( var i = 0; i < this.keys.length; i ++ ) {
  7432. var currKey = this.keys[i];
  7433. if ( ! currKey ) {
  7434. console.error( " key is null in track", this, i );
  7435. return;
  7436. }
  7437. if ( ( typeof currKey.time ) !== 'number' || Number.isNaN( currKey.time ) ) {
  7438. console.error( " key.time is not a valid number", this, i, currKey );
  7439. return;
  7440. }
  7441. if ( currKey.value === undefined || currKey.value === null) {
  7442. console.error( " key.value is null in track", this, i, currKey );
  7443. return;
  7444. }
  7445. if ( prevKey && prevKey.time > currKey.time ) {
  7446. console.error( " key.time is less than previous key time, out of order keys", this, i, currKey, prevKey );
  7447. return;
  7448. }
  7449. prevKey = currKey;
  7450. }
  7451. return this;
  7452. },
  7453. // currently only removes equivalent sequential keys (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0), which are common in morph target animations
  7454. optimize: function() {
  7455. var newKeys = [];
  7456. var prevKey = this.keys[0];
  7457. newKeys.push( prevKey );
  7458. var equalsFunc = THREE.AnimationUtils.getEqualsFunc( prevKey.value );
  7459. for ( var i = 1; i < this.keys.length - 1; i ++ ) {
  7460. var currKey = this.keys[i];
  7461. var nextKey = this.keys[i+1];
  7462. // if prevKey & currKey are the same time, remove currKey. If you want immediate adjacent keys, use an epsilon offset
  7463. // it is not possible to have two keys at the same time as we sort them. The sort is not stable on keys with the same time.
  7464. if ( ( prevKey.time === currKey.time ) ) {
  7465. continue;
  7466. }
  7467. // remove completely unnecessary keyframes that are the same as their prev and next keys
  7468. if ( this.compareValues( prevKey.value, currKey.value ) && this.compareValues( currKey.value, nextKey.value ) ) {
  7469. continue;
  7470. }
  7471. // determine if interpolation is required
  7472. prevKey.constantToNext = this.compareValues( prevKey.value, currKey.value );
  7473. newKeys.push( currKey );
  7474. prevKey = currKey;
  7475. }
  7476. newKeys.push( this.keys[ this.keys.length - 1 ] );
  7477. this.keys = newKeys;
  7478. return this;
  7479. }
  7480. };
  7481. THREE.KeyframeTrack.keyComparer = function keyComparator(key0, key1) {
  7482. return key0.time - key1.time;
  7483. };
  7484. THREE.KeyframeTrack.parse = function( json ) {
  7485. if ( json.type === undefined ) throw new Error( "track type undefined, can not parse" );
  7486. var trackType = THREE.KeyframeTrack.GetTrackTypeForTypeName( json.type );
  7487. return trackType.parse( json );
  7488. };
  7489. THREE.KeyframeTrack.GetTrackTypeForTypeName = function( typeName ) {
  7490. switch( typeName.toLowerCase() ) {
  7491. case "vector":
  7492. case "vector2":
  7493. case "vector3":
  7494. case "vector4":
  7495. return THREE.VectorKeyframeTrack;
  7496. case "quaternion":
  7497. return THREE.QuaternionKeyframeTrack;
  7498. case "integer":
  7499. case "scalar":
  7500. case "double":
  7501. case "float":
  7502. case "number":
  7503. return THREE.NumberKeyframeTrack;
  7504. case "bool":
  7505. case "boolean":
  7506. return THREE.BooleanKeyframeTrack;
  7507. case "string":
  7508. return THREE.StringKeyframeTrack;
  7509. };
  7510. throw new Error( "Unsupported typeName: " + typeName );
  7511. };
  7512. // File:src/animation/PropertyBinding.js
  7513. /**
  7514. *
  7515. * A track bound to a real value in the scene graph.
  7516. *
  7517. * @author Ben Houston / http://clara.io/
  7518. * @author David Sarno / http://lighthaus.us/
  7519. */
  7520. THREE.PropertyBinding = function ( rootNode, trackName ) {
  7521. this.rootNode = rootNode;
  7522. this.trackName = trackName;
  7523. this.referenceCount = 0;
  7524. this.originalValue = null; // the value of the property before it was controlled by this binding
  7525. var parseResults = THREE.PropertyBinding.parseTrackName( trackName );
  7526. this.directoryName = parseResults.directoryName;
  7527. this.nodeName = parseResults.nodeName;
  7528. this.objectName = parseResults.objectName;
  7529. this.objectIndex = parseResults.objectIndex;
  7530. this.propertyName = parseResults.propertyName;
  7531. this.propertyIndex = parseResults.propertyIndex;
  7532. this.node = THREE.PropertyBinding.findNode( rootNode, this.nodeName ) || rootNode;
  7533. this.cumulativeValue = null;
  7534. this.cumulativeWeight = 0;
  7535. };
  7536. THREE.PropertyBinding.prototype = {
  7537. constructor: THREE.PropertyBinding,
  7538. reset: function() {
  7539. this.cumulativeValue = null;
  7540. this.cumulativeWeight = 0;
  7541. },
  7542. accumulate: function( value, weight ) {
  7543. if ( ! this.isBound ) this.bind();
  7544. if ( this.cumulativeWeight === 0 ) {
  7545. if ( weight > 0 ) {
  7546. if ( this.cumulativeValue === null ) {
  7547. this.cumulativeValue = THREE.AnimationUtils.clone( value );
  7548. }
  7549. this.cumulativeWeight = weight;
  7550. }
  7551. } else {
  7552. var lerpAlpha = weight / ( this.cumulativeWeight + weight );
  7553. this.cumulativeValue = this.lerpValue( this.cumulativeValue, value, lerpAlpha );
  7554. this.cumulativeWeight += weight;
  7555. }
  7556. },
  7557. unbind: function() {
  7558. if ( ! this.isBound ) return;
  7559. this.setValue( this.originalValue );
  7560. this.setValue = null;
  7561. this.getValue = null;
  7562. this.lerpValue = null;
  7563. this.equalsValue = null;
  7564. this.triggerDirty = null;
  7565. this.isBound = false;
  7566. },
  7567. // bind to the real property in the scene graph, remember original value, memorize various accessors for speed/inefficiency
  7568. bind: function() {
  7569. if ( this.isBound ) return;
  7570. var targetObject = this.node;
  7571. // ensure there is a value node
  7572. if ( ! targetObject ) {
  7573. console.error( " trying to update node for track: " + this.trackName + " but it wasn't found." );
  7574. return;
  7575. }
  7576. if ( this.objectName ) {
  7577. // special case were we need to reach deeper into the hierarchy to get the face materials....
  7578. if ( this.objectName === "materials" ) {
  7579. if ( ! targetObject.material ) {
  7580. console.error( ' can not bind to material as node does not have a material', this );
  7581. return;
  7582. }
  7583. if ( ! targetObject.material.materials ) {
  7584. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  7585. return;
  7586. }
  7587. targetObject = targetObject.material.materials;
  7588. } else if ( this.objectName === "bones" ) {
  7589. if ( ! targetObject.skeleton ) {
  7590. console.error( ' can not bind to bones as node does not have a skeleton', this );
  7591. return;
  7592. }
  7593. // potential future optimization: skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7594. targetObject = targetObject.skeleton.bones;
  7595. // support resolving morphTarget names into indices.
  7596. for ( var i = 0; i < targetObject.length; i ++ ) {
  7597. if ( targetObject[i].name === this.objectIndex ) {
  7598. this.objectIndex = i;
  7599. break;
  7600. }
  7601. }
  7602. } else {
  7603. if ( targetObject[ this.objectName ] === undefined ) {
  7604. console.error( ' can not bind to objectName of node, undefined', this );
  7605. return;
  7606. }
  7607. targetObject = targetObject[ this.objectName ];
  7608. }
  7609. if ( this.objectIndex !== undefined ) {
  7610. if ( targetObject[ this.objectIndex ] === undefined ) {
  7611. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  7612. return;
  7613. }
  7614. targetObject = targetObject[ this.objectIndex ];
  7615. }
  7616. }
  7617. // special case mappings
  7618. var nodeProperty = targetObject[ this.propertyName ];
  7619. if ( ! nodeProperty ) {
  7620. console.error( " trying to update property for track: " + this.nodeName + '.' + this.propertyName + " but it wasn't found.", targetObject );
  7621. return;
  7622. }
  7623. // access a sub element of the property array (only primitives are supported right now)
  7624. if ( this.propertyIndex !== undefined ) {
  7625. if ( this.propertyName === "morphTargetInfluences" ) {
  7626. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7627. // support resolving morphTarget names into indices.
  7628. if ( ! targetObject.geometry ) {
  7629. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  7630. }
  7631. if ( ! targetObject.geometry.morphTargets ) {
  7632. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  7633. }
  7634. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  7635. if ( targetObject.geometry.morphTargets[i].name === this.propertyIndex ) {
  7636. this.propertyIndex = i;
  7637. break;
  7638. }
  7639. }
  7640. }
  7641. this.setValue = function setValue_propertyIndexed( value ) {
  7642. if ( ! this.equalsValue( nodeProperty[ this.propertyIndex ], value ) ) {
  7643. nodeProperty[ this.propertyIndex ] = value;
  7644. return true;
  7645. }
  7646. return false;
  7647. };
  7648. this.getValue = function getValue_propertyIndexed() {
  7649. return nodeProperty[ this.propertyIndex ];
  7650. };
  7651. }
  7652. // must use copy for Object3D.Euler/Quaternion
  7653. else if ( nodeProperty.copy ) {
  7654. this.setValue = function setValue_propertyObject( value ) {
  7655. if ( ! this.equalsValue( nodeProperty, value ) ) {
  7656. nodeProperty.copy( value );
  7657. return true;
  7658. }
  7659. return false;
  7660. }
  7661. this.getValue = function getValue_propertyObject() {
  7662. return nodeProperty;
  7663. };
  7664. }
  7665. // otherwise just set the property directly on the node (do not use nodeProperty as it may not be a reference object)
  7666. else {
  7667. this.setValue = function setValue_property( value ) {
  7668. if ( ! this.equalsValue( targetObject[ this.propertyName ], value ) ) {
  7669. targetObject[ this.propertyName ] = value;
  7670. return true;
  7671. }
  7672. return false;
  7673. }
  7674. this.getValue = function getValue_property() {
  7675. return targetObject[ this.propertyName ];
  7676. };
  7677. }
  7678. // trigger node dirty
  7679. if ( targetObject.needsUpdate !== undefined ) { // material
  7680. this.triggerDirty = function triggerDirty_needsUpdate() {
  7681. this.node.needsUpdate = true;
  7682. }
  7683. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  7684. this.triggerDirty = function triggerDirty_matrixWorldNeedsUpdate() {
  7685. targetObject.matrixWorldNeedsUpdate = true;
  7686. }
  7687. }
  7688. this.originalValue = this.getValue();
  7689. this.equalsValue = THREE.AnimationUtils.getEqualsFunc( this.originalValue );
  7690. this.lerpValue = THREE.AnimationUtils.getLerpFunc( this.originalValue, true );
  7691. this.isBound = true;
  7692. },
  7693. apply: function() {
  7694. // for speed capture the setter pattern as a closure (sort of a memoization pattern: https://en.wikipedia.org/wiki/Memoization)
  7695. if ( ! this.isBound ) this.bind();
  7696. // early exit if there is nothing to apply.
  7697. if ( this.cumulativeWeight > 0 ) {
  7698. // blend with original value
  7699. if ( this.cumulativeWeight < 1 ) {
  7700. var remainingWeight = 1 - this.cumulativeWeight;
  7701. var lerpAlpha = remainingWeight / ( this.cumulativeWeight + remainingWeight );
  7702. this.cumulativeValue = this.lerpValue( this.cumulativeValue, this.originalValue, lerpAlpha );
  7703. }
  7704. var valueChanged = this.setValue( this.cumulativeValue );
  7705. if ( valueChanged && this.triggerDirty ) {
  7706. this.triggerDirty();
  7707. }
  7708. // reset accumulator
  7709. this.cumulativeValue = null;
  7710. this.cumulativeWeight = 0;
  7711. }
  7712. }
  7713. };
  7714. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  7715. // matches strings in the form of:
  7716. // nodeName.property
  7717. // nodeName.property[accessor]
  7718. // nodeName.material.property[accessor]
  7719. // uuid.property[accessor]
  7720. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  7721. // parentName/nodeName.property
  7722. // parentName/parentName/nodeName.property[index]
  7723. // .bone[Armature.DEF_cog].position
  7724. // created and tested via https://regex101.com/#javascript
  7725. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  7726. var matches = re.exec(trackName);
  7727. if ( ! matches ) {
  7728. throw new Error( "cannot parse trackName at all: " + trackName );
  7729. }
  7730. if (matches.index === re.lastIndex) {
  7731. re.lastIndex++;
  7732. }
  7733. var results = {
  7734. directoryName: matches[1],
  7735. nodeName: matches[3], // allowed to be null, specified root node.
  7736. objectName: matches[5],
  7737. objectIndex: matches[7],
  7738. propertyName: matches[9],
  7739. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  7740. };
  7741. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  7742. throw new Error( "can not parse propertyName from trackName: " + trackName );
  7743. }
  7744. return results;
  7745. };
  7746. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  7747. function searchSkeleton( skeleton ) {
  7748. for ( var i = 0; i < skeleton.bones.length; i ++ ) {
  7749. var bone = skeleton.bones[i];
  7750. if ( bone.name === nodeName ) {
  7751. return bone;
  7752. }
  7753. }
  7754. return null;
  7755. }
  7756. function searchNodeSubtree( children ) {
  7757. for ( var i = 0; i < children.length; i ++ ) {
  7758. var childNode = children[i];
  7759. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  7760. return childNode;
  7761. }
  7762. var result = searchNodeSubtree( childNode.children );
  7763. if ( result ) return result;
  7764. }
  7765. return null;
  7766. }
  7767. //
  7768. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  7769. return root;
  7770. }
  7771. // search into skeleton bones.
  7772. if ( root.skeleton ) {
  7773. var bone = searchSkeleton( root.skeleton );
  7774. if ( bone ) {
  7775. return bone;
  7776. }
  7777. }
  7778. // search into node subtree.
  7779. if ( root.children ) {
  7780. var subTreeNode = searchNodeSubtree( root.children );
  7781. if ( subTreeNode ) {
  7782. return subTreeNode;
  7783. }
  7784. }
  7785. return null;
  7786. }
  7787. // File:src/animation/tracks/VectorKeyframeTrack.js
  7788. /**
  7789. *
  7790. * A Track that interpolates Vectors
  7791. *
  7792. * @author Ben Houston / http://clara.io/
  7793. * @author David Sarno / http://lighthaus.us/
  7794. */
  7795. THREE.VectorKeyframeTrack = function ( name, keys ) {
  7796. THREE.KeyframeTrack.call( this, name, keys );
  7797. // local cache of value type to avoid allocations during runtime.
  7798. this.result = this.keys[0].value.clone();
  7799. };
  7800. THREE.VectorKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7801. THREE.VectorKeyframeTrack.prototype.constructor = THREE.VectorKeyframeTrack;
  7802. THREE.VectorKeyframeTrack.prototype.setResult = function( value ) {
  7803. this.result.copy( value );
  7804. };
  7805. // memoization of the lerp function for speed.
  7806. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7807. THREE.VectorKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7808. return value0.lerp( value1, alpha );
  7809. };
  7810. THREE.VectorKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7811. return value0.equals( value1 );
  7812. };
  7813. THREE.VectorKeyframeTrack.prototype.clone = function() {
  7814. var clonedKeys = [];
  7815. for ( var i = 0; i < this.keys.length; i ++ ) {
  7816. var key = this.keys[i];
  7817. clonedKeys.push( {
  7818. time: key.time,
  7819. value: key.value.clone()
  7820. } );
  7821. }
  7822. return new THREE.VectorKeyframeTrack( this.name, clonedKeys );
  7823. };
  7824. THREE.VectorKeyframeTrack.parse = function( json ) {
  7825. var elementCount = json.keys[0].value.length;
  7826. var valueType = THREE[ 'Vector' + elementCount ];
  7827. var keys = [];
  7828. for ( var i = 0; i < json.keys.length; i ++ ) {
  7829. var jsonKey = json.keys[i];
  7830. keys.push( {
  7831. value: new valueType().fromArray( jsonKey.value ),
  7832. time: jsonKey.time
  7833. } );
  7834. }
  7835. return new THREE.VectorKeyframeTrack( json.name, keys );
  7836. };
  7837. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  7838. /**
  7839. *
  7840. * A Track that interpolates Quaternion
  7841. *
  7842. * @author Ben Houston / http://clara.io/
  7843. * @author David Sarno / http://lighthaus.us/
  7844. */
  7845. THREE.QuaternionKeyframeTrack = function ( name, keys ) {
  7846. THREE.KeyframeTrack.call( this, name, keys );
  7847. // local cache of value type to avoid allocations during runtime.
  7848. this.result = this.keys[0].value.clone();
  7849. };
  7850. THREE.QuaternionKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7851. THREE.QuaternionKeyframeTrack.prototype.constructor = THREE.QuaternionKeyframeTrack;
  7852. THREE.QuaternionKeyframeTrack.prototype.setResult = function( value ) {
  7853. this.result.copy( value );
  7854. };
  7855. // memoization of the lerp function for speed.
  7856. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7857. THREE.QuaternionKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7858. return value0.slerp( value1, alpha );
  7859. };
  7860. THREE.QuaternionKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7861. return value0.equals( value1 );
  7862. };
  7863. THREE.QuaternionKeyframeTrack.prototype.multiply = function( quat ) {
  7864. for ( var i = 0; i < this.keys.length; i ++ ) {
  7865. this.keys[i].value.multiply( quat );
  7866. }
  7867. return this;
  7868. };
  7869. THREE.QuaternionKeyframeTrack.prototype.clone = function() {
  7870. var clonedKeys = [];
  7871. for ( var i = 0; i < this.keys.length; i ++ ) {
  7872. var key = this.keys[i];
  7873. clonedKeys.push( {
  7874. time: key.time,
  7875. value: key.value.clone()
  7876. } );
  7877. }
  7878. return new THREE.QuaternionKeyframeTrack( this.name, clonedKeys );
  7879. };
  7880. THREE.QuaternionKeyframeTrack.parse = function( json ) {
  7881. var keys = [];
  7882. for ( var i = 0; i < json.keys.length; i ++ ) {
  7883. var jsonKey = json.keys[i];
  7884. keys.push( {
  7885. value: new THREE.Quaternion().fromArray( jsonKey.value ),
  7886. time: jsonKey.time
  7887. } );
  7888. }
  7889. return new THREE.QuaternionKeyframeTrack( json.name, keys );
  7890. };
  7891. // File:src/animation/tracks/StringKeyframeTrack.js
  7892. /**
  7893. *
  7894. * A Track that interpolates Strings
  7895. *
  7896. * @author Ben Houston / http://clara.io/
  7897. * @author David Sarno / http://lighthaus.us/
  7898. */
  7899. THREE.StringKeyframeTrack = function ( name, keys ) {
  7900. THREE.KeyframeTrack.call( this, name, keys );
  7901. // local cache of value type to avoid allocations during runtime.
  7902. this.result = this.keys[0].value;
  7903. };
  7904. THREE.StringKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7905. THREE.StringKeyframeTrack.prototype.constructor = THREE.StringKeyframeTrack;
  7906. THREE.StringKeyframeTrack.prototype.setResult = function( value ) {
  7907. this.result = value;
  7908. };
  7909. // memoization of the lerp function for speed.
  7910. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7911. THREE.StringKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7912. return ( alpha < 1.0 ) ? value0 : value1;
  7913. };
  7914. THREE.StringKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7915. return ( value0 === value1 );
  7916. };
  7917. THREE.StringKeyframeTrack.prototype.clone = function() {
  7918. var clonedKeys = [];
  7919. for ( var i = 0; i < this.keys.length; i ++ ) {
  7920. var key = this.keys[i];
  7921. clonedKeys.push( {
  7922. time: key.time,
  7923. value: key.value
  7924. } );
  7925. }
  7926. return new THREE.StringKeyframeTrack( this.name, clonedKeys );
  7927. };
  7928. THREE.StringKeyframeTrack.parse = function( json ) {
  7929. return new THREE.StringKeyframeTrack( json.name, json.keys );
  7930. };
  7931. // File:src/animation/tracks/BooleanKeyframeTrack.js
  7932. /**
  7933. *
  7934. * A Track that interpolates Boolean
  7935. *
  7936. * @author Ben Houston / http://clara.io/
  7937. * @author David Sarno / http://lighthaus.us/
  7938. */
  7939. THREE.BooleanKeyframeTrack = function ( name, keys ) {
  7940. THREE.KeyframeTrack.call( this, name, keys );
  7941. // local cache of value type to avoid allocations during runtime.
  7942. this.result = this.keys[0].value;
  7943. };
  7944. THREE.BooleanKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7945. THREE.BooleanKeyframeTrack.prototype.constructor = THREE.BooleanKeyframeTrack;
  7946. THREE.BooleanKeyframeTrack.prototype.setResult = function( value ) {
  7947. this.result = value;
  7948. };
  7949. // memoization of the lerp function for speed.
  7950. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7951. THREE.BooleanKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7952. return ( alpha < 1.0 ) ? value0 : value1;
  7953. };
  7954. THREE.BooleanKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7955. return ( value0 === value1 );
  7956. };
  7957. THREE.BooleanKeyframeTrack.prototype.clone = function() {
  7958. var clonedKeys = [];
  7959. for ( var i = 0; i < this.keys.length; i ++ ) {
  7960. var key = this.keys[i];
  7961. clonedKeys.push( {
  7962. time: key.time,
  7963. value: key.value
  7964. } );
  7965. }
  7966. return new THREE.BooleanKeyframeTrack( this.name, clonedKeys );
  7967. };
  7968. THREE.BooleanKeyframeTrack.parse = function( json ) {
  7969. return new THREE.BooleanKeyframeTrack( json.name, json.keys );
  7970. };
  7971. // File:src/animation/tracks/NumberKeyframeTrack.js
  7972. /**
  7973. *
  7974. * A Track that interpolates Numbers
  7975. *
  7976. * @author Ben Houston / http://clara.io/
  7977. * @author David Sarno / http://lighthaus.us/
  7978. */
  7979. THREE.NumberKeyframeTrack = function ( name, keys ) {
  7980. THREE.KeyframeTrack.call( this, name, keys );
  7981. // local cache of value type to avoid allocations during runtime.
  7982. this.result = this.keys[0].value;
  7983. };
  7984. THREE.NumberKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7985. THREE.NumberKeyframeTrack.prototype.constructor = THREE.NumberKeyframeTrack;
  7986. THREE.NumberKeyframeTrack.prototype.setResult = function( value ) {
  7987. this.result = value;
  7988. };
  7989. // memoization of the lerp function for speed.
  7990. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7991. THREE.NumberKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7992. return value0 * ( 1 - alpha ) + value1 * alpha;
  7993. };
  7994. THREE.NumberKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7995. return ( value0 === value1 );
  7996. };
  7997. THREE.NumberKeyframeTrack.prototype.clone = function() {
  7998. var clonedKeys = [];
  7999. for ( var i = 0; i < this.keys.length; i ++ ) {
  8000. var key = this.keys[i];
  8001. clonedKeys.push( {
  8002. time: key.time,
  8003. value: key.value
  8004. } );
  8005. }
  8006. return new THREE.NumberKeyframeTrack( this.name, clonedKeys );
  8007. };
  8008. THREE.NumberKeyframeTrack.parse = function( json ) {
  8009. return new THREE.NumberKeyframeTrack( json.name, json.keys );
  8010. };
  8011. // File:src/cameras/Camera.js
  8012. /**
  8013. * @author mrdoob / http://mrdoob.com/
  8014. * @author mikael emtinger / http://gomo.se/
  8015. * @author WestLangley / http://github.com/WestLangley
  8016. */
  8017. THREE.Camera = function () {
  8018. THREE.Object3D.call( this );
  8019. this.type = 'Camera';
  8020. this.matrixWorldInverse = new THREE.Matrix4();
  8021. this.projectionMatrix = new THREE.Matrix4();
  8022. };
  8023. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  8024. THREE.Camera.prototype.constructor = THREE.Camera;
  8025. THREE.Camera.prototype.getWorldDirection = function () {
  8026. var quaternion = new THREE.Quaternion();
  8027. return function ( optionalTarget ) {
  8028. var result = optionalTarget || new THREE.Vector3();
  8029. this.getWorldQuaternion( quaternion );
  8030. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  8031. };
  8032. }();
  8033. THREE.Camera.prototype.lookAt = function () {
  8034. // This routine does not support cameras with rotated and/or translated parent(s)
  8035. var m1 = new THREE.Matrix4();
  8036. return function ( vector ) {
  8037. m1.lookAt( this.position, vector, this.up );
  8038. this.quaternion.setFromRotationMatrix( m1 );
  8039. };
  8040. }();
  8041. THREE.Camera.prototype.clone = function () {
  8042. return new this.constructor().copy( this );
  8043. };
  8044. THREE.Camera.prototype.copy = function ( source ) {
  8045. THREE.Object3D.prototype.copy.call( this, source );
  8046. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  8047. this.projectionMatrix.copy( source.projectionMatrix );
  8048. return this;
  8049. };
  8050. // File:src/cameras/CubeCamera.js
  8051. /**
  8052. * Camera for rendering cube maps
  8053. * - renders scene into axis-aligned cube
  8054. *
  8055. * @author alteredq / http://alteredqualia.com/
  8056. */
  8057. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  8058. THREE.Object3D.call( this );
  8059. this.type = 'CubeCamera';
  8060. var fov = 90, aspect = 1;
  8061. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8062. cameraPX.up.set( 0, - 1, 0 );
  8063. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  8064. this.add( cameraPX );
  8065. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8066. cameraNX.up.set( 0, - 1, 0 );
  8067. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  8068. this.add( cameraNX );
  8069. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8070. cameraPY.up.set( 0, 0, 1 );
  8071. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  8072. this.add( cameraPY );
  8073. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8074. cameraNY.up.set( 0, 0, - 1 );
  8075. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  8076. this.add( cameraNY );
  8077. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8078. cameraPZ.up.set( 0, - 1, 0 );
  8079. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  8080. this.add( cameraPZ );
  8081. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8082. cameraNZ.up.set( 0, - 1, 0 );
  8083. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  8084. this.add( cameraNZ );
  8085. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  8086. this.updateCubeMap = function ( renderer, scene ) {
  8087. if ( this.parent === null ) this.updateMatrixWorld();
  8088. var renderTarget = this.renderTarget;
  8089. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8090. renderTarget.texture.generateMipmaps = false;
  8091. renderTarget.activeCubeFace = 0;
  8092. renderer.render( scene, cameraPX, renderTarget );
  8093. renderTarget.activeCubeFace = 1;
  8094. renderer.render( scene, cameraNX, renderTarget );
  8095. renderTarget.activeCubeFace = 2;
  8096. renderer.render( scene, cameraPY, renderTarget );
  8097. renderTarget.activeCubeFace = 3;
  8098. renderer.render( scene, cameraNY, renderTarget );
  8099. renderTarget.activeCubeFace = 4;
  8100. renderer.render( scene, cameraPZ, renderTarget );
  8101. renderTarget.texture.generateMipmaps = generateMipmaps;
  8102. renderTarget.activeCubeFace = 5;
  8103. renderer.render( scene, cameraNZ, renderTarget );
  8104. renderer.setRenderTarget( null );
  8105. };
  8106. };
  8107. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  8108. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  8109. // File:src/cameras/OrthographicCamera.js
  8110. /**
  8111. * @author alteredq / http://alteredqualia.com/
  8112. */
  8113. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  8114. THREE.Camera.call( this );
  8115. this.type = 'OrthographicCamera';
  8116. this.zoom = 1;
  8117. this.left = left;
  8118. this.right = right;
  8119. this.top = top;
  8120. this.bottom = bottom;
  8121. this.near = ( near !== undefined ) ? near : 0.1;
  8122. this.far = ( far !== undefined ) ? far : 2000;
  8123. this.updateProjectionMatrix();
  8124. };
  8125. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  8126. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  8127. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  8128. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  8129. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  8130. var cx = ( this.right + this.left ) / 2;
  8131. var cy = ( this.top + this.bottom ) / 2;
  8132. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  8133. };
  8134. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  8135. THREE.Camera.prototype.copy.call( this, source );
  8136. this.left = source.left;
  8137. this.right = source.right;
  8138. this.top = source.top;
  8139. this.bottom = source.bottom;
  8140. this.near = source.near;
  8141. this.far = source.far;
  8142. this.zoom = source.zoom;
  8143. return this;
  8144. };
  8145. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  8146. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8147. data.object.zoom = this.zoom;
  8148. data.object.left = this.left;
  8149. data.object.right = this.right;
  8150. data.object.top = this.top;
  8151. data.object.bottom = this.bottom;
  8152. data.object.near = this.near;
  8153. data.object.far = this.far;
  8154. return data;
  8155. };
  8156. // File:src/cameras/PerspectiveCamera.js
  8157. /**
  8158. * @author mrdoob / http://mrdoob.com/
  8159. * @author greggman / http://games.greggman.com/
  8160. * @author zz85 / http://www.lab4games.net/zz85/blog
  8161. */
  8162. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  8163. THREE.Camera.call( this );
  8164. this.type = 'PerspectiveCamera';
  8165. this.zoom = 1;
  8166. this.fov = fov !== undefined ? fov : 50;
  8167. this.aspect = aspect !== undefined ? aspect : 1;
  8168. this.near = near !== undefined ? near : 0.1;
  8169. this.far = far !== undefined ? far : 2000;
  8170. this.updateProjectionMatrix();
  8171. };
  8172. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  8173. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  8174. /**
  8175. * Uses Focal Length (in mm) to estimate and set FOV
  8176. * 35mm (full-frame) camera is used if frame size is not specified;
  8177. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  8178. */
  8179. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  8180. if ( frameHeight === undefined ) frameHeight = 24;
  8181. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  8182. this.updateProjectionMatrix();
  8183. };
  8184. /**
  8185. * Sets an offset in a larger frustum. This is useful for multi-window or
  8186. * multi-monitor/multi-machine setups.
  8187. *
  8188. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8189. * the monitors are in grid like this
  8190. *
  8191. * +---+---+---+
  8192. * | A | B | C |
  8193. * +---+---+---+
  8194. * | D | E | F |
  8195. * +---+---+---+
  8196. *
  8197. * then for each monitor you would call it like this
  8198. *
  8199. * var w = 1920;
  8200. * var h = 1080;
  8201. * var fullWidth = w * 3;
  8202. * var fullHeight = h * 2;
  8203. *
  8204. * --A--
  8205. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8206. * --B--
  8207. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8208. * --C--
  8209. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8210. * --D--
  8211. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8212. * --E--
  8213. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8214. * --F--
  8215. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8216. *
  8217. * Note there is no reason monitors have to be the same size or in a grid.
  8218. */
  8219. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  8220. this.fullWidth = fullWidth;
  8221. this.fullHeight = fullHeight;
  8222. this.x = x;
  8223. this.y = y;
  8224. this.width = width;
  8225. this.height = height;
  8226. this.updateProjectionMatrix();
  8227. };
  8228. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  8229. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  8230. if ( this.fullWidth ) {
  8231. var aspect = this.fullWidth / this.fullHeight;
  8232. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  8233. var bottom = - top;
  8234. var left = aspect * bottom;
  8235. var right = aspect * top;
  8236. var width = Math.abs( right - left );
  8237. var height = Math.abs( top - bottom );
  8238. this.projectionMatrix.makeFrustum(
  8239. left + this.x * width / this.fullWidth,
  8240. left + ( this.x + this.width ) * width / this.fullWidth,
  8241. top - ( this.y + this.height ) * height / this.fullHeight,
  8242. top - this.y * height / this.fullHeight,
  8243. this.near,
  8244. this.far
  8245. );
  8246. } else {
  8247. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  8248. }
  8249. };
  8250. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  8251. THREE.Camera.prototype.copy.call( this, source );
  8252. this.fov = source.fov;
  8253. this.aspect = source.aspect;
  8254. this.near = source.near;
  8255. this.far = source.far;
  8256. this.zoom = source.zoom;
  8257. return this;
  8258. };
  8259. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  8260. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8261. data.object.zoom = this.zoom;
  8262. data.object.fov = this.fov;
  8263. data.object.aspect = this.aspect;
  8264. data.object.near = this.near;
  8265. data.object.far = this.far;
  8266. return data;
  8267. };
  8268. // File:src/lights/Light.js
  8269. /**
  8270. * @author mrdoob / http://mrdoob.com/
  8271. * @author alteredq / http://alteredqualia.com/
  8272. */
  8273. THREE.Light = function ( color ) {
  8274. THREE.Object3D.call( this );
  8275. this.type = 'Light';
  8276. this.color = new THREE.Color( color );
  8277. };
  8278. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  8279. THREE.Light.prototype.constructor = THREE.Light;
  8280. THREE.Light.prototype.copy = function ( source ) {
  8281. THREE.Object3D.prototype.copy.call( this, source );
  8282. this.color.copy( source.color );
  8283. return this;
  8284. };
  8285. THREE.Light.prototype.toJSON = function ( meta ) {
  8286. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8287. data.object.color = this.color.getHex();
  8288. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  8289. if ( this.intensity !== undefined ) data.object.intensity = this.intensity;
  8290. if ( this.distance !== undefined ) data.object.distance = this.distance;
  8291. if ( this.angle !== undefined ) data.object.angle = this.angle;
  8292. if ( this.decay !== undefined ) data.object.decay = this.decay;
  8293. if ( this.exponent !== undefined ) data.object.exponent = this.exponent;
  8294. return data;
  8295. };
  8296. // File:src/lights/AmbientLight.js
  8297. /**
  8298. * @author mrdoob / http://mrdoob.com/
  8299. */
  8300. THREE.AmbientLight = function ( color ) {
  8301. THREE.Light.call( this, color );
  8302. this.type = 'AmbientLight';
  8303. };
  8304. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  8305. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  8306. // File:src/lights/DirectionalLight.js
  8307. /**
  8308. * @author mrdoob / http://mrdoob.com/
  8309. * @author alteredq / http://alteredqualia.com/
  8310. */
  8311. THREE.DirectionalLight = function ( color, intensity ) {
  8312. THREE.Light.call( this, color );
  8313. this.type = 'DirectionalLight';
  8314. this.position.set( 0, 1, 0 );
  8315. this.updateMatrix();
  8316. this.target = new THREE.Object3D();
  8317. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8318. this.castShadow = false;
  8319. this.onlyShadow = false;
  8320. this.shadowCameraNear = 50;
  8321. this.shadowCameraFar = 5000;
  8322. this.shadowCameraLeft = - 500;
  8323. this.shadowCameraRight = 500;
  8324. this.shadowCameraTop = 500;
  8325. this.shadowCameraBottom = - 500;
  8326. this.shadowCameraVisible = false;
  8327. this.shadowBias = 0;
  8328. this.shadowDarkness = 0.5;
  8329. this.shadowMapWidth = 512;
  8330. this.shadowMapHeight = 512;
  8331. this.shadowMap = null;
  8332. this.shadowMapSize = null;
  8333. this.shadowCamera = null;
  8334. this.shadowMatrix = null;
  8335. };
  8336. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  8337. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  8338. THREE.DirectionalLight.prototype.copy = function ( source ) {
  8339. THREE.Light.prototype.copy.call( this, source );
  8340. this.intensity = source.intensity;
  8341. this.target = source.target.clone();
  8342. this.castShadow = source.castShadow;
  8343. this.onlyShadow = source.onlyShadow;
  8344. this.shadowCameraNear = source.shadowCameraNear;
  8345. this.shadowCameraFar = source.shadowCameraFar;
  8346. this.shadowCameraLeft = source.shadowCameraLeft;
  8347. this.shadowCameraRight = source.shadowCameraRight;
  8348. this.shadowCameraTop = source.shadowCameraTop;
  8349. this.shadowCameraBottom = source.shadowCameraBottom;
  8350. this.shadowCameraVisible = source.shadowCameraVisible;
  8351. this.shadowBias = source.shadowBias;
  8352. this.shadowDarkness = source.shadowDarkness;
  8353. this.shadowMapWidth = source.shadowMapWidth;
  8354. this.shadowMapHeight = source.shadowMapHeight;
  8355. return this;
  8356. };
  8357. // File:src/lights/HemisphereLight.js
  8358. /**
  8359. * @author alteredq / http://alteredqualia.com/
  8360. */
  8361. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  8362. THREE.Light.call( this, skyColor );
  8363. this.type = 'HemisphereLight';
  8364. this.position.set( 0, 1, 0 );
  8365. this.updateMatrix();
  8366. this.groundColor = new THREE.Color( groundColor );
  8367. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8368. };
  8369. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  8370. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  8371. THREE.HemisphereLight.prototype.copy = function ( source ) {
  8372. THREE.Light.prototype.copy.call( this, source );
  8373. this.groundColor.copy( source.groundColor );
  8374. this.intensity = source.intensity;
  8375. return this;
  8376. };
  8377. // File:src/lights/PointLight.js
  8378. /**
  8379. * @author mrdoob / http://mrdoob.com/
  8380. */
  8381. THREE.PointLight = function ( color, intensity, distance, decay ) {
  8382. THREE.Light.call( this, color );
  8383. this.type = 'PointLight';
  8384. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8385. this.distance = ( distance !== undefined ) ? distance : 0;
  8386. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8387. this.castShadow = false;
  8388. this.onlyShadow = false;
  8389. //
  8390. this.shadowCameraNear = 1;
  8391. this.shadowCameraFar = 500;
  8392. this.shadowCameraFov = 90;
  8393. this.shadowCameraVisible = false;
  8394. this.shadowBias = 0;
  8395. this.shadowDarkness = 0.5;
  8396. this.shadowMapWidth = 512;
  8397. this.shadowMapHeight = 512;
  8398. //
  8399. this.shadowMap = null;
  8400. this.shadowMapSize = null;
  8401. this.shadowCamera = null;
  8402. this.shadowMatrix = null;
  8403. };
  8404. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  8405. THREE.PointLight.prototype.constructor = THREE.PointLight;
  8406. THREE.PointLight.prototype.copy = function ( source ) {
  8407. THREE.Light.prototype.copy.call( this, source );
  8408. this.intensity = source.intensity;
  8409. this.distance = source.distance;
  8410. this.decay = source.decay;
  8411. this.castShadow = source.castShadow;
  8412. this.onlyShadow = source.onlyShadow;
  8413. this.shadowCameraNear = source.shadowCameraNear;
  8414. this.shadowCameraFar = source.shadowCameraFar;
  8415. this.shadowCameraFov = source.shadowCameraFov;
  8416. this.shadowCameraVisible = source.shadowCameraVisible;
  8417. this.shadowBias = source.shadowBias;
  8418. this.shadowDarkness = source.shadowDarkness;
  8419. this.shadowMapWidth = source.shadowMapWidth;
  8420. this.shadowMapHeight = source.shadowMapHeight;
  8421. return this;
  8422. };
  8423. // File:src/lights/SpotLight.js
  8424. /**
  8425. * @author alteredq / http://alteredqualia.com/
  8426. */
  8427. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  8428. THREE.Light.call( this, color );
  8429. this.type = 'SpotLight';
  8430. this.position.set( 0, 1, 0 );
  8431. this.updateMatrix();
  8432. this.target = new THREE.Object3D();
  8433. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8434. this.distance = ( distance !== undefined ) ? distance : 0;
  8435. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  8436. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  8437. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8438. this.castShadow = false;
  8439. this.onlyShadow = false;
  8440. this.shadowCameraNear = 50;
  8441. this.shadowCameraFar = 5000;
  8442. this.shadowCameraFov = 50;
  8443. this.shadowCameraVisible = false;
  8444. this.shadowBias = 0;
  8445. this.shadowDarkness = 0.5;
  8446. this.shadowMapWidth = 512;
  8447. this.shadowMapHeight = 512;
  8448. this.shadowMap = null;
  8449. this.shadowMapSize = null;
  8450. this.shadowCamera = null;
  8451. this.shadowMatrix = null;
  8452. };
  8453. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  8454. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  8455. THREE.SpotLight.prototype.copy = function ( source ) {
  8456. THREE.Light.prototype.copy.call( this, source );
  8457. this.intensity = source.intensity;
  8458. this.distance = source.distance;
  8459. this.angle = source.angle;
  8460. this.exponent = source.exponent;
  8461. this.decay = source.decay;
  8462. this.target = source.target.clone();
  8463. this.castShadow = source.castShadow;
  8464. this.onlyShadow = source.onlyShadow;
  8465. this.shadowCameraNear = source.shadowCameraNear;
  8466. this.shadowCameraFar = source.shadowCameraFar;
  8467. this.shadowCameraFov = source.shadowCameraFov;
  8468. this.shadowCameraVisible = source.shadowCameraVisible;
  8469. this.shadowBias = source.shadowBias;
  8470. this.shadowDarkness = source.shadowDarkness;
  8471. this.shadowMapWidth = source.shadowMapWidth;
  8472. this.shadowMapHeight = source.shadowMapHeight;
  8473. return this;
  8474. };
  8475. // File:src/loaders/Cache.js
  8476. /**
  8477. * @author mrdoob / http://mrdoob.com/
  8478. */
  8479. THREE.Cache = {
  8480. enabled: false,
  8481. files: {},
  8482. add: function ( key, file ) {
  8483. if ( this.enabled === false ) return;
  8484. // console.log( 'THREE.Cache', 'Adding key:', key );
  8485. this.files[ key ] = file;
  8486. },
  8487. get: function ( key ) {
  8488. if ( this.enabled === false ) return;
  8489. // console.log( 'THREE.Cache', 'Checking key:', key );
  8490. return this.files[ key ];
  8491. },
  8492. remove: function ( key ) {
  8493. delete this.files[ key ];
  8494. },
  8495. clear: function () {
  8496. this.files = {};
  8497. }
  8498. };
  8499. // File:src/loaders/Loader.js
  8500. /**
  8501. * @author alteredq / http://alteredqualia.com/
  8502. */
  8503. THREE.Loader = function () {
  8504. this.onLoadStart = function () {};
  8505. this.onLoadProgress = function () {};
  8506. this.onLoadComplete = function () {};
  8507. };
  8508. THREE.Loader.prototype = {
  8509. constructor: THREE.Loader,
  8510. crossOrigin: undefined,
  8511. extractUrlBase: function ( url ) {
  8512. var parts = url.split( '/' );
  8513. if ( parts.length === 1 ) return './';
  8514. parts.pop();
  8515. return parts.join( '/' ) + '/';
  8516. },
  8517. initMaterials: function ( materials, texturePath, crossOrigin ) {
  8518. var array = [];
  8519. for ( var i = 0; i < materials.length; ++ i ) {
  8520. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  8521. }
  8522. return array;
  8523. },
  8524. createMaterial: ( function () {
  8525. var imageLoader;
  8526. return function createMaterial( m, texturePath, crossOrigin ) {
  8527. var scope = this;
  8528. if ( crossOrigin === undefined && scope.crossOrigin !== undefined ) crossOrigin = scope.crossOrigin;
  8529. if ( imageLoader === undefined ) imageLoader = new THREE.ImageLoader();
  8530. function nearest_pow2( n ) {
  8531. var l = Math.log( n ) / Math.LN2;
  8532. return Math.pow( 2, Math.round( l ) );
  8533. }
  8534. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  8535. var fullPath = texturePath + sourceFile;
  8536. var texture;
  8537. var loader = THREE.Loader.Handlers.get( fullPath );
  8538. if ( loader !== null ) {
  8539. texture = loader.load( fullPath );
  8540. } else {
  8541. texture = new THREE.Texture();
  8542. loader = imageLoader;
  8543. loader.setCrossOrigin( crossOrigin );
  8544. loader.load( fullPath, function ( image ) {
  8545. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  8546. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  8547. var width = nearest_pow2( image.width );
  8548. var height = nearest_pow2( image.height );
  8549. var canvas = document.createElement( 'canvas' );
  8550. canvas.width = width;
  8551. canvas.height = height;
  8552. var context = canvas.getContext( '2d' );
  8553. context.drawImage( image, 0, 0, width, height );
  8554. texture.image = canvas;
  8555. } else {
  8556. texture.image = image;
  8557. }
  8558. texture.needsUpdate = true;
  8559. } );
  8560. }
  8561. texture.sourceFile = sourceFile;
  8562. if ( repeat ) {
  8563. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  8564. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  8565. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  8566. }
  8567. if ( offset ) {
  8568. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  8569. }
  8570. if ( wrap ) {
  8571. var wrapMap = {
  8572. 'repeat': THREE.RepeatWrapping,
  8573. 'mirror': THREE.MirroredRepeatWrapping
  8574. };
  8575. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  8576. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  8577. }
  8578. if ( anisotropy ) {
  8579. texture.anisotropy = anisotropy;
  8580. }
  8581. where[ name ] = texture;
  8582. }
  8583. function rgb2hex( rgb ) {
  8584. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  8585. }
  8586. // defaults
  8587. var mtype = 'MeshLambertMaterial';
  8588. var mpars = {};
  8589. // parameters from model file
  8590. if ( m.shading ) {
  8591. var shading = m.shading.toLowerCase();
  8592. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  8593. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  8594. }
  8595. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  8596. mpars.blending = THREE[ m.blending ];
  8597. }
  8598. if ( m.transparent !== undefined ) {
  8599. mpars.transparent = m.transparent;
  8600. }
  8601. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  8602. mpars.transparent = true;
  8603. }
  8604. if ( m.depthTest !== undefined ) {
  8605. mpars.depthTest = m.depthTest;
  8606. }
  8607. if ( m.depthWrite !== undefined ) {
  8608. mpars.depthWrite = m.depthWrite;
  8609. }
  8610. if ( m.visible !== undefined ) {
  8611. mpars.visible = m.visible;
  8612. }
  8613. if ( m.flipSided !== undefined ) {
  8614. mpars.side = THREE.BackSide;
  8615. }
  8616. if ( m.doubleSided !== undefined ) {
  8617. mpars.side = THREE.DoubleSide;
  8618. }
  8619. if ( m.wireframe !== undefined ) {
  8620. mpars.wireframe = m.wireframe;
  8621. }
  8622. if ( m.vertexColors !== undefined ) {
  8623. if ( m.vertexColors === 'face' ) {
  8624. mpars.vertexColors = THREE.FaceColors;
  8625. } else if ( m.vertexColors ) {
  8626. mpars.vertexColors = THREE.VertexColors;
  8627. }
  8628. }
  8629. // colors
  8630. if ( m.colorDiffuse ) {
  8631. mpars.color = rgb2hex( m.colorDiffuse );
  8632. } else if ( m.DbgColor ) {
  8633. mpars.color = m.DbgColor;
  8634. }
  8635. if ( m.colorEmissive ) {
  8636. mpars.emissive = rgb2hex( m.colorEmissive );
  8637. }
  8638. if ( mtype === 'MeshPhongMaterial' ) {
  8639. if ( m.colorSpecular ) {
  8640. mpars.specular = rgb2hex( m.colorSpecular );
  8641. }
  8642. if ( m.specularCoef ) {
  8643. mpars.shininess = m.specularCoef;
  8644. }
  8645. }
  8646. // modifiers
  8647. if ( m.transparency !== undefined ) {
  8648. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  8649. m.opacity = m.transparency;
  8650. }
  8651. if ( m.opacity !== undefined ) {
  8652. mpars.opacity = m.opacity;
  8653. }
  8654. // textures
  8655. if ( texturePath ) {
  8656. if ( m.mapDiffuse ) {
  8657. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  8658. }
  8659. if ( m.mapLight ) {
  8660. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  8661. }
  8662. if ( m.mapAO ) {
  8663. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  8664. }
  8665. if ( m.mapBump ) {
  8666. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  8667. }
  8668. if ( m.mapNormal ) {
  8669. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  8670. }
  8671. if ( m.mapSpecular ) {
  8672. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  8673. }
  8674. if ( m.mapAlpha ) {
  8675. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  8676. }
  8677. }
  8678. //
  8679. if ( m.mapBumpScale ) {
  8680. mpars.bumpScale = m.mapBumpScale;
  8681. }
  8682. if ( m.mapNormalFactor ) {
  8683. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  8684. }
  8685. var material = new THREE[ mtype ]( mpars );
  8686. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  8687. return material;
  8688. };
  8689. } )()
  8690. };
  8691. THREE.Loader.Handlers = {
  8692. handlers: [],
  8693. add: function ( regex, loader ) {
  8694. this.handlers.push( regex, loader );
  8695. },
  8696. get: function ( file ) {
  8697. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  8698. var regex = this.handlers[ i ];
  8699. var loader = this.handlers[ i + 1 ];
  8700. if ( regex.test( file ) ) {
  8701. return loader;
  8702. }
  8703. }
  8704. return null;
  8705. }
  8706. };
  8707. // File:src/loaders/XHRLoader.js
  8708. /**
  8709. * @author mrdoob / http://mrdoob.com/
  8710. */
  8711. THREE.XHRLoader = function ( manager ) {
  8712. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8713. };
  8714. THREE.XHRLoader.prototype = {
  8715. constructor: THREE.XHRLoader,
  8716. load: function ( url, onLoad, onProgress, onError ) {
  8717. var scope = this;
  8718. var cached = THREE.Cache.get( url );
  8719. if ( cached !== undefined ) {
  8720. if ( onLoad ) {
  8721. setTimeout( function () {
  8722. onLoad( cached );
  8723. }, 0 );
  8724. }
  8725. return cached;
  8726. }
  8727. var request = new XMLHttpRequest();
  8728. request.open( 'GET', url, true );
  8729. request.addEventListener( 'load', function ( event ) {
  8730. var response = event.target.response;
  8731. THREE.Cache.add( url, response );
  8732. if ( onLoad ) onLoad( response );
  8733. scope.manager.itemEnd( url );
  8734. }, false );
  8735. if ( onProgress !== undefined ) {
  8736. request.addEventListener( 'progress', function ( event ) {
  8737. onProgress( event );
  8738. }, false );
  8739. }
  8740. request.addEventListener( 'error', function ( event ) {
  8741. if ( onError ) onError( event );
  8742. scope.manager.itemError( url );
  8743. }, false );
  8744. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  8745. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  8746. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  8747. request.send( null );
  8748. scope.manager.itemStart( url );
  8749. return request;
  8750. },
  8751. setResponseType: function ( value ) {
  8752. this.responseType = value;
  8753. },
  8754. setCrossOrigin: function ( value ) {
  8755. this.crossOrigin = value;
  8756. },
  8757. setWithCredentials: function ( value ) {
  8758. this.withCredentials = value;
  8759. }
  8760. };
  8761. // File:src/loaders/ImageLoader.js
  8762. /**
  8763. * @author mrdoob / http://mrdoob.com/
  8764. */
  8765. THREE.ImageLoader = function ( manager ) {
  8766. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8767. };
  8768. THREE.ImageLoader.prototype = {
  8769. constructor: THREE.ImageLoader,
  8770. load: function ( url, onLoad, onProgress, onError ) {
  8771. var scope = this;
  8772. var cached = THREE.Cache.get( url );
  8773. if ( cached !== undefined ) {
  8774. scope.manager.itemStart( url );
  8775. if ( onLoad ) {
  8776. setTimeout( function () {
  8777. onLoad( cached );
  8778. scope.manager.itemEnd( url );
  8779. }, 0 );
  8780. } else {
  8781. scope.manager.itemEnd( url );
  8782. }
  8783. return cached;
  8784. }
  8785. var image = document.createElement( 'img' );
  8786. image.addEventListener( 'load', function ( event ) {
  8787. THREE.Cache.add( url, this );
  8788. if ( onLoad ) onLoad( this );
  8789. scope.manager.itemEnd( url );
  8790. }, false );
  8791. if ( onProgress !== undefined ) {
  8792. image.addEventListener( 'progress', function ( event ) {
  8793. onProgress( event );
  8794. }, false );
  8795. }
  8796. image.addEventListener( 'error', function ( event ) {
  8797. if ( onError ) onError( event );
  8798. scope.manager.itemError( url );
  8799. }, false );
  8800. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  8801. scope.manager.itemStart( url );
  8802. image.src = url;
  8803. return image;
  8804. },
  8805. setCrossOrigin: function ( value ) {
  8806. this.crossOrigin = value;
  8807. }
  8808. };
  8809. // File:src/loaders/JSONLoader.js
  8810. /**
  8811. * @author mrdoob / http://mrdoob.com/
  8812. * @author alteredq / http://alteredqualia.com/
  8813. */
  8814. THREE.JSONLoader = function ( manager ) {
  8815. if ( typeof manager === 'boolean' ) {
  8816. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  8817. manager = undefined;
  8818. }
  8819. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8820. this.withCredentials = false;
  8821. };
  8822. THREE.JSONLoader.prototype = {
  8823. constructor: THREE.JSONLoader,
  8824. // Deprecated
  8825. get statusDomElement () {
  8826. if ( this._statusDomElement === undefined ) {
  8827. this._statusDomElement = document.createElement( 'div' );
  8828. }
  8829. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  8830. return this._statusDomElement;
  8831. },
  8832. load: function( url, onLoad, onProgress, onError ) {
  8833. var scope = this;
  8834. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  8835. var loader = new THREE.XHRLoader( this.manager );
  8836. loader.setCrossOrigin( this.crossOrigin );
  8837. loader.setWithCredentials( this.withCredentials );
  8838. loader.load( url, function ( text ) {
  8839. var json = JSON.parse( text );
  8840. var metadata = json.metadata;
  8841. if ( metadata !== undefined ) {
  8842. if ( metadata.type === 'object' ) {
  8843. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  8844. return;
  8845. }
  8846. if ( metadata.type === 'scene' ) {
  8847. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  8848. return;
  8849. }
  8850. }
  8851. var object = scope.parse( json, texturePath );
  8852. onLoad( object.geometry, object.materials );
  8853. } );
  8854. },
  8855. setCrossOrigin: function ( value ) {
  8856. this.crossOrigin = value;
  8857. },
  8858. setTexturePath: function ( value ) {
  8859. this.texturePath = value;
  8860. },
  8861. parse: function ( json, texturePath ) {
  8862. var geometry = new THREE.Geometry(),
  8863. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  8864. parseModel( scale );
  8865. parseSkin();
  8866. parseMorphing( scale );
  8867. parseAnimations();
  8868. geometry.computeFaceNormals();
  8869. geometry.computeBoundingSphere();
  8870. function parseModel( scale ) {
  8871. function isBitSet( value, position ) {
  8872. return value & ( 1 << position );
  8873. }
  8874. var i, j, fi,
  8875. offset, zLength,
  8876. colorIndex, normalIndex, uvIndex, materialIndex,
  8877. type,
  8878. isQuad,
  8879. hasMaterial,
  8880. hasFaceVertexUv,
  8881. hasFaceNormal, hasFaceVertexNormal,
  8882. hasFaceColor, hasFaceVertexColor,
  8883. vertex, face, faceA, faceB, hex, normal,
  8884. uvLayer, uv, u, v,
  8885. faces = json.faces,
  8886. vertices = json.vertices,
  8887. normals = json.normals,
  8888. colors = json.colors,
  8889. nUvLayers = 0;
  8890. if ( json.uvs !== undefined ) {
  8891. // disregard empty arrays
  8892. for ( i = 0; i < json.uvs.length; i ++ ) {
  8893. if ( json.uvs[ i ].length ) nUvLayers ++;
  8894. }
  8895. for ( i = 0; i < nUvLayers; i ++ ) {
  8896. geometry.faceVertexUvs[ i ] = [];
  8897. }
  8898. }
  8899. offset = 0;
  8900. zLength = vertices.length;
  8901. while ( offset < zLength ) {
  8902. vertex = new THREE.Vector3();
  8903. vertex.x = vertices[ offset ++ ] * scale;
  8904. vertex.y = vertices[ offset ++ ] * scale;
  8905. vertex.z = vertices[ offset ++ ] * scale;
  8906. geometry.vertices.push( vertex );
  8907. }
  8908. offset = 0;
  8909. zLength = faces.length;
  8910. while ( offset < zLength ) {
  8911. type = faces[ offset ++ ];
  8912. isQuad = isBitSet( type, 0 );
  8913. hasMaterial = isBitSet( type, 1 );
  8914. hasFaceVertexUv = isBitSet( type, 3 );
  8915. hasFaceNormal = isBitSet( type, 4 );
  8916. hasFaceVertexNormal = isBitSet( type, 5 );
  8917. hasFaceColor = isBitSet( type, 6 );
  8918. hasFaceVertexColor = isBitSet( type, 7 );
  8919. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  8920. if ( isQuad ) {
  8921. faceA = new THREE.Face3();
  8922. faceA.a = faces[ offset ];
  8923. faceA.b = faces[ offset + 1 ];
  8924. faceA.c = faces[ offset + 3 ];
  8925. faceB = new THREE.Face3();
  8926. faceB.a = faces[ offset + 1 ];
  8927. faceB.b = faces[ offset + 2 ];
  8928. faceB.c = faces[ offset + 3 ];
  8929. offset += 4;
  8930. if ( hasMaterial ) {
  8931. materialIndex = faces[ offset ++ ];
  8932. faceA.materialIndex = materialIndex;
  8933. faceB.materialIndex = materialIndex;
  8934. }
  8935. // to get face <=> uv index correspondence
  8936. fi = geometry.faces.length;
  8937. if ( hasFaceVertexUv ) {
  8938. for ( i = 0; i < nUvLayers; i ++ ) {
  8939. uvLayer = json.uvs[ i ];
  8940. geometry.faceVertexUvs[ i ][ fi ] = [];
  8941. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  8942. for ( j = 0; j < 4; j ++ ) {
  8943. uvIndex = faces[ offset ++ ];
  8944. u = uvLayer[ uvIndex * 2 ];
  8945. v = uvLayer[ uvIndex * 2 + 1 ];
  8946. uv = new THREE.Vector2( u, v );
  8947. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  8948. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  8949. }
  8950. }
  8951. }
  8952. if ( hasFaceNormal ) {
  8953. normalIndex = faces[ offset ++ ] * 3;
  8954. faceA.normal.set(
  8955. normals[ normalIndex ++ ],
  8956. normals[ normalIndex ++ ],
  8957. normals[ normalIndex ]
  8958. );
  8959. faceB.normal.copy( faceA.normal );
  8960. }
  8961. if ( hasFaceVertexNormal ) {
  8962. for ( i = 0; i < 4; i ++ ) {
  8963. normalIndex = faces[ offset ++ ] * 3;
  8964. normal = new THREE.Vector3(
  8965. normals[ normalIndex ++ ],
  8966. normals[ normalIndex ++ ],
  8967. normals[ normalIndex ]
  8968. );
  8969. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  8970. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  8971. }
  8972. }
  8973. if ( hasFaceColor ) {
  8974. colorIndex = faces[ offset ++ ];
  8975. hex = colors[ colorIndex ];
  8976. faceA.color.setHex( hex );
  8977. faceB.color.setHex( hex );
  8978. }
  8979. if ( hasFaceVertexColor ) {
  8980. for ( i = 0; i < 4; i ++ ) {
  8981. colorIndex = faces[ offset ++ ];
  8982. hex = colors[ colorIndex ];
  8983. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  8984. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  8985. }
  8986. }
  8987. geometry.faces.push( faceA );
  8988. geometry.faces.push( faceB );
  8989. } else {
  8990. face = new THREE.Face3();
  8991. face.a = faces[ offset ++ ];
  8992. face.b = faces[ offset ++ ];
  8993. face.c = faces[ offset ++ ];
  8994. if ( hasMaterial ) {
  8995. materialIndex = faces[ offset ++ ];
  8996. face.materialIndex = materialIndex;
  8997. }
  8998. // to get face <=> uv index correspondence
  8999. fi = geometry.faces.length;
  9000. if ( hasFaceVertexUv ) {
  9001. for ( i = 0; i < nUvLayers; i ++ ) {
  9002. uvLayer = json.uvs[ i ];
  9003. geometry.faceVertexUvs[ i ][ fi ] = [];
  9004. for ( j = 0; j < 3; j ++ ) {
  9005. uvIndex = faces[ offset ++ ];
  9006. u = uvLayer[ uvIndex * 2 ];
  9007. v = uvLayer[ uvIndex * 2 + 1 ];
  9008. uv = new THREE.Vector2( u, v );
  9009. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  9010. }
  9011. }
  9012. }
  9013. if ( hasFaceNormal ) {
  9014. normalIndex = faces[ offset ++ ] * 3;
  9015. face.normal.set(
  9016. normals[ normalIndex ++ ],
  9017. normals[ normalIndex ++ ],
  9018. normals[ normalIndex ]
  9019. );
  9020. }
  9021. if ( hasFaceVertexNormal ) {
  9022. for ( i = 0; i < 3; i ++ ) {
  9023. normalIndex = faces[ offset ++ ] * 3;
  9024. normal = new THREE.Vector3(
  9025. normals[ normalIndex ++ ],
  9026. normals[ normalIndex ++ ],
  9027. normals[ normalIndex ]
  9028. );
  9029. face.vertexNormals.push( normal );
  9030. }
  9031. }
  9032. if ( hasFaceColor ) {
  9033. colorIndex = faces[ offset ++ ];
  9034. face.color.setHex( colors[ colorIndex ] );
  9035. }
  9036. if ( hasFaceVertexColor ) {
  9037. for ( i = 0; i < 3; i ++ ) {
  9038. colorIndex = faces[ offset ++ ];
  9039. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  9040. }
  9041. }
  9042. geometry.faces.push( face );
  9043. }
  9044. }
  9045. };
  9046. function parseSkin() {
  9047. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  9048. if ( json.skinWeights ) {
  9049. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  9050. var x = json.skinWeights[ i ];
  9051. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  9052. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  9053. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  9054. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  9055. }
  9056. }
  9057. if ( json.skinIndices ) {
  9058. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  9059. var a = json.skinIndices[ i ];
  9060. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  9061. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  9062. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  9063. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  9064. }
  9065. }
  9066. geometry.bones = json.bones;
  9067. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  9068. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  9069. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  9070. }
  9071. };
  9072. function parseMorphing( scale ) {
  9073. if ( json.morphTargets !== undefined ) {
  9074. var i, l, v, vl, dstVertices, srcVertices;
  9075. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  9076. geometry.morphTargets[ i ] = {};
  9077. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  9078. geometry.morphTargets[ i ].vertices = [];
  9079. dstVertices = geometry.morphTargets[ i ].vertices;
  9080. srcVertices = json.morphTargets[ i ].vertices;
  9081. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  9082. var vertex = new THREE.Vector3();
  9083. vertex.x = srcVertices[ v ] * scale;
  9084. vertex.y = srcVertices[ v + 1 ] * scale;
  9085. vertex.z = srcVertices[ v + 2 ] * scale;
  9086. dstVertices.push( vertex );
  9087. }
  9088. }
  9089. }
  9090. if ( json.morphColors !== undefined ) {
  9091. var i, l, c, cl, dstColors, srcColors, color;
  9092. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  9093. geometry.morphColors[ i ] = {};
  9094. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  9095. geometry.morphColors[ i ].colors = [];
  9096. dstColors = geometry.morphColors[ i ].colors;
  9097. srcColors = json.morphColors[ i ].colors;
  9098. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  9099. color = new THREE.Color( 0xffaa00 );
  9100. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  9101. dstColors.push( color );
  9102. }
  9103. }
  9104. }
  9105. }
  9106. function parseAnimations() {
  9107. var outputAnimations = [];
  9108. // parse old style Bone/Hierarchy animations
  9109. var animations = [];
  9110. if ( json.animation !== undefined ) {
  9111. animations.push( json.animation );
  9112. }
  9113. if ( json.animations !== undefined ) {
  9114. if ( json.animations.length ) {
  9115. animations = animations.concat( json.animations );
  9116. } else {
  9117. animations.push( json.animations );
  9118. }
  9119. }
  9120. for ( var i = 0; i < animations.length; i ++ ) {
  9121. var clip = THREE.AnimationClip.parseAnimation( animations[i], geometry.bones );
  9122. if ( clip ) outputAnimations.push( clip );
  9123. }
  9124. // parse implicit morph animations
  9125. if ( geometry.morphTargets ) {
  9126. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  9127. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  9128. outputAnimations = outputAnimations.concat( morphAnimationClips );
  9129. }
  9130. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  9131. };
  9132. if ( json.materials === undefined || json.materials.length === 0 ) {
  9133. return { geometry: geometry };
  9134. } else {
  9135. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  9136. return { geometry: geometry, materials: materials };
  9137. }
  9138. }
  9139. };
  9140. // File:src/loaders/LoadingManager.js
  9141. /**
  9142. * @author mrdoob / http://mrdoob.com/
  9143. */
  9144. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  9145. var scope = this;
  9146. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  9147. this.onStart = undefined;
  9148. this.onLoad = onLoad;
  9149. this.onProgress = onProgress;
  9150. this.onError = onError;
  9151. this.itemStart = function ( url ) {
  9152. itemsTotal ++;
  9153. if ( isLoading === false ) {
  9154. if ( scope.onStart !== undefined ) {
  9155. scope.onStart( url, itemsLoaded, itemsTotal );
  9156. }
  9157. }
  9158. isLoading = true;
  9159. };
  9160. this.itemEnd = function ( url ) {
  9161. itemsLoaded ++;
  9162. if ( scope.onProgress !== undefined ) {
  9163. scope.onProgress( url, itemsLoaded, itemsTotal );
  9164. }
  9165. if ( itemsLoaded === itemsTotal ) {
  9166. isLoading = false;
  9167. if ( scope.onLoad !== undefined ) {
  9168. scope.onLoad();
  9169. }
  9170. }
  9171. };
  9172. this.itemError = function ( url ) {
  9173. if ( scope.onError !== undefined ) {
  9174. scope.onError( url );
  9175. }
  9176. };
  9177. };
  9178. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  9179. // File:src/loaders/BufferGeometryLoader.js
  9180. /**
  9181. * @author mrdoob / http://mrdoob.com/
  9182. */
  9183. THREE.BufferGeometryLoader = function ( manager ) {
  9184. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9185. };
  9186. THREE.BufferGeometryLoader.prototype = {
  9187. constructor: THREE.BufferGeometryLoader,
  9188. load: function ( url, onLoad, onProgress, onError ) {
  9189. var scope = this;
  9190. var loader = new THREE.XHRLoader( scope.manager );
  9191. loader.setCrossOrigin( this.crossOrigin );
  9192. loader.load( url, function ( text ) {
  9193. onLoad( scope.parse( JSON.parse( text ) ) );
  9194. }, onProgress, onError );
  9195. },
  9196. setCrossOrigin: function ( value ) {
  9197. this.crossOrigin = value;
  9198. },
  9199. parse: function ( json ) {
  9200. var geometry = new THREE.BufferGeometry();
  9201. var index = json.data.index;
  9202. if ( index !== undefined ) {
  9203. var typedArray = new self[ index.type ]( index.array );
  9204. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  9205. }
  9206. var attributes = json.data.attributes;
  9207. for ( var key in attributes ) {
  9208. var attribute = attributes[ key ];
  9209. var typedArray = new self[ attribute.type ]( attribute.array );
  9210. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  9211. }
  9212. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  9213. if ( groups !== undefined ) {
  9214. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  9215. var group = groups[ i ];
  9216. geometry.addGroup( group.start, group.count );
  9217. }
  9218. }
  9219. var boundingSphere = json.data.boundingSphere;
  9220. if ( boundingSphere !== undefined ) {
  9221. var center = new THREE.Vector3();
  9222. if ( boundingSphere.center !== undefined ) {
  9223. center.fromArray( boundingSphere.center );
  9224. }
  9225. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  9226. }
  9227. return geometry;
  9228. }
  9229. };
  9230. // File:src/loaders/MaterialLoader.js
  9231. /**
  9232. * @author mrdoob / http://mrdoob.com/
  9233. */
  9234. THREE.MaterialLoader = function ( manager ) {
  9235. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9236. this.textures = {};
  9237. };
  9238. THREE.MaterialLoader.prototype = {
  9239. constructor: THREE.MaterialLoader,
  9240. load: function ( url, onLoad, onProgress, onError ) {
  9241. var scope = this;
  9242. var loader = new THREE.XHRLoader( scope.manager );
  9243. loader.setCrossOrigin( this.crossOrigin );
  9244. loader.load( url, function ( text ) {
  9245. onLoad( scope.parse( JSON.parse( text ) ) );
  9246. }, onProgress, onError );
  9247. },
  9248. setCrossOrigin: function ( value ) {
  9249. this.crossOrigin = value;
  9250. },
  9251. setTextures: function ( value ) {
  9252. this.textures = value;
  9253. },
  9254. getTexture: function ( name ) {
  9255. var textures = this.textures;
  9256. if ( textures[ name ] === undefined ) {
  9257. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  9258. }
  9259. return textures[ name ];
  9260. },
  9261. parse: function ( json ) {
  9262. var material = new THREE[ json.type ];
  9263. material.uuid = json.uuid;
  9264. if ( json.name !== undefined ) material.name = json.name;
  9265. if ( json.color !== undefined ) material.color.setHex( json.color );
  9266. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  9267. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  9268. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  9269. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  9270. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  9271. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  9272. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  9273. if ( json.shading !== undefined ) material.shading = json.shading;
  9274. if ( json.blending !== undefined ) material.blending = json.blending;
  9275. if ( json.side !== undefined ) material.side = json.side;
  9276. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  9277. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  9278. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  9279. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  9280. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  9281. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  9282. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  9283. // for PointsMaterial
  9284. if ( json.size !== undefined ) material.size = json.size;
  9285. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  9286. // maps
  9287. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  9288. if ( json.alphaMap !== undefined ) {
  9289. material.alphaMap = this.getTexture( json.alphaMap );
  9290. material.transparent = true;
  9291. }
  9292. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  9293. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  9294. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  9295. if ( json.normalScale ) material.normalScale = new THREE.Vector2( json.normalScale, json.normalScale );
  9296. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  9297. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  9298. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  9299. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  9300. if ( json.envMap !== undefined ) {
  9301. material.envMap = this.getTexture( json.envMap );
  9302. material.combine = THREE.MultiplyOperation;
  9303. }
  9304. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  9305. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  9306. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  9307. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  9308. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  9309. // MeshFaceMaterial
  9310. if ( json.materials !== undefined ) {
  9311. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  9312. material.materials.push( this.parse( json.materials[ i ] ) );
  9313. }
  9314. }
  9315. return material;
  9316. }
  9317. };
  9318. // File:src/loaders/ObjectLoader.js
  9319. /**
  9320. * @author mrdoob / http://mrdoob.com/
  9321. */
  9322. THREE.ObjectLoader = function ( manager ) {
  9323. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9324. this.texturePath = '';
  9325. };
  9326. THREE.ObjectLoader.prototype = {
  9327. constructor: THREE.ObjectLoader,
  9328. load: function ( url, onLoad, onProgress, onError ) {
  9329. if ( this.texturePath === '' ) {
  9330. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  9331. }
  9332. var scope = this;
  9333. var loader = new THREE.XHRLoader( scope.manager );
  9334. loader.setCrossOrigin( this.crossOrigin );
  9335. loader.load( url, function ( text ) {
  9336. scope.parse( JSON.parse( text ), onLoad );
  9337. }, onProgress, onError );
  9338. },
  9339. setTexturePath: function ( value ) {
  9340. this.texturePath = value;
  9341. },
  9342. setCrossOrigin: function ( value ) {
  9343. this.crossOrigin = value;
  9344. },
  9345. parse: function ( json, onLoad ) {
  9346. var geometries = this.parseGeometries( json.geometries );
  9347. var images = this.parseImages( json.images, function () {
  9348. if ( onLoad !== undefined ) onLoad( object );
  9349. } );
  9350. var textures = this.parseTextures( json.textures, images );
  9351. var materials = this.parseMaterials( json.materials, textures );
  9352. var object = this.parseObject( json.object, geometries, materials );
  9353. if ( json.animations ) {
  9354. object.animations = this.parseAnimations( json.animations );
  9355. }
  9356. if ( json.images === undefined || json.images.length === 0 ) {
  9357. if ( onLoad !== undefined ) onLoad( object );
  9358. }
  9359. return object;
  9360. },
  9361. parseGeometries: function ( json ) {
  9362. var geometries = {};
  9363. if ( json !== undefined ) {
  9364. var geometryLoader = new THREE.JSONLoader();
  9365. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  9366. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9367. var geometry;
  9368. var data = json[ i ];
  9369. switch ( data.type ) {
  9370. case 'PlaneGeometry':
  9371. case 'PlaneBufferGeometry':
  9372. geometry = new THREE[ data.type ](
  9373. data.width,
  9374. data.height,
  9375. data.widthSegments,
  9376. data.heightSegments
  9377. );
  9378. break;
  9379. case 'BoxGeometry':
  9380. case 'CubeGeometry': // backwards compatible
  9381. geometry = new THREE.BoxGeometry(
  9382. data.width,
  9383. data.height,
  9384. data.depth,
  9385. data.widthSegments,
  9386. data.heightSegments,
  9387. data.depthSegments
  9388. );
  9389. break;
  9390. case 'CircleBufferGeometry':
  9391. geometry = new THREE.CircleBufferGeometry(
  9392. data.radius,
  9393. data.segments,
  9394. data.thetaStart,
  9395. data.thetaLength
  9396. );
  9397. break;
  9398. case 'CircleGeometry':
  9399. geometry = new THREE.CircleGeometry(
  9400. data.radius,
  9401. data.segments,
  9402. data.thetaStart,
  9403. data.thetaLength
  9404. );
  9405. break;
  9406. case 'CylinderGeometry':
  9407. geometry = new THREE.CylinderGeometry(
  9408. data.radiusTop,
  9409. data.radiusBottom,
  9410. data.height,
  9411. data.radialSegments,
  9412. data.heightSegments,
  9413. data.openEnded,
  9414. data.thetaStart,
  9415. data.thetaLength
  9416. );
  9417. break;
  9418. case 'SphereGeometry':
  9419. geometry = new THREE.SphereGeometry(
  9420. data.radius,
  9421. data.widthSegments,
  9422. data.heightSegments,
  9423. data.phiStart,
  9424. data.phiLength,
  9425. data.thetaStart,
  9426. data.thetaLength
  9427. );
  9428. break;
  9429. case 'SphereBufferGeometry':
  9430. geometry = new THREE.SphereBufferGeometry(
  9431. data.radius,
  9432. data.widthSegments,
  9433. data.heightSegments,
  9434. data.phiStart,
  9435. data.phiLength,
  9436. data.thetaStart,
  9437. data.thetaLength
  9438. );
  9439. break;
  9440. case 'DodecahedronGeometry':
  9441. geometry = new THREE.DodecahedronGeometry(
  9442. data.radius,
  9443. data.detail
  9444. );
  9445. break;
  9446. case 'IcosahedronGeometry':
  9447. geometry = new THREE.IcosahedronGeometry(
  9448. data.radius,
  9449. data.detail
  9450. );
  9451. break;
  9452. case 'OctahedronGeometry':
  9453. geometry = new THREE.OctahedronGeometry(
  9454. data.radius,
  9455. data.detail
  9456. );
  9457. break;
  9458. case 'TetrahedronGeometry':
  9459. geometry = new THREE.TetrahedronGeometry(
  9460. data.radius,
  9461. data.detail
  9462. );
  9463. break;
  9464. case 'RingGeometry':
  9465. geometry = new THREE.RingGeometry(
  9466. data.innerRadius,
  9467. data.outerRadius,
  9468. data.thetaSegments,
  9469. data.phiSegments,
  9470. data.thetaStart,
  9471. data.thetaLength
  9472. );
  9473. break;
  9474. case 'TorusGeometry':
  9475. geometry = new THREE.TorusGeometry(
  9476. data.radius,
  9477. data.tube,
  9478. data.radialSegments,
  9479. data.tubularSegments,
  9480. data.arc
  9481. );
  9482. break;
  9483. case 'TorusKnotGeometry':
  9484. geometry = new THREE.TorusKnotGeometry(
  9485. data.radius,
  9486. data.tube,
  9487. data.radialSegments,
  9488. data.tubularSegments,
  9489. data.p,
  9490. data.q,
  9491. data.heightScale
  9492. );
  9493. break;
  9494. case 'TextGeometry':
  9495. geometry = new THREE.TextGeometry(
  9496. data.text,
  9497. data.data
  9498. );
  9499. break;
  9500. case 'BufferGeometry':
  9501. geometry = bufferGeometryLoader.parse( data );
  9502. break;
  9503. case 'Geometry':
  9504. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  9505. break;
  9506. default:
  9507. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  9508. continue;
  9509. }
  9510. geometry.uuid = data.uuid;
  9511. if ( data.name !== undefined ) geometry.name = data.name;
  9512. geometries[ data.uuid ] = geometry;
  9513. }
  9514. }
  9515. return geometries;
  9516. },
  9517. parseMaterials: function ( json, textures ) {
  9518. var materials = {};
  9519. if ( json !== undefined ) {
  9520. var loader = new THREE.MaterialLoader();
  9521. loader.setTextures( textures );
  9522. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9523. var material = loader.parse( json[ i ] );
  9524. materials[ material.uuid ] = material;
  9525. }
  9526. }
  9527. return materials;
  9528. },
  9529. parseAnimations: function ( json ) {
  9530. var animations = [];
  9531. for ( var i = 0; i < json.length; i ++ ) {
  9532. var clip = THREE.AnimationClip.parse( json[i] );
  9533. animations.push( clip );
  9534. }
  9535. return animations;
  9536. },
  9537. parseImages: function ( json, onLoad ) {
  9538. var scope = this;
  9539. var images = {};
  9540. function loadImage( url ) {
  9541. scope.manager.itemStart( url );
  9542. return loader.load( url, function () {
  9543. scope.manager.itemEnd( url );
  9544. } );
  9545. }
  9546. if ( json !== undefined && json.length > 0 ) {
  9547. var manager = new THREE.LoadingManager( onLoad );
  9548. var loader = new THREE.ImageLoader( manager );
  9549. loader.setCrossOrigin( this.crossOrigin );
  9550. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9551. var image = json[ i ];
  9552. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  9553. images[ image.uuid ] = loadImage( path );
  9554. }
  9555. }
  9556. return images;
  9557. },
  9558. parseTextures: function ( json, images ) {
  9559. function parseConstant( value ) {
  9560. if ( typeof( value ) === 'number' ) return value;
  9561. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  9562. return THREE[ value ];
  9563. }
  9564. var textures = {};
  9565. if ( json !== undefined ) {
  9566. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9567. var data = json[ i ];
  9568. if ( data.image === undefined ) {
  9569. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  9570. }
  9571. if ( images[ data.image ] === undefined ) {
  9572. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  9573. }
  9574. var texture = new THREE.Texture( images[ data.image ] );
  9575. texture.needsUpdate = true;
  9576. texture.uuid = data.uuid;
  9577. if ( data.name !== undefined ) texture.name = data.name;
  9578. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  9579. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  9580. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  9581. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  9582. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  9583. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  9584. if ( Array.isArray( data.wrap ) ) {
  9585. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  9586. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  9587. }
  9588. textures[ data.uuid ] = texture;
  9589. }
  9590. }
  9591. return textures;
  9592. },
  9593. parseObject: function () {
  9594. var matrix = new THREE.Matrix4();
  9595. return function ( data, geometries, materials ) {
  9596. var object;
  9597. function getGeometry( name ) {
  9598. if ( geometries[ name ] === undefined ) {
  9599. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  9600. }
  9601. return geometries[ name ];
  9602. }
  9603. function getMaterial( name ) {
  9604. if ( name === undefined ) return undefined;
  9605. if ( materials[ name ] === undefined ) {
  9606. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  9607. }
  9608. return materials[ name ];
  9609. }
  9610. switch ( data.type ) {
  9611. case 'Scene':
  9612. object = new THREE.Scene();
  9613. break;
  9614. case 'PerspectiveCamera':
  9615. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  9616. break;
  9617. case 'OrthographicCamera':
  9618. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  9619. break;
  9620. case 'AmbientLight':
  9621. object = new THREE.AmbientLight( data.color );
  9622. break;
  9623. case 'DirectionalLight':
  9624. object = new THREE.DirectionalLight( data.color, data.intensity );
  9625. break;
  9626. case 'PointLight':
  9627. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  9628. break;
  9629. case 'SpotLight':
  9630. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  9631. break;
  9632. case 'HemisphereLight':
  9633. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  9634. break;
  9635. case 'Mesh':
  9636. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  9637. break;
  9638. case 'LOD':
  9639. object = new THREE.LOD();
  9640. break;
  9641. case 'Line':
  9642. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  9643. break;
  9644. case 'PointCloud':
  9645. case 'Points':
  9646. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  9647. break;
  9648. case 'Sprite':
  9649. object = new THREE.Sprite( getMaterial( data.material ) );
  9650. break;
  9651. case 'Group':
  9652. object = new THREE.Group();
  9653. break;
  9654. default:
  9655. object = new THREE.Object3D();
  9656. }
  9657. object.uuid = data.uuid;
  9658. if ( data.name !== undefined ) object.name = data.name;
  9659. if ( data.matrix !== undefined ) {
  9660. matrix.fromArray( data.matrix );
  9661. matrix.decompose( object.position, object.quaternion, object.scale );
  9662. } else {
  9663. if ( data.position !== undefined ) object.position.fromArray( data.position );
  9664. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  9665. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  9666. }
  9667. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  9668. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  9669. if ( data.visible !== undefined ) object.visible = data.visible;
  9670. if ( data.userData !== undefined ) object.userData = data.userData;
  9671. if ( data.children !== undefined ) {
  9672. for ( var child in data.children ) {
  9673. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  9674. }
  9675. }
  9676. if ( data.type === 'LOD' ) {
  9677. var levels = data.levels;
  9678. for ( var l = 0; l < levels.length; l ++ ) {
  9679. var level = levels[ l ];
  9680. var child = object.getObjectByProperty( 'uuid', level.object );
  9681. if ( child !== undefined ) {
  9682. object.addLevel( child, level.distance );
  9683. }
  9684. }
  9685. }
  9686. return object;
  9687. }
  9688. }()
  9689. };
  9690. // File:src/loaders/TextureLoader.js
  9691. /**
  9692. * @author mrdoob / http://mrdoob.com/
  9693. */
  9694. THREE.TextureLoader = function ( manager ) {
  9695. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9696. };
  9697. THREE.TextureLoader.prototype = {
  9698. constructor: THREE.TextureLoader,
  9699. load: function ( url, onLoad, onProgress, onError ) {
  9700. var scope = this;
  9701. var loader = new THREE.ImageLoader( scope.manager );
  9702. loader.setCrossOrigin( this.crossOrigin );
  9703. loader.load( url, function ( image ) {
  9704. var texture = new THREE.Texture( image );
  9705. texture.needsUpdate = true;
  9706. if ( onLoad !== undefined ) {
  9707. onLoad( texture );
  9708. }
  9709. }, onProgress, onError );
  9710. },
  9711. setCrossOrigin: function ( value ) {
  9712. this.crossOrigin = value;
  9713. }
  9714. };
  9715. // File:src/loaders/BinaryTextureLoader.js
  9716. /**
  9717. * @author Nikos M. / https://github.com/foo123/
  9718. *
  9719. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  9720. */
  9721. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  9722. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9723. // override in sub classes
  9724. this._parser = null;
  9725. };
  9726. THREE.BinaryTextureLoader.prototype = {
  9727. constructor: THREE.BinaryTextureLoader,
  9728. load: function ( url, onLoad, onProgress, onError ) {
  9729. var scope = this;
  9730. var texture = new THREE.DataTexture();
  9731. var loader = new THREE.XHRLoader( this.manager );
  9732. loader.setCrossOrigin( this.crossOrigin );
  9733. loader.setResponseType( 'arraybuffer' );
  9734. loader.load( url, function ( buffer ) {
  9735. var texData = scope._parser( buffer );
  9736. if ( ! texData ) return;
  9737. if ( undefined !== texData.image ) {
  9738. texture.image = texData.image;
  9739. } else if ( undefined !== texData.data ) {
  9740. texture.image.width = texData.width;
  9741. texture.image.height = texData.height;
  9742. texture.image.data = texData.data;
  9743. }
  9744. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  9745. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  9746. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  9747. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  9748. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  9749. if ( undefined !== texData.format ) {
  9750. texture.format = texData.format;
  9751. }
  9752. if ( undefined !== texData.type ) {
  9753. texture.type = texData.type;
  9754. }
  9755. if ( undefined !== texData.mipmaps ) {
  9756. texture.mipmaps = texData.mipmaps;
  9757. }
  9758. if ( 1 === texData.mipmapCount ) {
  9759. texture.minFilter = THREE.LinearFilter;
  9760. }
  9761. texture.needsUpdate = true;
  9762. if ( onLoad ) onLoad( texture, texData );
  9763. }, onProgress, onError );
  9764. return texture;
  9765. },
  9766. setCrossOrigin: function ( value ) {
  9767. this.crossOrigin = value;
  9768. }
  9769. };
  9770. // File:src/loaders/CompressedTextureLoader.js
  9771. /**
  9772. * @author mrdoob / http://mrdoob.com/
  9773. *
  9774. * Abstract Base class to block based textures loader (dds, pvr, ...)
  9775. */
  9776. THREE.CompressedTextureLoader = function ( manager ) {
  9777. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9778. // override in sub classes
  9779. this._parser = null;
  9780. };
  9781. THREE.CompressedTextureLoader.prototype = {
  9782. constructor: THREE.CompressedTextureLoader,
  9783. load: function ( url, onLoad, onProgress, onError ) {
  9784. var scope = this;
  9785. var images = [];
  9786. var texture = new THREE.CompressedTexture();
  9787. texture.image = images;
  9788. var loader = new THREE.XHRLoader( this.manager );
  9789. loader.setCrossOrigin( this.crossOrigin );
  9790. loader.setResponseType( 'arraybuffer' );
  9791. if ( Array.isArray( url ) ) {
  9792. var loaded = 0;
  9793. var loadTexture = function ( i ) {
  9794. loader.load( url[ i ], function ( buffer ) {
  9795. var texDatas = scope._parser( buffer, true );
  9796. images[ i ] = {
  9797. width: texDatas.width,
  9798. height: texDatas.height,
  9799. format: texDatas.format,
  9800. mipmaps: texDatas.mipmaps
  9801. };
  9802. loaded += 1;
  9803. if ( loaded === 6 ) {
  9804. if ( texDatas.mipmapCount === 1 )
  9805. texture.minFilter = THREE.LinearFilter;
  9806. texture.format = texDatas.format;
  9807. texture.needsUpdate = true;
  9808. if ( onLoad ) onLoad( texture );
  9809. }
  9810. }, onProgress, onError );
  9811. };
  9812. for ( var i = 0, il = url.length; i < il; ++ i ) {
  9813. loadTexture( i );
  9814. }
  9815. } else {
  9816. // compressed cubemap texture stored in a single DDS file
  9817. loader.load( url, function ( buffer ) {
  9818. var texDatas = scope._parser( buffer, true );
  9819. if ( texDatas.isCubemap ) {
  9820. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  9821. for ( var f = 0; f < faces; f ++ ) {
  9822. images[ f ] = { mipmaps : [] };
  9823. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  9824. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  9825. images[ f ].format = texDatas.format;
  9826. images[ f ].width = texDatas.width;
  9827. images[ f ].height = texDatas.height;
  9828. }
  9829. }
  9830. } else {
  9831. texture.image.width = texDatas.width;
  9832. texture.image.height = texDatas.height;
  9833. texture.mipmaps = texDatas.mipmaps;
  9834. }
  9835. if ( texDatas.mipmapCount === 1 ) {
  9836. texture.minFilter = THREE.LinearFilter;
  9837. }
  9838. texture.format = texDatas.format;
  9839. texture.needsUpdate = true;
  9840. if ( onLoad ) onLoad( texture );
  9841. }, onProgress, onError );
  9842. }
  9843. return texture;
  9844. },
  9845. setCrossOrigin: function ( value ) {
  9846. this.crossOrigin = value;
  9847. }
  9848. };
  9849. // File:src/materials/Material.js
  9850. /**
  9851. * @author mrdoob / http://mrdoob.com/
  9852. * @author alteredq / http://alteredqualia.com/
  9853. */
  9854. THREE.Material = function () {
  9855. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  9856. this.uuid = THREE.Math.generateUUID();
  9857. this.name = '';
  9858. this.type = 'Material';
  9859. this.side = THREE.FrontSide;
  9860. this.opacity = 1;
  9861. this.transparent = false;
  9862. this.blending = THREE.NormalBlending;
  9863. this.blendSrc = THREE.SrcAlphaFactor;
  9864. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  9865. this.blendEquation = THREE.AddEquation;
  9866. this.blendSrcAlpha = null;
  9867. this.blendDstAlpha = null;
  9868. this.blendEquationAlpha = null;
  9869. this.depthFunc = THREE.LessEqualDepth;
  9870. this.depthTest = true;
  9871. this.depthWrite = true;
  9872. this.colorWrite = true;
  9873. this.precision = null; // override the renderer's default precision for this material
  9874. this.polygonOffset = false;
  9875. this.polygonOffsetFactor = 0;
  9876. this.polygonOffsetUnits = 0;
  9877. this.alphaTest = 0;
  9878. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  9879. this.visible = true;
  9880. this._needsUpdate = true;
  9881. };
  9882. THREE.Material.prototype = {
  9883. constructor: THREE.Material,
  9884. get needsUpdate () {
  9885. return this._needsUpdate;
  9886. },
  9887. set needsUpdate ( value ) {
  9888. if ( value === true ) this.update();
  9889. this._needsUpdate = value;
  9890. },
  9891. setValues: function ( values ) {
  9892. if ( values === undefined ) return;
  9893. for ( var key in values ) {
  9894. var newValue = values[ key ];
  9895. if ( newValue === undefined ) {
  9896. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  9897. continue;
  9898. }
  9899. var currentValue = this[ key ];
  9900. if ( currentValue === undefined ) {
  9901. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  9902. continue;
  9903. }
  9904. if ( currentValue instanceof THREE.Color ) {
  9905. currentValue.set( newValue );
  9906. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  9907. currentValue.copy( newValue );
  9908. } else if ( key === 'overdraw' ) {
  9909. // ensure overdraw is backwards-compatible with legacy boolean type
  9910. this[ key ] = Number( newValue );
  9911. } else {
  9912. this[ key ] = newValue;
  9913. }
  9914. }
  9915. },
  9916. toJSON: function ( meta ) {
  9917. var data = {
  9918. metadata: {
  9919. version: 4.4,
  9920. type: 'Material',
  9921. generator: 'Material.toJSON'
  9922. }
  9923. };
  9924. // standard Material serialization
  9925. data.uuid = this.uuid;
  9926. data.type = this.type;
  9927. if ( this.name !== '' ) data.name = this.name;
  9928. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  9929. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  9930. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  9931. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  9932. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  9933. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  9934. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  9935. if ( this.bumpMap instanceof THREE.Texture ) {
  9936. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  9937. data.bumpScale = this.bumpScale;
  9938. }
  9939. if ( this.normalMap instanceof THREE.Texture ) {
  9940. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  9941. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  9942. }
  9943. if ( this.displacementMap instanceof THREE.Texture ) {
  9944. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  9945. data.displacementScale = this.displacementScale;
  9946. data.displacementBias = this.displacementBias;
  9947. }
  9948. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  9949. if ( this.envMap instanceof THREE.Texture ) {
  9950. data.envMap = this.envMap.toJSON( meta ).uuid;
  9951. data.reflectivity = this.reflectivity; // Scale behind envMap
  9952. }
  9953. if ( this.size !== undefined ) data.size = this.size;
  9954. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  9955. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  9956. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  9957. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  9958. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  9959. if ( this.opacity < 1 ) data.opacity = this.opacity;
  9960. if ( this.transparent === true ) data.transparent = this.transparent;
  9961. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  9962. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  9963. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  9964. return data;
  9965. },
  9966. clone: function () {
  9967. return new this.constructor().copy( this );
  9968. },
  9969. copy: function ( source ) {
  9970. this.name = source.name;
  9971. this.side = source.side;
  9972. this.opacity = source.opacity;
  9973. this.transparent = source.transparent;
  9974. this.blending = source.blending;
  9975. this.blendSrc = source.blendSrc;
  9976. this.blendDst = source.blendDst;
  9977. this.blendEquation = source.blendEquation;
  9978. this.blendSrcAlpha = source.blendSrcAlpha;
  9979. this.blendDstAlpha = source.blendDstAlpha;
  9980. this.blendEquationAlpha = source.blendEquationAlpha;
  9981. this.depthFunc = source.depthFunc;
  9982. this.depthTest = source.depthTest;
  9983. this.depthWrite = source.depthWrite;
  9984. this.precision = source.precision;
  9985. this.polygonOffset = source.polygonOffset;
  9986. this.polygonOffsetFactor = source.polygonOffsetFactor;
  9987. this.polygonOffsetUnits = source.polygonOffsetUnits;
  9988. this.alphaTest = source.alphaTest;
  9989. this.overdraw = source.overdraw;
  9990. this.visible = source.visible;
  9991. return this;
  9992. },
  9993. update: function () {
  9994. this.dispatchEvent( { type: 'update' } );
  9995. },
  9996. dispose: function () {
  9997. this.dispatchEvent( { type: 'dispose' } );
  9998. },
  9999. // Deprecated
  10000. get wrapAround () {
  10001. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  10002. },
  10003. set wrapAround ( boolean ) {
  10004. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  10005. },
  10006. get wrapRGB () {
  10007. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  10008. return new THREE.Color();
  10009. }
  10010. };
  10011. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  10012. THREE.MaterialIdCount = 0;
  10013. // File:src/materials/LineBasicMaterial.js
  10014. /**
  10015. * @author mrdoob / http://mrdoob.com/
  10016. * @author alteredq / http://alteredqualia.com/
  10017. *
  10018. * parameters = {
  10019. * color: <hex>,
  10020. * opacity: <float>,
  10021. *
  10022. * blending: THREE.NormalBlending,
  10023. * depthTest: <bool>,
  10024. * depthWrite: <bool>,
  10025. *
  10026. * linewidth: <float>,
  10027. * linecap: "round",
  10028. * linejoin: "round",
  10029. *
  10030. * vertexColors: <bool>
  10031. *
  10032. * fog: <bool>
  10033. * }
  10034. */
  10035. THREE.LineBasicMaterial = function ( parameters ) {
  10036. THREE.Material.call( this );
  10037. this.type = 'LineBasicMaterial';
  10038. this.color = new THREE.Color( 0xffffff );
  10039. this.linewidth = 1;
  10040. this.linecap = 'round';
  10041. this.linejoin = 'round';
  10042. this.vertexColors = THREE.NoColors;
  10043. this.fog = true;
  10044. this.setValues( parameters );
  10045. };
  10046. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  10047. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  10048. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  10049. THREE.Material.prototype.copy.call( this, source );
  10050. this.color.copy( source.color );
  10051. this.linewidth = source.linewidth;
  10052. this.linecap = source.linecap;
  10053. this.linejoin = source.linejoin;
  10054. this.vertexColors = source.vertexColors;
  10055. this.fog = source.fog;
  10056. return this;
  10057. };
  10058. // File:src/materials/LineDashedMaterial.js
  10059. /**
  10060. * @author alteredq / http://alteredqualia.com/
  10061. *
  10062. * parameters = {
  10063. * color: <hex>,
  10064. * opacity: <float>,
  10065. *
  10066. * blending: THREE.NormalBlending,
  10067. * depthTest: <bool>,
  10068. * depthWrite: <bool>,
  10069. *
  10070. * linewidth: <float>,
  10071. *
  10072. * scale: <float>,
  10073. * dashSize: <float>,
  10074. * gapSize: <float>,
  10075. *
  10076. * vertexColors: <bool>
  10077. *
  10078. * fog: <bool>
  10079. * }
  10080. */
  10081. THREE.LineDashedMaterial = function ( parameters ) {
  10082. THREE.Material.call( this );
  10083. this.type = 'LineDashedMaterial';
  10084. this.color = new THREE.Color( 0xffffff );
  10085. this.linewidth = 1;
  10086. this.scale = 1;
  10087. this.dashSize = 3;
  10088. this.gapSize = 1;
  10089. this.vertexColors = false;
  10090. this.fog = true;
  10091. this.setValues( parameters );
  10092. };
  10093. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  10094. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  10095. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  10096. THREE.Material.prototype.copy.call( this, source );
  10097. this.color.copy( source.color );
  10098. this.linewidth = source.linewidth;
  10099. this.scale = source.scale;
  10100. this.dashSize = source.dashSize;
  10101. this.gapSize = source.gapSize;
  10102. this.vertexColors = source.vertexColors;
  10103. this.fog = source.fog;
  10104. return this;
  10105. };
  10106. // File:src/materials/MeshBasicMaterial.js
  10107. /**
  10108. * @author mrdoob / http://mrdoob.com/
  10109. * @author alteredq / http://alteredqualia.com/
  10110. *
  10111. * parameters = {
  10112. * color: <hex>,
  10113. * opacity: <float>,
  10114. * map: new THREE.Texture( <Image> ),
  10115. *
  10116. * aoMap: new THREE.Texture( <Image> ),
  10117. * aoMapIntensity: <float>
  10118. *
  10119. * specularMap: new THREE.Texture( <Image> ),
  10120. *
  10121. * alphaMap: new THREE.Texture( <Image> ),
  10122. *
  10123. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10124. * combine: THREE.Multiply,
  10125. * reflectivity: <float>,
  10126. * refractionRatio: <float>,
  10127. *
  10128. * shading: THREE.SmoothShading,
  10129. * blending: THREE.NormalBlending,
  10130. * depthTest: <bool>,
  10131. * depthWrite: <bool>,
  10132. *
  10133. * wireframe: <boolean>,
  10134. * wireframeLinewidth: <float>,
  10135. *
  10136. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10137. *
  10138. * skinning: <bool>,
  10139. * morphTargets: <bool>,
  10140. *
  10141. * fog: <bool>
  10142. * }
  10143. */
  10144. THREE.MeshBasicMaterial = function ( parameters ) {
  10145. THREE.Material.call( this );
  10146. this.type = 'MeshBasicMaterial';
  10147. this.color = new THREE.Color( 0xffffff ); // emissive
  10148. this.map = null;
  10149. this.aoMap = null;
  10150. this.aoMapIntensity = 1.0;
  10151. this.specularMap = null;
  10152. this.alphaMap = null;
  10153. this.envMap = null;
  10154. this.combine = THREE.MultiplyOperation;
  10155. this.reflectivity = 1;
  10156. this.refractionRatio = 0.98;
  10157. this.fog = true;
  10158. this.shading = THREE.SmoothShading;
  10159. this.wireframe = false;
  10160. this.wireframeLinewidth = 1;
  10161. this.wireframeLinecap = 'round';
  10162. this.wireframeLinejoin = 'round';
  10163. this.vertexColors = THREE.NoColors;
  10164. this.skinning = false;
  10165. this.morphTargets = false;
  10166. this.setValues( parameters );
  10167. };
  10168. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  10169. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  10170. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  10171. THREE.Material.prototype.copy.call( this, source );
  10172. this.color.copy( source.color );
  10173. this.map = source.map;
  10174. this.aoMap = source.aoMap;
  10175. this.aoMapIntensity = source.aoMapIntensity;
  10176. this.specularMap = source.specularMap;
  10177. this.alphaMap = source.alphaMap;
  10178. this.envMap = source.envMap;
  10179. this.combine = source.combine;
  10180. this.reflectivity = source.reflectivity;
  10181. this.refractionRatio = source.refractionRatio;
  10182. this.fog = source.fog;
  10183. this.shading = source.shading;
  10184. this.wireframe = source.wireframe;
  10185. this.wireframeLinewidth = source.wireframeLinewidth;
  10186. this.wireframeLinecap = source.wireframeLinecap;
  10187. this.wireframeLinejoin = source.wireframeLinejoin;
  10188. this.vertexColors = source.vertexColors;
  10189. this.skinning = source.skinning;
  10190. this.morphTargets = source.morphTargets;
  10191. return this;
  10192. };
  10193. // File:src/materials/MeshLambertMaterial.js
  10194. /**
  10195. * @author mrdoob / http://mrdoob.com/
  10196. * @author alteredq / http://alteredqualia.com/
  10197. *
  10198. * parameters = {
  10199. * color: <hex>,
  10200. * emissive: <hex>,
  10201. * opacity: <float>,
  10202. *
  10203. * map: new THREE.Texture( <Image> ),
  10204. *
  10205. * specularMap: new THREE.Texture( <Image> ),
  10206. *
  10207. * alphaMap: new THREE.Texture( <Image> ),
  10208. *
  10209. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10210. * combine: THREE.Multiply,
  10211. * reflectivity: <float>,
  10212. * refractionRatio: <float>,
  10213. *
  10214. * blending: THREE.NormalBlending,
  10215. * depthTest: <bool>,
  10216. * depthWrite: <bool>,
  10217. *
  10218. * wireframe: <boolean>,
  10219. * wireframeLinewidth: <float>,
  10220. *
  10221. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10222. *
  10223. * skinning: <bool>,
  10224. * morphTargets: <bool>,
  10225. * morphNormals: <bool>,
  10226. *
  10227. * fog: <bool>
  10228. * }
  10229. */
  10230. THREE.MeshLambertMaterial = function ( parameters ) {
  10231. THREE.Material.call( this );
  10232. this.type = 'MeshLambertMaterial';
  10233. this.color = new THREE.Color( 0xffffff ); // diffuse
  10234. this.emissive = new THREE.Color( 0x000000 );
  10235. this.map = null;
  10236. this.specularMap = null;
  10237. this.alphaMap = null;
  10238. this.envMap = null;
  10239. this.combine = THREE.MultiplyOperation;
  10240. this.reflectivity = 1;
  10241. this.refractionRatio = 0.98;
  10242. this.fog = true;
  10243. this.wireframe = false;
  10244. this.wireframeLinewidth = 1;
  10245. this.wireframeLinecap = 'round';
  10246. this.wireframeLinejoin = 'round';
  10247. this.vertexColors = THREE.NoColors;
  10248. this.skinning = false;
  10249. this.morphTargets = false;
  10250. this.morphNormals = false;
  10251. this.setValues( parameters );
  10252. };
  10253. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  10254. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  10255. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  10256. THREE.Material.prototype.copy.call( this, source );
  10257. this.color.copy( source.color );
  10258. this.emissive.copy( source.emissive );
  10259. this.map = source.map;
  10260. this.specularMap = source.specularMap;
  10261. this.alphaMap = source.alphaMap;
  10262. this.envMap = source.envMap;
  10263. this.combine = source.combine;
  10264. this.reflectivity = source.reflectivity;
  10265. this.refractionRatio = source.refractionRatio;
  10266. this.fog = source.fog;
  10267. this.wireframe = source.wireframe;
  10268. this.wireframeLinewidth = source.wireframeLinewidth;
  10269. this.wireframeLinecap = source.wireframeLinecap;
  10270. this.wireframeLinejoin = source.wireframeLinejoin;
  10271. this.vertexColors = source.vertexColors;
  10272. this.skinning = source.skinning;
  10273. this.morphTargets = source.morphTargets;
  10274. this.morphNormals = source.morphNormals;
  10275. return this;
  10276. };
  10277. // File:src/materials/MeshPhongMaterial.js
  10278. /**
  10279. * @author mrdoob / http://mrdoob.com/
  10280. * @author alteredq / http://alteredqualia.com/
  10281. *
  10282. * parameters = {
  10283. * color: <hex>,
  10284. * emissive: <hex>,
  10285. * specular: <hex>,
  10286. * shininess: <float>,
  10287. * opacity: <float>,
  10288. *
  10289. * map: new THREE.Texture( <Image> ),
  10290. *
  10291. * lightMap: new THREE.Texture( <Image> ),
  10292. * lightMapIntensity: <float>
  10293. *
  10294. * aoMap: new THREE.Texture( <Image> ),
  10295. * aoMapIntensity: <float>
  10296. *
  10297. * emissiveMap: new THREE.Texture( <Image> ),
  10298. *
  10299. * bumpMap: new THREE.Texture( <Image> ),
  10300. * bumpScale: <float>,
  10301. *
  10302. * normalMap: new THREE.Texture( <Image> ),
  10303. * normalScale: <Vector2>,
  10304. *
  10305. * displacementMap: new THREE.Texture( <Image> ),
  10306. * displacementScale: <float>,
  10307. * displacementBias: <float>,
  10308. *
  10309. * specularMap: new THREE.Texture( <Image> ),
  10310. *
  10311. * alphaMap: new THREE.Texture( <Image> ),
  10312. *
  10313. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10314. * combine: THREE.Multiply,
  10315. * reflectivity: <float>,
  10316. * refractionRatio: <float>,
  10317. *
  10318. * shading: THREE.SmoothShading,
  10319. * blending: THREE.NormalBlending,
  10320. * depthTest: <bool>,
  10321. * depthWrite: <bool>,
  10322. *
  10323. * wireframe: <boolean>,
  10324. * wireframeLinewidth: <float>,
  10325. *
  10326. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10327. *
  10328. * skinning: <bool>,
  10329. * morphTargets: <bool>,
  10330. * morphNormals: <bool>,
  10331. *
  10332. * fog: <bool>
  10333. * }
  10334. */
  10335. THREE.MeshPhongMaterial = function ( parameters ) {
  10336. THREE.Material.call( this );
  10337. this.type = 'MeshPhongMaterial';
  10338. this.color = new THREE.Color( 0xffffff ); // diffuse
  10339. this.emissive = new THREE.Color( 0x000000 );
  10340. this.specular = new THREE.Color( 0x111111 );
  10341. this.shininess = 30;
  10342. this.metal = false;
  10343. this.map = null;
  10344. this.lightMap = null;
  10345. this.lightMapIntensity = 1.0;
  10346. this.aoMap = null;
  10347. this.aoMapIntensity = 1.0;
  10348. this.emissiveMap = null;
  10349. this.bumpMap = null;
  10350. this.bumpScale = 1;
  10351. this.normalMap = null;
  10352. this.normalScale = new THREE.Vector2( 1, 1 );
  10353. this.displacementMap = null;
  10354. this.displacementScale = 1;
  10355. this.displacementBias = 0;
  10356. this.specularMap = null;
  10357. this.alphaMap = null;
  10358. this.envMap = null;
  10359. this.combine = THREE.MultiplyOperation;
  10360. this.reflectivity = 1;
  10361. this.refractionRatio = 0.98;
  10362. this.fog = true;
  10363. this.shading = THREE.SmoothShading;
  10364. this.wireframe = false;
  10365. this.wireframeLinewidth = 1;
  10366. this.wireframeLinecap = 'round';
  10367. this.wireframeLinejoin = 'round';
  10368. this.vertexColors = THREE.NoColors;
  10369. this.skinning = false;
  10370. this.morphTargets = false;
  10371. this.morphNormals = false;
  10372. this.setValues( parameters );
  10373. };
  10374. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  10375. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  10376. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  10377. THREE.Material.prototype.copy.call( this, source );
  10378. this.color.copy( source.color );
  10379. this.emissive.copy( source.emissive );
  10380. this.specular.copy( source.specular );
  10381. this.shininess = source.shininess;
  10382. this.metal = source.metal;
  10383. this.map = source.map;
  10384. this.lightMap = source.lightMap;
  10385. this.lightMapIntensity = source.lightMapIntensity;
  10386. this.aoMap = source.aoMap;
  10387. this.aoMapIntensity = source.aoMapIntensity;
  10388. this.emissiveMap = source.emissiveMap;
  10389. this.bumpMap = source.bumpMap;
  10390. this.bumpScale = source.bumpScale;
  10391. this.normalMap = source.normalMap;
  10392. this.normalScale.copy( source.normalScale );
  10393. this.displacementMap = source.displacementMap;
  10394. this.displacementScale = source.displacementScale;
  10395. this.displacementBias = source.displacementBias;
  10396. this.specularMap = source.specularMap;
  10397. this.alphaMap = source.alphaMap;
  10398. this.envMap = source.envMap;
  10399. this.combine = source.combine;
  10400. this.reflectivity = source.reflectivity;
  10401. this.refractionRatio = source.refractionRatio;
  10402. this.fog = source.fog;
  10403. this.shading = source.shading;
  10404. this.wireframe = source.wireframe;
  10405. this.wireframeLinewidth = source.wireframeLinewidth;
  10406. this.wireframeLinecap = source.wireframeLinecap;
  10407. this.wireframeLinejoin = source.wireframeLinejoin;
  10408. this.vertexColors = source.vertexColors;
  10409. this.skinning = source.skinning;
  10410. this.morphTargets = source.morphTargets;
  10411. this.morphNormals = source.morphNormals;
  10412. return this;
  10413. };
  10414. // File:src/materials/MeshDepthMaterial.js
  10415. /**
  10416. * @author mrdoob / http://mrdoob.com/
  10417. * @author alteredq / http://alteredqualia.com/
  10418. *
  10419. * parameters = {
  10420. * opacity: <float>,
  10421. *
  10422. * blending: THREE.NormalBlending,
  10423. * depthTest: <bool>,
  10424. * depthWrite: <bool>,
  10425. *
  10426. * wireframe: <boolean>,
  10427. * wireframeLinewidth: <float>
  10428. * }
  10429. */
  10430. THREE.MeshDepthMaterial = function ( parameters ) {
  10431. THREE.Material.call( this );
  10432. this.type = 'MeshDepthMaterial';
  10433. this.morphTargets = false;
  10434. this.wireframe = false;
  10435. this.wireframeLinewidth = 1;
  10436. this.setValues( parameters );
  10437. };
  10438. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  10439. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  10440. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  10441. THREE.Material.prototype.copy.call( this, source );
  10442. this.wireframe = source.wireframe;
  10443. this.wireframeLinewidth = source.wireframeLinewidth;
  10444. return this;
  10445. };
  10446. // File:src/materials/MeshNormalMaterial.js
  10447. /**
  10448. * @author mrdoob / http://mrdoob.com/
  10449. *
  10450. * parameters = {
  10451. * opacity: <float>,
  10452. *
  10453. * shading: THREE.FlatShading,
  10454. * blending: THREE.NormalBlending,
  10455. * depthTest: <bool>,
  10456. * depthWrite: <bool>,
  10457. *
  10458. * wireframe: <boolean>,
  10459. * wireframeLinewidth: <float>
  10460. * }
  10461. */
  10462. THREE.MeshNormalMaterial = function ( parameters ) {
  10463. THREE.Material.call( this, parameters );
  10464. this.type = 'MeshNormalMaterial';
  10465. this.wireframe = false;
  10466. this.wireframeLinewidth = 1;
  10467. this.morphTargets = false;
  10468. this.setValues( parameters );
  10469. };
  10470. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  10471. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  10472. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  10473. THREE.Material.prototype.copy.call( this, source );
  10474. this.wireframe = source.wireframe;
  10475. this.wireframeLinewidth = source.wireframeLinewidth;
  10476. return this;
  10477. };
  10478. // File:src/materials/MultiMaterial.js
  10479. /**
  10480. * @author mrdoob / http://mrdoob.com/
  10481. */
  10482. THREE.MultiMaterial = function ( materials ) {
  10483. this.uuid = THREE.Math.generateUUID();
  10484. this.type = 'MultiMaterial';
  10485. this.materials = materials instanceof Array ? materials : [];
  10486. this.visible = true;
  10487. };
  10488. THREE.MultiMaterial.prototype = {
  10489. constructor: THREE.MultiMaterial,
  10490. toJSON: function () {
  10491. var output = {
  10492. metadata: {
  10493. version: 4.2,
  10494. type: 'material',
  10495. generator: 'MaterialExporter'
  10496. },
  10497. uuid: this.uuid,
  10498. type: this.type,
  10499. materials: []
  10500. };
  10501. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  10502. output.materials.push( this.materials[ i ].toJSON() );
  10503. }
  10504. output.visible = this.visible;
  10505. return output;
  10506. },
  10507. clone: function () {
  10508. var material = new this.constructor();
  10509. for ( var i = 0; i < this.materials.length; i ++ ) {
  10510. material.materials.push( this.materials[ i ].clone() );
  10511. }
  10512. material.visible = this.visible;
  10513. return material;
  10514. }
  10515. };
  10516. // backwards compatibility
  10517. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  10518. // File:src/materials/PointsMaterial.js
  10519. /**
  10520. * @author mrdoob / http://mrdoob.com/
  10521. * @author alteredq / http://alteredqualia.com/
  10522. *
  10523. * parameters = {
  10524. * color: <hex>,
  10525. * opacity: <float>,
  10526. * map: new THREE.Texture( <Image> ),
  10527. *
  10528. * size: <float>,
  10529. * sizeAttenuation: <bool>,
  10530. *
  10531. * blending: THREE.NormalBlending,
  10532. * depthTest: <bool>,
  10533. * depthWrite: <bool>,
  10534. *
  10535. * vertexColors: <bool>,
  10536. *
  10537. * fog: <bool>
  10538. * }
  10539. */
  10540. THREE.PointsMaterial = function ( parameters ) {
  10541. THREE.Material.call( this );
  10542. this.type = 'PointsMaterial';
  10543. this.color = new THREE.Color( 0xffffff );
  10544. this.map = null;
  10545. this.size = 1;
  10546. this.sizeAttenuation = true;
  10547. this.vertexColors = THREE.NoColors;
  10548. this.fog = true;
  10549. this.setValues( parameters );
  10550. };
  10551. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  10552. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  10553. THREE.PointsMaterial.prototype.copy = function ( source ) {
  10554. THREE.Material.prototype.copy.call( this, source );
  10555. this.color.copy( source.color );
  10556. this.map = source.map;
  10557. this.size = source.size;
  10558. this.sizeAttenuation = source.sizeAttenuation;
  10559. this.vertexColors = source.vertexColors;
  10560. this.fog = source.fog;
  10561. return this;
  10562. };
  10563. // backwards compatibility
  10564. THREE.PointCloudMaterial = function ( parameters ) {
  10565. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  10566. return new THREE.PointsMaterial( parameters );
  10567. };
  10568. THREE.ParticleBasicMaterial = function ( parameters ) {
  10569. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  10570. return new THREE.PointsMaterial( parameters );
  10571. };
  10572. THREE.ParticleSystemMaterial = function ( parameters ) {
  10573. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  10574. return new THREE.PointsMaterial( parameters );
  10575. };
  10576. // File:src/materials/ShaderMaterial.js
  10577. /**
  10578. * @author alteredq / http://alteredqualia.com/
  10579. *
  10580. * parameters = {
  10581. * defines: { "label" : "value" },
  10582. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  10583. *
  10584. * fragmentShader: <string>,
  10585. * vertexShader: <string>,
  10586. *
  10587. * shading: THREE.SmoothShading,
  10588. * blending: THREE.NormalBlending,
  10589. * depthTest: <bool>,
  10590. * depthWrite: <bool>,
  10591. *
  10592. * wireframe: <boolean>,
  10593. * wireframeLinewidth: <float>,
  10594. *
  10595. * lights: <bool>,
  10596. *
  10597. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10598. *
  10599. * skinning: <bool>,
  10600. * morphTargets: <bool>,
  10601. * morphNormals: <bool>,
  10602. *
  10603. * fog: <bool>
  10604. * }
  10605. */
  10606. THREE.ShaderMaterial = function ( parameters ) {
  10607. THREE.Material.call( this );
  10608. this.type = 'ShaderMaterial';
  10609. this.defines = {};
  10610. this.uniforms = {};
  10611. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  10612. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  10613. this.shading = THREE.SmoothShading;
  10614. this.linewidth = 1;
  10615. this.wireframe = false;
  10616. this.wireframeLinewidth = 1;
  10617. this.fog = false; // set to use scene fog
  10618. this.lights = false; // set to use scene lights
  10619. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  10620. this.skinning = false; // set to use skinning attribute streams
  10621. this.morphTargets = false; // set to use morph targets
  10622. this.morphNormals = false; // set to use morph normals
  10623. this.derivatives = false; // set to use derivatives
  10624. // When rendered geometry doesn't include these attributes but the material does,
  10625. // use these default values in WebGL. This avoids errors when buffer data is missing.
  10626. this.defaultAttributeValues = {
  10627. 'color': [ 1, 1, 1 ],
  10628. 'uv': [ 0, 0 ],
  10629. 'uv2': [ 0, 0 ]
  10630. };
  10631. this.index0AttributeName = undefined;
  10632. if ( parameters !== undefined ) {
  10633. if ( parameters.attributes !== undefined ) {
  10634. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  10635. }
  10636. this.setValues( parameters );
  10637. }
  10638. };
  10639. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  10640. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  10641. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  10642. THREE.Material.prototype.copy.call( this, source );
  10643. this.fragmentShader = source.fragmentShader;
  10644. this.vertexShader = source.vertexShader;
  10645. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  10646. this.attributes = source.attributes;
  10647. this.defines = source.defines;
  10648. this.shading = source.shading;
  10649. this.wireframe = source.wireframe;
  10650. this.wireframeLinewidth = source.wireframeLinewidth;
  10651. this.fog = source.fog;
  10652. this.lights = source.lights;
  10653. this.vertexColors = source.vertexColors;
  10654. this.skinning = source.skinning;
  10655. this.morphTargets = source.morphTargets;
  10656. this.morphNormals = source.morphNormals;
  10657. this.derivatives = source.derivatives;
  10658. return this;
  10659. };
  10660. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  10661. var data = THREE.Material.prototype.toJSON.call( this, meta );
  10662. data.uniforms = this.uniforms;
  10663. data.attributes = this.attributes;
  10664. data.vertexShader = this.vertexShader;
  10665. data.fragmentShader = this.fragmentShader;
  10666. return data;
  10667. };
  10668. // File:src/materials/RawShaderMaterial.js
  10669. /**
  10670. * @author mrdoob / http://mrdoob.com/
  10671. */
  10672. THREE.RawShaderMaterial = function ( parameters ) {
  10673. THREE.ShaderMaterial.call( this, parameters );
  10674. this.type = 'RawShaderMaterial';
  10675. };
  10676. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  10677. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  10678. // File:src/materials/SpriteMaterial.js
  10679. /**
  10680. * @author alteredq / http://alteredqualia.com/
  10681. *
  10682. * parameters = {
  10683. * color: <hex>,
  10684. * opacity: <float>,
  10685. * map: new THREE.Texture( <Image> ),
  10686. *
  10687. * blending: THREE.NormalBlending,
  10688. * depthTest: <bool>,
  10689. * depthWrite: <bool>,
  10690. *
  10691. * uvOffset: new THREE.Vector2(),
  10692. * uvScale: new THREE.Vector2(),
  10693. *
  10694. * fog: <bool>
  10695. * }
  10696. */
  10697. THREE.SpriteMaterial = function ( parameters ) {
  10698. THREE.Material.call( this );
  10699. this.type = 'SpriteMaterial';
  10700. this.color = new THREE.Color( 0xffffff );
  10701. this.map = null;
  10702. this.rotation = 0;
  10703. this.fog = false;
  10704. // set parameters
  10705. this.setValues( parameters );
  10706. };
  10707. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  10708. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  10709. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  10710. THREE.Material.prototype.copy.call( this, source );
  10711. this.color.copy( source.color );
  10712. this.map = source.map;
  10713. this.rotation = source.rotation;
  10714. this.fog = source.fog;
  10715. return this;
  10716. };
  10717. // File:src/textures/Texture.js
  10718. /**
  10719. * @author mrdoob / http://mrdoob.com/
  10720. * @author alteredq / http://alteredqualia.com/
  10721. * @author szimek / https://github.com/szimek/
  10722. */
  10723. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10724. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  10725. this.uuid = THREE.Math.generateUUID();
  10726. this.name = '';
  10727. this.sourceFile = '';
  10728. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  10729. this.mipmaps = [];
  10730. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  10731. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  10732. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  10733. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  10734. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  10735. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  10736. this.format = format !== undefined ? format : THREE.RGBAFormat;
  10737. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  10738. this.offset = new THREE.Vector2( 0, 0 );
  10739. this.repeat = new THREE.Vector2( 1, 1 );
  10740. this.generateMipmaps = true;
  10741. this.premultiplyAlpha = false;
  10742. this.flipY = true;
  10743. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  10744. this.version = 0;
  10745. this.onUpdate = null;
  10746. };
  10747. THREE.Texture.DEFAULT_IMAGE = undefined;
  10748. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  10749. THREE.Texture.prototype = {
  10750. constructor: THREE.Texture,
  10751. set needsUpdate ( value ) {
  10752. if ( value === true ) this.version ++;
  10753. },
  10754. clone: function () {
  10755. return new this.constructor().copy( this );
  10756. },
  10757. copy: function ( source ) {
  10758. this.image = source.image;
  10759. this.mipmaps = source.mipmaps.slice( 0 );
  10760. this.mapping = source.mapping;
  10761. this.wrapS = source.wrapS;
  10762. this.wrapT = source.wrapT;
  10763. this.magFilter = source.magFilter;
  10764. this.minFilter = source.minFilter;
  10765. this.anisotropy = source.anisotropy;
  10766. this.format = source.format;
  10767. this.type = source.type;
  10768. this.offset.copy( source.offset );
  10769. this.repeat.copy( source.repeat );
  10770. this.generateMipmaps = source.generateMipmaps;
  10771. this.premultiplyAlpha = source.premultiplyAlpha;
  10772. this.flipY = source.flipY;
  10773. this.unpackAlignment = source.unpackAlignment;
  10774. return this;
  10775. },
  10776. toJSON: function ( meta ) {
  10777. if ( meta.textures[ this.uuid ] !== undefined ) {
  10778. return meta.textures[ this.uuid ];
  10779. }
  10780. function getDataURL( image ) {
  10781. var canvas;
  10782. if ( image.toDataURL !== undefined ) {
  10783. canvas = image;
  10784. } else {
  10785. canvas = document.createElement( 'canvas' );
  10786. canvas.width = image.width;
  10787. canvas.height = image.height;
  10788. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  10789. }
  10790. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  10791. return canvas.toDataURL( 'image/jpeg', 0.6 );
  10792. } else {
  10793. return canvas.toDataURL( 'image/png' );
  10794. }
  10795. }
  10796. var output = {
  10797. metadata: {
  10798. version: 4.4,
  10799. type: 'Texture',
  10800. generator: 'Texture.toJSON'
  10801. },
  10802. uuid: this.uuid,
  10803. name: this.name,
  10804. mapping: this.mapping,
  10805. repeat: [ this.repeat.x, this.repeat.y ],
  10806. offset: [ this.offset.x, this.offset.y ],
  10807. wrap: [ this.wrapS, this.wrapT ],
  10808. minFilter: this.minFilter,
  10809. magFilter: this.magFilter,
  10810. anisotropy: this.anisotropy
  10811. };
  10812. if ( this.image !== undefined ) {
  10813. // TODO: Move to THREE.Image
  10814. var image = this.image;
  10815. if ( image.uuid === undefined ) {
  10816. image.uuid = THREE.Math.generateUUID(); // UGH
  10817. }
  10818. if ( meta.images[ image.uuid ] === undefined ) {
  10819. meta.images[ image.uuid ] = {
  10820. uuid: image.uuid,
  10821. url: getDataURL( image )
  10822. };
  10823. }
  10824. output.image = image.uuid;
  10825. }
  10826. meta.textures[ this.uuid ] = output;
  10827. return output;
  10828. },
  10829. dispose: function () {
  10830. this.dispatchEvent( { type: 'dispose' } );
  10831. },
  10832. transformUv: function ( uv ) {
  10833. if ( this.mapping !== THREE.UVMapping ) return;
  10834. uv.multiply( this.repeat );
  10835. uv.add( this.offset );
  10836. if ( uv.x < 0 || uv.x > 1 ) {
  10837. switch ( this.wrapS ) {
  10838. case THREE.RepeatWrapping:
  10839. uv.x = uv.x - Math.floor( uv.x );
  10840. break;
  10841. case THREE.ClampToEdgeWrapping:
  10842. uv.x = uv.x < 0 ? 0 : 1;
  10843. break;
  10844. case THREE.MirroredRepeatWrapping:
  10845. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  10846. uv.x = Math.ceil( uv.x ) - uv.x;
  10847. } else {
  10848. uv.x = uv.x - Math.floor( uv.x );
  10849. }
  10850. break;
  10851. }
  10852. }
  10853. if ( uv.y < 0 || uv.y > 1 ) {
  10854. switch ( this.wrapT ) {
  10855. case THREE.RepeatWrapping:
  10856. uv.y = uv.y - Math.floor( uv.y );
  10857. break;
  10858. case THREE.ClampToEdgeWrapping:
  10859. uv.y = uv.y < 0 ? 0 : 1;
  10860. break;
  10861. case THREE.MirroredRepeatWrapping:
  10862. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  10863. uv.y = Math.ceil( uv.y ) - uv.y;
  10864. } else {
  10865. uv.y = uv.y - Math.floor( uv.y );
  10866. }
  10867. break;
  10868. }
  10869. }
  10870. if ( this.flipY ) {
  10871. uv.y = 1 - uv.y;
  10872. }
  10873. }
  10874. };
  10875. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  10876. THREE.TextureIdCount = 0;
  10877. // File:src/textures/CanvasTexture.js
  10878. /**
  10879. * @author mrdoob / http://mrdoob.com/
  10880. */
  10881. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10882. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10883. this.needsUpdate = true;
  10884. };
  10885. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  10886. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  10887. // File:src/textures/CubeTexture.js
  10888. /**
  10889. * @author mrdoob / http://mrdoob.com/
  10890. */
  10891. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10892. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  10893. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10894. this.images = images;
  10895. this.flipY = false;
  10896. };
  10897. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  10898. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  10899. THREE.CubeTexture.prototype.copy = function ( source ) {
  10900. THREE.Texture.prototype.copy.call( this, source );
  10901. this.images = source.images;
  10902. return this;
  10903. };
  10904. // File:src/textures/CompressedTexture.js
  10905. /**
  10906. * @author alteredq / http://alteredqualia.com/
  10907. */
  10908. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10909. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10910. this.image = { width: width, height: height };
  10911. this.mipmaps = mipmaps;
  10912. // no flipping for cube textures
  10913. // (also flipping doesn't work for compressed textures )
  10914. this.flipY = false;
  10915. // can't generate mipmaps for compressed textures
  10916. // mips must be embedded in DDS files
  10917. this.generateMipmaps = false;
  10918. };
  10919. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  10920. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  10921. // File:src/textures/DataTexture.js
  10922. /**
  10923. * @author alteredq / http://alteredqualia.com/
  10924. */
  10925. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10926. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10927. this.image = { data: data, width: width, height: height };
  10928. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  10929. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  10930. this.flipY = false;
  10931. this.generateMipmaps = false;
  10932. };
  10933. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  10934. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  10935. // File:src/textures/VideoTexture.js
  10936. /**
  10937. * @author mrdoob / http://mrdoob.com/
  10938. */
  10939. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10940. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10941. this.generateMipmaps = false;
  10942. var scope = this;
  10943. function update() {
  10944. requestAnimationFrame( update );
  10945. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  10946. scope.needsUpdate = true;
  10947. }
  10948. }
  10949. update();
  10950. };
  10951. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  10952. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  10953. // File:src/objects/Group.js
  10954. /**
  10955. * @author mrdoob / http://mrdoob.com/
  10956. */
  10957. THREE.Group = function () {
  10958. THREE.Object3D.call( this );
  10959. this.type = 'Group';
  10960. };
  10961. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  10962. THREE.Group.prototype.constructor = THREE.Group;
  10963. // File:src/objects/Points.js
  10964. /**
  10965. * @author alteredq / http://alteredqualia.com/
  10966. */
  10967. THREE.Points = function ( geometry, material ) {
  10968. THREE.Object3D.call( this );
  10969. this.type = 'Points';
  10970. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  10971. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  10972. };
  10973. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  10974. THREE.Points.prototype.constructor = THREE.Points;
  10975. THREE.Points.prototype.raycast = ( function () {
  10976. var inverseMatrix = new THREE.Matrix4();
  10977. var ray = new THREE.Ray();
  10978. return function raycast( raycaster, intersects ) {
  10979. var object = this;
  10980. var geometry = object.geometry;
  10981. var threshold = raycaster.params.Points.threshold;
  10982. inverseMatrix.getInverse( this.matrixWorld );
  10983. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10984. if ( geometry.boundingBox !== null ) {
  10985. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  10986. return;
  10987. }
  10988. }
  10989. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10990. var localThresholdSq = localThreshold * localThreshold;
  10991. var position = new THREE.Vector3();
  10992. function testPoint( point, index ) {
  10993. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  10994. if ( rayPointDistanceSq < localThresholdSq ) {
  10995. var intersectPoint = ray.closestPointToPoint( point );
  10996. intersectPoint.applyMatrix4( object.matrixWorld );
  10997. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  10998. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10999. intersects.push( {
  11000. distance: distance,
  11001. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  11002. point: intersectPoint.clone(),
  11003. index: index,
  11004. face: null,
  11005. object: object
  11006. } );
  11007. }
  11008. }
  11009. if ( geometry instanceof THREE.BufferGeometry ) {
  11010. var index = geometry.index;
  11011. var attributes = geometry.attributes;
  11012. var positions = attributes.position.array;
  11013. if ( index !== null ) {
  11014. var indices = index.array;
  11015. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  11016. var a = indices[ i ];
  11017. position.fromArray( positions, a * 3 );
  11018. testPoint( position, a );
  11019. }
  11020. } else {
  11021. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  11022. position.fromArray( positions, i * 3 );
  11023. testPoint( position, i );
  11024. }
  11025. }
  11026. } else {
  11027. var vertices = geometry.vertices;
  11028. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  11029. testPoint( vertices[ i ], i );
  11030. }
  11031. }
  11032. };
  11033. }() );
  11034. THREE.Points.prototype.clone = function () {
  11035. return new this.constructor( this.geometry, this.material ).copy( this );
  11036. };
  11037. // Backwards compatibility
  11038. THREE.PointCloud = function ( geometry, material ) {
  11039. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  11040. return new THREE.Points( geometry, material );
  11041. };
  11042. THREE.ParticleSystem = function ( geometry, material ) {
  11043. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  11044. return new THREE.Points( geometry, material );
  11045. };
  11046. // File:src/objects/Line.js
  11047. /**
  11048. * @author mrdoob / http://mrdoob.com/
  11049. */
  11050. THREE.Line = function ( geometry, material, mode ) {
  11051. if ( mode === 1 ) {
  11052. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  11053. return new THREE.LineSegments( geometry, material );
  11054. }
  11055. THREE.Object3D.call( this );
  11056. this.type = 'Line';
  11057. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11058. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  11059. };
  11060. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  11061. THREE.Line.prototype.constructor = THREE.Line;
  11062. THREE.Line.prototype.raycast = ( function () {
  11063. var inverseMatrix = new THREE.Matrix4();
  11064. var ray = new THREE.Ray();
  11065. var sphere = new THREE.Sphere();
  11066. return function raycast( raycaster, intersects ) {
  11067. var precision = raycaster.linePrecision;
  11068. var precisionSq = precision * precision;
  11069. var geometry = this.geometry;
  11070. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11071. // Checking boundingSphere distance to ray
  11072. sphere.copy( geometry.boundingSphere );
  11073. sphere.applyMatrix4( this.matrixWorld );
  11074. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  11075. return;
  11076. }
  11077. inverseMatrix.getInverse( this.matrixWorld );
  11078. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11079. var vStart = new THREE.Vector3();
  11080. var vEnd = new THREE.Vector3();
  11081. var interSegment = new THREE.Vector3();
  11082. var interRay = new THREE.Vector3();
  11083. var step = this instanceof THREE.LineSegments ? 2 : 1;
  11084. if ( geometry instanceof THREE.BufferGeometry ) {
  11085. var index = geometry.index;
  11086. var attributes = geometry.attributes;
  11087. if ( index !== null ) {
  11088. var indices = index.array;
  11089. var positions = attributes.position.array;
  11090. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  11091. var a = indices[ i ];
  11092. var b = indices[ i + 1 ];
  11093. vStart.fromArray( positions, a * 3 );
  11094. vEnd.fromArray( positions, b * 3 );
  11095. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11096. if ( distSq > precisionSq ) continue;
  11097. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11098. var distance = raycaster.ray.origin.distanceTo( interRay );
  11099. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11100. intersects.push( {
  11101. distance: distance,
  11102. // What do we want? intersection point on the ray or on the segment??
  11103. // point: raycaster.ray.at( distance ),
  11104. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11105. index: i,
  11106. face: null,
  11107. faceIndex: null,
  11108. object: this
  11109. } );
  11110. }
  11111. } else {
  11112. var positions = attributes.position.array;
  11113. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  11114. vStart.fromArray( positions, 3 * i );
  11115. vEnd.fromArray( positions, 3 * i + 3 );
  11116. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11117. if ( distSq > precisionSq ) continue;
  11118. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11119. var distance = raycaster.ray.origin.distanceTo( interRay );
  11120. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11121. intersects.push( {
  11122. distance: distance,
  11123. // What do we want? intersection point on the ray or on the segment??
  11124. // point: raycaster.ray.at( distance ),
  11125. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11126. index: i,
  11127. face: null,
  11128. faceIndex: null,
  11129. object: this
  11130. } );
  11131. }
  11132. }
  11133. } else if ( geometry instanceof THREE.Geometry ) {
  11134. var vertices = geometry.vertices;
  11135. var nbVertices = vertices.length;
  11136. for ( var i = 0; i < nbVertices - 1; i += step ) {
  11137. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  11138. if ( distSq > precisionSq ) continue;
  11139. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11140. var distance = raycaster.ray.origin.distanceTo( interRay );
  11141. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11142. intersects.push( {
  11143. distance: distance,
  11144. // What do we want? intersection point on the ray or on the segment??
  11145. // point: raycaster.ray.at( distance ),
  11146. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11147. index: i,
  11148. face: null,
  11149. faceIndex: null,
  11150. object: this
  11151. } );
  11152. }
  11153. }
  11154. };
  11155. }() );
  11156. THREE.Line.prototype.clone = function () {
  11157. return new this.constructor( this.geometry, this.material ).copy( this );
  11158. };
  11159. // DEPRECATED
  11160. THREE.LineStrip = 0;
  11161. THREE.LinePieces = 1;
  11162. // File:src/objects/LineSegments.js
  11163. /**
  11164. * @author mrdoob / http://mrdoob.com/
  11165. */
  11166. THREE.LineSegments = function ( geometry, material ) {
  11167. THREE.Line.call( this, geometry, material );
  11168. this.type = 'LineSegments';
  11169. };
  11170. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  11171. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  11172. // File:src/objects/Mesh.js
  11173. /**
  11174. * @author mrdoob / http://mrdoob.com/
  11175. * @author alteredq / http://alteredqualia.com/
  11176. * @author mikael emtinger / http://gomo.se/
  11177. * @author jonobr1 / http://jonobr1.com/
  11178. */
  11179. THREE.Mesh = function ( geometry, material ) {
  11180. THREE.Object3D.call( this );
  11181. this.type = 'Mesh';
  11182. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11183. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  11184. this.updateMorphTargets();
  11185. };
  11186. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  11187. THREE.Mesh.prototype.constructor = THREE.Mesh;
  11188. THREE.Mesh.prototype.updateMorphTargets = function () {
  11189. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  11190. this.morphTargetBase = - 1;
  11191. this.morphTargetInfluences = [];
  11192. this.morphTargetDictionary = {};
  11193. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  11194. this.morphTargetInfluences.push( 0 );
  11195. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  11196. }
  11197. }
  11198. };
  11199. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  11200. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  11201. return this.morphTargetDictionary[ name ];
  11202. }
  11203. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  11204. return 0;
  11205. };
  11206. THREE.Mesh.prototype.raycast = ( function () {
  11207. var inverseMatrix = new THREE.Matrix4();
  11208. var ray = new THREE.Ray();
  11209. var sphere = new THREE.Sphere();
  11210. var vA = new THREE.Vector3();
  11211. var vB = new THREE.Vector3();
  11212. var vC = new THREE.Vector3();
  11213. var tempA = new THREE.Vector3();
  11214. var tempB = new THREE.Vector3();
  11215. var tempC = new THREE.Vector3();
  11216. var uvA = new THREE.Vector2();
  11217. var uvB = new THREE.Vector2();
  11218. var uvC = new THREE.Vector2();
  11219. var barycoord = new THREE.Vector3();
  11220. var intersectionPoint = new THREE.Vector3();
  11221. var intersectionPointWorld = new THREE.Vector3();
  11222. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  11223. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  11224. uv1.multiplyScalar( barycoord.x );
  11225. uv2.multiplyScalar( barycoord.y );
  11226. uv3.multiplyScalar( barycoord.z );
  11227. uv1.add( uv2 ).add( uv3 );
  11228. return uv1.clone();
  11229. }
  11230. return function raycast( raycaster, intersects ) {
  11231. var geometry = this.geometry;
  11232. var material = this.material;
  11233. if ( material === undefined ) return;
  11234. // Checking boundingSphere distance to ray
  11235. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11236. sphere.copy( geometry.boundingSphere );
  11237. sphere.applyMatrix4( this.matrixWorld );
  11238. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  11239. return;
  11240. }
  11241. // Check boundingBox before continuing
  11242. inverseMatrix.getInverse( this.matrixWorld );
  11243. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11244. if ( geometry.boundingBox !== null ) {
  11245. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  11246. return;
  11247. }
  11248. }
  11249. var a, b, c;
  11250. if ( geometry instanceof THREE.BufferGeometry ) {
  11251. var index = geometry.index;
  11252. var attributes = geometry.attributes;
  11253. if ( index !== null ) {
  11254. var indices = index.array;
  11255. var positions = attributes.position.array;
  11256. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  11257. a = indices[ i ];
  11258. b = indices[ i + 1 ];
  11259. c = indices[ i + 2 ];
  11260. vA.fromArray( positions, a * 3 );
  11261. vB.fromArray( positions, b * 3 );
  11262. vC.fromArray( positions, c * 3 );
  11263. if ( material.side === THREE.BackSide ) {
  11264. if ( ray.intersectTriangle( vC, vB, vA, true, intersectionPoint ) === null ) continue;
  11265. } else {
  11266. if ( ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide, intersectionPoint ) === null ) continue;
  11267. }
  11268. intersectionPointWorld.copy( intersectionPoint );
  11269. intersectionPointWorld.applyMatrix4( this.matrixWorld );
  11270. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11271. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11272. var uv;
  11273. if ( attributes.uv !== undefined ) {
  11274. var uvs = attributes.uv.array;
  11275. uvA.fromArray( uvs, a * 2 );
  11276. uvB.fromArray( uvs, b * 2 );
  11277. uvC.fromArray( uvs, c * 2 );
  11278. uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  11279. }
  11280. intersects.push( {
  11281. distance: distance,
  11282. point: intersectionPointWorld.clone(),
  11283. uv: uv,
  11284. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  11285. faceIndex: Math.floor( i / 3 ), // triangle number in indices buffer semantics
  11286. object: this
  11287. } );
  11288. }
  11289. } else {
  11290. var positions = attributes.position.array;
  11291. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  11292. vA.fromArray( positions, i );
  11293. vB.fromArray( positions, i + 3 );
  11294. vC.fromArray( positions, i + 6 );
  11295. if ( material.side === THREE.BackSide ) {
  11296. if ( ray.intersectTriangle( vC, vB, vA, true, intersectionPoint ) === null ) continue;
  11297. } else {
  11298. if ( ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide, intersectionPoint ) === null ) continue;
  11299. }
  11300. intersectionPointWorld.copy( intersectionPoint );
  11301. intersectionPointWorld.applyMatrix4( this.matrixWorld );
  11302. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11303. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11304. a = i / 3;
  11305. b = a + 1;
  11306. c = a + 2;
  11307. var uv;
  11308. if ( attributes.uv !== undefined ) {
  11309. var uvs = attributes.uv.array;
  11310. uvA.fromArray( uvs, a * 2 );
  11311. uvB.fromArray( uvs, b * 2 );
  11312. uvC.fromArray( uvs, c * 2 );
  11313. uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  11314. }
  11315. intersects.push( {
  11316. distance: distance,
  11317. point: intersectionPointWorld.clone(),
  11318. uv: uv,
  11319. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  11320. index: a, // triangle number in positions buffer semantics
  11321. object: this
  11322. } );
  11323. }
  11324. }
  11325. } else if ( geometry instanceof THREE.Geometry ) {
  11326. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  11327. var materials = isFaceMaterial === true ? material.materials : null;
  11328. var vertices = geometry.vertices;
  11329. var faces = geometry.faces;
  11330. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  11331. var face = faces[ f ];
  11332. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  11333. if ( faceMaterial === undefined ) continue;
  11334. a = vertices[ face.a ];
  11335. b = vertices[ face.b ];
  11336. c = vertices[ face.c ];
  11337. if ( faceMaterial.morphTargets === true ) {
  11338. var morphTargets = geometry.morphTargets;
  11339. var morphInfluences = this.morphTargetInfluences;
  11340. vA.set( 0, 0, 0 );
  11341. vB.set( 0, 0, 0 );
  11342. vC.set( 0, 0, 0 );
  11343. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  11344. var influence = morphInfluences[ t ];
  11345. if ( influence === 0 ) continue;
  11346. var targets = morphTargets[ t ].vertices;
  11347. vA.addScaledVector( tempA.subVectors( targets[ face.a ], a ), influence );
  11348. vB.addScaledVector( tempB.subVectors( targets[ face.b ], b ), influence );
  11349. vC.addScaledVector( tempC.subVectors( targets[ face.c ], c ), influence );
  11350. }
  11351. vA.add( a );
  11352. vB.add( b );
  11353. vC.add( c );
  11354. a = vA;
  11355. b = vB;
  11356. c = vC;
  11357. }
  11358. if ( faceMaterial.side === THREE.BackSide ) {
  11359. if ( ray.intersectTriangle( c, b, a, true, intersectionPoint ) === null ) continue;
  11360. } else {
  11361. if ( ray.intersectTriangle( a, b, c, faceMaterial.side !== THREE.DoubleSide, intersectionPoint ) === null ) continue;
  11362. }
  11363. intersectionPointWorld.copy( intersectionPoint );
  11364. intersectionPointWorld.applyMatrix4( this.matrixWorld );
  11365. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11366. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11367. var uv;
  11368. if ( geometry.faceVertexUvs[ 0 ].length > 0 ) {
  11369. var uvs = geometry.faceVertexUvs[ 0 ][ f ];
  11370. uvA.copy( uvs[ 0 ] );
  11371. uvB.copy( uvs[ 1 ] );
  11372. uvC.copy( uvs[ 2 ] );
  11373. uv = uvIntersection( intersectionPoint, a, b, c, uvA, uvB, uvC );
  11374. }
  11375. intersects.push( {
  11376. distance: distance,
  11377. point: intersectionPointWorld.clone(),
  11378. uv: uv,
  11379. face: face,
  11380. faceIndex: f,
  11381. object: this
  11382. } );
  11383. }
  11384. }
  11385. };
  11386. }() );
  11387. THREE.Mesh.prototype.clone = function () {
  11388. return new this.constructor( this.geometry, this.material ).copy( this );
  11389. };
  11390. // File:src/objects/Bone.js
  11391. /**
  11392. * @author mikael emtinger / http://gomo.se/
  11393. * @author alteredq / http://alteredqualia.com/
  11394. * @author ikerr / http://verold.com
  11395. */
  11396. THREE.Bone = function ( skin ) {
  11397. THREE.Object3D.call( this );
  11398. this.type = 'Bone';
  11399. this.skin = skin;
  11400. };
  11401. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  11402. THREE.Bone.prototype.constructor = THREE.Bone;
  11403. THREE.Bone.prototype.copy = function ( source ) {
  11404. THREE.Object3D.prototype.copy.call( this, source );
  11405. this.skin = source.skin;
  11406. return this;
  11407. };
  11408. // File:src/objects/Skeleton.js
  11409. /**
  11410. * @author mikael emtinger / http://gomo.se/
  11411. * @author alteredq / http://alteredqualia.com/
  11412. * @author michael guerrero / http://realitymeltdown.com
  11413. * @author ikerr / http://verold.com
  11414. */
  11415. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  11416. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  11417. this.identityMatrix = new THREE.Matrix4();
  11418. // copy the bone array
  11419. bones = bones || [];
  11420. this.bones = bones.slice( 0 );
  11421. // create a bone texture or an array of floats
  11422. if ( this.useVertexTexture ) {
  11423. // layout (1 matrix = 4 pixels)
  11424. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  11425. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  11426. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  11427. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  11428. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  11429. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  11430. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  11431. size = Math.max( size, 4 );
  11432. this.boneTextureWidth = size;
  11433. this.boneTextureHeight = size;
  11434. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  11435. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  11436. } else {
  11437. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  11438. }
  11439. // use the supplied bone inverses or calculate the inverses
  11440. if ( boneInverses === undefined ) {
  11441. this.calculateInverses();
  11442. } else {
  11443. if ( this.bones.length === boneInverses.length ) {
  11444. this.boneInverses = boneInverses.slice( 0 );
  11445. } else {
  11446. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  11447. this.boneInverses = [];
  11448. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11449. this.boneInverses.push( new THREE.Matrix4() );
  11450. }
  11451. }
  11452. }
  11453. };
  11454. THREE.Skeleton.prototype.calculateInverses = function () {
  11455. this.boneInverses = [];
  11456. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11457. var inverse = new THREE.Matrix4();
  11458. if ( this.bones[ b ] ) {
  11459. inverse.getInverse( this.bones[ b ].matrixWorld );
  11460. }
  11461. this.boneInverses.push( inverse );
  11462. }
  11463. };
  11464. THREE.Skeleton.prototype.pose = function () {
  11465. var bone;
  11466. // recover the bind-time world matrices
  11467. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11468. bone = this.bones[ b ];
  11469. if ( bone ) {
  11470. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  11471. }
  11472. }
  11473. // compute the local matrices, positions, rotations and scales
  11474. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11475. bone = this.bones[ b ];
  11476. if ( bone ) {
  11477. if ( bone.parent ) {
  11478. bone.matrix.getInverse( bone.parent.matrixWorld );
  11479. bone.matrix.multiply( bone.matrixWorld );
  11480. } else {
  11481. bone.matrix.copy( bone.matrixWorld );
  11482. }
  11483. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  11484. }
  11485. }
  11486. };
  11487. THREE.Skeleton.prototype.update = ( function () {
  11488. var offsetMatrix = new THREE.Matrix4();
  11489. return function update() {
  11490. // flatten bone matrices to array
  11491. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11492. // compute the offset between the current and the original transform
  11493. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  11494. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  11495. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  11496. }
  11497. if ( this.useVertexTexture ) {
  11498. this.boneTexture.needsUpdate = true;
  11499. }
  11500. };
  11501. } )();
  11502. THREE.Skeleton.prototype.clone = function () {
  11503. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  11504. };
  11505. // File:src/objects/SkinnedMesh.js
  11506. /**
  11507. * @author mikael emtinger / http://gomo.se/
  11508. * @author alteredq / http://alteredqualia.com/
  11509. * @author ikerr / http://verold.com
  11510. */
  11511. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  11512. THREE.Mesh.call( this, geometry, material );
  11513. this.type = 'SkinnedMesh';
  11514. this.bindMode = "attached";
  11515. this.bindMatrix = new THREE.Matrix4();
  11516. this.bindMatrixInverse = new THREE.Matrix4();
  11517. // init bones
  11518. // TODO: remove bone creation as there is no reason (other than
  11519. // convenience) for THREE.SkinnedMesh to do this.
  11520. var bones = [];
  11521. if ( this.geometry && this.geometry.bones !== undefined ) {
  11522. var bone, gbone;
  11523. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11524. gbone = this.geometry.bones[ b ];
  11525. bone = new THREE.Bone( this );
  11526. bones.push( bone );
  11527. bone.name = gbone.name;
  11528. bone.position.fromArray( gbone.pos );
  11529. bone.quaternion.fromArray( gbone.rotq );
  11530. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  11531. }
  11532. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11533. gbone = this.geometry.bones[ b ];
  11534. if ( gbone.parent !== - 1 ) {
  11535. bones[ gbone.parent ].add( bones[ b ] );
  11536. } else {
  11537. this.add( bones[ b ] );
  11538. }
  11539. }
  11540. }
  11541. this.normalizeSkinWeights();
  11542. this.updateMatrixWorld( true );
  11543. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  11544. };
  11545. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  11546. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  11547. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  11548. this.skeleton = skeleton;
  11549. if ( bindMatrix === undefined ) {
  11550. this.updateMatrixWorld( true );
  11551. this.skeleton.calculateInverses();
  11552. bindMatrix = this.matrixWorld;
  11553. }
  11554. this.bindMatrix.copy( bindMatrix );
  11555. this.bindMatrixInverse.getInverse( bindMatrix );
  11556. };
  11557. THREE.SkinnedMesh.prototype.pose = function () {
  11558. this.skeleton.pose();
  11559. };
  11560. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  11561. if ( this.geometry instanceof THREE.Geometry ) {
  11562. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  11563. var sw = this.geometry.skinWeights[ i ];
  11564. var scale = 1.0 / sw.lengthManhattan();
  11565. if ( scale !== Infinity ) {
  11566. sw.multiplyScalar( scale );
  11567. } else {
  11568. sw.set( 1 ); // this will be normalized by the shader anyway
  11569. }
  11570. }
  11571. } else {
  11572. // skinning weights assumed to be normalized for THREE.BufferGeometry
  11573. }
  11574. };
  11575. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  11576. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  11577. if ( this.bindMode === "attached" ) {
  11578. this.bindMatrixInverse.getInverse( this.matrixWorld );
  11579. } else if ( this.bindMode === "detached" ) {
  11580. this.bindMatrixInverse.getInverse( this.bindMatrix );
  11581. } else {
  11582. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  11583. }
  11584. };
  11585. THREE.SkinnedMesh.prototype.clone = function() {
  11586. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  11587. };
  11588. // File:src/objects/LOD.js
  11589. /**
  11590. * @author mikael emtinger / http://gomo.se/
  11591. * @author alteredq / http://alteredqualia.com/
  11592. * @author mrdoob / http://mrdoob.com/
  11593. */
  11594. THREE.LOD = function () {
  11595. THREE.Object3D.call( this );
  11596. this.type = 'LOD';
  11597. Object.defineProperties( this, {
  11598. levels: {
  11599. enumerable: true,
  11600. value: []
  11601. },
  11602. objects: {
  11603. get: function () {
  11604. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  11605. return this.levels;
  11606. }
  11607. }
  11608. } );
  11609. };
  11610. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  11611. THREE.LOD.prototype.constructor = THREE.LOD;
  11612. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  11613. if ( distance === undefined ) distance = 0;
  11614. distance = Math.abs( distance );
  11615. var levels = this.levels;
  11616. for ( var l = 0; l < levels.length; l ++ ) {
  11617. if ( distance < levels[ l ].distance ) {
  11618. break;
  11619. }
  11620. }
  11621. levels.splice( l, 0, { distance: distance, object: object } );
  11622. this.add( object );
  11623. };
  11624. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  11625. var levels = this.levels;
  11626. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11627. if ( distance < levels[ i ].distance ) {
  11628. break;
  11629. }
  11630. }
  11631. return levels[ i - 1 ].object;
  11632. };
  11633. THREE.LOD.prototype.raycast = ( function () {
  11634. var matrixPosition = new THREE.Vector3();
  11635. return function raycast( raycaster, intersects ) {
  11636. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11637. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  11638. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  11639. };
  11640. }() );
  11641. THREE.LOD.prototype.update = function () {
  11642. var v1 = new THREE.Vector3();
  11643. var v2 = new THREE.Vector3();
  11644. return function update( camera ) {
  11645. var levels = this.levels;
  11646. if ( levels.length > 1 ) {
  11647. v1.setFromMatrixPosition( camera.matrixWorld );
  11648. v2.setFromMatrixPosition( this.matrixWorld );
  11649. var distance = v1.distanceTo( v2 );
  11650. levels[ 0 ].object.visible = true;
  11651. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11652. if ( distance >= levels[ i ].distance ) {
  11653. levels[ i - 1 ].object.visible = false;
  11654. levels[ i ].object.visible = true;
  11655. } else {
  11656. break;
  11657. }
  11658. }
  11659. for ( ; i < l; i ++ ) {
  11660. levels[ i ].object.visible = false;
  11661. }
  11662. }
  11663. };
  11664. }();
  11665. THREE.LOD.prototype.copy = function ( source ) {
  11666. THREE.Object3D.prototype.copy.call( this, source, false );
  11667. var levels = source.levels;
  11668. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11669. var level = levels[ i ];
  11670. this.addLevel( level.object.clone(), level.distance );
  11671. }
  11672. return this;
  11673. };
  11674. THREE.LOD.prototype.toJSON = function ( meta ) {
  11675. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11676. data.object.levels = [];
  11677. var levels = this.levels;
  11678. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11679. var level = levels[ i ];
  11680. data.object.levels.push( {
  11681. object: level.object.uuid,
  11682. distance: level.distance
  11683. } );
  11684. }
  11685. return data;
  11686. };
  11687. // File:src/objects/Sprite.js
  11688. /**
  11689. * @author mikael emtinger / http://gomo.se/
  11690. * @author alteredq / http://alteredqualia.com/
  11691. */
  11692. THREE.Sprite = ( function () {
  11693. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  11694. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  11695. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  11696. var geometry = new THREE.BufferGeometry();
  11697. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  11698. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  11699. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  11700. return function Sprite( material ) {
  11701. THREE.Object3D.call( this );
  11702. this.type = 'Sprite';
  11703. this.geometry = geometry;
  11704. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  11705. };
  11706. } )();
  11707. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  11708. THREE.Sprite.prototype.constructor = THREE.Sprite;
  11709. THREE.Sprite.prototype.raycast = ( function () {
  11710. var matrixPosition = new THREE.Vector3();
  11711. return function raycast( raycaster, intersects ) {
  11712. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11713. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  11714. var guessSizeSq = this.scale.x * this.scale.y;
  11715. if ( distanceSq > guessSizeSq ) {
  11716. return;
  11717. }
  11718. intersects.push( {
  11719. distance: Math.sqrt( distanceSq ),
  11720. point: this.position,
  11721. face: null,
  11722. object: this
  11723. } );
  11724. };
  11725. }() );
  11726. THREE.Sprite.prototype.clone = function () {
  11727. return new this.constructor( this.material ).copy( this );
  11728. };
  11729. // Backwards compatibility
  11730. THREE.Particle = THREE.Sprite;
  11731. // File:src/objects/LensFlare.js
  11732. /**
  11733. * @author mikael emtinger / http://gomo.se/
  11734. * @author alteredq / http://alteredqualia.com/
  11735. */
  11736. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  11737. THREE.Object3D.call( this );
  11738. this.lensFlares = [];
  11739. this.positionScreen = new THREE.Vector3();
  11740. this.customUpdateCallback = undefined;
  11741. if ( texture !== undefined ) {
  11742. this.add( texture, size, distance, blending, color );
  11743. }
  11744. };
  11745. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  11746. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  11747. /*
  11748. * Add: adds another flare
  11749. */
  11750. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  11751. if ( size === undefined ) size = - 1;
  11752. if ( distance === undefined ) distance = 0;
  11753. if ( opacity === undefined ) opacity = 1;
  11754. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  11755. if ( blending === undefined ) blending = THREE.NormalBlending;
  11756. distance = Math.min( distance, Math.max( 0, distance ) );
  11757. this.lensFlares.push( {
  11758. texture: texture, // THREE.Texture
  11759. size: size, // size in pixels (-1 = use texture.width)
  11760. distance: distance, // distance (0-1) from light source (0=at light source)
  11761. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  11762. scale: 1, // scale
  11763. rotation: 0, // rotation
  11764. opacity: opacity, // opacity
  11765. color: color, // color
  11766. blending: blending // blending
  11767. } );
  11768. };
  11769. /*
  11770. * Update lens flares update positions on all flares based on the screen position
  11771. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  11772. */
  11773. THREE.LensFlare.prototype.updateLensFlares = function () {
  11774. var f, fl = this.lensFlares.length;
  11775. var flare;
  11776. var vecX = - this.positionScreen.x * 2;
  11777. var vecY = - this.positionScreen.y * 2;
  11778. for ( f = 0; f < fl; f ++ ) {
  11779. flare = this.lensFlares[ f ];
  11780. flare.x = this.positionScreen.x + vecX * flare.distance;
  11781. flare.y = this.positionScreen.y + vecY * flare.distance;
  11782. flare.wantedRotation = flare.x * Math.PI * 0.25;
  11783. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  11784. }
  11785. };
  11786. THREE.LensFlare.prototype.copy = function ( source ) {
  11787. THREE.Object3D.prototype.copy.call( this, source );
  11788. this.positionScreen.copy( source.positionScreen );
  11789. this.customUpdateCallback = source.customUpdateCallback;
  11790. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  11791. this.lensFlares.push( source.lensFlares[ i ] );
  11792. }
  11793. return this;
  11794. };
  11795. // File:src/scenes/Scene.js
  11796. /**
  11797. * @author mrdoob / http://mrdoob.com/
  11798. */
  11799. THREE.Scene = function () {
  11800. THREE.Object3D.call( this );
  11801. this.type = 'Scene';
  11802. this.fog = null;
  11803. this.overrideMaterial = null;
  11804. this.autoUpdate = true; // checked by the renderer
  11805. };
  11806. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  11807. THREE.Scene.prototype.constructor = THREE.Scene;
  11808. THREE.Scene.prototype.copy = function ( source ) {
  11809. THREE.Object3D.prototype.copy.call( this, source );
  11810. if ( source.fog !== null ) this.fog = source.fog.clone();
  11811. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  11812. this.autoUpdate = source.autoUpdate;
  11813. this.matrixAutoUpdate = source.matrixAutoUpdate;
  11814. return this;
  11815. };
  11816. // File:src/scenes/Fog.js
  11817. /**
  11818. * @author mrdoob / http://mrdoob.com/
  11819. * @author alteredq / http://alteredqualia.com/
  11820. */
  11821. THREE.Fog = function ( color, near, far ) {
  11822. this.name = '';
  11823. this.color = new THREE.Color( color );
  11824. this.near = ( near !== undefined ) ? near : 1;
  11825. this.far = ( far !== undefined ) ? far : 1000;
  11826. };
  11827. THREE.Fog.prototype.clone = function () {
  11828. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  11829. };
  11830. // File:src/scenes/FogExp2.js
  11831. /**
  11832. * @author mrdoob / http://mrdoob.com/
  11833. * @author alteredq / http://alteredqualia.com/
  11834. */
  11835. THREE.FogExp2 = function ( color, density ) {
  11836. this.name = '';
  11837. this.color = new THREE.Color( color );
  11838. this.density = ( density !== undefined ) ? density : 0.00025;
  11839. };
  11840. THREE.FogExp2.prototype.clone = function () {
  11841. return new THREE.FogExp2( this.color.getHex(), this.density );
  11842. };
  11843. // File:src/renderers/shaders/ShaderChunk.js
  11844. THREE.ShaderChunk = {};
  11845. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  11846. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  11847. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  11848. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  11849. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  11850. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  11851. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  11852. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  11853. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  11854. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  11855. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  11856. THREE.ShaderChunk[ 'begin_vertex'] = "\nvec3 transformed = vec3( position );\n";
  11857. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  11858. THREE.ShaderChunk[ 'beginnormal_vertex'] = "\nvec3 objectNormal = vec3( normal );\n";
  11859. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  11860. 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";
  11861. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  11862. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  11863. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  11864. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  11865. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  11866. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  11867. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  11868. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  11869. // File:src/renderers/shaders/ShaderChunk/common.glsl
  11870. THREE.ShaderChunk[ 'common'] = "#define PI 3.14159\n#define PI2 6.28318\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\n\nvec3 transformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );\n\n}\n\n// http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations\nvec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );\n\n}\n\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n float distance = dot( planeNormal, point - pointOnPlane );\n\n return - distance * planeNormal + point;\n\n}\n\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return sign( dot( point - pointOnPlane, planeNormal ) );\n\n}\n\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n\n}\n\nfloat calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {\n\n if ( decayExponent > 0.0 ) {\n\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\n }\n\n return 1.0;\n\n}\n\nvec3 F_Schlick( in vec3 specularColor, in float dotLH ) {\n\n // Original approximation by Christophe Schlick '94\n //;float fresnel = pow( 1.0 - dotLH, 5.0 );\n\n // Optimized variant (presented by Epic at SIGGRAPH '13)\n float fresnel = exp2( ( -5.55437 * dotLH - 6.98316 ) * dotLH );\n\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n\n}\n\nfloat G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {\n\n // geometry term is (n⋅l)(n⋅v) / 4(n⋅l)(n⋅v)\n\n return 0.25;\n\n}\n\nfloat D_BlinnPhong( in float shininess, in float dotNH ) {\n\n // factor of 1/PI in distribution term omitted\n\n return ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n\n}\n\nvec3 BRDF_BlinnPhong( in vec3 specularColor, in float shininess, in vec3 normal, in vec3 lightDir, in vec3 viewDir ) {\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n //float dotNL = saturate( dot( normal, lightDir ) );\n //float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotLH = saturate( dot( lightDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, dotLH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * G * D;\n\n}\n\nvec3 inputToLinear( in vec3 a ) {\n\n #ifdef GAMMA_INPUT\n\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n\nvec3 linearToOutput( in vec3 a ) {\n\n #ifdef GAMMA_OUTPUT\n\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n";
  11871. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  11872. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  11873. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  11874. THREE.ShaderChunk[ 'displacementmap_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n\n#endif\n";
  11875. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  11876. THREE.ShaderChunk[ 'displacementmap_pars_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n\n#endif\n";
  11877. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  11878. 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";
  11879. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  11880. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  11881. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  11882. 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";
  11883. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  11884. 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";
  11885. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  11886. 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";
  11887. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  11888. THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\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";
  11889. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  11890. 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";
  11891. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  11892. 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";
  11893. // File:src/renderers/shaders/ShaderChunk/hemilight_fragment.glsl
  11894. THREE.ShaderChunk[ 'hemilight_fragment'] = "#if MAX_HEMI_LIGHTS > 0\n\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = hemisphereLightDirection[ i ];\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vec3 lightColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n totalAmbientLight += lightColor;\n\n }\n\n#endif\n\n";
  11895. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  11896. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  11897. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  11898. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  11899. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  11900. 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";
  11901. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  11902. THREE.ShaderChunk[ 'lights_lambert_vertex'] = "vLightFront = vec3( 0.0 );\n\n#ifdef DOUBLE_SIDED\n\n vLightBack = vec3( 0.0 );\n\n#endif\n\nvec3 normal = normalize( transformedNormal );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec3 lVector = pointLightPosition[ i ] - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec3 lVector = lightPosition - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], lightDir );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = directionalLightDirection[ i ];\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = hemisphereLightDirection[ i ];\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n #ifdef DOUBLE_SIDED\n\n float hemiDiffuseWeightBack = - 0.5 * dotProduct + 0.5;\n\n vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );\n\n #endif\n\n }\n\n#endif\n\nvLightFront += ambientLightColor;\n\n#ifdef DOUBLE_SIDED\n\n vLightBack += ambientLightColor;\n\n#endif\n";
  11903. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  11904. THREE.ShaderChunk[ 'lights_phong_fragment'] = "vec3 viewDir = normalize( vViewPosition );\n\nvec3 totalDiffuseLight = vec3( 0.0 );\nvec3 totalSpecularLight = vec3( 0.0 );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec3 lightPosition = pointLightPosition[ i ];\n vec3 lVector = lightPosition + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec3 lVector = lightPosition + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], lightDir );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = directionalLightDirection[ i ];\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * cosineTerm;\n\n }\n\n#endif\n\n#ifdef METAL\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;\n\n#else\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;\n\n#endif\n";
  11905. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  11906. THREE.ShaderChunk[ 'lights_phong_pars_fragment'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\nvarying vec3 vViewPosition;\n\n#ifndef FLAT_SHADED\n\n varying vec3 vNormal;\n\n#endif\n";
  11907. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  11908. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n\n#endif\n";
  11909. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  11910. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif\n";
  11911. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  11912. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  11913. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  11914. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  11915. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  11916. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n\n uniform float logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n varying float vFragDepth;\n\n #endif\n\n#endif\n";
  11917. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  11918. 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";
  11919. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  11920. 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";
  11921. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  11922. 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";
  11923. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  11924. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  11925. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  11926. 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";
  11927. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  11928. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  11929. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  11930. THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n\n objectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n objectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n objectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n objectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n\n#endif\n";
  11931. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  11932. 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";
  11933. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  11934. THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n\n transformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n transformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n transformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n transformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\n #ifndef USE_MORPHNORMALS\n\n transformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n transformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n transformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n transformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\n #endif\n\n#endif\n";
  11935. // File:src/renderers/shaders/ShaderChunk/normal_phong_fragment.glsl
  11936. THREE.ShaderChunk[ 'normal_phong_fragment'] = "#ifndef FLAT_SHADED\n\n vec3 normal = normalize( vNormal );\n\n #ifdef DOUBLE_SIDED\n\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n\n #endif\n\n#else\n\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n\n#endif\n\n#ifdef USE_NORMALMAP\n\n normal = perturbNormal2Arb( -vViewPosition, normal );\n\n#elif defined( USE_BUMPMAP )\n\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n\n#endif\n\n";
  11937. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  11938. 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";
  11939. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  11940. THREE.ShaderChunk[ 'project_vertex'] = "#ifdef USE_SKINNING\n\n vec4 mvPosition = modelViewMatrix * skinned;\n\n#else\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;\n";
  11941. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  11942. THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\n\n vec3 shadowMask = vec3( 1.0 );\n\n for ( int i = 0; i < MAX_SHADOWS; i ++ ) {\n \n float texelSizeY = 1.0 / shadowMapSize[ i ].y;\n\n float shadow = 0.0; \n\n#if defined( POINT_LIGHT_SHADOWS )\n\n // to save on uniform space, we use the sign of @shadowDarkness[ i ] to determine\n // whether or not this light is a point light ( shadowDarkness[ i ] < 0 == point light)\n bool isPointLight = shadowDarkness[ i ] < 0.0; \n\n if ( isPointLight ) {\n\n // get the real shadow darkness\n float realShadowDarkness = abs( shadowDarkness[ i ] );\n\n // for point lights, the uniform @vShadowCoord is re-purposed to hold\n // the distance from the light to the world-space position of the fragment.\n vec3 lightToPosition = vShadowCoord[ i ].xyz;\n\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n // bd3D = base direction 3D\n vec3 bd3D = normalize( lightToPosition );\n // dp = distance from light to fragment position\n float dp = length( lightToPosition );\n\n // base measurement\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n\n // Dr = disk radius\n\n #if defined( SHADOWMAP_TYPE_PCF )\n const float Dr = 1.25;\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n const float Dr = 2.25;\n #endif\n\n // os = offset scale\n float os = Dr * 2.0 * texelSizeY;\n\n const vec3 Gsd = vec3( - 1, 0, 1 );\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n\n shadow *= realShadowDarkness * ( 1.0 / 21.0 );\n\n #else // no percentage-closer filtering:\n\n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n\n shadow *= realShadowDarkness;\n\n #endif\n\n } else {\n\n#endif // POINT_LIGHT_SHADOWS\n\n float texelSizeX = 1.0 / shadowMapSize[ i ].x;\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 #if defined( SHADOWMAP_TYPE_PCF )\n \n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n \n /*\n // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL\n // must enroll loop manually\n for ( float y = -1.25; y <= 1.25; y += 1.25 )\n for ( float x = -1.25; x <= 1.25; x += 1.25 ) {\n vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\n // doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup\n //vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );\n float fDepth = unpackDepth( rgbaDepth );\n if ( fDepth < shadowCoord.z )\n shadow += 1.0;\n }\n shadow /= 9.0;\n */\n\n shadowCoord.z += shadowBias[ i ];\n\n const float ShadowDelta = 1.0 / 9.0;\n\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n\n float dx0 = - 1.25 * xPixelOffset;\n float dy0 = - 1.25 * yPixelOffset;\n float dx1 = 1.25 * xPixelOffset;\n float dy1 = 1.25 * yPixelOffset;\n\n float 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 shadow *= shadowDarkness[ i ];\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT ) \n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n shadowCoord.z += shadowBias[ i ];\n\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n\n float dx0 = - 1.0 * xPixelOffset;\n float dy0 = - 1.0 * yPixelOffset;\n float dx1 = 1.0 * xPixelOffset;\n float dy1 = 1.0 * yPixelOffset;\n\n mat3 shadowKernel;\n mat3 depthKernel;\n\n depthKernel[ 0 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n depthKernel[ 0 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n depthKernel[ 0 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n depthKernel[ 1 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n depthKernel[ 1 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n depthKernel[ 1 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n depthKernel[ 2 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n depthKernel[ 2 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n depthKernel[ 2 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[ 0 ] = vec3( lessThan( depthKernel[ 0 ], shadowZ ) );\n shadowKernel[ 0 ] *= vec3( 0.25 );\n\n shadowKernel[ 1 ] = vec3( lessThan( depthKernel[ 1 ], shadowZ ) );\n shadowKernel[ 1 ] *= vec3( 0.25 );\n\n shadowKernel[ 2 ] = vec3( lessThan( depthKernel[ 2 ], shadowZ ) );\n shadowKernel[ 2 ] *= vec3( 0.25 );\n\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[ i ].xy );\n\n shadowKernel[ 0 ] = mix( shadowKernel[ 1 ], shadowKernel[ 0 ], fractionalCoord.x );\n shadowKernel[ 1 ] = mix( shadowKernel[ 2 ], shadowKernel[ 1 ], fractionalCoord.x );\n\n vec4 shadowValues;\n shadowValues.x = mix( shadowKernel[ 0 ][ 1 ], shadowKernel[ 0 ][ 0 ], fractionalCoord.y );\n shadowValues.y = mix( shadowKernel[ 0 ][ 2 ], shadowKernel[ 0 ][ 1 ], fractionalCoord.y );\n shadowValues.z = mix( shadowKernel[ 1 ][ 1 ], shadowKernel[ 1 ][ 0 ], fractionalCoord.y );\n shadowValues.w = mix( shadowKernel[ 1 ][ 2 ], shadowKernel[ 1 ][ 1 ], fractionalCoord.y );\n\n shadow = dot( shadowValues, vec4( 1.0 ) ) * shadowDarkness[ i ];\n\n #else // no percentage-closer filtering:\n \n shadowCoord.z += shadowBias[ i ];\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n shadow = shadowDarkness[ i ]; \n\n #endif\n\n }\n\n#ifdef SHADOWMAP_DEBUG\n\n if ( inFrustum ) {\n\n if ( i == 0 ) {\n\n outgoingLight *= vec3( 1.0, 0.5, 0.0 );\n\n } else if ( i == 1 ) {\n\n outgoingLight *= vec3( 0.0, 1.0, 0.8 );\n\n } else {\n\n outgoingLight *= vec3( 0.0, 0.5, 1.0 );\n\n }\n\n }\n\n#endif\n\n#if defined( POINT_LIGHT_SHADOWS )\n\n }\n\n#endif\n\n shadowMask = shadowMask * vec3( 1.0 - shadow ); \n\n }\n\n outgoingLight = outgoingLight * shadowMask;\n\n#endif\n";
  11943. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  11944. THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n\n uniform sampler2D shadowMap[ MAX_SHADOWS ];\n uniform vec2 shadowMapSize[ MAX_SHADOWS ];\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform float shadowBias[ MAX_SHADOWS ];\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n float unpackDepth( const in vec4 rgba_depth ) {\n\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n float depth = dot( rgba_depth, bit_shift );\n return depth;\n\n }\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n // adjustShadowValue1K() upacks the depth value stored in @textureData, adds @bias to it, and then\n // comapres the result with @testDepth. If @testDepth is larger than or equal to that result, then\n // @shadowValue is incremented by 1.0.\n\n void adjustShadowValue1K( const float testDepth, const vec4 textureData, const float bias, inout float shadowValue ) {\n\n const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n if ( testDepth >= dot( textureData, bitSh ) * 1000.0 + bias )\n shadowValue += 1.0;\n\n }\n\n // cubeToUV() maps a 3D direction vector suitable for cube texture mapping to a 2D\n // vector suitable for 2D texture mapping. This code uses the following layout for the\n // 2D texture:\n //\n // xzXZ\n // y Y\n //\n // Y - Positive y direction\n // y - Negative y direction\n // X - Positive x direction\n // x - Negative x direction\n // Z - Positive z direction\n // z - Negative z direction\n //\n // Source and test bed:\n // https://gist.github.com/tschw/da10c43c467ce8afd0c4\n\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n\n // Number of texels to avoid at the edge of each square\n\n vec3 absV = abs( v );\n\n // Intersect unit cube\n\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n\n // Apply scale to avoid seams\n\n // two texels less per square (one texel will do for NEAREST)\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\n // Unwrap\n\n // space: -1 ... 1 range for each square\n //\n // #X## dim := ( 4 , 2 )\n // # # center := ( 1 , 1 )\n\n vec2 planar = v.xy;\n\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n\n if ( absV.z >= almostOne ) {\n\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n\n } else if ( absV.x >= almostOne ) {\n\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n\n } else if ( absV.y >= almostOne ) {\n\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n\n }\n\n // Transform to UV space\n\n // scale := 0.5 / dim\n // translate := ( center + 0.5 ) / dim\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\n }\n\n #endif\n\n#endif\n";
  11945. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  11946. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n#endif";
  11947. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  11948. 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";
  11949. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  11950. 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";
  11951. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  11952. 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";
  11953. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  11954. THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n skinned = bindMatrixInverse * skinned;\n\n#endif\n";
  11955. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  11956. THREE.ShaderChunk[ 'skinnormal_vertex'] = "#ifdef USE_SKINNING\n\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\n objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\n#endif\n";
  11957. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  11958. 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";
  11959. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  11960. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  11961. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  11962. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  11963. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  11964. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  11965. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  11966. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  11967. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  11968. 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";
  11969. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  11970. 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";
  11971. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  11972. 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";
  11973. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  11974. THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\n #ifdef USE_SKINNING\n\n vec4 worldPosition = modelMatrix * skinned;\n\n #else\n\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n\n #endif\n\n#endif\n";
  11975. // File:src/renderers/shaders/UniformsUtils.js
  11976. /**
  11977. * Uniform Utilities
  11978. */
  11979. THREE.UniformsUtils = {
  11980. merge: function ( uniforms ) {
  11981. var merged = {};
  11982. for ( var u = 0; u < uniforms.length; u ++ ) {
  11983. var tmp = this.clone( uniforms[ u ] );
  11984. for ( var p in tmp ) {
  11985. merged[ p ] = tmp[ p ];
  11986. }
  11987. }
  11988. return merged;
  11989. },
  11990. clone: function ( uniforms_src ) {
  11991. var uniforms_dst = {};
  11992. for ( var u in uniforms_src ) {
  11993. uniforms_dst[ u ] = {};
  11994. for ( var p in uniforms_src[ u ] ) {
  11995. var parameter_src = uniforms_src[ u ][ p ];
  11996. if ( parameter_src instanceof THREE.Color ||
  11997. parameter_src instanceof THREE.Vector2 ||
  11998. parameter_src instanceof THREE.Vector3 ||
  11999. parameter_src instanceof THREE.Vector4 ||
  12000. parameter_src instanceof THREE.Matrix3 ||
  12001. parameter_src instanceof THREE.Matrix4 ||
  12002. parameter_src instanceof THREE.Texture ) {
  12003. uniforms_dst[ u ][ p ] = parameter_src.clone();
  12004. } else if ( Array.isArray( parameter_src ) ) {
  12005. uniforms_dst[ u ][ p ] = parameter_src.slice();
  12006. } else {
  12007. uniforms_dst[ u ][ p ] = parameter_src;
  12008. }
  12009. }
  12010. }
  12011. return uniforms_dst;
  12012. }
  12013. };
  12014. // File:src/renderers/shaders/UniformsLib.js
  12015. /**
  12016. * Uniforms library for shared webgl shaders
  12017. */
  12018. THREE.UniformsLib = {
  12019. common: {
  12020. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  12021. "opacity" : { type: "f", value: 1.0 },
  12022. "map" : { type: "t", value: null },
  12023. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  12024. "specularMap" : { type: "t", value: null },
  12025. "alphaMap" : { type: "t", value: null },
  12026. "envMap" : { type: "t", value: null },
  12027. "flipEnvMap" : { type: "f", value: - 1 },
  12028. "reflectivity" : { type: "f", value: 1.0 },
  12029. "refractionRatio" : { type: "f", value: 0.98 }
  12030. },
  12031. aomap: {
  12032. "aoMap" : { type: "t", value: null },
  12033. "aoMapIntensity" : { type: "f", value: 1 },
  12034. },
  12035. lightmap: {
  12036. "lightMap" : { type: "t", value: null },
  12037. "lightMapIntensity" : { type: "f", value: 1 },
  12038. },
  12039. emissivemap: {
  12040. "emissiveMap" : { type: "t", value: null },
  12041. },
  12042. bumpmap: {
  12043. "bumpMap" : { type: "t", value: null },
  12044. "bumpScale" : { type: "f", value: 1 }
  12045. },
  12046. normalmap: {
  12047. "normalMap" : { type: "t", value: null },
  12048. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  12049. },
  12050. displacementmap: {
  12051. "displacementMap" : { type: "t", value: null },
  12052. "displacementScale" : { type: "f", value: 1 },
  12053. "displacementBias" : { type: "f", value: 0 }
  12054. },
  12055. fog : {
  12056. "fogDensity" : { type: "f", value: 0.00025 },
  12057. "fogNear" : { type: "f", value: 1 },
  12058. "fogFar" : { type: "f", value: 2000 },
  12059. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  12060. },
  12061. lights: {
  12062. "ambientLightColor" : { type: "fv", value: [] },
  12063. "directionalLightDirection" : { type: "fv", value: [] },
  12064. "directionalLightColor" : { type: "fv", value: [] },
  12065. "hemisphereLightDirection" : { type: "fv", value: [] },
  12066. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  12067. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  12068. "pointLightColor" : { type: "fv", value: [] },
  12069. "pointLightPosition" : { type: "fv", value: [] },
  12070. "pointLightDistance" : { type: "fv1", value: [] },
  12071. "pointLightDecay" : { type: "fv1", value: [] },
  12072. "spotLightColor" : { type: "fv", value: [] },
  12073. "spotLightPosition" : { type: "fv", value: [] },
  12074. "spotLightDirection" : { type: "fv", value: [] },
  12075. "spotLightDistance" : { type: "fv1", value: [] },
  12076. "spotLightAngleCos" : { type: "fv1", value: [] },
  12077. "spotLightExponent" : { type: "fv1", value: [] },
  12078. "spotLightDecay" : { type: "fv1", value: [] }
  12079. },
  12080. points: {
  12081. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  12082. "opacity" : { type: "f", value: 1.0 },
  12083. "size" : { type: "f", value: 1.0 },
  12084. "scale" : { type: "f", value: 1.0 },
  12085. "map" : { type: "t", value: null },
  12086. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  12087. "fogDensity" : { type: "f", value: 0.00025 },
  12088. "fogNear" : { type: "f", value: 1 },
  12089. "fogFar" : { type: "f", value: 2000 },
  12090. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  12091. },
  12092. shadowmap: {
  12093. "shadowMap": { type: "tv", value: [] },
  12094. "shadowMapSize": { type: "v2v", value: [] },
  12095. "shadowBias" : { type: "fv1", value: [] },
  12096. "shadowDarkness": { type: "fv1", value: [] },
  12097. "shadowMatrix" : { type: "m4v", value: [] }
  12098. }
  12099. };
  12100. // File:src/renderers/shaders/ShaderLib.js
  12101. /**
  12102. * Webgl Shader Library for three.js
  12103. *
  12104. * @author alteredq / http://alteredqualia.com/
  12105. * @author mrdoob / http://mrdoob.com/
  12106. * @author mikael emtinger / http://gomo.se/
  12107. */
  12108. THREE.ShaderLib = {
  12109. 'basic': {
  12110. uniforms: THREE.UniformsUtils.merge( [
  12111. THREE.UniformsLib[ "common" ],
  12112. THREE.UniformsLib[ "aomap" ],
  12113. THREE.UniformsLib[ "fog" ],
  12114. THREE.UniformsLib[ "shadowmap" ]
  12115. ] ),
  12116. vertexShader: [
  12117. THREE.ShaderChunk[ "common" ],
  12118. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12119. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12120. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12121. THREE.ShaderChunk[ "color_pars_vertex" ],
  12122. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12123. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12124. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12125. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12126. "void main() {",
  12127. THREE.ShaderChunk[ "uv_vertex" ],
  12128. THREE.ShaderChunk[ "uv2_vertex" ],
  12129. THREE.ShaderChunk[ "color_vertex" ],
  12130. THREE.ShaderChunk[ "skinbase_vertex" ],
  12131. " #ifdef USE_ENVMAP",
  12132. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12133. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12134. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12135. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12136. " #endif",
  12137. THREE.ShaderChunk[ "begin_vertex" ],
  12138. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12139. THREE.ShaderChunk[ "skinning_vertex" ],
  12140. THREE.ShaderChunk[ "project_vertex" ],
  12141. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12142. THREE.ShaderChunk[ "worldpos_vertex" ],
  12143. THREE.ShaderChunk[ "envmap_vertex" ],
  12144. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12145. "}"
  12146. ].join( "\n" ),
  12147. fragmentShader: [
  12148. "uniform vec3 diffuse;",
  12149. "uniform float opacity;",
  12150. THREE.ShaderChunk[ "common" ],
  12151. THREE.ShaderChunk[ "color_pars_fragment" ],
  12152. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12153. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12154. THREE.ShaderChunk[ "map_pars_fragment" ],
  12155. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12156. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12157. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12158. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12159. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12160. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12161. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12162. "void main() {",
  12163. " vec3 outgoingLight = vec3( 0.0 );",
  12164. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12165. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  12166. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12167. THREE.ShaderChunk[ "map_fragment" ],
  12168. THREE.ShaderChunk[ "color_fragment" ],
  12169. THREE.ShaderChunk[ "alphamap_fragment" ],
  12170. THREE.ShaderChunk[ "alphatest_fragment" ],
  12171. THREE.ShaderChunk[ "specularmap_fragment" ],
  12172. THREE.ShaderChunk[ "aomap_fragment" ],
  12173. " outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
  12174. THREE.ShaderChunk[ "envmap_fragment" ],
  12175. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  12176. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12177. THREE.ShaderChunk[ "fog_fragment" ],
  12178. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12179. "}"
  12180. ].join( "\n" )
  12181. },
  12182. 'lambert': {
  12183. uniforms: THREE.UniformsUtils.merge( [
  12184. THREE.UniformsLib[ "common" ],
  12185. THREE.UniformsLib[ "fog" ],
  12186. THREE.UniformsLib[ "lights" ],
  12187. THREE.UniformsLib[ "shadowmap" ],
  12188. {
  12189. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  12190. }
  12191. ] ),
  12192. vertexShader: [
  12193. "#define LAMBERT",
  12194. "varying vec3 vLightFront;",
  12195. "#ifdef DOUBLE_SIDED",
  12196. " varying vec3 vLightBack;",
  12197. "#endif",
  12198. THREE.ShaderChunk[ "common" ],
  12199. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12200. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12201. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12202. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  12203. THREE.ShaderChunk[ "color_pars_vertex" ],
  12204. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12205. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12206. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12207. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12208. "void main() {",
  12209. THREE.ShaderChunk[ "uv_vertex" ],
  12210. THREE.ShaderChunk[ "uv2_vertex" ],
  12211. THREE.ShaderChunk[ "color_vertex" ],
  12212. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12213. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12214. THREE.ShaderChunk[ "skinbase_vertex" ],
  12215. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12216. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12217. THREE.ShaderChunk[ "begin_vertex" ],
  12218. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12219. THREE.ShaderChunk[ "skinning_vertex" ],
  12220. THREE.ShaderChunk[ "project_vertex" ],
  12221. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12222. THREE.ShaderChunk[ "worldpos_vertex" ],
  12223. THREE.ShaderChunk[ "envmap_vertex" ],
  12224. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  12225. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12226. "}"
  12227. ].join( "\n" ),
  12228. fragmentShader: [
  12229. "uniform vec3 diffuse;",
  12230. "uniform vec3 emissive;",
  12231. "uniform float opacity;",
  12232. "varying vec3 vLightFront;",
  12233. "#ifdef DOUBLE_SIDED",
  12234. " varying vec3 vLightBack;",
  12235. "#endif",
  12236. THREE.ShaderChunk[ "common" ],
  12237. THREE.ShaderChunk[ "color_pars_fragment" ],
  12238. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12239. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12240. THREE.ShaderChunk[ "map_pars_fragment" ],
  12241. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12242. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12243. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12244. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12245. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12246. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12247. "void main() {",
  12248. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  12249. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12250. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12251. THREE.ShaderChunk[ "map_fragment" ],
  12252. THREE.ShaderChunk[ "color_fragment" ],
  12253. THREE.ShaderChunk[ "alphamap_fragment" ],
  12254. THREE.ShaderChunk[ "alphatest_fragment" ],
  12255. THREE.ShaderChunk[ "specularmap_fragment" ],
  12256. " #ifdef DOUBLE_SIDED",
  12257. " if ( gl_FrontFacing )",
  12258. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  12259. " else",
  12260. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  12261. " #else",
  12262. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  12263. " #endif",
  12264. THREE.ShaderChunk[ "envmap_fragment" ],
  12265. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12266. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12267. THREE.ShaderChunk[ "fog_fragment" ],
  12268. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12269. "}"
  12270. ].join( "\n" )
  12271. },
  12272. 'phong': {
  12273. uniforms: THREE.UniformsUtils.merge( [
  12274. THREE.UniformsLib[ "common" ],
  12275. THREE.UniformsLib[ "aomap" ],
  12276. THREE.UniformsLib[ "lightmap" ],
  12277. THREE.UniformsLib[ "emissivemap" ],
  12278. THREE.UniformsLib[ "bumpmap" ],
  12279. THREE.UniformsLib[ "normalmap" ],
  12280. THREE.UniformsLib[ "displacementmap" ],
  12281. THREE.UniformsLib[ "fog" ],
  12282. THREE.UniformsLib[ "lights" ],
  12283. THREE.UniformsLib[ "shadowmap" ],
  12284. {
  12285. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  12286. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  12287. "shininess": { type: "f", value: 30 }
  12288. }
  12289. ] ),
  12290. vertexShader: [
  12291. "#define PHONG",
  12292. "varying vec3 vViewPosition;",
  12293. "#ifndef FLAT_SHADED",
  12294. " varying vec3 vNormal;",
  12295. "#endif",
  12296. THREE.ShaderChunk[ "common" ],
  12297. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12298. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12299. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  12300. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12301. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  12302. THREE.ShaderChunk[ "color_pars_vertex" ],
  12303. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12304. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12305. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12306. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12307. "void main() {",
  12308. THREE.ShaderChunk[ "uv_vertex" ],
  12309. THREE.ShaderChunk[ "uv2_vertex" ],
  12310. THREE.ShaderChunk[ "color_vertex" ],
  12311. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12312. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12313. THREE.ShaderChunk[ "skinbase_vertex" ],
  12314. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12315. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12316. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  12317. " vNormal = normalize( transformedNormal );",
  12318. "#endif",
  12319. THREE.ShaderChunk[ "begin_vertex" ],
  12320. THREE.ShaderChunk[ "displacementmap_vertex" ],
  12321. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12322. THREE.ShaderChunk[ "skinning_vertex" ],
  12323. THREE.ShaderChunk[ "project_vertex" ],
  12324. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12325. " vViewPosition = - mvPosition.xyz;",
  12326. THREE.ShaderChunk[ "worldpos_vertex" ],
  12327. THREE.ShaderChunk[ "envmap_vertex" ],
  12328. THREE.ShaderChunk[ "lights_phong_vertex" ],
  12329. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12330. "}"
  12331. ].join( "\n" ),
  12332. fragmentShader: [
  12333. "#define PHONG",
  12334. "uniform vec3 diffuse;",
  12335. "uniform vec3 emissive;",
  12336. "uniform vec3 specular;",
  12337. "uniform float shininess;",
  12338. "uniform float opacity;",
  12339. THREE.ShaderChunk[ "common" ],
  12340. THREE.ShaderChunk[ "color_pars_fragment" ],
  12341. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12342. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12343. THREE.ShaderChunk[ "map_pars_fragment" ],
  12344. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12345. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12346. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  12347. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  12348. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12349. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12350. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  12351. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12352. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  12353. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  12354. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12355. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12356. "void main() {",
  12357. " vec3 outgoingLight = vec3( 0.0 );",
  12358. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12359. " vec3 totalAmbientLight = ambientLightColor;",
  12360. " vec3 totalEmissiveLight = emissive;",
  12361. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12362. THREE.ShaderChunk[ "map_fragment" ],
  12363. THREE.ShaderChunk[ "color_fragment" ],
  12364. THREE.ShaderChunk[ "alphamap_fragment" ],
  12365. THREE.ShaderChunk[ "alphatest_fragment" ],
  12366. THREE.ShaderChunk[ "specularmap_fragment" ],
  12367. THREE.ShaderChunk[ "normal_phong_fragment" ],
  12368. THREE.ShaderChunk[ "lightmap_fragment" ],
  12369. THREE.ShaderChunk[ "hemilight_fragment" ],
  12370. THREE.ShaderChunk[ "aomap_fragment" ],
  12371. THREE.ShaderChunk[ "emissivemap_fragment" ],
  12372. THREE.ShaderChunk[ "lights_phong_fragment" ],
  12373. THREE.ShaderChunk[ "envmap_fragment" ],
  12374. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12375. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12376. THREE.ShaderChunk[ "fog_fragment" ],
  12377. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12378. "}"
  12379. ].join( "\n" )
  12380. },
  12381. 'points': {
  12382. uniforms: THREE.UniformsUtils.merge( [
  12383. THREE.UniformsLib[ "points" ],
  12384. THREE.UniformsLib[ "shadowmap" ]
  12385. ] ),
  12386. vertexShader: [
  12387. "uniform float size;",
  12388. "uniform float scale;",
  12389. THREE.ShaderChunk[ "common" ],
  12390. THREE.ShaderChunk[ "color_pars_vertex" ],
  12391. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12392. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12393. "void main() {",
  12394. THREE.ShaderChunk[ "color_vertex" ],
  12395. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12396. " #ifdef USE_SIZEATTENUATION",
  12397. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  12398. " #else",
  12399. " gl_PointSize = size;",
  12400. " #endif",
  12401. " gl_Position = projectionMatrix * mvPosition;",
  12402. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12403. THREE.ShaderChunk[ "worldpos_vertex" ],
  12404. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12405. "}"
  12406. ].join( "\n" ),
  12407. fragmentShader: [
  12408. "uniform vec3 psColor;",
  12409. "uniform float opacity;",
  12410. THREE.ShaderChunk[ "common" ],
  12411. THREE.ShaderChunk[ "color_pars_fragment" ],
  12412. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  12413. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12414. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12415. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12416. "void main() {",
  12417. " vec3 outgoingLight = vec3( 0.0 );",
  12418. " vec4 diffuseColor = vec4( psColor, opacity );",
  12419. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12420. THREE.ShaderChunk[ "map_particle_fragment" ],
  12421. THREE.ShaderChunk[ "color_fragment" ],
  12422. THREE.ShaderChunk[ "alphatest_fragment" ],
  12423. " outgoingLight = diffuseColor.rgb;", // simple shader
  12424. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12425. THREE.ShaderChunk[ "fog_fragment" ],
  12426. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12427. "}"
  12428. ].join( "\n" )
  12429. },
  12430. 'dashed': {
  12431. uniforms: THREE.UniformsUtils.merge( [
  12432. THREE.UniformsLib[ "common" ],
  12433. THREE.UniformsLib[ "fog" ],
  12434. {
  12435. "scale" : { type: "f", value: 1 },
  12436. "dashSize" : { type: "f", value: 1 },
  12437. "totalSize": { type: "f", value: 2 }
  12438. }
  12439. ] ),
  12440. vertexShader: [
  12441. "uniform float scale;",
  12442. "attribute float lineDistance;",
  12443. "varying float vLineDistance;",
  12444. THREE.ShaderChunk[ "common" ],
  12445. THREE.ShaderChunk[ "color_pars_vertex" ],
  12446. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12447. "void main() {",
  12448. THREE.ShaderChunk[ "color_vertex" ],
  12449. " vLineDistance = scale * lineDistance;",
  12450. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12451. " gl_Position = projectionMatrix * mvPosition;",
  12452. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12453. "}"
  12454. ].join( "\n" ),
  12455. fragmentShader: [
  12456. "uniform vec3 diffuse;",
  12457. "uniform float opacity;",
  12458. "uniform float dashSize;",
  12459. "uniform float totalSize;",
  12460. "varying float vLineDistance;",
  12461. THREE.ShaderChunk[ "common" ],
  12462. THREE.ShaderChunk[ "color_pars_fragment" ],
  12463. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12464. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12465. "void main() {",
  12466. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  12467. " discard;",
  12468. " }",
  12469. " vec3 outgoingLight = vec3( 0.0 );",
  12470. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12471. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12472. THREE.ShaderChunk[ "color_fragment" ],
  12473. " outgoingLight = diffuseColor.rgb;", // simple shader
  12474. THREE.ShaderChunk[ "fog_fragment" ],
  12475. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12476. "}"
  12477. ].join( "\n" )
  12478. },
  12479. 'depth': {
  12480. uniforms: {
  12481. "mNear": { type: "f", value: 1.0 },
  12482. "mFar" : { type: "f", value: 2000.0 },
  12483. "opacity" : { type: "f", value: 1.0 }
  12484. },
  12485. vertexShader: [
  12486. THREE.ShaderChunk[ "common" ],
  12487. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12488. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12489. "void main() {",
  12490. THREE.ShaderChunk[ "begin_vertex" ],
  12491. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12492. THREE.ShaderChunk[ "project_vertex" ],
  12493. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12494. "}"
  12495. ].join( "\n" ),
  12496. fragmentShader: [
  12497. "uniform float mNear;",
  12498. "uniform float mFar;",
  12499. "uniform float opacity;",
  12500. THREE.ShaderChunk[ "common" ],
  12501. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12502. "void main() {",
  12503. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12504. " #ifdef USE_LOGDEPTHBUF_EXT",
  12505. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  12506. " #else",
  12507. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  12508. " #endif",
  12509. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  12510. " gl_FragColor = vec4( vec3( color ), opacity );",
  12511. "}"
  12512. ].join( "\n" )
  12513. },
  12514. 'normal': {
  12515. uniforms: {
  12516. "opacity" : { type: "f", value: 1.0 }
  12517. },
  12518. vertexShader: [
  12519. "varying vec3 vNormal;",
  12520. THREE.ShaderChunk[ "common" ],
  12521. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12522. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12523. "void main() {",
  12524. " vNormal = normalize( normalMatrix * normal );",
  12525. THREE.ShaderChunk[ "begin_vertex" ],
  12526. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12527. THREE.ShaderChunk[ "project_vertex" ],
  12528. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12529. "}"
  12530. ].join( "\n" ),
  12531. fragmentShader: [
  12532. "uniform float opacity;",
  12533. "varying vec3 vNormal;",
  12534. THREE.ShaderChunk[ "common" ],
  12535. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12536. "void main() {",
  12537. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  12538. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12539. "}"
  12540. ].join( "\n" )
  12541. },
  12542. /* -------------------------------------------------------------------------
  12543. // Cube map shader
  12544. ------------------------------------------------------------------------- */
  12545. 'cube': {
  12546. uniforms: { "tCube": { type: "t", value: null },
  12547. "tFlip": { type: "f", value: - 1 } },
  12548. vertexShader: [
  12549. "varying vec3 vWorldPosition;",
  12550. THREE.ShaderChunk[ "common" ],
  12551. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12552. "void main() {",
  12553. " vWorldPosition = transformDirection( position, modelMatrix );",
  12554. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12555. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12556. "}"
  12557. ].join( "\n" ),
  12558. fragmentShader: [
  12559. "uniform samplerCube tCube;",
  12560. "uniform float tFlip;",
  12561. "varying vec3 vWorldPosition;",
  12562. THREE.ShaderChunk[ "common" ],
  12563. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12564. "void main() {",
  12565. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12566. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12567. "}"
  12568. ].join( "\n" )
  12569. },
  12570. /* -------------------------------------------------------------------------
  12571. // Cube map shader
  12572. ------------------------------------------------------------------------- */
  12573. 'equirect': {
  12574. uniforms: { "tEquirect": { type: "t", value: null },
  12575. "tFlip": { type: "f", value: - 1 } },
  12576. vertexShader: [
  12577. "varying vec3 vWorldPosition;",
  12578. THREE.ShaderChunk[ "common" ],
  12579. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12580. "void main() {",
  12581. " vWorldPosition = transformDirection( position, modelMatrix );",
  12582. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12583. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12584. "}"
  12585. ].join( "\n" ),
  12586. fragmentShader: [
  12587. "uniform sampler2D tEquirect;",
  12588. "uniform float tFlip;",
  12589. "varying vec3 vWorldPosition;",
  12590. THREE.ShaderChunk[ "common" ],
  12591. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12592. "void main() {",
  12593. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12594. "vec3 direction = normalize( vWorldPosition );",
  12595. "vec2 sampleUV;",
  12596. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  12597. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  12598. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  12599. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12600. "}"
  12601. ].join( "\n" )
  12602. },
  12603. /* Depth encoding into RGBA texture
  12604. *
  12605. * based on SpiderGL shadow map example
  12606. * http://spidergl.org/example.php?id=6
  12607. *
  12608. * originally from
  12609. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  12610. *
  12611. * see also
  12612. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  12613. */
  12614. 'depthRGBA': {
  12615. uniforms: {},
  12616. vertexShader: [
  12617. THREE.ShaderChunk[ "common" ],
  12618. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12619. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12620. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12621. "void main() {",
  12622. THREE.ShaderChunk[ "skinbase_vertex" ],
  12623. THREE.ShaderChunk[ "begin_vertex" ],
  12624. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12625. THREE.ShaderChunk[ "skinning_vertex" ],
  12626. THREE.ShaderChunk[ "project_vertex" ],
  12627. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12628. "}"
  12629. ].join( "\n" ),
  12630. fragmentShader: [
  12631. THREE.ShaderChunk[ "common" ],
  12632. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12633. "vec4 pack_depth( const in float depth ) {",
  12634. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12635. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12636. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  12637. " res -= res.xxyz * bit_mask;",
  12638. " return res;",
  12639. "}",
  12640. "void main() {",
  12641. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12642. " #ifdef USE_LOGDEPTHBUF_EXT",
  12643. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  12644. " #else",
  12645. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  12646. " #endif",
  12647. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  12648. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  12649. //"gl_FragData[ 0 ] = pack_depth( z );",
  12650. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  12651. "}"
  12652. ].join( "\n" )
  12653. },
  12654. 'distanceRGBA': {
  12655. uniforms: {
  12656. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  12657. },
  12658. vertexShader: [
  12659. "varying vec4 vWorldPosition;",
  12660. THREE.ShaderChunk[ "common" ],
  12661. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12662. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12663. "void main() {",
  12664. THREE.ShaderChunk[ "skinbase_vertex" ],
  12665. THREE.ShaderChunk[ "begin_vertex" ],
  12666. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12667. THREE.ShaderChunk[ "skinning_vertex" ],
  12668. THREE.ShaderChunk[ "project_vertex" ],
  12669. THREE.ShaderChunk[ "worldpos_vertex" ],
  12670. "vWorldPosition = worldPosition;",
  12671. "}"
  12672. ].join( "\n" ),
  12673. fragmentShader: [
  12674. "uniform vec3 lightPos;",
  12675. "varying vec4 vWorldPosition;",
  12676. THREE.ShaderChunk[ "common" ],
  12677. "vec4 pack1K ( float depth ) {",
  12678. " depth /= 1000.0;",
  12679. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12680. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12681. " vec4 res = fract( depth * bitSh );",
  12682. " res -= res.xxyz * bitMsk;",
  12683. " return res; ",
  12684. "}",
  12685. "float unpack1K ( vec4 color ) {",
  12686. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  12687. " return dot( color, bitSh ) * 1000.0;",
  12688. "}",
  12689. "void main () {",
  12690. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  12691. "}"
  12692. ].join( "\n" )
  12693. }
  12694. };
  12695. // File:src/renderers/WebGLRenderer.js
  12696. /**
  12697. * @author supereggbert / http://www.paulbrunt.co.uk/
  12698. * @author mrdoob / http://mrdoob.com/
  12699. * @author alteredq / http://alteredqualia.com/
  12700. * @author szimek / https://github.com/szimek/
  12701. */
  12702. THREE.WebGLRenderer = function ( parameters ) {
  12703. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  12704. parameters = parameters || {};
  12705. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  12706. _context = parameters.context !== undefined ? parameters.context : null,
  12707. _width = _canvas.width,
  12708. _height = _canvas.height,
  12709. pixelRatio = 1,
  12710. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  12711. _depth = parameters.depth !== undefined ? parameters.depth : true,
  12712. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  12713. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  12714. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  12715. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  12716. _clearColor = new THREE.Color( 0x000000 ),
  12717. _clearAlpha = 0;
  12718. var lights = [];
  12719. var opaqueObjects = [];
  12720. var opaqueObjectsLastIndex = - 1;
  12721. var transparentObjects = [];
  12722. var transparentObjectsLastIndex = - 1;
  12723. var morphInfluences = new Float32Array( 8 );
  12724. var sprites = [];
  12725. var lensFlares = [];
  12726. // public properties
  12727. this.domElement = _canvas;
  12728. this.context = null;
  12729. // clearing
  12730. this.autoClear = true;
  12731. this.autoClearColor = true;
  12732. this.autoClearDepth = true;
  12733. this.autoClearStencil = true;
  12734. // scene graph
  12735. this.sortObjects = true;
  12736. // physically based shading
  12737. this.gammaFactor = 2.0; // for backwards compatibility
  12738. this.gammaInput = false;
  12739. this.gammaOutput = false;
  12740. // morphs
  12741. this.maxMorphTargets = 8;
  12742. this.maxMorphNormals = 4;
  12743. // flags
  12744. this.autoScaleCubemaps = true;
  12745. // internal properties
  12746. var _this = this,
  12747. // internal state cache
  12748. _currentProgram = null,
  12749. _currentFramebuffer = null,
  12750. _currentMaterialId = - 1,
  12751. _currentGeometryProgram = '',
  12752. _currentCamera = null,
  12753. _usedTextureUnits = 0,
  12754. _viewportX = 0,
  12755. _viewportY = 0,
  12756. _viewportWidth = _canvas.width,
  12757. _viewportHeight = _canvas.height,
  12758. _currentWidth = 0,
  12759. _currentHeight = 0,
  12760. // frustum
  12761. _frustum = new THREE.Frustum(),
  12762. // camera matrices cache
  12763. _projScreenMatrix = new THREE.Matrix4(),
  12764. _vector3 = new THREE.Vector3(),
  12765. // light arrays cache
  12766. _direction = new THREE.Vector3(),
  12767. _lightsNeedUpdate = true,
  12768. _lights = {
  12769. ambient: [ 0, 0, 0 ],
  12770. directional: { length: 0, colors: [], positions: [] },
  12771. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  12772. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  12773. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  12774. },
  12775. // info
  12776. _infoMemory = {
  12777. geometries: 0,
  12778. textures: 0
  12779. },
  12780. _infoRender = {
  12781. calls: 0,
  12782. vertices: 0,
  12783. faces: 0,
  12784. points: 0
  12785. };
  12786. this.info = {
  12787. render: _infoRender,
  12788. memory: _infoMemory,
  12789. programs: null
  12790. };
  12791. // initialize
  12792. var _gl;
  12793. try {
  12794. var attributes = {
  12795. alpha: _alpha,
  12796. depth: _depth,
  12797. stencil: _stencil,
  12798. antialias: _antialias,
  12799. premultipliedAlpha: _premultipliedAlpha,
  12800. preserveDrawingBuffer: _preserveDrawingBuffer
  12801. };
  12802. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  12803. if ( _gl === null ) {
  12804. if ( _canvas.getContext( 'webgl' ) !== null ) {
  12805. throw 'Error creating WebGL context with your selected attributes.';
  12806. } else {
  12807. throw 'Error creating WebGL context.';
  12808. }
  12809. }
  12810. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  12811. } catch ( error ) {
  12812. console.error( 'THREE.WebGLRenderer: ' + error );
  12813. }
  12814. var extensions = new THREE.WebGLExtensions( _gl );
  12815. extensions.get( 'OES_texture_float' );
  12816. extensions.get( 'OES_texture_float_linear' );
  12817. extensions.get( 'OES_texture_half_float' );
  12818. extensions.get( 'OES_texture_half_float_linear' );
  12819. extensions.get( 'OES_standard_derivatives' );
  12820. extensions.get( 'ANGLE_instanced_arrays' );
  12821. if ( extensions.get( 'OES_element_index_uint' ) ) {
  12822. THREE.BufferGeometry.MaxIndex = 4294967296;
  12823. }
  12824. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  12825. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  12826. var properties = new THREE.WebGLProperties();
  12827. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  12828. var programCache = new THREE.WebGLPrograms( this, capabilities );
  12829. this.info.programs = programCache.programs;
  12830. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  12831. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  12832. //
  12833. function glClearColor( r, g, b, a ) {
  12834. if ( _premultipliedAlpha === true ) {
  12835. r *= a; g *= a; b *= a;
  12836. }
  12837. _gl.clearColor( r, g, b, a );
  12838. }
  12839. function setDefaultGLState() {
  12840. state.init();
  12841. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12842. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12843. }
  12844. function resetGLState() {
  12845. _currentProgram = null;
  12846. _currentCamera = null;
  12847. _currentGeometryProgram = '';
  12848. _currentMaterialId = - 1;
  12849. _lightsNeedUpdate = true;
  12850. state.reset();
  12851. }
  12852. setDefaultGLState();
  12853. this.context = _gl;
  12854. this.capabilities = capabilities;
  12855. this.extensions = extensions;
  12856. this.state = state;
  12857. // shadow map
  12858. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  12859. this.shadowMap = shadowMap;
  12860. // Plugins
  12861. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  12862. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  12863. // API
  12864. this.getContext = function () {
  12865. return _gl;
  12866. };
  12867. this.getContextAttributes = function () {
  12868. return _gl.getContextAttributes();
  12869. };
  12870. this.forceContextLoss = function () {
  12871. extensions.get( 'WEBGL_lose_context' ).loseContext();
  12872. };
  12873. this.getMaxAnisotropy = ( function () {
  12874. var value;
  12875. return function getMaxAnisotropy() {
  12876. if ( value !== undefined ) return value;
  12877. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12878. if ( extension !== null ) {
  12879. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  12880. } else {
  12881. value = 0;
  12882. }
  12883. return value;
  12884. }
  12885. } )();
  12886. this.getPrecision = function () {
  12887. return capabilities.precision;
  12888. };
  12889. this.getPixelRatio = function () {
  12890. return pixelRatio;
  12891. };
  12892. this.setPixelRatio = function ( value ) {
  12893. if ( value !== undefined ) pixelRatio = value;
  12894. };
  12895. this.getSize = function () {
  12896. return {
  12897. width: _width,
  12898. height: _height
  12899. };
  12900. };
  12901. this.setSize = function ( width, height, updateStyle ) {
  12902. _width = width;
  12903. _height = height;
  12904. _canvas.width = width * pixelRatio;
  12905. _canvas.height = height * pixelRatio;
  12906. if ( updateStyle !== false ) {
  12907. _canvas.style.width = width + 'px';
  12908. _canvas.style.height = height + 'px';
  12909. }
  12910. this.setViewport( 0, 0, width, height );
  12911. };
  12912. this.setViewport = function ( x, y, width, height ) {
  12913. _viewportX = x * pixelRatio;
  12914. _viewportY = y * pixelRatio;
  12915. _viewportWidth = width * pixelRatio;
  12916. _viewportHeight = height * pixelRatio;
  12917. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12918. };
  12919. this.getViewport = function ( dimensions ) {
  12920. dimensions.x = _viewportX / pixelRatio;
  12921. dimensions.y = _viewportY / pixelRatio;
  12922. dimensions.z = _viewportWidth / pixelRatio;
  12923. dimensions.w = _viewportHeight / pixelRatio;
  12924. };
  12925. this.setScissor = function ( x, y, width, height ) {
  12926. _gl.scissor(
  12927. x * pixelRatio,
  12928. y * pixelRatio,
  12929. width * pixelRatio,
  12930. height * pixelRatio
  12931. );
  12932. };
  12933. this.enableScissorTest = function ( boolean ) {
  12934. state.setScissorTest( boolean );
  12935. };
  12936. // Clearing
  12937. this.getClearColor = function () {
  12938. return _clearColor;
  12939. };
  12940. this.setClearColor = function ( color, alpha ) {
  12941. _clearColor.set( color );
  12942. _clearAlpha = alpha !== undefined ? alpha : 1;
  12943. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12944. };
  12945. this.getClearAlpha = function () {
  12946. return _clearAlpha;
  12947. };
  12948. this.setClearAlpha = function ( alpha ) {
  12949. _clearAlpha = alpha;
  12950. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12951. };
  12952. this.clear = function ( color, depth, stencil ) {
  12953. var bits = 0;
  12954. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  12955. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  12956. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  12957. _gl.clear( bits );
  12958. };
  12959. this.clearColor = function () {
  12960. _gl.clear( _gl.COLOR_BUFFER_BIT );
  12961. };
  12962. this.clearDepth = function () {
  12963. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  12964. };
  12965. this.clearStencil = function () {
  12966. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  12967. };
  12968. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  12969. this.setRenderTarget( renderTarget );
  12970. this.clear( color, depth, stencil );
  12971. };
  12972. // Reset
  12973. this.resetGLState = resetGLState;
  12974. this.dispose = function() {
  12975. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  12976. };
  12977. // Events
  12978. function onContextLost( event ) {
  12979. event.preventDefault();
  12980. resetGLState();
  12981. setDefaultGLState();
  12982. properties.clear();
  12983. };
  12984. function onTextureDispose( event ) {
  12985. var texture = event.target;
  12986. texture.removeEventListener( 'dispose', onTextureDispose );
  12987. deallocateTexture( texture );
  12988. _infoMemory.textures --;
  12989. }
  12990. function onRenderTargetDispose( event ) {
  12991. var renderTarget = event.target;
  12992. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12993. deallocateRenderTarget( renderTarget );
  12994. _infoMemory.textures --;
  12995. }
  12996. function onMaterialDispose( event ) {
  12997. var material = event.target;
  12998. material.removeEventListener( 'dispose', onMaterialDispose );
  12999. deallocateMaterial( material );
  13000. }
  13001. // Buffer deallocation
  13002. function deallocateTexture( texture ) {
  13003. var textureProperties = properties.get( texture );
  13004. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  13005. // cube texture
  13006. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  13007. } else {
  13008. // 2D texture
  13009. if ( textureProperties.__webglInit === undefined ) return;
  13010. _gl.deleteTexture( textureProperties.__webglTexture );
  13011. }
  13012. // remove all webgl properties
  13013. properties.remove( texture );
  13014. }
  13015. function deallocateRenderTarget( renderTarget ) {
  13016. var renderTargetProperties = properties.get( renderTarget );
  13017. var textureProperties = properties.get( renderTarget.texture );
  13018. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  13019. _gl.deleteTexture( textureProperties.__webglTexture );
  13020. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13021. for ( var i = 0; i < 6; i ++ ) {
  13022. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  13023. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  13024. }
  13025. } else {
  13026. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  13027. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  13028. }
  13029. properties.remove( renderTarget.texture );
  13030. properties.remove( renderTarget );
  13031. }
  13032. function deallocateMaterial( material ) {
  13033. releaseMaterialProgramReference( material );
  13034. properties.remove( material );
  13035. }
  13036. function releaseMaterialProgramReference( material ) {
  13037. var programInfo = properties.get( material ).program;
  13038. material.program = undefined;
  13039. if ( programInfo !== undefined ) {
  13040. programCache.releaseProgram( programInfo );
  13041. }
  13042. }
  13043. // Buffer rendering
  13044. this.renderBufferImmediate = function ( object, program, material ) {
  13045. state.initAttributes();
  13046. var buffers = properties.get( object );
  13047. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13048. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13049. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13050. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13051. var attributes = program.getAttributes();
  13052. if ( object.hasPositions ) {
  13053. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  13054. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  13055. state.enableAttribute( attributes.position );
  13056. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  13057. }
  13058. if ( object.hasNormals ) {
  13059. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  13060. if ( material.type !== 'MeshPhongMaterial' && material.shading === THREE.FlatShading ) {
  13061. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  13062. var array = object.normalArray;
  13063. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  13064. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  13065. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  13066. array[ i + 0 ] = nx;
  13067. array[ i + 1 ] = ny;
  13068. array[ i + 2 ] = nz;
  13069. array[ i + 3 ] = nx;
  13070. array[ i + 4 ] = ny;
  13071. array[ i + 5 ] = nz;
  13072. array[ i + 6 ] = nx;
  13073. array[ i + 7 ] = ny;
  13074. array[ i + 8 ] = nz;
  13075. }
  13076. }
  13077. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  13078. state.enableAttribute( attributes.normal );
  13079. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  13080. }
  13081. if ( object.hasUvs && material.map ) {
  13082. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  13083. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  13084. state.enableAttribute( attributes.uv );
  13085. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  13086. }
  13087. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  13088. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  13089. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  13090. state.enableAttribute( attributes.color );
  13091. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  13092. }
  13093. state.disableUnusedAttributes();
  13094. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  13095. object.count = 0;
  13096. };
  13097. this.renderBufferDirect = function ( camera, lights, fog, geometry, material, object, group ) {
  13098. setMaterial( material );
  13099. var program = setProgram( camera, lights, fog, material, object );
  13100. var updateBuffers = false;
  13101. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  13102. if ( geometryProgram !== _currentGeometryProgram ) {
  13103. _currentGeometryProgram = geometryProgram;
  13104. updateBuffers = true;
  13105. }
  13106. // morph targets
  13107. var morphTargetInfluences = object.morphTargetInfluences;
  13108. if ( morphTargetInfluences !== undefined ) {
  13109. var activeInfluences = [];
  13110. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  13111. var influence = morphTargetInfluences[ i ];
  13112. activeInfluences.push( [ influence, i ] );
  13113. }
  13114. activeInfluences.sort( numericalSort );
  13115. if ( activeInfluences.length > 8 ) {
  13116. activeInfluences.length = 8;
  13117. }
  13118. var morphAttributes = geometry.morphAttributes;
  13119. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  13120. var influence = activeInfluences[ i ];
  13121. morphInfluences[ i ] = influence[ 0 ];
  13122. if ( influence[ 0 ] !== 0 ) {
  13123. var index = influence[ 1 ];
  13124. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  13125. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  13126. } else {
  13127. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  13128. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  13129. }
  13130. }
  13131. var uniforms = program.getUniforms();
  13132. if ( uniforms.morphTargetInfluences !== null ) {
  13133. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  13134. }
  13135. updateBuffers = true;
  13136. }
  13137. //
  13138. var index = geometry.index;
  13139. var position = geometry.attributes.position;
  13140. if ( material.wireframe === true ) {
  13141. index = objects.getWireframeAttribute( geometry );
  13142. }
  13143. var renderer;
  13144. if ( index !== null ) {
  13145. renderer = indexedBufferRenderer;
  13146. renderer.setIndex( index );
  13147. } else {
  13148. renderer = bufferRenderer;
  13149. }
  13150. if ( updateBuffers ) {
  13151. setupVertexAttributes( material, program, geometry );
  13152. if ( index !== null ) {
  13153. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  13154. }
  13155. }
  13156. var drawStart = geometry.drawRange.start;
  13157. var drawCount = geometry.drawRange.count;
  13158. if ( drawCount === Infinity ) {
  13159. drawCount = index !== null ? index.count : position.count;
  13160. }
  13161. if ( group !== null ) {
  13162. drawStart = Math.max( drawStart, group.start );
  13163. drawCount = Math.min( drawCount, group.count );
  13164. }
  13165. if ( object instanceof THREE.Mesh ) {
  13166. if ( material.wireframe === true ) {
  13167. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  13168. renderer.setMode( _gl.LINES );
  13169. } else {
  13170. renderer.setMode( _gl.TRIANGLES );
  13171. }
  13172. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  13173. renderer.renderInstances( geometry );
  13174. } else {
  13175. renderer.render( drawStart, drawCount );
  13176. }
  13177. } else if ( object instanceof THREE.Line ) {
  13178. var lineWidth = material.linewidth;
  13179. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13180. state.setLineWidth( lineWidth * pixelRatio );
  13181. if ( object instanceof THREE.LineSegments ) {
  13182. renderer.setMode( _gl.LINES );
  13183. } else {
  13184. renderer.setMode( _gl.LINE_STRIP );
  13185. }
  13186. renderer.render( drawStart, drawCount );
  13187. } else if ( object instanceof THREE.Points ) {
  13188. renderer.setMode( _gl.POINTS );
  13189. renderer.render( drawStart, drawCount );
  13190. }
  13191. };
  13192. function setupVertexAttributes( material, program, geometry, startIndex ) {
  13193. var extension;
  13194. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  13195. extension = extensions.get( 'ANGLE_instanced_arrays' );
  13196. if ( extension === null ) {
  13197. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13198. return;
  13199. }
  13200. }
  13201. if ( startIndex === undefined ) startIndex = 0;
  13202. state.initAttributes();
  13203. var geometryAttributes = geometry.attributes;
  13204. var programAttributes = program.getAttributes();
  13205. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13206. for ( var name in programAttributes ) {
  13207. var programAttribute = programAttributes[ name ];
  13208. if ( programAttribute >= 0 ) {
  13209. var geometryAttribute = geometryAttributes[ name ];
  13210. if ( geometryAttribute !== undefined ) {
  13211. var size = geometryAttribute.itemSize;
  13212. var buffer = objects.getAttributeBuffer( geometryAttribute );
  13213. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  13214. var data = geometryAttribute.data;
  13215. var stride = data.stride;
  13216. var offset = geometryAttribute.offset;
  13217. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  13218. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  13219. if ( geometry.maxInstancedCount === undefined ) {
  13220. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13221. }
  13222. } else {
  13223. state.enableAttribute( programAttribute );
  13224. }
  13225. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13226. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  13227. } else {
  13228. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  13229. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  13230. if ( geometry.maxInstancedCount === undefined ) {
  13231. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13232. }
  13233. } else {
  13234. state.enableAttribute( programAttribute );
  13235. }
  13236. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13237. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  13238. }
  13239. } else if ( materialDefaultAttributeValues !== undefined ) {
  13240. var value = materialDefaultAttributeValues[ name ];
  13241. if ( value !== undefined ) {
  13242. switch ( value.length ) {
  13243. case 2:
  13244. _gl.vertexAttrib2fv( programAttribute, value );
  13245. break;
  13246. case 3:
  13247. _gl.vertexAttrib3fv( programAttribute, value );
  13248. break;
  13249. case 4:
  13250. _gl.vertexAttrib4fv( programAttribute, value );
  13251. break;
  13252. default:
  13253. _gl.vertexAttrib1fv( programAttribute, value );
  13254. }
  13255. }
  13256. }
  13257. }
  13258. }
  13259. state.disableUnusedAttributes();
  13260. }
  13261. // Sorting
  13262. function numericalSort ( a, b ) {
  13263. return b[ 0 ] - a[ 0 ];
  13264. }
  13265. function painterSortStable ( a, b ) {
  13266. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13267. return a.object.renderOrder - b.object.renderOrder;
  13268. } else if ( a.material.id !== b.material.id ) {
  13269. return a.material.id - b.material.id;
  13270. } else if ( a.z !== b.z ) {
  13271. return a.z - b.z;
  13272. } else {
  13273. return a.id - b.id;
  13274. }
  13275. }
  13276. function reversePainterSortStable ( a, b ) {
  13277. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13278. return a.object.renderOrder - b.object.renderOrder;
  13279. } if ( a.z !== b.z ) {
  13280. return b.z - a.z;
  13281. } else {
  13282. return a.id - b.id;
  13283. }
  13284. }
  13285. // Rendering
  13286. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13287. if ( camera instanceof THREE.Camera === false ) {
  13288. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13289. return;
  13290. }
  13291. var fog = scene.fog;
  13292. // reset caching for this frame
  13293. _currentGeometryProgram = '';
  13294. _currentMaterialId = - 1;
  13295. _currentCamera = null;
  13296. _lightsNeedUpdate = true;
  13297. // update scene graph
  13298. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13299. // update camera matrices and frustum
  13300. if ( camera.parent === null ) camera.updateMatrixWorld();
  13301. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13302. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13303. _frustum.setFromMatrix( _projScreenMatrix );
  13304. lights.length = 0;
  13305. opaqueObjectsLastIndex = - 1;
  13306. transparentObjectsLastIndex = - 1;
  13307. sprites.length = 0;
  13308. lensFlares.length = 0;
  13309. projectObject( scene );
  13310. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  13311. transparentObjects.length = transparentObjectsLastIndex + 1;
  13312. if ( _this.sortObjects === true ) {
  13313. opaqueObjects.sort( painterSortStable );
  13314. transparentObjects.sort( reversePainterSortStable );
  13315. }
  13316. //
  13317. shadowMap.render( scene );
  13318. //
  13319. _infoRender.calls = 0;
  13320. _infoRender.vertices = 0;
  13321. _infoRender.faces = 0;
  13322. _infoRender.points = 0;
  13323. this.setRenderTarget( renderTarget );
  13324. if ( this.autoClear || forceClear ) {
  13325. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  13326. }
  13327. //
  13328. if ( scene.overrideMaterial ) {
  13329. var overrideMaterial = scene.overrideMaterial;
  13330. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  13331. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  13332. } else {
  13333. // opaque pass (front-to-back order)
  13334. state.setBlending( THREE.NoBlending );
  13335. renderObjects( opaqueObjects, camera, lights, fog );
  13336. // transparent pass (back-to-front order)
  13337. renderObjects( transparentObjects, camera, lights, fog );
  13338. }
  13339. // custom render plugins (post pass)
  13340. spritePlugin.render( scene, camera );
  13341. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  13342. // Generate mipmap if we're using any kind of mipmap filtering
  13343. if ( renderTarget ) {
  13344. var texture = renderTarget.texture;
  13345. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  13346. if ( texture.generateMipmaps && isTargetPowerOfTwo && texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13347. updateRenderTargetMipmap( renderTarget );
  13348. }
  13349. }
  13350. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13351. state.setDepthTest( true );
  13352. state.setDepthWrite( true );
  13353. state.setColorWrite( true );
  13354. // _gl.finish();
  13355. };
  13356. function pushRenderItem( object, geometry, material, z, group ) {
  13357. var array, index;
  13358. // allocate the next position in the appropriate array
  13359. if ( material.transparent ) {
  13360. array = transparentObjects;
  13361. index = ++ transparentObjectsLastIndex;
  13362. } else {
  13363. array = opaqueObjects;
  13364. index = ++ opaqueObjectsLastIndex;
  13365. }
  13366. // recycle existing render item or grow the array
  13367. var renderItem = array[ index ];
  13368. if ( renderItem !== undefined ) {
  13369. renderItem.id = object.id;
  13370. renderItem.object = object;
  13371. renderItem.geometry = geometry;
  13372. renderItem.material = material;
  13373. renderItem.z = _vector3.z;
  13374. renderItem.group = group;
  13375. } else {
  13376. renderItem = {
  13377. id: object.id,
  13378. object: object,
  13379. geometry: geometry,
  13380. material: material,
  13381. z: _vector3.z,
  13382. group: group
  13383. };
  13384. // assert( index === array.length );
  13385. array.push( renderItem );
  13386. }
  13387. }
  13388. function projectObject( object ) {
  13389. if ( object.visible === false ) return;
  13390. if ( object instanceof THREE.Light ) {
  13391. lights.push( object );
  13392. } else if ( object instanceof THREE.Sprite ) {
  13393. sprites.push( object );
  13394. } else if ( object instanceof THREE.LensFlare ) {
  13395. lensFlares.push( object );
  13396. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  13397. if ( _this.sortObjects === true ) {
  13398. _vector3.setFromMatrixPosition( object.matrixWorld );
  13399. _vector3.applyProjection( _projScreenMatrix );
  13400. }
  13401. pushRenderItem( object, null, object.material, _vector3.z, null );
  13402. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  13403. if ( object instanceof THREE.SkinnedMesh ) {
  13404. object.skeleton.update();
  13405. }
  13406. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  13407. var material = object.material;
  13408. if ( material.visible === true ) {
  13409. if ( _this.sortObjects === true ) {
  13410. _vector3.setFromMatrixPosition( object.matrixWorld );
  13411. _vector3.applyProjection( _projScreenMatrix );
  13412. }
  13413. var geometry = objects.update( object );
  13414. if ( material instanceof THREE.MeshFaceMaterial ) {
  13415. var groups = geometry.groups;
  13416. var materials = material.materials;
  13417. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13418. var group = groups[ i ];
  13419. var groupMaterial = materials[ group.materialIndex ];
  13420. if ( groupMaterial.visible === true ) {
  13421. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  13422. }
  13423. }
  13424. } else {
  13425. pushRenderItem( object, geometry, material, _vector3.z, null );
  13426. }
  13427. }
  13428. }
  13429. }
  13430. var children = object.children;
  13431. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13432. projectObject( children[ i ] );
  13433. }
  13434. }
  13435. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  13436. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  13437. var renderItem = renderList[ i ];
  13438. var object = renderItem.object;
  13439. var geometry = renderItem.geometry;
  13440. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  13441. var group = renderItem.group;
  13442. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13443. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  13444. if ( object instanceof THREE.ImmediateRenderObject ) {
  13445. setMaterial( material );
  13446. var program = setProgram( camera, lights, fog, material, object );
  13447. _currentGeometryProgram = '';
  13448. object.render( function ( object ) {
  13449. _this.renderBufferImmediate( object, program, material );
  13450. } );
  13451. } else {
  13452. _this.renderBufferDirect( camera, lights, fog, geometry, material, object, group );
  13453. }
  13454. }
  13455. }
  13456. function initMaterial( material, lights, fog, object ) {
  13457. var materialProperties = properties.get( material );
  13458. var parameters = programCache.getParameters( material, lights, fog, object );
  13459. var code = programCache.getProgramCode( material, parameters );
  13460. var program = materialProperties.program;
  13461. var programChange = true;
  13462. if ( program === undefined ) {
  13463. // new material
  13464. material.addEventListener( 'dispose', onMaterialDispose );
  13465. } else if ( program.code !== code ) {
  13466. // changed glsl or parameters
  13467. releaseMaterialProgramReference( material );
  13468. } else if ( parameters.shaderID !== undefined ) {
  13469. // same glsl and uniform list
  13470. return;
  13471. } else {
  13472. // only rebuild uniform list
  13473. programChange = false;
  13474. }
  13475. if ( programChange ) {
  13476. if ( parameters.shaderID ) {
  13477. var shader = THREE.ShaderLib[ parameters.shaderID ];
  13478. materialProperties.__webglShader = {
  13479. name: material.type,
  13480. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  13481. vertexShader: shader.vertexShader,
  13482. fragmentShader: shader.fragmentShader
  13483. };
  13484. } else {
  13485. materialProperties.__webglShader = {
  13486. name: material.type,
  13487. uniforms: material.uniforms,
  13488. vertexShader: material.vertexShader,
  13489. fragmentShader: material.fragmentShader
  13490. };
  13491. }
  13492. material.__webglShader = materialProperties.__webglShader;
  13493. program = programCache.acquireProgram( material, parameters, code );
  13494. materialProperties.program = program;
  13495. material.program = program;
  13496. }
  13497. var attributes = program.getAttributes();
  13498. if ( material.morphTargets ) {
  13499. material.numSupportedMorphTargets = 0;
  13500. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  13501. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  13502. material.numSupportedMorphTargets ++;
  13503. }
  13504. }
  13505. }
  13506. if ( material.morphNormals ) {
  13507. material.numSupportedMorphNormals = 0;
  13508. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  13509. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  13510. material.numSupportedMorphNormals ++;
  13511. }
  13512. }
  13513. }
  13514. materialProperties.uniformsList = [];
  13515. var uniformLocations = materialProperties.program.getUniforms();
  13516. for ( var u in materialProperties.__webglShader.uniforms ) {
  13517. var location = uniformLocations[ u ];
  13518. if ( location ) {
  13519. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  13520. }
  13521. }
  13522. }
  13523. function setMaterial( material ) {
  13524. setMaterialFaces( material );
  13525. if ( material.transparent === true ) {
  13526. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  13527. } else {
  13528. state.setBlending( THREE.NoBlending );
  13529. }
  13530. state.setDepthFunc( material.depthFunc );
  13531. state.setDepthTest( material.depthTest );
  13532. state.setDepthWrite( material.depthWrite );
  13533. state.setColorWrite( material.colorWrite );
  13534. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  13535. }
  13536. function setMaterialFaces( material ) {
  13537. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  13538. state.setFlipSided( material.side === THREE.BackSide );
  13539. }
  13540. function setProgram( camera, lights, fog, material, object ) {
  13541. _usedTextureUnits = 0;
  13542. var materialProperties = properties.get( material );
  13543. if ( material.needsUpdate || ! materialProperties.program ) {
  13544. initMaterial( material, lights, fog, object );
  13545. material.needsUpdate = false;
  13546. }
  13547. var refreshProgram = false;
  13548. var refreshMaterial = false;
  13549. var refreshLights = false;
  13550. var program = materialProperties.program,
  13551. p_uniforms = program.getUniforms(),
  13552. m_uniforms = materialProperties.__webglShader.uniforms;
  13553. if ( program.id !== _currentProgram ) {
  13554. _gl.useProgram( program.program );
  13555. _currentProgram = program.id;
  13556. refreshProgram = true;
  13557. refreshMaterial = true;
  13558. refreshLights = true;
  13559. }
  13560. if ( material.id !== _currentMaterialId ) {
  13561. if ( _currentMaterialId === - 1 ) refreshLights = true;
  13562. _currentMaterialId = material.id;
  13563. refreshMaterial = true;
  13564. }
  13565. if ( refreshProgram || camera !== _currentCamera ) {
  13566. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  13567. if ( capabilities.logarithmicDepthBuffer ) {
  13568. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  13569. }
  13570. if ( camera !== _currentCamera ) _currentCamera = camera;
  13571. // load material specific uniforms
  13572. // (shader material also gets them for the sake of genericity)
  13573. if ( material instanceof THREE.ShaderMaterial ||
  13574. material instanceof THREE.MeshPhongMaterial ||
  13575. material.envMap ) {
  13576. if ( p_uniforms.cameraPosition !== undefined ) {
  13577. _vector3.setFromMatrixPosition( camera.matrixWorld );
  13578. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  13579. }
  13580. }
  13581. if ( material instanceof THREE.MeshPhongMaterial ||
  13582. material instanceof THREE.MeshLambertMaterial ||
  13583. material instanceof THREE.MeshBasicMaterial ||
  13584. material instanceof THREE.ShaderMaterial ||
  13585. material.skinning ) {
  13586. if ( p_uniforms.viewMatrix !== undefined ) {
  13587. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  13588. }
  13589. }
  13590. }
  13591. // skinning uniforms must be set even if material didn't change
  13592. // auto-setting of texture unit for bone texture must go before other textures
  13593. // not sure why, but otherwise weird things happen
  13594. if ( material.skinning ) {
  13595. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  13596. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  13597. }
  13598. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  13599. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  13600. }
  13601. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  13602. if ( p_uniforms.boneTexture !== undefined ) {
  13603. var textureUnit = getTextureUnit();
  13604. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  13605. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  13606. }
  13607. if ( p_uniforms.boneTextureWidth !== undefined ) {
  13608. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  13609. }
  13610. if ( p_uniforms.boneTextureHeight !== undefined ) {
  13611. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  13612. }
  13613. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  13614. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  13615. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  13616. }
  13617. }
  13618. }
  13619. if ( refreshMaterial ) {
  13620. // refresh uniforms common to several materials
  13621. if ( fog && material.fog ) {
  13622. refreshUniformsFog( m_uniforms, fog );
  13623. }
  13624. if ( material instanceof THREE.MeshPhongMaterial ||
  13625. material instanceof THREE.MeshLambertMaterial ||
  13626. material.lights ) {
  13627. if ( _lightsNeedUpdate ) {
  13628. refreshLights = true;
  13629. setupLights( lights, camera );
  13630. _lightsNeedUpdate = false;
  13631. }
  13632. if ( refreshLights ) {
  13633. refreshUniformsLights( m_uniforms, _lights );
  13634. markUniformsLightsNeedsUpdate( m_uniforms, true );
  13635. } else {
  13636. markUniformsLightsNeedsUpdate( m_uniforms, false );
  13637. }
  13638. }
  13639. if ( material instanceof THREE.MeshBasicMaterial ||
  13640. material instanceof THREE.MeshLambertMaterial ||
  13641. material instanceof THREE.MeshPhongMaterial ) {
  13642. refreshUniformsCommon( m_uniforms, material );
  13643. }
  13644. // refresh single material specific uniforms
  13645. if ( material instanceof THREE.LineBasicMaterial ) {
  13646. refreshUniformsLine( m_uniforms, material );
  13647. } else if ( material instanceof THREE.LineDashedMaterial ) {
  13648. refreshUniformsLine( m_uniforms, material );
  13649. refreshUniformsDash( m_uniforms, material );
  13650. } else if ( material instanceof THREE.PointsMaterial ) {
  13651. refreshUniformsParticle( m_uniforms, material );
  13652. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  13653. refreshUniformsPhong( m_uniforms, material );
  13654. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  13655. m_uniforms.mNear.value = camera.near;
  13656. m_uniforms.mFar.value = camera.far;
  13657. m_uniforms.opacity.value = material.opacity;
  13658. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  13659. m_uniforms.opacity.value = material.opacity;
  13660. }
  13661. if ( object.receiveShadow && ! material._shadowPass ) {
  13662. refreshUniformsShadow( m_uniforms, lights, camera );
  13663. }
  13664. // load common uniforms
  13665. loadUniformsGeneric( materialProperties.uniformsList );
  13666. }
  13667. loadUniformsMatrices( p_uniforms, object );
  13668. if ( p_uniforms.modelMatrix !== undefined ) {
  13669. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  13670. }
  13671. return program;
  13672. }
  13673. // Uniforms (refresh uniforms objects)
  13674. function refreshUniformsCommon ( uniforms, material ) {
  13675. uniforms.opacity.value = material.opacity;
  13676. uniforms.diffuse.value = material.color;
  13677. if ( material.emissive ) {
  13678. uniforms.emissive.value = material.emissive;
  13679. }
  13680. uniforms.map.value = material.map;
  13681. uniforms.specularMap.value = material.specularMap;
  13682. uniforms.alphaMap.value = material.alphaMap;
  13683. if ( material.aoMap ) {
  13684. uniforms.aoMap.value = material.aoMap;
  13685. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13686. }
  13687. // uv repeat and offset setting priorities
  13688. // 1. color map
  13689. // 2. specular map
  13690. // 3. normal map
  13691. // 4. bump map
  13692. // 5. alpha map
  13693. // 6. emissive map
  13694. var uvScaleMap;
  13695. if ( material.map ) {
  13696. uvScaleMap = material.map;
  13697. } else if ( material.specularMap ) {
  13698. uvScaleMap = material.specularMap;
  13699. } else if ( material.displacementMap ) {
  13700. uvScaleMap = material.displacementMap;
  13701. } else if ( material.normalMap ) {
  13702. uvScaleMap = material.normalMap;
  13703. } else if ( material.bumpMap ) {
  13704. uvScaleMap = material.bumpMap;
  13705. } else if ( material.alphaMap ) {
  13706. uvScaleMap = material.alphaMap;
  13707. } else if ( material.emissiveMap ) {
  13708. uvScaleMap = material.emissiveMap;
  13709. }
  13710. if ( uvScaleMap !== undefined ) {
  13711. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) uvScaleMap = uvScaleMap.texture;
  13712. var offset = uvScaleMap.offset;
  13713. var repeat = uvScaleMap.repeat;
  13714. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13715. }
  13716. uniforms.envMap.value = material.envMap;
  13717. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  13718. uniforms.reflectivity.value = material.reflectivity;
  13719. uniforms.refractionRatio.value = material.refractionRatio;
  13720. }
  13721. function refreshUniformsLine ( uniforms, material ) {
  13722. uniforms.diffuse.value = material.color;
  13723. uniforms.opacity.value = material.opacity;
  13724. }
  13725. function refreshUniformsDash ( uniforms, material ) {
  13726. uniforms.dashSize.value = material.dashSize;
  13727. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13728. uniforms.scale.value = material.scale;
  13729. }
  13730. function refreshUniformsParticle ( uniforms, material ) {
  13731. uniforms.psColor.value = material.color;
  13732. uniforms.opacity.value = material.opacity;
  13733. uniforms.size.value = material.size;
  13734. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  13735. uniforms.map.value = material.map;
  13736. if ( material.map !== null ) {
  13737. var offset = material.map.offset;
  13738. var repeat = material.map.repeat;
  13739. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13740. }
  13741. }
  13742. function refreshUniformsFog ( uniforms, fog ) {
  13743. uniforms.fogColor.value = fog.color;
  13744. if ( fog instanceof THREE.Fog ) {
  13745. uniforms.fogNear.value = fog.near;
  13746. uniforms.fogFar.value = fog.far;
  13747. } else if ( fog instanceof THREE.FogExp2 ) {
  13748. uniforms.fogDensity.value = fog.density;
  13749. }
  13750. }
  13751. function refreshUniformsPhong ( uniforms, material ) {
  13752. uniforms.specular.value = material.specular;
  13753. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13754. if ( material.lightMap ) {
  13755. uniforms.lightMap.value = material.lightMap;
  13756. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13757. }
  13758. if ( material.emissiveMap ) {
  13759. uniforms.emissiveMap.value = material.emissiveMap;
  13760. }
  13761. if ( material.bumpMap ) {
  13762. uniforms.bumpMap.value = material.bumpMap;
  13763. uniforms.bumpScale.value = material.bumpScale;
  13764. }
  13765. if ( material.normalMap ) {
  13766. uniforms.normalMap.value = material.normalMap;
  13767. uniforms.normalScale.value.copy( material.normalScale );
  13768. }
  13769. if ( material.displacementMap ) {
  13770. uniforms.displacementMap.value = material.displacementMap;
  13771. uniforms.displacementScale.value = material.displacementScale;
  13772. uniforms.displacementBias.value = material.displacementBias;
  13773. }
  13774. }
  13775. function refreshUniformsLights ( uniforms, lights ) {
  13776. uniforms.ambientLightColor.value = lights.ambient;
  13777. uniforms.directionalLightColor.value = lights.directional.colors;
  13778. uniforms.directionalLightDirection.value = lights.directional.positions;
  13779. uniforms.pointLightColor.value = lights.point.colors;
  13780. uniforms.pointLightPosition.value = lights.point.positions;
  13781. uniforms.pointLightDistance.value = lights.point.distances;
  13782. uniforms.pointLightDecay.value = lights.point.decays;
  13783. uniforms.spotLightColor.value = lights.spot.colors;
  13784. uniforms.spotLightPosition.value = lights.spot.positions;
  13785. uniforms.spotLightDistance.value = lights.spot.distances;
  13786. uniforms.spotLightDirection.value = lights.spot.directions;
  13787. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  13788. uniforms.spotLightExponent.value = lights.spot.exponents;
  13789. uniforms.spotLightDecay.value = lights.spot.decays;
  13790. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  13791. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  13792. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  13793. }
  13794. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13795. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  13796. uniforms.ambientLightColor.needsUpdate = value;
  13797. uniforms.directionalLightColor.needsUpdate = value;
  13798. uniforms.directionalLightDirection.needsUpdate = value;
  13799. uniforms.pointLightColor.needsUpdate = value;
  13800. uniforms.pointLightPosition.needsUpdate = value;
  13801. uniforms.pointLightDistance.needsUpdate = value;
  13802. uniforms.pointLightDecay.needsUpdate = value;
  13803. uniforms.spotLightColor.needsUpdate = value;
  13804. uniforms.spotLightPosition.needsUpdate = value;
  13805. uniforms.spotLightDistance.needsUpdate = value;
  13806. uniforms.spotLightDirection.needsUpdate = value;
  13807. uniforms.spotLightAngleCos.needsUpdate = value;
  13808. uniforms.spotLightExponent.needsUpdate = value;
  13809. uniforms.spotLightDecay.needsUpdate = value;
  13810. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  13811. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  13812. uniforms.hemisphereLightDirection.needsUpdate = value;
  13813. }
  13814. function refreshUniformsShadow ( uniforms, lights, camera ) {
  13815. if ( uniforms.shadowMatrix ) {
  13816. var j = 0;
  13817. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  13818. var light = lights[ i ];
  13819. if ( ! light.castShadow ) continue;
  13820. if ( light instanceof THREE.PointLight || light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) {
  13821. if ( light instanceof THREE.PointLight ) {
  13822. // for point lights we set the shadow matrix to be a translation-only matrix
  13823. // equal to inverse of the light's position
  13824. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  13825. light.shadowMatrix.identity().setPosition( _vector3 );
  13826. // for point lights we set the sign of the shadowDarkness uniform to be negative
  13827. uniforms.shadowDarkness.value[ j ] = - light.shadowDarkness;
  13828. } else {
  13829. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  13830. }
  13831. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  13832. uniforms.shadowMap.value[ j ] = light.shadowMap;
  13833. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  13834. uniforms.shadowBias.value[ j ] = light.shadowBias;
  13835. j ++;
  13836. }
  13837. }
  13838. }
  13839. }
  13840. // Uniforms (load to GPU)
  13841. function loadUniformsMatrices ( uniforms, object ) {
  13842. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  13843. if ( uniforms.normalMatrix ) {
  13844. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  13845. }
  13846. }
  13847. function getTextureUnit() {
  13848. var textureUnit = _usedTextureUnits;
  13849. if ( textureUnit >= capabilities.maxTextures ) {
  13850. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13851. }
  13852. _usedTextureUnits += 1;
  13853. return textureUnit;
  13854. }
  13855. function loadUniformsGeneric ( uniforms ) {
  13856. var texture, textureUnit;
  13857. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  13858. var uniform = uniforms[ j ][ 0 ];
  13859. // needsUpdate property is not added to all uniforms.
  13860. if ( uniform.needsUpdate === false ) continue;
  13861. var type = uniform.type;
  13862. var value = uniform.value;
  13863. var location = uniforms[ j ][ 1 ];
  13864. switch ( type ) {
  13865. case '1i':
  13866. _gl.uniform1i( location, value );
  13867. break;
  13868. case '1f':
  13869. _gl.uniform1f( location, value );
  13870. break;
  13871. case '2f':
  13872. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  13873. break;
  13874. case '3f':
  13875. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  13876. break;
  13877. case '4f':
  13878. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  13879. break;
  13880. case '1iv':
  13881. _gl.uniform1iv( location, value );
  13882. break;
  13883. case '3iv':
  13884. _gl.uniform3iv( location, value );
  13885. break;
  13886. case '1fv':
  13887. _gl.uniform1fv( location, value );
  13888. break;
  13889. case '2fv':
  13890. _gl.uniform2fv( location, value );
  13891. break;
  13892. case '3fv':
  13893. _gl.uniform3fv( location, value );
  13894. break;
  13895. case '4fv':
  13896. _gl.uniform4fv( location, value );
  13897. break;
  13898. case 'Matrix3fv':
  13899. _gl.uniformMatrix3fv( location, false, value );
  13900. break;
  13901. case 'Matrix4fv':
  13902. _gl.uniformMatrix4fv( location, false, value );
  13903. break;
  13904. //
  13905. case 'i':
  13906. // single integer
  13907. _gl.uniform1i( location, value );
  13908. break;
  13909. case 'f':
  13910. // single float
  13911. _gl.uniform1f( location, value );
  13912. break;
  13913. case 'v2':
  13914. // single THREE.Vector2
  13915. _gl.uniform2f( location, value.x, value.y );
  13916. break;
  13917. case 'v3':
  13918. // single THREE.Vector3
  13919. _gl.uniform3f( location, value.x, value.y, value.z );
  13920. break;
  13921. case 'v4':
  13922. // single THREE.Vector4
  13923. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  13924. break;
  13925. case 'c':
  13926. // single THREE.Color
  13927. _gl.uniform3f( location, value.r, value.g, value.b );
  13928. break;
  13929. case 'iv1':
  13930. // flat array of integers (JS or typed array)
  13931. _gl.uniform1iv( location, value );
  13932. break;
  13933. case 'iv':
  13934. // flat array of integers with 3 x N size (JS or typed array)
  13935. _gl.uniform3iv( location, value );
  13936. break;
  13937. case 'fv1':
  13938. // flat array of floats (JS or typed array)
  13939. _gl.uniform1fv( location, value );
  13940. break;
  13941. case 'fv':
  13942. // flat array of floats with 3 x N size (JS or typed array)
  13943. _gl.uniform3fv( location, value );
  13944. break;
  13945. case 'v2v':
  13946. // array of THREE.Vector2
  13947. if ( uniform._array === undefined ) {
  13948. uniform._array = new Float32Array( 2 * value.length );
  13949. }
  13950. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  13951. uniform._array[ i2 + 0 ] = value[ i ].x;
  13952. uniform._array[ i2 + 1 ] = value[ i ].y;
  13953. }
  13954. _gl.uniform2fv( location, uniform._array );
  13955. break;
  13956. case 'v3v':
  13957. // array of THREE.Vector3
  13958. if ( uniform._array === undefined ) {
  13959. uniform._array = new Float32Array( 3 * value.length );
  13960. }
  13961. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  13962. uniform._array[ i3 + 0 ] = value[ i ].x;
  13963. uniform._array[ i3 + 1 ] = value[ i ].y;
  13964. uniform._array[ i3 + 2 ] = value[ i ].z;
  13965. }
  13966. _gl.uniform3fv( location, uniform._array );
  13967. break;
  13968. case 'v4v':
  13969. // array of THREE.Vector4
  13970. if ( uniform._array === undefined ) {
  13971. uniform._array = new Float32Array( 4 * value.length );
  13972. }
  13973. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  13974. uniform._array[ i4 + 0 ] = value[ i ].x;
  13975. uniform._array[ i4 + 1 ] = value[ i ].y;
  13976. uniform._array[ i4 + 2 ] = value[ i ].z;
  13977. uniform._array[ i4 + 3 ] = value[ i ].w;
  13978. }
  13979. _gl.uniform4fv( location, uniform._array );
  13980. break;
  13981. case 'm3':
  13982. // single THREE.Matrix3
  13983. _gl.uniformMatrix3fv( location, false, value.elements );
  13984. break;
  13985. case 'm3v':
  13986. // array of THREE.Matrix3
  13987. if ( uniform._array === undefined ) {
  13988. uniform._array = new Float32Array( 9 * value.length );
  13989. }
  13990. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13991. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  13992. }
  13993. _gl.uniformMatrix3fv( location, false, uniform._array );
  13994. break;
  13995. case 'm4':
  13996. // single THREE.Matrix4
  13997. _gl.uniformMatrix4fv( location, false, value.elements );
  13998. break;
  13999. case 'm4v':
  14000. // array of THREE.Matrix4
  14001. if ( uniform._array === undefined ) {
  14002. uniform._array = new Float32Array( 16 * value.length );
  14003. }
  14004. for ( var i = 0, il = value.length; i < il; i ++ ) {
  14005. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  14006. }
  14007. _gl.uniformMatrix4fv( location, false, uniform._array );
  14008. break;
  14009. case 't':
  14010. // single THREE.Texture (2d or cube)
  14011. texture = value;
  14012. textureUnit = getTextureUnit();
  14013. _gl.uniform1i( location, textureUnit );
  14014. if ( ! texture ) continue;
  14015. if ( texture instanceof THREE.CubeTexture ||
  14016. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14017. // CompressedTexture can have Array in image :/
  14018. setCubeTexture( texture, textureUnit );
  14019. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  14020. setCubeTextureDynamic( texture.texture, textureUnit );
  14021. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  14022. _this.setTexture( texture.texture, textureUnit );
  14023. } else {
  14024. _this.setTexture( texture, textureUnit );
  14025. }
  14026. break;
  14027. case 'tv':
  14028. // array of THREE.Texture (2d or cube)
  14029. if ( uniform._array === undefined ) {
  14030. uniform._array = [];
  14031. }
  14032. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  14033. uniform._array[ i ] = getTextureUnit();
  14034. }
  14035. _gl.uniform1iv( location, uniform._array );
  14036. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  14037. texture = uniform.value[ i ];
  14038. textureUnit = uniform._array[ i ];
  14039. if ( ! texture ) continue;
  14040. if ( texture instanceof THREE.CubeTexture ||
  14041. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  14042. // CompressedTexture can have Array in image :/
  14043. setCubeTexture( texture, textureUnit );
  14044. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  14045. _this.setTexture( texture.texture, textureUnit );
  14046. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  14047. setCubeTextureDynamic( texture.texture, textureUnit );
  14048. } else {
  14049. _this.setTexture( texture, textureUnit );
  14050. }
  14051. }
  14052. break;
  14053. default:
  14054. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  14055. }
  14056. }
  14057. }
  14058. function setColorLinear( array, offset, color, intensity ) {
  14059. array[ offset + 0 ] = color.r * intensity;
  14060. array[ offset + 1 ] = color.g * intensity;
  14061. array[ offset + 2 ] = color.b * intensity;
  14062. }
  14063. function setupLights ( lights, camera ) {
  14064. var l, ll, light,
  14065. r = 0, g = 0, b = 0,
  14066. color, skyColor, groundColor,
  14067. intensity,
  14068. distance,
  14069. zlights = _lights,
  14070. viewMatrix = camera.matrixWorldInverse,
  14071. dirColors = zlights.directional.colors,
  14072. dirPositions = zlights.directional.positions,
  14073. pointColors = zlights.point.colors,
  14074. pointPositions = zlights.point.positions,
  14075. pointDistances = zlights.point.distances,
  14076. pointDecays = zlights.point.decays,
  14077. spotColors = zlights.spot.colors,
  14078. spotPositions = zlights.spot.positions,
  14079. spotDistances = zlights.spot.distances,
  14080. spotDirections = zlights.spot.directions,
  14081. spotAnglesCos = zlights.spot.anglesCos,
  14082. spotExponents = zlights.spot.exponents,
  14083. spotDecays = zlights.spot.decays,
  14084. hemiSkyColors = zlights.hemi.skyColors,
  14085. hemiGroundColors = zlights.hemi.groundColors,
  14086. hemiPositions = zlights.hemi.positions,
  14087. dirLength = 0,
  14088. pointLength = 0,
  14089. spotLength = 0,
  14090. hemiLength = 0,
  14091. dirCount = 0,
  14092. pointCount = 0,
  14093. spotCount = 0,
  14094. hemiCount = 0,
  14095. dirOffset = 0,
  14096. pointOffset = 0,
  14097. spotOffset = 0,
  14098. hemiOffset = 0;
  14099. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  14100. light = lights[ l ];
  14101. if ( light.onlyShadow ) continue;
  14102. color = light.color;
  14103. intensity = light.intensity;
  14104. distance = light.distance;
  14105. if ( light instanceof THREE.AmbientLight ) {
  14106. if ( ! light.visible ) continue;
  14107. r += color.r;
  14108. g += color.g;
  14109. b += color.b;
  14110. } else if ( light instanceof THREE.DirectionalLight ) {
  14111. dirCount += 1;
  14112. if ( ! light.visible ) continue;
  14113. _direction.setFromMatrixPosition( light.matrixWorld );
  14114. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14115. _direction.sub( _vector3 );
  14116. _direction.transformDirection( viewMatrix );
  14117. dirOffset = dirLength * 3;
  14118. dirPositions[ dirOffset + 0 ] = _direction.x;
  14119. dirPositions[ dirOffset + 1 ] = _direction.y;
  14120. dirPositions[ dirOffset + 2 ] = _direction.z;
  14121. setColorLinear( dirColors, dirOffset, color, intensity );
  14122. dirLength += 1;
  14123. } else if ( light instanceof THREE.PointLight ) {
  14124. pointCount += 1;
  14125. if ( ! light.visible ) continue;
  14126. pointOffset = pointLength * 3;
  14127. setColorLinear( pointColors, pointOffset, color, intensity );
  14128. _vector3.setFromMatrixPosition( light.matrixWorld );
  14129. _vector3.applyMatrix4( viewMatrix );
  14130. pointPositions[ pointOffset + 0 ] = _vector3.x;
  14131. pointPositions[ pointOffset + 1 ] = _vector3.y;
  14132. pointPositions[ pointOffset + 2 ] = _vector3.z;
  14133. // distance is 0 if decay is 0, because there is no attenuation at all.
  14134. pointDistances[ pointLength ] = distance;
  14135. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14136. pointLength += 1;
  14137. } else if ( light instanceof THREE.SpotLight ) {
  14138. spotCount += 1;
  14139. if ( ! light.visible ) continue;
  14140. spotOffset = spotLength * 3;
  14141. setColorLinear( spotColors, spotOffset, color, intensity );
  14142. _direction.setFromMatrixPosition( light.matrixWorld );
  14143. _vector3.copy( _direction ).applyMatrix4( viewMatrix );
  14144. spotPositions[ spotOffset + 0 ] = _vector3.x;
  14145. spotPositions[ spotOffset + 1 ] = _vector3.y;
  14146. spotPositions[ spotOffset + 2 ] = _vector3.z;
  14147. spotDistances[ spotLength ] = distance;
  14148. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14149. _direction.sub( _vector3 );
  14150. _direction.transformDirection( viewMatrix );
  14151. spotDirections[ spotOffset + 0 ] = _direction.x;
  14152. spotDirections[ spotOffset + 1 ] = _direction.y;
  14153. spotDirections[ spotOffset + 2 ] = _direction.z;
  14154. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  14155. spotExponents[ spotLength ] = light.exponent;
  14156. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14157. spotLength += 1;
  14158. } else if ( light instanceof THREE.HemisphereLight ) {
  14159. hemiCount += 1;
  14160. if ( ! light.visible ) continue;
  14161. _direction.setFromMatrixPosition( light.matrixWorld );
  14162. _direction.transformDirection( viewMatrix );
  14163. hemiOffset = hemiLength * 3;
  14164. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  14165. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  14166. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  14167. skyColor = light.color;
  14168. groundColor = light.groundColor;
  14169. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  14170. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  14171. hemiLength += 1;
  14172. }
  14173. }
  14174. // null eventual remains from removed lights
  14175. // (this is to avoid if in shader)
  14176. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  14177. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  14178. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  14179. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  14180. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  14181. zlights.directional.length = dirLength;
  14182. zlights.point.length = pointLength;
  14183. zlights.spot.length = spotLength;
  14184. zlights.hemi.length = hemiLength;
  14185. zlights.ambient[ 0 ] = r;
  14186. zlights.ambient[ 1 ] = g;
  14187. zlights.ambient[ 2 ] = b;
  14188. }
  14189. // GL state setting
  14190. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  14191. if ( cullFace === THREE.CullFaceNone ) {
  14192. state.disable( _gl.CULL_FACE );
  14193. } else {
  14194. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  14195. _gl.frontFace( _gl.CW );
  14196. } else {
  14197. _gl.frontFace( _gl.CCW );
  14198. }
  14199. if ( cullFace === THREE.CullFaceBack ) {
  14200. _gl.cullFace( _gl.BACK );
  14201. } else if ( cullFace === THREE.CullFaceFront ) {
  14202. _gl.cullFace( _gl.FRONT );
  14203. } else {
  14204. _gl.cullFace( _gl.FRONT_AND_BACK );
  14205. }
  14206. state.enable( _gl.CULL_FACE );
  14207. }
  14208. };
  14209. // Textures
  14210. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  14211. var extension;
  14212. if ( isImagePowerOfTwo ) {
  14213. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  14214. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  14215. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  14216. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  14217. } else {
  14218. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  14219. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  14220. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  14221. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  14222. }
  14223. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  14224. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  14225. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  14226. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  14227. }
  14228. }
  14229. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14230. if ( extension ) {
  14231. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  14232. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  14233. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  14234. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  14235. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  14236. }
  14237. }
  14238. }
  14239. function uploadTexture( textureProperties, texture, slot ) {
  14240. if ( textureProperties.__webglInit === undefined ) {
  14241. textureProperties.__webglInit = true;
  14242. texture.__webglInit = true;
  14243. texture.addEventListener( 'dispose', onTextureDispose );
  14244. textureProperties.__webglTexture = _gl.createTexture();
  14245. _infoMemory.textures ++;
  14246. }
  14247. state.activeTexture( _gl.TEXTURE0 + slot );
  14248. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14249. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14250. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  14251. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  14252. texture.image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  14253. var image = texture.image,
  14254. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  14255. glFormat = paramThreeToGL( texture.format ),
  14256. glType = paramThreeToGL( texture.type );
  14257. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  14258. var mipmap, mipmaps = texture.mipmaps;
  14259. if ( texture instanceof THREE.DataTexture ) {
  14260. // use manually created mipmaps if available
  14261. // if there are no manual mipmaps
  14262. // set 0 level mipmap and then use GL to generate other mipmap levels
  14263. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14264. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14265. mipmap = mipmaps[ i ];
  14266. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14267. }
  14268. texture.generateMipmaps = false;
  14269. } else {
  14270. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  14271. }
  14272. } else if ( texture instanceof THREE.CompressedTexture ) {
  14273. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14274. mipmap = mipmaps[ i ];
  14275. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14276. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14277. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14278. } else {
  14279. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  14280. }
  14281. } else {
  14282. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14283. }
  14284. }
  14285. } else {
  14286. // regular Texture (image, video, canvas)
  14287. // use manually created mipmaps if available
  14288. // if there are no manual mipmaps
  14289. // set 0 level mipmap and then use GL to generate other mipmap levels
  14290. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14291. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14292. mipmap = mipmaps[ i ];
  14293. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  14294. }
  14295. texture.generateMipmaps = false;
  14296. } else {
  14297. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  14298. }
  14299. }
  14300. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14301. textureProperties.__version = texture.version;
  14302. if ( texture.onUpdate ) texture.onUpdate( texture );
  14303. }
  14304. this.setTexture = function ( texture, slot ) {
  14305. var textureProperties = properties.get( texture );
  14306. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14307. var image = texture.image;
  14308. if ( image === undefined ) {
  14309. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  14310. return;
  14311. }
  14312. if ( image.complete === false ) {
  14313. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  14314. return;
  14315. }
  14316. uploadTexture( textureProperties, texture, slot );
  14317. return;
  14318. }
  14319. state.activeTexture( _gl.TEXTURE0 + slot );
  14320. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14321. };
  14322. function clampToMaxSize ( image, maxSize ) {
  14323. if ( image.width > maxSize || image.height > maxSize ) {
  14324. // Warning: Scaling through the canvas will only work with images that use
  14325. // premultiplied alpha.
  14326. var scale = maxSize / Math.max( image.width, image.height );
  14327. var canvas = document.createElement( 'canvas' );
  14328. canvas.width = Math.floor( image.width * scale );
  14329. canvas.height = Math.floor( image.height * scale );
  14330. var context = canvas.getContext( '2d' );
  14331. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  14332. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  14333. return canvas;
  14334. }
  14335. return image;
  14336. }
  14337. function setCubeTexture ( texture, slot ) {
  14338. var textureProperties = properties.get( texture );
  14339. if ( texture.image.length === 6 ) {
  14340. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14341. if ( ! textureProperties.__image__webglTextureCube ) {
  14342. texture.addEventListener( 'dispose', onTextureDispose );
  14343. textureProperties.__image__webglTextureCube = _gl.createTexture();
  14344. _infoMemory.textures ++;
  14345. }
  14346. state.activeTexture( _gl.TEXTURE0 + slot );
  14347. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14348. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14349. var isCompressed = texture instanceof THREE.CompressedTexture;
  14350. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  14351. var cubeImage = [];
  14352. for ( var i = 0; i < 6; i ++ ) {
  14353. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  14354. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  14355. } else {
  14356. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  14357. }
  14358. }
  14359. var image = cubeImage[ 0 ],
  14360. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  14361. glFormat = paramThreeToGL( texture.format ),
  14362. glType = paramThreeToGL( texture.type );
  14363. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  14364. for ( var i = 0; i < 6; i ++ ) {
  14365. if ( ! isCompressed ) {
  14366. if ( isDataTexture ) {
  14367. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  14368. } else {
  14369. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  14370. }
  14371. } else {
  14372. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  14373. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  14374. mipmap = mipmaps[ j ];
  14375. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14376. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14377. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14378. } else {
  14379. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  14380. }
  14381. } else {
  14382. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14383. }
  14384. }
  14385. }
  14386. }
  14387. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  14388. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14389. }
  14390. textureProperties.__version = texture.version;
  14391. if ( texture.onUpdate ) texture.onUpdate( texture );
  14392. } else {
  14393. state.activeTexture( _gl.TEXTURE0 + slot );
  14394. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14395. }
  14396. }
  14397. }
  14398. function setCubeTextureDynamic ( texture, slot ) {
  14399. state.activeTexture( _gl.TEXTURE0 + slot );
  14400. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  14401. }
  14402. // Render targets
  14403. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  14404. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14405. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  14406. }
  14407. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  14408. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  14409. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14410. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  14411. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14412. /* For some reason this is not working. Defaulting to RGBA4.
  14413. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14414. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  14415. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14416. */
  14417. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14418. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  14419. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14420. } else {
  14421. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  14422. }
  14423. }
  14424. this.setRenderTarget = function ( renderTarget ) {
  14425. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  14426. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14427. var renderTargetProperties = properties.get( renderTarget );
  14428. var textureProperties = properties.get( renderTarget.texture );
  14429. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  14430. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  14431. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  14432. textureProperties.__webglTexture = _gl.createTexture();
  14433. _infoMemory.textures ++;
  14434. // Setup texture, create render and frame buffers
  14435. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  14436. glFormat = paramThreeToGL( renderTarget.texture.format ),
  14437. glType = paramThreeToGL( renderTarget.texture.type );
  14438. if ( isCube ) {
  14439. renderTargetProperties.__webglFramebuffer = [];
  14440. renderTargetProperties.__webglRenderbuffer = [];
  14441. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  14442. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  14443. for ( var i = 0; i < 6; i ++ ) {
  14444. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  14445. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  14446. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14447. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  14448. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  14449. }
  14450. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14451. } else {
  14452. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  14453. if ( renderTarget.shareDepthFrom ) {
  14454. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  14455. } else {
  14456. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  14457. }
  14458. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14459. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  14460. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14461. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  14462. if ( renderTarget.shareDepthFrom ) {
  14463. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14464. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14465. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14466. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14467. }
  14468. } else {
  14469. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  14470. }
  14471. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14472. }
  14473. // Release everything
  14474. if ( isCube ) {
  14475. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  14476. } else {
  14477. state.bindTexture( _gl.TEXTURE_2D, null );
  14478. }
  14479. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  14480. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  14481. }
  14482. var framebuffer, width, height, vx, vy;
  14483. if ( renderTarget ) {
  14484. var renderTargetProperties = properties.get( renderTarget );
  14485. if ( isCube ) {
  14486. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  14487. } else {
  14488. framebuffer = renderTargetProperties.__webglFramebuffer;
  14489. }
  14490. width = renderTarget.width;
  14491. height = renderTarget.height;
  14492. vx = 0;
  14493. vy = 0;
  14494. } else {
  14495. framebuffer = null;
  14496. width = _viewportWidth;
  14497. height = _viewportHeight;
  14498. vx = _viewportX;
  14499. vy = _viewportY;
  14500. }
  14501. if ( framebuffer !== _currentFramebuffer ) {
  14502. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14503. _gl.viewport( vx, vy, width, height );
  14504. _currentFramebuffer = framebuffer;
  14505. }
  14506. if ( isCube ) {
  14507. var textureProperties = properties.get( renderTarget.texture );
  14508. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, 0 );
  14509. }
  14510. _currentWidth = width;
  14511. _currentHeight = height;
  14512. };
  14513. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14514. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  14515. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14516. return;
  14517. }
  14518. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14519. if ( framebuffer ) {
  14520. var restore = false;
  14521. if ( framebuffer !== _currentFramebuffer ) {
  14522. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14523. restore = true;
  14524. }
  14525. try {
  14526. var texture = renderTarget.texture;
  14527. if ( texture.format !== THREE.RGBAFormat
  14528. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  14529. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14530. return;
  14531. }
  14532. if ( texture.type !== THREE.UnsignedByteType
  14533. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  14534. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  14535. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  14536. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14537. return;
  14538. }
  14539. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  14540. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  14541. } else {
  14542. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14543. }
  14544. } finally {
  14545. if ( restore ) {
  14546. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  14547. }
  14548. }
  14549. }
  14550. };
  14551. function updateRenderTargetMipmap( renderTarget ) {
  14552. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  14553. var texture = properties.get( renderTarget.texture ).__webglTexture;
  14554. state.bindTexture( target, texture );
  14555. _gl.generateMipmap( target );
  14556. state.bindTexture( target, null );
  14557. }
  14558. // Fallback filters for non-power-of-2 textures
  14559. function filterFallback ( f ) {
  14560. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  14561. return _gl.NEAREST;
  14562. }
  14563. return _gl.LINEAR;
  14564. }
  14565. // Map three.js constants to WebGL constants
  14566. function paramThreeToGL ( p ) {
  14567. var extension;
  14568. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  14569. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  14570. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  14571. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  14572. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  14573. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  14574. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  14575. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  14576. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  14577. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  14578. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  14579. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  14580. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  14581. if ( p === THREE.ByteType ) return _gl.BYTE;
  14582. if ( p === THREE.ShortType ) return _gl.SHORT;
  14583. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  14584. if ( p === THREE.IntType ) return _gl.INT;
  14585. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  14586. if ( p === THREE.FloatType ) return _gl.FLOAT;
  14587. extension = extensions.get( 'OES_texture_half_float' );
  14588. if ( extension !== null ) {
  14589. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  14590. }
  14591. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  14592. if ( p === THREE.RGBFormat ) return _gl.RGB;
  14593. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  14594. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  14595. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  14596. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  14597. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  14598. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  14599. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  14600. if ( p === THREE.OneFactor ) return _gl.ONE;
  14601. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  14602. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  14603. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  14604. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  14605. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  14606. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  14607. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  14608. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  14609. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  14610. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14611. if ( extension !== null ) {
  14612. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  14613. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  14614. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  14615. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  14616. }
  14617. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14618. if ( extension !== null ) {
  14619. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  14620. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  14621. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  14622. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  14623. }
  14624. extension = extensions.get( 'EXT_blend_minmax' );
  14625. if ( extension !== null ) {
  14626. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  14627. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  14628. }
  14629. return 0;
  14630. }
  14631. // DEPRECATED
  14632. this.supportsFloatTextures = function () {
  14633. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  14634. return extensions.get( 'OES_texture_float' );
  14635. };
  14636. this.supportsHalfFloatTextures = function () {
  14637. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  14638. return extensions.get( 'OES_texture_half_float' );
  14639. };
  14640. this.supportsStandardDerivatives = function () {
  14641. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  14642. return extensions.get( 'OES_standard_derivatives' );
  14643. };
  14644. this.supportsCompressedTextureS3TC = function () {
  14645. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  14646. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14647. };
  14648. this.supportsCompressedTexturePVRTC = function () {
  14649. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  14650. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14651. };
  14652. this.supportsBlendMinMax = function () {
  14653. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  14654. return extensions.get( 'EXT_blend_minmax' );
  14655. };
  14656. this.supportsVertexTextures = function () {
  14657. return capabilities.vertexTextures;
  14658. };
  14659. this.supportsInstancedArrays = function () {
  14660. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  14661. return extensions.get( 'ANGLE_instanced_arrays' );
  14662. };
  14663. //
  14664. this.initMaterial = function () {
  14665. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  14666. };
  14667. this.addPrePlugin = function () {
  14668. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  14669. };
  14670. this.addPostPlugin = function () {
  14671. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  14672. };
  14673. this.updateShadowMap = function () {
  14674. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  14675. };
  14676. Object.defineProperties( this, {
  14677. shadowMapEnabled: {
  14678. get: function () {
  14679. return shadowMap.enabled;
  14680. },
  14681. set: function ( value ) {
  14682. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  14683. shadowMap.enabled = value;
  14684. }
  14685. },
  14686. shadowMapType: {
  14687. get: function () {
  14688. return shadowMap.type;
  14689. },
  14690. set: function ( value ) {
  14691. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  14692. shadowMap.type = value;
  14693. }
  14694. },
  14695. shadowMapCullFace: {
  14696. get: function () {
  14697. return shadowMap.cullFace;
  14698. },
  14699. set: function ( value ) {
  14700. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  14701. shadowMap.cullFace = value;
  14702. }
  14703. },
  14704. shadowMapDebug: {
  14705. get: function () {
  14706. return shadowMap.debug;
  14707. },
  14708. set: function ( value ) {
  14709. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  14710. shadowMap.debug = value;
  14711. }
  14712. }
  14713. } );
  14714. };
  14715. // File:src/renderers/WebGLRenderTarget.js
  14716. /**
  14717. * @author szimek / https://github.com/szimek/
  14718. * @author alteredq / http://alteredqualia.com/
  14719. */
  14720. THREE.WebGLRenderTarget = function ( width, height, options ) {
  14721. this.uuid = THREE.Math.generateUUID();
  14722. this.width = width;
  14723. this.height = height;
  14724. options = options || {};
  14725. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  14726. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  14727. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  14728. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  14729. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  14730. };
  14731. THREE.WebGLRenderTarget.prototype = {
  14732. constructor: THREE.WebGLRenderTarget,
  14733. get wrapS() {
  14734. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  14735. return this.texture.wrapS;
  14736. },
  14737. set wrapS( value ) {
  14738. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  14739. this.texture.wrapS = value;
  14740. },
  14741. get wrapT() {
  14742. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  14743. return this.texture.wrapT;
  14744. },
  14745. set wrapT( value ) {
  14746. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  14747. this.texture.wrapT = value;
  14748. },
  14749. get magFilter() {
  14750. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  14751. return this.texture.magFilter;
  14752. },
  14753. set magFilter( value ) {
  14754. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  14755. this.texture.magFilter = value;
  14756. },
  14757. get minFilter() {
  14758. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  14759. return this.texture.minFilter;
  14760. },
  14761. set minFilter( value ) {
  14762. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  14763. this.texture.minFilter = value;
  14764. },
  14765. get anisotropy() {
  14766. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  14767. return this.texture.anisotropy;
  14768. },
  14769. set anisotropy( value ) {
  14770. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  14771. this.texture.anisotropy = value;
  14772. },
  14773. get offset() {
  14774. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  14775. return this.texture.offset;
  14776. },
  14777. set offset( value ) {
  14778. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  14779. this.texture.offset = value;
  14780. },
  14781. get repeat() {
  14782. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  14783. return this.texture.repeat;
  14784. },
  14785. set repeat( value ) {
  14786. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  14787. this.texture.repeat = value;
  14788. },
  14789. get format() {
  14790. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  14791. return this.texture.format;
  14792. },
  14793. set format( value ) {
  14794. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  14795. this.texture.format = value;
  14796. },
  14797. get type() {
  14798. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  14799. return this.texture.type;
  14800. },
  14801. set type( value ) {
  14802. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  14803. this.texture.type = value;
  14804. },
  14805. get generateMipmaps() {
  14806. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  14807. return this.texture.generateMipmaps;
  14808. },
  14809. set generateMipmaps( value ) {
  14810. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  14811. this.texture.generateMipmaps = value;
  14812. },
  14813. //
  14814. setSize: function ( width, height ) {
  14815. if ( this.width !== width || this.height !== height ) {
  14816. this.width = width;
  14817. this.height = height;
  14818. this.dispose();
  14819. }
  14820. },
  14821. clone: function () {
  14822. return new this.constructor().copy( this );
  14823. },
  14824. copy: function ( source ) {
  14825. this.width = source.width;
  14826. this.height = source.height;
  14827. this.texture = source.texture.clone();
  14828. this.depthBuffer = source.depthBuffer;
  14829. this.stencilBuffer = source.stencilBuffer;
  14830. this.shareDepthFrom = source.shareDepthFrom;
  14831. return this;
  14832. },
  14833. dispose: function () {
  14834. this.dispatchEvent( { type: 'dispose' } );
  14835. }
  14836. };
  14837. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  14838. // File:src/renderers/WebGLRenderTargetCube.js
  14839. /**
  14840. * @author alteredq / http://alteredqualia.com
  14841. */
  14842. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  14843. THREE.WebGLRenderTarget.call( this, width, height, options );
  14844. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  14845. };
  14846. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  14847. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  14848. // File:src/renderers/webgl/WebGLBufferRenderer.js
  14849. /**
  14850. * @author mrdoob / http://mrdoob.com/
  14851. */
  14852. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14853. var mode;
  14854. function setMode( value ) {
  14855. mode = value;
  14856. }
  14857. function render( start, count ) {
  14858. _gl.drawArrays( mode, start, count );
  14859. _infoRender.calls ++;
  14860. _infoRender.vertices += count;
  14861. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14862. }
  14863. function renderInstances( geometry ) {
  14864. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14865. if ( extension === null ) {
  14866. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14867. return;
  14868. }
  14869. var position = geometry.attributes.position;
  14870. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  14871. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount );
  14872. } else {
  14873. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount );
  14874. }
  14875. }
  14876. this.setMode = setMode;
  14877. this.render = render;
  14878. this.renderInstances = renderInstances;
  14879. };
  14880. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  14881. /**
  14882. * @author mrdoob / http://mrdoob.com/
  14883. */
  14884. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14885. var mode;
  14886. function setMode( value ) {
  14887. mode = value;
  14888. }
  14889. var type, size;
  14890. function setIndex( index ) {
  14891. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  14892. type = _gl.UNSIGNED_INT;
  14893. size = 4;
  14894. } else {
  14895. type = _gl.UNSIGNED_SHORT;
  14896. size = 2;
  14897. }
  14898. }
  14899. function render( start, count ) {
  14900. _gl.drawElements( mode, count, type, start * size );
  14901. _infoRender.calls ++;
  14902. _infoRender.vertices += count;
  14903. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14904. }
  14905. function renderInstances( geometry ) {
  14906. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14907. if ( extension === null ) {
  14908. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14909. return;
  14910. }
  14911. var index = geometry.index;
  14912. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount );
  14913. }
  14914. this.setMode = setMode;
  14915. this.setIndex = setIndex;
  14916. this.render = render;
  14917. this.renderInstances = renderInstances;
  14918. };
  14919. // File:src/renderers/webgl/WebGLExtensions.js
  14920. /**
  14921. * @author mrdoob / http://mrdoob.com/
  14922. */
  14923. THREE.WebGLExtensions = function ( gl ) {
  14924. var extensions = {};
  14925. this.get = function ( name ) {
  14926. if ( extensions[ name ] !== undefined ) {
  14927. return extensions[ name ];
  14928. }
  14929. var extension;
  14930. switch ( name ) {
  14931. case 'EXT_texture_filter_anisotropic':
  14932. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  14933. break;
  14934. case 'WEBGL_compressed_texture_s3tc':
  14935. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  14936. break;
  14937. case 'WEBGL_compressed_texture_pvrtc':
  14938. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  14939. break;
  14940. default:
  14941. extension = gl.getExtension( name );
  14942. }
  14943. if ( extension === null ) {
  14944. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  14945. }
  14946. extensions[ name ] = extension;
  14947. return extension;
  14948. };
  14949. };
  14950. // File:src/renderers/webgl/WebGLCapabilities.js
  14951. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  14952. function getMaxPrecision( precision ) {
  14953. if ( precision === 'highp' ) {
  14954. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  14955. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  14956. return 'highp';
  14957. }
  14958. precision = 'mediump';
  14959. }
  14960. if ( precision === 'mediump' ) {
  14961. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  14962. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  14963. return 'mediump';
  14964. }
  14965. }
  14966. return 'lowp';
  14967. }
  14968. this.getMaxPrecision = getMaxPrecision;
  14969. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  14970. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  14971. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14972. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  14973. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  14974. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  14975. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  14976. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  14977. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  14978. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  14979. this.vertexTextures = this.maxVertexTextures > 0;
  14980. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  14981. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  14982. var _maxPrecision = getMaxPrecision( this.precision );
  14983. if ( _maxPrecision !== this.precision ) {
  14984. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  14985. this.precision = _maxPrecision;
  14986. }
  14987. if ( this.logarithmicDepthBuffer ) {
  14988. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  14989. }
  14990. };
  14991. // File:src/renderers/webgl/WebGLGeometries.js
  14992. /**
  14993. * @author mrdoob / http://mrdoob.com/
  14994. */
  14995. THREE.WebGLGeometries = function ( gl, properties, info ) {
  14996. var geometries = {};
  14997. function get( object ) {
  14998. var geometry = object.geometry;
  14999. if ( geometries[ geometry.id ] !== undefined ) {
  15000. return geometries[ geometry.id ];
  15001. }
  15002. geometry.addEventListener( 'dispose', onGeometryDispose );
  15003. var buffergeometry;
  15004. if ( geometry instanceof THREE.BufferGeometry ) {
  15005. buffergeometry = geometry;
  15006. } else if ( geometry instanceof THREE.Geometry ) {
  15007. if ( geometry._bufferGeometry === undefined ) {
  15008. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  15009. }
  15010. buffergeometry = geometry._bufferGeometry;
  15011. }
  15012. geometries[ geometry.id ] = buffergeometry;
  15013. info.memory.geometries ++;
  15014. return buffergeometry;
  15015. }
  15016. function onGeometryDispose( event ) {
  15017. var geometry = event.target;
  15018. var buffergeometry = geometries[ geometry.id ];
  15019. deleteAttributes( buffergeometry.attributes );
  15020. geometry.removeEventListener( 'dispose', onGeometryDispose );
  15021. delete geometries[ geometry.id ];
  15022. var property = properties.get( geometry );
  15023. if ( property.wireframe ) deleteAttribute( property.wireframe );
  15024. info.memory.geometries --;
  15025. }
  15026. function getAttributeBuffer( attribute ) {
  15027. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15028. return properties.get( attribute.data ).__webglBuffer;
  15029. }
  15030. return properties.get( attribute ).__webglBuffer;
  15031. }
  15032. function deleteAttribute( attribute ) {
  15033. var buffer = getAttributeBuffer( attribute );
  15034. if ( buffer !== undefined ) {
  15035. gl.deleteBuffer( buffer );
  15036. removeAttributeBuffer( attribute );
  15037. }
  15038. }
  15039. function deleteAttributes( attributes ) {
  15040. for ( var name in attributes ) {
  15041. deleteAttribute( attributes[ name ] );
  15042. }
  15043. }
  15044. function removeAttributeBuffer( attribute ) {
  15045. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15046. properties.remove( attribute.data );
  15047. } else {
  15048. properties.remove( attribute );
  15049. }
  15050. }
  15051. this.get = get;
  15052. };
  15053. // File:src/renderers/webgl/WebGLObjects.js
  15054. /**
  15055. * @author mrdoob / http://mrdoob.com/
  15056. */
  15057. THREE.WebGLObjects = function ( gl, properties, info ) {
  15058. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  15059. //
  15060. function update( object ) {
  15061. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  15062. var geometry = geometries.get( object );
  15063. if ( object.geometry instanceof THREE.Geometry ) {
  15064. geometry.updateFromObject( object );
  15065. }
  15066. var index = geometry.index;
  15067. var attributes = geometry.attributes;
  15068. if ( index !== null ) {
  15069. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  15070. }
  15071. for ( var name in attributes ) {
  15072. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  15073. }
  15074. // morph targets
  15075. var morphAttributes = geometry.morphAttributes;
  15076. for ( var name in morphAttributes ) {
  15077. var array = morphAttributes[ name ];
  15078. for ( var i = 0, l = array.length; i < l; i ++ ) {
  15079. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  15080. }
  15081. }
  15082. return geometry;
  15083. }
  15084. function updateAttribute( attribute, bufferType ) {
  15085. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  15086. var attributeProperties = properties.get( data );
  15087. if ( attributeProperties.__webglBuffer === undefined ) {
  15088. createBuffer( attributeProperties, data, bufferType );
  15089. } else if ( attributeProperties.version !== data.version ) {
  15090. updateBuffer( attributeProperties, data, bufferType );
  15091. }
  15092. }
  15093. function createBuffer( attributeProperties, data, bufferType ) {
  15094. attributeProperties.__webglBuffer = gl.createBuffer();
  15095. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15096. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  15097. gl.bufferData( bufferType, data.array, usage );
  15098. attributeProperties.version = data.version;
  15099. }
  15100. function updateBuffer( attributeProperties, data, bufferType ) {
  15101. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15102. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  15103. // Not using update ranges
  15104. gl.bufferSubData( bufferType, 0, data.array );
  15105. } else if ( data.updateRange.count === 0 ) {
  15106. console.error( 'THREE.WebGLObjects.updateBuffer: dynamic THREE.BufferAttribute marked as needsUpdate but updateRange.count is 0, ensure you are using set methods or updating manually.' );
  15107. } else {
  15108. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  15109. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  15110. data.updateRange.count = 0; // reset range
  15111. }
  15112. attributeProperties.version = data.version;
  15113. }
  15114. function getAttributeBuffer( attribute ) {
  15115. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15116. return properties.get( attribute.data ).__webglBuffer;
  15117. }
  15118. return properties.get( attribute ).__webglBuffer;
  15119. }
  15120. function getWireframeAttribute( geometry ) {
  15121. var property = properties.get( geometry );
  15122. if ( property.wireframe !== undefined ) {
  15123. return property.wireframe;
  15124. }
  15125. var indices = [];
  15126. var index = geometry.index;
  15127. var attributes = geometry.attributes;
  15128. var position = attributes.position;
  15129. // console.time( 'wireframe' );
  15130. if ( index !== null ) {
  15131. var edges = {};
  15132. var array = index.array;
  15133. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  15134. var a = array[ i + 0 ];
  15135. var b = array[ i + 1 ];
  15136. var c = array[ i + 2 ];
  15137. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  15138. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  15139. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  15140. }
  15141. } else {
  15142. var array = attributes.position.array;
  15143. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  15144. var a = i + 0;
  15145. var b = i + 1;
  15146. var c = i + 2;
  15147. indices.push( a, b, b, c, c, a );
  15148. }
  15149. }
  15150. // console.timeEnd( 'wireframe' );
  15151. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  15152. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  15153. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  15154. property.wireframe = attribute;
  15155. return attribute;
  15156. }
  15157. function checkEdge( edges, a, b ) {
  15158. if ( a > b ) {
  15159. var tmp = a;
  15160. a = b;
  15161. b = tmp;
  15162. }
  15163. var list = edges[ a ];
  15164. if ( list === undefined ) {
  15165. edges[ a ] = [ b ];
  15166. return true;
  15167. } else if ( list.indexOf( b ) === -1 ) {
  15168. list.push( b );
  15169. return true;
  15170. }
  15171. return false;
  15172. }
  15173. this.getAttributeBuffer = getAttributeBuffer;
  15174. this.getWireframeAttribute = getWireframeAttribute;
  15175. this.update = update;
  15176. };
  15177. // File:src/renderers/webgl/WebGLProgram.js
  15178. THREE.WebGLProgram = ( function () {
  15179. var programIdCount = 0;
  15180. function generateDefines( defines ) {
  15181. var chunks = [];
  15182. for ( var name in defines ) {
  15183. var value = defines[ name ];
  15184. if ( value === false ) continue;
  15185. chunks.push( '#define ' + name + ' ' + value );
  15186. }
  15187. return chunks.join( '\n' );
  15188. }
  15189. function fetchUniformLocations( gl, program, identifiers ) {
  15190. var uniforms = {};
  15191. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  15192. for ( var i = 0; i < n; i ++ ) {
  15193. var info = gl.getActiveUniform( program, i );
  15194. var name = info.name;
  15195. var location = gl.getUniformLocation( program, name );
  15196. // console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  15197. var suffixPos = name.lastIndexOf( '[0]' );
  15198. if ( suffixPos !== - 1 && suffixPos === name.length - 3 ) {
  15199. uniforms[ name.substr( 0, suffixPos ) ] = location;
  15200. }
  15201. uniforms[ name ] = location;
  15202. }
  15203. return uniforms;
  15204. }
  15205. function fetchAttributeLocations( gl, program, identifiers ) {
  15206. var attributes = {};
  15207. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  15208. for ( var i = 0; i < n; i ++ ) {
  15209. var info = gl.getActiveAttrib( program, i );
  15210. var name = info.name;
  15211. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  15212. attributes[ name ] = gl.getAttribLocation( program, name );
  15213. }
  15214. return attributes;
  15215. }
  15216. function filterEmptyLine( string ) {
  15217. return string !== '';
  15218. }
  15219. return function WebGLProgram( renderer, code, material, parameters ) {
  15220. var gl = renderer.context;
  15221. var defines = material.defines;
  15222. var vertexShader = material.__webglShader.vertexShader;
  15223. var fragmentShader = material.__webglShader.fragmentShader;
  15224. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  15225. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  15226. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  15227. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  15228. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  15229. }
  15230. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15231. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  15232. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15233. if ( parameters.envMap ) {
  15234. switch ( material.envMap.mapping ) {
  15235. case THREE.CubeReflectionMapping:
  15236. case THREE.CubeRefractionMapping:
  15237. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15238. break;
  15239. case THREE.EquirectangularReflectionMapping:
  15240. case THREE.EquirectangularRefractionMapping:
  15241. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  15242. break;
  15243. case THREE.SphericalReflectionMapping:
  15244. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  15245. break;
  15246. }
  15247. switch ( material.envMap.mapping ) {
  15248. case THREE.CubeRefractionMapping:
  15249. case THREE.EquirectangularRefractionMapping:
  15250. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  15251. break;
  15252. }
  15253. switch ( material.combine ) {
  15254. case THREE.MultiplyOperation:
  15255. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15256. break;
  15257. case THREE.MixOperation:
  15258. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  15259. break;
  15260. case THREE.AddOperation:
  15261. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  15262. break;
  15263. }
  15264. }
  15265. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  15266. // console.log( 'building new program ' );
  15267. //
  15268. var customDefines = generateDefines( defines );
  15269. //
  15270. var program = gl.createProgram();
  15271. var prefixVertex, prefixFragment;
  15272. if ( material instanceof THREE.RawShaderMaterial ) {
  15273. prefixVertex = '';
  15274. prefixFragment = '';
  15275. } else {
  15276. prefixVertex = [
  15277. 'precision ' + parameters.precision + ' float;',
  15278. 'precision ' + parameters.precision + ' int;',
  15279. '#define SHADER_NAME ' + material.__webglShader.name,
  15280. customDefines,
  15281. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  15282. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15283. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15284. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15285. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15286. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15287. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15288. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15289. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15290. '#define MAX_BONES ' + parameters.maxBones,
  15291. parameters.map ? '#define USE_MAP' : '',
  15292. parameters.envMap ? '#define USE_ENVMAP' : '',
  15293. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15294. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15295. parameters.aoMap ? '#define USE_AOMAP' : '',
  15296. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15297. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15298. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15299. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  15300. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15301. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15302. parameters.vertexColors ? '#define USE_COLOR' : '',
  15303. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15304. parameters.skinning ? '#define USE_SKINNING' : '',
  15305. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  15306. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  15307. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  15308. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15309. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15310. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15311. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15312. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15313. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15314. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  15315. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15316. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15317. 'uniform mat4 modelMatrix;',
  15318. 'uniform mat4 modelViewMatrix;',
  15319. 'uniform mat4 projectionMatrix;',
  15320. 'uniform mat4 viewMatrix;',
  15321. 'uniform mat3 normalMatrix;',
  15322. 'uniform vec3 cameraPosition;',
  15323. 'attribute vec3 position;',
  15324. 'attribute vec3 normal;',
  15325. 'attribute vec2 uv;',
  15326. '#ifdef USE_COLOR',
  15327. ' attribute vec3 color;',
  15328. '#endif',
  15329. '#ifdef USE_MORPHTARGETS',
  15330. ' attribute vec3 morphTarget0;',
  15331. ' attribute vec3 morphTarget1;',
  15332. ' attribute vec3 morphTarget2;',
  15333. ' attribute vec3 morphTarget3;',
  15334. ' #ifdef USE_MORPHNORMALS',
  15335. ' attribute vec3 morphNormal0;',
  15336. ' attribute vec3 morphNormal1;',
  15337. ' attribute vec3 morphNormal2;',
  15338. ' attribute vec3 morphNormal3;',
  15339. ' #else',
  15340. ' attribute vec3 morphTarget4;',
  15341. ' attribute vec3 morphTarget5;',
  15342. ' attribute vec3 morphTarget6;',
  15343. ' attribute vec3 morphTarget7;',
  15344. ' #endif',
  15345. '#endif',
  15346. '#ifdef USE_SKINNING',
  15347. ' attribute vec4 skinIndex;',
  15348. ' attribute vec4 skinWeight;',
  15349. '#endif',
  15350. '\n'
  15351. ].filter( filterEmptyLine ).join( '\n' );
  15352. prefixFragment = [
  15353. parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ? '#extension GL_OES_standard_derivatives : enable' : '',
  15354. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  15355. 'precision ' + parameters.precision + ' float;',
  15356. 'precision ' + parameters.precision + ' int;',
  15357. '#define SHADER_NAME ' + material.__webglShader.name,
  15358. customDefines,
  15359. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15360. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15361. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15362. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15363. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15364. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  15365. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15366. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15367. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15368. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  15369. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  15370. parameters.map ? '#define USE_MAP' : '',
  15371. parameters.envMap ? '#define USE_ENVMAP' : '',
  15372. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  15373. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15374. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  15375. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15376. parameters.aoMap ? '#define USE_AOMAP' : '',
  15377. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15378. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15379. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15380. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15381. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15382. parameters.vertexColors ? '#define USE_COLOR' : '',
  15383. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15384. parameters.metal ? '#define METAL' : '',
  15385. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15386. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15387. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15388. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15389. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15390. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15391. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15392. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15393. 'uniform mat4 viewMatrix;',
  15394. 'uniform vec3 cameraPosition;',
  15395. '\n'
  15396. ].filter( filterEmptyLine ).join( '\n' );
  15397. }
  15398. var vertexGlsl = prefixVertex + vertexShader;
  15399. var fragmentGlsl = prefixFragment + fragmentShader;
  15400. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  15401. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  15402. gl.attachShader( program, glVertexShader );
  15403. gl.attachShader( program, glFragmentShader );
  15404. // Force a particular attribute to index 0.
  15405. if ( material.index0AttributeName !== undefined ) {
  15406. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  15407. } else if ( parameters.morphTargets === true ) {
  15408. // programs with morphTargets displace position out of attribute 0
  15409. gl.bindAttribLocation( program, 0, 'position' );
  15410. }
  15411. gl.linkProgram( program );
  15412. var programLog = gl.getProgramInfoLog( program );
  15413. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  15414. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  15415. var runnable = true;
  15416. var haveDiagnostics = true;
  15417. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  15418. runnable = false;
  15419. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  15420. } else if ( programLog !== '' ) {
  15421. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  15422. } else if ( vertexLog === '' || fragmentLog === '' ) {
  15423. haveDiagnostics = false;
  15424. }
  15425. if ( haveDiagnostics ) {
  15426. this.diagnostics = {
  15427. runnable: runnable,
  15428. material: material,
  15429. programLog: programLog,
  15430. vertexShader: {
  15431. log: vertexLog,
  15432. prefix: prefixVertex
  15433. },
  15434. fragmentShader: {
  15435. log: fragmentLog,
  15436. prefix: prefixFragment
  15437. }
  15438. };
  15439. }
  15440. // clean up
  15441. gl.deleteShader( glVertexShader );
  15442. gl.deleteShader( glFragmentShader );
  15443. // set up caching for uniform locations
  15444. var cachedUniforms;
  15445. this.getUniforms = function() {
  15446. if ( cachedUniforms === undefined ) {
  15447. cachedUniforms = fetchUniformLocations( gl, program );
  15448. }
  15449. return cachedUniforms;
  15450. };
  15451. // set up caching for attribute locations
  15452. var cachedAttributes;
  15453. this.getAttributes = function() {
  15454. if ( cachedAttributes === undefined ) {
  15455. cachedAttributes = fetchAttributeLocations( gl, program );
  15456. }
  15457. return cachedAttributes;
  15458. };
  15459. // free resource
  15460. this.destroy = function() {
  15461. gl.deleteProgram( program );
  15462. this.program = undefined;
  15463. };
  15464. // DEPRECATED
  15465. Object.defineProperties( this, {
  15466. uniforms: {
  15467. get: function() {
  15468. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  15469. return this.getUniforms();
  15470. }
  15471. },
  15472. attributes: {
  15473. get: function() {
  15474. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  15475. return this.getAttributes();
  15476. }
  15477. }
  15478. } );
  15479. //
  15480. this.id = programIdCount ++;
  15481. this.code = code;
  15482. this.usedTimes = 1;
  15483. this.program = program;
  15484. this.vertexShader = glVertexShader;
  15485. this.fragmentShader = glFragmentShader;
  15486. return this;
  15487. };
  15488. } )();
  15489. // File:src/renderers/webgl/WebGLPrograms.js
  15490. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  15491. var programs = [];
  15492. var shaderIDs = {
  15493. MeshDepthMaterial: 'depth',
  15494. MeshNormalMaterial: 'normal',
  15495. MeshBasicMaterial: 'basic',
  15496. MeshLambertMaterial: 'lambert',
  15497. MeshPhongMaterial: 'phong',
  15498. LineBasicMaterial: 'basic',
  15499. LineDashedMaterial: 'dashed',
  15500. PointsMaterial: 'points'
  15501. };
  15502. var parameterNames = [
  15503. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  15504. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "specularMap",
  15505. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  15506. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  15507. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  15508. "maxMorphTargets", "maxMorphNormals", "maxDirLights", "maxPointLights",
  15509. "maxSpotLights", "maxHemiLights", "maxShadows", "shadowMapEnabled", "pointLightShadows",
  15510. "shadowMapType", "shadowMapDebug", "alphaTest", "metal", "doubleSided",
  15511. "flipSided"
  15512. ];
  15513. function allocateBones ( object ) {
  15514. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  15515. return 1024;
  15516. } else {
  15517. // default for when object is not specified
  15518. // ( for example when prebuilding shader to be used with multiple objects )
  15519. //
  15520. // - leave some extra space for other uniforms
  15521. // - limit here is ANGLE's 254 max uniform vectors
  15522. // (up to 54 should be safe)
  15523. var nVertexUniforms = capabilities.maxVertexUniforms;
  15524. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  15525. var maxBones = nVertexMatrices;
  15526. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  15527. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  15528. if ( maxBones < object.skeleton.bones.length ) {
  15529. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  15530. }
  15531. }
  15532. return maxBones;
  15533. }
  15534. }
  15535. function allocateLights( lights ) {
  15536. var dirLights = 0;
  15537. var pointLights = 0;
  15538. var spotLights = 0;
  15539. var hemiLights = 0;
  15540. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15541. var light = lights[ l ];
  15542. if ( light.onlyShadow || light.visible === false ) continue;
  15543. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  15544. if ( light instanceof THREE.PointLight ) pointLights ++;
  15545. if ( light instanceof THREE.SpotLight ) spotLights ++;
  15546. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  15547. }
  15548. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  15549. }
  15550. function allocateShadows( lights ) {
  15551. var maxShadows = 0;
  15552. var pointLightShadows = 0;
  15553. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15554. var light = lights[ l ];
  15555. if ( ! light.castShadow ) continue;
  15556. if ( light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) maxShadows ++;
  15557. if ( light instanceof THREE.PointLight ) {
  15558. maxShadows ++;
  15559. pointLightShadows ++;
  15560. }
  15561. }
  15562. return { 'maxShadows': maxShadows, 'pointLightShadows': pointLightShadows };
  15563. }
  15564. this.getParameters = function ( material, lights, fog, object ) {
  15565. var shaderID = shaderIDs[ material.type ];
  15566. // heuristics to create shader parameters according to lights in the scene
  15567. // (not to blow over maxLights budget)
  15568. var maxLightCount = allocateLights( lights );
  15569. var allocatedShadows = allocateShadows( lights );
  15570. var maxBones = allocateBones( object );
  15571. var precision = renderer.getPrecision();
  15572. if ( material.precision !== null ) {
  15573. precision = capabilities.getMaxPrecision( material.precision );
  15574. if ( precision !== material.precision ) {
  15575. console.warn( 'THREE.WebGLRenderer.initMaterial:', material.precision, 'not supported, using', precision, 'instead.' );
  15576. }
  15577. }
  15578. var parameters = {
  15579. shaderID: shaderID,
  15580. precision: precision,
  15581. supportsVertexTextures: capabilities.vertexTextures,
  15582. map: !! material.map,
  15583. envMap: !! material.envMap,
  15584. envMapMode: material.envMap && material.envMap.mapping,
  15585. lightMap: !! material.lightMap,
  15586. aoMap: !! material.aoMap,
  15587. emissiveMap: !! material.emissiveMap,
  15588. bumpMap: !! material.bumpMap,
  15589. normalMap: !! material.normalMap,
  15590. displacementMap: !! material.displacementMap,
  15591. specularMap: !! material.specularMap,
  15592. alphaMap: !! material.alphaMap,
  15593. combine: material.combine,
  15594. vertexColors: material.vertexColors,
  15595. fog: fog,
  15596. useFog: material.fog,
  15597. fogExp: fog instanceof THREE.FogExp2,
  15598. flatShading: material.shading === THREE.FlatShading,
  15599. sizeAttenuation: material.sizeAttenuation,
  15600. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  15601. skinning: material.skinning,
  15602. maxBones: maxBones,
  15603. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  15604. morphTargets: material.morphTargets,
  15605. morphNormals: material.morphNormals,
  15606. maxMorphTargets: renderer.maxMorphTargets,
  15607. maxMorphNormals: renderer.maxMorphNormals,
  15608. maxDirLights: maxLightCount.directional,
  15609. maxPointLights: maxLightCount.point,
  15610. maxSpotLights: maxLightCount.spot,
  15611. maxHemiLights: maxLightCount.hemi,
  15612. maxShadows: allocatedShadows.maxShadows,
  15613. pointLightShadows: allocatedShadows.pointLightShadows,
  15614. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && allocatedShadows.maxShadows > 0,
  15615. shadowMapType: renderer.shadowMap.type,
  15616. shadowMapDebug: renderer.shadowMap.debug,
  15617. alphaTest: material.alphaTest,
  15618. metal: material.metal,
  15619. doubleSided: material.side === THREE.DoubleSide,
  15620. flipSided: material.side === THREE.BackSide
  15621. };
  15622. return parameters;
  15623. };
  15624. this.getProgramCode = function ( material, parameters ) {
  15625. var chunks = [];
  15626. if ( parameters.shaderID ) {
  15627. chunks.push( parameters.shaderID );
  15628. } else {
  15629. chunks.push( material.fragmentShader );
  15630. chunks.push( material.vertexShader );
  15631. }
  15632. if ( material.defines !== undefined ) {
  15633. for ( var name in material.defines ) {
  15634. chunks.push( name );
  15635. chunks.push( material.defines[ name ] );
  15636. }
  15637. }
  15638. for ( var i = 0; i < parameterNames.length; i ++ ) {
  15639. var parameterName = parameterNames[ i ];
  15640. chunks.push( parameterName );
  15641. chunks.push( parameters[ parameterName ] );
  15642. }
  15643. return chunks.join();
  15644. };
  15645. this.acquireProgram = function ( material, parameters, code ) {
  15646. var program;
  15647. // Check if code has been already compiled
  15648. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  15649. var programInfo = programs[ p ];
  15650. if ( programInfo.code === code ) {
  15651. program = programInfo;
  15652. ++ program.usedTimes;
  15653. break;
  15654. }
  15655. }
  15656. if ( program === undefined ) {
  15657. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  15658. programs.push( program );
  15659. }
  15660. return program;
  15661. };
  15662. this.releaseProgram = function( program ) {
  15663. if ( -- program.usedTimes === 0 ) {
  15664. // Remove from unordered set
  15665. var i = programs.indexOf( program );
  15666. programs[ i ] = programs[ programs.length - 1 ];
  15667. programs.pop();
  15668. // Free WebGL resources
  15669. program.destroy();
  15670. }
  15671. };
  15672. // Exposed for resource monitoring & error feedback via renderer.info:
  15673. this.programs = programs;
  15674. };
  15675. // File:src/renderers/webgl/WebGLProperties.js
  15676. /**
  15677. * @author fordacious / fordacious.github.io
  15678. */
  15679. THREE.WebGLProperties = function () {
  15680. var properties = {};
  15681. this.get = function ( object ) {
  15682. var uuid = object.uuid;
  15683. var map = properties[ uuid ];
  15684. if ( map === undefined ) {
  15685. map = {};
  15686. properties[ uuid ] = map;
  15687. }
  15688. return map;
  15689. };
  15690. this.remove = function ( object ) {
  15691. delete properties[ object.uuid ];
  15692. };
  15693. this.clear = function () {
  15694. properties = {};
  15695. };
  15696. };
  15697. // File:src/renderers/webgl/WebGLShader.js
  15698. THREE.WebGLShader = ( function () {
  15699. function addLineNumbers( string ) {
  15700. var lines = string.split( '\n' );
  15701. for ( var i = 0; i < lines.length; i ++ ) {
  15702. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  15703. }
  15704. return lines.join( '\n' );
  15705. }
  15706. return function WebGLShader( gl, type, string ) {
  15707. var shader = gl.createShader( type );
  15708. gl.shaderSource( shader, string );
  15709. gl.compileShader( shader );
  15710. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  15711. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  15712. }
  15713. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  15714. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  15715. }
  15716. // --enable-privileged-webgl-extension
  15717. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  15718. return shader;
  15719. };
  15720. } )();
  15721. // File:src/renderers/webgl/WebGLShadowMap.js
  15722. /**
  15723. * @author alteredq / http://alteredqualia.com/
  15724. * @author mrdoob / http://mrdoob.com/
  15725. */
  15726. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  15727. var _gl = _renderer.context,
  15728. _state = _renderer.state,
  15729. _frustum = new THREE.Frustum(),
  15730. _projScreenMatrix = new THREE.Matrix4(),
  15731. _min = new THREE.Vector3(),
  15732. _max = new THREE.Vector3(),
  15733. _lookTarget = new THREE.Vector3(),
  15734. _lightPositionWorld = new THREE.Vector3(),
  15735. _renderList = [],
  15736. _MorphingFlag = 1,
  15737. _SkinningFlag = 2,
  15738. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  15739. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  15740. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  15741. var cubeDirections = [
  15742. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  15743. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  15744. ];
  15745. var cubeUps = [
  15746. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  15747. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  15748. ];
  15749. var cube2DViewPorts = [
  15750. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  15751. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  15752. ];
  15753. var _vector4 = new THREE.Vector4();
  15754. // init
  15755. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  15756. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  15757. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  15758. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  15759. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  15760. var useMorphing = ( i & _MorphingFlag ) !== 0;
  15761. var useSkinning = ( i & _SkinningFlag ) !== 0;
  15762. var depthMaterial = new THREE.ShaderMaterial( {
  15763. uniforms: depthUniforms,
  15764. vertexShader: depthShader.vertexShader,
  15765. fragmentShader: depthShader.fragmentShader,
  15766. morphTargets: useMorphing,
  15767. skinning: useSkinning
  15768. } );
  15769. depthMaterial._shadowPass = true;
  15770. _depthMaterials[ i ] = depthMaterial;
  15771. var distanceMaterial = new THREE.ShaderMaterial( {
  15772. uniforms: distanceUniforms,
  15773. vertexShader: distanceShader.vertexShader,
  15774. fragmentShader: distanceShader.fragmentShader,
  15775. morphTargets: useMorphing,
  15776. skinning: useSkinning
  15777. } );
  15778. distanceMaterial._shadowPass = true;
  15779. _distanceMaterials[ i ] = distanceMaterial;
  15780. }
  15781. //
  15782. var scope = this;
  15783. this.enabled = false;
  15784. this.autoUpdate = true;
  15785. this.needsUpdate = false;
  15786. this.type = THREE.PCFShadowMap;
  15787. this.cullFace = THREE.CullFaceFront;
  15788. this.render = function ( scene ) {
  15789. var faceCount, isPointLight;
  15790. if ( scope.enabled === false ) return;
  15791. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  15792. // Set GL state for depth map.
  15793. _gl.clearColor( 1, 1, 1, 1 );
  15794. _state.disable( _gl.BLEND );
  15795. _state.enable( _gl.CULL_FACE );
  15796. _gl.frontFace( _gl.CCW );
  15797. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  15798. _state.setDepthTest( true );
  15799. // save the existing viewport so it can be restored later
  15800. _renderer.getViewport( _vector4 );
  15801. // render depth map
  15802. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  15803. var light = _lights[ i ];
  15804. if ( ! light.castShadow ) continue;
  15805. if ( light instanceof THREE.PointLight ) {
  15806. faceCount = 6;
  15807. isPointLight = true;
  15808. var vpWidth = light.shadowMapWidth / 4.0;
  15809. var vpHeight = light.shadowMapHeight / 2.0;
  15810. // These viewports map a cube-map onto a 2D texture with the
  15811. // following orientation:
  15812. //
  15813. // xzXZ
  15814. // y Y
  15815. //
  15816. // X - Positive x direction
  15817. // x - Negative x direction
  15818. // Y - Positive y direction
  15819. // y - Negative y direction
  15820. // Z - Positive z direction
  15821. // z - Negative z direction
  15822. // positive X
  15823. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  15824. // negative X
  15825. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  15826. // positive Z
  15827. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  15828. // negative Z
  15829. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  15830. // positive Y
  15831. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  15832. // negative Y
  15833. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  15834. } else {
  15835. faceCount = 1;
  15836. isPointLight = false;
  15837. }
  15838. if ( ! light.shadowMap ) {
  15839. var shadowFilter = THREE.LinearFilter;
  15840. if ( scope.type === THREE.PCFSoftShadowMap ) {
  15841. shadowFilter = THREE.NearestFilter;
  15842. }
  15843. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  15844. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  15845. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  15846. light.shadowMatrix = new THREE.Matrix4();
  15847. }
  15848. if ( ! light.shadowCamera ) {
  15849. if ( light instanceof THREE.SpotLight ) {
  15850. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  15851. } else if ( light instanceof THREE.DirectionalLight ) {
  15852. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  15853. } else {
  15854. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, 1.0, light.shadowCameraNear, light.shadowCameraFar );
  15855. }
  15856. scene.add( light.shadowCamera );
  15857. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15858. }
  15859. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  15860. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  15861. scene.add( light.cameraHelper );
  15862. }
  15863. var shadowMap = light.shadowMap;
  15864. var shadowMatrix = light.shadowMatrix;
  15865. var shadowCamera = light.shadowCamera;
  15866. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  15867. shadowCamera.position.copy( _lightPositionWorld );
  15868. _renderer.setRenderTarget( shadowMap );
  15869. _renderer.clear();
  15870. // render shadow map for each cube face (if omni-directional) or
  15871. // run a single pass if not
  15872. for ( var face = 0; face < faceCount; face ++ ) {
  15873. if ( isPointLight ) {
  15874. _lookTarget.copy( shadowCamera.position );
  15875. _lookTarget.add( cubeDirections[ face ] );
  15876. shadowCamera.up.copy( cubeUps[ face ] );
  15877. shadowCamera.lookAt( _lookTarget );
  15878. var vpDimensions = cube2DViewPorts[ face ];
  15879. _renderer.setViewport( vpDimensions.x, vpDimensions.y, vpDimensions.z, vpDimensions.w );
  15880. } else {
  15881. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  15882. shadowCamera.lookAt( _lookTarget );
  15883. }
  15884. shadowCamera.updateMatrixWorld();
  15885. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  15886. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  15887. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  15888. // compute shadow matrix
  15889. shadowMatrix.set(
  15890. 0.5, 0.0, 0.0, 0.5,
  15891. 0.0, 0.5, 0.0, 0.5,
  15892. 0.0, 0.0, 0.5, 0.5,
  15893. 0.0, 0.0, 0.0, 1.0
  15894. );
  15895. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  15896. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  15897. // update camera matrices and frustum
  15898. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  15899. _frustum.setFromMatrix( _projScreenMatrix );
  15900. // set object matrices & frustum culling
  15901. _renderList.length = 0;
  15902. projectObject( scene, shadowCamera );
  15903. // render shadow map
  15904. // render regular objects
  15905. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  15906. var object = _renderList[ j ];
  15907. var geometry = _objects.update( object );
  15908. var material = object.material;
  15909. if ( material instanceof THREE.MeshFaceMaterial ) {
  15910. var groups = geometry.groups;
  15911. var materials = material.materials;
  15912. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  15913. var group = groups[ k ];
  15914. var groupMaterial = materials[ group.materialIndex ];
  15915. if ( groupMaterial.visible === true ) {
  15916. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  15917. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, group );
  15918. }
  15919. }
  15920. } else {
  15921. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  15922. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, null );
  15923. }
  15924. }
  15925. }
  15926. //We must call _renderer.resetGLState() at the end of each iteration of
  15927. // the light loop in order to force material updates for each light.
  15928. _renderer.resetGLState();
  15929. }
  15930. _renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
  15931. // Restore GL state.
  15932. var clearColor = _renderer.getClearColor(),
  15933. clearAlpha = _renderer.getClearAlpha();
  15934. _renderer.setClearColor( clearColor, clearAlpha );
  15935. _state.enable( _gl.BLEND );
  15936. if ( scope.cullFace === THREE.CullFaceFront ) {
  15937. _gl.cullFace( _gl.BACK );
  15938. }
  15939. _renderer.resetGLState();
  15940. scope.needsUpdate = false;
  15941. };
  15942. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  15943. var geometry = object.geometry;
  15944. var newMaterial = null;
  15945. var materialVariants = _depthMaterials;
  15946. var customMaterial = object.customDepthMaterial;
  15947. if ( isPointLight ) {
  15948. materialVariants = _distanceMaterials;
  15949. customMaterial = object.customDistanceMaterial;
  15950. }
  15951. if ( ! customMaterial ) {
  15952. var useMorphing = geometry.morphTargets !== undefined &&
  15953. geometry.morphTargets.length > 0 && material.morphTargets;
  15954. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  15955. var variantIndex = 0;
  15956. if ( useMorphing ) variantIndex |= _MorphingFlag;
  15957. if ( useSkinning ) variantIndex |= _SkinningFlag;
  15958. newMaterial = materialVariants[ variantIndex ];
  15959. } else {
  15960. newMaterial = customMaterial;
  15961. }
  15962. newMaterial.visible = material.visible;
  15963. newMaterial.wireframe = material.wireframe;
  15964. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  15965. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  15966. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  15967. }
  15968. return newMaterial;
  15969. }
  15970. function projectObject( object, camera ) {
  15971. if ( object.visible === false ) return;
  15972. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15973. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  15974. var material = object.material;
  15975. if ( material.visible === true ) {
  15976. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15977. _renderList.push( object );
  15978. }
  15979. }
  15980. }
  15981. var children = object.children;
  15982. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15983. projectObject( children[ i ], camera );
  15984. }
  15985. }
  15986. };
  15987. // File:src/renderers/webgl/WebGLState.js
  15988. /**
  15989. * @author mrdoob / http://mrdoob.com/
  15990. */
  15991. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  15992. var _this = this;
  15993. var newAttributes = new Uint8Array( 16 );
  15994. var enabledAttributes = new Uint8Array( 16 );
  15995. var attributeDivisors = new Uint8Array( 16 );
  15996. var capabilities = {};
  15997. var compressedTextureFormats = null;
  15998. var currentBlending = null;
  15999. var currentBlendEquation = null;
  16000. var currentBlendSrc = null;
  16001. var currentBlendDst = null;
  16002. var currentBlendEquationAlpha = null;
  16003. var currentBlendSrcAlpha = null;
  16004. var currentBlendDstAlpha = null;
  16005. var currentDepthFunc = null;
  16006. var currentDepthWrite = null;
  16007. var currentColorWrite = null;
  16008. var currentFlipSided = null;
  16009. var currentLineWidth = null;
  16010. var currentPolygonOffsetFactor = null;
  16011. var currentPolygonOffsetUnits = null;
  16012. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16013. var currentTextureSlot = undefined;
  16014. var currentBoundTextures = {};
  16015. this.init = function () {
  16016. gl.clearColor( 0, 0, 0, 1 );
  16017. gl.clearDepth( 1 );
  16018. gl.clearStencil( 0 );
  16019. this.enable( gl.DEPTH_TEST );
  16020. gl.depthFunc( gl.LEQUAL );
  16021. gl.frontFace( gl.CCW );
  16022. gl.cullFace( gl.BACK );
  16023. this.enable( gl.CULL_FACE );
  16024. this.enable( gl.BLEND );
  16025. gl.blendEquation( gl.FUNC_ADD );
  16026. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  16027. };
  16028. this.initAttributes = function () {
  16029. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  16030. newAttributes[ i ] = 0;
  16031. }
  16032. };
  16033. this.enableAttribute = function ( attribute ) {
  16034. newAttributes[ attribute ] = 1;
  16035. if ( enabledAttributes[ attribute ] === 0 ) {
  16036. gl.enableVertexAttribArray( attribute );
  16037. enabledAttributes[ attribute ] = 1;
  16038. }
  16039. if ( attributeDivisors[ attribute ] !== 0 ) {
  16040. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16041. extension.vertexAttribDivisorANGLE( attribute, 0 );
  16042. attributeDivisors[ attribute ] = 0;
  16043. }
  16044. };
  16045. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  16046. newAttributes[ attribute ] = 1;
  16047. if ( enabledAttributes[ attribute ] === 0 ) {
  16048. gl.enableVertexAttribArray( attribute );
  16049. enabledAttributes[ attribute ] = 1;
  16050. }
  16051. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  16052. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  16053. attributeDivisors[ attribute ] = meshPerAttribute;
  16054. }
  16055. };
  16056. this.disableUnusedAttributes = function () {
  16057. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  16058. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  16059. gl.disableVertexAttribArray( i );
  16060. enabledAttributes[ i ] = 0;
  16061. }
  16062. }
  16063. };
  16064. this.enable = function ( id ) {
  16065. if ( capabilities[ id ] !== true ) {
  16066. gl.enable( id );
  16067. capabilities[ id ] = true;
  16068. }
  16069. };
  16070. this.disable = function ( id ) {
  16071. if ( capabilities[ id ] !== false ) {
  16072. gl.disable( id );
  16073. capabilities[ id ] = false;
  16074. }
  16075. };
  16076. this.getCompressedTextureFormats = function () {
  16077. if ( compressedTextureFormats === null ) {
  16078. compressedTextureFormats = [];
  16079. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  16080. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  16081. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  16082. for ( var i = 0; i < formats.length; i ++ ) {
  16083. compressedTextureFormats.push( formats[ i ] );
  16084. }
  16085. }
  16086. }
  16087. return compressedTextureFormats;
  16088. };
  16089. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  16090. if ( blending !== currentBlending ) {
  16091. if ( blending === THREE.NoBlending ) {
  16092. this.disable( gl.BLEND );
  16093. } else if ( blending === THREE.AdditiveBlending ) {
  16094. this.enable( gl.BLEND );
  16095. gl.blendEquation( gl.FUNC_ADD );
  16096. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  16097. } else if ( blending === THREE.SubtractiveBlending ) {
  16098. // TODO: Find blendFuncSeparate() combination
  16099. this.enable( gl.BLEND );
  16100. gl.blendEquation( gl.FUNC_ADD );
  16101. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  16102. } else if ( blending === THREE.MultiplyBlending ) {
  16103. // TODO: Find blendFuncSeparate() combination
  16104. this.enable( gl.BLEND );
  16105. gl.blendEquation( gl.FUNC_ADD );
  16106. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  16107. } else if ( blending === THREE.CustomBlending ) {
  16108. this.enable( gl.BLEND );
  16109. } else {
  16110. this.enable( gl.BLEND );
  16111. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  16112. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  16113. }
  16114. currentBlending = blending;
  16115. }
  16116. if ( blending === THREE.CustomBlending ) {
  16117. blendEquationAlpha = blendEquationAlpha || blendEquation;
  16118. blendSrcAlpha = blendSrcAlpha || blendSrc;
  16119. blendDstAlpha = blendDstAlpha || blendDst;
  16120. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  16121. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  16122. currentBlendEquation = blendEquation;
  16123. currentBlendEquationAlpha = blendEquationAlpha;
  16124. }
  16125. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  16126. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  16127. currentBlendSrc = blendSrc;
  16128. currentBlendDst = blendDst;
  16129. currentBlendSrcAlpha = blendSrcAlpha;
  16130. currentBlendDstAlpha = blendDstAlpha;
  16131. }
  16132. } else {
  16133. currentBlendEquation = null;
  16134. currentBlendSrc = null;
  16135. currentBlendDst = null;
  16136. currentBlendEquationAlpha = null;
  16137. currentBlendSrcAlpha = null;
  16138. currentBlendDstAlpha = null;
  16139. }
  16140. };
  16141. this.setDepthFunc = function ( depthFunc ) {
  16142. if ( currentDepthFunc !== depthFunc ) {
  16143. if ( depthFunc ) {
  16144. switch ( depthFunc ) {
  16145. case THREE.NeverDepth:
  16146. gl.depthFunc( gl.NEVER );
  16147. break;
  16148. case THREE.AlwaysDepth:
  16149. gl.depthFunc( gl.ALWAYS );
  16150. break;
  16151. case THREE.LessDepth:
  16152. gl.depthFunc( gl.LESS );
  16153. break;
  16154. case THREE.LessEqualDepth:
  16155. gl.depthFunc( gl.LEQUAL );
  16156. break;
  16157. case THREE.EqualDepth:
  16158. gl.depthFunc( gl.EQUAL );
  16159. break;
  16160. case THREE.GreaterEqualDepth:
  16161. gl.depthFunc( gl.GEQUAL );
  16162. break;
  16163. case THREE.GreaterDepth:
  16164. gl.depthFunc( gl.GREATER );
  16165. break;
  16166. case THREE.NotEqualDepth:
  16167. gl.depthFunc( gl.NOTEQUAL );
  16168. break;
  16169. default:
  16170. gl.depthFunc( gl.LEQUAL );
  16171. }
  16172. } else {
  16173. gl.depthFunc( gl.LEQUAL );
  16174. }
  16175. currentDepthFunc = depthFunc;
  16176. }
  16177. };
  16178. this.setDepthTest = function ( depthTest ) {
  16179. if ( depthTest ) {
  16180. this.enable( gl.DEPTH_TEST );
  16181. } else {
  16182. this.disable( gl.DEPTH_TEST );
  16183. }
  16184. };
  16185. this.setDepthWrite = function ( depthWrite ) {
  16186. if ( currentDepthWrite !== depthWrite ) {
  16187. gl.depthMask( depthWrite );
  16188. currentDepthWrite = depthWrite;
  16189. }
  16190. };
  16191. this.setColorWrite = function ( colorWrite ) {
  16192. if ( currentColorWrite !== colorWrite ) {
  16193. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  16194. currentColorWrite = colorWrite;
  16195. }
  16196. };
  16197. this.setFlipSided = function ( flipSided ) {
  16198. if ( currentFlipSided !== flipSided ) {
  16199. if ( flipSided ) {
  16200. gl.frontFace( gl.CW );
  16201. } else {
  16202. gl.frontFace( gl.CCW );
  16203. }
  16204. currentFlipSided = flipSided;
  16205. }
  16206. };
  16207. this.setLineWidth = function ( width ) {
  16208. if ( width !== currentLineWidth ) {
  16209. gl.lineWidth( width );
  16210. currentLineWidth = width;
  16211. }
  16212. };
  16213. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  16214. if ( polygonOffset ) {
  16215. this.enable( gl.POLYGON_OFFSET_FILL );
  16216. } else {
  16217. this.disable( gl.POLYGON_OFFSET_FILL );
  16218. }
  16219. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  16220. gl.polygonOffset( factor, units );
  16221. currentPolygonOffsetFactor = factor;
  16222. currentPolygonOffsetUnits = units;
  16223. }
  16224. };
  16225. this.setScissorTest = function ( scissorTest ) {
  16226. if ( scissorTest ) {
  16227. this.enable( gl.SCISSOR_TEST );
  16228. } else {
  16229. this.disable( gl.SCISSOR_TEST );
  16230. }
  16231. };
  16232. // texture
  16233. this.activeTexture = function ( webglSlot ) {
  16234. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  16235. if ( currentTextureSlot !== webglSlot ) {
  16236. gl.activeTexture( webglSlot );
  16237. currentTextureSlot = webglSlot;
  16238. }
  16239. }
  16240. this.bindTexture = function ( webglType, webglTexture ) {
  16241. if ( currentTextureSlot === undefined ) {
  16242. _this.activeTexture();
  16243. }
  16244. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  16245. if ( boundTexture === undefined ) {
  16246. boundTexture = { type: undefined, texture: undefined };
  16247. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  16248. }
  16249. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  16250. gl.bindTexture( webglType, webglTexture );
  16251. boundTexture.type = webglType;
  16252. boundTexture.texture = webglTexture;
  16253. }
  16254. };
  16255. this.compressedTexImage2D = function () {
  16256. try {
  16257. gl.compressedTexImage2D.apply( gl, arguments );
  16258. } catch ( error ) {
  16259. console.error( error );
  16260. }
  16261. };
  16262. this.texImage2D = function () {
  16263. try {
  16264. gl.texImage2D.apply( gl, arguments );
  16265. } catch ( error ) {
  16266. console.error( error );
  16267. }
  16268. };
  16269. //
  16270. this.reset = function () {
  16271. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  16272. if ( enabledAttributes[ i ] === 1 ) {
  16273. gl.disableVertexAttribArray( i );
  16274. enabledAttributes[ i ] = 0;
  16275. }
  16276. }
  16277. capabilities = {};
  16278. compressedTextureFormats = null;
  16279. currentBlending = null;
  16280. currentDepthWrite = null;
  16281. currentColorWrite = null;
  16282. currentFlipSided = null;
  16283. };
  16284. };
  16285. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  16286. /**
  16287. * @author mikael emtinger / http://gomo.se/
  16288. * @author alteredq / http://alteredqualia.com/
  16289. */
  16290. THREE.LensFlarePlugin = function ( renderer, flares ) {
  16291. var gl = renderer.context;
  16292. var state = renderer.state;
  16293. var vertexBuffer, elementBuffer;
  16294. var program, attributes, uniforms;
  16295. var hasVertexTexture;
  16296. var tempTexture, occlusionTexture;
  16297. function init() {
  16298. var vertices = new Float32Array( [
  16299. - 1, - 1, 0, 0,
  16300. 1, - 1, 1, 0,
  16301. 1, 1, 1, 1,
  16302. - 1, 1, 0, 1
  16303. ] );
  16304. var faces = new Uint16Array( [
  16305. 0, 1, 2,
  16306. 0, 2, 3
  16307. ] );
  16308. // buffers
  16309. vertexBuffer = gl.createBuffer();
  16310. elementBuffer = gl.createBuffer();
  16311. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16312. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16313. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16314. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16315. // textures
  16316. tempTexture = gl.createTexture();
  16317. occlusionTexture = gl.createTexture();
  16318. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16319. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  16320. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16321. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16322. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16323. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16324. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16325. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  16326. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16327. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16328. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16329. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16330. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  16331. var shader;
  16332. if ( hasVertexTexture ) {
  16333. shader = {
  16334. vertexShader: [
  16335. "uniform lowp int renderType;",
  16336. "uniform vec3 screenPosition;",
  16337. "uniform vec2 scale;",
  16338. "uniform float rotation;",
  16339. "uniform sampler2D occlusionMap;",
  16340. "attribute vec2 position;",
  16341. "attribute vec2 uv;",
  16342. "varying vec2 vUV;",
  16343. "varying float vVisibility;",
  16344. "void main() {",
  16345. "vUV = uv;",
  16346. "vec2 pos = position;",
  16347. "if ( renderType == 2 ) {",
  16348. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  16349. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  16350. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  16351. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  16352. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  16353. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  16354. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  16355. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  16356. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  16357. "vVisibility = visibility.r / 9.0;",
  16358. "vVisibility *= 1.0 - visibility.g / 9.0;",
  16359. "vVisibility *= visibility.b / 9.0;",
  16360. "vVisibility *= 1.0 - visibility.a / 9.0;",
  16361. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16362. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16363. "}",
  16364. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16365. "}"
  16366. ].join( "\n" ),
  16367. fragmentShader: [
  16368. "uniform lowp int renderType;",
  16369. "uniform sampler2D map;",
  16370. "uniform float opacity;",
  16371. "uniform vec3 color;",
  16372. "varying vec2 vUV;",
  16373. "varying float vVisibility;",
  16374. "void main() {",
  16375. // pink square
  16376. "if ( renderType == 0 ) {",
  16377. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  16378. // restore
  16379. "} else if ( renderType == 1 ) {",
  16380. "gl_FragColor = texture2D( map, vUV );",
  16381. // flare
  16382. "} else {",
  16383. "vec4 texture = texture2D( map, vUV );",
  16384. "texture.a *= opacity * vVisibility;",
  16385. "gl_FragColor = texture;",
  16386. "gl_FragColor.rgb *= color;",
  16387. "}",
  16388. "}"
  16389. ].join( "\n" )
  16390. };
  16391. } else {
  16392. shader = {
  16393. vertexShader: [
  16394. "uniform lowp int renderType;",
  16395. "uniform vec3 screenPosition;",
  16396. "uniform vec2 scale;",
  16397. "uniform float rotation;",
  16398. "attribute vec2 position;",
  16399. "attribute vec2 uv;",
  16400. "varying vec2 vUV;",
  16401. "void main() {",
  16402. "vUV = uv;",
  16403. "vec2 pos = position;",
  16404. "if ( renderType == 2 ) {",
  16405. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16406. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16407. "}",
  16408. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16409. "}"
  16410. ].join( "\n" ),
  16411. fragmentShader: [
  16412. "precision mediump float;",
  16413. "uniform lowp int renderType;",
  16414. "uniform sampler2D map;",
  16415. "uniform sampler2D occlusionMap;",
  16416. "uniform float opacity;",
  16417. "uniform vec3 color;",
  16418. "varying vec2 vUV;",
  16419. "void main() {",
  16420. // pink square
  16421. "if ( renderType == 0 ) {",
  16422. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  16423. // restore
  16424. "} else if ( renderType == 1 ) {",
  16425. "gl_FragColor = texture2D( map, vUV );",
  16426. // flare
  16427. "} else {",
  16428. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  16429. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  16430. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  16431. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  16432. "visibility = ( 1.0 - visibility / 4.0 );",
  16433. "vec4 texture = texture2D( map, vUV );",
  16434. "texture.a *= opacity * visibility;",
  16435. "gl_FragColor = texture;",
  16436. "gl_FragColor.rgb *= color;",
  16437. "}",
  16438. "}"
  16439. ].join( "\n" )
  16440. };
  16441. }
  16442. program = createProgram( shader );
  16443. attributes = {
  16444. vertex: gl.getAttribLocation ( program, "position" ),
  16445. uv: gl.getAttribLocation ( program, "uv" )
  16446. };
  16447. uniforms = {
  16448. renderType: gl.getUniformLocation( program, "renderType" ),
  16449. map: gl.getUniformLocation( program, "map" ),
  16450. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  16451. opacity: gl.getUniformLocation( program, "opacity" ),
  16452. color: gl.getUniformLocation( program, "color" ),
  16453. scale: gl.getUniformLocation( program, "scale" ),
  16454. rotation: gl.getUniformLocation( program, "rotation" ),
  16455. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  16456. };
  16457. }
  16458. /*
  16459. * Render lens flares
  16460. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  16461. * reads these back and calculates occlusion.
  16462. */
  16463. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  16464. if ( flares.length === 0 ) return;
  16465. var tempPosition = new THREE.Vector3();
  16466. var invAspect = viewportHeight / viewportWidth,
  16467. halfViewportWidth = viewportWidth * 0.5,
  16468. halfViewportHeight = viewportHeight * 0.5;
  16469. var size = 16 / viewportHeight,
  16470. scale = new THREE.Vector2( size * invAspect, size );
  16471. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  16472. screenPositionPixels = new THREE.Vector2( 1, 1 );
  16473. if ( program === undefined ) {
  16474. init();
  16475. }
  16476. gl.useProgram( program );
  16477. state.initAttributes();
  16478. state.enableAttribute( attributes.vertex );
  16479. state.enableAttribute( attributes.uv );
  16480. state.disableUnusedAttributes();
  16481. // loop through all lens flares to update their occlusion and positions
  16482. // setup gl and common used attribs/uniforms
  16483. gl.uniform1i( uniforms.occlusionMap, 0 );
  16484. gl.uniform1i( uniforms.map, 1 );
  16485. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16486. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  16487. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16488. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16489. state.disable( gl.CULL_FACE );
  16490. gl.depthMask( false );
  16491. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  16492. size = 16 / viewportHeight;
  16493. scale.set( size * invAspect, size );
  16494. // calc object screen position
  16495. var flare = flares[ i ];
  16496. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  16497. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  16498. tempPosition.applyProjection( camera.projectionMatrix );
  16499. // setup arrays for gl programs
  16500. screenPosition.copy( tempPosition );
  16501. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  16502. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  16503. // screen cull
  16504. if ( hasVertexTexture || (
  16505. screenPositionPixels.x > 0 &&
  16506. screenPositionPixels.x < viewportWidth &&
  16507. screenPositionPixels.y > 0 &&
  16508. screenPositionPixels.y < viewportHeight ) ) {
  16509. // save current RGB to temp texture
  16510. state.activeTexture( gl.TEXTURE0 );
  16511. state.bindTexture( gl.TEXTURE_2D, null );
  16512. state.activeTexture( gl.TEXTURE1 );
  16513. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16514. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16515. // render pink quad
  16516. gl.uniform1i( uniforms.renderType, 0 );
  16517. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16518. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16519. state.disable( gl.BLEND );
  16520. state.enable( gl.DEPTH_TEST );
  16521. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16522. // copy result to occlusionMap
  16523. state.activeTexture( gl.TEXTURE0 );
  16524. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16525. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16526. // restore graphics
  16527. gl.uniform1i( uniforms.renderType, 1 );
  16528. state.disable( gl.DEPTH_TEST );
  16529. state.activeTexture( gl.TEXTURE1 );
  16530. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16531. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16532. // update object positions
  16533. flare.positionScreen.copy( screenPosition );
  16534. if ( flare.customUpdateCallback ) {
  16535. flare.customUpdateCallback( flare );
  16536. } else {
  16537. flare.updateLensFlares();
  16538. }
  16539. // render flares
  16540. gl.uniform1i( uniforms.renderType, 2 );
  16541. state.enable( gl.BLEND );
  16542. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  16543. var sprite = flare.lensFlares[ j ];
  16544. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  16545. screenPosition.x = sprite.x;
  16546. screenPosition.y = sprite.y;
  16547. screenPosition.z = sprite.z;
  16548. size = sprite.size * sprite.scale / viewportHeight;
  16549. scale.x = size * invAspect;
  16550. scale.y = size;
  16551. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16552. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16553. gl.uniform1f( uniforms.rotation, sprite.rotation );
  16554. gl.uniform1f( uniforms.opacity, sprite.opacity );
  16555. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  16556. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  16557. renderer.setTexture( sprite.texture, 1 );
  16558. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16559. }
  16560. }
  16561. }
  16562. }
  16563. // restore gl
  16564. state.enable( gl.CULL_FACE );
  16565. state.enable( gl.DEPTH_TEST );
  16566. gl.depthMask( true );
  16567. renderer.resetGLState();
  16568. };
  16569. function createProgram ( shader ) {
  16570. var program = gl.createProgram();
  16571. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16572. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16573. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  16574. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  16575. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  16576. gl.compileShader( fragmentShader );
  16577. gl.compileShader( vertexShader );
  16578. gl.attachShader( program, fragmentShader );
  16579. gl.attachShader( program, vertexShader );
  16580. gl.linkProgram( program );
  16581. return program;
  16582. }
  16583. };
  16584. // File:src/renderers/webgl/plugins/SpritePlugin.js
  16585. /**
  16586. * @author mikael emtinger / http://gomo.se/
  16587. * @author alteredq / http://alteredqualia.com/
  16588. */
  16589. THREE.SpritePlugin = function ( renderer, sprites ) {
  16590. var gl = renderer.context;
  16591. var state = renderer.state;
  16592. var vertexBuffer, elementBuffer;
  16593. var program, attributes, uniforms;
  16594. var texture;
  16595. // decompose matrixWorld
  16596. var spritePosition = new THREE.Vector3();
  16597. var spriteRotation = new THREE.Quaternion();
  16598. var spriteScale = new THREE.Vector3();
  16599. function init() {
  16600. var vertices = new Float32Array( [
  16601. - 0.5, - 0.5, 0, 0,
  16602. 0.5, - 0.5, 1, 0,
  16603. 0.5, 0.5, 1, 1,
  16604. - 0.5, 0.5, 0, 1
  16605. ] );
  16606. var faces = new Uint16Array( [
  16607. 0, 1, 2,
  16608. 0, 2, 3
  16609. ] );
  16610. vertexBuffer = gl.createBuffer();
  16611. elementBuffer = gl.createBuffer();
  16612. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16613. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16614. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16615. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16616. program = createProgram();
  16617. attributes = {
  16618. position: gl.getAttribLocation ( program, 'position' ),
  16619. uv: gl.getAttribLocation ( program, 'uv' )
  16620. };
  16621. uniforms = {
  16622. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  16623. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  16624. rotation: gl.getUniformLocation( program, 'rotation' ),
  16625. scale: gl.getUniformLocation( program, 'scale' ),
  16626. color: gl.getUniformLocation( program, 'color' ),
  16627. map: gl.getUniformLocation( program, 'map' ),
  16628. opacity: gl.getUniformLocation( program, 'opacity' ),
  16629. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  16630. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  16631. fogType: gl.getUniformLocation( program, 'fogType' ),
  16632. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  16633. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  16634. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  16635. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  16636. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  16637. };
  16638. var canvas = document.createElement( 'canvas' );
  16639. canvas.width = 8;
  16640. canvas.height = 8;
  16641. var context = canvas.getContext( '2d' );
  16642. context.fillStyle = 'white';
  16643. context.fillRect( 0, 0, 8, 8 );
  16644. texture = new THREE.Texture( canvas );
  16645. texture.needsUpdate = true;
  16646. }
  16647. this.render = function ( scene, camera ) {
  16648. if ( sprites.length === 0 ) return;
  16649. // setup gl
  16650. if ( program === undefined ) {
  16651. init();
  16652. }
  16653. gl.useProgram( program );
  16654. state.initAttributes();
  16655. state.enableAttribute( attributes.position );
  16656. state.enableAttribute( attributes.uv );
  16657. state.disableUnusedAttributes();
  16658. state.disable( gl.CULL_FACE );
  16659. state.enable( gl.BLEND );
  16660. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16661. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  16662. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16663. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16664. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  16665. state.activeTexture( gl.TEXTURE0 );
  16666. gl.uniform1i( uniforms.map, 0 );
  16667. var oldFogType = 0;
  16668. var sceneFogType = 0;
  16669. var fog = scene.fog;
  16670. if ( fog ) {
  16671. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  16672. if ( fog instanceof THREE.Fog ) {
  16673. gl.uniform1f( uniforms.fogNear, fog.near );
  16674. gl.uniform1f( uniforms.fogFar, fog.far );
  16675. gl.uniform1i( uniforms.fogType, 1 );
  16676. oldFogType = 1;
  16677. sceneFogType = 1;
  16678. } else if ( fog instanceof THREE.FogExp2 ) {
  16679. gl.uniform1f( uniforms.fogDensity, fog.density );
  16680. gl.uniform1i( uniforms.fogType, 2 );
  16681. oldFogType = 2;
  16682. sceneFogType = 2;
  16683. }
  16684. } else {
  16685. gl.uniform1i( uniforms.fogType, 0 );
  16686. oldFogType = 0;
  16687. sceneFogType = 0;
  16688. }
  16689. // update positions and sort
  16690. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16691. var sprite = sprites[ i ];
  16692. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  16693. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  16694. }
  16695. sprites.sort( painterSortStable );
  16696. // render all sprites
  16697. var scale = [];
  16698. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16699. var sprite = sprites[ i ];
  16700. var material = sprite.material;
  16701. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  16702. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  16703. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  16704. scale[ 0 ] = spriteScale.x;
  16705. scale[ 1 ] = spriteScale.y;
  16706. var fogType = 0;
  16707. if ( scene.fog && material.fog ) {
  16708. fogType = sceneFogType;
  16709. }
  16710. if ( oldFogType !== fogType ) {
  16711. gl.uniform1i( uniforms.fogType, fogType );
  16712. oldFogType = fogType;
  16713. }
  16714. if ( material.map !== null ) {
  16715. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  16716. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  16717. } else {
  16718. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  16719. gl.uniform2f( uniforms.uvScale, 1, 1 );
  16720. }
  16721. gl.uniform1f( uniforms.opacity, material.opacity );
  16722. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  16723. gl.uniform1f( uniforms.rotation, material.rotation );
  16724. gl.uniform2fv( uniforms.scale, scale );
  16725. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  16726. state.setDepthTest( material.depthTest );
  16727. state.setDepthWrite( material.depthWrite );
  16728. if ( material.map && material.map.image && material.map.image.width ) {
  16729. renderer.setTexture( material.map, 0 );
  16730. } else {
  16731. renderer.setTexture( texture, 0 );
  16732. }
  16733. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16734. }
  16735. // restore gl
  16736. state.enable( gl.CULL_FACE );
  16737. renderer.resetGLState();
  16738. };
  16739. function createProgram () {
  16740. var program = gl.createProgram();
  16741. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16742. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16743. gl.shaderSource( vertexShader, [
  16744. 'precision ' + renderer.getPrecision() + ' float;',
  16745. 'uniform mat4 modelViewMatrix;',
  16746. 'uniform mat4 projectionMatrix;',
  16747. 'uniform float rotation;',
  16748. 'uniform vec2 scale;',
  16749. 'uniform vec2 uvOffset;',
  16750. 'uniform vec2 uvScale;',
  16751. 'attribute vec2 position;',
  16752. 'attribute vec2 uv;',
  16753. 'varying vec2 vUV;',
  16754. 'void main() {',
  16755. 'vUV = uvOffset + uv * uvScale;',
  16756. 'vec2 alignedPosition = position * scale;',
  16757. 'vec2 rotatedPosition;',
  16758. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  16759. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  16760. 'vec4 finalPosition;',
  16761. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  16762. 'finalPosition.xy += rotatedPosition;',
  16763. 'finalPosition = projectionMatrix * finalPosition;',
  16764. 'gl_Position = finalPosition;',
  16765. '}'
  16766. ].join( '\n' ) );
  16767. gl.shaderSource( fragmentShader, [
  16768. 'precision ' + renderer.getPrecision() + ' float;',
  16769. 'uniform vec3 color;',
  16770. 'uniform sampler2D map;',
  16771. 'uniform float opacity;',
  16772. 'uniform int fogType;',
  16773. 'uniform vec3 fogColor;',
  16774. 'uniform float fogDensity;',
  16775. 'uniform float fogNear;',
  16776. 'uniform float fogFar;',
  16777. 'uniform float alphaTest;',
  16778. 'varying vec2 vUV;',
  16779. 'void main() {',
  16780. 'vec4 texture = texture2D( map, vUV );',
  16781. 'if ( texture.a < alphaTest ) discard;',
  16782. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  16783. 'if ( fogType > 0 ) {',
  16784. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  16785. 'float fogFactor = 0.0;',
  16786. 'if ( fogType == 1 ) {',
  16787. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  16788. '} else {',
  16789. 'const float LOG2 = 1.442695;',
  16790. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  16791. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  16792. '}',
  16793. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  16794. '}',
  16795. '}'
  16796. ].join( '\n' ) );
  16797. gl.compileShader( vertexShader );
  16798. gl.compileShader( fragmentShader );
  16799. gl.attachShader( program, vertexShader );
  16800. gl.attachShader( program, fragmentShader );
  16801. gl.linkProgram( program );
  16802. return program;
  16803. }
  16804. function painterSortStable ( a, b ) {
  16805. if ( a.z !== b.z ) {
  16806. return b.z - a.z;
  16807. } else {
  16808. return b.id - a.id;
  16809. }
  16810. }
  16811. };
  16812. // File:src/extras/GeometryUtils.js
  16813. /**
  16814. * @author mrdoob / http://mrdoob.com/
  16815. */
  16816. THREE.GeometryUtils = {
  16817. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  16818. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  16819. var matrix;
  16820. if ( geometry2 instanceof THREE.Mesh ) {
  16821. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  16822. matrix = geometry2.matrix;
  16823. geometry2 = geometry2.geometry;
  16824. }
  16825. geometry1.merge( geometry2, matrix, materialIndexOffset );
  16826. },
  16827. center: function ( geometry ) {
  16828. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  16829. return geometry.center();
  16830. }
  16831. };
  16832. // File:src/extras/ImageUtils.js
  16833. /**
  16834. * @author alteredq / http://alteredqualia.com/
  16835. * @author mrdoob / http://mrdoob.com/
  16836. * @author Daosheng Mu / https://github.com/DaoshengMu/
  16837. */
  16838. THREE.ImageUtils = {
  16839. crossOrigin: undefined,
  16840. loadTexture: function ( url, mapping, onLoad, onError ) {
  16841. var loader = new THREE.ImageLoader();
  16842. loader.crossOrigin = this.crossOrigin;
  16843. var texture = new THREE.Texture( undefined, mapping );
  16844. loader.load( url, function ( image ) {
  16845. texture.image = image;
  16846. texture.needsUpdate = true;
  16847. if ( onLoad ) onLoad( texture );
  16848. }, undefined, function ( event ) {
  16849. if ( onError ) onError( event );
  16850. } );
  16851. texture.sourceFile = url;
  16852. return texture;
  16853. },
  16854. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  16855. var images = [];
  16856. var loader = new THREE.ImageLoader();
  16857. loader.crossOrigin = this.crossOrigin;
  16858. var texture = new THREE.CubeTexture( images, mapping );
  16859. var loaded = 0;
  16860. function loadTexture( i ) {
  16861. loader.load( array[ i ], function ( image ) {
  16862. texture.images[ i ] = image;
  16863. loaded += 1;
  16864. if ( loaded === 6 ) {
  16865. texture.needsUpdate = true;
  16866. if ( onLoad ) onLoad( texture );
  16867. }
  16868. }, undefined, onError );
  16869. }
  16870. for ( var i = 0, il = array.length; i < il; ++ i ) {
  16871. loadTexture( i );
  16872. }
  16873. return texture;
  16874. },
  16875. loadCompressedTexture: function () {
  16876. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  16877. },
  16878. loadCompressedTextureCube: function () {
  16879. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  16880. },
  16881. getNormalMap: function ( image, depth ) {
  16882. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  16883. function cross( a, b ) {
  16884. 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 ] ];
  16885. }
  16886. function subtract( a, b ) {
  16887. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  16888. }
  16889. function normalize( a ) {
  16890. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  16891. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  16892. }
  16893. depth = depth | 1;
  16894. var width = image.width;
  16895. var height = image.height;
  16896. var canvas = document.createElement( 'canvas' );
  16897. canvas.width = width;
  16898. canvas.height = height;
  16899. var context = canvas.getContext( '2d' );
  16900. context.drawImage( image, 0, 0 );
  16901. var data = context.getImageData( 0, 0, width, height ).data;
  16902. var imageData = context.createImageData( width, height );
  16903. var output = imageData.data;
  16904. for ( var x = 0; x < width; x ++ ) {
  16905. for ( var y = 0; y < height; y ++ ) {
  16906. var ly = y - 1 < 0 ? 0 : y - 1;
  16907. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  16908. var lx = x - 1 < 0 ? 0 : x - 1;
  16909. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  16910. var points = [];
  16911. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  16912. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  16913. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  16914. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  16915. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  16916. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  16917. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  16918. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  16919. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  16920. var normals = [];
  16921. var num_points = points.length;
  16922. for ( var i = 0; i < num_points; i ++ ) {
  16923. var v1 = points[ i ];
  16924. var v2 = points[ ( i + 1 ) % num_points ];
  16925. v1 = subtract( v1, origin );
  16926. v2 = subtract( v2, origin );
  16927. normals.push( normalize( cross( v1, v2 ) ) );
  16928. }
  16929. var normal = [ 0, 0, 0 ];
  16930. for ( var i = 0; i < normals.length; i ++ ) {
  16931. normal[ 0 ] += normals[ i ][ 0 ];
  16932. normal[ 1 ] += normals[ i ][ 1 ];
  16933. normal[ 2 ] += normals[ i ][ 2 ];
  16934. }
  16935. normal[ 0 ] /= normals.length;
  16936. normal[ 1 ] /= normals.length;
  16937. normal[ 2 ] /= normals.length;
  16938. var idx = ( y * width + x ) * 4;
  16939. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  16940. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  16941. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  16942. output[ idx + 3 ] = 255;
  16943. }
  16944. }
  16945. context.putImageData( imageData, 0, 0 );
  16946. return canvas;
  16947. },
  16948. generateDataTexture: function ( width, height, color ) {
  16949. var size = width * height;
  16950. var data = new Uint8Array( 3 * size );
  16951. var r = Math.floor( color.r * 255 );
  16952. var g = Math.floor( color.g * 255 );
  16953. var b = Math.floor( color.b * 255 );
  16954. for ( var i = 0; i < size; i ++ ) {
  16955. data[ i * 3 ] = r;
  16956. data[ i * 3 + 1 ] = g;
  16957. data[ i * 3 + 2 ] = b;
  16958. }
  16959. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  16960. texture.needsUpdate = true;
  16961. return texture;
  16962. }
  16963. };
  16964. // File:src/extras/SceneUtils.js
  16965. /**
  16966. * @author alteredq / http://alteredqualia.com/
  16967. */
  16968. THREE.SceneUtils = {
  16969. createMultiMaterialObject: function ( geometry, materials ) {
  16970. var group = new THREE.Group();
  16971. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  16972. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  16973. }
  16974. return group;
  16975. },
  16976. detach: function ( child, parent, scene ) {
  16977. child.applyMatrix( parent.matrixWorld );
  16978. parent.remove( child );
  16979. scene.add( child );
  16980. },
  16981. attach: function ( child, scene, parent ) {
  16982. var matrixWorldInverse = new THREE.Matrix4();
  16983. matrixWorldInverse.getInverse( parent.matrixWorld );
  16984. child.applyMatrix( matrixWorldInverse );
  16985. scene.remove( child );
  16986. parent.add( child );
  16987. }
  16988. };
  16989. // File:src/extras/FontUtils.js
  16990. /**
  16991. * @author zz85 / http://www.lab4games.net/zz85/blog
  16992. * @author alteredq / http://alteredqualia.com/
  16993. *
  16994. * For Text operations in three.js (See TextGeometry)
  16995. *
  16996. * It uses techniques used in:
  16997. *
  16998. * Triangulation ported from AS3
  16999. * Simple Polygon Triangulation
  17000. * http://actionsnippet.com/?p=1462
  17001. *
  17002. * A Method to triangulate shapes with holes
  17003. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  17004. *
  17005. */
  17006. THREE.FontUtils = {
  17007. faces: {},
  17008. // Just for now. face[weight][style]
  17009. face: 'helvetiker',
  17010. weight: 'normal',
  17011. style: 'normal',
  17012. size: 150,
  17013. divisions: 10,
  17014. getFace: function () {
  17015. try {
  17016. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  17017. } catch ( e ) {
  17018. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  17019. }
  17020. },
  17021. loadFace: function ( data ) {
  17022. var family = data.familyName.toLowerCase();
  17023. var ThreeFont = this;
  17024. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  17025. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  17026. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  17027. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  17028. return data;
  17029. },
  17030. drawText: function ( text ) {
  17031. // RenderText
  17032. var i,
  17033. face = this.getFace(),
  17034. scale = this.size / face.resolution,
  17035. offset = 0,
  17036. chars = String( text ).split( '' ),
  17037. length = chars.length;
  17038. var fontPaths = [];
  17039. for ( i = 0; i < length; i ++ ) {
  17040. var path = new THREE.Path();
  17041. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  17042. offset += ret.offset;
  17043. fontPaths.push( ret.path );
  17044. }
  17045. // get the width
  17046. var width = offset / 2;
  17047. //
  17048. // for ( p = 0; p < allPts.length; p++ ) {
  17049. //
  17050. // allPts[ p ].x -= width;
  17051. //
  17052. // }
  17053. //var extract = this.extractPoints( allPts, characterPts );
  17054. //extract.contour = allPts;
  17055. //extract.paths = fontPaths;
  17056. //extract.offset = width;
  17057. return { paths: fontPaths, offset: width };
  17058. },
  17059. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  17060. var pts = [];
  17061. var i, i2, divisions,
  17062. outline, action, length,
  17063. scaleX, scaleY,
  17064. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  17065. laste,
  17066. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  17067. if ( ! glyph ) return;
  17068. if ( glyph.o ) {
  17069. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  17070. length = outline.length;
  17071. scaleX = scale;
  17072. scaleY = scale;
  17073. for ( i = 0; i < length; ) {
  17074. action = outline[ i ++ ];
  17075. //console.log( action );
  17076. switch ( action ) {
  17077. case 'm':
  17078. // Move To
  17079. x = outline[ i ++ ] * scaleX + offset;
  17080. y = outline[ i ++ ] * scaleY;
  17081. path.moveTo( x, y );
  17082. break;
  17083. case 'l':
  17084. // Line To
  17085. x = outline[ i ++ ] * scaleX + offset;
  17086. y = outline[ i ++ ] * scaleY;
  17087. path.lineTo( x, y );
  17088. break;
  17089. case 'q':
  17090. // QuadraticCurveTo
  17091. cpx = outline[ i ++ ] * scaleX + offset;
  17092. cpy = outline[ i ++ ] * scaleY;
  17093. cpx1 = outline[ i ++ ] * scaleX + offset;
  17094. cpy1 = outline[ i ++ ] * scaleY;
  17095. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  17096. laste = pts[ pts.length - 1 ];
  17097. if ( laste ) {
  17098. cpx0 = laste.x;
  17099. cpy0 = laste.y;
  17100. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  17101. var t = i2 / divisions;
  17102. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  17103. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  17104. }
  17105. }
  17106. break;
  17107. case 'b':
  17108. // Cubic Bezier Curve
  17109. cpx = outline[ i ++ ] * scaleX + offset;
  17110. cpy = outline[ i ++ ] * scaleY;
  17111. cpx1 = outline[ i ++ ] * scaleX + offset;
  17112. cpy1 = outline[ i ++ ] * scaleY;
  17113. cpx2 = outline[ i ++ ] * scaleX + offset;
  17114. cpy2 = outline[ i ++ ] * scaleY;
  17115. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  17116. laste = pts[ pts.length - 1 ];
  17117. if ( laste ) {
  17118. cpx0 = laste.x;
  17119. cpy0 = laste.y;
  17120. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  17121. var t = i2 / divisions;
  17122. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  17123. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  17124. }
  17125. }
  17126. break;
  17127. }
  17128. }
  17129. }
  17130. return { offset: glyph.ha * scale, path: path };
  17131. }
  17132. };
  17133. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  17134. // Parameters
  17135. parameters = parameters || {};
  17136. var size = parameters.size !== undefined ? parameters.size : 100;
  17137. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  17138. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  17139. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  17140. var style = parameters.style !== undefined ? parameters.style : 'normal';
  17141. THREE.FontUtils.size = size;
  17142. THREE.FontUtils.divisions = curveSegments;
  17143. THREE.FontUtils.face = font;
  17144. THREE.FontUtils.weight = weight;
  17145. THREE.FontUtils.style = style;
  17146. // Get a Font data json object
  17147. var data = THREE.FontUtils.drawText( text );
  17148. var paths = data.paths;
  17149. var shapes = [];
  17150. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  17151. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  17152. }
  17153. return shapes;
  17154. };
  17155. /**
  17156. * This code is a quick port of code written in C++ which was submitted to
  17157. * flipcode.com by John W. Ratcliff // July 22, 2000
  17158. * See original code and more information here:
  17159. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  17160. *
  17161. * ported to actionscript by Zevan Rosser
  17162. * www.actionsnippet.com
  17163. *
  17164. * ported to javascript by Joshua Koo
  17165. * http://www.lab4games.net/zz85/blog
  17166. *
  17167. */
  17168. ( function ( namespace ) {
  17169. var EPSILON = 0.0000000001;
  17170. // takes in an contour array and returns
  17171. function process( contour, indices ) {
  17172. var n = contour.length;
  17173. if ( n < 3 ) return null;
  17174. var result = [],
  17175. verts = [],
  17176. vertIndices = [];
  17177. /* we want a counter-clockwise polygon in verts */
  17178. var u, v, w;
  17179. if ( area( contour ) > 0.0 ) {
  17180. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  17181. } else {
  17182. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  17183. }
  17184. var nv = n;
  17185. /* remove nv - 2 vertices, creating 1 triangle every time */
  17186. var count = 2 * nv; /* error detection */
  17187. for ( v = nv - 1; nv > 2; ) {
  17188. /* if we loop, it is probably a non-simple polygon */
  17189. if ( ( count -- ) <= 0 ) {
  17190. //** Triangulate: ERROR - probable bad polygon!
  17191. //throw ( "Warning, unable to triangulate polygon!" );
  17192. //return null;
  17193. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  17194. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  17195. if ( indices ) return vertIndices;
  17196. return result;
  17197. }
  17198. /* three consecutive vertices in current polygon, <u,v,w> */
  17199. u = v; if ( nv <= u ) u = 0; /* previous */
  17200. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  17201. w = v + 1; if ( nv <= w ) w = 0; /* next */
  17202. if ( snip( contour, u, v, w, nv, verts ) ) {
  17203. var a, b, c, s, t;
  17204. /* true names of the vertices */
  17205. a = verts[ u ];
  17206. b = verts[ v ];
  17207. c = verts[ w ];
  17208. /* output Triangle */
  17209. result.push( [ contour[ a ],
  17210. contour[ b ],
  17211. contour[ c ] ] );
  17212. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  17213. /* remove v from the remaining polygon */
  17214. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  17215. verts[ s ] = verts[ t ];
  17216. }
  17217. nv --;
  17218. /* reset error detection counter */
  17219. count = 2 * nv;
  17220. }
  17221. }
  17222. if ( indices ) return vertIndices;
  17223. return result;
  17224. }
  17225. // calculate area of the contour polygon
  17226. function area( contour ) {
  17227. var n = contour.length;
  17228. var a = 0.0;
  17229. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17230. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17231. }
  17232. return a * 0.5;
  17233. }
  17234. function snip( contour, u, v, w, n, verts ) {
  17235. var p;
  17236. var ax, ay, bx, by;
  17237. var cx, cy, px, py;
  17238. ax = contour[ verts[ u ] ].x;
  17239. ay = contour[ verts[ u ] ].y;
  17240. bx = contour[ verts[ v ] ].x;
  17241. by = contour[ verts[ v ] ].y;
  17242. cx = contour[ verts[ w ] ].x;
  17243. cy = contour[ verts[ w ] ].y;
  17244. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  17245. var aX, aY, bX, bY, cX, cY;
  17246. var apx, apy, bpx, bpy, cpx, cpy;
  17247. var cCROSSap, bCROSScp, aCROSSbp;
  17248. aX = cx - bx; aY = cy - by;
  17249. bX = ax - cx; bY = ay - cy;
  17250. cX = bx - ax; cY = by - ay;
  17251. for ( p = 0; p < n; p ++ ) {
  17252. px = contour[ verts[ p ] ].x;
  17253. py = contour[ verts[ p ] ].y;
  17254. if ( ( ( px === ax ) && ( py === ay ) ) ||
  17255. ( ( px === bx ) && ( py === by ) ) ||
  17256. ( ( px === cx ) && ( py === cy ) ) ) continue;
  17257. apx = px - ax; apy = py - ay;
  17258. bpx = px - bx; bpy = py - by;
  17259. cpx = px - cx; cpy = py - cy;
  17260. // see if p is inside triangle abc
  17261. aCROSSbp = aX * bpy - aY * bpx;
  17262. cCROSSap = cX * apy - cY * apx;
  17263. bCROSScp = bX * cpy - bY * cpx;
  17264. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  17265. }
  17266. return true;
  17267. }
  17268. namespace.Triangulate = process;
  17269. namespace.Triangulate.area = area;
  17270. return namespace;
  17271. } )( THREE.FontUtils );
  17272. // To use the typeface.js face files, hook up the API
  17273. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  17274. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  17275. // File:src/extras/audio/Audio.js
  17276. /**
  17277. * @author mrdoob / http://mrdoob.com/
  17278. */
  17279. THREE.Audio = function ( listener ) {
  17280. THREE.Object3D.call( this );
  17281. this.type = 'Audio';
  17282. this.context = listener.context;
  17283. this.source = this.context.createBufferSource();
  17284. this.source.onended = this.onEnded.bind( this );
  17285. this.gain = this.context.createGain();
  17286. this.gain.connect( this.context.destination );
  17287. this.panner = this.context.createPanner();
  17288. this.panner.connect( this.gain );
  17289. this.autoplay = false;
  17290. this.startTime = 0;
  17291. this.playbackRate = 1;
  17292. this.isPlaying = false;
  17293. };
  17294. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  17295. THREE.Audio.prototype.constructor = THREE.Audio;
  17296. THREE.Audio.prototype.load = function ( file ) {
  17297. var scope = this;
  17298. var request = new XMLHttpRequest();
  17299. request.open( 'GET', file, true );
  17300. request.responseType = 'arraybuffer';
  17301. request.onload = function ( e ) {
  17302. scope.context.decodeAudioData( this.response, function ( buffer ) {
  17303. scope.source.buffer = buffer;
  17304. if ( scope.autoplay ) scope.play();
  17305. } );
  17306. };
  17307. request.send();
  17308. return this;
  17309. };
  17310. THREE.Audio.prototype.play = function () {
  17311. if ( this.isPlaying === true ) {
  17312. console.warn( 'THREE.Audio: Audio is already playing.' );
  17313. return;
  17314. }
  17315. var source = this.context.createBufferSource();
  17316. source.buffer = this.source.buffer;
  17317. source.loop = this.source.loop;
  17318. source.onended = this.source.onended;
  17319. source.start( 0, this.startTime );
  17320. source.playbackRate.value = this.playbackRate;
  17321. this.isPlaying = true;
  17322. this.source = source;
  17323. this.connect();
  17324. };
  17325. THREE.Audio.prototype.pause = function () {
  17326. this.source.stop();
  17327. this.startTime = this.context.currentTime;
  17328. };
  17329. THREE.Audio.prototype.stop = function () {
  17330. this.source.stop();
  17331. this.startTime = 0;
  17332. };
  17333. THREE.Audio.prototype.connect = function () {
  17334. if ( this.filter !== undefined ) {
  17335. this.source.connect( this.filter );
  17336. this.filter.connect( this.panner );
  17337. } else {
  17338. this.source.connect( this.panner );
  17339. }
  17340. };
  17341. THREE.Audio.prototype.disconnect = function () {
  17342. if ( this.filter !== undefined ) {
  17343. this.source.disconnect( this.filter );
  17344. this.filter.disconnect( this.panner );
  17345. } else {
  17346. this.source.disconnect( this.panner );
  17347. }
  17348. };
  17349. THREE.Audio.prototype.setFilter = function ( value ) {
  17350. if ( this.isPlaying === true ) {
  17351. this.disconnect();
  17352. this.filter = value;
  17353. this.connect();
  17354. } else {
  17355. this.filter = value;
  17356. }
  17357. };
  17358. THREE.Audio.prototype.getFilter = function () {
  17359. return this.filter;
  17360. };
  17361. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  17362. this.playbackRate = value;
  17363. if ( this.isPlaying === true ) {
  17364. this.source.playbackRate.value = this.playbackRate;
  17365. }
  17366. };
  17367. THREE.Audio.prototype.getPlaybackRate = function () {
  17368. return this.playbackRate;
  17369. };
  17370. THREE.Audio.prototype.onEnded = function() {
  17371. this.isPlaying = false;
  17372. };
  17373. THREE.Audio.prototype.setLoop = function ( value ) {
  17374. this.source.loop = value;
  17375. };
  17376. THREE.Audio.prototype.getLoop = function () {
  17377. return this.source.loop;
  17378. };
  17379. THREE.Audio.prototype.setRefDistance = function ( value ) {
  17380. this.panner.refDistance = value;
  17381. };
  17382. THREE.Audio.prototype.getRefDistance = function () {
  17383. return this.panner.refDistance;
  17384. };
  17385. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  17386. this.panner.rolloffFactor = value;
  17387. };
  17388. THREE.Audio.prototype.getRolloffFactor = function () {
  17389. return this.panner.rolloffFactor;
  17390. };
  17391. THREE.Audio.prototype.setVolume = function ( value ) {
  17392. this.gain.gain.value = value;
  17393. };
  17394. THREE.Audio.prototype.getVolume = function () {
  17395. return this.gain.gain.value;
  17396. };
  17397. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  17398. var position = new THREE.Vector3();
  17399. return function updateMatrixWorld( force ) {
  17400. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17401. position.setFromMatrixPosition( this.matrixWorld );
  17402. this.panner.setPosition( position.x, position.y, position.z );
  17403. };
  17404. } )();
  17405. // File:src/extras/audio/AudioListener.js
  17406. /**
  17407. * @author mrdoob / http://mrdoob.com/
  17408. */
  17409. THREE.AudioListener = function () {
  17410. THREE.Object3D.call( this );
  17411. this.type = 'AudioListener';
  17412. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  17413. };
  17414. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  17415. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  17416. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  17417. var position = new THREE.Vector3();
  17418. var quaternion = new THREE.Quaternion();
  17419. var scale = new THREE.Vector3();
  17420. var orientation = new THREE.Vector3();
  17421. return function updateMatrixWorld( force ) {
  17422. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17423. var listener = this.context.listener;
  17424. var up = this.up;
  17425. this.matrixWorld.decompose( position, quaternion, scale );
  17426. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  17427. listener.setPosition( position.x, position.y, position.z );
  17428. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  17429. };
  17430. } )();
  17431. // File:src/extras/core/Curve.js
  17432. /**
  17433. * @author zz85 / http://www.lab4games.net/zz85/blog
  17434. * Extensible curve object
  17435. *
  17436. * Some common of Curve methods
  17437. * .getPoint(t), getTangent(t)
  17438. * .getPointAt(u), getTagentAt(u)
  17439. * .getPoints(), .getSpacedPoints()
  17440. * .getLength()
  17441. * .updateArcLengths()
  17442. *
  17443. * This following classes subclasses THREE.Curve:
  17444. *
  17445. * -- 2d classes --
  17446. * THREE.LineCurve
  17447. * THREE.QuadraticBezierCurve
  17448. * THREE.CubicBezierCurve
  17449. * THREE.SplineCurve
  17450. * THREE.ArcCurve
  17451. * THREE.EllipseCurve
  17452. *
  17453. * -- 3d classes --
  17454. * THREE.LineCurve3
  17455. * THREE.QuadraticBezierCurve3
  17456. * THREE.CubicBezierCurve3
  17457. * THREE.SplineCurve3
  17458. * THREE.ClosedSplineCurve3
  17459. *
  17460. * A series of curves can be represented as a THREE.CurvePath
  17461. *
  17462. **/
  17463. /**************************************************************
  17464. * Abstract Curve base class
  17465. **************************************************************/
  17466. THREE.Curve = function () {
  17467. };
  17468. // Virtual base class method to overwrite and implement in subclasses
  17469. // - t [0 .. 1]
  17470. THREE.Curve.prototype.getPoint = function ( t ) {
  17471. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  17472. return null;
  17473. };
  17474. // Get point at relative position in curve according to arc length
  17475. // - u [0 .. 1]
  17476. THREE.Curve.prototype.getPointAt = function ( u ) {
  17477. var t = this.getUtoTmapping( u );
  17478. return this.getPoint( t );
  17479. };
  17480. // Get sequence of points using getPoint( t )
  17481. THREE.Curve.prototype.getPoints = function ( divisions ) {
  17482. if ( ! divisions ) divisions = 5;
  17483. var d, pts = [];
  17484. for ( d = 0; d <= divisions; d ++ ) {
  17485. pts.push( this.getPoint( d / divisions ) );
  17486. }
  17487. return pts;
  17488. };
  17489. // Get sequence of points using getPointAt( u )
  17490. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  17491. if ( ! divisions ) divisions = 5;
  17492. var d, pts = [];
  17493. for ( d = 0; d <= divisions; d ++ ) {
  17494. pts.push( this.getPointAt( d / divisions ) );
  17495. }
  17496. return pts;
  17497. };
  17498. // Get total curve arc length
  17499. THREE.Curve.prototype.getLength = function () {
  17500. var lengths = this.getLengths();
  17501. return lengths[ lengths.length - 1 ];
  17502. };
  17503. // Get list of cumulative segment lengths
  17504. THREE.Curve.prototype.getLengths = function ( divisions ) {
  17505. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  17506. if ( this.cacheArcLengths
  17507. && ( this.cacheArcLengths.length === divisions + 1 )
  17508. && ! this.needsUpdate ) {
  17509. //console.log( "cached", this.cacheArcLengths );
  17510. return this.cacheArcLengths;
  17511. }
  17512. this.needsUpdate = false;
  17513. var cache = [];
  17514. var current, last = this.getPoint( 0 );
  17515. var p, sum = 0;
  17516. cache.push( 0 );
  17517. for ( p = 1; p <= divisions; p ++ ) {
  17518. current = this.getPoint ( p / divisions );
  17519. sum += current.distanceTo( last );
  17520. cache.push( sum );
  17521. last = current;
  17522. }
  17523. this.cacheArcLengths = cache;
  17524. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  17525. };
  17526. THREE.Curve.prototype.updateArcLengths = function() {
  17527. this.needsUpdate = true;
  17528. this.getLengths();
  17529. };
  17530. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  17531. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  17532. var arcLengths = this.getLengths();
  17533. var i = 0, il = arcLengths.length;
  17534. var targetArcLength; // The targeted u distance value to get
  17535. if ( distance ) {
  17536. targetArcLength = distance;
  17537. } else {
  17538. targetArcLength = u * arcLengths[ il - 1 ];
  17539. }
  17540. //var time = Date.now();
  17541. // binary search for the index with largest value smaller than target u distance
  17542. var low = 0, high = il - 1, comparison;
  17543. while ( low <= high ) {
  17544. 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
  17545. comparison = arcLengths[ i ] - targetArcLength;
  17546. if ( comparison < 0 ) {
  17547. low = i + 1;
  17548. } else if ( comparison > 0 ) {
  17549. high = i - 1;
  17550. } else {
  17551. high = i;
  17552. break;
  17553. // DONE
  17554. }
  17555. }
  17556. i = high;
  17557. //console.log('b' , i, low, high, Date.now()- time);
  17558. if ( arcLengths[ i ] === targetArcLength ) {
  17559. var t = i / ( il - 1 );
  17560. return t;
  17561. }
  17562. // we could get finer grain at lengths, or use simple interpolation between two points
  17563. var lengthBefore = arcLengths[ i ];
  17564. var lengthAfter = arcLengths[ i + 1 ];
  17565. var segmentLength = lengthAfter - lengthBefore;
  17566. // determine where we are between the 'before' and 'after' points
  17567. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  17568. // add that fractional amount to t
  17569. var t = ( i + segmentFraction ) / ( il - 1 );
  17570. return t;
  17571. };
  17572. // Returns a unit vector tangent at t
  17573. // In case any sub curve does not implement its tangent derivation,
  17574. // 2 points a small delta apart will be used to find its gradient
  17575. // which seems to give a reasonable approximation
  17576. THREE.Curve.prototype.getTangent = function( t ) {
  17577. var delta = 0.0001;
  17578. var t1 = t - delta;
  17579. var t2 = t + delta;
  17580. // Capping in case of danger
  17581. if ( t1 < 0 ) t1 = 0;
  17582. if ( t2 > 1 ) t2 = 1;
  17583. var pt1 = this.getPoint( t1 );
  17584. var pt2 = this.getPoint( t2 );
  17585. var vec = pt2.clone().sub( pt1 );
  17586. return vec.normalize();
  17587. };
  17588. THREE.Curve.prototype.getTangentAt = function ( u ) {
  17589. var t = this.getUtoTmapping( u );
  17590. return this.getTangent( t );
  17591. };
  17592. /**************************************************************
  17593. * Utils
  17594. **************************************************************/
  17595. THREE.Curve.Utils = {
  17596. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  17597. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  17598. },
  17599. // Puay Bing, thanks for helping with this derivative!
  17600. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  17601. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  17602. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  17603. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  17604. 3 * t * t * p3;
  17605. },
  17606. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  17607. // To check if my formulas are correct
  17608. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  17609. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  17610. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  17611. var h11 = 3 * t * t - 2 * t; // t3 − t2
  17612. return h00 + h10 + h01 + h11;
  17613. },
  17614. // Catmull-Rom
  17615. interpolate: function( p0, p1, p2, p3, t ) {
  17616. var v0 = ( p2 - p0 ) * 0.5;
  17617. var v1 = ( p3 - p1 ) * 0.5;
  17618. var t2 = t * t;
  17619. var t3 = t * t2;
  17620. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  17621. }
  17622. };
  17623. // TODO: Transformation for Curves?
  17624. /**************************************************************
  17625. * 3D Curves
  17626. **************************************************************/
  17627. // A Factory method for creating new curve subclasses
  17628. THREE.Curve.create = function ( constructor, getPointFunc ) {
  17629. constructor.prototype = Object.create( THREE.Curve.prototype );
  17630. constructor.prototype.constructor = constructor;
  17631. constructor.prototype.getPoint = getPointFunc;
  17632. return constructor;
  17633. };
  17634. // File:src/extras/core/CurvePath.js
  17635. /**
  17636. * @author zz85 / http://www.lab4games.net/zz85/blog
  17637. *
  17638. **/
  17639. /**************************************************************
  17640. * Curved Path - a curve path is simply a array of connected
  17641. * curves, but retains the api of a curve
  17642. **************************************************************/
  17643. THREE.CurvePath = function () {
  17644. this.curves = [];
  17645. this.bends = [];
  17646. this.autoClose = false; // Automatically closes the path
  17647. };
  17648. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  17649. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  17650. THREE.CurvePath.prototype.add = function ( curve ) {
  17651. this.curves.push( curve );
  17652. };
  17653. THREE.CurvePath.prototype.checkConnection = function() {
  17654. // TODO
  17655. // If the ending of curve is not connected to the starting
  17656. // or the next curve, then, this is not a real path
  17657. };
  17658. THREE.CurvePath.prototype.closePath = function() {
  17659. // TODO Test
  17660. // and verify for vector3 (needs to implement equals)
  17661. // Add a line curve if start and end of lines are not connected
  17662. var startPoint = this.curves[ 0 ].getPoint( 0 );
  17663. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  17664. if ( ! startPoint.equals( endPoint ) ) {
  17665. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  17666. }
  17667. };
  17668. // To get accurate point with reference to
  17669. // entire path distance at time t,
  17670. // following has to be done:
  17671. // 1. Length of each sub path have to be known
  17672. // 2. Locate and identify type of curve
  17673. // 3. Get t for the curve
  17674. // 4. Return curve.getPointAt(t')
  17675. THREE.CurvePath.prototype.getPoint = function( t ) {
  17676. var d = t * this.getLength();
  17677. var curveLengths = this.getCurveLengths();
  17678. var i = 0, diff, curve;
  17679. // To think about boundaries points.
  17680. while ( i < curveLengths.length ) {
  17681. if ( curveLengths[ i ] >= d ) {
  17682. diff = curveLengths[ i ] - d;
  17683. curve = this.curves[ i ];
  17684. var u = 1 - diff / curve.getLength();
  17685. return curve.getPointAt( u );
  17686. }
  17687. i ++;
  17688. }
  17689. return null;
  17690. // loop where sum != 0, sum > d , sum+1 <d
  17691. };
  17692. /*
  17693. THREE.CurvePath.prototype.getTangent = function( t ) {
  17694. };*/
  17695. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  17696. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  17697. // getPoint() depends on getLength
  17698. THREE.CurvePath.prototype.getLength = function() {
  17699. var lens = this.getCurveLengths();
  17700. return lens[ lens.length - 1 ];
  17701. };
  17702. // Compute lengths and cache them
  17703. // We cannot overwrite getLengths() because UtoT mapping uses it.
  17704. THREE.CurvePath.prototype.getCurveLengths = function() {
  17705. // We use cache values if curves and cache array are same length
  17706. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  17707. return this.cacheLengths;
  17708. }
  17709. // Get length of sub-curve
  17710. // Push sums into cached array
  17711. var lengths = [], sums = 0;
  17712. var i, il = this.curves.length;
  17713. for ( i = 0; i < il; i ++ ) {
  17714. sums += this.curves[ i ].getLength();
  17715. lengths.push( sums );
  17716. }
  17717. this.cacheLengths = lengths;
  17718. return lengths;
  17719. };
  17720. // Returns min and max coordinates
  17721. THREE.CurvePath.prototype.getBoundingBox = function () {
  17722. var points = this.getPoints();
  17723. var maxX, maxY, maxZ;
  17724. var minX, minY, minZ;
  17725. maxX = maxY = Number.NEGATIVE_INFINITY;
  17726. minX = minY = Number.POSITIVE_INFINITY;
  17727. var p, i, il, sum;
  17728. var v3 = points[ 0 ] instanceof THREE.Vector3;
  17729. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  17730. for ( i = 0, il = points.length; i < il; i ++ ) {
  17731. p = points[ i ];
  17732. if ( p.x > maxX ) maxX = p.x;
  17733. else if ( p.x < minX ) minX = p.x;
  17734. if ( p.y > maxY ) maxY = p.y;
  17735. else if ( p.y < minY ) minY = p.y;
  17736. if ( v3 ) {
  17737. if ( p.z > maxZ ) maxZ = p.z;
  17738. else if ( p.z < minZ ) minZ = p.z;
  17739. }
  17740. sum.add( p );
  17741. }
  17742. var ret = {
  17743. minX: minX,
  17744. minY: minY,
  17745. maxX: maxX,
  17746. maxY: maxY
  17747. };
  17748. if ( v3 ) {
  17749. ret.maxZ = maxZ;
  17750. ret.minZ = minZ;
  17751. }
  17752. return ret;
  17753. };
  17754. /**************************************************************
  17755. * Create Geometries Helpers
  17756. **************************************************************/
  17757. /// Generate geometry from path points (for Line or Points objects)
  17758. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  17759. var pts = this.getPoints( divisions, true );
  17760. return this.createGeometry( pts );
  17761. };
  17762. // Generate geometry from equidistant sampling along the path
  17763. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  17764. var pts = this.getSpacedPoints( divisions, true );
  17765. return this.createGeometry( pts );
  17766. };
  17767. THREE.CurvePath.prototype.createGeometry = function( points ) {
  17768. var geometry = new THREE.Geometry();
  17769. for ( var i = 0; i < points.length; i ++ ) {
  17770. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0 ) );
  17771. }
  17772. return geometry;
  17773. };
  17774. /**************************************************************
  17775. * Bend / Wrap Helper Methods
  17776. **************************************************************/
  17777. // Wrap path / Bend modifiers?
  17778. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  17779. this.bends.push( bendpath );
  17780. };
  17781. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  17782. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  17783. var i, il;
  17784. if ( ! bends ) {
  17785. bends = this.bends;
  17786. }
  17787. for ( i = 0, il = bends.length; i < il; i ++ ) {
  17788. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  17789. }
  17790. return oldPts;
  17791. };
  17792. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  17793. var oldPts = this.getSpacedPoints( segments );
  17794. var i, il;
  17795. if ( ! bends ) {
  17796. bends = this.bends;
  17797. }
  17798. for ( i = 0, il = bends.length; i < il; i ++ ) {
  17799. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  17800. }
  17801. return oldPts;
  17802. };
  17803. // This returns getPoints() bend/wrapped around the contour of a path.
  17804. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  17805. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  17806. var bounds = this.getBoundingBox();
  17807. var i, il, p, oldX, oldY, xNorm;
  17808. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  17809. p = oldPts[ i ];
  17810. oldX = p.x;
  17811. oldY = p.y;
  17812. xNorm = oldX / bounds.maxX;
  17813. // If using actual distance, for length > path, requires line extrusions
  17814. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  17815. xNorm = path.getUtoTmapping( xNorm, oldX );
  17816. // check for out of bounds?
  17817. var pathPt = path.getPoint( xNorm );
  17818. var normal = path.getTangent( xNorm );
  17819. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  17820. p.x = pathPt.x + normal.x;
  17821. p.y = pathPt.y + normal.y;
  17822. }
  17823. return oldPts;
  17824. };
  17825. // File:src/extras/core/Path.js
  17826. /**
  17827. * @author zz85 / http://www.lab4games.net/zz85/blog
  17828. * Creates free form 2d path using series of points, lines or curves.
  17829. *
  17830. **/
  17831. THREE.Path = function ( points ) {
  17832. THREE.CurvePath.call( this );
  17833. this.actions = [];
  17834. if ( points ) {
  17835. this.fromPoints( points );
  17836. }
  17837. };
  17838. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  17839. THREE.Path.prototype.constructor = THREE.Path;
  17840. THREE.PathActions = {
  17841. MOVE_TO: 'moveTo',
  17842. LINE_TO: 'lineTo',
  17843. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  17844. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  17845. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  17846. ARC: 'arc', // Circle
  17847. ELLIPSE: 'ellipse'
  17848. };
  17849. // TODO Clean up PATH API
  17850. // Create path using straight lines to connect all points
  17851. // - vectors: array of Vector2
  17852. THREE.Path.prototype.fromPoints = function ( vectors ) {
  17853. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  17854. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  17855. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  17856. }
  17857. };
  17858. // startPath() endPath()?
  17859. THREE.Path.prototype.moveTo = function ( x, y ) {
  17860. var args = Array.prototype.slice.call( arguments );
  17861. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  17862. };
  17863. THREE.Path.prototype.lineTo = function ( x, y ) {
  17864. var args = Array.prototype.slice.call( arguments );
  17865. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17866. var x0 = lastargs[ lastargs.length - 2 ];
  17867. var y0 = lastargs[ lastargs.length - 1 ];
  17868. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  17869. this.curves.push( curve );
  17870. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  17871. };
  17872. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  17873. var args = Array.prototype.slice.call( arguments );
  17874. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17875. var x0 = lastargs[ lastargs.length - 2 ];
  17876. var y0 = lastargs[ lastargs.length - 1 ];
  17877. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  17878. new THREE.Vector2( aCPx, aCPy ),
  17879. new THREE.Vector2( aX, aY ) );
  17880. this.curves.push( curve );
  17881. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  17882. };
  17883. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  17884. aCP2x, aCP2y,
  17885. aX, aY ) {
  17886. var args = Array.prototype.slice.call( arguments );
  17887. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17888. var x0 = lastargs[ lastargs.length - 2 ];
  17889. var y0 = lastargs[ lastargs.length - 1 ];
  17890. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  17891. new THREE.Vector2( aCP1x, aCP1y ),
  17892. new THREE.Vector2( aCP2x, aCP2y ),
  17893. new THREE.Vector2( aX, aY ) );
  17894. this.curves.push( curve );
  17895. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  17896. };
  17897. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  17898. var args = Array.prototype.slice.call( arguments );
  17899. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17900. var x0 = lastargs[ lastargs.length - 2 ];
  17901. var y0 = lastargs[ lastargs.length - 1 ];
  17902. //---
  17903. var npts = [ new THREE.Vector2( x0, y0 ) ];
  17904. Array.prototype.push.apply( npts, pts );
  17905. var curve = new THREE.SplineCurve( npts );
  17906. this.curves.push( curve );
  17907. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  17908. };
  17909. // FUTURE: Change the API or follow canvas API?
  17910. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  17911. aStartAngle, aEndAngle, aClockwise ) {
  17912. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17913. var x0 = lastargs[ lastargs.length - 2 ];
  17914. var y0 = lastargs[ lastargs.length - 1 ];
  17915. this.absarc( aX + x0, aY + y0, aRadius,
  17916. aStartAngle, aEndAngle, aClockwise );
  17917. };
  17918. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  17919. aStartAngle, aEndAngle, aClockwise ) {
  17920. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17921. };
  17922. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  17923. aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17924. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17925. var x0 = lastargs[ lastargs.length - 2 ];
  17926. var y0 = lastargs[ lastargs.length - 1 ];
  17927. this.absellipse( aX + x0, aY + y0, xRadius, yRadius,
  17928. aStartAngle, aEndAngle, aClockwise, aRotation );
  17929. };
  17930. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  17931. aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17932. var args = [
  17933. aX, aY,
  17934. xRadius, yRadius,
  17935. aStartAngle, aEndAngle,
  17936. aClockwise,
  17937. aRotation || 0 // aRotation is optional.
  17938. ];
  17939. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  17940. aStartAngle, aEndAngle, aClockwise, aRotation );
  17941. this.curves.push( curve );
  17942. var lastPoint = curve.getPoint( 1 );
  17943. args.push( lastPoint.x );
  17944. args.push( lastPoint.y );
  17945. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  17946. };
  17947. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  17948. if ( ! divisions ) divisions = 40;
  17949. var points = [];
  17950. for ( var i = 0; i < divisions; i ++ ) {
  17951. points.push( this.getPoint( i / divisions ) );
  17952. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  17953. }
  17954. // if ( closedPath ) {
  17955. //
  17956. // points.push( points[ 0 ] );
  17957. //
  17958. // }
  17959. return points;
  17960. };
  17961. /* Return an array of vectors based on contour of the path */
  17962. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  17963. if ( this.useSpacedPoints ) {
  17964. return this.getSpacedPoints( divisions, closedPath );
  17965. }
  17966. divisions = divisions || 12;
  17967. var points = [];
  17968. var i, il, item, action, args;
  17969. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  17970. laste, j,
  17971. t, tx, ty;
  17972. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  17973. item = this.actions[ i ];
  17974. action = item.action;
  17975. args = item.args;
  17976. switch ( action ) {
  17977. case THREE.PathActions.MOVE_TO:
  17978. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17979. break;
  17980. case THREE.PathActions.LINE_TO:
  17981. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17982. break;
  17983. case THREE.PathActions.QUADRATIC_CURVE_TO:
  17984. cpx = args[ 2 ];
  17985. cpy = args[ 3 ];
  17986. cpx1 = args[ 0 ];
  17987. cpy1 = args[ 1 ];
  17988. if ( points.length > 0 ) {
  17989. laste = points[ points.length - 1 ];
  17990. cpx0 = laste.x;
  17991. cpy0 = laste.y;
  17992. } else {
  17993. laste = this.actions[ i - 1 ].args;
  17994. cpx0 = laste[ laste.length - 2 ];
  17995. cpy0 = laste[ laste.length - 1 ];
  17996. }
  17997. for ( j = 1; j <= divisions; j ++ ) {
  17998. t = j / divisions;
  17999. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  18000. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  18001. points.push( new THREE.Vector2( tx, ty ) );
  18002. }
  18003. break;
  18004. case THREE.PathActions.BEZIER_CURVE_TO:
  18005. cpx = args[ 4 ];
  18006. cpy = args[ 5 ];
  18007. cpx1 = args[ 0 ];
  18008. cpy1 = args[ 1 ];
  18009. cpx2 = args[ 2 ];
  18010. cpy2 = args[ 3 ];
  18011. if ( points.length > 0 ) {
  18012. laste = points[ points.length - 1 ];
  18013. cpx0 = laste.x;
  18014. cpy0 = laste.y;
  18015. } else {
  18016. laste = this.actions[ i - 1 ].args;
  18017. cpx0 = laste[ laste.length - 2 ];
  18018. cpy0 = laste[ laste.length - 1 ];
  18019. }
  18020. for ( j = 1; j <= divisions; j ++ ) {
  18021. t = j / divisions;
  18022. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  18023. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  18024. points.push( new THREE.Vector2( tx, ty ) );
  18025. }
  18026. break;
  18027. case THREE.PathActions.CSPLINE_THRU:
  18028. laste = this.actions[ i - 1 ].args;
  18029. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  18030. var spts = [ last ];
  18031. var n = divisions * args[ 0 ].length;
  18032. spts = spts.concat( args[ 0 ] );
  18033. var spline = new THREE.SplineCurve( spts );
  18034. for ( j = 1; j <= n; j ++ ) {
  18035. points.push( spline.getPointAt( j / n ) );
  18036. }
  18037. break;
  18038. case THREE.PathActions.ARC:
  18039. var aX = args[ 0 ], aY = args[ 1 ],
  18040. aRadius = args[ 2 ],
  18041. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  18042. aClockwise = !! args[ 5 ];
  18043. var deltaAngle = aEndAngle - aStartAngle;
  18044. var angle;
  18045. var tdivisions = divisions * 2;
  18046. for ( j = 1; j <= tdivisions; j ++ ) {
  18047. t = j / tdivisions;
  18048. if ( ! aClockwise ) {
  18049. t = 1 - t;
  18050. }
  18051. angle = aStartAngle + t * deltaAngle;
  18052. tx = aX + aRadius * Math.cos( angle );
  18053. ty = aY + aRadius * Math.sin( angle );
  18054. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  18055. points.push( new THREE.Vector2( tx, ty ) );
  18056. }
  18057. //console.log(points);
  18058. break;
  18059. case THREE.PathActions.ELLIPSE:
  18060. var aX = args[ 0 ], aY = args[ 1 ],
  18061. xRadius = args[ 2 ],
  18062. yRadius = args[ 3 ],
  18063. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  18064. aClockwise = !! args[ 6 ],
  18065. aRotation = args[ 7 ];
  18066. var deltaAngle = aEndAngle - aStartAngle;
  18067. var angle;
  18068. var tdivisions = divisions * 2;
  18069. var cos, sin;
  18070. if ( aRotation !== 0 ) {
  18071. cos = Math.cos( aRotation );
  18072. sin = Math.sin( aRotation );
  18073. }
  18074. for ( j = 1; j <= tdivisions; j ++ ) {
  18075. t = j / tdivisions;
  18076. if ( ! aClockwise ) {
  18077. t = 1 - t;
  18078. }
  18079. angle = aStartAngle + t * deltaAngle;
  18080. tx = aX + xRadius * Math.cos( angle );
  18081. ty = aY + yRadius * Math.sin( angle );
  18082. if ( aRotation !== 0 ) {
  18083. var x = tx, y = ty;
  18084. // Rotate the point about the center of the ellipse.
  18085. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  18086. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  18087. }
  18088. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  18089. points.push( new THREE.Vector2( tx, ty ) );
  18090. }
  18091. //console.log(points);
  18092. break;
  18093. } // end switch
  18094. }
  18095. // Normalize to remove the closing point by default.
  18096. var lastPoint = points[ points.length - 1 ];
  18097. var EPSILON = 0.0000000001;
  18098. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < EPSILON &&
  18099. Math.abs( lastPoint.y - points[ 0 ].y ) < EPSILON )
  18100. points.splice( points.length - 1, 1 );
  18101. if ( closedPath ) {
  18102. points.push( points[ 0 ] );
  18103. }
  18104. return points;
  18105. };
  18106. //
  18107. // Breaks path into shapes
  18108. //
  18109. // Assumptions (if parameter isCCW==true the opposite holds):
  18110. // - solid shapes are defined clockwise (CW)
  18111. // - holes are defined counterclockwise (CCW)
  18112. //
  18113. // If parameter noHoles==true:
  18114. // - all subPaths are regarded as solid shapes
  18115. // - definition order CW/CCW has no relevance
  18116. //
  18117. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  18118. function extractSubpaths( inActions ) {
  18119. var i, il, item, action, args;
  18120. var subPaths = [], lastPath = new THREE.Path();
  18121. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  18122. item = inActions[ i ];
  18123. args = item.args;
  18124. action = item.action;
  18125. if ( action === THREE.PathActions.MOVE_TO ) {
  18126. if ( lastPath.actions.length !== 0 ) {
  18127. subPaths.push( lastPath );
  18128. lastPath = new THREE.Path();
  18129. }
  18130. }
  18131. lastPath[ action ].apply( lastPath, args );
  18132. }
  18133. if ( lastPath.actions.length !== 0 ) {
  18134. subPaths.push( lastPath );
  18135. }
  18136. // console.log(subPaths);
  18137. return subPaths;
  18138. }
  18139. function toShapesNoHoles( inSubpaths ) {
  18140. var shapes = [];
  18141. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  18142. var tmpPath = inSubpaths[ i ];
  18143. var tmpShape = new THREE.Shape();
  18144. tmpShape.actions = tmpPath.actions;
  18145. tmpShape.curves = tmpPath.curves;
  18146. shapes.push( tmpShape );
  18147. }
  18148. //console.log("shape", shapes);
  18149. return shapes;
  18150. }
  18151. function isPointInsidePolygon( inPt, inPolygon ) {
  18152. var EPSILON = 0.0000000001;
  18153. var polyLen = inPolygon.length;
  18154. // inPt on polygon contour => immediate success or
  18155. // toggling of inside/outside at every single! intersection point of an edge
  18156. // with the horizontal line through inPt, left of inPt
  18157. // not counting lowerY endpoints of edges and whole edges on that line
  18158. var inside = false;
  18159. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  18160. var edgeLowPt = inPolygon[ p ];
  18161. var edgeHighPt = inPolygon[ q ];
  18162. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  18163. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  18164. if ( Math.abs( edgeDy ) > EPSILON ) {
  18165. // not parallel
  18166. if ( edgeDy < 0 ) {
  18167. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  18168. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  18169. }
  18170. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  18171. if ( inPt.y === edgeLowPt.y ) {
  18172. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  18173. // continue; // no intersection or edgeLowPt => doesn't count !!!
  18174. } else {
  18175. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  18176. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  18177. if ( perpEdge < 0 ) continue;
  18178. inside = ! inside; // true intersection left of inPt
  18179. }
  18180. } else {
  18181. // parallel or collinear
  18182. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  18183. // edge lies on the same horizontal line as inPt
  18184. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  18185. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  18186. // continue;
  18187. }
  18188. }
  18189. return inside;
  18190. }
  18191. var subPaths = extractSubpaths( this.actions );
  18192. if ( subPaths.length === 0 ) return [];
  18193. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  18194. var solid, tmpPath, tmpShape, shapes = [];
  18195. if ( subPaths.length === 1 ) {
  18196. tmpPath = subPaths[ 0 ];
  18197. tmpShape = new THREE.Shape();
  18198. tmpShape.actions = tmpPath.actions;
  18199. tmpShape.curves = tmpPath.curves;
  18200. shapes.push( tmpShape );
  18201. return shapes;
  18202. }
  18203. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  18204. holesFirst = isCCW ? ! holesFirst : holesFirst;
  18205. // console.log("Holes first", holesFirst);
  18206. var betterShapeHoles = [];
  18207. var newShapes = [];
  18208. var newShapeHoles = [];
  18209. var mainIdx = 0;
  18210. var tmpPoints;
  18211. newShapes[ mainIdx ] = undefined;
  18212. newShapeHoles[ mainIdx ] = [];
  18213. var i, il;
  18214. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  18215. tmpPath = subPaths[ i ];
  18216. tmpPoints = tmpPath.getPoints();
  18217. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  18218. solid = isCCW ? ! solid : solid;
  18219. if ( solid ) {
  18220. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  18221. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  18222. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  18223. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  18224. if ( holesFirst ) mainIdx ++;
  18225. newShapeHoles[ mainIdx ] = [];
  18226. //console.log('cw', i);
  18227. } else {
  18228. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  18229. //console.log('ccw', i);
  18230. }
  18231. }
  18232. // only Holes? -> probably all Shapes with wrong orientation
  18233. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  18234. if ( newShapes.length > 1 ) {
  18235. var ambiguous = false;
  18236. var toChange = [];
  18237. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18238. betterShapeHoles[ sIdx ] = [];
  18239. }
  18240. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18241. var sho = newShapeHoles[ sIdx ];
  18242. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  18243. var ho = sho[ hIdx ];
  18244. var hole_unassigned = true;
  18245. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  18246. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  18247. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  18248. if ( hole_unassigned ) {
  18249. hole_unassigned = false;
  18250. betterShapeHoles[ s2Idx ].push( ho );
  18251. } else {
  18252. ambiguous = true;
  18253. }
  18254. }
  18255. }
  18256. if ( hole_unassigned ) {
  18257. betterShapeHoles[ sIdx ].push( ho );
  18258. }
  18259. }
  18260. }
  18261. // console.log("ambiguous: ", ambiguous);
  18262. if ( toChange.length > 0 ) {
  18263. // console.log("to change: ", toChange);
  18264. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  18265. }
  18266. }
  18267. var tmpHoles, j, jl;
  18268. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  18269. tmpShape = newShapes[ i ].s;
  18270. shapes.push( tmpShape );
  18271. tmpHoles = newShapeHoles[ i ];
  18272. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  18273. tmpShape.holes.push( tmpHoles[ j ].h );
  18274. }
  18275. }
  18276. //console.log("shape", shapes);
  18277. return shapes;
  18278. };
  18279. // File:src/extras/core/Shape.js
  18280. /**
  18281. * @author zz85 / http://www.lab4games.net/zz85/blog
  18282. * Defines a 2d shape plane using paths.
  18283. **/
  18284. // STEP 1 Create a path.
  18285. // STEP 2 Turn path into shape.
  18286. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  18287. // STEP 3a - Extract points from each shape, turn to vertices
  18288. // STEP 3b - Triangulate each shape, add faces.
  18289. THREE.Shape = function () {
  18290. THREE.Path.apply( this, arguments );
  18291. this.holes = [];
  18292. };
  18293. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  18294. THREE.Shape.prototype.constructor = THREE.Shape;
  18295. // Convenience method to return ExtrudeGeometry
  18296. THREE.Shape.prototype.extrude = function ( options ) {
  18297. var extruded = new THREE.ExtrudeGeometry( this, options );
  18298. return extruded;
  18299. };
  18300. // Convenience method to return ShapeGeometry
  18301. THREE.Shape.prototype.makeGeometry = function ( options ) {
  18302. var geometry = new THREE.ShapeGeometry( this, options );
  18303. return geometry;
  18304. };
  18305. // Get points of holes
  18306. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  18307. var i, il = this.holes.length, holesPts = [];
  18308. for ( i = 0; i < il; i ++ ) {
  18309. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  18310. }
  18311. return holesPts;
  18312. };
  18313. // Get points of holes (spaced by regular distance)
  18314. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  18315. var i, il = this.holes.length, holesPts = [];
  18316. for ( i = 0; i < il; i ++ ) {
  18317. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  18318. }
  18319. return holesPts;
  18320. };
  18321. // Get points of shape and holes (keypoints based on segments parameter)
  18322. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  18323. return {
  18324. shape: this.getTransformedPoints( divisions ),
  18325. holes: this.getPointsHoles( divisions )
  18326. };
  18327. };
  18328. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  18329. if ( this.useSpacedPoints ) {
  18330. return this.extractAllSpacedPoints( divisions );
  18331. }
  18332. return this.extractAllPoints( divisions );
  18333. };
  18334. //
  18335. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  18336. //
  18337. // return {
  18338. //
  18339. // shape: this.transform( bend, divisions ),
  18340. // holes: this.getPointsHoles( divisions, bend )
  18341. //
  18342. // };
  18343. //
  18344. // };
  18345. // Get points of shape and holes (spaced by regular distance)
  18346. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  18347. return {
  18348. shape: this.getTransformedSpacedPoints( divisions ),
  18349. holes: this.getSpacedPointsHoles( divisions )
  18350. };
  18351. };
  18352. /**************************************************************
  18353. * Utils
  18354. **************************************************************/
  18355. THREE.Shape.Utils = {
  18356. triangulateShape: function ( contour, holes ) {
  18357. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  18358. // inOtherPt needs to be collinear to the inSegment
  18359. if ( inSegPt1.x !== inSegPt2.x ) {
  18360. if ( inSegPt1.x < inSegPt2.x ) {
  18361. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  18362. } else {
  18363. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  18364. }
  18365. } else {
  18366. if ( inSegPt1.y < inSegPt2.y ) {
  18367. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  18368. } else {
  18369. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  18370. }
  18371. }
  18372. }
  18373. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  18374. var EPSILON = 0.0000000001;
  18375. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  18376. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  18377. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  18378. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  18379. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  18380. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  18381. if ( Math.abs( limit ) > EPSILON ) {
  18382. // not parallel
  18383. var perpSeg2;
  18384. if ( limit > 0 ) {
  18385. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  18386. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  18387. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  18388. } else {
  18389. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  18390. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  18391. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  18392. }
  18393. // i.e. to reduce rounding errors
  18394. // intersection at endpoint of segment#1?
  18395. if ( perpSeg2 === 0 ) {
  18396. if ( ( inExcludeAdjacentSegs ) &&
  18397. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  18398. return [ inSeg1Pt1 ];
  18399. }
  18400. if ( perpSeg2 === limit ) {
  18401. if ( ( inExcludeAdjacentSegs ) &&
  18402. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  18403. return [ inSeg1Pt2 ];
  18404. }
  18405. // intersection at endpoint of segment#2?
  18406. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  18407. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  18408. // return real intersection point
  18409. var factorSeg1 = perpSeg2 / limit;
  18410. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  18411. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  18412. } else {
  18413. // parallel or collinear
  18414. if ( ( perpSeg1 !== 0 ) ||
  18415. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  18416. // they are collinear or degenerate
  18417. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  18418. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  18419. // both segments are points
  18420. if ( seg1Pt && seg2Pt ) {
  18421. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  18422. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  18423. return [ inSeg1Pt1 ]; // they are the same point
  18424. }
  18425. // segment#1 is a single point
  18426. if ( seg1Pt ) {
  18427. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  18428. return [ inSeg1Pt1 ];
  18429. }
  18430. // segment#2 is a single point
  18431. if ( seg2Pt ) {
  18432. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  18433. return [ inSeg2Pt1 ];
  18434. }
  18435. // they are collinear segments, which might overlap
  18436. var seg1min, seg1max, seg1minVal, seg1maxVal;
  18437. var seg2min, seg2max, seg2minVal, seg2maxVal;
  18438. if ( seg1dx !== 0 ) {
  18439. // the segments are NOT on a vertical line
  18440. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  18441. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  18442. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  18443. } else {
  18444. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  18445. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  18446. }
  18447. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  18448. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  18449. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  18450. } else {
  18451. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  18452. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  18453. }
  18454. } else {
  18455. // the segments are on a vertical line
  18456. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  18457. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  18458. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  18459. } else {
  18460. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  18461. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  18462. }
  18463. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  18464. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  18465. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  18466. } else {
  18467. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  18468. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  18469. }
  18470. }
  18471. if ( seg1minVal <= seg2minVal ) {
  18472. if ( seg1maxVal < seg2minVal ) return [];
  18473. if ( seg1maxVal === seg2minVal ) {
  18474. if ( inExcludeAdjacentSegs ) return [];
  18475. return [ seg2min ];
  18476. }
  18477. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  18478. return [ seg2min, seg2max ];
  18479. } else {
  18480. if ( seg1minVal > seg2maxVal ) return [];
  18481. if ( seg1minVal === seg2maxVal ) {
  18482. if ( inExcludeAdjacentSegs ) return [];
  18483. return [ seg1min ];
  18484. }
  18485. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  18486. return [ seg1min, seg2max ];
  18487. }
  18488. }
  18489. }
  18490. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  18491. // The order of legs is important
  18492. var EPSILON = 0.0000000001;
  18493. // translation of all points, so that Vertex is at (0,0)
  18494. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  18495. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  18496. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  18497. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  18498. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  18499. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  18500. if ( Math.abs( from2toAngle ) > EPSILON ) {
  18501. // angle != 180 deg.
  18502. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  18503. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  18504. if ( from2toAngle > 0 ) {
  18505. // main angle < 180 deg.
  18506. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  18507. } else {
  18508. // main angle > 180 deg.
  18509. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  18510. }
  18511. } else {
  18512. // angle == 180 deg.
  18513. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  18514. return ( from2otherAngle > 0 );
  18515. }
  18516. }
  18517. function removeHoles( contour, holes ) {
  18518. var shape = contour.concat(); // work on this shape
  18519. var hole;
  18520. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  18521. // Check if hole point lies within angle around shape point
  18522. var lastShapeIdx = shape.length - 1;
  18523. var prevShapeIdx = inShapeIdx - 1;
  18524. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  18525. var nextShapeIdx = inShapeIdx + 1;
  18526. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  18527. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  18528. if ( ! insideAngle ) {
  18529. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  18530. return false;
  18531. }
  18532. // Check if shape point lies within angle around hole point
  18533. var lastHoleIdx = hole.length - 1;
  18534. var prevHoleIdx = inHoleIdx - 1;
  18535. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  18536. var nextHoleIdx = inHoleIdx + 1;
  18537. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  18538. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  18539. if ( ! insideAngle ) {
  18540. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  18541. return false;
  18542. }
  18543. return true;
  18544. }
  18545. function intersectsShapeEdge( inShapePt, inHolePt ) {
  18546. // checks for intersections with shape edges
  18547. var sIdx, nextIdx, intersection;
  18548. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  18549. nextIdx = sIdx + 1; nextIdx %= shape.length;
  18550. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  18551. if ( intersection.length > 0 ) return true;
  18552. }
  18553. return false;
  18554. }
  18555. var indepHoles = [];
  18556. function intersectsHoleEdge( inShapePt, inHolePt ) {
  18557. // checks for intersections with hole edges
  18558. var ihIdx, chkHole,
  18559. hIdx, nextIdx, intersection;
  18560. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  18561. chkHole = holes[ indepHoles[ ihIdx ]];
  18562. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  18563. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  18564. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  18565. if ( intersection.length > 0 ) return true;
  18566. }
  18567. }
  18568. return false;
  18569. }
  18570. var holeIndex, shapeIndex,
  18571. shapePt, holePt,
  18572. holeIdx, cutKey, failedCuts = [],
  18573. tmpShape1, tmpShape2,
  18574. tmpHole1, tmpHole2;
  18575. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18576. indepHoles.push( h );
  18577. }
  18578. var minShapeIndex = 0;
  18579. var counter = indepHoles.length * 2;
  18580. while ( indepHoles.length > 0 ) {
  18581. counter --;
  18582. if ( counter < 0 ) {
  18583. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  18584. break;
  18585. }
  18586. // search for shape-vertex and hole-vertex,
  18587. // which can be connected without intersections
  18588. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  18589. shapePt = shape[ shapeIndex ];
  18590. holeIndex = - 1;
  18591. // search for hole which can be reached without intersections
  18592. for ( var h = 0; h < indepHoles.length; h ++ ) {
  18593. holeIdx = indepHoles[ h ];
  18594. // prevent multiple checks
  18595. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  18596. if ( failedCuts[ cutKey ] !== undefined ) continue;
  18597. hole = holes[ holeIdx ];
  18598. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  18599. holePt = hole[ h2 ];
  18600. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  18601. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  18602. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  18603. holeIndex = h2;
  18604. indepHoles.splice( h, 1 );
  18605. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  18606. tmpShape2 = shape.slice( shapeIndex );
  18607. tmpHole1 = hole.slice( holeIndex );
  18608. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  18609. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  18610. minShapeIndex = shapeIndex;
  18611. // Debug only, to show the selected cuts
  18612. // glob_CutLines.push( [ shapePt, holePt ] );
  18613. break;
  18614. }
  18615. if ( holeIndex >= 0 ) break; // hole-vertex found
  18616. failedCuts[ cutKey ] = true; // remember failure
  18617. }
  18618. if ( holeIndex >= 0 ) break; // hole-vertex found
  18619. }
  18620. }
  18621. return shape; /* shape with no holes */
  18622. }
  18623. var i, il, f, face,
  18624. key, index,
  18625. allPointsMap = {};
  18626. // 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.
  18627. var allpoints = contour.concat();
  18628. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18629. Array.prototype.push.apply( allpoints, holes[ h ] );
  18630. }
  18631. //console.log( "allpoints",allpoints, allpoints.length );
  18632. // prepare all points map
  18633. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  18634. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  18635. if ( allPointsMap[ key ] !== undefined ) {
  18636. console.warn( "THREE.Shape: Duplicate point", key );
  18637. }
  18638. allPointsMap[ key ] = i;
  18639. }
  18640. // remove holes by cutting paths to holes and adding them to the shape
  18641. var shapeWithoutHoles = removeHoles( contour, holes );
  18642. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  18643. //console.log( "triangles",triangles, triangles.length );
  18644. // check all face vertices against all points map
  18645. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  18646. face = triangles[ i ];
  18647. for ( f = 0; f < 3; f ++ ) {
  18648. key = face[ f ].x + ":" + face[ f ].y;
  18649. index = allPointsMap[ key ];
  18650. if ( index !== undefined ) {
  18651. face[ f ] = index;
  18652. }
  18653. }
  18654. }
  18655. return triangles.concat();
  18656. },
  18657. isClockWise: function ( pts ) {
  18658. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  18659. },
  18660. // Bezier Curves formulas obtained from
  18661. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  18662. // Quad Bezier Functions
  18663. b2p0: function ( t, p ) {
  18664. var k = 1 - t;
  18665. return k * k * p;
  18666. },
  18667. b2p1: function ( t, p ) {
  18668. return 2 * ( 1 - t ) * t * p;
  18669. },
  18670. b2p2: function ( t, p ) {
  18671. return t * t * p;
  18672. },
  18673. b2: function ( t, p0, p1, p2 ) {
  18674. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  18675. },
  18676. // Cubic Bezier Functions
  18677. b3p0: function ( t, p ) {
  18678. var k = 1 - t;
  18679. return k * k * k * p;
  18680. },
  18681. b3p1: function ( t, p ) {
  18682. var k = 1 - t;
  18683. return 3 * k * k * t * p;
  18684. },
  18685. b3p2: function ( t, p ) {
  18686. var k = 1 - t;
  18687. return 3 * k * t * t * p;
  18688. },
  18689. b3p3: function ( t, p ) {
  18690. return t * t * t * p;
  18691. },
  18692. b3: function ( t, p0, p1, p2, p3 ) {
  18693. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  18694. }
  18695. };
  18696. // File:src/extras/curves/LineCurve.js
  18697. /**************************************************************
  18698. * Line
  18699. **************************************************************/
  18700. THREE.LineCurve = function ( v1, v2 ) {
  18701. this.v1 = v1;
  18702. this.v2 = v2;
  18703. };
  18704. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  18705. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  18706. THREE.LineCurve.prototype.getPoint = function ( t ) {
  18707. var point = this.v2.clone().sub( this.v1 );
  18708. point.multiplyScalar( t ).add( this.v1 );
  18709. return point;
  18710. };
  18711. // Line curve is linear, so we can overwrite default getPointAt
  18712. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  18713. return this.getPoint( u );
  18714. };
  18715. THREE.LineCurve.prototype.getTangent = function( t ) {
  18716. var tangent = this.v2.clone().sub( this.v1 );
  18717. return tangent.normalize();
  18718. };
  18719. // File:src/extras/curves/QuadraticBezierCurve.js
  18720. /**************************************************************
  18721. * Quadratic Bezier curve
  18722. **************************************************************/
  18723. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  18724. this.v0 = v0;
  18725. this.v1 = v1;
  18726. this.v2 = v2;
  18727. };
  18728. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18729. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  18730. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  18731. var vector = new THREE.Vector2();
  18732. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  18733. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  18734. return vector;
  18735. };
  18736. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  18737. var vector = new THREE.Vector2();
  18738. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  18739. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  18740. // returns unit vector
  18741. return vector.normalize();
  18742. };
  18743. // File:src/extras/curves/CubicBezierCurve.js
  18744. /**************************************************************
  18745. * Cubic Bezier curve
  18746. **************************************************************/
  18747. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  18748. this.v0 = v0;
  18749. this.v1 = v1;
  18750. this.v2 = v2;
  18751. this.v3 = v3;
  18752. };
  18753. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18754. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  18755. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  18756. var tx, ty;
  18757. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18758. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18759. return new THREE.Vector2( tx, ty );
  18760. };
  18761. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  18762. var tx, ty;
  18763. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18764. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18765. var tangent = new THREE.Vector2( tx, ty );
  18766. tangent.normalize();
  18767. return tangent;
  18768. };
  18769. // File:src/extras/curves/SplineCurve.js
  18770. /**************************************************************
  18771. * Spline curve
  18772. **************************************************************/
  18773. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  18774. this.points = ( points == undefined ) ? [] : points;
  18775. };
  18776. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  18777. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  18778. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  18779. var points = this.points;
  18780. var point = ( points.length - 1 ) * t;
  18781. var intPoint = Math.floor( point );
  18782. var weight = point - intPoint;
  18783. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  18784. var point1 = points[ intPoint ];
  18785. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18786. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18787. var vector = new THREE.Vector2();
  18788. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  18789. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  18790. return vector;
  18791. };
  18792. // File:src/extras/curves/EllipseCurve.js
  18793. /**************************************************************
  18794. * Ellipse curve
  18795. **************************************************************/
  18796. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18797. this.aX = aX;
  18798. this.aY = aY;
  18799. this.xRadius = xRadius;
  18800. this.yRadius = yRadius;
  18801. this.aStartAngle = aStartAngle;
  18802. this.aEndAngle = aEndAngle;
  18803. this.aClockwise = aClockwise;
  18804. this.aRotation = aRotation || 0;
  18805. };
  18806. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  18807. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  18808. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  18809. var deltaAngle = this.aEndAngle - this.aStartAngle;
  18810. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  18811. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  18812. var angle;
  18813. if ( this.aClockwise === true ) {
  18814. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  18815. } else {
  18816. angle = this.aStartAngle + t * deltaAngle;
  18817. }
  18818. var x = this.aX + this.xRadius * Math.cos( angle );
  18819. var y = this.aY + this.yRadius * Math.sin( angle );
  18820. if ( this.aRotation !== 0 ) {
  18821. var cos = Math.cos( this.aRotation );
  18822. var sin = Math.sin( this.aRotation );
  18823. var tx = x, ty = y;
  18824. // Rotate the point about the center of the ellipse.
  18825. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  18826. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  18827. }
  18828. return new THREE.Vector2( x, y );
  18829. };
  18830. // File:src/extras/curves/ArcCurve.js
  18831. /**************************************************************
  18832. * Arc curve
  18833. **************************************************************/
  18834. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18835. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  18836. };
  18837. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  18838. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  18839. // File:src/extras/curves/LineCurve3.js
  18840. /**************************************************************
  18841. * Line3D
  18842. **************************************************************/
  18843. THREE.LineCurve3 = THREE.Curve.create(
  18844. function ( v1, v2 ) {
  18845. this.v1 = v1;
  18846. this.v2 = v2;
  18847. },
  18848. function ( t ) {
  18849. var vector = new THREE.Vector3();
  18850. vector.subVectors( this.v2, this.v1 ); // diff
  18851. vector.multiplyScalar( t );
  18852. vector.add( this.v1 );
  18853. return vector;
  18854. }
  18855. );
  18856. // File:src/extras/curves/QuadraticBezierCurve3.js
  18857. /**************************************************************
  18858. * Quadratic Bezier 3D curve
  18859. **************************************************************/
  18860. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  18861. function ( v0, v1, v2 ) {
  18862. this.v0 = v0;
  18863. this.v1 = v1;
  18864. this.v2 = v2;
  18865. },
  18866. function ( t ) {
  18867. var vector = new THREE.Vector3();
  18868. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  18869. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  18870. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  18871. return vector;
  18872. }
  18873. );
  18874. // File:src/extras/curves/CubicBezierCurve3.js
  18875. /**************************************************************
  18876. * Cubic Bezier 3D curve
  18877. **************************************************************/
  18878. THREE.CubicBezierCurve3 = THREE.Curve.create(
  18879. function ( v0, v1, v2, v3 ) {
  18880. this.v0 = v0;
  18881. this.v1 = v1;
  18882. this.v2 = v2;
  18883. this.v3 = v3;
  18884. },
  18885. function ( t ) {
  18886. var vector = new THREE.Vector3();
  18887. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18888. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18889. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  18890. return vector;
  18891. }
  18892. );
  18893. // File:src/extras/curves/SplineCurve3.js
  18894. /**************************************************************
  18895. * Spline 3D curve
  18896. **************************************************************/
  18897. THREE.SplineCurve3 = THREE.Curve.create(
  18898. function ( points /* array of Vector3 */ ) {
  18899. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  18900. this.points = ( points == undefined ) ? [] : points;
  18901. },
  18902. function ( t ) {
  18903. var points = this.points;
  18904. var point = ( points.length - 1 ) * t;
  18905. var intPoint = Math.floor( point );
  18906. var weight = point - intPoint;
  18907. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  18908. var point1 = points[ intPoint ];
  18909. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18910. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18911. var vector = new THREE.Vector3();
  18912. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  18913. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  18914. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  18915. return vector;
  18916. }
  18917. );
  18918. // File:src/extras/curves/CatmullRomCurve3.js
  18919. /**
  18920. * @author zz85 https://github.com/zz85
  18921. *
  18922. * Centripetal CatmullRom Curve - which is useful for avoiding
  18923. * cusps and self-intersections in non-uniform catmull rom curves.
  18924. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18925. *
  18926. * curve.type accepts centripetal(default), chordal and catmullrom
  18927. * curve.tension is used for catmullrom which defaults to 0.5
  18928. */
  18929. THREE.CatmullRomCurve3 = ( function() {
  18930. var
  18931. tmp = new THREE.Vector3(),
  18932. px = new CubicPoly(),
  18933. py = new CubicPoly(),
  18934. pz = new CubicPoly();
  18935. /*
  18936. Based on an optimized c++ solution in
  18937. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  18938. - http://ideone.com/NoEbVM
  18939. This CubicPoly class could be used for reusing some variables and calculations,
  18940. but for three.js curve use, it could be possible inlined and flatten into a single function call
  18941. which can be placed in CurveUtils.
  18942. */
  18943. function CubicPoly() {
  18944. }
  18945. /*
  18946. * Compute coefficients for a cubic polynomial
  18947. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18948. * such that
  18949. * p(0) = x0, p(1) = x1
  18950. * and
  18951. * p'(0) = t0, p'(1) = t1.
  18952. */
  18953. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  18954. this.c0 = x0;
  18955. this.c1 = t0;
  18956. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18957. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18958. };
  18959. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18960. // compute tangents when parameterized in [t1,t2]
  18961. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18962. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18963. // rescale tangents for parametrization in [0,1]
  18964. t1 *= dt1;
  18965. t2 *= dt1;
  18966. // initCubicPoly
  18967. this.init( x1, x2, t1, t2 );
  18968. };
  18969. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  18970. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  18971. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18972. };
  18973. CubicPoly.prototype.calc = function( t ) {
  18974. var t2 = t * t;
  18975. var t3 = t2 * t;
  18976. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  18977. };
  18978. // Subclass Three.js curve
  18979. return THREE.Curve.create(
  18980. function ( p /* array of Vector3 */ ) {
  18981. this.points = p || [];
  18982. },
  18983. function ( t ) {
  18984. var points = this.points,
  18985. point, intPoint, weight, l;
  18986. l = points.length;
  18987. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  18988. point = ( l - 1 ) * t;
  18989. intPoint = Math.floor( point );
  18990. weight = point - intPoint;
  18991. if ( weight === 0 && intPoint === l - 1 ) {
  18992. intPoint = l - 2;
  18993. weight = 1;
  18994. }
  18995. var p0, p1, p2, p3;
  18996. if ( intPoint === 0 ) {
  18997. // extrapolate first point
  18998. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  18999. p0 = tmp;
  19000. } else {
  19001. p0 = points[ intPoint - 1 ];
  19002. }
  19003. p1 = points[ intPoint ];
  19004. p2 = points[ intPoint + 1 ];
  19005. if ( intPoint + 2 < l ) {
  19006. p3 = points[ intPoint + 2 ]
  19007. } else {
  19008. // extrapolate last point
  19009. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  19010. p3 = tmp;
  19011. }
  19012. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  19013. // init Centripetal / Chordal Catmull-Rom
  19014. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  19015. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  19016. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  19017. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  19018. // safety check for repeated points
  19019. if ( dt1 < 1e-4 ) dt1 = 1.0;
  19020. if ( dt0 < 1e-4 ) dt0 = dt1;
  19021. if ( dt2 < 1e-4 ) dt2 = dt1;
  19022. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  19023. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  19024. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  19025. } else if ( this.type === 'catmullrom' ) {
  19026. var tension = this.tension !== undefined ? this.tension : 0.5;
  19027. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  19028. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  19029. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  19030. }
  19031. var v = new THREE.Vector3(
  19032. px.calc( weight ),
  19033. py.calc( weight ),
  19034. pz.calc( weight )
  19035. );
  19036. return v;
  19037. }
  19038. );
  19039. } )();
  19040. // File:src/extras/curves/ClosedSplineCurve3.js
  19041. /**************************************************************
  19042. * Closed Spline 3D curve
  19043. **************************************************************/
  19044. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  19045. function ( points /* array of Vector3 */ ) {
  19046. this.points = ( points == undefined ) ? [] : points;
  19047. },
  19048. function ( t ) {
  19049. var points = this.points;
  19050. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  19051. var intPoint = Math.floor( point );
  19052. var weight = point - intPoint;
  19053. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  19054. var point0 = points[ ( intPoint - 1 ) % points.length ];
  19055. var point1 = points[ ( intPoint ) % points.length ];
  19056. var point2 = points[ ( intPoint + 1 ) % points.length ];
  19057. var point3 = points[ ( intPoint + 2 ) % points.length ];
  19058. var vector = new THREE.Vector3();
  19059. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  19060. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  19061. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  19062. return vector;
  19063. }
  19064. );
  19065. // File:src/extras/geometries/BoxGeometry.js
  19066. /**
  19067. * @author mrdoob / http://mrdoob.com/
  19068. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  19069. */
  19070. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  19071. THREE.Geometry.call( this );
  19072. this.type = 'BoxGeometry';
  19073. this.parameters = {
  19074. width: width,
  19075. height: height,
  19076. depth: depth,
  19077. widthSegments: widthSegments,
  19078. heightSegments: heightSegments,
  19079. depthSegments: depthSegments
  19080. };
  19081. this.widthSegments = widthSegments || 1;
  19082. this.heightSegments = heightSegments || 1;
  19083. this.depthSegments = depthSegments || 1;
  19084. var scope = this;
  19085. var width_half = width / 2;
  19086. var height_half = height / 2;
  19087. var depth_half = depth / 2;
  19088. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  19089. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  19090. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  19091. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  19092. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  19093. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  19094. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  19095. var w, ix, iy,
  19096. gridX = scope.widthSegments,
  19097. gridY = scope.heightSegments,
  19098. width_half = width / 2,
  19099. height_half = height / 2,
  19100. offset = scope.vertices.length;
  19101. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  19102. w = 'z';
  19103. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  19104. w = 'y';
  19105. gridY = scope.depthSegments;
  19106. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  19107. w = 'x';
  19108. gridX = scope.depthSegments;
  19109. }
  19110. var gridX1 = gridX + 1,
  19111. gridY1 = gridY + 1,
  19112. segment_width = width / gridX,
  19113. segment_height = height / gridY,
  19114. normal = new THREE.Vector3();
  19115. normal[ w ] = depth > 0 ? 1 : - 1;
  19116. for ( iy = 0; iy < gridY1; iy ++ ) {
  19117. for ( ix = 0; ix < gridX1; ix ++ ) {
  19118. var vector = new THREE.Vector3();
  19119. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  19120. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  19121. vector[ w ] = depth;
  19122. scope.vertices.push( vector );
  19123. }
  19124. }
  19125. for ( iy = 0; iy < gridY; iy ++ ) {
  19126. for ( ix = 0; ix < gridX; ix ++ ) {
  19127. var a = ix + gridX1 * iy;
  19128. var b = ix + gridX1 * ( iy + 1 );
  19129. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19130. var d = ( ix + 1 ) + gridX1 * iy;
  19131. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  19132. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  19133. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  19134. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  19135. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  19136. face.normal.copy( normal );
  19137. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  19138. face.materialIndex = materialIndex;
  19139. scope.faces.push( face );
  19140. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19141. face = new THREE.Face3( b + offset, c + offset, d + offset );
  19142. face.normal.copy( normal );
  19143. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  19144. face.materialIndex = materialIndex;
  19145. scope.faces.push( face );
  19146. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19147. }
  19148. }
  19149. }
  19150. this.mergeVertices();
  19151. };
  19152. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19153. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  19154. THREE.BoxGeometry.prototype.clone = function () {
  19155. var geometry = new THREE.BoxGeometry(
  19156. this.parameters.width,
  19157. this.parameters.height,
  19158. this.parameters.depth,
  19159. this.parameters.widthSegments,
  19160. this.parameters.heightSegments,
  19161. this.parameters.depthSegments
  19162. );
  19163. return geometry;
  19164. };
  19165. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  19166. // File:src/extras/geometries/CircleGeometry.js
  19167. /**
  19168. * @author hughes
  19169. */
  19170. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  19171. THREE.Geometry.call( this );
  19172. this.type = 'CircleGeometry';
  19173. this.parameters = {
  19174. radius: radius,
  19175. segments: segments,
  19176. thetaStart: thetaStart,
  19177. thetaLength: thetaLength
  19178. };
  19179. radius = radius || 50;
  19180. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19181. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19182. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19183. var i, uvs = [],
  19184. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  19185. this.vertices.push( center );
  19186. uvs.push( centerUV );
  19187. for ( i = 0; i <= segments; i ++ ) {
  19188. var vertex = new THREE.Vector3();
  19189. var segment = thetaStart + i / segments * thetaLength;
  19190. vertex.x = radius * Math.cos( segment );
  19191. vertex.y = radius * Math.sin( segment );
  19192. this.vertices.push( vertex );
  19193. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  19194. }
  19195. var n = new THREE.Vector3( 0, 0, 1 );
  19196. for ( i = 1; i <= segments; i ++ ) {
  19197. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  19198. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  19199. }
  19200. this.computeFaceNormals();
  19201. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19202. };
  19203. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19204. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  19205. THREE.CircleGeometry.prototype.clone = function () {
  19206. var geometry = new THREE.CircleGeometry(
  19207. this.parameters.radius,
  19208. this.parameters.segments,
  19209. this.parameters.thetaStart,
  19210. this.parameters.thetaLength
  19211. );
  19212. return geometry;
  19213. };
  19214. // File:src/extras/geometries/CircleBufferGeometry.js
  19215. /**
  19216. * @author benaadams / https://twitter.com/ben_a_adams
  19217. */
  19218. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  19219. THREE.BufferGeometry.call( this );
  19220. this.type = 'CircleBufferGeometry';
  19221. this.parameters = {
  19222. radius: radius,
  19223. segments: segments,
  19224. thetaStart: thetaStart,
  19225. thetaLength: thetaLength
  19226. };
  19227. radius = radius || 50;
  19228. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19229. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19230. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19231. var vertices = segments + 2;
  19232. var positions = new Float32Array( vertices * 3 );
  19233. var normals = new Float32Array( vertices * 3 );
  19234. var uvs = new Float32Array( vertices * 2 );
  19235. // center data is already zero, but need to set a few extras
  19236. normals[ 2 ] = 1.0;
  19237. uvs[ 0 ] = 0.5;
  19238. uvs[ 1 ] = 0.5;
  19239. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  19240. var segment = thetaStart + s / segments * thetaLength;
  19241. positions[ i ] = radius * Math.cos( segment );
  19242. positions[ i + 1 ] = radius * Math.sin( segment );
  19243. normals[ i + 2 ] = 1; // normal z
  19244. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  19245. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  19246. }
  19247. var indices = [];
  19248. for ( var i = 1; i <= segments; i ++ ) {
  19249. indices.push( i );
  19250. indices.push( i + 1 );
  19251. indices.push( 0 );
  19252. }
  19253. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19254. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  19255. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19256. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19257. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19258. };
  19259. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19260. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  19261. THREE.CircleBufferGeometry.prototype.clone = function () {
  19262. var geometry = new THREE.CircleBufferGeometry(
  19263. this.parameters.radius,
  19264. this.parameters.segments,
  19265. this.parameters.thetaStart,
  19266. this.parameters.thetaLength
  19267. );
  19268. geometry.copy( this );
  19269. return geometry;
  19270. };
  19271. // File:src/extras/geometries/CylinderGeometry.js
  19272. /**
  19273. * @author mrdoob / http://mrdoob.com/
  19274. */
  19275. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19276. THREE.Geometry.call( this );
  19277. this.type = 'CylinderGeometry';
  19278. this.parameters = {
  19279. radiusTop: radiusTop,
  19280. radiusBottom: radiusBottom,
  19281. height: height,
  19282. radialSegments: radialSegments,
  19283. heightSegments: heightSegments,
  19284. openEnded: openEnded,
  19285. thetaStart: thetaStart,
  19286. thetaLength: thetaLength
  19287. };
  19288. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  19289. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  19290. height = height !== undefined ? height : 100;
  19291. radialSegments = radialSegments || 8;
  19292. heightSegments = heightSegments || 1;
  19293. openEnded = openEnded !== undefined ? openEnded : false;
  19294. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19295. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  19296. var heightHalf = height / 2;
  19297. var x, y, vertices = [], uvs = [];
  19298. for ( y = 0; y <= heightSegments; y ++ ) {
  19299. var verticesRow = [];
  19300. var uvsRow = [];
  19301. var v = y / heightSegments;
  19302. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  19303. for ( x = 0; x <= radialSegments; x ++ ) {
  19304. var u = x / radialSegments;
  19305. var vertex = new THREE.Vector3();
  19306. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  19307. vertex.y = - v * height + heightHalf;
  19308. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  19309. this.vertices.push( vertex );
  19310. verticesRow.push( this.vertices.length - 1 );
  19311. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19312. }
  19313. vertices.push( verticesRow );
  19314. uvs.push( uvsRow );
  19315. }
  19316. var tanTheta = ( radiusBottom - radiusTop ) / height;
  19317. var na, nb;
  19318. for ( x = 0; x < radialSegments; x ++ ) {
  19319. if ( radiusTop !== 0 ) {
  19320. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  19321. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  19322. } else {
  19323. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  19324. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  19325. }
  19326. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  19327. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  19328. for ( y = 0; y < heightSegments; y ++ ) {
  19329. var v1 = vertices[ y ][ x ];
  19330. var v2 = vertices[ y + 1 ][ x ];
  19331. var v3 = vertices[ y + 1 ][ x + 1 ];
  19332. var v4 = vertices[ y ][ x + 1 ];
  19333. var n1 = na.clone();
  19334. var n2 = na.clone();
  19335. var n3 = nb.clone();
  19336. var n4 = nb.clone();
  19337. var uv1 = uvs[ y ][ x ].clone();
  19338. var uv2 = uvs[ y + 1 ][ x ].clone();
  19339. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  19340. var uv4 = uvs[ y ][ x + 1 ].clone();
  19341. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19342. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19343. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19344. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19345. }
  19346. }
  19347. // top cap
  19348. if ( openEnded === false && radiusTop > 0 ) {
  19349. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  19350. for ( x = 0; x < radialSegments; x ++ ) {
  19351. var v1 = vertices[ 0 ][ x ];
  19352. var v2 = vertices[ 0 ][ x + 1 ];
  19353. var v3 = this.vertices.length - 1;
  19354. var n1 = new THREE.Vector3( 0, 1, 0 );
  19355. var n2 = new THREE.Vector3( 0, 1, 0 );
  19356. var n3 = new THREE.Vector3( 0, 1, 0 );
  19357. var uv1 = uvs[ 0 ][ x ].clone();
  19358. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  19359. var uv3 = new THREE.Vector2( uv2.x, 0 );
  19360. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  19361. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19362. }
  19363. }
  19364. // bottom cap
  19365. if ( openEnded === false && radiusBottom > 0 ) {
  19366. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  19367. for ( x = 0; x < radialSegments; x ++ ) {
  19368. var v1 = vertices[ heightSegments ][ x + 1 ];
  19369. var v2 = vertices[ heightSegments ][ x ];
  19370. var v3 = this.vertices.length - 1;
  19371. var n1 = new THREE.Vector3( 0, - 1, 0 );
  19372. var n2 = new THREE.Vector3( 0, - 1, 0 );
  19373. var n3 = new THREE.Vector3( 0, - 1, 0 );
  19374. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  19375. var uv2 = uvs[ heightSegments ][ x ].clone();
  19376. var uv3 = new THREE.Vector2( uv2.x, 1 );
  19377. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  19378. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19379. }
  19380. }
  19381. this.computeFaceNormals();
  19382. };
  19383. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19384. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  19385. THREE.CylinderGeometry.prototype.clone = function () {
  19386. var geometry = new THREE.CylinderGeometry(
  19387. this.parameters.radiusTop,
  19388. this.parameters.radiusBottom,
  19389. this.parameters.height,
  19390. this.parameters.radialSegments,
  19391. this.parameters.heightSegments,
  19392. this.parameters.openEnded,
  19393. this.parameters.thetaStart,
  19394. this.parameters.thetaLength
  19395. );
  19396. return geometry;
  19397. };
  19398. // File:src/extras/geometries/EdgesGeometry.js
  19399. /**
  19400. * @author WestLangley / http://github.com/WestLangley
  19401. */
  19402. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  19403. THREE.BufferGeometry.call( this );
  19404. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  19405. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  19406. var edge = [ 0, 0 ], hash = {};
  19407. function sortFunction( a, b ) {
  19408. return a - b;
  19409. }
  19410. var keys = [ 'a', 'b', 'c' ];
  19411. var geometry2;
  19412. if ( geometry instanceof THREE.BufferGeometry ) {
  19413. geometry2 = new THREE.Geometry();
  19414. geometry2.fromBufferGeometry( geometry );
  19415. } else {
  19416. geometry2 = geometry.clone();
  19417. }
  19418. geometry2.mergeVertices();
  19419. geometry2.computeFaceNormals();
  19420. var vertices = geometry2.vertices;
  19421. var faces = geometry2.faces;
  19422. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19423. var face = faces[ i ];
  19424. for ( var j = 0; j < 3; j ++ ) {
  19425. edge[ 0 ] = face[ keys[ j ] ];
  19426. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  19427. edge.sort( sortFunction );
  19428. var key = edge.toString();
  19429. if ( hash[ key ] === undefined ) {
  19430. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  19431. } else {
  19432. hash[ key ].face2 = i;
  19433. }
  19434. }
  19435. }
  19436. var coords = [];
  19437. for ( var key in hash ) {
  19438. var h = hash[ key ];
  19439. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  19440. var vertex = vertices[ h.vert1 ];
  19441. coords.push( vertex.x );
  19442. coords.push( vertex.y );
  19443. coords.push( vertex.z );
  19444. vertex = vertices[ h.vert2 ];
  19445. coords.push( vertex.x );
  19446. coords.push( vertex.y );
  19447. coords.push( vertex.z );
  19448. }
  19449. }
  19450. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  19451. };
  19452. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19453. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  19454. // File:src/extras/geometries/ExtrudeGeometry.js
  19455. /**
  19456. * @author zz85 / http://www.lab4games.net/zz85/blog
  19457. *
  19458. * Creates extruded geometry from a path shape.
  19459. *
  19460. * parameters = {
  19461. *
  19462. * curveSegments: <int>, // number of points on the curves
  19463. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  19464. * amount: <int>, // Depth to extrude the shape
  19465. *
  19466. * bevelEnabled: <bool>, // turn on bevel
  19467. * bevelThickness: <float>, // how deep into the original shape bevel goes
  19468. * bevelSize: <float>, // how far from shape outline is bevel
  19469. * bevelSegments: <int>, // number of bevel layers
  19470. *
  19471. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  19472. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  19473. *
  19474. * uvGenerator: <Object> // object that provides UV generator functions
  19475. *
  19476. * }
  19477. **/
  19478. THREE.ExtrudeGeometry = function ( shapes, options ) {
  19479. if ( typeof( shapes ) === "undefined" ) {
  19480. shapes = [];
  19481. return;
  19482. }
  19483. THREE.Geometry.call( this );
  19484. this.type = 'ExtrudeGeometry';
  19485. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  19486. this.addShapeList( shapes, options );
  19487. this.computeFaceNormals();
  19488. // can't really use automatic vertex normals
  19489. // as then front and back sides get smoothed too
  19490. // should do separate smoothing just for sides
  19491. //this.computeVertexNormals();
  19492. //console.log( "took", ( Date.now() - startTime ) );
  19493. };
  19494. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19495. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  19496. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19497. var sl = shapes.length;
  19498. for ( var s = 0; s < sl; s ++ ) {
  19499. var shape = shapes[ s ];
  19500. this.addShape( shape, options );
  19501. }
  19502. };
  19503. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  19504. var amount = options.amount !== undefined ? options.amount : 100;
  19505. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  19506. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  19507. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  19508. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  19509. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19510. var steps = options.steps !== undefined ? options.steps : 1;
  19511. var extrudePath = options.extrudePath;
  19512. var extrudePts, extrudeByPath = false;
  19513. // Use default WorldUVGenerator if no UV generators are specified.
  19514. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  19515. var splineTube, binormal, normal, position2;
  19516. if ( extrudePath ) {
  19517. extrudePts = extrudePath.getSpacedPoints( steps );
  19518. extrudeByPath = true;
  19519. bevelEnabled = false; // bevels not supported for path extrusion
  19520. // SETUP TNB variables
  19521. // Reuse TNB from TubeGeomtry for now.
  19522. // TODO1 - have a .isClosed in spline?
  19523. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  19524. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  19525. binormal = new THREE.Vector3();
  19526. normal = new THREE.Vector3();
  19527. position2 = new THREE.Vector3();
  19528. }
  19529. // Safeguards if bevels are not enabled
  19530. if ( ! bevelEnabled ) {
  19531. bevelSegments = 0;
  19532. bevelThickness = 0;
  19533. bevelSize = 0;
  19534. }
  19535. // Variables initialization
  19536. var ahole, h, hl; // looping of holes
  19537. var scope = this;
  19538. var shapesOffset = this.vertices.length;
  19539. var shapePoints = shape.extractPoints( curveSegments );
  19540. var vertices = shapePoints.shape;
  19541. var holes = shapePoints.holes;
  19542. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19543. if ( reverse ) {
  19544. vertices = vertices.reverse();
  19545. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  19546. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19547. ahole = holes[ h ];
  19548. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  19549. holes[ h ] = ahole.reverse();
  19550. }
  19551. }
  19552. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  19553. }
  19554. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  19555. /* Vertices */
  19556. var contour = vertices; // vertices has all points but contour has only points of circumference
  19557. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19558. ahole = holes[ h ];
  19559. vertices = vertices.concat( ahole );
  19560. }
  19561. function scalePt2 ( pt, vec, size ) {
  19562. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  19563. return vec.clone().multiplyScalar( size ).add( pt );
  19564. }
  19565. var b, bs, t, z,
  19566. vert, vlen = vertices.length,
  19567. face, flen = faces.length;
  19568. // Find directions for point movement
  19569. function getBevelVec( inPt, inPrev, inNext ) {
  19570. var EPSILON = 0.0000000001;
  19571. // computes for inPt the corresponding point inPt' on a new contour
  19572. // shifted by 1 unit (length of normalized vector) to the left
  19573. // if we walk along contour clockwise, this new contour is outside the old one
  19574. //
  19575. // inPt' is the intersection of the two lines parallel to the two
  19576. // adjacent edges of inPt at a distance of 1 unit on the left side.
  19577. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  19578. // good reading for geometry algorithms (here: line-line intersection)
  19579. // http://geomalgorithms.com/a05-_intersect-1.html
  19580. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  19581. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  19582. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  19583. // check for collinear edges
  19584. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19585. if ( Math.abs( collinear0 ) > EPSILON ) {
  19586. // not collinear
  19587. // length of vectors for normalizing
  19588. var v_prev_len = Math.sqrt( v_prev_lensq );
  19589. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  19590. // shift adjacent points by unit vectors to the left
  19591. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  19592. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  19593. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  19594. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  19595. // scaling factor for v_prev to intersection point
  19596. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  19597. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  19598. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19599. // vector from inPt to intersection point
  19600. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  19601. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  19602. // Don't normalize!, otherwise sharp corners become ugly
  19603. // but prevent crazy spikes
  19604. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  19605. if ( v_trans_lensq <= 2 ) {
  19606. return new THREE.Vector2( v_trans_x, v_trans_y );
  19607. } else {
  19608. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  19609. }
  19610. } else {
  19611. // handle special case of collinear edges
  19612. var direction_eq = false; // assumes: opposite
  19613. if ( v_prev_x > EPSILON ) {
  19614. if ( v_next_x > EPSILON ) {
  19615. direction_eq = true;
  19616. }
  19617. } else {
  19618. if ( v_prev_x < - EPSILON ) {
  19619. if ( v_next_x < - EPSILON ) {
  19620. direction_eq = true;
  19621. }
  19622. } else {
  19623. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  19624. direction_eq = true;
  19625. }
  19626. }
  19627. }
  19628. if ( direction_eq ) {
  19629. // console.log("Warning: lines are a straight sequence");
  19630. v_trans_x = - v_prev_y;
  19631. v_trans_y = v_prev_x;
  19632. shrink_by = Math.sqrt( v_prev_lensq );
  19633. } else {
  19634. // console.log("Warning: lines are a straight spike");
  19635. v_trans_x = v_prev_x;
  19636. v_trans_y = v_prev_y;
  19637. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  19638. }
  19639. }
  19640. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  19641. }
  19642. var contourMovements = [];
  19643. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19644. if ( j === il ) j = 0;
  19645. if ( k === il ) k = 0;
  19646. // (j)---(i)---(k)
  19647. // console.log('i,j,k', i, j , k)
  19648. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  19649. }
  19650. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  19651. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19652. ahole = holes[ h ];
  19653. oneHoleMovements = [];
  19654. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19655. if ( j === il ) j = 0;
  19656. if ( k === il ) k = 0;
  19657. // (j)---(i)---(k)
  19658. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  19659. }
  19660. holesMovements.push( oneHoleMovements );
  19661. verticesMovements = verticesMovements.concat( oneHoleMovements );
  19662. }
  19663. // Loop bevelSegments, 1 for the front, 1 for the back
  19664. for ( b = 0; b < bevelSegments; b ++ ) {
  19665. //for ( b = bevelSegments; b > 0; b -- ) {
  19666. t = b / bevelSegments;
  19667. z = bevelThickness * ( 1 - t );
  19668. //z = bevelThickness * t;
  19669. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  19670. //bs = bevelSize * t; // linear
  19671. // contract shape
  19672. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19673. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19674. v( vert.x, vert.y, - z );
  19675. }
  19676. // expand holes
  19677. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19678. ahole = holes[ h ];
  19679. oneHoleMovements = holesMovements[ h ];
  19680. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19681. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19682. v( vert.x, vert.y, - z );
  19683. }
  19684. }
  19685. }
  19686. bs = bevelSize;
  19687. // Back facing vertices
  19688. for ( i = 0; i < vlen; i ++ ) {
  19689. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19690. if ( ! extrudeByPath ) {
  19691. v( vert.x, vert.y, 0 );
  19692. } else {
  19693. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  19694. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  19695. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  19696. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  19697. v( position2.x, position2.y, position2.z );
  19698. }
  19699. }
  19700. // Add stepped vertices...
  19701. // Including front facing vertices
  19702. var s;
  19703. for ( s = 1; s <= steps; s ++ ) {
  19704. for ( i = 0; i < vlen; i ++ ) {
  19705. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19706. if ( ! extrudeByPath ) {
  19707. v( vert.x, vert.y, amount / steps * s );
  19708. } else {
  19709. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  19710. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  19711. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  19712. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  19713. v( position2.x, position2.y, position2.z );
  19714. }
  19715. }
  19716. }
  19717. // Add bevel segments planes
  19718. //for ( b = 1; b <= bevelSegments; b ++ ) {
  19719. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  19720. t = b / bevelSegments;
  19721. z = bevelThickness * ( 1 - t );
  19722. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  19723. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  19724. // contract shape
  19725. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19726. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19727. v( vert.x, vert.y, amount + z );
  19728. }
  19729. // expand holes
  19730. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19731. ahole = holes[ h ];
  19732. oneHoleMovements = holesMovements[ h ];
  19733. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19734. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19735. if ( ! extrudeByPath ) {
  19736. v( vert.x, vert.y, amount + z );
  19737. } else {
  19738. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19739. }
  19740. }
  19741. }
  19742. }
  19743. /* Faces */
  19744. // Top and bottom faces
  19745. buildLidFaces();
  19746. // Sides faces
  19747. buildSideFaces();
  19748. ///// Internal functions
  19749. function buildLidFaces() {
  19750. if ( bevelEnabled ) {
  19751. var layer = 0; // steps + 1
  19752. var offset = vlen * layer;
  19753. // Bottom faces
  19754. for ( i = 0; i < flen; i ++ ) {
  19755. face = faces[ i ];
  19756. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19757. }
  19758. layer = steps + bevelSegments * 2;
  19759. offset = vlen * layer;
  19760. // Top faces
  19761. for ( i = 0; i < flen; i ++ ) {
  19762. face = faces[ i ];
  19763. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19764. }
  19765. } else {
  19766. // Bottom faces
  19767. for ( i = 0; i < flen; i ++ ) {
  19768. face = faces[ i ];
  19769. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19770. }
  19771. // Top faces
  19772. for ( i = 0; i < flen; i ++ ) {
  19773. face = faces[ i ];
  19774. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19775. }
  19776. }
  19777. }
  19778. // Create faces for the z-sides of the shape
  19779. function buildSideFaces() {
  19780. var layeroffset = 0;
  19781. sidewalls( contour, layeroffset );
  19782. layeroffset += contour.length;
  19783. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19784. ahole = holes[ h ];
  19785. sidewalls( ahole, layeroffset );
  19786. //, true
  19787. layeroffset += ahole.length;
  19788. }
  19789. }
  19790. function sidewalls( contour, layeroffset ) {
  19791. var j, k;
  19792. i = contour.length;
  19793. while ( -- i >= 0 ) {
  19794. j = i;
  19795. k = i - 1;
  19796. if ( k < 0 ) k = contour.length - 1;
  19797. //console.log('b', i,j, i-1, k,vertices.length);
  19798. var s = 0, sl = steps + bevelSegments * 2;
  19799. for ( s = 0; s < sl; s ++ ) {
  19800. var slen1 = vlen * s;
  19801. var slen2 = vlen * ( s + 1 );
  19802. var a = layeroffset + j + slen1,
  19803. b = layeroffset + k + slen1,
  19804. c = layeroffset + k + slen2,
  19805. d = layeroffset + j + slen2;
  19806. f4( a, b, c, d, contour, s, sl, j, k );
  19807. }
  19808. }
  19809. }
  19810. function v( x, y, z ) {
  19811. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  19812. }
  19813. function f3( a, b, c ) {
  19814. a += shapesOffset;
  19815. b += shapesOffset;
  19816. c += shapesOffset;
  19817. scope.faces.push( new THREE.Face3( a, b, c ) );
  19818. var uvs = uvgen.generateTopUV( scope, a, b, c );
  19819. scope.faceVertexUvs[ 0 ].push( uvs );
  19820. }
  19821. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  19822. a += shapesOffset;
  19823. b += shapesOffset;
  19824. c += shapesOffset;
  19825. d += shapesOffset;
  19826. scope.faces.push( new THREE.Face3( a, b, d ) );
  19827. scope.faces.push( new THREE.Face3( b, c, d ) );
  19828. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  19829. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  19830. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  19831. }
  19832. };
  19833. THREE.ExtrudeGeometry.WorldUVGenerator = {
  19834. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  19835. var vertices = geometry.vertices;
  19836. var a = vertices[ indexA ];
  19837. var b = vertices[ indexB ];
  19838. var c = vertices[ indexC ];
  19839. return [
  19840. new THREE.Vector2( a.x, a.y ),
  19841. new THREE.Vector2( b.x, b.y ),
  19842. new THREE.Vector2( c.x, c.y )
  19843. ];
  19844. },
  19845. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  19846. var vertices = geometry.vertices;
  19847. var a = vertices[ indexA ];
  19848. var b = vertices[ indexB ];
  19849. var c = vertices[ indexC ];
  19850. var d = vertices[ indexD ];
  19851. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  19852. return [
  19853. new THREE.Vector2( a.x, 1 - a.z ),
  19854. new THREE.Vector2( b.x, 1 - b.z ),
  19855. new THREE.Vector2( c.x, 1 - c.z ),
  19856. new THREE.Vector2( d.x, 1 - d.z )
  19857. ];
  19858. } else {
  19859. return [
  19860. new THREE.Vector2( a.y, 1 - a.z ),
  19861. new THREE.Vector2( b.y, 1 - b.z ),
  19862. new THREE.Vector2( c.y, 1 - c.z ),
  19863. new THREE.Vector2( d.y, 1 - d.z )
  19864. ];
  19865. }
  19866. }
  19867. };
  19868. // File:src/extras/geometries/ShapeGeometry.js
  19869. /**
  19870. * @author jonobr1 / http://jonobr1.com
  19871. *
  19872. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19873. * ExtrudeGeometry.
  19874. *
  19875. * parameters = {
  19876. *
  19877. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19878. *
  19879. * material: <int> // material index for front and back faces
  19880. * uvGenerator: <Object> // object that provides UV generator functions
  19881. *
  19882. * }
  19883. **/
  19884. THREE.ShapeGeometry = function ( shapes, options ) {
  19885. THREE.Geometry.call( this );
  19886. this.type = 'ShapeGeometry';
  19887. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19888. this.addShapeList( shapes, options );
  19889. this.computeFaceNormals();
  19890. };
  19891. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19892. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19893. /**
  19894. * Add an array of shapes to THREE.ShapeGeometry.
  19895. */
  19896. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19897. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19898. this.addShape( shapes[ i ], options );
  19899. }
  19900. return this;
  19901. };
  19902. /**
  19903. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19904. */
  19905. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19906. if ( options === undefined ) options = {};
  19907. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19908. var material = options.material;
  19909. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19910. //
  19911. var i, l, hole;
  19912. var shapesOffset = this.vertices.length;
  19913. var shapePoints = shape.extractPoints( curveSegments );
  19914. var vertices = shapePoints.shape;
  19915. var holes = shapePoints.holes;
  19916. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19917. if ( reverse ) {
  19918. vertices = vertices.reverse();
  19919. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19920. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19921. hole = holes[ i ];
  19922. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19923. holes[ i ] = hole.reverse();
  19924. }
  19925. }
  19926. reverse = false;
  19927. }
  19928. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19929. // Vertices
  19930. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19931. hole = holes[ i ];
  19932. vertices = vertices.concat( hole );
  19933. }
  19934. //
  19935. var vert, vlen = vertices.length;
  19936. var face, flen = faces.length;
  19937. for ( i = 0; i < vlen; i ++ ) {
  19938. vert = vertices[ i ];
  19939. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19940. }
  19941. for ( i = 0; i < flen; i ++ ) {
  19942. face = faces[ i ];
  19943. var a = face[ 0 ] + shapesOffset;
  19944. var b = face[ 1 ] + shapesOffset;
  19945. var c = face[ 2 ] + shapesOffset;
  19946. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19947. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19948. }
  19949. };
  19950. // File:src/extras/geometries/LatheGeometry.js
  19951. /**
  19952. * @author astrodud / http://astrodud.isgreat.org/
  19953. * @author zz85 / https://github.com/zz85
  19954. * @author bhouston / http://clara.io
  19955. */
  19956. // points - to create a closed torus, one must use a set of points
  19957. // like so: [ a, b, c, d, a ], see first is the same as last.
  19958. // segments - the number of circumference segments to create
  19959. // phiStart - the starting radian
  19960. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19961. // 2*pi is a closed lathe, less than 2PI is a portion.
  19962. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19963. THREE.Geometry.call( this );
  19964. this.type = 'LatheGeometry';
  19965. this.parameters = {
  19966. points: points,
  19967. segments: segments,
  19968. phiStart: phiStart,
  19969. phiLength: phiLength
  19970. };
  19971. segments = segments || 12;
  19972. phiStart = phiStart || 0;
  19973. phiLength = phiLength || 2 * Math.PI;
  19974. var inversePointLength = 1.0 / ( points.length - 1 );
  19975. var inverseSegments = 1.0 / segments;
  19976. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19977. var phi = phiStart + i * inverseSegments * phiLength;
  19978. var c = Math.cos( phi ),
  19979. s = Math.sin( phi );
  19980. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19981. var pt = points[ j ];
  19982. var vertex = new THREE.Vector3();
  19983. vertex.x = c * pt.x - s * pt.y;
  19984. vertex.y = s * pt.x + c * pt.y;
  19985. vertex.z = pt.z;
  19986. this.vertices.push( vertex );
  19987. }
  19988. }
  19989. var np = points.length;
  19990. for ( var i = 0, il = segments; i < il; i ++ ) {
  19991. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19992. var base = j + np * i;
  19993. var a = base;
  19994. var b = base + np;
  19995. var c = base + 1 + np;
  19996. var d = base + 1;
  19997. var u0 = i * inverseSegments;
  19998. var v0 = j * inversePointLength;
  19999. var u1 = u0 + inverseSegments;
  20000. var v1 = v0 + inversePointLength;
  20001. this.faces.push( new THREE.Face3( a, b, d ) );
  20002. this.faceVertexUvs[ 0 ].push( [
  20003. new THREE.Vector2( u0, v0 ),
  20004. new THREE.Vector2( u1, v0 ),
  20005. new THREE.Vector2( u0, v1 )
  20006. ] );
  20007. this.faces.push( new THREE.Face3( b, c, d ) );
  20008. this.faceVertexUvs[ 0 ].push( [
  20009. new THREE.Vector2( u1, v0 ),
  20010. new THREE.Vector2( u1, v1 ),
  20011. new THREE.Vector2( u0, v1 )
  20012. ] );
  20013. }
  20014. }
  20015. this.mergeVertices();
  20016. this.computeFaceNormals();
  20017. this.computeVertexNormals();
  20018. };
  20019. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20020. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  20021. // File:src/extras/geometries/PlaneGeometry.js
  20022. /**
  20023. * @author mrdoob / http://mrdoob.com/
  20024. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  20025. */
  20026. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  20027. THREE.Geometry.call( this );
  20028. this.type = 'PlaneGeometry';
  20029. this.parameters = {
  20030. width: width,
  20031. height: height,
  20032. widthSegments: widthSegments,
  20033. heightSegments: heightSegments
  20034. };
  20035. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  20036. };
  20037. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20038. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  20039. THREE.PlaneGeometry.prototype.clone = function () {
  20040. var geometry = new THREE.PlaneGeometry(
  20041. this.parameters.width,
  20042. this.parameters.height,
  20043. this.parameters.widthSegments,
  20044. this.parameters.heightSegments
  20045. );
  20046. return geometry;
  20047. };
  20048. // File:src/extras/geometries/PlaneBufferGeometry.js
  20049. /**
  20050. * @author mrdoob / http://mrdoob.com/
  20051. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  20052. */
  20053. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  20054. THREE.BufferGeometry.call( this );
  20055. this.type = 'PlaneBufferGeometry';
  20056. this.parameters = {
  20057. width: width,
  20058. height: height,
  20059. widthSegments: widthSegments,
  20060. heightSegments: heightSegments
  20061. };
  20062. var width_half = width / 2;
  20063. var height_half = height / 2;
  20064. var gridX = Math.floor( widthSegments ) || 1;
  20065. var gridY = Math.floor( heightSegments ) || 1;
  20066. var gridX1 = gridX + 1;
  20067. var gridY1 = gridY + 1;
  20068. var segment_width = width / gridX;
  20069. var segment_height = height / gridY;
  20070. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  20071. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  20072. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  20073. var offset = 0;
  20074. var offset2 = 0;
  20075. for ( var iy = 0; iy < gridY1; iy ++ ) {
  20076. var y = iy * segment_height - height_half;
  20077. for ( var ix = 0; ix < gridX1; ix ++ ) {
  20078. var x = ix * segment_width - width_half;
  20079. vertices[ offset ] = x;
  20080. vertices[ offset + 1 ] = - y;
  20081. normals[ offset + 2 ] = 1;
  20082. uvs[ offset2 ] = ix / gridX;
  20083. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  20084. offset += 3;
  20085. offset2 += 2;
  20086. }
  20087. }
  20088. offset = 0;
  20089. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  20090. for ( var iy = 0; iy < gridY; iy ++ ) {
  20091. for ( var ix = 0; ix < gridX; ix ++ ) {
  20092. var a = ix + gridX1 * iy;
  20093. var b = ix + gridX1 * ( iy + 1 );
  20094. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  20095. var d = ( ix + 1 ) + gridX1 * iy;
  20096. indices[ offset ] = a;
  20097. indices[ offset + 1 ] = b;
  20098. indices[ offset + 2 ] = d;
  20099. indices[ offset + 3 ] = b;
  20100. indices[ offset + 4 ] = c;
  20101. indices[ offset + 5 ] = d;
  20102. offset += 6;
  20103. }
  20104. }
  20105. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  20106. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20107. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  20108. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  20109. };
  20110. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20111. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  20112. THREE.PlaneBufferGeometry.prototype.clone = function () {
  20113. var geometry = new THREE.PlaneBufferGeometry(
  20114. this.parameters.width,
  20115. this.parameters.height,
  20116. this.parameters.widthSegments,
  20117. this.parameters.heightSegments
  20118. );
  20119. geometry.copy( this );
  20120. return geometry;
  20121. };
  20122. // File:src/extras/geometries/RingGeometry.js
  20123. /**
  20124. * @author Kaleb Murphy
  20125. */
  20126. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  20127. THREE.Geometry.call( this );
  20128. this.type = 'RingGeometry';
  20129. this.parameters = {
  20130. innerRadius: innerRadius,
  20131. outerRadius: outerRadius,
  20132. thetaSegments: thetaSegments,
  20133. phiSegments: phiSegments,
  20134. thetaStart: thetaStart,
  20135. thetaLength: thetaLength
  20136. };
  20137. innerRadius = innerRadius || 0;
  20138. outerRadius = outerRadius || 50;
  20139. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20140. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20141. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  20142. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  20143. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  20144. for ( i = 0; i < phiSegments + 1; i ++ ) {
  20145. // concentric circles inside ring
  20146. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  20147. // number of segments per circle
  20148. var vertex = new THREE.Vector3();
  20149. var segment = thetaStart + o / thetaSegments * thetaLength;
  20150. vertex.x = radius * Math.cos( segment );
  20151. vertex.y = radius * Math.sin( segment );
  20152. this.vertices.push( vertex );
  20153. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  20154. }
  20155. radius += radiusStep;
  20156. }
  20157. var n = new THREE.Vector3( 0, 0, 1 );
  20158. for ( i = 0; i < phiSegments; i ++ ) {
  20159. // concentric circles inside ring
  20160. var thetaSegment = i * ( thetaSegments + 1 );
  20161. for ( o = 0; o < thetaSegments ; o ++ ) {
  20162. // number of segments per circle
  20163. var segment = o + thetaSegment;
  20164. var v1 = segment;
  20165. var v2 = segment + thetaSegments + 1;
  20166. var v3 = segment + thetaSegments + 2;
  20167. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  20168. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  20169. v1 = segment;
  20170. v2 = segment + thetaSegments + 2;
  20171. v3 = segment + 1;
  20172. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  20173. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  20174. }
  20175. }
  20176. this.computeFaceNormals();
  20177. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20178. };
  20179. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20180. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  20181. THREE.RingGeometry.prototype.clone = function () {
  20182. var geometry = new THREE.RingGeometry(
  20183. this.parameters.innerRadius,
  20184. this.parameters.outerRadius,
  20185. this.parameters.thetaSegments,
  20186. this.parameters.phiSegments,
  20187. this.parameters.thetaStart,
  20188. this.parameters.thetaLength
  20189. );
  20190. return geometry;
  20191. };
  20192. // File:src/extras/geometries/SphereGeometry.js
  20193. /**
  20194. * @author mrdoob / http://mrdoob.com/
  20195. */
  20196. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  20197. THREE.Geometry.call( this );
  20198. this.type = 'SphereGeometry';
  20199. this.parameters = {
  20200. radius: radius,
  20201. widthSegments: widthSegments,
  20202. heightSegments: heightSegments,
  20203. phiStart: phiStart,
  20204. phiLength: phiLength,
  20205. thetaStart: thetaStart,
  20206. thetaLength: thetaLength
  20207. };
  20208. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  20209. };
  20210. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20211. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  20212. THREE.SphereGeometry.prototype.clone = function () {
  20213. var geometry = new THREE.SphereGeometry(
  20214. this.parameters.radius,
  20215. this.parameters.widthSegments,
  20216. this.parameters.heightSegments,
  20217. this.parameters.phiStart,
  20218. this.parameters.phiLength,
  20219. this.parameters.thetaStart,
  20220. this.parameters.thetaLength
  20221. );
  20222. return geometry;
  20223. };
  20224. // File:src/extras/geometries/SphereBufferGeometry.js
  20225. /**
  20226. * @author benaadams / https://twitter.com/ben_a_adams
  20227. * based on THREE.SphereGeometry
  20228. */
  20229. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  20230. THREE.BufferGeometry.call( this );
  20231. this.type = 'SphereBufferGeometry';
  20232. this.parameters = {
  20233. radius: radius,
  20234. widthSegments: widthSegments,
  20235. heightSegments: heightSegments,
  20236. phiStart: phiStart,
  20237. phiLength: phiLength,
  20238. thetaStart: thetaStart,
  20239. thetaLength: thetaLength
  20240. };
  20241. radius = radius || 50;
  20242. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  20243. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  20244. phiStart = phiStart !== undefined ? phiStart : 0;
  20245. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  20246. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20247. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  20248. var thetaEnd = thetaStart + thetaLength;
  20249. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  20250. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  20251. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  20252. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  20253. var index = 0, vertices = [], normal = new THREE.Vector3();
  20254. for ( var y = 0; y <= heightSegments; y ++ ) {
  20255. var verticesRow = [];
  20256. var v = y / heightSegments;
  20257. for ( var x = 0; x <= widthSegments; x ++ ) {
  20258. var u = x / widthSegments;
  20259. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20260. var py = radius * Math.cos( thetaStart + v * thetaLength );
  20261. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20262. normal.set( px, py, pz ).normalize();
  20263. positions.setXYZ( index, px, py, pz );
  20264. normals.setXYZ( index, normal.x, normal.y, normal.z );
  20265. uvs.setXY( index, u, 1 - v );
  20266. verticesRow.push( index );
  20267. index ++;
  20268. }
  20269. vertices.push( verticesRow );
  20270. }
  20271. var indices = [];
  20272. for ( var y = 0; y < heightSegments; y ++ ) {
  20273. for ( var x = 0; x < widthSegments; x ++ ) {
  20274. var v1 = vertices[ y ][ x + 1 ];
  20275. var v2 = vertices[ y ][ x ];
  20276. var v3 = vertices[ y + 1 ][ x ];
  20277. var v4 = vertices[ y + 1 ][ x + 1 ];
  20278. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  20279. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  20280. }
  20281. }
  20282. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  20283. this.addAttribute( 'position', positions );
  20284. this.addAttribute( 'normal', normals );
  20285. this.addAttribute( 'uv', uvs );
  20286. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20287. };
  20288. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20289. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  20290. THREE.SphereBufferGeometry.prototype.clone = function () {
  20291. var geometry = new THREE.SphereBufferGeometry(
  20292. this.parameters.radius,
  20293. this.parameters.widthSegments,
  20294. this.parameters.heightSegments,
  20295. this.parameters.phiStart,
  20296. this.parameters.phiLength,
  20297. this.parameters.thetaStart,
  20298. this.parameters.thetaLength
  20299. );
  20300. geometry.copy( this );
  20301. return geometry;
  20302. };
  20303. // File:src/extras/geometries/TextGeometry.js
  20304. /**
  20305. * @author zz85 / http://www.lab4games.net/zz85/blog
  20306. * @author alteredq / http://alteredqualia.com/
  20307. *
  20308. * For creating 3D text geometry in three.js
  20309. *
  20310. * Text = 3D Text
  20311. *
  20312. * parameters = {
  20313. * size: <float>, // size of the text
  20314. * height: <float>, // thickness to extrude text
  20315. * curveSegments: <int>, // number of points on the curves
  20316. *
  20317. * font: <string>, // font name
  20318. * weight: <string>, // font weight (normal, bold)
  20319. * style: <string>, // font style (normal, italics)
  20320. *
  20321. * bevelEnabled: <bool>, // turn on bevel
  20322. * bevelThickness: <float>, // how deep into text bevel goes
  20323. * bevelSize: <float>, // how far from text outline is bevel
  20324. * }
  20325. *
  20326. */
  20327. /* Usage Examples
  20328. // TextGeometry wrapper
  20329. var text3d = new TextGeometry( text, options );
  20330. // Complete manner
  20331. var textShapes = THREE.FontUtils.generateShapes( text, options );
  20332. var text3d = new ExtrudeGeometry( textShapes, options );
  20333. */
  20334. THREE.TextGeometry = function ( text, parameters ) {
  20335. parameters = parameters || {};
  20336. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  20337. // translate parameters to ExtrudeGeometry API
  20338. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  20339. // defaults
  20340. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  20341. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  20342. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  20343. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  20344. this.type = 'TextGeometry';
  20345. };
  20346. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  20347. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  20348. // File:src/extras/geometries/TorusGeometry.js
  20349. /**
  20350. * @author oosmoxiecode
  20351. * @author mrdoob / http://mrdoob.com/
  20352. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  20353. */
  20354. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  20355. THREE.Geometry.call( this );
  20356. this.type = 'TorusGeometry';
  20357. this.parameters = {
  20358. radius: radius,
  20359. tube: tube,
  20360. radialSegments: radialSegments,
  20361. tubularSegments: tubularSegments,
  20362. arc: arc
  20363. };
  20364. radius = radius || 100;
  20365. tube = tube || 40;
  20366. radialSegments = radialSegments || 8;
  20367. tubularSegments = tubularSegments || 6;
  20368. arc = arc || Math.PI * 2;
  20369. var center = new THREE.Vector3(), uvs = [], normals = [];
  20370. for ( var j = 0; j <= radialSegments; j ++ ) {
  20371. for ( var i = 0; i <= tubularSegments; i ++ ) {
  20372. var u = i / tubularSegments * arc;
  20373. var v = j / radialSegments * Math.PI * 2;
  20374. center.x = radius * Math.cos( u );
  20375. center.y = radius * Math.sin( u );
  20376. var vertex = new THREE.Vector3();
  20377. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  20378. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  20379. vertex.z = tube * Math.sin( v );
  20380. this.vertices.push( vertex );
  20381. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  20382. normals.push( vertex.clone().sub( center ).normalize() );
  20383. }
  20384. }
  20385. for ( var j = 1; j <= radialSegments; j ++ ) {
  20386. for ( var i = 1; i <= tubularSegments; i ++ ) {
  20387. var a = ( tubularSegments + 1 ) * j + i - 1;
  20388. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  20389. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  20390. var d = ( tubularSegments + 1 ) * j + i;
  20391. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  20392. this.faces.push( face );
  20393. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  20394. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  20395. this.faces.push( face );
  20396. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  20397. }
  20398. }
  20399. this.computeFaceNormals();
  20400. };
  20401. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20402. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  20403. THREE.TorusGeometry.prototype.clone = function () {
  20404. var geometry = new THREE.TorusGeometry(
  20405. this.parameters.radius,
  20406. this.parameters.tube,
  20407. this.parameters.radialSegments,
  20408. this.parameters.tubularSegments,
  20409. this.parameters.arc
  20410. );
  20411. return geometry;
  20412. };
  20413. // File:src/extras/geometries/TorusKnotGeometry.js
  20414. /**
  20415. * @author oosmoxiecode
  20416. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  20417. */
  20418. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  20419. THREE.Geometry.call( this );
  20420. this.type = 'TorusKnotGeometry';
  20421. this.parameters = {
  20422. radius: radius,
  20423. tube: tube,
  20424. radialSegments: radialSegments,
  20425. tubularSegments: tubularSegments,
  20426. p: p,
  20427. q: q,
  20428. heightScale: heightScale
  20429. };
  20430. radius = radius || 100;
  20431. tube = tube || 40;
  20432. radialSegments = radialSegments || 64;
  20433. tubularSegments = tubularSegments || 8;
  20434. p = p || 2;
  20435. q = q || 3;
  20436. heightScale = heightScale || 1;
  20437. var grid = new Array( radialSegments );
  20438. var tang = new THREE.Vector3();
  20439. var n = new THREE.Vector3();
  20440. var bitan = new THREE.Vector3();
  20441. for ( var i = 0; i < radialSegments; ++ i ) {
  20442. grid[ i ] = new Array( tubularSegments );
  20443. var u = i / radialSegments * 2 * p * Math.PI;
  20444. var p1 = getPos( u, q, p, radius, heightScale );
  20445. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  20446. tang.subVectors( p2, p1 );
  20447. n.addVectors( p2, p1 );
  20448. bitan.crossVectors( tang, n );
  20449. n.crossVectors( bitan, tang );
  20450. bitan.normalize();
  20451. n.normalize();
  20452. for ( var j = 0; j < tubularSegments; ++ j ) {
  20453. var v = j / tubularSegments * 2 * Math.PI;
  20454. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20455. var cy = tube * Math.sin( v );
  20456. var pos = new THREE.Vector3();
  20457. pos.x = p1.x + cx * n.x + cy * bitan.x;
  20458. pos.y = p1.y + cx * n.y + cy * bitan.y;
  20459. pos.z = p1.z + cx * n.z + cy * bitan.z;
  20460. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  20461. }
  20462. }
  20463. for ( var i = 0; i < radialSegments; ++ i ) {
  20464. for ( var j = 0; j < tubularSegments; ++ j ) {
  20465. var ip = ( i + 1 ) % radialSegments;
  20466. var jp = ( j + 1 ) % tubularSegments;
  20467. var a = grid[ i ][ j ];
  20468. var b = grid[ ip ][ j ];
  20469. var c = grid[ ip ][ jp ];
  20470. var d = grid[ i ][ jp ];
  20471. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  20472. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  20473. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  20474. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  20475. this.faces.push( new THREE.Face3( a, b, d ) );
  20476. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20477. this.faces.push( new THREE.Face3( b, c, d ) );
  20478. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20479. }
  20480. }
  20481. this.computeFaceNormals();
  20482. this.computeVertexNormals();
  20483. function getPos( u, in_q, in_p, radius, heightScale ) {
  20484. var cu = Math.cos( u );
  20485. var su = Math.sin( u );
  20486. var quOverP = in_q / in_p * u;
  20487. var cs = Math.cos( quOverP );
  20488. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  20489. var ty = radius * ( 2 + cs ) * su * 0.5;
  20490. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  20491. return new THREE.Vector3( tx, ty, tz );
  20492. }
  20493. };
  20494. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20495. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  20496. THREE.TorusKnotGeometry.prototype.clone = function () {
  20497. var geometry = new THREE.TorusKnotGeometry(
  20498. this.parameters.radius,
  20499. this.parameters.tube,
  20500. this.parameters.radialSegments,
  20501. this.parameters.tubularSegments,
  20502. this.parameters.p,
  20503. this.parameters.q,
  20504. this.parameters.heightScale
  20505. );
  20506. return geometry;
  20507. };
  20508. // File:src/extras/geometries/TubeGeometry.js
  20509. /**
  20510. * @author WestLangley / https://github.com/WestLangley
  20511. * @author zz85 / https://github.com/zz85
  20512. * @author miningold / https://github.com/miningold
  20513. * @author jonobr1 / https://github.com/jonobr1
  20514. *
  20515. * Modified from the TorusKnotGeometry by @oosmoxiecode
  20516. *
  20517. * Creates a tube which extrudes along a 3d spline
  20518. *
  20519. * Uses parallel transport frames as described in
  20520. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  20521. */
  20522. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  20523. THREE.Geometry.call( this );
  20524. this.type = 'TubeGeometry';
  20525. this.parameters = {
  20526. path: path,
  20527. segments: segments,
  20528. radius: radius,
  20529. radialSegments: radialSegments,
  20530. closed: closed,
  20531. taper: taper
  20532. };
  20533. segments = segments || 64;
  20534. radius = radius || 1;
  20535. radialSegments = radialSegments || 8;
  20536. closed = closed || false;
  20537. taper = taper || THREE.TubeGeometry.NoTaper;
  20538. var grid = [];
  20539. var scope = this,
  20540. tangent,
  20541. normal,
  20542. binormal,
  20543. numpoints = segments + 1,
  20544. u, v, r,
  20545. cx, cy,
  20546. pos, pos2 = new THREE.Vector3(),
  20547. i, j,
  20548. ip, jp,
  20549. a, b, c, d,
  20550. uva, uvb, uvc, uvd;
  20551. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  20552. tangents = frames.tangents,
  20553. normals = frames.normals,
  20554. binormals = frames.binormals;
  20555. // proxy internals
  20556. this.tangents = tangents;
  20557. this.normals = normals;
  20558. this.binormals = binormals;
  20559. function vert( x, y, z ) {
  20560. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  20561. }
  20562. // construct the grid
  20563. for ( i = 0; i < numpoints; i ++ ) {
  20564. grid[ i ] = [];
  20565. u = i / ( numpoints - 1 );
  20566. pos = path.getPointAt( u );
  20567. tangent = tangents[ i ];
  20568. normal = normals[ i ];
  20569. binormal = binormals[ i ];
  20570. r = radius * taper( u );
  20571. for ( j = 0; j < radialSegments; j ++ ) {
  20572. v = j / radialSegments * 2 * Math.PI;
  20573. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20574. cy = r * Math.sin( v );
  20575. pos2.copy( pos );
  20576. pos2.x += cx * normal.x + cy * binormal.x;
  20577. pos2.y += cx * normal.y + cy * binormal.y;
  20578. pos2.z += cx * normal.z + cy * binormal.z;
  20579. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  20580. }
  20581. }
  20582. // construct the mesh
  20583. for ( i = 0; i < segments; i ++ ) {
  20584. for ( j = 0; j < radialSegments; j ++ ) {
  20585. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  20586. jp = ( j + 1 ) % radialSegments;
  20587. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  20588. b = grid[ ip ][ j ];
  20589. c = grid[ ip ][ jp ];
  20590. d = grid[ i ][ jp ];
  20591. uva = new THREE.Vector2( i / segments, j / radialSegments );
  20592. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  20593. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  20594. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  20595. this.faces.push( new THREE.Face3( a, b, d ) );
  20596. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20597. this.faces.push( new THREE.Face3( b, c, d ) );
  20598. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20599. }
  20600. }
  20601. this.computeFaceNormals();
  20602. this.computeVertexNormals();
  20603. };
  20604. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20605. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  20606. THREE.TubeGeometry.prototype.clone = function() {
  20607. return new this.constructor( this.parameters.path,
  20608. this.parameters.segments, this.parameters.radius, this.parameters.radialSegments,
  20609. this.parameters.closed, this.parameters.taper
  20610. );
  20611. };
  20612. THREE.TubeGeometry.NoTaper = function ( u ) {
  20613. return 1;
  20614. };
  20615. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  20616. return Math.sin( Math.PI * u );
  20617. };
  20618. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  20619. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  20620. var normal = new THREE.Vector3(),
  20621. tangents = [],
  20622. normals = [],
  20623. binormals = [],
  20624. vec = new THREE.Vector3(),
  20625. mat = new THREE.Matrix4(),
  20626. numpoints = segments + 1,
  20627. theta,
  20628. epsilon = 0.0001,
  20629. smallest,
  20630. tx, ty, tz,
  20631. i, u;
  20632. // expose internals
  20633. this.tangents = tangents;
  20634. this.normals = normals;
  20635. this.binormals = binormals;
  20636. // compute the tangent vectors for each segment on the path
  20637. for ( i = 0; i < numpoints; i ++ ) {
  20638. u = i / ( numpoints - 1 );
  20639. tangents[ i ] = path.getTangentAt( u );
  20640. tangents[ i ].normalize();
  20641. }
  20642. initialNormal3();
  20643. /*
  20644. function initialNormal1(lastBinormal) {
  20645. // fixed start binormal. Has dangers of 0 vectors
  20646. normals[ 0 ] = new THREE.Vector3();
  20647. binormals[ 0 ] = new THREE.Vector3();
  20648. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  20649. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  20650. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20651. }
  20652. function initialNormal2() {
  20653. // This uses the Frenet-Serret formula for deriving binormal
  20654. var t2 = path.getTangentAt( epsilon );
  20655. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  20656. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  20657. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  20658. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20659. }
  20660. */
  20661. function initialNormal3() {
  20662. // select an initial normal vector perpendicular to the first tangent vector,
  20663. // and in the direction of the smallest tangent xyz component
  20664. normals[ 0 ] = new THREE.Vector3();
  20665. binormals[ 0 ] = new THREE.Vector3();
  20666. smallest = Number.MAX_VALUE;
  20667. tx = Math.abs( tangents[ 0 ].x );
  20668. ty = Math.abs( tangents[ 0 ].y );
  20669. tz = Math.abs( tangents[ 0 ].z );
  20670. if ( tx <= smallest ) {
  20671. smallest = tx;
  20672. normal.set( 1, 0, 0 );
  20673. }
  20674. if ( ty <= smallest ) {
  20675. smallest = ty;
  20676. normal.set( 0, 1, 0 );
  20677. }
  20678. if ( tz <= smallest ) {
  20679. normal.set( 0, 0, 1 );
  20680. }
  20681. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20682. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20683. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20684. }
  20685. // compute the slowly-varying normal and binormal vectors for each segment on the path
  20686. for ( i = 1; i < numpoints; i ++ ) {
  20687. normals[ i ] = normals[ i - 1 ].clone();
  20688. binormals[ i ] = binormals[ i - 1 ].clone();
  20689. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20690. if ( vec.length() > epsilon ) {
  20691. vec.normalize();
  20692. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20693. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20694. }
  20695. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20696. }
  20697. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20698. if ( closed ) {
  20699. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  20700. theta /= ( numpoints - 1 );
  20701. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  20702. theta = - theta;
  20703. }
  20704. for ( i = 1; i < numpoints; i ++ ) {
  20705. // twist a little...
  20706. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20707. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20708. }
  20709. }
  20710. };
  20711. // File:src/extras/geometries/PolyhedronGeometry.js
  20712. /**
  20713. * @author clockworkgeek / https://github.com/clockworkgeek
  20714. * @author timothypratley / https://github.com/timothypratley
  20715. * @author WestLangley / http://github.com/WestLangley
  20716. */
  20717. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  20718. THREE.Geometry.call( this );
  20719. this.type = 'PolyhedronGeometry';
  20720. this.parameters = {
  20721. vertices: vertices,
  20722. indices: indices,
  20723. radius: radius,
  20724. detail: detail
  20725. };
  20726. radius = radius || 1;
  20727. detail = detail || 0;
  20728. var that = this;
  20729. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  20730. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  20731. }
  20732. var p = this.vertices;
  20733. var faces = [];
  20734. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  20735. var v1 = p[ indices[ i ] ];
  20736. var v2 = p[ indices[ i + 1 ] ];
  20737. var v3 = p[ indices[ i + 2 ] ];
  20738. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  20739. }
  20740. var centroid = new THREE.Vector3();
  20741. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20742. subdivide( faces[ i ], detail );
  20743. }
  20744. // Handle case when face straddles the seam
  20745. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  20746. var uvs = this.faceVertexUvs[ 0 ][ i ];
  20747. var x0 = uvs[ 0 ].x;
  20748. var x1 = uvs[ 1 ].x;
  20749. var x2 = uvs[ 2 ].x;
  20750. var max = Math.max( x0, Math.max( x1, x2 ) );
  20751. var min = Math.min( x0, Math.min( x1, x2 ) );
  20752. if ( max > 0.9 && min < 0.1 ) {
  20753. // 0.9 is somewhat arbitrary
  20754. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  20755. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  20756. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  20757. }
  20758. }
  20759. // Apply radius
  20760. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  20761. this.vertices[ i ].multiplyScalar( radius );
  20762. }
  20763. // Merge vertices
  20764. this.mergeVertices();
  20765. this.computeFaceNormals();
  20766. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20767. // Project vector onto sphere's surface
  20768. function prepare( vector ) {
  20769. var vertex = vector.normalize().clone();
  20770. vertex.index = that.vertices.push( vertex ) - 1;
  20771. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  20772. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  20773. var v = inclination( vector ) / Math.PI + 0.5;
  20774. vertex.uv = new THREE.Vector2( u, 1 - v );
  20775. return vertex;
  20776. }
  20777. // Approximate a curved face with recursively sub-divided triangles.
  20778. function make( v1, v2, v3, materialIndex ) {
  20779. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  20780. that.faces.push( face );
  20781. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  20782. var azi = azimuth( centroid );
  20783. that.faceVertexUvs[ 0 ].push( [
  20784. correctUV( v1.uv, v1, azi ),
  20785. correctUV( v2.uv, v2, azi ),
  20786. correctUV( v3.uv, v3, azi )
  20787. ] );
  20788. }
  20789. // Analytically subdivide a face to the required detail level.
  20790. function subdivide( face, detail ) {
  20791. var cols = Math.pow( 2, detail );
  20792. var a = prepare( that.vertices[ face.a ] );
  20793. var b = prepare( that.vertices[ face.b ] );
  20794. var c = prepare( that.vertices[ face.c ] );
  20795. var v = [];
  20796. var materialIndex = face.materialIndex;
  20797. // Construct all of the vertices for this subdivision.
  20798. for ( var i = 0 ; i <= cols; i ++ ) {
  20799. v[ i ] = [];
  20800. var aj = prepare( a.clone().lerp( c, i / cols ) );
  20801. var bj = prepare( b.clone().lerp( c, i / cols ) );
  20802. var rows = cols - i;
  20803. for ( var j = 0; j <= rows; j ++ ) {
  20804. if ( j === 0 && i === cols ) {
  20805. v[ i ][ j ] = aj;
  20806. } else {
  20807. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  20808. }
  20809. }
  20810. }
  20811. // Construct all of the faces.
  20812. for ( var i = 0; i < cols ; i ++ ) {
  20813. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  20814. var k = Math.floor( j / 2 );
  20815. if ( j % 2 === 0 ) {
  20816. make(
  20817. v[ i ][ k + 1 ],
  20818. v[ i + 1 ][ k ],
  20819. v[ i ][ k ],
  20820. materialIndex
  20821. );
  20822. } else {
  20823. make(
  20824. v[ i ][ k + 1 ],
  20825. v[ i + 1 ][ k + 1 ],
  20826. v[ i + 1 ][ k ],
  20827. materialIndex
  20828. );
  20829. }
  20830. }
  20831. }
  20832. }
  20833. // Angle around the Y axis, counter-clockwise when looking from above.
  20834. function azimuth( vector ) {
  20835. return Math.atan2( vector.z, - vector.x );
  20836. }
  20837. // Angle above the XZ plane.
  20838. function inclination( vector ) {
  20839. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  20840. }
  20841. // Texture fixing helper. Spheres have some odd behaviours.
  20842. function correctUV( uv, vector, azimuth ) {
  20843. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  20844. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  20845. return uv.clone();
  20846. }
  20847. };
  20848. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20849. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  20850. THREE.PolyhedronGeometry.prototype.clone = function () {
  20851. var geometry = new THREE.PolyhedronGeometry(
  20852. this.parameters.vertices,
  20853. this.parameters.indices,
  20854. this.parameters.radius,
  20855. this.parameters.detail
  20856. );
  20857. return geometry.copy( this );
  20858. };
  20859. THREE.PolyhedronGeometry.prototype.copy = function ( source ) {
  20860. THREE.Geometry.prototype.copy.call( this, source );
  20861. return this;
  20862. };
  20863. // File:src/extras/geometries/DodecahedronGeometry.js
  20864. /**
  20865. * @author Abe Pazos / https://hamoid.com
  20866. */
  20867. THREE.DodecahedronGeometry = function ( radius, detail ) {
  20868. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20869. var r = 1 / t;
  20870. var vertices = [
  20871. // (±1, ±1, ±1)
  20872. - 1, - 1, - 1, - 1, - 1, 1,
  20873. - 1, 1, - 1, - 1, 1, 1,
  20874. 1, - 1, - 1, 1, - 1, 1,
  20875. 1, 1, - 1, 1, 1, 1,
  20876. // (0, ±1/φ, ±φ)
  20877. 0, - r, - t, 0, - r, t,
  20878. 0, r, - t, 0, r, t,
  20879. // (±1/φ, ±φ, 0)
  20880. - r, - t, 0, - r, t, 0,
  20881. r, - t, 0, r, t, 0,
  20882. // (±φ, 0, ±1/φ)
  20883. - t, 0, - r, t, 0, - r,
  20884. - t, 0, r, t, 0, r
  20885. ];
  20886. var indices = [
  20887. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  20888. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  20889. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  20890. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  20891. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  20892. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  20893. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  20894. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  20895. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  20896. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  20897. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  20898. 1, 12, 14, 1, 14, 5, 1, 5, 9
  20899. ];
  20900. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20901. this.type = 'DodecahedronGeometry';
  20902. this.parameters = {
  20903. radius: radius,
  20904. detail: detail
  20905. };
  20906. };
  20907. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20908. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  20909. THREE.DodecahedronGeometry.prototype.clone = function () {
  20910. var geometry = new THREE.DodecahedronGeometry(
  20911. this.parameters.radius,
  20912. this.parameters.detail
  20913. );
  20914. geometry.copy( this );
  20915. return geometry;
  20916. };
  20917. // File:src/extras/geometries/IcosahedronGeometry.js
  20918. /**
  20919. * @author timothypratley / https://github.com/timothypratley
  20920. */
  20921. THREE.IcosahedronGeometry = function ( radius, detail ) {
  20922. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20923. var vertices = [
  20924. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20925. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20926. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20927. ];
  20928. var indices = [
  20929. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20930. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20931. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20932. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20933. ];
  20934. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20935. this.type = 'IcosahedronGeometry';
  20936. this.parameters = {
  20937. radius: radius,
  20938. detail: detail
  20939. };
  20940. };
  20941. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20942. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20943. THREE.IcosahedronGeometry.prototype.clone = function () {
  20944. var geometry = new THREE.IcosahedronGeometry(
  20945. this.parameters.radius,
  20946. this.parameters.detail
  20947. );
  20948. geometry.copy( this );
  20949. return geometry;
  20950. };
  20951. // File:src/extras/geometries/OctahedronGeometry.js
  20952. /**
  20953. * @author timothypratley / https://github.com/timothypratley
  20954. */
  20955. THREE.OctahedronGeometry = function ( radius, detail ) {
  20956. var vertices = [
  20957. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  20958. ];
  20959. var indices = [
  20960. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20961. ];
  20962. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20963. this.type = 'OctahedronGeometry';
  20964. this.parameters = {
  20965. radius: radius,
  20966. detail: detail
  20967. };
  20968. };
  20969. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20970. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20971. THREE.OctahedronGeometry.prototype.clone = function () {
  20972. var geometry = new THREE.OctahedronGeometry(
  20973. this.parameters.radius,
  20974. this.parameters.detail
  20975. );
  20976. geometry.copy( this );
  20977. return geometry;
  20978. };
  20979. // File:src/extras/geometries/TetrahedronGeometry.js
  20980. /**
  20981. * @author timothypratley / https://github.com/timothypratley
  20982. */
  20983. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20984. var vertices = [
  20985. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20986. ];
  20987. var indices = [
  20988. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20989. ];
  20990. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20991. this.type = 'TetrahedronGeometry';
  20992. this.parameters = {
  20993. radius: radius,
  20994. detail: detail
  20995. };
  20996. };
  20997. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20998. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20999. THREE.TetrahedronGeometry.prototype.clone = function () {
  21000. var geometry = new THREE.TetrahedronGeometry(
  21001. this.parameters.radius,
  21002. this.parameters.detail
  21003. );
  21004. geometry.copy( this );
  21005. return geometry;
  21006. };
  21007. // File:src/extras/geometries/ParametricGeometry.js
  21008. /**
  21009. * @author zz85 / https://github.com/zz85
  21010. * Parametric Surfaces Geometry
  21011. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  21012. *
  21013. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  21014. *
  21015. */
  21016. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  21017. THREE.Geometry.call( this );
  21018. this.type = 'ParametricGeometry';
  21019. this.parameters = {
  21020. func: func,
  21021. slices: slices,
  21022. stacks: stacks
  21023. };
  21024. var verts = this.vertices;
  21025. var faces = this.faces;
  21026. var uvs = this.faceVertexUvs[ 0 ];
  21027. var i, j, p;
  21028. var u, v;
  21029. var sliceCount = slices + 1;
  21030. for ( i = 0; i <= stacks; i ++ ) {
  21031. v = i / stacks;
  21032. for ( j = 0; j <= slices; j ++ ) {
  21033. u = j / slices;
  21034. p = func( u, v );
  21035. verts.push( p );
  21036. }
  21037. }
  21038. var a, b, c, d;
  21039. var uva, uvb, uvc, uvd;
  21040. for ( i = 0; i < stacks; i ++ ) {
  21041. for ( j = 0; j < slices; j ++ ) {
  21042. a = i * sliceCount + j;
  21043. b = i * sliceCount + j + 1;
  21044. c = ( i + 1 ) * sliceCount + j + 1;
  21045. d = ( i + 1 ) * sliceCount + j;
  21046. uva = new THREE.Vector2( j / slices, i / stacks );
  21047. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  21048. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  21049. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  21050. faces.push( new THREE.Face3( a, b, d ) );
  21051. uvs.push( [ uva, uvb, uvd ] );
  21052. faces.push( new THREE.Face3( b, c, d ) );
  21053. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  21054. }
  21055. }
  21056. // console.log(this);
  21057. // magic bullet
  21058. // var diff = this.mergeVertices();
  21059. // console.log('removed ', diff, ' vertices by merging');
  21060. this.computeFaceNormals();
  21061. this.computeVertexNormals();
  21062. };
  21063. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21064. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  21065. // File:src/extras/geometries/WireframeGeometry.js
  21066. /**
  21067. * @author mrdoob / http://mrdoob.com/
  21068. */
  21069. THREE.WireframeGeometry = function ( geometry ) {
  21070. THREE.BufferGeometry.call( this );
  21071. var edge = [ 0, 0 ], hash = {};
  21072. function sortFunction( a, b ) {
  21073. return a - b;
  21074. }
  21075. var keys = [ 'a', 'b', 'c' ];
  21076. if ( geometry instanceof THREE.Geometry ) {
  21077. var vertices = geometry.vertices;
  21078. var faces = geometry.faces;
  21079. var numEdges = 0;
  21080. // allocate maximal size
  21081. var edges = new Uint32Array( 6 * faces.length );
  21082. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21083. var face = faces[ i ];
  21084. for ( var j = 0; j < 3; j ++ ) {
  21085. edge[ 0 ] = face[ keys[ j ] ];
  21086. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21087. edge.sort( sortFunction );
  21088. var key = edge.toString();
  21089. if ( hash[ key ] === undefined ) {
  21090. edges[ 2 * numEdges ] = edge[ 0 ];
  21091. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  21092. hash[ key ] = true;
  21093. numEdges ++;
  21094. }
  21095. }
  21096. }
  21097. var coords = new Float32Array( numEdges * 2 * 3 );
  21098. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  21099. for ( var j = 0; j < 2; j ++ ) {
  21100. var vertex = vertices[ edges [ 2 * i + j ] ];
  21101. var index = 6 * i + 3 * j;
  21102. coords[ index + 0 ] = vertex.x;
  21103. coords[ index + 1 ] = vertex.y;
  21104. coords[ index + 2 ] = vertex.z;
  21105. }
  21106. }
  21107. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21108. } else if ( geometry instanceof THREE.BufferGeometry ) {
  21109. if ( geometry.index !== null ) {
  21110. // Indexed BufferGeometry
  21111. var indices = geometry.index.array;
  21112. var vertices = geometry.attributes.position;
  21113. var drawcalls = geometry.drawcalls;
  21114. var numEdges = 0;
  21115. if ( drawcalls.length === 0 ) {
  21116. geometry.addGroup( 0, indices.length );
  21117. }
  21118. // allocate maximal size
  21119. var edges = new Uint32Array( 2 * indices.length );
  21120. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  21121. var drawcall = drawcalls[ o ];
  21122. var start = drawcall.start;
  21123. var count = drawcall.count;
  21124. for ( var i = start, il = start + count; i < il; i += 3 ) {
  21125. for ( var j = 0; j < 3; j ++ ) {
  21126. edge[ 0 ] = indices[ i + j ];
  21127. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  21128. edge.sort( sortFunction );
  21129. var key = edge.toString();
  21130. if ( hash[ key ] === undefined ) {
  21131. edges[ 2 * numEdges ] = edge[ 0 ];
  21132. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  21133. hash[ key ] = true;
  21134. numEdges ++;
  21135. }
  21136. }
  21137. }
  21138. }
  21139. var coords = new Float32Array( numEdges * 2 * 3 );
  21140. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  21141. for ( var j = 0; j < 2; j ++ ) {
  21142. var index = 6 * i + 3 * j;
  21143. var index2 = edges[ 2 * i + j ];
  21144. coords[ index + 0 ] = vertices.getX( index2 );
  21145. coords[ index + 1 ] = vertices.getY( index2 );
  21146. coords[ index + 2 ] = vertices.getZ( index2 );
  21147. }
  21148. }
  21149. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21150. } else {
  21151. // non-indexed BufferGeometry
  21152. var vertices = geometry.attributes.position.array;
  21153. var numEdges = vertices.length / 3;
  21154. var numTris = numEdges / 3;
  21155. var coords = new Float32Array( numEdges * 2 * 3 );
  21156. for ( var i = 0, l = numTris; i < l; i ++ ) {
  21157. for ( var j = 0; j < 3; j ++ ) {
  21158. var index = 18 * i + 6 * j;
  21159. var index1 = 9 * i + 3 * j;
  21160. coords[ index + 0 ] = vertices[ index1 ];
  21161. coords[ index + 1 ] = vertices[ index1 + 1 ];
  21162. coords[ index + 2 ] = vertices[ index1 + 2 ];
  21163. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  21164. coords[ index + 3 ] = vertices[ index2 ];
  21165. coords[ index + 4 ] = vertices[ index2 + 1 ];
  21166. coords[ index + 5 ] = vertices[ index2 + 2 ];
  21167. }
  21168. }
  21169. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21170. }
  21171. }
  21172. };
  21173. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21174. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  21175. // File:src/extras/helpers/AxisHelper.js
  21176. /**
  21177. * @author sroucheray / http://sroucheray.org/
  21178. * @author mrdoob / http://mrdoob.com/
  21179. */
  21180. THREE.AxisHelper = function ( size ) {
  21181. size = size || 1;
  21182. var vertices = new Float32Array( [
  21183. 0, 0, 0, size, 0, 0,
  21184. 0, 0, 0, 0, size, 0,
  21185. 0, 0, 0, 0, 0, size
  21186. ] );
  21187. var colors = new Float32Array( [
  21188. 1, 0, 0, 1, 0.6, 0,
  21189. 0, 1, 0, 0.6, 1, 0,
  21190. 0, 0, 1, 0, 0.6, 1
  21191. ] );
  21192. var geometry = new THREE.BufferGeometry();
  21193. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21194. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  21195. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21196. THREE.LineSegments.call( this, geometry, material );
  21197. };
  21198. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21199. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  21200. // File:src/extras/helpers/ArrowHelper.js
  21201. /**
  21202. * @author WestLangley / http://github.com/WestLangley
  21203. * @author zz85 / http://github.com/zz85
  21204. * @author bhouston / http://clara.io
  21205. *
  21206. * Creates an arrow for visualizing directions
  21207. *
  21208. * Parameters:
  21209. * dir - Vector3
  21210. * origin - Vector3
  21211. * length - Number
  21212. * color - color in hex value
  21213. * headLength - Number
  21214. * headWidth - Number
  21215. */
  21216. THREE.ArrowHelper = ( function () {
  21217. var lineGeometry = new THREE.Geometry();
  21218. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  21219. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  21220. coneGeometry.translate( 0, - 0.5, 0 );
  21221. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  21222. // dir is assumed to be normalized
  21223. THREE.Object3D.call( this );
  21224. if ( color === undefined ) color = 0xffff00;
  21225. if ( length === undefined ) length = 1;
  21226. if ( headLength === undefined ) headLength = 0.2 * length;
  21227. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  21228. this.position.copy( origin );
  21229. if ( headLength < length ) {
  21230. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  21231. this.line.matrixAutoUpdate = false;
  21232. this.add( this.line );
  21233. }
  21234. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  21235. this.cone.matrixAutoUpdate = false;
  21236. this.add( this.cone );
  21237. this.setDirection( dir );
  21238. this.setLength( length, headLength, headWidth );
  21239. }
  21240. }() );
  21241. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  21242. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  21243. THREE.ArrowHelper.prototype.setDirection = ( function () {
  21244. var axis = new THREE.Vector3();
  21245. var radians;
  21246. return function setDirection( dir ) {
  21247. // dir is assumed to be normalized
  21248. if ( dir.y > 0.99999 ) {
  21249. this.quaternion.set( 0, 0, 0, 1 );
  21250. } else if ( dir.y < - 0.99999 ) {
  21251. this.quaternion.set( 1, 0, 0, 0 );
  21252. } else {
  21253. axis.set( dir.z, 0, - dir.x ).normalize();
  21254. radians = Math.acos( dir.y );
  21255. this.quaternion.setFromAxisAngle( axis, radians );
  21256. }
  21257. };
  21258. }() );
  21259. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  21260. if ( headLength === undefined ) headLength = 0.2 * length;
  21261. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  21262. if ( headLength < length ){
  21263. this.line.scale.set( 1, length - headLength, 1 );
  21264. this.line.updateMatrix();
  21265. }
  21266. this.cone.scale.set( headWidth, headLength, headWidth );
  21267. this.cone.position.y = length;
  21268. this.cone.updateMatrix();
  21269. };
  21270. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  21271. if ( this.line !== undefined ) this.line.material.color.set( color );
  21272. this.cone.material.color.set( color );
  21273. };
  21274. // File:src/extras/helpers/BoxHelper.js
  21275. /**
  21276. * @author mrdoob / http://mrdoob.com/
  21277. */
  21278. THREE.BoxHelper = function ( object ) {
  21279. var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
  21280. var positions = new Float32Array( 8 * 3 );
  21281. var geometry = new THREE.BufferGeometry();
  21282. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21283. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21284. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  21285. if ( object !== undefined ) {
  21286. this.update( object );
  21287. }
  21288. };
  21289. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21290. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  21291. THREE.BoxHelper.prototype.update = ( function () {
  21292. var box = new THREE.Box3();
  21293. return function ( object ) {
  21294. box.setFromObject( object );
  21295. if ( box.empty() ) return;
  21296. var min = box.min;
  21297. var max = box.max;
  21298. /*
  21299. 5____4
  21300. 1/___0/|
  21301. | 6__|_7
  21302. 2/___3/
  21303. 0: max.x, max.y, max.z
  21304. 1: min.x, max.y, max.z
  21305. 2: min.x, min.y, max.z
  21306. 3: max.x, min.y, max.z
  21307. 4: max.x, max.y, min.z
  21308. 5: min.x, max.y, min.z
  21309. 6: min.x, min.y, min.z
  21310. 7: max.x, min.y, min.z
  21311. */
  21312. var position = this.geometry.attributes.position;
  21313. var array = position.array;
  21314. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  21315. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  21316. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  21317. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  21318. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  21319. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  21320. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  21321. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  21322. position.needsUpdate = true;
  21323. this.geometry.computeBoundingSphere();
  21324. }
  21325. } )();
  21326. // File:src/extras/helpers/BoundingBoxHelper.js
  21327. /**
  21328. * @author WestLangley / http://github.com/WestLangley
  21329. */
  21330. // a helper to show the world-axis-aligned bounding box for an object
  21331. THREE.BoundingBoxHelper = function ( object, hex ) {
  21332. var color = ( hex !== undefined ) ? hex : 0x888888;
  21333. this.object = object;
  21334. this.box = new THREE.Box3();
  21335. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  21336. };
  21337. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  21338. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  21339. THREE.BoundingBoxHelper.prototype.update = function () {
  21340. this.box.setFromObject( this.object );
  21341. this.box.size( this.scale );
  21342. this.box.center( this.position );
  21343. };
  21344. // File:src/extras/helpers/CameraHelper.js
  21345. /**
  21346. * @author alteredq / http://alteredqualia.com/
  21347. *
  21348. * - shows frustum, line of sight and up of the camera
  21349. * - suitable for fast updates
  21350. * - based on frustum visualization in lightgl.js shadowmap example
  21351. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  21352. */
  21353. THREE.CameraHelper = function ( camera ) {
  21354. var geometry = new THREE.Geometry();
  21355. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  21356. var pointMap = {};
  21357. // colors
  21358. var hexFrustum = 0xffaa00;
  21359. var hexCone = 0xff0000;
  21360. var hexUp = 0x00aaff;
  21361. var hexTarget = 0xffffff;
  21362. var hexCross = 0x333333;
  21363. // near
  21364. addLine( "n1", "n2", hexFrustum );
  21365. addLine( "n2", "n4", hexFrustum );
  21366. addLine( "n4", "n3", hexFrustum );
  21367. addLine( "n3", "n1", hexFrustum );
  21368. // far
  21369. addLine( "f1", "f2", hexFrustum );
  21370. addLine( "f2", "f4", hexFrustum );
  21371. addLine( "f4", "f3", hexFrustum );
  21372. addLine( "f3", "f1", hexFrustum );
  21373. // sides
  21374. addLine( "n1", "f1", hexFrustum );
  21375. addLine( "n2", "f2", hexFrustum );
  21376. addLine( "n3", "f3", hexFrustum );
  21377. addLine( "n4", "f4", hexFrustum );
  21378. // cone
  21379. addLine( "p", "n1", hexCone );
  21380. addLine( "p", "n2", hexCone );
  21381. addLine( "p", "n3", hexCone );
  21382. addLine( "p", "n4", hexCone );
  21383. // up
  21384. addLine( "u1", "u2", hexUp );
  21385. addLine( "u2", "u3", hexUp );
  21386. addLine( "u3", "u1", hexUp );
  21387. // target
  21388. addLine( "c", "t", hexTarget );
  21389. addLine( "p", "c", hexCross );
  21390. // cross
  21391. addLine( "cn1", "cn2", hexCross );
  21392. addLine( "cn3", "cn4", hexCross );
  21393. addLine( "cf1", "cf2", hexCross );
  21394. addLine( "cf3", "cf4", hexCross );
  21395. function addLine( a, b, hex ) {
  21396. addPoint( a, hex );
  21397. addPoint( b, hex );
  21398. }
  21399. function addPoint( id, hex ) {
  21400. geometry.vertices.push( new THREE.Vector3() );
  21401. geometry.colors.push( new THREE.Color( hex ) );
  21402. if ( pointMap[ id ] === undefined ) {
  21403. pointMap[ id ] = [];
  21404. }
  21405. pointMap[ id ].push( geometry.vertices.length - 1 );
  21406. }
  21407. THREE.LineSegments.call( this, geometry, material );
  21408. this.camera = camera;
  21409. this.matrix = camera.matrixWorld;
  21410. this.matrixAutoUpdate = false;
  21411. this.pointMap = pointMap;
  21412. this.update();
  21413. };
  21414. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21415. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  21416. THREE.CameraHelper.prototype.update = function () {
  21417. var geometry, pointMap;
  21418. var vector = new THREE.Vector3();
  21419. var camera = new THREE.Camera();
  21420. function setPoint( point, x, y, z ) {
  21421. vector.set( x, y, z ).unproject( camera );
  21422. var points = pointMap[ point ];
  21423. if ( points !== undefined ) {
  21424. for ( var i = 0, il = points.length; i < il; i ++ ) {
  21425. geometry.vertices[ points[ i ] ].copy( vector );
  21426. }
  21427. }
  21428. }
  21429. return function () {
  21430. geometry = this.geometry;
  21431. pointMap = this.pointMap;
  21432. var w = 1, h = 1;
  21433. // we need just camera projection matrix
  21434. // world matrix must be identity
  21435. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  21436. // center / target
  21437. setPoint( "c", 0, 0, - 1 );
  21438. setPoint( "t", 0, 0, 1 );
  21439. // near
  21440. setPoint( "n1", - w, - h, - 1 );
  21441. setPoint( "n2", w, - h, - 1 );
  21442. setPoint( "n3", - w, h, - 1 );
  21443. setPoint( "n4", w, h, - 1 );
  21444. // far
  21445. setPoint( "f1", - w, - h, 1 );
  21446. setPoint( "f2", w, - h, 1 );
  21447. setPoint( "f3", - w, h, 1 );
  21448. setPoint( "f4", w, h, 1 );
  21449. // up
  21450. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  21451. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  21452. setPoint( "u3", 0, h * 2, - 1 );
  21453. // cross
  21454. setPoint( "cf1", - w, 0, 1 );
  21455. setPoint( "cf2", w, 0, 1 );
  21456. setPoint( "cf3", 0, - h, 1 );
  21457. setPoint( "cf4", 0, h, 1 );
  21458. setPoint( "cn1", - w, 0, - 1 );
  21459. setPoint( "cn2", w, 0, - 1 );
  21460. setPoint( "cn3", 0, - h, - 1 );
  21461. setPoint( "cn4", 0, h, - 1 );
  21462. geometry.verticesNeedUpdate = true;
  21463. };
  21464. }();
  21465. // File:src/extras/helpers/DirectionalLightHelper.js
  21466. /**
  21467. * @author alteredq / http://alteredqualia.com/
  21468. * @author mrdoob / http://mrdoob.com/
  21469. * @author WestLangley / http://github.com/WestLangley
  21470. */
  21471. THREE.DirectionalLightHelper = function ( light, size ) {
  21472. THREE.Object3D.call( this );
  21473. this.light = light;
  21474. this.light.updateMatrixWorld();
  21475. this.matrix = light.matrixWorld;
  21476. this.matrixAutoUpdate = false;
  21477. size = size || 1;
  21478. var geometry = new THREE.Geometry();
  21479. geometry.vertices.push(
  21480. new THREE.Vector3( - size, size, 0 ),
  21481. new THREE.Vector3( size, size, 0 ),
  21482. new THREE.Vector3( size, - size, 0 ),
  21483. new THREE.Vector3( - size, - size, 0 ),
  21484. new THREE.Vector3( - size, size, 0 )
  21485. );
  21486. var material = new THREE.LineBasicMaterial( { fog: false } );
  21487. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21488. this.lightPlane = new THREE.Line( geometry, material );
  21489. this.add( this.lightPlane );
  21490. geometry = new THREE.Geometry();
  21491. geometry.vertices.push(
  21492. new THREE.Vector3(),
  21493. new THREE.Vector3()
  21494. );
  21495. material = new THREE.LineBasicMaterial( { fog: false } );
  21496. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21497. this.targetLine = new THREE.Line( geometry, material );
  21498. this.add( this.targetLine );
  21499. this.update();
  21500. };
  21501. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21502. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  21503. THREE.DirectionalLightHelper.prototype.dispose = function () {
  21504. this.lightPlane.geometry.dispose();
  21505. this.lightPlane.material.dispose();
  21506. this.targetLine.geometry.dispose();
  21507. this.targetLine.material.dispose();
  21508. };
  21509. THREE.DirectionalLightHelper.prototype.update = function () {
  21510. var v1 = new THREE.Vector3();
  21511. var v2 = new THREE.Vector3();
  21512. var v3 = new THREE.Vector3();
  21513. return function () {
  21514. v1.setFromMatrixPosition( this.light.matrixWorld );
  21515. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21516. v3.subVectors( v2, v1 );
  21517. this.lightPlane.lookAt( v3 );
  21518. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21519. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  21520. this.targetLine.geometry.verticesNeedUpdate = true;
  21521. this.targetLine.material.color.copy( this.lightPlane.material.color );
  21522. };
  21523. }();
  21524. // File:src/extras/helpers/EdgesHelper.js
  21525. /**
  21526. * @author WestLangley / http://github.com/WestLangley
  21527. * @param object THREE.Mesh whose geometry will be used
  21528. * @param hex line color
  21529. * @param thresholdAngle the minimum angle (in degrees),
  21530. * between the face normals of adjacent faces,
  21531. * that is required to render an edge. A value of 10 means
  21532. * an edge is only rendered if the angle is at least 10 degrees.
  21533. */
  21534. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  21535. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21536. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  21537. this.matrix = object.matrixWorld;
  21538. this.matrixAutoUpdate = false;
  21539. };
  21540. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21541. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  21542. // File:src/extras/helpers/FaceNormalsHelper.js
  21543. /**
  21544. * @author mrdoob / http://mrdoob.com/
  21545. * @author WestLangley / http://github.com/WestLangley
  21546. */
  21547. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  21548. // FaceNormalsHelper only supports THREE.Geometry
  21549. this.object = object;
  21550. this.size = ( size !== undefined ) ? size : 1;
  21551. var color = ( hex !== undefined ) ? hex : 0xffff00;
  21552. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21553. //
  21554. var nNormals = 0;
  21555. var objGeometry = this.object.geometry;
  21556. if ( objGeometry instanceof THREE.Geometry ) {
  21557. nNormals = objGeometry.faces.length;
  21558. } else {
  21559. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  21560. }
  21561. //
  21562. var geometry = new THREE.BufferGeometry();
  21563. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21564. geometry.addAttribute( 'position', positions );
  21565. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21566. //
  21567. this.matrixAutoUpdate = false;
  21568. this.update();
  21569. };
  21570. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21571. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  21572. THREE.FaceNormalsHelper.prototype.update = ( function () {
  21573. var v1 = new THREE.Vector3();
  21574. var v2 = new THREE.Vector3();
  21575. var normalMatrix = new THREE.Matrix3();
  21576. return function update() {
  21577. this.object.updateMatrixWorld( true );
  21578. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21579. var matrixWorld = this.object.matrixWorld;
  21580. var position = this.geometry.attributes.position;
  21581. //
  21582. var objGeometry = this.object.geometry;
  21583. var vertices = objGeometry.vertices;
  21584. var faces = objGeometry.faces;
  21585. var idx = 0;
  21586. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21587. var face = faces[ i ];
  21588. var normal = face.normal;
  21589. v1.copy( vertices[ face.a ] )
  21590. .add( vertices[ face.b ] )
  21591. .add( vertices[ face.c ] )
  21592. .divideScalar( 3 )
  21593. .applyMatrix4( matrixWorld );
  21594. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21595. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21596. idx = idx + 1;
  21597. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21598. idx = idx + 1;
  21599. }
  21600. position.needsUpdate = true;
  21601. return this;
  21602. }
  21603. }() );
  21604. // File:src/extras/helpers/GridHelper.js
  21605. /**
  21606. * @author mrdoob / http://mrdoob.com/
  21607. */
  21608. THREE.GridHelper = function ( size, step ) {
  21609. var geometry = new THREE.Geometry();
  21610. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21611. this.color1 = new THREE.Color( 0x444444 );
  21612. this.color2 = new THREE.Color( 0x888888 );
  21613. for ( var i = - size; i <= size; i += step ) {
  21614. geometry.vertices.push(
  21615. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  21616. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  21617. );
  21618. var color = i === 0 ? this.color1 : this.color2;
  21619. geometry.colors.push( color, color, color, color );
  21620. }
  21621. THREE.LineSegments.call( this, geometry, material );
  21622. };
  21623. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21624. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  21625. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  21626. this.color1.set( colorCenterLine );
  21627. this.color2.set( colorGrid );
  21628. this.geometry.colorsNeedUpdate = true;
  21629. };
  21630. // File:src/extras/helpers/HemisphereLightHelper.js
  21631. /**
  21632. * @author alteredq / http://alteredqualia.com/
  21633. * @author mrdoob / http://mrdoob.com/
  21634. */
  21635. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  21636. THREE.Object3D.call( this );
  21637. this.light = light;
  21638. this.light.updateMatrixWorld();
  21639. this.matrix = light.matrixWorld;
  21640. this.matrixAutoUpdate = false;
  21641. this.colors = [ new THREE.Color(), new THREE.Color() ];
  21642. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21643. geometry.rotateX( - Math.PI / 2 );
  21644. for ( var i = 0, il = 8; i < il; i ++ ) {
  21645. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  21646. }
  21647. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  21648. this.lightSphere = new THREE.Mesh( geometry, material );
  21649. this.add( this.lightSphere );
  21650. this.update();
  21651. };
  21652. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21653. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  21654. THREE.HemisphereLightHelper.prototype.dispose = function () {
  21655. this.lightSphere.geometry.dispose();
  21656. this.lightSphere.material.dispose();
  21657. };
  21658. THREE.HemisphereLightHelper.prototype.update = function () {
  21659. var vector = new THREE.Vector3();
  21660. return function () {
  21661. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  21662. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  21663. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  21664. this.lightSphere.geometry.colorsNeedUpdate = true;
  21665. }
  21666. }();
  21667. // File:src/extras/helpers/PointLightHelper.js
  21668. /**
  21669. * @author alteredq / http://alteredqualia.com/
  21670. * @author mrdoob / http://mrdoob.com/
  21671. */
  21672. THREE.PointLightHelper = function ( light, sphereSize ) {
  21673. this.light = light;
  21674. this.light.updateMatrixWorld();
  21675. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21676. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21677. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21678. THREE.Mesh.call( this, geometry, material );
  21679. this.matrix = this.light.matrixWorld;
  21680. this.matrixAutoUpdate = false;
  21681. /*
  21682. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21683. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21684. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21685. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21686. var d = light.distance;
  21687. if ( d === 0.0 ) {
  21688. this.lightDistance.visible = false;
  21689. } else {
  21690. this.lightDistance.scale.set( d, d, d );
  21691. }
  21692. this.add( this.lightDistance );
  21693. */
  21694. };
  21695. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  21696. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  21697. THREE.PointLightHelper.prototype.dispose = function () {
  21698. this.geometry.dispose();
  21699. this.material.dispose();
  21700. };
  21701. THREE.PointLightHelper.prototype.update = function () {
  21702. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21703. /*
  21704. var d = this.light.distance;
  21705. if ( d === 0.0 ) {
  21706. this.lightDistance.visible = false;
  21707. } else {
  21708. this.lightDistance.visible = true;
  21709. this.lightDistance.scale.set( d, d, d );
  21710. }
  21711. */
  21712. };
  21713. // File:src/extras/helpers/SkeletonHelper.js
  21714. /**
  21715. * @author Sean Griffin / http://twitter.com/sgrif
  21716. * @author Michael Guerrero / http://realitymeltdown.com
  21717. * @author mrdoob / http://mrdoob.com/
  21718. * @author ikerr / http://verold.com
  21719. */
  21720. THREE.SkeletonHelper = function ( object ) {
  21721. this.bones = this.getBoneList( object );
  21722. var geometry = new THREE.Geometry();
  21723. for ( var i = 0; i < this.bones.length; i ++ ) {
  21724. var bone = this.bones[ i ];
  21725. if ( bone.parent instanceof THREE.Bone ) {
  21726. geometry.vertices.push( new THREE.Vector3() );
  21727. geometry.vertices.push( new THREE.Vector3() );
  21728. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  21729. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  21730. }
  21731. }
  21732. geometry.dynamic = true;
  21733. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  21734. THREE.LineSegments.call( this, geometry, material );
  21735. this.root = object;
  21736. this.matrix = object.matrixWorld;
  21737. this.matrixAutoUpdate = false;
  21738. this.update();
  21739. };
  21740. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21741. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  21742. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  21743. var boneList = [];
  21744. if ( object instanceof THREE.Bone ) {
  21745. boneList.push( object );
  21746. }
  21747. for ( var i = 0; i < object.children.length; i ++ ) {
  21748. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  21749. }
  21750. return boneList;
  21751. };
  21752. THREE.SkeletonHelper.prototype.update = function () {
  21753. var geometry = this.geometry;
  21754. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  21755. var boneMatrix = new THREE.Matrix4();
  21756. var j = 0;
  21757. for ( var i = 0; i < this.bones.length; i ++ ) {
  21758. var bone = this.bones[ i ];
  21759. if ( bone.parent instanceof THREE.Bone ) {
  21760. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  21761. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  21762. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  21763. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  21764. j += 2;
  21765. }
  21766. }
  21767. geometry.verticesNeedUpdate = true;
  21768. geometry.computeBoundingSphere();
  21769. };
  21770. // File:src/extras/helpers/SpotLightHelper.js
  21771. /**
  21772. * @author alteredq / http://alteredqualia.com/
  21773. * @author mrdoob / http://mrdoob.com/
  21774. * @author WestLangley / http://github.com/WestLangley
  21775. */
  21776. THREE.SpotLightHelper = function ( light ) {
  21777. THREE.Object3D.call( this );
  21778. this.light = light;
  21779. this.light.updateMatrixWorld();
  21780. this.matrix = light.matrixWorld;
  21781. this.matrixAutoUpdate = false;
  21782. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  21783. geometry.translate( 0, - 0.5, 0 );
  21784. geometry.rotateX( - Math.PI / 2 );
  21785. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21786. this.cone = new THREE.Mesh( geometry, material );
  21787. this.add( this.cone );
  21788. this.update();
  21789. };
  21790. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21791. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  21792. THREE.SpotLightHelper.prototype.dispose = function () {
  21793. this.cone.geometry.dispose();
  21794. this.cone.material.dispose();
  21795. };
  21796. THREE.SpotLightHelper.prototype.update = function () {
  21797. var vector = new THREE.Vector3();
  21798. var vector2 = new THREE.Vector3();
  21799. return function () {
  21800. var coneLength = this.light.distance ? this.light.distance : 10000;
  21801. var coneWidth = coneLength * Math.tan( this.light.angle );
  21802. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21803. vector.setFromMatrixPosition( this.light.matrixWorld );
  21804. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  21805. this.cone.lookAt( vector2.sub( vector ) );
  21806. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21807. };
  21808. }();
  21809. // File:src/extras/helpers/VertexNormalsHelper.js
  21810. /**
  21811. * @author mrdoob / http://mrdoob.com/
  21812. * @author WestLangley / http://github.com/WestLangley
  21813. */
  21814. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  21815. this.object = object;
  21816. this.size = ( size !== undefined ) ? size : 1;
  21817. var color = ( hex !== undefined ) ? hex : 0xff0000;
  21818. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21819. //
  21820. var nNormals = 0;
  21821. var objGeometry = this.object.geometry;
  21822. if ( objGeometry instanceof THREE.Geometry ) {
  21823. nNormals = objGeometry.faces.length * 3;
  21824. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21825. nNormals = objGeometry.attributes.normal.count
  21826. }
  21827. //
  21828. var geometry = new THREE.BufferGeometry();
  21829. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21830. geometry.addAttribute( 'position', positions );
  21831. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21832. //
  21833. this.matrixAutoUpdate = false;
  21834. this.update();
  21835. };
  21836. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21837. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  21838. THREE.VertexNormalsHelper.prototype.update = ( function () {
  21839. var v1 = new THREE.Vector3();
  21840. var v2 = new THREE.Vector3();
  21841. var normalMatrix = new THREE.Matrix3();
  21842. return function update() {
  21843. var keys = [ 'a', 'b', 'c' ];
  21844. this.object.updateMatrixWorld( true );
  21845. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21846. var matrixWorld = this.object.matrixWorld;
  21847. var position = this.geometry.attributes.position;
  21848. //
  21849. var objGeometry = this.object.geometry;
  21850. if ( objGeometry instanceof THREE.Geometry ) {
  21851. var vertices = objGeometry.vertices;
  21852. var faces = objGeometry.faces;
  21853. var idx = 0;
  21854. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21855. var face = faces[ i ];
  21856. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  21857. var vertex = vertices[ face[ keys[ j ] ] ];
  21858. var normal = face.vertexNormals[ j ];
  21859. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21860. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21861. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21862. idx = idx + 1;
  21863. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21864. idx = idx + 1;
  21865. }
  21866. }
  21867. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21868. var objPos = objGeometry.attributes.position;
  21869. var objNorm = objGeometry.attributes.normal;
  21870. var idx = 0;
  21871. // for simplicity, ignore index and drawcalls, and render every normal
  21872. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21873. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21874. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  21875. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21876. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21877. idx = idx + 1;
  21878. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21879. idx = idx + 1;
  21880. }
  21881. }
  21882. position.needsUpdate = true;
  21883. return this;
  21884. }
  21885. }() );
  21886. // File:src/extras/helpers/WireframeHelper.js
  21887. /**
  21888. * @author mrdoob / http://mrdoob.com/
  21889. */
  21890. THREE.WireframeHelper = function ( object, hex ) {
  21891. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21892. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21893. this.matrix = object.matrixWorld;
  21894. this.matrixAutoUpdate = false;
  21895. };
  21896. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21897. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21898. // File:src/extras/objects/ImmediateRenderObject.js
  21899. /**
  21900. * @author alteredq / http://alteredqualia.com/
  21901. */
  21902. THREE.ImmediateRenderObject = function ( material ) {
  21903. THREE.Object3D.call( this );
  21904. this.material = material;
  21905. this.render = function ( renderCallback ) {};
  21906. };
  21907. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21908. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21909. // File:src/extras/objects/MorphBlendMesh.js
  21910. /**
  21911. * @author alteredq / http://alteredqualia.com/
  21912. */
  21913. THREE.MorphBlendMesh = function( geometry, material ) {
  21914. THREE.Mesh.call( this, geometry, material );
  21915. this.animationsMap = {};
  21916. this.animationsList = [];
  21917. // prepare default animation
  21918. // (all frames played together in 1 second)
  21919. var numFrames = this.geometry.morphTargets.length;
  21920. var name = "__default";
  21921. var startFrame = 0;
  21922. var endFrame = numFrames - 1;
  21923. var fps = numFrames / 1;
  21924. this.createAnimation( name, startFrame, endFrame, fps );
  21925. this.setAnimationWeight( name, 1 );
  21926. };
  21927. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21928. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21929. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21930. var animation = {
  21931. start: start,
  21932. end: end,
  21933. length: end - start + 1,
  21934. fps: fps,
  21935. duration: ( end - start ) / fps,
  21936. lastFrame: 0,
  21937. currentFrame: 0,
  21938. active: false,
  21939. time: 0,
  21940. direction: 1,
  21941. weight: 1,
  21942. directionBackwards: false,
  21943. mirroredLoop: false
  21944. };
  21945. this.animationsMap[ name ] = animation;
  21946. this.animationsList.push( animation );
  21947. };
  21948. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21949. var pattern = /([a-z]+)_?(\d+)/;
  21950. var firstAnimation, frameRanges = {};
  21951. var geometry = this.geometry;
  21952. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21953. var morph = geometry.morphTargets[ i ];
  21954. var chunks = morph.name.match( pattern );
  21955. if ( chunks && chunks.length > 1 ) {
  21956. var name = chunks[ 1 ];
  21957. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21958. var range = frameRanges[ name ];
  21959. if ( i < range.start ) range.start = i;
  21960. if ( i > range.end ) range.end = i;
  21961. if ( ! firstAnimation ) firstAnimation = name;
  21962. }
  21963. }
  21964. for ( var name in frameRanges ) {
  21965. var range = frameRanges[ name ];
  21966. this.createAnimation( name, range.start, range.end, fps );
  21967. }
  21968. this.firstAnimation = firstAnimation;
  21969. };
  21970. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21971. var animation = this.animationsMap[ name ];
  21972. if ( animation ) {
  21973. animation.direction = 1;
  21974. animation.directionBackwards = false;
  21975. }
  21976. };
  21977. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21978. var animation = this.animationsMap[ name ];
  21979. if ( animation ) {
  21980. animation.direction = - 1;
  21981. animation.directionBackwards = true;
  21982. }
  21983. };
  21984. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21985. var animation = this.animationsMap[ name ];
  21986. if ( animation ) {
  21987. animation.fps = fps;
  21988. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21989. }
  21990. };
  21991. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21992. var animation = this.animationsMap[ name ];
  21993. if ( animation ) {
  21994. animation.duration = duration;
  21995. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21996. }
  21997. };
  21998. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21999. var animation = this.animationsMap[ name ];
  22000. if ( animation ) {
  22001. animation.weight = weight;
  22002. }
  22003. };
  22004. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  22005. var animation = this.animationsMap[ name ];
  22006. if ( animation ) {
  22007. animation.time = time;
  22008. }
  22009. };
  22010. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  22011. var time = 0;
  22012. var animation = this.animationsMap[ name ];
  22013. if ( animation ) {
  22014. time = animation.time;
  22015. }
  22016. return time;
  22017. };
  22018. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  22019. var duration = - 1;
  22020. var animation = this.animationsMap[ name ];
  22021. if ( animation ) {
  22022. duration = animation.duration;
  22023. }
  22024. return duration;
  22025. };
  22026. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  22027. var animation = this.animationsMap[ name ];
  22028. if ( animation ) {
  22029. animation.time = 0;
  22030. animation.active = true;
  22031. } else {
  22032. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  22033. }
  22034. };
  22035. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  22036. var animation = this.animationsMap[ name ];
  22037. if ( animation ) {
  22038. animation.active = false;
  22039. }
  22040. };
  22041. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  22042. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  22043. var animation = this.animationsList[ i ];
  22044. if ( ! animation.active ) continue;
  22045. var frameTime = animation.duration / animation.length;
  22046. animation.time += animation.direction * delta;
  22047. if ( animation.mirroredLoop ) {
  22048. if ( animation.time > animation.duration || animation.time < 0 ) {
  22049. animation.direction *= - 1;
  22050. if ( animation.time > animation.duration ) {
  22051. animation.time = animation.duration;
  22052. animation.directionBackwards = true;
  22053. }
  22054. if ( animation.time < 0 ) {
  22055. animation.time = 0;
  22056. animation.directionBackwards = false;
  22057. }
  22058. }
  22059. } else {
  22060. animation.time = animation.time % animation.duration;
  22061. if ( animation.time < 0 ) animation.time += animation.duration;
  22062. }
  22063. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  22064. var weight = animation.weight;
  22065. if ( keyframe !== animation.currentFrame ) {
  22066. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  22067. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  22068. this.morphTargetInfluences[ keyframe ] = 0;
  22069. animation.lastFrame = animation.currentFrame;
  22070. animation.currentFrame = keyframe;
  22071. }
  22072. var mix = ( animation.time % frameTime ) / frameTime;
  22073. if ( animation.directionBackwards ) mix = 1 - mix;
  22074. if ( animation.currentFrame !== animation.lastFrame ) {
  22075. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  22076. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  22077. } else {
  22078. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  22079. }
  22080. }
  22081. };