three.js 792 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942359433594435945359463594735948359493595035951359523595335954359553595635957359583595935960359613596235963359643596535966359673596835969359703597135972359733597435975359763597735978359793598035981359823598335984359853598635987359883598935990359913599235993359943599535996359973599835999360003600136002360033600436005360063600736008360093601036011360123601336014360153601636017360183601936020360213602236023360243602536026360273602836029360303603136032360333603436035360363603736038360393604036041360423604336044360453604636047360483604936050360513605236053360543605536056360573605836059360603606136062360633606436065360663606736068360693607036071360723607336074360753607636077360783607936080360813608236083360843608536086360873608836089360903609136092360933609436095360963609736098360993610036101361023610336104361053610636107361083610936110361113611236113
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '73' };
  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. //
  52. if ( Number.EPSILON === undefined ) {
  53. Number.EPSILON = Math.pow( 2, -52 );
  54. }
  55. //
  56. if ( Math.sign === undefined ) {
  57. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  58. Math.sign = function ( x ) {
  59. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  60. };
  61. }
  62. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  63. // Missing in IE9-11.
  64. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  65. Object.defineProperty( Function.prototype, 'name', {
  66. get: function () {
  67. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  68. }
  69. } );
  70. }
  71. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  72. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  73. // GL STATE CONSTANTS
  74. THREE.CullFaceNone = 0;
  75. THREE.CullFaceBack = 1;
  76. THREE.CullFaceFront = 2;
  77. THREE.CullFaceFrontBack = 3;
  78. THREE.FrontFaceDirectionCW = 0;
  79. THREE.FrontFaceDirectionCCW = 1;
  80. // SHADOWING TYPES
  81. THREE.BasicShadowMap = 0;
  82. THREE.PCFShadowMap = 1;
  83. THREE.PCFSoftShadowMap = 2;
  84. // MATERIAL CONSTANTS
  85. // side
  86. THREE.FrontSide = 0;
  87. THREE.BackSide = 1;
  88. THREE.DoubleSide = 2;
  89. // shading
  90. THREE.FlatShading = 1;
  91. THREE.SmoothShading = 2;
  92. // colors
  93. THREE.NoColors = 0;
  94. THREE.FaceColors = 1;
  95. THREE.VertexColors = 2;
  96. // blending modes
  97. THREE.NoBlending = 0;
  98. THREE.NormalBlending = 1;
  99. THREE.AdditiveBlending = 2;
  100. THREE.SubtractiveBlending = 3;
  101. THREE.MultiplyBlending = 4;
  102. THREE.CustomBlending = 5;
  103. // custom blending equations
  104. // (numbers start from 100 not to clash with other
  105. // mappings to OpenGL constants defined in Texture.js)
  106. THREE.AddEquation = 100;
  107. THREE.SubtractEquation = 101;
  108. THREE.ReverseSubtractEquation = 102;
  109. THREE.MinEquation = 103;
  110. THREE.MaxEquation = 104;
  111. // custom blending destination factors
  112. THREE.ZeroFactor = 200;
  113. THREE.OneFactor = 201;
  114. THREE.SrcColorFactor = 202;
  115. THREE.OneMinusSrcColorFactor = 203;
  116. THREE.SrcAlphaFactor = 204;
  117. THREE.OneMinusSrcAlphaFactor = 205;
  118. THREE.DstAlphaFactor = 206;
  119. THREE.OneMinusDstAlphaFactor = 207;
  120. // custom blending source factors
  121. //THREE.ZeroFactor = 200;
  122. //THREE.OneFactor = 201;
  123. //THREE.SrcAlphaFactor = 204;
  124. //THREE.OneMinusSrcAlphaFactor = 205;
  125. //THREE.DstAlphaFactor = 206;
  126. //THREE.OneMinusDstAlphaFactor = 207;
  127. THREE.DstColorFactor = 208;
  128. THREE.OneMinusDstColorFactor = 209;
  129. THREE.SrcAlphaSaturateFactor = 210;
  130. // depth modes
  131. THREE.NeverDepth = 0;
  132. THREE.AlwaysDepth = 1;
  133. THREE.LessDepth = 2;
  134. THREE.LessEqualDepth = 3;
  135. THREE.EqualDepth = 4;
  136. THREE.GreaterEqualDepth = 5;
  137. THREE.GreaterDepth = 6;
  138. THREE.NotEqualDepth = 7;
  139. // TEXTURE CONSTANTS
  140. THREE.MultiplyOperation = 0;
  141. THREE.MixOperation = 1;
  142. THREE.AddOperation = 2;
  143. // Mapping modes
  144. THREE.UVMapping = 300;
  145. THREE.CubeReflectionMapping = 301;
  146. THREE.CubeRefractionMapping = 302;
  147. THREE.EquirectangularReflectionMapping = 303;
  148. THREE.EquirectangularRefractionMapping = 304;
  149. THREE.SphericalReflectionMapping = 305;
  150. // Wrapping modes
  151. THREE.RepeatWrapping = 1000;
  152. THREE.ClampToEdgeWrapping = 1001;
  153. THREE.MirroredRepeatWrapping = 1002;
  154. // Filters
  155. THREE.NearestFilter = 1003;
  156. THREE.NearestMipMapNearestFilter = 1004;
  157. THREE.NearestMipMapLinearFilter = 1005;
  158. THREE.LinearFilter = 1006;
  159. THREE.LinearMipMapNearestFilter = 1007;
  160. THREE.LinearMipMapLinearFilter = 1008;
  161. // Data types
  162. THREE.UnsignedByteType = 1009;
  163. THREE.ByteType = 1010;
  164. THREE.ShortType = 1011;
  165. THREE.UnsignedShortType = 1012;
  166. THREE.IntType = 1013;
  167. THREE.UnsignedIntType = 1014;
  168. THREE.FloatType = 1015;
  169. THREE.HalfFloatType = 1025;
  170. // Pixel types
  171. //THREE.UnsignedByteType = 1009;
  172. THREE.UnsignedShort4444Type = 1016;
  173. THREE.UnsignedShort5551Type = 1017;
  174. THREE.UnsignedShort565Type = 1018;
  175. // Pixel formats
  176. THREE.AlphaFormat = 1019;
  177. THREE.RGBFormat = 1020;
  178. THREE.RGBAFormat = 1021;
  179. THREE.LuminanceFormat = 1022;
  180. THREE.LuminanceAlphaFormat = 1023;
  181. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  182. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  183. // DDS / ST3C Compressed texture formats
  184. THREE.RGB_S3TC_DXT1_Format = 2001;
  185. THREE.RGBA_S3TC_DXT1_Format = 2002;
  186. THREE.RGBA_S3TC_DXT3_Format = 2003;
  187. THREE.RGBA_S3TC_DXT5_Format = 2004;
  188. // PVRTC compressed texture formats
  189. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  190. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  191. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  192. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  193. // Loop styles for AnimationAction
  194. THREE.LoopOnce = 2200;
  195. THREE.LoopRepeat = 2201;
  196. THREE.LoopPingPong = 2202;
  197. // DEPRECATED
  198. THREE.Projector = function () {
  199. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  200. this.projectVector = function ( vector, camera ) {
  201. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  202. vector.project( camera );
  203. };
  204. this.unprojectVector = function ( vector, camera ) {
  205. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  206. vector.unproject( camera );
  207. };
  208. this.pickingRay = function ( vector, camera ) {
  209. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  210. };
  211. };
  212. THREE.CanvasRenderer = function () {
  213. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  214. this.domElement = document.createElement( 'canvas' );
  215. this.clear = function () {};
  216. this.render = function () {};
  217. this.setClearColor = function () {};
  218. this.setSize = function () {};
  219. };
  220. // File:src/math/Color.js
  221. /**
  222. * @author mrdoob / http://mrdoob.com/
  223. */
  224. THREE.Color = function ( color ) {
  225. if ( arguments.length === 3 ) {
  226. return this.fromArray( arguments );
  227. }
  228. return this.set( color );
  229. };
  230. THREE.Color.prototype = {
  231. constructor: THREE.Color,
  232. r: 1, g: 1, b: 1,
  233. set: function ( value ) {
  234. if ( value instanceof THREE.Color ) {
  235. this.copy( value );
  236. } else if ( typeof value === 'number' ) {
  237. this.setHex( value );
  238. } else if ( typeof value === 'string' ) {
  239. this.setStyle( value );
  240. }
  241. return this;
  242. },
  243. setHex: function ( hex ) {
  244. hex = Math.floor( hex );
  245. this.r = ( hex >> 16 & 255 ) / 255;
  246. this.g = ( hex >> 8 & 255 ) / 255;
  247. this.b = ( hex & 255 ) / 255;
  248. return this;
  249. },
  250. setRGB: function ( r, g, b ) {
  251. this.r = r;
  252. this.g = g;
  253. this.b = b;
  254. return this;
  255. },
  256. setHSL: function () {
  257. function hue2rgb( p, q, t ) {
  258. if ( t < 0 ) t += 1;
  259. if ( t > 1 ) t -= 1;
  260. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  261. if ( t < 1 / 2 ) return q;
  262. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  263. return p;
  264. }
  265. return function ( h, s, l ) {
  266. // h,s,l ranges are in 0.0 - 1.0
  267. h = THREE.Math.euclideanModulo( h, 1 );
  268. s = THREE.Math.clamp( s, 0, 1 );
  269. l = THREE.Math.clamp( l, 0, 1 );
  270. if ( s === 0 ) {
  271. this.r = this.g = this.b = l;
  272. } else {
  273. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  274. var q = ( 2 * l ) - p;
  275. this.r = hue2rgb( q, p, h + 1 / 3 );
  276. this.g = hue2rgb( q, p, h );
  277. this.b = hue2rgb( q, p, h - 1 / 3 );
  278. }
  279. return this;
  280. };
  281. }(),
  282. setStyle: function ( style ) {
  283. function handleAlpha( string ) {
  284. if ( string === undefined ) return;
  285. if ( parseFloat( string ) < 1 ) {
  286. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  287. }
  288. }
  289. var m;
  290. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  291. // rgb / hsl
  292. var color;
  293. var name = m[ 1 ];
  294. var components = m[ 2 ];
  295. switch ( name ) {
  296. case 'rgb':
  297. case 'rgba':
  298. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  299. // rgb(255,0,0) rgba(255,0,0,0.5)
  300. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  301. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  302. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  303. handleAlpha( color[ 5 ] );
  304. return this;
  305. }
  306. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  307. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  308. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  309. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  310. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  311. handleAlpha( color[ 5 ] );
  312. return this;
  313. }
  314. break;
  315. case 'hsl':
  316. case 'hsla':
  317. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  318. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  319. var h = parseFloat( color[ 1 ] ) / 360;
  320. var s = parseInt( color[ 2 ], 10 ) / 100;
  321. var l = parseInt( color[ 3 ], 10 ) / 100;
  322. handleAlpha( color[ 5 ] );
  323. return this.setHSL( h, s, l );
  324. }
  325. break;
  326. }
  327. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  328. // hex color
  329. var hex = m[ 1 ];
  330. var size = hex.length;
  331. if ( size === 3 ) {
  332. // #ff0
  333. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  334. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  335. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  336. return this;
  337. } else if ( size === 6 ) {
  338. // #ff0000
  339. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  340. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  341. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  342. return this;
  343. }
  344. }
  345. if ( style && style.length > 0 ) {
  346. // color keywords
  347. var hex = THREE.ColorKeywords[ style ];
  348. if ( hex !== undefined ) {
  349. // red
  350. this.setHex( hex );
  351. } else {
  352. // unknown color
  353. console.warn( 'THREE.Color: Unknown color ' + style );
  354. }
  355. }
  356. return this;
  357. },
  358. clone: function () {
  359. return new this.constructor( this.r, this.g, this.b );
  360. },
  361. copy: function ( color ) {
  362. this.r = color.r;
  363. this.g = color.g;
  364. this.b = color.b;
  365. return this;
  366. },
  367. copyGammaToLinear: function ( color, gammaFactor ) {
  368. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  369. this.r = Math.pow( color.r, gammaFactor );
  370. this.g = Math.pow( color.g, gammaFactor );
  371. this.b = Math.pow( color.b, gammaFactor );
  372. return this;
  373. },
  374. copyLinearToGamma: function ( color, gammaFactor ) {
  375. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  376. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  377. this.r = Math.pow( color.r, safeInverse );
  378. this.g = Math.pow( color.g, safeInverse );
  379. this.b = Math.pow( color.b, safeInverse );
  380. return this;
  381. },
  382. convertGammaToLinear: function () {
  383. var r = this.r, g = this.g, b = this.b;
  384. this.r = r * r;
  385. this.g = g * g;
  386. this.b = b * b;
  387. return this;
  388. },
  389. convertLinearToGamma: function () {
  390. this.r = Math.sqrt( this.r );
  391. this.g = Math.sqrt( this.g );
  392. this.b = Math.sqrt( this.b );
  393. return this;
  394. },
  395. getHex: function () {
  396. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  397. },
  398. getHexString: function () {
  399. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  400. },
  401. getHSL: function ( optionalTarget ) {
  402. // h,s,l ranges are in 0.0 - 1.0
  403. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  404. var r = this.r, g = this.g, b = this.b;
  405. var max = Math.max( r, g, b );
  406. var min = Math.min( r, g, b );
  407. var hue, saturation;
  408. var lightness = ( min + max ) / 2.0;
  409. if ( min === max ) {
  410. hue = 0;
  411. saturation = 0;
  412. } else {
  413. var delta = max - min;
  414. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  415. switch ( max ) {
  416. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  417. case g: hue = ( b - r ) / delta + 2; break;
  418. case b: hue = ( r - g ) / delta + 4; break;
  419. }
  420. hue /= 6;
  421. }
  422. hsl.h = hue;
  423. hsl.s = saturation;
  424. hsl.l = lightness;
  425. return hsl;
  426. },
  427. getStyle: function () {
  428. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  429. },
  430. offsetHSL: function ( h, s, l ) {
  431. var hsl = this.getHSL();
  432. hsl.h += h; hsl.s += s; hsl.l += l;
  433. this.setHSL( hsl.h, hsl.s, hsl.l );
  434. return this;
  435. },
  436. add: function ( color ) {
  437. this.r += color.r;
  438. this.g += color.g;
  439. this.b += color.b;
  440. return this;
  441. },
  442. addColors: function ( color1, color2 ) {
  443. this.r = color1.r + color2.r;
  444. this.g = color1.g + color2.g;
  445. this.b = color1.b + color2.b;
  446. return this;
  447. },
  448. addScalar: function ( s ) {
  449. this.r += s;
  450. this.g += s;
  451. this.b += s;
  452. return this;
  453. },
  454. multiply: function ( color ) {
  455. this.r *= color.r;
  456. this.g *= color.g;
  457. this.b *= color.b;
  458. return this;
  459. },
  460. multiplyScalar: function ( s ) {
  461. this.r *= s;
  462. this.g *= s;
  463. this.b *= s;
  464. return this;
  465. },
  466. lerp: function ( color, alpha ) {
  467. this.r += ( color.r - this.r ) * alpha;
  468. this.g += ( color.g - this.g ) * alpha;
  469. this.b += ( color.b - this.b ) * alpha;
  470. return this;
  471. },
  472. equals: function ( c ) {
  473. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  474. },
  475. fromArray: function ( array, offset ) {
  476. if ( offset === undefined ) offset = 0;
  477. this.r = array[ offset ];
  478. this.g = array[ offset + 1 ];
  479. this.b = array[ offset + 2 ];
  480. return this;
  481. },
  482. toArray: function ( array, offset ) {
  483. if ( array === undefined ) array = [];
  484. if ( offset === undefined ) offset = 0;
  485. array[ offset ] = this.r;
  486. array[ offset + 1 ] = this.g;
  487. array[ offset + 2 ] = this.b;
  488. return array;
  489. }
  490. };
  491. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  492. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  493. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  494. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  495. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  496. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  497. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  498. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  499. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  500. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  501. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  502. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  503. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  504. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  505. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  506. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  507. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  508. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  509. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  510. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  511. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  512. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  513. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  514. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  515. // File:src/math/Quaternion.js
  516. /**
  517. * @author mikael emtinger / http://gomo.se/
  518. * @author alteredq / http://alteredqualia.com/
  519. * @author WestLangley / http://github.com/WestLangley
  520. * @author bhouston / http://clara.io
  521. */
  522. THREE.Quaternion = function ( x, y, z, w ) {
  523. this._x = x || 0;
  524. this._y = y || 0;
  525. this._z = z || 0;
  526. this._w = ( w !== undefined ) ? w : 1;
  527. };
  528. THREE.Quaternion.prototype = {
  529. constructor: THREE.Quaternion,
  530. get x () {
  531. return this._x;
  532. },
  533. set x ( value ) {
  534. this._x = value;
  535. this.onChangeCallback();
  536. },
  537. get y () {
  538. return this._y;
  539. },
  540. set y ( value ) {
  541. this._y = value;
  542. this.onChangeCallback();
  543. },
  544. get z () {
  545. return this._z;
  546. },
  547. set z ( value ) {
  548. this._z = value;
  549. this.onChangeCallback();
  550. },
  551. get w () {
  552. return this._w;
  553. },
  554. set w ( value ) {
  555. this._w = value;
  556. this.onChangeCallback();
  557. },
  558. set: function ( x, y, z, w ) {
  559. this._x = x;
  560. this._y = y;
  561. this._z = z;
  562. this._w = w;
  563. this.onChangeCallback();
  564. return this;
  565. },
  566. clone: function () {
  567. return new this.constructor( this._x, this._y, this._z, this._w );
  568. },
  569. copy: function ( quaternion ) {
  570. this._x = quaternion.x;
  571. this._y = quaternion.y;
  572. this._z = quaternion.z;
  573. this._w = quaternion.w;
  574. this.onChangeCallback();
  575. return this;
  576. },
  577. setFromEuler: function ( euler, update ) {
  578. if ( euler instanceof THREE.Euler === false ) {
  579. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  580. }
  581. // http://www.mathworks.com/matlabcentral/fileexchange/
  582. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  583. // content/SpinCalc.m
  584. var c1 = Math.cos( euler._x / 2 );
  585. var c2 = Math.cos( euler._y / 2 );
  586. var c3 = Math.cos( euler._z / 2 );
  587. var s1 = Math.sin( euler._x / 2 );
  588. var s2 = Math.sin( euler._y / 2 );
  589. var s3 = Math.sin( euler._z / 2 );
  590. var order = euler.order;
  591. if ( order === 'XYZ' ) {
  592. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  593. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  594. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  595. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  596. } else if ( order === 'YXZ' ) {
  597. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  598. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  599. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  600. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  601. } else if ( order === 'ZXY' ) {
  602. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  603. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  604. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  605. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  606. } else if ( order === 'ZYX' ) {
  607. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  608. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  609. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  610. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  611. } else if ( order === 'YZX' ) {
  612. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  613. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  614. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  615. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  616. } else if ( order === 'XZY' ) {
  617. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  618. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  619. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  620. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  621. }
  622. if ( update !== false ) this.onChangeCallback();
  623. return this;
  624. },
  625. setFromAxisAngle: function ( axis, angle ) {
  626. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  627. // assumes axis is normalized
  628. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  629. this._x = axis.x * s;
  630. this._y = axis.y * s;
  631. this._z = axis.z * s;
  632. this._w = Math.cos( halfAngle );
  633. this.onChangeCallback();
  634. return this;
  635. },
  636. setFromRotationMatrix: function ( m ) {
  637. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  638. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  639. var te = m.elements,
  640. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  641. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  642. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  643. trace = m11 + m22 + m33,
  644. s;
  645. if ( trace > 0 ) {
  646. s = 0.5 / Math.sqrt( trace + 1.0 );
  647. this._w = 0.25 / s;
  648. this._x = ( m32 - m23 ) * s;
  649. this._y = ( m13 - m31 ) * s;
  650. this._z = ( m21 - m12 ) * s;
  651. } else if ( m11 > m22 && m11 > m33 ) {
  652. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  653. this._w = ( m32 - m23 ) / s;
  654. this._x = 0.25 * s;
  655. this._y = ( m12 + m21 ) / s;
  656. this._z = ( m13 + m31 ) / s;
  657. } else if ( m22 > m33 ) {
  658. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  659. this._w = ( m13 - m31 ) / s;
  660. this._x = ( m12 + m21 ) / s;
  661. this._y = 0.25 * s;
  662. this._z = ( m23 + m32 ) / s;
  663. } else {
  664. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  665. this._w = ( m21 - m12 ) / s;
  666. this._x = ( m13 + m31 ) / s;
  667. this._y = ( m23 + m32 ) / s;
  668. this._z = 0.25 * s;
  669. }
  670. this.onChangeCallback();
  671. return this;
  672. },
  673. setFromUnitVectors: function () {
  674. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  675. // assumes direction vectors vFrom and vTo are normalized
  676. var v1, r;
  677. var EPS = 0.000001;
  678. return function ( vFrom, vTo ) {
  679. if ( v1 === undefined ) v1 = new THREE.Vector3();
  680. r = vFrom.dot( vTo ) + 1;
  681. if ( r < EPS ) {
  682. r = 0;
  683. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  684. v1.set( - vFrom.y, vFrom.x, 0 );
  685. } else {
  686. v1.set( 0, - vFrom.z, vFrom.y );
  687. }
  688. } else {
  689. v1.crossVectors( vFrom, vTo );
  690. }
  691. this._x = v1.x;
  692. this._y = v1.y;
  693. this._z = v1.z;
  694. this._w = r;
  695. this.normalize();
  696. return this;
  697. }
  698. }(),
  699. inverse: function () {
  700. this.conjugate().normalize();
  701. return this;
  702. },
  703. conjugate: function () {
  704. this._x *= - 1;
  705. this._y *= - 1;
  706. this._z *= - 1;
  707. this.onChangeCallback();
  708. return this;
  709. },
  710. dot: function ( v ) {
  711. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  712. },
  713. lengthSq: function () {
  714. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  715. },
  716. length: function () {
  717. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  718. },
  719. normalize: function () {
  720. var l = this.length();
  721. if ( l === 0 ) {
  722. this._x = 0;
  723. this._y = 0;
  724. this._z = 0;
  725. this._w = 1;
  726. } else {
  727. l = 1 / l;
  728. this._x = this._x * l;
  729. this._y = this._y * l;
  730. this._z = this._z * l;
  731. this._w = this._w * l;
  732. }
  733. this.onChangeCallback();
  734. return this;
  735. },
  736. multiply: function ( q, p ) {
  737. if ( p !== undefined ) {
  738. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  739. return this.multiplyQuaternions( q, p );
  740. }
  741. return this.multiplyQuaternions( this, q );
  742. },
  743. multiplyQuaternions: function ( a, b ) {
  744. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  745. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  746. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  747. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  748. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  749. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  750. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  751. this.onChangeCallback();
  752. return this;
  753. },
  754. multiplyVector3: function ( vector ) {
  755. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  756. return vector.applyQuaternion( this );
  757. },
  758. slerp: function ( qb, t ) {
  759. if ( t === 0 ) return this;
  760. if ( t === 1 ) return this.copy( qb );
  761. var x = this._x, y = this._y, z = this._z, w = this._w;
  762. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  763. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  764. if ( cosHalfTheta < 0 ) {
  765. this._w = - qb._w;
  766. this._x = - qb._x;
  767. this._y = - qb._y;
  768. this._z = - qb._z;
  769. cosHalfTheta = - cosHalfTheta;
  770. } else {
  771. this.copy( qb );
  772. }
  773. if ( cosHalfTheta >= 1.0 ) {
  774. this._w = w;
  775. this._x = x;
  776. this._y = y;
  777. this._z = z;
  778. return this;
  779. }
  780. var halfTheta = Math.acos( cosHalfTheta );
  781. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  782. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  783. this._w = 0.5 * ( w + this._w );
  784. this._x = 0.5 * ( x + this._x );
  785. this._y = 0.5 * ( y + this._y );
  786. this._z = 0.5 * ( z + this._z );
  787. return this;
  788. }
  789. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  790. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  791. this._w = ( w * ratioA + this._w * ratioB );
  792. this._x = ( x * ratioA + this._x * ratioB );
  793. this._y = ( y * ratioA + this._y * ratioB );
  794. this._z = ( z * ratioA + this._z * ratioB );
  795. this.onChangeCallback();
  796. return this;
  797. },
  798. equals: function ( quaternion ) {
  799. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  800. },
  801. fromArray: function ( array, offset ) {
  802. if ( offset === undefined ) offset = 0;
  803. this._x = array[ offset ];
  804. this._y = array[ offset + 1 ];
  805. this._z = array[ offset + 2 ];
  806. this._w = array[ offset + 3 ];
  807. this.onChangeCallback();
  808. return this;
  809. },
  810. toArray: function ( array, offset ) {
  811. if ( array === undefined ) array = [];
  812. if ( offset === undefined ) offset = 0;
  813. array[ offset ] = this._x;
  814. array[ offset + 1 ] = this._y;
  815. array[ offset + 2 ] = this._z;
  816. array[ offset + 3 ] = this._w;
  817. return array;
  818. },
  819. onChange: function ( callback ) {
  820. this.onChangeCallback = callback;
  821. return this;
  822. },
  823. onChangeCallback: function () {}
  824. };
  825. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  826. return qm.copy( qa ).slerp( qb, t );
  827. };
  828. // File:src/math/Vector2.js
  829. /**
  830. * @author mrdoob / http://mrdoob.com/
  831. * @author philogb / http://blog.thejit.org/
  832. * @author egraether / http://egraether.com/
  833. * @author zz85 / http://www.lab4games.net/zz85/blog
  834. */
  835. THREE.Vector2 = function ( x, y ) {
  836. this.x = x || 0;
  837. this.y = y || 0;
  838. };
  839. THREE.Vector2.prototype = {
  840. constructor: THREE.Vector2,
  841. get width() { return this.x },
  842. set width( value ) { this.x = value },
  843. get height() { return this.y },
  844. set height( value ) { this.y = value },
  845. //
  846. set: function ( x, y ) {
  847. this.x = x;
  848. this.y = y;
  849. return this;
  850. },
  851. setX: function ( x ) {
  852. this.x = x;
  853. return this;
  854. },
  855. setY: function ( y ) {
  856. this.y = y;
  857. return this;
  858. },
  859. setComponent: function ( index, value ) {
  860. switch ( index ) {
  861. case 0: this.x = value; break;
  862. case 1: this.y = value; break;
  863. default: throw new Error( 'index is out of range: ' + index );
  864. }
  865. },
  866. getComponent: function ( index ) {
  867. switch ( index ) {
  868. case 0: return this.x;
  869. case 1: return this.y;
  870. default: throw new Error( 'index is out of range: ' + index );
  871. }
  872. },
  873. clone: function () {
  874. return new this.constructor( this.x, this.y );
  875. },
  876. copy: function ( v ) {
  877. this.x = v.x;
  878. this.y = v.y;
  879. return this;
  880. },
  881. add: function ( v, w ) {
  882. if ( w !== undefined ) {
  883. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  884. return this.addVectors( v, w );
  885. }
  886. this.x += v.x;
  887. this.y += v.y;
  888. return this;
  889. },
  890. addScalar: function ( s ) {
  891. this.x += s;
  892. this.y += s;
  893. return this;
  894. },
  895. addVectors: function ( a, b ) {
  896. this.x = a.x + b.x;
  897. this.y = a.y + b.y;
  898. return this;
  899. },
  900. addScaledVector: function ( v, s ) {
  901. this.x += v.x * s;
  902. this.y += v.y * s;
  903. return this;
  904. },
  905. sub: function ( v, w ) {
  906. if ( w !== undefined ) {
  907. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  908. return this.subVectors( v, w );
  909. }
  910. this.x -= v.x;
  911. this.y -= v.y;
  912. return this;
  913. },
  914. subScalar: function ( s ) {
  915. this.x -= s;
  916. this.y -= s;
  917. return this;
  918. },
  919. subVectors: function ( a, b ) {
  920. this.x = a.x - b.x;
  921. this.y = a.y - b.y;
  922. return this;
  923. },
  924. multiply: function ( v ) {
  925. this.x *= v.x;
  926. this.y *= v.y;
  927. return this;
  928. },
  929. multiplyScalar: function ( scalar ) {
  930. if ( isFinite( scalar ) ) {
  931. this.x *= scalar;
  932. this.y *= scalar;
  933. } else {
  934. this.x = 0;
  935. this.y = 0;
  936. }
  937. return this;
  938. },
  939. divide: function ( v ) {
  940. this.x /= v.x;
  941. this.y /= v.y;
  942. return this;
  943. },
  944. divideScalar: function ( scalar ) {
  945. return this.multiplyScalar( 1 / scalar );
  946. },
  947. min: function ( v ) {
  948. this.x = Math.min( this.x, v.x );
  949. this.y = Math.min( this.y, v.y );
  950. return this;
  951. },
  952. max: function ( v ) {
  953. this.x = Math.max( this.x, v.x );
  954. this.y = Math.max( this.y, v.y );
  955. return this;
  956. },
  957. clamp: function ( min, max ) {
  958. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  959. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  960. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  961. return this;
  962. },
  963. clampScalar: function () {
  964. var min, max;
  965. return function clampScalar( minVal, maxVal ) {
  966. if ( min === undefined ) {
  967. min = new THREE.Vector2();
  968. max = new THREE.Vector2();
  969. }
  970. min.set( minVal, minVal );
  971. max.set( maxVal, maxVal );
  972. return this.clamp( min, max );
  973. };
  974. }(),
  975. clampLength: function ( min, max ) {
  976. var length = this.length();
  977. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  978. return this;
  979. },
  980. floor: function () {
  981. this.x = Math.floor( this.x );
  982. this.y = Math.floor( this.y );
  983. return this;
  984. },
  985. ceil: function () {
  986. this.x = Math.ceil( this.x );
  987. this.y = Math.ceil( this.y );
  988. return this;
  989. },
  990. round: function () {
  991. this.x = Math.round( this.x );
  992. this.y = Math.round( this.y );
  993. return this;
  994. },
  995. roundToZero: function () {
  996. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  997. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  998. return this;
  999. },
  1000. negate: function () {
  1001. this.x = - this.x;
  1002. this.y = - this.y;
  1003. return this;
  1004. },
  1005. dot: function ( v ) {
  1006. return this.x * v.x + this.y * v.y;
  1007. },
  1008. lengthSq: function () {
  1009. return this.x * this.x + this.y * this.y;
  1010. },
  1011. length: function () {
  1012. return Math.sqrt( this.x * this.x + this.y * this.y );
  1013. },
  1014. lengthManhattan: function() {
  1015. return Math.abs( this.x ) + Math.abs( this.y );
  1016. },
  1017. normalize: function () {
  1018. return this.divideScalar( this.length() );
  1019. },
  1020. distanceTo: function ( v ) {
  1021. return Math.sqrt( this.distanceToSquared( v ) );
  1022. },
  1023. distanceToSquared: function ( v ) {
  1024. var dx = this.x - v.x, dy = this.y - v.y;
  1025. return dx * dx + dy * dy;
  1026. },
  1027. setLength: function ( length ) {
  1028. return this.multiplyScalar( length / this.length() );
  1029. },
  1030. lerp: function ( v, alpha ) {
  1031. this.x += ( v.x - this.x ) * alpha;
  1032. this.y += ( v.y - this.y ) * alpha;
  1033. return this;
  1034. },
  1035. lerpVectors: function ( v1, v2, alpha ) {
  1036. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1037. return this;
  1038. },
  1039. equals: function ( v ) {
  1040. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1041. },
  1042. fromArray: function ( array, offset ) {
  1043. if ( offset === undefined ) offset = 0;
  1044. this.x = array[ offset ];
  1045. this.y = array[ offset + 1 ];
  1046. return this;
  1047. },
  1048. toArray: function ( array, offset ) {
  1049. if ( array === undefined ) array = [];
  1050. if ( offset === undefined ) offset = 0;
  1051. array[ offset ] = this.x;
  1052. array[ offset + 1 ] = this.y;
  1053. return array;
  1054. },
  1055. fromAttribute: function ( attribute, index, offset ) {
  1056. if ( offset === undefined ) offset = 0;
  1057. index = index * attribute.itemSize + offset;
  1058. this.x = attribute.array[ index ];
  1059. this.y = attribute.array[ index + 1 ];
  1060. return this;
  1061. }
  1062. };
  1063. // File:src/math/Vector3.js
  1064. /**
  1065. * @author mrdoob / http://mrdoob.com/
  1066. * @author *kile / http://kile.stravaganza.org/
  1067. * @author philogb / http://blog.thejit.org/
  1068. * @author mikael emtinger / http://gomo.se/
  1069. * @author egraether / http://egraether.com/
  1070. * @author WestLangley / http://github.com/WestLangley
  1071. */
  1072. THREE.Vector3 = function ( x, y, z ) {
  1073. this.x = x || 0;
  1074. this.y = y || 0;
  1075. this.z = z || 0;
  1076. };
  1077. THREE.Vector3.prototype = {
  1078. constructor: THREE.Vector3,
  1079. set: function ( x, y, z ) {
  1080. this.x = x;
  1081. this.y = y;
  1082. this.z = z;
  1083. return this;
  1084. },
  1085. setX: function ( x ) {
  1086. this.x = x;
  1087. return this;
  1088. },
  1089. setY: function ( y ) {
  1090. this.y = y;
  1091. return this;
  1092. },
  1093. setZ: function ( z ) {
  1094. this.z = z;
  1095. return this;
  1096. },
  1097. setComponent: function ( index, value ) {
  1098. switch ( index ) {
  1099. case 0: this.x = value; break;
  1100. case 1: this.y = value; break;
  1101. case 2: this.z = value; break;
  1102. default: throw new Error( 'index is out of range: ' + index );
  1103. }
  1104. },
  1105. getComponent: function ( index ) {
  1106. switch ( index ) {
  1107. case 0: return this.x;
  1108. case 1: return this.y;
  1109. case 2: return this.z;
  1110. default: throw new Error( 'index is out of range: ' + index );
  1111. }
  1112. },
  1113. clone: function () {
  1114. return new this.constructor( this.x, this.y, this.z );
  1115. },
  1116. copy: function ( v ) {
  1117. this.x = v.x;
  1118. this.y = v.y;
  1119. this.z = v.z;
  1120. return this;
  1121. },
  1122. add: function ( v, w ) {
  1123. if ( w !== undefined ) {
  1124. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1125. return this.addVectors( v, w );
  1126. }
  1127. this.x += v.x;
  1128. this.y += v.y;
  1129. this.z += v.z;
  1130. return this;
  1131. },
  1132. addScalar: function ( s ) {
  1133. this.x += s;
  1134. this.y += s;
  1135. this.z += s;
  1136. return this;
  1137. },
  1138. addVectors: function ( a, b ) {
  1139. this.x = a.x + b.x;
  1140. this.y = a.y + b.y;
  1141. this.z = a.z + b.z;
  1142. return this;
  1143. },
  1144. addScaledVector: function ( v, s ) {
  1145. this.x += v.x * s;
  1146. this.y += v.y * s;
  1147. this.z += v.z * s;
  1148. return this;
  1149. },
  1150. sub: function ( v, w ) {
  1151. if ( w !== undefined ) {
  1152. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1153. return this.subVectors( v, w );
  1154. }
  1155. this.x -= v.x;
  1156. this.y -= v.y;
  1157. this.z -= v.z;
  1158. return this;
  1159. },
  1160. subScalar: function ( s ) {
  1161. this.x -= s;
  1162. this.y -= s;
  1163. this.z -= s;
  1164. return this;
  1165. },
  1166. subVectors: function ( a, b ) {
  1167. this.x = a.x - b.x;
  1168. this.y = a.y - b.y;
  1169. this.z = a.z - b.z;
  1170. return this;
  1171. },
  1172. multiply: function ( v, w ) {
  1173. if ( w !== undefined ) {
  1174. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1175. return this.multiplyVectors( v, w );
  1176. }
  1177. this.x *= v.x;
  1178. this.y *= v.y;
  1179. this.z *= v.z;
  1180. return this;
  1181. },
  1182. multiplyScalar: function ( scalar ) {
  1183. if ( isFinite( scalar ) ) {
  1184. this.x *= scalar;
  1185. this.y *= scalar;
  1186. this.z *= scalar;
  1187. } else {
  1188. this.x = 0;
  1189. this.y = 0;
  1190. this.z = 0;
  1191. }
  1192. return this;
  1193. },
  1194. multiplyVectors: function ( a, b ) {
  1195. this.x = a.x * b.x;
  1196. this.y = a.y * b.y;
  1197. this.z = a.z * b.z;
  1198. return this;
  1199. },
  1200. applyEuler: function () {
  1201. var quaternion;
  1202. return function applyEuler( euler ) {
  1203. if ( euler instanceof THREE.Euler === false ) {
  1204. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1205. }
  1206. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1207. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1208. return this;
  1209. };
  1210. }(),
  1211. applyAxisAngle: function () {
  1212. var quaternion;
  1213. return function applyAxisAngle( axis, angle ) {
  1214. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1215. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1216. return this;
  1217. };
  1218. }(),
  1219. applyMatrix3: function ( m ) {
  1220. var x = this.x;
  1221. var y = this.y;
  1222. var z = this.z;
  1223. var e = m.elements;
  1224. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1225. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1226. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1227. return this;
  1228. },
  1229. applyMatrix4: function ( m ) {
  1230. // input: THREE.Matrix4 affine matrix
  1231. var x = this.x, y = this.y, z = this.z;
  1232. var e = m.elements;
  1233. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1234. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1235. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1236. return this;
  1237. },
  1238. applyProjection: function ( m ) {
  1239. // input: THREE.Matrix4 projection matrix
  1240. var x = this.x, y = this.y, z = this.z;
  1241. var e = m.elements;
  1242. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1243. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1244. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1245. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1246. return this;
  1247. },
  1248. applyQuaternion: function ( q ) {
  1249. var x = this.x;
  1250. var y = this.y;
  1251. var z = this.z;
  1252. var qx = q.x;
  1253. var qy = q.y;
  1254. var qz = q.z;
  1255. var qw = q.w;
  1256. // calculate quat * vector
  1257. var ix = qw * x + qy * z - qz * y;
  1258. var iy = qw * y + qz * x - qx * z;
  1259. var iz = qw * z + qx * y - qy * x;
  1260. var iw = - qx * x - qy * y - qz * z;
  1261. // calculate result * inverse quat
  1262. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1263. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1264. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1265. return this;
  1266. },
  1267. project: function () {
  1268. var matrix;
  1269. return function project( camera ) {
  1270. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1271. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1272. return this.applyProjection( matrix );
  1273. };
  1274. }(),
  1275. unproject: function () {
  1276. var matrix;
  1277. return function unproject( camera ) {
  1278. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1279. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1280. return this.applyProjection( matrix );
  1281. };
  1282. }(),
  1283. transformDirection: function ( m ) {
  1284. // input: THREE.Matrix4 affine matrix
  1285. // vector interpreted as a direction
  1286. var x = this.x, y = this.y, z = this.z;
  1287. var e = m.elements;
  1288. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1289. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1290. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1291. this.normalize();
  1292. return this;
  1293. },
  1294. divide: function ( v ) {
  1295. this.x /= v.x;
  1296. this.y /= v.y;
  1297. this.z /= v.z;
  1298. return this;
  1299. },
  1300. divideScalar: function ( scalar ) {
  1301. return this.multiplyScalar( 1 / scalar );
  1302. },
  1303. min: function ( v ) {
  1304. this.x = Math.min( this.x, v.x );
  1305. this.y = Math.min( this.y, v.y );
  1306. this.z = Math.min( this.z, v.z );
  1307. return this;
  1308. },
  1309. max: function ( v ) {
  1310. this.x = Math.max( this.x, v.x );
  1311. this.y = Math.max( this.y, v.y );
  1312. this.z = Math.max( this.z, v.z );
  1313. return this;
  1314. },
  1315. clamp: function ( min, max ) {
  1316. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1317. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1318. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1319. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1320. return this;
  1321. },
  1322. clampScalar: function () {
  1323. var min, max;
  1324. return function clampScalar( minVal, maxVal ) {
  1325. if ( min === undefined ) {
  1326. min = new THREE.Vector3();
  1327. max = new THREE.Vector3();
  1328. }
  1329. min.set( minVal, minVal, minVal );
  1330. max.set( maxVal, maxVal, maxVal );
  1331. return this.clamp( min, max );
  1332. };
  1333. }(),
  1334. clampLength: function ( min, max ) {
  1335. var length = this.length();
  1336. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1337. return this;
  1338. },
  1339. floor: function () {
  1340. this.x = Math.floor( this.x );
  1341. this.y = Math.floor( this.y );
  1342. this.z = Math.floor( this.z );
  1343. return this;
  1344. },
  1345. ceil: function () {
  1346. this.x = Math.ceil( this.x );
  1347. this.y = Math.ceil( this.y );
  1348. this.z = Math.ceil( this.z );
  1349. return this;
  1350. },
  1351. round: function () {
  1352. this.x = Math.round( this.x );
  1353. this.y = Math.round( this.y );
  1354. this.z = Math.round( this.z );
  1355. return this;
  1356. },
  1357. roundToZero: function () {
  1358. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1359. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1360. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1361. return this;
  1362. },
  1363. negate: function () {
  1364. this.x = - this.x;
  1365. this.y = - this.y;
  1366. this.z = - this.z;
  1367. return this;
  1368. },
  1369. dot: function ( v ) {
  1370. return this.x * v.x + this.y * v.y + this.z * v.z;
  1371. },
  1372. lengthSq: function () {
  1373. return this.x * this.x + this.y * this.y + this.z * this.z;
  1374. },
  1375. length: function () {
  1376. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1377. },
  1378. lengthManhattan: function () {
  1379. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1380. },
  1381. normalize: function () {
  1382. return this.divideScalar( this.length() );
  1383. },
  1384. setLength: function ( length ) {
  1385. return this.multiplyScalar( length / this.length() );
  1386. },
  1387. lerp: function ( v, alpha ) {
  1388. this.x += ( v.x - this.x ) * alpha;
  1389. this.y += ( v.y - this.y ) * alpha;
  1390. this.z += ( v.z - this.z ) * alpha;
  1391. return this;
  1392. },
  1393. lerpVectors: function ( v1, v2, alpha ) {
  1394. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1395. return this;
  1396. },
  1397. cross: function ( v, w ) {
  1398. if ( w !== undefined ) {
  1399. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1400. return this.crossVectors( v, w );
  1401. }
  1402. var x = this.x, y = this.y, z = this.z;
  1403. this.x = y * v.z - z * v.y;
  1404. this.y = z * v.x - x * v.z;
  1405. this.z = x * v.y - y * v.x;
  1406. return this;
  1407. },
  1408. crossVectors: function ( a, b ) {
  1409. var ax = a.x, ay = a.y, az = a.z;
  1410. var bx = b.x, by = b.y, bz = b.z;
  1411. this.x = ay * bz - az * by;
  1412. this.y = az * bx - ax * bz;
  1413. this.z = ax * by - ay * bx;
  1414. return this;
  1415. },
  1416. projectOnVector: function () {
  1417. var v1, dot;
  1418. return function projectOnVector( vector ) {
  1419. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1420. v1.copy( vector ).normalize();
  1421. dot = this.dot( v1 );
  1422. return this.copy( v1 ).multiplyScalar( dot );
  1423. };
  1424. }(),
  1425. projectOnPlane: function () {
  1426. var v1;
  1427. return function projectOnPlane( planeNormal ) {
  1428. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1429. v1.copy( this ).projectOnVector( planeNormal );
  1430. return this.sub( v1 );
  1431. }
  1432. }(),
  1433. reflect: function () {
  1434. // reflect incident vector off plane orthogonal to normal
  1435. // normal is assumed to have unit length
  1436. var v1;
  1437. return function reflect( normal ) {
  1438. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1439. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1440. }
  1441. }(),
  1442. angleTo: function ( v ) {
  1443. var theta = this.dot( v ) / ( this.length() * v.length() );
  1444. // clamp, to handle numerical problems
  1445. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1446. },
  1447. distanceTo: function ( v ) {
  1448. return Math.sqrt( this.distanceToSquared( v ) );
  1449. },
  1450. distanceToSquared: function ( v ) {
  1451. var dx = this.x - v.x;
  1452. var dy = this.y - v.y;
  1453. var dz = this.z - v.z;
  1454. return dx * dx + dy * dy + dz * dz;
  1455. },
  1456. setEulerFromRotationMatrix: function ( m, order ) {
  1457. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1458. },
  1459. setEulerFromQuaternion: function ( q, order ) {
  1460. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1461. },
  1462. getPositionFromMatrix: function ( m ) {
  1463. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1464. return this.setFromMatrixPosition( m );
  1465. },
  1466. getScaleFromMatrix: function ( m ) {
  1467. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1468. return this.setFromMatrixScale( m );
  1469. },
  1470. getColumnFromMatrix: function ( index, matrix ) {
  1471. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1472. return this.setFromMatrixColumn( index, matrix );
  1473. },
  1474. setFromMatrixPosition: function ( m ) {
  1475. this.x = m.elements[ 12 ];
  1476. this.y = m.elements[ 13 ];
  1477. this.z = m.elements[ 14 ];
  1478. return this;
  1479. },
  1480. setFromMatrixScale: function ( m ) {
  1481. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1482. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1483. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1484. this.x = sx;
  1485. this.y = sy;
  1486. this.z = sz;
  1487. return this;
  1488. },
  1489. setFromMatrixColumn: function ( index, matrix ) {
  1490. var offset = index * 4;
  1491. var me = matrix.elements;
  1492. this.x = me[ offset ];
  1493. this.y = me[ offset + 1 ];
  1494. this.z = me[ offset + 2 ];
  1495. return this;
  1496. },
  1497. equals: function ( v ) {
  1498. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1499. },
  1500. fromArray: function ( array, offset ) {
  1501. if ( offset === undefined ) offset = 0;
  1502. this.x = array[ offset ];
  1503. this.y = array[ offset + 1 ];
  1504. this.z = array[ offset + 2 ];
  1505. return this;
  1506. },
  1507. toArray: function ( array, offset ) {
  1508. if ( array === undefined ) array = [];
  1509. if ( offset === undefined ) offset = 0;
  1510. array[ offset ] = this.x;
  1511. array[ offset + 1 ] = this.y;
  1512. array[ offset + 2 ] = this.z;
  1513. return array;
  1514. },
  1515. fromAttribute: function ( attribute, index, offset ) {
  1516. if ( offset === undefined ) offset = 0;
  1517. index = index * attribute.itemSize + offset;
  1518. this.x = attribute.array[ index ];
  1519. this.y = attribute.array[ index + 1 ];
  1520. this.z = attribute.array[ index + 2 ];
  1521. return this;
  1522. }
  1523. };
  1524. // File:src/math/Vector4.js
  1525. /**
  1526. * @author supereggbert / http://www.paulbrunt.co.uk/
  1527. * @author philogb / http://blog.thejit.org/
  1528. * @author mikael emtinger / http://gomo.se/
  1529. * @author egraether / http://egraether.com/
  1530. * @author WestLangley / http://github.com/WestLangley
  1531. */
  1532. THREE.Vector4 = function ( x, y, z, w ) {
  1533. this.x = x || 0;
  1534. this.y = y || 0;
  1535. this.z = z || 0;
  1536. this.w = ( w !== undefined ) ? w : 1;
  1537. };
  1538. THREE.Vector4.prototype = {
  1539. constructor: THREE.Vector4,
  1540. set: function ( x, y, z, w ) {
  1541. this.x = x;
  1542. this.y = y;
  1543. this.z = z;
  1544. this.w = w;
  1545. return this;
  1546. },
  1547. setX: function ( x ) {
  1548. this.x = x;
  1549. return this;
  1550. },
  1551. setY: function ( y ) {
  1552. this.y = y;
  1553. return this;
  1554. },
  1555. setZ: function ( z ) {
  1556. this.z = z;
  1557. return this;
  1558. },
  1559. setW: function ( w ) {
  1560. this.w = w;
  1561. return this;
  1562. },
  1563. setComponent: function ( index, value ) {
  1564. switch ( index ) {
  1565. case 0: this.x = value; break;
  1566. case 1: this.y = value; break;
  1567. case 2: this.z = value; break;
  1568. case 3: this.w = value; break;
  1569. default: throw new Error( 'index is out of range: ' + index );
  1570. }
  1571. },
  1572. getComponent: function ( index ) {
  1573. switch ( index ) {
  1574. case 0: return this.x;
  1575. case 1: return this.y;
  1576. case 2: return this.z;
  1577. case 3: return this.w;
  1578. default: throw new Error( 'index is out of range: ' + index );
  1579. }
  1580. },
  1581. clone: function () {
  1582. return new this.constructor( this.x, this.y, this.z, this.w );
  1583. },
  1584. copy: function ( v ) {
  1585. this.x = v.x;
  1586. this.y = v.y;
  1587. this.z = v.z;
  1588. this.w = ( v.w !== undefined ) ? v.w : 1;
  1589. return this;
  1590. },
  1591. add: function ( v, w ) {
  1592. if ( w !== undefined ) {
  1593. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1594. return this.addVectors( v, w );
  1595. }
  1596. this.x += v.x;
  1597. this.y += v.y;
  1598. this.z += v.z;
  1599. this.w += v.w;
  1600. return this;
  1601. },
  1602. addScalar: function ( s ) {
  1603. this.x += s;
  1604. this.y += s;
  1605. this.z += s;
  1606. this.w += s;
  1607. return this;
  1608. },
  1609. addVectors: function ( a, b ) {
  1610. this.x = a.x + b.x;
  1611. this.y = a.y + b.y;
  1612. this.z = a.z + b.z;
  1613. this.w = a.w + b.w;
  1614. return this;
  1615. },
  1616. addScaledVector: function ( v, s ) {
  1617. this.x += v.x * s;
  1618. this.y += v.y * s;
  1619. this.z += v.z * s;
  1620. this.w += v.w * s;
  1621. return this;
  1622. },
  1623. sub: function ( v, w ) {
  1624. if ( w !== undefined ) {
  1625. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1626. return this.subVectors( v, w );
  1627. }
  1628. this.x -= v.x;
  1629. this.y -= v.y;
  1630. this.z -= v.z;
  1631. this.w -= v.w;
  1632. return this;
  1633. },
  1634. subScalar: function ( s ) {
  1635. this.x -= s;
  1636. this.y -= s;
  1637. this.z -= s;
  1638. this.w -= s;
  1639. return this;
  1640. },
  1641. subVectors: function ( a, b ) {
  1642. this.x = a.x - b.x;
  1643. this.y = a.y - b.y;
  1644. this.z = a.z - b.z;
  1645. this.w = a.w - b.w;
  1646. return this;
  1647. },
  1648. multiplyScalar: function ( scalar ) {
  1649. if ( isFinite( scalar ) ) {
  1650. this.x *= scalar;
  1651. this.y *= scalar;
  1652. this.z *= scalar;
  1653. this.w *= scalar;
  1654. } else {
  1655. this.x = 0;
  1656. this.y = 0;
  1657. this.z = 0;
  1658. this.w = 0;
  1659. }
  1660. return this;
  1661. },
  1662. applyMatrix4: function ( m ) {
  1663. var x = this.x;
  1664. var y = this.y;
  1665. var z = this.z;
  1666. var w = this.w;
  1667. var e = m.elements;
  1668. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1669. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1670. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1671. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1672. return this;
  1673. },
  1674. divideScalar: function ( scalar ) {
  1675. return this.multiplyScalar( 1 / scalar );
  1676. },
  1677. setAxisAngleFromQuaternion: function ( q ) {
  1678. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1679. // q is assumed to be normalized
  1680. this.w = 2 * Math.acos( q.w );
  1681. var s = Math.sqrt( 1 - q.w * q.w );
  1682. if ( s < 0.0001 ) {
  1683. this.x = 1;
  1684. this.y = 0;
  1685. this.z = 0;
  1686. } else {
  1687. this.x = q.x / s;
  1688. this.y = q.y / s;
  1689. this.z = q.z / s;
  1690. }
  1691. return this;
  1692. },
  1693. setAxisAngleFromRotationMatrix: function ( m ) {
  1694. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1695. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1696. var angle, x, y, z, // variables for result
  1697. epsilon = 0.01, // margin to allow for rounding errors
  1698. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1699. te = m.elements,
  1700. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1701. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1702. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1703. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1704. && ( Math.abs( m13 - m31 ) < epsilon )
  1705. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1706. // singularity found
  1707. // first check for identity matrix which must have +1 for all terms
  1708. // in leading diagonal and zero in other terms
  1709. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1710. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1711. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1712. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1713. // this singularity is identity matrix so angle = 0
  1714. this.set( 1, 0, 0, 0 );
  1715. return this; // zero angle, arbitrary axis
  1716. }
  1717. // otherwise this singularity is angle = 180
  1718. angle = Math.PI;
  1719. var xx = ( m11 + 1 ) / 2;
  1720. var yy = ( m22 + 1 ) / 2;
  1721. var zz = ( m33 + 1 ) / 2;
  1722. var xy = ( m12 + m21 ) / 4;
  1723. var xz = ( m13 + m31 ) / 4;
  1724. var yz = ( m23 + m32 ) / 4;
  1725. if ( ( xx > yy ) && ( xx > zz ) ) {
  1726. // m11 is the largest diagonal term
  1727. if ( xx < epsilon ) {
  1728. x = 0;
  1729. y = 0.707106781;
  1730. z = 0.707106781;
  1731. } else {
  1732. x = Math.sqrt( xx );
  1733. y = xy / x;
  1734. z = xz / x;
  1735. }
  1736. } else if ( yy > zz ) {
  1737. // m22 is the largest diagonal term
  1738. if ( yy < epsilon ) {
  1739. x = 0.707106781;
  1740. y = 0;
  1741. z = 0.707106781;
  1742. } else {
  1743. y = Math.sqrt( yy );
  1744. x = xy / y;
  1745. z = yz / y;
  1746. }
  1747. } else {
  1748. // m33 is the largest diagonal term so base result on this
  1749. if ( zz < epsilon ) {
  1750. x = 0.707106781;
  1751. y = 0.707106781;
  1752. z = 0;
  1753. } else {
  1754. z = Math.sqrt( zz );
  1755. x = xz / z;
  1756. y = yz / z;
  1757. }
  1758. }
  1759. this.set( x, y, z, angle );
  1760. return this; // return 180 deg rotation
  1761. }
  1762. // as we have reached here there are no singularities so we can handle normally
  1763. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1764. + ( m13 - m31 ) * ( m13 - m31 )
  1765. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1766. if ( Math.abs( s ) < 0.001 ) s = 1;
  1767. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1768. // caught by singularity test above, but I've left it in just in case
  1769. this.x = ( m32 - m23 ) / s;
  1770. this.y = ( m13 - m31 ) / s;
  1771. this.z = ( m21 - m12 ) / s;
  1772. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1773. return this;
  1774. },
  1775. min: function ( v ) {
  1776. this.x = Math.min( this.x, v.x );
  1777. this.y = Math.min( this.y, v.y );
  1778. this.z = Math.min( this.z, v.z );
  1779. this.w = Math.min( this.w, v.w );
  1780. return this;
  1781. },
  1782. max: function ( v ) {
  1783. this.x = Math.max( this.x, v.x );
  1784. this.y = Math.max( this.y, v.y );
  1785. this.z = Math.max( this.z, v.z );
  1786. this.w = Math.max( this.w, v.w );
  1787. return this;
  1788. },
  1789. clamp: function ( min, max ) {
  1790. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1791. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1792. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1793. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1794. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1795. return this;
  1796. },
  1797. clampScalar: function () {
  1798. var min, max;
  1799. return function clampScalar( minVal, maxVal ) {
  1800. if ( min === undefined ) {
  1801. min = new THREE.Vector4();
  1802. max = new THREE.Vector4();
  1803. }
  1804. min.set( minVal, minVal, minVal, minVal );
  1805. max.set( maxVal, maxVal, maxVal, maxVal );
  1806. return this.clamp( min, max );
  1807. };
  1808. }(),
  1809. floor: function () {
  1810. this.x = Math.floor( this.x );
  1811. this.y = Math.floor( this.y );
  1812. this.z = Math.floor( this.z );
  1813. this.w = Math.floor( this.w );
  1814. return this;
  1815. },
  1816. ceil: function () {
  1817. this.x = Math.ceil( this.x );
  1818. this.y = Math.ceil( this.y );
  1819. this.z = Math.ceil( this.z );
  1820. this.w = Math.ceil( this.w );
  1821. return this;
  1822. },
  1823. round: function () {
  1824. this.x = Math.round( this.x );
  1825. this.y = Math.round( this.y );
  1826. this.z = Math.round( this.z );
  1827. this.w = Math.round( this.w );
  1828. return this;
  1829. },
  1830. roundToZero: function () {
  1831. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1832. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1833. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1834. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1835. return this;
  1836. },
  1837. negate: function () {
  1838. this.x = - this.x;
  1839. this.y = - this.y;
  1840. this.z = - this.z;
  1841. this.w = - this.w;
  1842. return this;
  1843. },
  1844. dot: function ( v ) {
  1845. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1846. },
  1847. lengthSq: function () {
  1848. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1849. },
  1850. length: function () {
  1851. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1852. },
  1853. lengthManhattan: function () {
  1854. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1855. },
  1856. normalize: function () {
  1857. return this.divideScalar( this.length() );
  1858. },
  1859. setLength: function ( length ) {
  1860. return this.multiplyScalar( length / this.length() );
  1861. },
  1862. lerp: function ( v, alpha ) {
  1863. this.x += ( v.x - this.x ) * alpha;
  1864. this.y += ( v.y - this.y ) * alpha;
  1865. this.z += ( v.z - this.z ) * alpha;
  1866. this.w += ( v.w - this.w ) * alpha;
  1867. return this;
  1868. },
  1869. lerpVectors: function ( v1, v2, alpha ) {
  1870. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1871. return this;
  1872. },
  1873. equals: function ( v ) {
  1874. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1875. },
  1876. fromArray: function ( array, offset ) {
  1877. if ( offset === undefined ) offset = 0;
  1878. this.x = array[ offset ];
  1879. this.y = array[ offset + 1 ];
  1880. this.z = array[ offset + 2 ];
  1881. this.w = array[ offset + 3 ];
  1882. return this;
  1883. },
  1884. toArray: function ( array, offset ) {
  1885. if ( array === undefined ) array = [];
  1886. if ( offset === undefined ) offset = 0;
  1887. array[ offset ] = this.x;
  1888. array[ offset + 1 ] = this.y;
  1889. array[ offset + 2 ] = this.z;
  1890. array[ offset + 3 ] = this.w;
  1891. return array;
  1892. },
  1893. fromAttribute: function ( attribute, index, offset ) {
  1894. if ( offset === undefined ) offset = 0;
  1895. index = index * attribute.itemSize + offset;
  1896. this.x = attribute.array[ index ];
  1897. this.y = attribute.array[ index + 1 ];
  1898. this.z = attribute.array[ index + 2 ];
  1899. this.w = attribute.array[ index + 3 ];
  1900. return this;
  1901. }
  1902. };
  1903. // File:src/math/Euler.js
  1904. /**
  1905. * @author mrdoob / http://mrdoob.com/
  1906. * @author WestLangley / http://github.com/WestLangley
  1907. * @author bhouston / http://clara.io
  1908. */
  1909. THREE.Euler = function ( x, y, z, order ) {
  1910. this._x = x || 0;
  1911. this._y = y || 0;
  1912. this._z = z || 0;
  1913. this._order = order || THREE.Euler.DefaultOrder;
  1914. };
  1915. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1916. THREE.Euler.DefaultOrder = 'XYZ';
  1917. THREE.Euler.prototype = {
  1918. constructor: THREE.Euler,
  1919. get x () {
  1920. return this._x;
  1921. },
  1922. set x ( value ) {
  1923. this._x = value;
  1924. this.onChangeCallback();
  1925. },
  1926. get y () {
  1927. return this._y;
  1928. },
  1929. set y ( value ) {
  1930. this._y = value;
  1931. this.onChangeCallback();
  1932. },
  1933. get z () {
  1934. return this._z;
  1935. },
  1936. set z ( value ) {
  1937. this._z = value;
  1938. this.onChangeCallback();
  1939. },
  1940. get order () {
  1941. return this._order;
  1942. },
  1943. set order ( value ) {
  1944. this._order = value;
  1945. this.onChangeCallback();
  1946. },
  1947. set: function ( x, y, z, order ) {
  1948. this._x = x;
  1949. this._y = y;
  1950. this._z = z;
  1951. this._order = order || this._order;
  1952. this.onChangeCallback();
  1953. return this;
  1954. },
  1955. clone: function () {
  1956. return new this.constructor( this._x, this._y, this._z, this._order);
  1957. },
  1958. copy: function ( euler ) {
  1959. this._x = euler._x;
  1960. this._y = euler._y;
  1961. this._z = euler._z;
  1962. this._order = euler._order;
  1963. this.onChangeCallback();
  1964. return this;
  1965. },
  1966. setFromRotationMatrix: function ( m, order, update ) {
  1967. var clamp = THREE.Math.clamp;
  1968. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1969. var te = m.elements;
  1970. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  1971. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  1972. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1973. order = order || this._order;
  1974. if ( order === 'XYZ' ) {
  1975. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  1976. if ( Math.abs( m13 ) < 0.99999 ) {
  1977. this._x = Math.atan2( - m23, m33 );
  1978. this._z = Math.atan2( - m12, m11 );
  1979. } else {
  1980. this._x = Math.atan2( m32, m22 );
  1981. this._z = 0;
  1982. }
  1983. } else if ( order === 'YXZ' ) {
  1984. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  1985. if ( Math.abs( m23 ) < 0.99999 ) {
  1986. this._y = Math.atan2( m13, m33 );
  1987. this._z = Math.atan2( m21, m22 );
  1988. } else {
  1989. this._y = Math.atan2( - m31, m11 );
  1990. this._z = 0;
  1991. }
  1992. } else if ( order === 'ZXY' ) {
  1993. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  1994. if ( Math.abs( m32 ) < 0.99999 ) {
  1995. this._y = Math.atan2( - m31, m33 );
  1996. this._z = Math.atan2( - m12, m22 );
  1997. } else {
  1998. this._y = 0;
  1999. this._z = Math.atan2( m21, m11 );
  2000. }
  2001. } else if ( order === 'ZYX' ) {
  2002. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2003. if ( Math.abs( m31 ) < 0.99999 ) {
  2004. this._x = Math.atan2( m32, m33 );
  2005. this._z = Math.atan2( m21, m11 );
  2006. } else {
  2007. this._x = 0;
  2008. this._z = Math.atan2( - m12, m22 );
  2009. }
  2010. } else if ( order === 'YZX' ) {
  2011. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2012. if ( Math.abs( m21 ) < 0.99999 ) {
  2013. this._x = Math.atan2( - m23, m22 );
  2014. this._y = Math.atan2( - m31, m11 );
  2015. } else {
  2016. this._x = 0;
  2017. this._y = Math.atan2( m13, m33 );
  2018. }
  2019. } else if ( order === 'XZY' ) {
  2020. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2021. if ( Math.abs( m12 ) < 0.99999 ) {
  2022. this._x = Math.atan2( m32, m22 );
  2023. this._y = Math.atan2( m13, m11 );
  2024. } else {
  2025. this._x = Math.atan2( - m23, m33 );
  2026. this._y = 0;
  2027. }
  2028. } else {
  2029. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2030. }
  2031. this._order = order;
  2032. if ( update !== false ) this.onChangeCallback();
  2033. return this;
  2034. },
  2035. setFromQuaternion: function () {
  2036. var matrix;
  2037. return function ( q, order, update ) {
  2038. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2039. matrix.makeRotationFromQuaternion( q );
  2040. this.setFromRotationMatrix( matrix, order, update );
  2041. return this;
  2042. };
  2043. }(),
  2044. setFromVector3: function ( v, order ) {
  2045. return this.set( v.x, v.y, v.z, order || this._order );
  2046. },
  2047. reorder: function () {
  2048. // WARNING: this discards revolution information -bhouston
  2049. var q = new THREE.Quaternion();
  2050. return function ( newOrder ) {
  2051. q.setFromEuler( this );
  2052. this.setFromQuaternion( q, newOrder );
  2053. };
  2054. }(),
  2055. equals: function ( euler ) {
  2056. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2057. },
  2058. fromArray: function ( array ) {
  2059. this._x = array[ 0 ];
  2060. this._y = array[ 1 ];
  2061. this._z = array[ 2 ];
  2062. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2063. this.onChangeCallback();
  2064. return this;
  2065. },
  2066. toArray: function ( array, offset ) {
  2067. if ( array === undefined ) array = [];
  2068. if ( offset === undefined ) offset = 0;
  2069. array[ offset ] = this._x;
  2070. array[ offset + 1 ] = this._y;
  2071. array[ offset + 2 ] = this._z;
  2072. array[ offset + 3 ] = this._order;
  2073. return array;
  2074. },
  2075. toVector3: function ( optionalResult ) {
  2076. if ( optionalResult ) {
  2077. return optionalResult.set( this._x, this._y, this._z );
  2078. } else {
  2079. return new THREE.Vector3( this._x, this._y, this._z );
  2080. }
  2081. },
  2082. onChange: function ( callback ) {
  2083. this.onChangeCallback = callback;
  2084. return this;
  2085. },
  2086. onChangeCallback: function () {}
  2087. };
  2088. // File:src/math/Line3.js
  2089. /**
  2090. * @author bhouston / http://clara.io
  2091. */
  2092. THREE.Line3 = function ( start, end ) {
  2093. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2094. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2095. };
  2096. THREE.Line3.prototype = {
  2097. constructor: THREE.Line3,
  2098. set: function ( start, end ) {
  2099. this.start.copy( start );
  2100. this.end.copy( end );
  2101. return this;
  2102. },
  2103. clone: function () {
  2104. return new this.constructor().copy( this );
  2105. },
  2106. copy: function ( line ) {
  2107. this.start.copy( line.start );
  2108. this.end.copy( line.end );
  2109. return this;
  2110. },
  2111. center: function ( optionalTarget ) {
  2112. var result = optionalTarget || new THREE.Vector3();
  2113. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2114. },
  2115. delta: function ( optionalTarget ) {
  2116. var result = optionalTarget || new THREE.Vector3();
  2117. return result.subVectors( this.end, this.start );
  2118. },
  2119. distanceSq: function () {
  2120. return this.start.distanceToSquared( this.end );
  2121. },
  2122. distance: function () {
  2123. return this.start.distanceTo( this.end );
  2124. },
  2125. at: function ( t, optionalTarget ) {
  2126. var result = optionalTarget || new THREE.Vector3();
  2127. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2128. },
  2129. closestPointToPointParameter: function () {
  2130. var startP = new THREE.Vector3();
  2131. var startEnd = new THREE.Vector3();
  2132. return function ( point, clampToLine ) {
  2133. startP.subVectors( point, this.start );
  2134. startEnd.subVectors( this.end, this.start );
  2135. var startEnd2 = startEnd.dot( startEnd );
  2136. var startEnd_startP = startEnd.dot( startP );
  2137. var t = startEnd_startP / startEnd2;
  2138. if ( clampToLine ) {
  2139. t = THREE.Math.clamp( t, 0, 1 );
  2140. }
  2141. return t;
  2142. };
  2143. }(),
  2144. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2145. var t = this.closestPointToPointParameter( point, clampToLine );
  2146. var result = optionalTarget || new THREE.Vector3();
  2147. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2148. },
  2149. applyMatrix4: function ( matrix ) {
  2150. this.start.applyMatrix4( matrix );
  2151. this.end.applyMatrix4( matrix );
  2152. return this;
  2153. },
  2154. equals: function ( line ) {
  2155. return line.start.equals( this.start ) && line.end.equals( this.end );
  2156. }
  2157. };
  2158. // File:src/math/Box2.js
  2159. /**
  2160. * @author bhouston / http://clara.io
  2161. */
  2162. THREE.Box2 = function ( min, max ) {
  2163. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2164. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2165. };
  2166. THREE.Box2.prototype = {
  2167. constructor: THREE.Box2,
  2168. set: function ( min, max ) {
  2169. this.min.copy( min );
  2170. this.max.copy( max );
  2171. return this;
  2172. },
  2173. setFromPoints: function ( points ) {
  2174. this.makeEmpty();
  2175. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2176. this.expandByPoint( points[ i ] )
  2177. }
  2178. return this;
  2179. },
  2180. setFromCenterAndSize: function () {
  2181. var v1 = new THREE.Vector2();
  2182. return function ( center, size ) {
  2183. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2184. this.min.copy( center ).sub( halfSize );
  2185. this.max.copy( center ).add( halfSize );
  2186. return this;
  2187. };
  2188. }(),
  2189. clone: function () {
  2190. return new this.constructor().copy( this );
  2191. },
  2192. copy: function ( box ) {
  2193. this.min.copy( box.min );
  2194. this.max.copy( box.max );
  2195. return this;
  2196. },
  2197. makeEmpty: function () {
  2198. this.min.x = this.min.y = Infinity;
  2199. this.max.x = this.max.y = - Infinity;
  2200. return this;
  2201. },
  2202. empty: function () {
  2203. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2204. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2205. },
  2206. center: function ( optionalTarget ) {
  2207. var result = optionalTarget || new THREE.Vector2();
  2208. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2209. },
  2210. size: function ( optionalTarget ) {
  2211. var result = optionalTarget || new THREE.Vector2();
  2212. return result.subVectors( this.max, this.min );
  2213. },
  2214. expandByPoint: function ( point ) {
  2215. this.min.min( point );
  2216. this.max.max( point );
  2217. return this;
  2218. },
  2219. expandByVector: function ( vector ) {
  2220. this.min.sub( vector );
  2221. this.max.add( vector );
  2222. return this;
  2223. },
  2224. expandByScalar: function ( scalar ) {
  2225. this.min.addScalar( - scalar );
  2226. this.max.addScalar( scalar );
  2227. return this;
  2228. },
  2229. containsPoint: function ( point ) {
  2230. if ( point.x < this.min.x || point.x > this.max.x ||
  2231. point.y < this.min.y || point.y > this.max.y ) {
  2232. return false;
  2233. }
  2234. return true;
  2235. },
  2236. containsBox: function ( box ) {
  2237. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2238. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2239. return true;
  2240. }
  2241. return false;
  2242. },
  2243. getParameter: function ( point, optionalTarget ) {
  2244. // This can potentially have a divide by zero if the box
  2245. // has a size dimension of 0.
  2246. var result = optionalTarget || new THREE.Vector2();
  2247. return result.set(
  2248. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2249. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2250. );
  2251. },
  2252. isIntersectionBox: function ( box ) {
  2253. // using 6 splitting planes to rule out intersections.
  2254. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2255. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2256. return false;
  2257. }
  2258. return true;
  2259. },
  2260. clampPoint: function ( point, optionalTarget ) {
  2261. var result = optionalTarget || new THREE.Vector2();
  2262. return result.copy( point ).clamp( this.min, this.max );
  2263. },
  2264. distanceToPoint: function () {
  2265. var v1 = new THREE.Vector2();
  2266. return function ( point ) {
  2267. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2268. return clampedPoint.sub( point ).length();
  2269. };
  2270. }(),
  2271. intersect: function ( box ) {
  2272. this.min.max( box.min );
  2273. this.max.min( box.max );
  2274. return this;
  2275. },
  2276. union: function ( box ) {
  2277. this.min.min( box.min );
  2278. this.max.max( box.max );
  2279. return this;
  2280. },
  2281. translate: function ( offset ) {
  2282. this.min.add( offset );
  2283. this.max.add( offset );
  2284. return this;
  2285. },
  2286. equals: function ( box ) {
  2287. return box.min.equals( this.min ) && box.max.equals( this.max );
  2288. }
  2289. };
  2290. // File:src/math/Box3.js
  2291. /**
  2292. * @author bhouston / http://clara.io
  2293. * @author WestLangley / http://github.com/WestLangley
  2294. */
  2295. THREE.Box3 = function ( min, max ) {
  2296. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2297. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2298. };
  2299. THREE.Box3.prototype = {
  2300. constructor: THREE.Box3,
  2301. set: function ( min, max ) {
  2302. this.min.copy( min );
  2303. this.max.copy( max );
  2304. return this;
  2305. },
  2306. setFromPoints: function ( points ) {
  2307. this.makeEmpty();
  2308. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2309. this.expandByPoint( points[ i ] );
  2310. }
  2311. return this;
  2312. },
  2313. setFromCenterAndSize: function () {
  2314. var v1 = new THREE.Vector3();
  2315. return function ( center, size ) {
  2316. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2317. this.min.copy( center ).sub( halfSize );
  2318. this.max.copy( center ).add( halfSize );
  2319. return this;
  2320. };
  2321. }(),
  2322. setFromObject: function () {
  2323. // Computes the world-axis-aligned bounding box of an object (including its children),
  2324. // accounting for both the object's, and children's, world transforms
  2325. var v1 = new THREE.Vector3();
  2326. return function ( object ) {
  2327. var scope = this;
  2328. object.updateMatrixWorld( true );
  2329. this.makeEmpty();
  2330. object.traverse( function ( node ) {
  2331. var geometry = node.geometry;
  2332. if ( geometry !== undefined ) {
  2333. if ( geometry instanceof THREE.Geometry ) {
  2334. var vertices = geometry.vertices;
  2335. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2336. v1.copy( vertices[ i ] );
  2337. v1.applyMatrix4( node.matrixWorld );
  2338. scope.expandByPoint( v1 );
  2339. }
  2340. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2341. var positions = geometry.attributes[ 'position' ].array;
  2342. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2343. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2344. v1.applyMatrix4( node.matrixWorld );
  2345. scope.expandByPoint( v1 );
  2346. }
  2347. }
  2348. }
  2349. } );
  2350. return this;
  2351. };
  2352. }(),
  2353. clone: function () {
  2354. return new this.constructor().copy( this );
  2355. },
  2356. copy: function ( box ) {
  2357. this.min.copy( box.min );
  2358. this.max.copy( box.max );
  2359. return this;
  2360. },
  2361. makeEmpty: function () {
  2362. this.min.x = this.min.y = this.min.z = Infinity;
  2363. this.max.x = this.max.y = this.max.z = - Infinity;
  2364. return this;
  2365. },
  2366. empty: function () {
  2367. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2368. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2369. },
  2370. center: function ( optionalTarget ) {
  2371. var result = optionalTarget || new THREE.Vector3();
  2372. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2373. },
  2374. size: function ( optionalTarget ) {
  2375. var result = optionalTarget || new THREE.Vector3();
  2376. return result.subVectors( this.max, this.min );
  2377. },
  2378. expandByPoint: function ( point ) {
  2379. this.min.min( point );
  2380. this.max.max( point );
  2381. return this;
  2382. },
  2383. expandByVector: function ( vector ) {
  2384. this.min.sub( vector );
  2385. this.max.add( vector );
  2386. return this;
  2387. },
  2388. expandByScalar: function ( scalar ) {
  2389. this.min.addScalar( - scalar );
  2390. this.max.addScalar( scalar );
  2391. return this;
  2392. },
  2393. containsPoint: function ( point ) {
  2394. if ( point.x < this.min.x || point.x > this.max.x ||
  2395. point.y < this.min.y || point.y > this.max.y ||
  2396. point.z < this.min.z || point.z > this.max.z ) {
  2397. return false;
  2398. }
  2399. return true;
  2400. },
  2401. containsBox: function ( box ) {
  2402. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2403. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2404. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2405. return true;
  2406. }
  2407. return false;
  2408. },
  2409. getParameter: function ( point, optionalTarget ) {
  2410. // This can potentially have a divide by zero if the box
  2411. // has a size dimension of 0.
  2412. var result = optionalTarget || new THREE.Vector3();
  2413. return result.set(
  2414. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2415. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2416. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2417. );
  2418. },
  2419. isIntersectionBox: function ( box ) {
  2420. // using 6 splitting planes to rule out intersections.
  2421. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2422. box.max.y < this.min.y || box.min.y > this.max.y ||
  2423. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2424. return false;
  2425. }
  2426. return true;
  2427. },
  2428. clampPoint: function ( point, optionalTarget ) {
  2429. var result = optionalTarget || new THREE.Vector3();
  2430. return result.copy( point ).clamp( this.min, this.max );
  2431. },
  2432. distanceToPoint: function () {
  2433. var v1 = new THREE.Vector3();
  2434. return function ( point ) {
  2435. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2436. return clampedPoint.sub( point ).length();
  2437. };
  2438. }(),
  2439. getBoundingSphere: function () {
  2440. var v1 = new THREE.Vector3();
  2441. return function ( optionalTarget ) {
  2442. var result = optionalTarget || new THREE.Sphere();
  2443. result.center = this.center();
  2444. result.radius = this.size( v1 ).length() * 0.5;
  2445. return result;
  2446. };
  2447. }(),
  2448. intersect: function ( box ) {
  2449. this.min.max( box.min );
  2450. this.max.min( box.max );
  2451. return this;
  2452. },
  2453. union: function ( box ) {
  2454. this.min.min( box.min );
  2455. this.max.max( box.max );
  2456. return this;
  2457. },
  2458. applyMatrix4: function () {
  2459. var points = [
  2460. new THREE.Vector3(),
  2461. new THREE.Vector3(),
  2462. new THREE.Vector3(),
  2463. new THREE.Vector3(),
  2464. new THREE.Vector3(),
  2465. new THREE.Vector3(),
  2466. new THREE.Vector3(),
  2467. new THREE.Vector3()
  2468. ];
  2469. return function ( matrix ) {
  2470. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2471. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2472. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2473. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2474. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2475. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2476. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2477. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2478. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2479. this.makeEmpty();
  2480. this.setFromPoints( points );
  2481. return this;
  2482. };
  2483. }(),
  2484. translate: function ( offset ) {
  2485. this.min.add( offset );
  2486. this.max.add( offset );
  2487. return this;
  2488. },
  2489. equals: function ( box ) {
  2490. return box.min.equals( this.min ) && box.max.equals( this.max );
  2491. }
  2492. };
  2493. // File:src/math/Matrix3.js
  2494. /**
  2495. * @author alteredq / http://alteredqualia.com/
  2496. * @author WestLangley / http://github.com/WestLangley
  2497. * @author bhouston / http://clara.io
  2498. */
  2499. THREE.Matrix3 = function () {
  2500. this.elements = new Float32Array( [
  2501. 1, 0, 0,
  2502. 0, 1, 0,
  2503. 0, 0, 1
  2504. ] );
  2505. if ( arguments.length > 0 ) {
  2506. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2507. }
  2508. };
  2509. THREE.Matrix3.prototype = {
  2510. constructor: THREE.Matrix3,
  2511. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2512. var te = this.elements;
  2513. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2514. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2515. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2516. return this;
  2517. },
  2518. identity: function () {
  2519. this.set(
  2520. 1, 0, 0,
  2521. 0, 1, 0,
  2522. 0, 0, 1
  2523. );
  2524. return this;
  2525. },
  2526. clone: function () {
  2527. return new this.constructor().fromArray( this.elements );
  2528. },
  2529. copy: function ( m ) {
  2530. var me = m.elements;
  2531. this.set(
  2532. me[ 0 ], me[ 3 ], me[ 6 ],
  2533. me[ 1 ], me[ 4 ], me[ 7 ],
  2534. me[ 2 ], me[ 5 ], me[ 8 ]
  2535. );
  2536. return this;
  2537. },
  2538. multiplyVector3: function ( vector ) {
  2539. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2540. return vector.applyMatrix3( this );
  2541. },
  2542. multiplyVector3Array: function ( a ) {
  2543. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2544. return this.applyToVector3Array( a );
  2545. },
  2546. applyToVector3Array: function () {
  2547. var v1;
  2548. return function ( array, offset, length ) {
  2549. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2550. if ( offset === undefined ) offset = 0;
  2551. if ( length === undefined ) length = array.length;
  2552. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2553. v1.fromArray( array, j );
  2554. v1.applyMatrix3( this );
  2555. v1.toArray( array, j );
  2556. }
  2557. return array;
  2558. };
  2559. }(),
  2560. applyToBuffer: function () {
  2561. var v1;
  2562. return function applyToBuffer( buffer, offset, length ) {
  2563. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2564. if ( offset === undefined ) offset = 0;
  2565. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2566. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2567. v1.x = buffer.getX( j );
  2568. v1.y = buffer.getY( j );
  2569. v1.z = buffer.getZ( j );
  2570. v1.applyMatrix3( this );
  2571. buffer.setXYZ( v1.x, v1.y, v1.z );
  2572. }
  2573. return buffer;
  2574. };
  2575. }(),
  2576. multiplyScalar: function ( s ) {
  2577. var te = this.elements;
  2578. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2579. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2580. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2581. return this;
  2582. },
  2583. determinant: function () {
  2584. var te = this.elements;
  2585. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2586. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2587. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2588. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2589. },
  2590. getInverse: function ( matrix, throwOnInvertible ) {
  2591. // input: THREE.Matrix4
  2592. // ( based on http://code.google.com/p/webgl-mjs/ )
  2593. var me = matrix.elements;
  2594. var te = this.elements;
  2595. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2596. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2597. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2598. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2599. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2600. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2601. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2602. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2603. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2604. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2605. // no inverse
  2606. if ( det === 0 ) {
  2607. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2608. if ( throwOnInvertible || false ) {
  2609. throw new Error( msg );
  2610. } else {
  2611. console.warn( msg );
  2612. }
  2613. this.identity();
  2614. return this;
  2615. }
  2616. this.multiplyScalar( 1.0 / det );
  2617. return this;
  2618. },
  2619. transpose: function () {
  2620. var tmp, m = this.elements;
  2621. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2622. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2623. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2624. return this;
  2625. },
  2626. flattenToArrayOffset: function ( array, offset ) {
  2627. var te = this.elements;
  2628. array[ offset ] = te[ 0 ];
  2629. array[ offset + 1 ] = te[ 1 ];
  2630. array[ offset + 2 ] = te[ 2 ];
  2631. array[ offset + 3 ] = te[ 3 ];
  2632. array[ offset + 4 ] = te[ 4 ];
  2633. array[ offset + 5 ] = te[ 5 ];
  2634. array[ offset + 6 ] = te[ 6 ];
  2635. array[ offset + 7 ] = te[ 7 ];
  2636. array[ offset + 8 ] = te[ 8 ];
  2637. return array;
  2638. },
  2639. getNormalMatrix: function ( m ) {
  2640. // input: THREE.Matrix4
  2641. this.getInverse( m ).transpose();
  2642. return this;
  2643. },
  2644. transposeIntoArray: function ( r ) {
  2645. var m = this.elements;
  2646. r[ 0 ] = m[ 0 ];
  2647. r[ 1 ] = m[ 3 ];
  2648. r[ 2 ] = m[ 6 ];
  2649. r[ 3 ] = m[ 1 ];
  2650. r[ 4 ] = m[ 4 ];
  2651. r[ 5 ] = m[ 7 ];
  2652. r[ 6 ] = m[ 2 ];
  2653. r[ 7 ] = m[ 5 ];
  2654. r[ 8 ] = m[ 8 ];
  2655. return this;
  2656. },
  2657. fromArray: function ( array ) {
  2658. this.elements.set( array );
  2659. return this;
  2660. },
  2661. toArray: function () {
  2662. var te = this.elements;
  2663. return [
  2664. te[ 0 ], te[ 1 ], te[ 2 ],
  2665. te[ 3 ], te[ 4 ], te[ 5 ],
  2666. te[ 6 ], te[ 7 ], te[ 8 ]
  2667. ];
  2668. }
  2669. };
  2670. // File:src/math/Matrix4.js
  2671. /**
  2672. * @author mrdoob / http://mrdoob.com/
  2673. * @author supereggbert / http://www.paulbrunt.co.uk/
  2674. * @author philogb / http://blog.thejit.org/
  2675. * @author jordi_ros / http://plattsoft.com
  2676. * @author D1plo1d / http://github.com/D1plo1d
  2677. * @author alteredq / http://alteredqualia.com/
  2678. * @author mikael emtinger / http://gomo.se/
  2679. * @author timknip / http://www.floorplanner.com/
  2680. * @author bhouston / http://clara.io
  2681. * @author WestLangley / http://github.com/WestLangley
  2682. */
  2683. THREE.Matrix4 = function () {
  2684. this.elements = new Float32Array( [
  2685. 1, 0, 0, 0,
  2686. 0, 1, 0, 0,
  2687. 0, 0, 1, 0,
  2688. 0, 0, 0, 1
  2689. ] );
  2690. if ( arguments.length > 0 ) {
  2691. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2692. }
  2693. };
  2694. THREE.Matrix4.prototype = {
  2695. constructor: THREE.Matrix4,
  2696. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2697. var te = this.elements;
  2698. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2699. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2700. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2701. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2702. return this;
  2703. },
  2704. identity: function () {
  2705. this.set(
  2706. 1, 0, 0, 0,
  2707. 0, 1, 0, 0,
  2708. 0, 0, 1, 0,
  2709. 0, 0, 0, 1
  2710. );
  2711. return this;
  2712. },
  2713. clone: function () {
  2714. return new THREE.Matrix4().fromArray( this.elements );
  2715. },
  2716. copy: function ( m ) {
  2717. this.elements.set( m.elements );
  2718. return this;
  2719. },
  2720. extractPosition: function ( m ) {
  2721. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2722. return this.copyPosition( m );
  2723. },
  2724. copyPosition: function ( m ) {
  2725. var te = this.elements;
  2726. var me = m.elements;
  2727. te[ 12 ] = me[ 12 ];
  2728. te[ 13 ] = me[ 13 ];
  2729. te[ 14 ] = me[ 14 ];
  2730. return this;
  2731. },
  2732. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2733. var te = this.elements;
  2734. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2735. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2736. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2737. return this;
  2738. },
  2739. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2740. this.set(
  2741. xAxis.x, yAxis.x, zAxis.x, 0,
  2742. xAxis.y, yAxis.y, zAxis.y, 0,
  2743. xAxis.z, yAxis.z, zAxis.z, 0,
  2744. 0, 0, 0, 1
  2745. );
  2746. return this;
  2747. },
  2748. extractRotation: function () {
  2749. var v1;
  2750. return function ( m ) {
  2751. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2752. var te = this.elements;
  2753. var me = m.elements;
  2754. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2755. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2756. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2757. te[ 0 ] = me[ 0 ] * scaleX;
  2758. te[ 1 ] = me[ 1 ] * scaleX;
  2759. te[ 2 ] = me[ 2 ] * scaleX;
  2760. te[ 4 ] = me[ 4 ] * scaleY;
  2761. te[ 5 ] = me[ 5 ] * scaleY;
  2762. te[ 6 ] = me[ 6 ] * scaleY;
  2763. te[ 8 ] = me[ 8 ] * scaleZ;
  2764. te[ 9 ] = me[ 9 ] * scaleZ;
  2765. te[ 10 ] = me[ 10 ] * scaleZ;
  2766. return this;
  2767. };
  2768. }(),
  2769. makeRotationFromEuler: function ( euler ) {
  2770. if ( euler instanceof THREE.Euler === false ) {
  2771. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2772. }
  2773. var te = this.elements;
  2774. var x = euler.x, y = euler.y, z = euler.z;
  2775. var a = Math.cos( x ), b = Math.sin( x );
  2776. var c = Math.cos( y ), d = Math.sin( y );
  2777. var e = Math.cos( z ), f = Math.sin( z );
  2778. if ( euler.order === 'XYZ' ) {
  2779. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2780. te[ 0 ] = c * e;
  2781. te[ 4 ] = - c * f;
  2782. te[ 8 ] = d;
  2783. te[ 1 ] = af + be * d;
  2784. te[ 5 ] = ae - bf * d;
  2785. te[ 9 ] = - b * c;
  2786. te[ 2 ] = bf - ae * d;
  2787. te[ 6 ] = be + af * d;
  2788. te[ 10 ] = a * c;
  2789. } else if ( euler.order === 'YXZ' ) {
  2790. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2791. te[ 0 ] = ce + df * b;
  2792. te[ 4 ] = de * b - cf;
  2793. te[ 8 ] = a * d;
  2794. te[ 1 ] = a * f;
  2795. te[ 5 ] = a * e;
  2796. te[ 9 ] = - b;
  2797. te[ 2 ] = cf * b - de;
  2798. te[ 6 ] = df + ce * b;
  2799. te[ 10 ] = a * c;
  2800. } else if ( euler.order === 'ZXY' ) {
  2801. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2802. te[ 0 ] = ce - df * b;
  2803. te[ 4 ] = - a * f;
  2804. te[ 8 ] = de + cf * b;
  2805. te[ 1 ] = cf + de * b;
  2806. te[ 5 ] = a * e;
  2807. te[ 9 ] = df - ce * b;
  2808. te[ 2 ] = - a * d;
  2809. te[ 6 ] = b;
  2810. te[ 10 ] = a * c;
  2811. } else if ( euler.order === 'ZYX' ) {
  2812. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2813. te[ 0 ] = c * e;
  2814. te[ 4 ] = be * d - af;
  2815. te[ 8 ] = ae * d + bf;
  2816. te[ 1 ] = c * f;
  2817. te[ 5 ] = bf * d + ae;
  2818. te[ 9 ] = af * d - be;
  2819. te[ 2 ] = - d;
  2820. te[ 6 ] = b * c;
  2821. te[ 10 ] = a * c;
  2822. } else if ( euler.order === 'YZX' ) {
  2823. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2824. te[ 0 ] = c * e;
  2825. te[ 4 ] = bd - ac * f;
  2826. te[ 8 ] = bc * f + ad;
  2827. te[ 1 ] = f;
  2828. te[ 5 ] = a * e;
  2829. te[ 9 ] = - b * e;
  2830. te[ 2 ] = - d * e;
  2831. te[ 6 ] = ad * f + bc;
  2832. te[ 10 ] = ac - bd * f;
  2833. } else if ( euler.order === 'XZY' ) {
  2834. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2835. te[ 0 ] = c * e;
  2836. te[ 4 ] = - f;
  2837. te[ 8 ] = d * e;
  2838. te[ 1 ] = ac * f + bd;
  2839. te[ 5 ] = a * e;
  2840. te[ 9 ] = ad * f - bc;
  2841. te[ 2 ] = bc * f - ad;
  2842. te[ 6 ] = b * e;
  2843. te[ 10 ] = bd * f + ac;
  2844. }
  2845. // last column
  2846. te[ 3 ] = 0;
  2847. te[ 7 ] = 0;
  2848. te[ 11 ] = 0;
  2849. // bottom row
  2850. te[ 12 ] = 0;
  2851. te[ 13 ] = 0;
  2852. te[ 14 ] = 0;
  2853. te[ 15 ] = 1;
  2854. return this;
  2855. },
  2856. setRotationFromQuaternion: function ( q ) {
  2857. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2858. return this.makeRotationFromQuaternion( q );
  2859. },
  2860. makeRotationFromQuaternion: function ( q ) {
  2861. var te = this.elements;
  2862. var x = q.x, y = q.y, z = q.z, w = q.w;
  2863. var x2 = x + x, y2 = y + y, z2 = z + z;
  2864. var xx = x * x2, xy = x * y2, xz = x * z2;
  2865. var yy = y * y2, yz = y * z2, zz = z * z2;
  2866. var wx = w * x2, wy = w * y2, wz = w * z2;
  2867. te[ 0 ] = 1 - ( yy + zz );
  2868. te[ 4 ] = xy - wz;
  2869. te[ 8 ] = xz + wy;
  2870. te[ 1 ] = xy + wz;
  2871. te[ 5 ] = 1 - ( xx + zz );
  2872. te[ 9 ] = yz - wx;
  2873. te[ 2 ] = xz - wy;
  2874. te[ 6 ] = yz + wx;
  2875. te[ 10 ] = 1 - ( xx + yy );
  2876. // last column
  2877. te[ 3 ] = 0;
  2878. te[ 7 ] = 0;
  2879. te[ 11 ] = 0;
  2880. // bottom row
  2881. te[ 12 ] = 0;
  2882. te[ 13 ] = 0;
  2883. te[ 14 ] = 0;
  2884. te[ 15 ] = 1;
  2885. return this;
  2886. },
  2887. lookAt: function () {
  2888. var x, y, z;
  2889. return function ( eye, target, up ) {
  2890. if ( x === undefined ) x = new THREE.Vector3();
  2891. if ( y === undefined ) y = new THREE.Vector3();
  2892. if ( z === undefined ) z = new THREE.Vector3();
  2893. var te = this.elements;
  2894. z.subVectors( eye, target ).normalize();
  2895. if ( z.lengthSq() === 0 ) {
  2896. z.z = 1;
  2897. }
  2898. x.crossVectors( up, z ).normalize();
  2899. if ( x.lengthSq() === 0 ) {
  2900. z.x += 0.0001;
  2901. x.crossVectors( up, z ).normalize();
  2902. }
  2903. y.crossVectors( z, x );
  2904. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2905. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2906. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2907. return this;
  2908. };
  2909. }(),
  2910. multiply: function ( m, n ) {
  2911. if ( n !== undefined ) {
  2912. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2913. return this.multiplyMatrices( m, n );
  2914. }
  2915. return this.multiplyMatrices( this, m );
  2916. },
  2917. multiplyMatrices: function ( a, b ) {
  2918. var ae = a.elements;
  2919. var be = b.elements;
  2920. var te = this.elements;
  2921. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2922. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2923. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2924. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2925. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2926. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2927. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2928. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2929. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2930. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2931. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2932. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2933. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2934. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2935. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2936. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2937. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2938. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2939. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2940. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2941. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2942. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2943. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2944. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2945. return this;
  2946. },
  2947. multiplyToArray: function ( a, b, r ) {
  2948. var te = this.elements;
  2949. this.multiplyMatrices( a, b );
  2950. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  2951. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  2952. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  2953. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  2954. return this;
  2955. },
  2956. multiplyScalar: function ( s ) {
  2957. var te = this.elements;
  2958. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2959. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2960. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  2961. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  2962. return this;
  2963. },
  2964. multiplyVector3: function ( vector ) {
  2965. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  2966. return vector.applyProjection( this );
  2967. },
  2968. multiplyVector4: function ( vector ) {
  2969. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  2970. return vector.applyMatrix4( this );
  2971. },
  2972. multiplyVector3Array: function ( a ) {
  2973. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2974. return this.applyToVector3Array( a );
  2975. },
  2976. applyToVector3Array: function () {
  2977. var v1;
  2978. return function ( array, offset, length ) {
  2979. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2980. if ( offset === undefined ) offset = 0;
  2981. if ( length === undefined ) length = array.length;
  2982. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2983. v1.fromArray( array, j );
  2984. v1.applyMatrix4( this );
  2985. v1.toArray( array, j );
  2986. }
  2987. return array;
  2988. };
  2989. }(),
  2990. applyToBuffer: function () {
  2991. var v1;
  2992. return function applyToBuffer( buffer, offset, length ) {
  2993. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2994. if ( offset === undefined ) offset = 0;
  2995. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2996. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2997. v1.x = buffer.getX( j );
  2998. v1.y = buffer.getY( j );
  2999. v1.z = buffer.getZ( j );
  3000. v1.applyMatrix4( this );
  3001. buffer.setXYZ( v1.x, v1.y, v1.z );
  3002. }
  3003. return buffer;
  3004. };
  3005. }(),
  3006. rotateAxis: function ( v ) {
  3007. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3008. v.transformDirection( this );
  3009. },
  3010. crossVector: function ( vector ) {
  3011. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3012. return vector.applyMatrix4( this );
  3013. },
  3014. determinant: function () {
  3015. var te = this.elements;
  3016. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3017. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3018. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3019. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3020. //TODO: make this more efficient
  3021. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3022. return (
  3023. n41 * (
  3024. + n14 * n23 * n32
  3025. - n13 * n24 * n32
  3026. - n14 * n22 * n33
  3027. + n12 * n24 * n33
  3028. + n13 * n22 * n34
  3029. - n12 * n23 * n34
  3030. ) +
  3031. n42 * (
  3032. + n11 * n23 * n34
  3033. - n11 * n24 * n33
  3034. + n14 * n21 * n33
  3035. - n13 * n21 * n34
  3036. + n13 * n24 * n31
  3037. - n14 * n23 * n31
  3038. ) +
  3039. n43 * (
  3040. + n11 * n24 * n32
  3041. - n11 * n22 * n34
  3042. - n14 * n21 * n32
  3043. + n12 * n21 * n34
  3044. + n14 * n22 * n31
  3045. - n12 * n24 * n31
  3046. ) +
  3047. n44 * (
  3048. - n13 * n22 * n31
  3049. - n11 * n23 * n32
  3050. + n11 * n22 * n33
  3051. + n13 * n21 * n32
  3052. - n12 * n21 * n33
  3053. + n12 * n23 * n31
  3054. )
  3055. );
  3056. },
  3057. transpose: function () {
  3058. var te = this.elements;
  3059. var tmp;
  3060. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3061. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3062. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3063. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3064. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3065. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3066. return this;
  3067. },
  3068. flattenToArrayOffset: function ( array, offset ) {
  3069. var te = this.elements;
  3070. array[ offset ] = te[ 0 ];
  3071. array[ offset + 1 ] = te[ 1 ];
  3072. array[ offset + 2 ] = te[ 2 ];
  3073. array[ offset + 3 ] = te[ 3 ];
  3074. array[ offset + 4 ] = te[ 4 ];
  3075. array[ offset + 5 ] = te[ 5 ];
  3076. array[ offset + 6 ] = te[ 6 ];
  3077. array[ offset + 7 ] = te[ 7 ];
  3078. array[ offset + 8 ] = te[ 8 ];
  3079. array[ offset + 9 ] = te[ 9 ];
  3080. array[ offset + 10 ] = te[ 10 ];
  3081. array[ offset + 11 ] = te[ 11 ];
  3082. array[ offset + 12 ] = te[ 12 ];
  3083. array[ offset + 13 ] = te[ 13 ];
  3084. array[ offset + 14 ] = te[ 14 ];
  3085. array[ offset + 15 ] = te[ 15 ];
  3086. return array;
  3087. },
  3088. getPosition: function () {
  3089. var v1;
  3090. return function () {
  3091. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3092. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3093. var te = this.elements;
  3094. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3095. };
  3096. }(),
  3097. setPosition: function ( v ) {
  3098. var te = this.elements;
  3099. te[ 12 ] = v.x;
  3100. te[ 13 ] = v.y;
  3101. te[ 14 ] = v.z;
  3102. return this;
  3103. },
  3104. getInverse: function ( m, throwOnInvertible ) {
  3105. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3106. var te = this.elements;
  3107. var me = m.elements;
  3108. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3109. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3110. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3111. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3112. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3113. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3114. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3115. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3116. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3117. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3118. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3119. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3120. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3121. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3122. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3123. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3124. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3125. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3126. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3127. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3128. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3129. if ( det === 0 ) {
  3130. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3131. if ( throwOnInvertible || false ) {
  3132. throw new Error( msg );
  3133. } else {
  3134. console.warn( msg );
  3135. }
  3136. this.identity();
  3137. return this;
  3138. }
  3139. this.multiplyScalar( 1 / det );
  3140. return this;
  3141. },
  3142. translate: function ( v ) {
  3143. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3144. },
  3145. rotateX: function ( angle ) {
  3146. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3147. },
  3148. rotateY: function ( angle ) {
  3149. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3150. },
  3151. rotateZ: function ( angle ) {
  3152. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3153. },
  3154. rotateByAxis: function ( axis, angle ) {
  3155. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3156. },
  3157. scale: function ( v ) {
  3158. var te = this.elements;
  3159. var x = v.x, y = v.y, z = v.z;
  3160. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3161. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3162. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3163. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3164. return this;
  3165. },
  3166. getMaxScaleOnAxis: function () {
  3167. var te = this.elements;
  3168. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3169. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3170. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3171. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3172. },
  3173. makeTranslation: function ( x, y, z ) {
  3174. this.set(
  3175. 1, 0, 0, x,
  3176. 0, 1, 0, y,
  3177. 0, 0, 1, z,
  3178. 0, 0, 0, 1
  3179. );
  3180. return this;
  3181. },
  3182. makeRotationX: function ( theta ) {
  3183. var c = Math.cos( theta ), s = Math.sin( theta );
  3184. this.set(
  3185. 1, 0, 0, 0,
  3186. 0, c, - s, 0,
  3187. 0, s, c, 0,
  3188. 0, 0, 0, 1
  3189. );
  3190. return this;
  3191. },
  3192. makeRotationY: function ( theta ) {
  3193. var c = Math.cos( theta ), s = Math.sin( theta );
  3194. this.set(
  3195. c, 0, s, 0,
  3196. 0, 1, 0, 0,
  3197. - s, 0, c, 0,
  3198. 0, 0, 0, 1
  3199. );
  3200. return this;
  3201. },
  3202. makeRotationZ: function ( theta ) {
  3203. var c = Math.cos( theta ), s = Math.sin( theta );
  3204. this.set(
  3205. c, - s, 0, 0,
  3206. s, c, 0, 0,
  3207. 0, 0, 1, 0,
  3208. 0, 0, 0, 1
  3209. );
  3210. return this;
  3211. },
  3212. makeRotationAxis: function ( axis, angle ) {
  3213. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3214. var c = Math.cos( angle );
  3215. var s = Math.sin( angle );
  3216. var t = 1 - c;
  3217. var x = axis.x, y = axis.y, z = axis.z;
  3218. var tx = t * x, ty = t * y;
  3219. this.set(
  3220. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3221. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3222. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3223. 0, 0, 0, 1
  3224. );
  3225. return this;
  3226. },
  3227. makeScale: function ( x, y, z ) {
  3228. this.set(
  3229. x, 0, 0, 0,
  3230. 0, y, 0, 0,
  3231. 0, 0, z, 0,
  3232. 0, 0, 0, 1
  3233. );
  3234. return this;
  3235. },
  3236. compose: function ( position, quaternion, scale ) {
  3237. this.makeRotationFromQuaternion( quaternion );
  3238. this.scale( scale );
  3239. this.setPosition( position );
  3240. return this;
  3241. },
  3242. decompose: function () {
  3243. var vector, matrix;
  3244. return function ( position, quaternion, scale ) {
  3245. if ( vector === undefined ) vector = new THREE.Vector3();
  3246. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3247. var te = this.elements;
  3248. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3249. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3250. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3251. // if determine is negative, we need to invert one scale
  3252. var det = this.determinant();
  3253. if ( det < 0 ) {
  3254. sx = - sx;
  3255. }
  3256. position.x = te[ 12 ];
  3257. position.y = te[ 13 ];
  3258. position.z = te[ 14 ];
  3259. // scale the rotation part
  3260. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3261. var invSX = 1 / sx;
  3262. var invSY = 1 / sy;
  3263. var invSZ = 1 / sz;
  3264. matrix.elements[ 0 ] *= invSX;
  3265. matrix.elements[ 1 ] *= invSX;
  3266. matrix.elements[ 2 ] *= invSX;
  3267. matrix.elements[ 4 ] *= invSY;
  3268. matrix.elements[ 5 ] *= invSY;
  3269. matrix.elements[ 6 ] *= invSY;
  3270. matrix.elements[ 8 ] *= invSZ;
  3271. matrix.elements[ 9 ] *= invSZ;
  3272. matrix.elements[ 10 ] *= invSZ;
  3273. quaternion.setFromRotationMatrix( matrix );
  3274. scale.x = sx;
  3275. scale.y = sy;
  3276. scale.z = sz;
  3277. return this;
  3278. };
  3279. }(),
  3280. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3281. var te = this.elements;
  3282. var x = 2 * near / ( right - left );
  3283. var y = 2 * near / ( top - bottom );
  3284. var a = ( right + left ) / ( right - left );
  3285. var b = ( top + bottom ) / ( top - bottom );
  3286. var c = - ( far + near ) / ( far - near );
  3287. var d = - 2 * far * near / ( far - near );
  3288. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3289. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3290. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3291. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3292. return this;
  3293. },
  3294. makePerspective: function ( fov, aspect, near, far ) {
  3295. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3296. var ymin = - ymax;
  3297. var xmin = ymin * aspect;
  3298. var xmax = ymax * aspect;
  3299. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3300. },
  3301. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3302. var te = this.elements;
  3303. var w = right - left;
  3304. var h = top - bottom;
  3305. var p = far - near;
  3306. var x = ( right + left ) / w;
  3307. var y = ( top + bottom ) / h;
  3308. var z = ( far + near ) / p;
  3309. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3310. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3311. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3312. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3313. return this;
  3314. },
  3315. equals: function ( matrix ) {
  3316. var te = this.elements;
  3317. var me = matrix.elements;
  3318. for ( var i = 0; i < 16; i ++ ) {
  3319. if ( te[ i ] !== me[ i ] ) return false;
  3320. }
  3321. return true;
  3322. },
  3323. fromArray: function ( array ) {
  3324. this.elements.set( array );
  3325. return this;
  3326. },
  3327. toArray: function () {
  3328. var te = this.elements;
  3329. return [
  3330. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3331. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3332. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3333. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3334. ];
  3335. }
  3336. };
  3337. // File:src/math/Ray.js
  3338. /**
  3339. * @author bhouston / http://clara.io
  3340. */
  3341. THREE.Ray = function ( origin, direction ) {
  3342. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3343. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3344. };
  3345. THREE.Ray.prototype = {
  3346. constructor: THREE.Ray,
  3347. set: function ( origin, direction ) {
  3348. this.origin.copy( origin );
  3349. this.direction.copy( direction );
  3350. return this;
  3351. },
  3352. clone: function () {
  3353. return new this.constructor().copy( this );
  3354. },
  3355. copy: function ( ray ) {
  3356. this.origin.copy( ray.origin );
  3357. this.direction.copy( ray.direction );
  3358. return this;
  3359. },
  3360. at: function ( t, optionalTarget ) {
  3361. var result = optionalTarget || new THREE.Vector3();
  3362. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3363. },
  3364. recast: function () {
  3365. var v1 = new THREE.Vector3();
  3366. return function ( t ) {
  3367. this.origin.copy( this.at( t, v1 ) );
  3368. return this;
  3369. };
  3370. }(),
  3371. closestPointToPoint: function ( point, optionalTarget ) {
  3372. var result = optionalTarget || new THREE.Vector3();
  3373. result.subVectors( point, this.origin );
  3374. var directionDistance = result.dot( this.direction );
  3375. if ( directionDistance < 0 ) {
  3376. return result.copy( this.origin );
  3377. }
  3378. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3379. },
  3380. distanceToPoint: function ( point ) {
  3381. return Math.sqrt( this.distanceSqToPoint( point ) );
  3382. },
  3383. distanceSqToPoint: function () {
  3384. var v1 = new THREE.Vector3();
  3385. return function ( point ) {
  3386. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3387. // point behind the ray
  3388. if ( directionDistance < 0 ) {
  3389. return this.origin.distanceToSquared( point );
  3390. }
  3391. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3392. return v1.distanceToSquared( point );
  3393. };
  3394. }(),
  3395. distanceSqToSegment: function () {
  3396. var segCenter = new THREE.Vector3();
  3397. var segDir = new THREE.Vector3();
  3398. var diff = new THREE.Vector3();
  3399. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3400. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3401. // It returns the min distance between the ray and the segment
  3402. // defined by v0 and v1
  3403. // It can also set two optional targets :
  3404. // - The closest point on the ray
  3405. // - The closest point on the segment
  3406. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3407. segDir.copy( v1 ).sub( v0 ).normalize();
  3408. diff.copy( this.origin ).sub( segCenter );
  3409. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3410. var a01 = - this.direction.dot( segDir );
  3411. var b0 = diff.dot( this.direction );
  3412. var b1 = - diff.dot( segDir );
  3413. var c = diff.lengthSq();
  3414. var det = Math.abs( 1 - a01 * a01 );
  3415. var s0, s1, sqrDist, extDet;
  3416. if ( det > 0 ) {
  3417. // The ray and segment are not parallel.
  3418. s0 = a01 * b1 - b0;
  3419. s1 = a01 * b0 - b1;
  3420. extDet = segExtent * det;
  3421. if ( s0 >= 0 ) {
  3422. if ( s1 >= - extDet ) {
  3423. if ( s1 <= extDet ) {
  3424. // region 0
  3425. // Minimum at interior points of ray and segment.
  3426. var invDet = 1 / det;
  3427. s0 *= invDet;
  3428. s1 *= invDet;
  3429. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3430. } else {
  3431. // region 1
  3432. s1 = segExtent;
  3433. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3434. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3435. }
  3436. } else {
  3437. // region 5
  3438. s1 = - segExtent;
  3439. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3440. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3441. }
  3442. } else {
  3443. if ( s1 <= - extDet ) {
  3444. // region 4
  3445. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3446. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3447. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3448. } else if ( s1 <= extDet ) {
  3449. // region 3
  3450. s0 = 0;
  3451. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3452. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3453. } else {
  3454. // region 2
  3455. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3456. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3457. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3458. }
  3459. }
  3460. } else {
  3461. // Ray and segment are parallel.
  3462. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3463. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3464. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3465. }
  3466. if ( optionalPointOnRay ) {
  3467. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3468. }
  3469. if ( optionalPointOnSegment ) {
  3470. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3471. }
  3472. return sqrDist;
  3473. };
  3474. }(),
  3475. isIntersectionSphere: function ( sphere ) {
  3476. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3477. },
  3478. intersectSphere: function () {
  3479. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3480. var v1 = new THREE.Vector3();
  3481. return function ( sphere, optionalTarget ) {
  3482. v1.subVectors( sphere.center, this.origin );
  3483. var tca = v1.dot( this.direction );
  3484. var d2 = v1.dot( v1 ) - tca * tca;
  3485. var radius2 = sphere.radius * sphere.radius;
  3486. if ( d2 > radius2 ) return null;
  3487. var thc = Math.sqrt( radius2 - d2 );
  3488. // t0 = first intersect point - entrance on front of sphere
  3489. var t0 = tca - thc;
  3490. // t1 = second intersect point - exit point on back of sphere
  3491. var t1 = tca + thc;
  3492. // test to see if both t0 and t1 are behind the ray - if so, return null
  3493. if ( t0 < 0 && t1 < 0 ) return null;
  3494. // test to see if t0 is behind the ray:
  3495. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3496. // in order to always return an intersect point that is in front of the ray.
  3497. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3498. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3499. return this.at( t0, optionalTarget );
  3500. }
  3501. }(),
  3502. isIntersectionPlane: function ( plane ) {
  3503. // check if the ray lies on the plane first
  3504. var distToPoint = plane.distanceToPoint( this.origin );
  3505. if ( distToPoint === 0 ) {
  3506. return true;
  3507. }
  3508. var denominator = plane.normal.dot( this.direction );
  3509. if ( denominator * distToPoint < 0 ) {
  3510. return true;
  3511. }
  3512. // ray origin is behind the plane (and is pointing behind it)
  3513. return false;
  3514. },
  3515. distanceToPlane: function ( plane ) {
  3516. var denominator = plane.normal.dot( this.direction );
  3517. if ( denominator === 0 ) {
  3518. // line is coplanar, return origin
  3519. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3520. return 0;
  3521. }
  3522. // Null is preferable to undefined since undefined means.... it is undefined
  3523. return null;
  3524. }
  3525. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3526. // Return if the ray never intersects the plane
  3527. return t >= 0 ? t : null;
  3528. },
  3529. intersectPlane: function ( plane, optionalTarget ) {
  3530. var t = this.distanceToPlane( plane );
  3531. if ( t === null ) {
  3532. return null;
  3533. }
  3534. return this.at( t, optionalTarget );
  3535. },
  3536. isIntersectionBox: function () {
  3537. var v = new THREE.Vector3();
  3538. return function ( box ) {
  3539. return this.intersectBox( box, v ) !== null;
  3540. };
  3541. }(),
  3542. intersectBox: function ( box, optionalTarget ) {
  3543. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3544. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3545. var invdirx = 1 / this.direction.x,
  3546. invdiry = 1 / this.direction.y,
  3547. invdirz = 1 / this.direction.z;
  3548. var origin = this.origin;
  3549. if ( invdirx >= 0 ) {
  3550. tmin = ( box.min.x - origin.x ) * invdirx;
  3551. tmax = ( box.max.x - origin.x ) * invdirx;
  3552. } else {
  3553. tmin = ( box.max.x - origin.x ) * invdirx;
  3554. tmax = ( box.min.x - origin.x ) * invdirx;
  3555. }
  3556. if ( invdiry >= 0 ) {
  3557. tymin = ( box.min.y - origin.y ) * invdiry;
  3558. tymax = ( box.max.y - origin.y ) * invdiry;
  3559. } else {
  3560. tymin = ( box.max.y - origin.y ) * invdiry;
  3561. tymax = ( box.min.y - origin.y ) * invdiry;
  3562. }
  3563. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3564. // These lines also handle the case where tmin or tmax is NaN
  3565. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3566. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3567. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3568. if ( invdirz >= 0 ) {
  3569. tzmin = ( box.min.z - origin.z ) * invdirz;
  3570. tzmax = ( box.max.z - origin.z ) * invdirz;
  3571. } else {
  3572. tzmin = ( box.max.z - origin.z ) * invdirz;
  3573. tzmax = ( box.min.z - origin.z ) * invdirz;
  3574. }
  3575. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3576. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3577. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3578. //return point closest to the ray (positive side)
  3579. if ( tmax < 0 ) return null;
  3580. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3581. },
  3582. intersectTriangle: function () {
  3583. // Compute the offset origin, edges, and normal.
  3584. var diff = new THREE.Vector3();
  3585. var edge1 = new THREE.Vector3();
  3586. var edge2 = new THREE.Vector3();
  3587. var normal = new THREE.Vector3();
  3588. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3589. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3590. edge1.subVectors( b, a );
  3591. edge2.subVectors( c, a );
  3592. normal.crossVectors( edge1, edge2 );
  3593. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3594. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3595. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3596. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3597. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3598. var DdN = this.direction.dot( normal );
  3599. var sign;
  3600. if ( DdN > 0 ) {
  3601. if ( backfaceCulling ) return null;
  3602. sign = 1;
  3603. } else if ( DdN < 0 ) {
  3604. sign = - 1;
  3605. DdN = - DdN;
  3606. } else {
  3607. return null;
  3608. }
  3609. diff.subVectors( this.origin, a );
  3610. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3611. // b1 < 0, no intersection
  3612. if ( DdQxE2 < 0 ) {
  3613. return null;
  3614. }
  3615. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3616. // b2 < 0, no intersection
  3617. if ( DdE1xQ < 0 ) {
  3618. return null;
  3619. }
  3620. // b1+b2 > 1, no intersection
  3621. if ( DdQxE2 + DdE1xQ > DdN ) {
  3622. return null;
  3623. }
  3624. // Line intersects triangle, check if ray does.
  3625. var QdN = - sign * diff.dot( normal );
  3626. // t < 0, no intersection
  3627. if ( QdN < 0 ) {
  3628. return null;
  3629. }
  3630. // Ray intersects triangle.
  3631. return this.at( QdN / DdN, optionalTarget );
  3632. };
  3633. }(),
  3634. applyMatrix4: function ( matrix4 ) {
  3635. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3636. this.origin.applyMatrix4( matrix4 );
  3637. this.direction.sub( this.origin );
  3638. this.direction.normalize();
  3639. return this;
  3640. },
  3641. equals: function ( ray ) {
  3642. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3643. }
  3644. };
  3645. // File:src/math/Sphere.js
  3646. /**
  3647. * @author bhouston / http://clara.io
  3648. * @author mrdoob / http://mrdoob.com/
  3649. */
  3650. THREE.Sphere = function ( center, radius ) {
  3651. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3652. this.radius = ( radius !== undefined ) ? radius : 0;
  3653. };
  3654. THREE.Sphere.prototype = {
  3655. constructor: THREE.Sphere,
  3656. set: function ( center, radius ) {
  3657. this.center.copy( center );
  3658. this.radius = radius;
  3659. return this;
  3660. },
  3661. setFromPoints: function () {
  3662. var box = new THREE.Box3();
  3663. return function ( points, optionalCenter ) {
  3664. var center = this.center;
  3665. if ( optionalCenter !== undefined ) {
  3666. center.copy( optionalCenter );
  3667. } else {
  3668. box.setFromPoints( points ).center( center );
  3669. }
  3670. var maxRadiusSq = 0;
  3671. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3672. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3673. }
  3674. this.radius = Math.sqrt( maxRadiusSq );
  3675. return this;
  3676. };
  3677. }(),
  3678. clone: function () {
  3679. return new this.constructor().copy( this );
  3680. },
  3681. copy: function ( sphere ) {
  3682. this.center.copy( sphere.center );
  3683. this.radius = sphere.radius;
  3684. return this;
  3685. },
  3686. empty: function () {
  3687. return ( this.radius <= 0 );
  3688. },
  3689. containsPoint: function ( point ) {
  3690. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3691. },
  3692. distanceToPoint: function ( point ) {
  3693. return ( point.distanceTo( this.center ) - this.radius );
  3694. },
  3695. intersectsSphere: function ( sphere ) {
  3696. var radiusSum = this.radius + sphere.radius;
  3697. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3698. },
  3699. clampPoint: function ( point, optionalTarget ) {
  3700. var deltaLengthSq = this.center.distanceToSquared( point );
  3701. var result = optionalTarget || new THREE.Vector3();
  3702. result.copy( point );
  3703. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3704. result.sub( this.center ).normalize();
  3705. result.multiplyScalar( this.radius ).add( this.center );
  3706. }
  3707. return result;
  3708. },
  3709. getBoundingBox: function ( optionalTarget ) {
  3710. var box = optionalTarget || new THREE.Box3();
  3711. box.set( this.center, this.center );
  3712. box.expandByScalar( this.radius );
  3713. return box;
  3714. },
  3715. applyMatrix4: function ( matrix ) {
  3716. this.center.applyMatrix4( matrix );
  3717. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3718. return this;
  3719. },
  3720. translate: function ( offset ) {
  3721. this.center.add( offset );
  3722. return this;
  3723. },
  3724. equals: function ( sphere ) {
  3725. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3726. }
  3727. };
  3728. // File:src/math/Frustum.js
  3729. /**
  3730. * @author mrdoob / http://mrdoob.com/
  3731. * @author alteredq / http://alteredqualia.com/
  3732. * @author bhouston / http://clara.io
  3733. */
  3734. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3735. this.planes = [
  3736. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3737. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3738. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3739. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3740. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3741. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3742. ];
  3743. };
  3744. THREE.Frustum.prototype = {
  3745. constructor: THREE.Frustum,
  3746. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3747. var planes = this.planes;
  3748. planes[ 0 ].copy( p0 );
  3749. planes[ 1 ].copy( p1 );
  3750. planes[ 2 ].copy( p2 );
  3751. planes[ 3 ].copy( p3 );
  3752. planes[ 4 ].copy( p4 );
  3753. planes[ 5 ].copy( p5 );
  3754. return this;
  3755. },
  3756. clone: function () {
  3757. return new this.constructor().copy( this );
  3758. },
  3759. copy: function ( frustum ) {
  3760. var planes = this.planes;
  3761. for ( var i = 0; i < 6; i ++ ) {
  3762. planes[ i ].copy( frustum.planes[ i ] );
  3763. }
  3764. return this;
  3765. },
  3766. setFromMatrix: function ( m ) {
  3767. var planes = this.planes;
  3768. var me = m.elements;
  3769. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3770. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3771. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3772. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3773. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3774. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3775. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3776. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3777. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3778. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3779. return this;
  3780. },
  3781. intersectsObject: function () {
  3782. var sphere = new THREE.Sphere();
  3783. return function ( object ) {
  3784. var geometry = object.geometry;
  3785. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3786. sphere.copy( geometry.boundingSphere );
  3787. sphere.applyMatrix4( object.matrixWorld );
  3788. return this.intersectsSphere( sphere );
  3789. };
  3790. }(),
  3791. intersectsSphere: function ( sphere ) {
  3792. var planes = this.planes;
  3793. var center = sphere.center;
  3794. var negRadius = - sphere.radius;
  3795. for ( var i = 0; i < 6; i ++ ) {
  3796. var distance = planes[ i ].distanceToPoint( center );
  3797. if ( distance < negRadius ) {
  3798. return false;
  3799. }
  3800. }
  3801. return true;
  3802. },
  3803. intersectsBox: function () {
  3804. var p1 = new THREE.Vector3(),
  3805. p2 = new THREE.Vector3();
  3806. return function ( box ) {
  3807. var planes = this.planes;
  3808. for ( var i = 0; i < 6 ; i ++ ) {
  3809. var plane = planes[ i ];
  3810. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3811. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3812. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3813. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3814. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3815. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3816. var d1 = plane.distanceToPoint( p1 );
  3817. var d2 = plane.distanceToPoint( p2 );
  3818. // if both outside plane, no intersection
  3819. if ( d1 < 0 && d2 < 0 ) {
  3820. return false;
  3821. }
  3822. }
  3823. return true;
  3824. };
  3825. }(),
  3826. containsPoint: function ( point ) {
  3827. var planes = this.planes;
  3828. for ( var i = 0; i < 6; i ++ ) {
  3829. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3830. return false;
  3831. }
  3832. }
  3833. return true;
  3834. }
  3835. };
  3836. // File:src/math/Plane.js
  3837. /**
  3838. * @author bhouston / http://clara.io
  3839. */
  3840. THREE.Plane = function ( normal, constant ) {
  3841. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3842. this.constant = ( constant !== undefined ) ? constant : 0;
  3843. };
  3844. THREE.Plane.prototype = {
  3845. constructor: THREE.Plane,
  3846. set: function ( normal, constant ) {
  3847. this.normal.copy( normal );
  3848. this.constant = constant;
  3849. return this;
  3850. },
  3851. setComponents: function ( x, y, z, w ) {
  3852. this.normal.set( x, y, z );
  3853. this.constant = w;
  3854. return this;
  3855. },
  3856. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3857. this.normal.copy( normal );
  3858. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3859. return this;
  3860. },
  3861. setFromCoplanarPoints: function () {
  3862. var v1 = new THREE.Vector3();
  3863. var v2 = new THREE.Vector3();
  3864. return function ( a, b, c ) {
  3865. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3866. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3867. this.setFromNormalAndCoplanarPoint( normal, a );
  3868. return this;
  3869. };
  3870. }(),
  3871. clone: function () {
  3872. return new this.constructor().copy( this );
  3873. },
  3874. copy: function ( plane ) {
  3875. this.normal.copy( plane.normal );
  3876. this.constant = plane.constant;
  3877. return this;
  3878. },
  3879. normalize: function () {
  3880. // Note: will lead to a divide by zero if the plane is invalid.
  3881. var inverseNormalLength = 1.0 / this.normal.length();
  3882. this.normal.multiplyScalar( inverseNormalLength );
  3883. this.constant *= inverseNormalLength;
  3884. return this;
  3885. },
  3886. negate: function () {
  3887. this.constant *= - 1;
  3888. this.normal.negate();
  3889. return this;
  3890. },
  3891. distanceToPoint: function ( point ) {
  3892. return this.normal.dot( point ) + this.constant;
  3893. },
  3894. distanceToSphere: function ( sphere ) {
  3895. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3896. },
  3897. projectPoint: function ( point, optionalTarget ) {
  3898. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3899. },
  3900. orthoPoint: function ( point, optionalTarget ) {
  3901. var perpendicularMagnitude = this.distanceToPoint( point );
  3902. var result = optionalTarget || new THREE.Vector3();
  3903. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3904. },
  3905. isIntersectionLine: function ( line ) {
  3906. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3907. var startSign = this.distanceToPoint( line.start );
  3908. var endSign = this.distanceToPoint( line.end );
  3909. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3910. },
  3911. intersectLine: function () {
  3912. var v1 = new THREE.Vector3();
  3913. return function ( line, optionalTarget ) {
  3914. var result = optionalTarget || new THREE.Vector3();
  3915. var direction = line.delta( v1 );
  3916. var denominator = this.normal.dot( direction );
  3917. if ( denominator === 0 ) {
  3918. // line is coplanar, return origin
  3919. if ( this.distanceToPoint( line.start ) === 0 ) {
  3920. return result.copy( line.start );
  3921. }
  3922. // Unsure if this is the correct method to handle this case.
  3923. return undefined;
  3924. }
  3925. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3926. if ( t < 0 || t > 1 ) {
  3927. return undefined;
  3928. }
  3929. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3930. };
  3931. }(),
  3932. coplanarPoint: function ( optionalTarget ) {
  3933. var result = optionalTarget || new THREE.Vector3();
  3934. return result.copy( this.normal ).multiplyScalar( - this.constant );
  3935. },
  3936. applyMatrix4: function () {
  3937. var v1 = new THREE.Vector3();
  3938. var v2 = new THREE.Vector3();
  3939. var m1 = new THREE.Matrix3();
  3940. return function ( matrix, optionalNormalMatrix ) {
  3941. // compute new normal based on theory here:
  3942. // http://www.songho.ca/opengl/gl_normaltransform.html
  3943. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3944. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  3945. var newCoplanarPoint = this.coplanarPoint( v2 );
  3946. newCoplanarPoint.applyMatrix4( matrix );
  3947. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  3948. return this;
  3949. };
  3950. }(),
  3951. translate: function ( offset ) {
  3952. this.constant = this.constant - offset.dot( this.normal );
  3953. return this;
  3954. },
  3955. equals: function ( plane ) {
  3956. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3957. }
  3958. };
  3959. // File:src/math/Math.js
  3960. /**
  3961. * @author alteredq / http://alteredqualia.com/
  3962. * @author mrdoob / http://mrdoob.com/
  3963. */
  3964. THREE.Math = {
  3965. generateUUID: function () {
  3966. // http://www.broofa.com/Tools/Math.uuid.htm
  3967. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  3968. var uuid = new Array( 36 );
  3969. var rnd = 0, r;
  3970. return function () {
  3971. for ( var i = 0; i < 36; i ++ ) {
  3972. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  3973. uuid[ i ] = '-';
  3974. } else if ( i === 14 ) {
  3975. uuid[ i ] = '4';
  3976. } else {
  3977. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  3978. r = rnd & 0xf;
  3979. rnd = rnd >> 4;
  3980. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  3981. }
  3982. }
  3983. return uuid.join( '' );
  3984. };
  3985. }(),
  3986. clamp: function ( value, min, max ) {
  3987. return Math.max( min, Math.min( max, value ) );
  3988. },
  3989. // compute euclidian modulo of m % n
  3990. // https://en.wikipedia.org/wiki/Modulo_operation
  3991. euclideanModulo: function ( n, m ) {
  3992. return ( ( n % m ) + m ) % m;
  3993. },
  3994. // Linear mapping from range <a1, a2> to range <b1, b2>
  3995. mapLinear: function ( x, a1, a2, b1, b2 ) {
  3996. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  3997. },
  3998. // http://en.wikipedia.org/wiki/Smoothstep
  3999. smoothstep: function ( x, min, max ) {
  4000. if ( x <= min ) return 0;
  4001. if ( x >= max ) return 1;
  4002. x = ( x - min ) / ( max - min );
  4003. return x * x * ( 3 - 2 * x );
  4004. },
  4005. smootherstep: function ( x, min, max ) {
  4006. if ( x <= min ) return 0;
  4007. if ( x >= max ) return 1;
  4008. x = ( x - min ) / ( max - min );
  4009. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4010. },
  4011. // Random float from <0, 1> with 16 bits of randomness
  4012. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4013. random16: function () {
  4014. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4015. },
  4016. // Random integer from <low, high> interval
  4017. randInt: function ( low, high ) {
  4018. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4019. },
  4020. // Random float from <low, high> interval
  4021. randFloat: function ( low, high ) {
  4022. return low + Math.random() * ( high - low );
  4023. },
  4024. // Random float from <-range/2, range/2> interval
  4025. randFloatSpread: function ( range ) {
  4026. return range * ( 0.5 - Math.random() );
  4027. },
  4028. degToRad: function () {
  4029. var degreeToRadiansFactor = Math.PI / 180;
  4030. return function ( degrees ) {
  4031. return degrees * degreeToRadiansFactor;
  4032. };
  4033. }(),
  4034. radToDeg: function () {
  4035. var radianToDegreesFactor = 180 / Math.PI;
  4036. return function ( radians ) {
  4037. return radians * radianToDegreesFactor;
  4038. };
  4039. }(),
  4040. isPowerOfTwo: function ( value ) {
  4041. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4042. },
  4043. nearestPowerOfTwo: function ( value ) {
  4044. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4045. },
  4046. nextPowerOfTwo: function ( value ) {
  4047. value --;
  4048. value |= value >> 1;
  4049. value |= value >> 2;
  4050. value |= value >> 4;
  4051. value |= value >> 8;
  4052. value |= value >> 16;
  4053. value ++;
  4054. return value;
  4055. }
  4056. };
  4057. // File:src/math/Spline.js
  4058. /**
  4059. * Spline from Tween.js, slightly optimized (and trashed)
  4060. * http://sole.github.com/tween.js/examples/05_spline.html
  4061. *
  4062. * @author mrdoob / http://mrdoob.com/
  4063. * @author alteredq / http://alteredqualia.com/
  4064. */
  4065. THREE.Spline = function ( points ) {
  4066. this.points = points;
  4067. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4068. point, intPoint, weight, w2, w3,
  4069. pa, pb, pc, pd;
  4070. this.initFromArray = function ( a ) {
  4071. this.points = [];
  4072. for ( var i = 0; i < a.length; i ++ ) {
  4073. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4074. }
  4075. };
  4076. this.getPoint = function ( k ) {
  4077. point = ( this.points.length - 1 ) * k;
  4078. intPoint = Math.floor( point );
  4079. weight = point - intPoint;
  4080. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4081. c[ 1 ] = intPoint;
  4082. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4083. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4084. pa = this.points[ c[ 0 ] ];
  4085. pb = this.points[ c[ 1 ] ];
  4086. pc = this.points[ c[ 2 ] ];
  4087. pd = this.points[ c[ 3 ] ];
  4088. w2 = weight * weight;
  4089. w3 = weight * w2;
  4090. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4091. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4092. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4093. return v3;
  4094. };
  4095. this.getControlPointsArray = function () {
  4096. var i, p, l = this.points.length,
  4097. coords = [];
  4098. for ( i = 0; i < l; i ++ ) {
  4099. p = this.points[ i ];
  4100. coords[ i ] = [ p.x, p.y, p.z ];
  4101. }
  4102. return coords;
  4103. };
  4104. // approximate length by summing linear segments
  4105. this.getLength = function ( nSubDivisions ) {
  4106. var i, index, nSamples, position,
  4107. point = 0, intPoint = 0, oldIntPoint = 0,
  4108. oldPosition = new THREE.Vector3(),
  4109. tmpVec = new THREE.Vector3(),
  4110. chunkLengths = [],
  4111. totalLength = 0;
  4112. // first point has 0 length
  4113. chunkLengths[ 0 ] = 0;
  4114. if ( ! nSubDivisions ) nSubDivisions = 100;
  4115. nSamples = this.points.length * nSubDivisions;
  4116. oldPosition.copy( this.points[ 0 ] );
  4117. for ( i = 1; i < nSamples; i ++ ) {
  4118. index = i / nSamples;
  4119. position = this.getPoint( index );
  4120. tmpVec.copy( position );
  4121. totalLength += tmpVec.distanceTo( oldPosition );
  4122. oldPosition.copy( position );
  4123. point = ( this.points.length - 1 ) * index;
  4124. intPoint = Math.floor( point );
  4125. if ( intPoint !== oldIntPoint ) {
  4126. chunkLengths[ intPoint ] = totalLength;
  4127. oldIntPoint = intPoint;
  4128. }
  4129. }
  4130. // last point ends with total length
  4131. chunkLengths[ chunkLengths.length ] = totalLength;
  4132. return { chunks: chunkLengths, total: totalLength };
  4133. };
  4134. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4135. var i, j,
  4136. index, indexCurrent, indexNext,
  4137. realDistance,
  4138. sampling, position,
  4139. newpoints = [],
  4140. tmpVec = new THREE.Vector3(),
  4141. sl = this.getLength();
  4142. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4143. for ( i = 1; i < this.points.length; i ++ ) {
  4144. //tmpVec.copy( this.points[ i - 1 ] );
  4145. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4146. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4147. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4148. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4149. indexNext = i / ( this.points.length - 1 );
  4150. for ( j = 1; j < sampling - 1; j ++ ) {
  4151. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4152. position = this.getPoint( index );
  4153. newpoints.push( tmpVec.copy( position ).clone() );
  4154. }
  4155. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4156. }
  4157. this.points = newpoints;
  4158. };
  4159. // Catmull-Rom
  4160. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4161. var v0 = ( p2 - p0 ) * 0.5,
  4162. v1 = ( p3 - p1 ) * 0.5;
  4163. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4164. }
  4165. };
  4166. // File:src/math/Triangle.js
  4167. /**
  4168. * @author bhouston / http://clara.io
  4169. * @author mrdoob / http://mrdoob.com/
  4170. */
  4171. THREE.Triangle = function ( a, b, c ) {
  4172. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4173. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4174. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4175. };
  4176. THREE.Triangle.normal = function () {
  4177. var v0 = new THREE.Vector3();
  4178. return function ( a, b, c, optionalTarget ) {
  4179. var result = optionalTarget || new THREE.Vector3();
  4180. result.subVectors( c, b );
  4181. v0.subVectors( a, b );
  4182. result.cross( v0 );
  4183. var resultLengthSq = result.lengthSq();
  4184. if ( resultLengthSq > 0 ) {
  4185. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4186. }
  4187. return result.set( 0, 0, 0 );
  4188. };
  4189. }();
  4190. // static/instance method to calculate barycentric coordinates
  4191. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4192. THREE.Triangle.barycoordFromPoint = function () {
  4193. var v0 = new THREE.Vector3();
  4194. var v1 = new THREE.Vector3();
  4195. var v2 = new THREE.Vector3();
  4196. return function ( point, a, b, c, optionalTarget ) {
  4197. v0.subVectors( c, a );
  4198. v1.subVectors( b, a );
  4199. v2.subVectors( point, a );
  4200. var dot00 = v0.dot( v0 );
  4201. var dot01 = v0.dot( v1 );
  4202. var dot02 = v0.dot( v2 );
  4203. var dot11 = v1.dot( v1 );
  4204. var dot12 = v1.dot( v2 );
  4205. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4206. var result = optionalTarget || new THREE.Vector3();
  4207. // collinear or singular triangle
  4208. if ( denom === 0 ) {
  4209. // arbitrary location outside of triangle?
  4210. // not sure if this is the best idea, maybe should be returning undefined
  4211. return result.set( - 2, - 1, - 1 );
  4212. }
  4213. var invDenom = 1 / denom;
  4214. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4215. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4216. // barycentric coordinates must always sum to 1
  4217. return result.set( 1 - u - v, v, u );
  4218. };
  4219. }();
  4220. THREE.Triangle.containsPoint = function () {
  4221. var v1 = new THREE.Vector3();
  4222. return function ( point, a, b, c ) {
  4223. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4224. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4225. };
  4226. }();
  4227. THREE.Triangle.prototype = {
  4228. constructor: THREE.Triangle,
  4229. set: function ( a, b, c ) {
  4230. this.a.copy( a );
  4231. this.b.copy( b );
  4232. this.c.copy( c );
  4233. return this;
  4234. },
  4235. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4236. this.a.copy( points[ i0 ] );
  4237. this.b.copy( points[ i1 ] );
  4238. this.c.copy( points[ i2 ] );
  4239. return this;
  4240. },
  4241. clone: function () {
  4242. return new this.constructor().copy( this );
  4243. },
  4244. copy: function ( triangle ) {
  4245. this.a.copy( triangle.a );
  4246. this.b.copy( triangle.b );
  4247. this.c.copy( triangle.c );
  4248. return this;
  4249. },
  4250. area: function () {
  4251. var v0 = new THREE.Vector3();
  4252. var v1 = new THREE.Vector3();
  4253. return function () {
  4254. v0.subVectors( this.c, this.b );
  4255. v1.subVectors( this.a, this.b );
  4256. return v0.cross( v1 ).length() * 0.5;
  4257. };
  4258. }(),
  4259. midpoint: function ( optionalTarget ) {
  4260. var result = optionalTarget || new THREE.Vector3();
  4261. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4262. },
  4263. normal: function ( optionalTarget ) {
  4264. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4265. },
  4266. plane: function ( optionalTarget ) {
  4267. var result = optionalTarget || new THREE.Plane();
  4268. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4269. },
  4270. barycoordFromPoint: function ( point, optionalTarget ) {
  4271. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4272. },
  4273. containsPoint: function ( point ) {
  4274. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4275. },
  4276. equals: function ( triangle ) {
  4277. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4278. }
  4279. };
  4280. // File:src/core/Clock.js
  4281. /**
  4282. * @author alteredq / http://alteredqualia.com/
  4283. */
  4284. THREE.Clock = function ( autoStart ) {
  4285. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4286. this.startTime = 0;
  4287. this.oldTime = 0;
  4288. this.elapsedTime = 0;
  4289. this.running = false;
  4290. };
  4291. THREE.Clock.prototype = {
  4292. constructor: THREE.Clock,
  4293. start: function () {
  4294. this.startTime = self.performance.now();
  4295. this.oldTime = this.startTime;
  4296. this.running = true;
  4297. },
  4298. stop: function () {
  4299. this.getElapsedTime();
  4300. this.running = false;
  4301. },
  4302. getElapsedTime: function () {
  4303. this.getDelta();
  4304. return this.elapsedTime;
  4305. },
  4306. getDelta: function () {
  4307. var diff = 0;
  4308. if ( this.autoStart && ! this.running ) {
  4309. this.start();
  4310. }
  4311. if ( this.running ) {
  4312. var newTime = self.performance.now();
  4313. diff = 0.001 * ( newTime - this.oldTime );
  4314. this.oldTime = newTime;
  4315. this.elapsedTime += diff;
  4316. }
  4317. return diff;
  4318. }
  4319. };
  4320. // File:src/core/EventDispatcher.js
  4321. /**
  4322. * https://github.com/mrdoob/eventdispatcher.js/
  4323. */
  4324. THREE.EventDispatcher = function () {};
  4325. THREE.EventDispatcher.prototype = {
  4326. constructor: THREE.EventDispatcher,
  4327. apply: function ( object ) {
  4328. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4329. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4330. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4331. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4332. },
  4333. addEventListener: function ( type, listener ) {
  4334. if ( this._listeners === undefined ) this._listeners = {};
  4335. var listeners = this._listeners;
  4336. if ( listeners[ type ] === undefined ) {
  4337. listeners[ type ] = [];
  4338. }
  4339. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4340. listeners[ type ].push( listener );
  4341. }
  4342. },
  4343. hasEventListener: function ( type, listener ) {
  4344. if ( this._listeners === undefined ) return false;
  4345. var listeners = this._listeners;
  4346. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4347. return true;
  4348. }
  4349. return false;
  4350. },
  4351. removeEventListener: function ( type, listener ) {
  4352. if ( this._listeners === undefined ) return;
  4353. var listeners = this._listeners;
  4354. var listenerArray = listeners[ type ];
  4355. if ( listenerArray !== undefined ) {
  4356. var index = listenerArray.indexOf( listener );
  4357. if ( index !== - 1 ) {
  4358. listenerArray.splice( index, 1 );
  4359. }
  4360. }
  4361. },
  4362. dispatchEvent: function ( event ) {
  4363. if ( this._listeners === undefined ) return;
  4364. var listeners = this._listeners;
  4365. var listenerArray = listeners[ event.type ];
  4366. if ( listenerArray !== undefined ) {
  4367. event.target = this;
  4368. var array = [];
  4369. var length = listenerArray.length;
  4370. for ( var i = 0; i < length; i ++ ) {
  4371. array[ i ] = listenerArray[ i ];
  4372. }
  4373. for ( var i = 0; i < length; i ++ ) {
  4374. array[ i ].call( this, event );
  4375. }
  4376. }
  4377. }
  4378. };
  4379. // File:src/core/Raycaster.js
  4380. /**
  4381. * @author mrdoob / http://mrdoob.com/
  4382. * @author bhouston / http://clara.io/
  4383. * @author stephomi / http://stephaneginier.com/
  4384. */
  4385. ( function ( THREE ) {
  4386. THREE.Raycaster = function ( origin, direction, near, far ) {
  4387. this.ray = new THREE.Ray( origin, direction );
  4388. // direction is assumed to be normalized (for accurate distance calculations)
  4389. this.near = near || 0;
  4390. this.far = far || Infinity;
  4391. this.params = {
  4392. Mesh: {},
  4393. Line: {},
  4394. LOD: {},
  4395. Points: { threshold: 1 },
  4396. Sprite: {}
  4397. };
  4398. Object.defineProperties( this.params, {
  4399. PointCloud: {
  4400. get: function () {
  4401. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4402. return this.Points;
  4403. }
  4404. }
  4405. } );
  4406. };
  4407. function descSort( a, b ) {
  4408. return a.distance - b.distance;
  4409. }
  4410. function intersectObject( object, raycaster, intersects, recursive ) {
  4411. if ( object.visible === false ) return;
  4412. object.raycast( raycaster, intersects );
  4413. if ( recursive === true ) {
  4414. var children = object.children;
  4415. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4416. intersectObject( children[ i ], raycaster, intersects, true );
  4417. }
  4418. }
  4419. }
  4420. //
  4421. THREE.Raycaster.prototype = {
  4422. constructor: THREE.Raycaster,
  4423. linePrecision: 1,
  4424. set: function ( origin, direction ) {
  4425. // direction is assumed to be normalized (for accurate distance calculations)
  4426. this.ray.set( origin, direction );
  4427. },
  4428. setFromCamera: function ( coords, camera ) {
  4429. if ( camera instanceof THREE.PerspectiveCamera ) {
  4430. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4431. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4432. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4433. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4434. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4435. } else {
  4436. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4437. }
  4438. },
  4439. intersectObject: function ( object, recursive ) {
  4440. var intersects = [];
  4441. intersectObject( object, this, intersects, recursive );
  4442. intersects.sort( descSort );
  4443. return intersects;
  4444. },
  4445. intersectObjects: function ( objects, recursive ) {
  4446. var intersects = [];
  4447. if ( Array.isArray( objects ) === false ) {
  4448. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4449. return intersects;
  4450. }
  4451. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4452. intersectObject( objects[ i ], this, intersects, recursive );
  4453. }
  4454. intersects.sort( descSort );
  4455. return intersects;
  4456. }
  4457. };
  4458. }( THREE ) );
  4459. // File:src/core/Object3D.js
  4460. /**
  4461. * @author mrdoob / http://mrdoob.com/
  4462. * @author mikael emtinger / http://gomo.se/
  4463. * @author alteredq / http://alteredqualia.com/
  4464. * @author WestLangley / http://github.com/WestLangley
  4465. * @author elephantatwork / www.elephantatwork.ch
  4466. */
  4467. THREE.Object3D = function () {
  4468. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4469. this.uuid = THREE.Math.generateUUID();
  4470. this.name = '';
  4471. this.type = 'Object3D';
  4472. this.parent = null;
  4473. this.children = [];
  4474. this.up = THREE.Object3D.DefaultUp.clone();
  4475. var position = new THREE.Vector3();
  4476. var rotation = new THREE.Euler();
  4477. var quaternion = new THREE.Quaternion();
  4478. var scale = new THREE.Vector3( 1, 1, 1 );
  4479. function onRotationChange() {
  4480. quaternion.setFromEuler( rotation, false );
  4481. }
  4482. function onQuaternionChange() {
  4483. rotation.setFromQuaternion( quaternion, undefined, false );
  4484. }
  4485. rotation.onChange( onRotationChange );
  4486. quaternion.onChange( onQuaternionChange );
  4487. Object.defineProperties( this, {
  4488. position: {
  4489. enumerable: true,
  4490. value: position
  4491. },
  4492. rotation: {
  4493. enumerable: true,
  4494. value: rotation
  4495. },
  4496. quaternion: {
  4497. enumerable: true,
  4498. value: quaternion
  4499. },
  4500. scale: {
  4501. enumerable: true,
  4502. value: scale
  4503. },
  4504. modelViewMatrix: {
  4505. value: new THREE.Matrix4()
  4506. },
  4507. normalMatrix: {
  4508. value: new THREE.Matrix3()
  4509. }
  4510. } );
  4511. this.rotationAutoUpdate = true;
  4512. this.matrix = new THREE.Matrix4();
  4513. this.matrixWorld = new THREE.Matrix4();
  4514. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4515. this.matrixWorldNeedsUpdate = false;
  4516. this.visible = true;
  4517. this.castShadow = false;
  4518. this.receiveShadow = false;
  4519. this.frustumCulled = true;
  4520. this.renderOrder = 0;
  4521. this.userData = {};
  4522. };
  4523. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4524. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4525. THREE.Object3D.prototype = {
  4526. constructor: THREE.Object3D,
  4527. get eulerOrder () {
  4528. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  4529. return this.rotation.order;
  4530. },
  4531. set eulerOrder ( value ) {
  4532. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  4533. this.rotation.order = value;
  4534. },
  4535. get useQuaternion () {
  4536. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4537. },
  4538. set useQuaternion ( value ) {
  4539. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4540. },
  4541. set renderDepth ( value ) {
  4542. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4543. },
  4544. //
  4545. applyMatrix: function ( matrix ) {
  4546. this.matrix.multiplyMatrices( matrix, this.matrix );
  4547. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4548. },
  4549. setRotationFromAxisAngle: function ( axis, angle ) {
  4550. // assumes axis is normalized
  4551. this.quaternion.setFromAxisAngle( axis, angle );
  4552. },
  4553. setRotationFromEuler: function ( euler ) {
  4554. this.quaternion.setFromEuler( euler, true );
  4555. },
  4556. setRotationFromMatrix: function ( m ) {
  4557. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4558. this.quaternion.setFromRotationMatrix( m );
  4559. },
  4560. setRotationFromQuaternion: function ( q ) {
  4561. // assumes q is normalized
  4562. this.quaternion.copy( q );
  4563. },
  4564. rotateOnAxis: function () {
  4565. // rotate object on axis in object space
  4566. // axis is assumed to be normalized
  4567. var q1 = new THREE.Quaternion();
  4568. return function ( axis, angle ) {
  4569. q1.setFromAxisAngle( axis, angle );
  4570. this.quaternion.multiply( q1 );
  4571. return this;
  4572. };
  4573. }(),
  4574. rotateX: function () {
  4575. var v1 = new THREE.Vector3( 1, 0, 0 );
  4576. return function ( angle ) {
  4577. return this.rotateOnAxis( v1, angle );
  4578. };
  4579. }(),
  4580. rotateY: function () {
  4581. var v1 = new THREE.Vector3( 0, 1, 0 );
  4582. return function ( angle ) {
  4583. return this.rotateOnAxis( v1, angle );
  4584. };
  4585. }(),
  4586. rotateZ: function () {
  4587. var v1 = new THREE.Vector3( 0, 0, 1 );
  4588. return function ( angle ) {
  4589. return this.rotateOnAxis( v1, angle );
  4590. };
  4591. }(),
  4592. translateOnAxis: function () {
  4593. // translate object by distance along axis in object space
  4594. // axis is assumed to be normalized
  4595. var v1 = new THREE.Vector3();
  4596. return function ( axis, distance ) {
  4597. v1.copy( axis ).applyQuaternion( this.quaternion );
  4598. this.position.add( v1.multiplyScalar( distance ) );
  4599. return this;
  4600. };
  4601. }(),
  4602. translate: function ( distance, axis ) {
  4603. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4604. return this.translateOnAxis( axis, distance );
  4605. },
  4606. translateX: function () {
  4607. var v1 = new THREE.Vector3( 1, 0, 0 );
  4608. return function ( distance ) {
  4609. return this.translateOnAxis( v1, distance );
  4610. };
  4611. }(),
  4612. translateY: function () {
  4613. var v1 = new THREE.Vector3( 0, 1, 0 );
  4614. return function ( distance ) {
  4615. return this.translateOnAxis( v1, distance );
  4616. };
  4617. }(),
  4618. translateZ: function () {
  4619. var v1 = new THREE.Vector3( 0, 0, 1 );
  4620. return function ( distance ) {
  4621. return this.translateOnAxis( v1, distance );
  4622. };
  4623. }(),
  4624. localToWorld: function ( vector ) {
  4625. return vector.applyMatrix4( this.matrixWorld );
  4626. },
  4627. worldToLocal: function () {
  4628. var m1 = new THREE.Matrix4();
  4629. return function ( vector ) {
  4630. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4631. };
  4632. }(),
  4633. lookAt: function () {
  4634. // This routine does not support objects with rotated and/or translated parent(s)
  4635. var m1 = new THREE.Matrix4();
  4636. return function ( vector ) {
  4637. m1.lookAt( vector, this.position, this.up );
  4638. this.quaternion.setFromRotationMatrix( m1 );
  4639. };
  4640. }(),
  4641. add: function ( object ) {
  4642. if ( arguments.length > 1 ) {
  4643. for ( var i = 0; i < arguments.length; i ++ ) {
  4644. this.add( arguments[ i ] );
  4645. }
  4646. return this;
  4647. }
  4648. if ( object === this ) {
  4649. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4650. return this;
  4651. }
  4652. if ( object instanceof THREE.Object3D ) {
  4653. if ( object.parent !== null ) {
  4654. object.parent.remove( object );
  4655. }
  4656. object.parent = this;
  4657. object.dispatchEvent( { type: 'added' } );
  4658. this.children.push( object );
  4659. } else {
  4660. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4661. }
  4662. return this;
  4663. },
  4664. remove: function ( object ) {
  4665. if ( arguments.length > 1 ) {
  4666. for ( var i = 0; i < arguments.length; i ++ ) {
  4667. this.remove( arguments[ i ] );
  4668. }
  4669. }
  4670. var index = this.children.indexOf( object );
  4671. if ( index !== - 1 ) {
  4672. object.parent = null;
  4673. object.dispatchEvent( { type: 'removed' } );
  4674. this.children.splice( index, 1 );
  4675. }
  4676. },
  4677. getChildByName: function ( name ) {
  4678. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4679. return this.getObjectByName( name );
  4680. },
  4681. getObjectById: function ( id ) {
  4682. return this.getObjectByProperty( 'id', id );
  4683. },
  4684. getObjectByName: function ( name ) {
  4685. return this.getObjectByProperty( 'name', name );
  4686. },
  4687. getObjectByProperty: function ( name, value ) {
  4688. if ( this[ name ] === value ) return this;
  4689. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4690. var child = this.children[ i ];
  4691. var object = child.getObjectByProperty( name, value );
  4692. if ( object !== undefined ) {
  4693. return object;
  4694. }
  4695. }
  4696. return undefined;
  4697. },
  4698. getWorldPosition: function ( optionalTarget ) {
  4699. var result = optionalTarget || new THREE.Vector3();
  4700. this.updateMatrixWorld( true );
  4701. return result.setFromMatrixPosition( this.matrixWorld );
  4702. },
  4703. getWorldQuaternion: function () {
  4704. var position = new THREE.Vector3();
  4705. var scale = new THREE.Vector3();
  4706. return function ( optionalTarget ) {
  4707. var result = optionalTarget || new THREE.Quaternion();
  4708. this.updateMatrixWorld( true );
  4709. this.matrixWorld.decompose( position, result, scale );
  4710. return result;
  4711. };
  4712. }(),
  4713. getWorldRotation: function () {
  4714. var quaternion = new THREE.Quaternion();
  4715. return function ( optionalTarget ) {
  4716. var result = optionalTarget || new THREE.Euler();
  4717. this.getWorldQuaternion( quaternion );
  4718. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4719. };
  4720. }(),
  4721. getWorldScale: function () {
  4722. var position = new THREE.Vector3();
  4723. var quaternion = new THREE.Quaternion();
  4724. return function ( optionalTarget ) {
  4725. var result = optionalTarget || new THREE.Vector3();
  4726. this.updateMatrixWorld( true );
  4727. this.matrixWorld.decompose( position, quaternion, result );
  4728. return result;
  4729. };
  4730. }(),
  4731. getWorldDirection: function () {
  4732. var quaternion = new THREE.Quaternion();
  4733. return function ( optionalTarget ) {
  4734. var result = optionalTarget || new THREE.Vector3();
  4735. this.getWorldQuaternion( quaternion );
  4736. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4737. };
  4738. }(),
  4739. raycast: function () {},
  4740. traverse: function ( callback ) {
  4741. callback( this );
  4742. var children = this.children;
  4743. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4744. children[ i ].traverse( callback );
  4745. }
  4746. },
  4747. traverseVisible: function ( callback ) {
  4748. if ( this.visible === false ) return;
  4749. callback( this );
  4750. var children = this.children;
  4751. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4752. children[ i ].traverseVisible( callback );
  4753. }
  4754. },
  4755. traverseAncestors: function ( callback ) {
  4756. var parent = this.parent;
  4757. if ( parent !== null ) {
  4758. callback( parent );
  4759. parent.traverseAncestors( callback );
  4760. }
  4761. },
  4762. updateMatrix: function () {
  4763. this.matrix.compose( this.position, this.quaternion, this.scale );
  4764. this.matrixWorldNeedsUpdate = true;
  4765. },
  4766. updateMatrixWorld: function ( force ) {
  4767. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4768. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4769. if ( this.parent === null ) {
  4770. this.matrixWorld.copy( this.matrix );
  4771. } else {
  4772. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4773. }
  4774. this.matrixWorldNeedsUpdate = false;
  4775. force = true;
  4776. }
  4777. // update children
  4778. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4779. this.children[ i ].updateMatrixWorld( force );
  4780. }
  4781. },
  4782. toJSON: function ( meta ) {
  4783. var isRootObject = ( meta === undefined );
  4784. var output = {};
  4785. // meta is a hash used to collect geometries, materials.
  4786. // not providing it implies that this is the root object
  4787. // being serialized.
  4788. if ( isRootObject ) {
  4789. // initialize meta obj
  4790. meta = {
  4791. geometries: {},
  4792. materials: {},
  4793. textures: {},
  4794. images: {}
  4795. };
  4796. output.metadata = {
  4797. version: 4.4,
  4798. type: 'Object',
  4799. generator: 'Object3D.toJSON'
  4800. };
  4801. }
  4802. // standard Object3D serialization
  4803. var object = {};
  4804. object.uuid = this.uuid;
  4805. object.type = this.type;
  4806. if ( this.name !== '' ) object.name = this.name;
  4807. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  4808. if ( this.castShadow === true ) object.castShadow = true;
  4809. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4810. if ( this.visible === false ) object.visible = false;
  4811. object.matrix = this.matrix.toArray();
  4812. //
  4813. if ( this.geometry !== undefined ) {
  4814. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  4815. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  4816. }
  4817. object.geometry = this.geometry.uuid;
  4818. }
  4819. if ( this.material !== undefined ) {
  4820. if ( meta.materials[ this.material.uuid ] === undefined ) {
  4821. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  4822. }
  4823. object.material = this.material.uuid;
  4824. }
  4825. //
  4826. if ( this.children.length > 0 ) {
  4827. object.children = [];
  4828. for ( var i = 0; i < this.children.length; i ++ ) {
  4829. object.children.push( this.children[ i ].toJSON( meta ).object );
  4830. }
  4831. }
  4832. if ( isRootObject ) {
  4833. var geometries = extractFromCache( meta.geometries );
  4834. var materials = extractFromCache( meta.materials );
  4835. var textures = extractFromCache( meta.textures );
  4836. var images = extractFromCache( meta.images );
  4837. if ( geometries.length > 0 ) output.geometries = geometries;
  4838. if ( materials.length > 0 ) output.materials = materials;
  4839. if ( textures.length > 0 ) output.textures = textures;
  4840. if ( images.length > 0 ) output.images = images;
  4841. }
  4842. output.object = object;
  4843. return output;
  4844. // extract data from the cache hash
  4845. // remove metadata on each item
  4846. // and return as array
  4847. function extractFromCache ( cache ) {
  4848. var values = [];
  4849. for ( var key in cache ) {
  4850. var data = cache[ key ];
  4851. delete data.metadata;
  4852. values.push( data );
  4853. }
  4854. return values;
  4855. }
  4856. },
  4857. clone: function ( recursive ) {
  4858. return new this.constructor().copy( this, recursive );
  4859. },
  4860. copy: function ( source, recursive ) {
  4861. if ( recursive === undefined ) recursive = true;
  4862. this.name = source.name;
  4863. this.up.copy( source.up );
  4864. this.position.copy( source.position );
  4865. this.quaternion.copy( source.quaternion );
  4866. this.scale.copy( source.scale );
  4867. this.rotationAutoUpdate = source.rotationAutoUpdate;
  4868. this.matrix.copy( source.matrix );
  4869. this.matrixWorld.copy( source.matrixWorld );
  4870. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4871. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4872. this.visible = source.visible;
  4873. this.castShadow = source.castShadow;
  4874. this.receiveShadow = source.receiveShadow;
  4875. this.frustumCulled = source.frustumCulled;
  4876. this.renderOrder = source.renderOrder;
  4877. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4878. if ( recursive === true ) {
  4879. for ( var i = 0; i < source.children.length; i ++ ) {
  4880. var child = source.children[ i ];
  4881. this.add( child.clone() );
  4882. }
  4883. }
  4884. return this;
  4885. }
  4886. };
  4887. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4888. THREE.Object3DIdCount = 0;
  4889. // File:src/core/Face3.js
  4890. /**
  4891. * @author mrdoob / http://mrdoob.com/
  4892. * @author alteredq / http://alteredqualia.com/
  4893. */
  4894. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  4895. this.a = a;
  4896. this.b = b;
  4897. this.c = c;
  4898. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4899. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4900. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4901. this.vertexColors = Array.isArray( color ) ? color : [];
  4902. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  4903. };
  4904. THREE.Face3.prototype = {
  4905. constructor: THREE.Face3,
  4906. clone: function () {
  4907. return new this.constructor().copy( this );
  4908. },
  4909. copy: function ( source ) {
  4910. this.a = source.a;
  4911. this.b = source.b;
  4912. this.c = source.c;
  4913. this.normal.copy( source.normal );
  4914. this.color.copy( source.color );
  4915. this.materialIndex = source.materialIndex;
  4916. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  4917. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  4918. }
  4919. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  4920. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  4921. }
  4922. return this;
  4923. }
  4924. };
  4925. // File:src/core/Face4.js
  4926. /**
  4927. * @author mrdoob / http://mrdoob.com/
  4928. */
  4929. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  4930. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  4931. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  4932. };
  4933. // File:src/core/BufferAttribute.js
  4934. /**
  4935. * @author mrdoob / http://mrdoob.com/
  4936. */
  4937. THREE.BufferAttribute = function ( array, itemSize ) {
  4938. this.uuid = THREE.Math.generateUUID();
  4939. this.array = array;
  4940. this.itemSize = itemSize;
  4941. this.dynamic = false;
  4942. this.updateRange = { offset: 0, count: - 1 };
  4943. this.version = 0;
  4944. };
  4945. THREE.BufferAttribute.prototype = {
  4946. constructor: THREE.BufferAttribute,
  4947. get length() {
  4948. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  4949. return this.array.length;
  4950. },
  4951. get count() {
  4952. return this.array.length / this.itemSize;
  4953. },
  4954. set needsUpdate( value ) {
  4955. if ( value === true ) this.version ++;
  4956. },
  4957. setDynamic: function ( value ) {
  4958. this.dynamic = value;
  4959. return this;
  4960. },
  4961. copy: function ( source ) {
  4962. this.array = new source.array.constructor( source.array );
  4963. this.itemSize = source.itemSize;
  4964. this.dynamic = source.dynamic;
  4965. return this;
  4966. },
  4967. copyAt: function ( index1, attribute, index2 ) {
  4968. index1 *= this.itemSize;
  4969. index2 *= attribute.itemSize;
  4970. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  4971. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  4972. }
  4973. return this;
  4974. },
  4975. copyArray: function ( array ) {
  4976. this.array.set( array );
  4977. return this;
  4978. },
  4979. copyColorsArray: function ( colors ) {
  4980. var array = this.array, offset = 0;
  4981. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  4982. var color = colors[ i ];
  4983. if ( color === undefined ) {
  4984. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  4985. color = new THREE.Color();
  4986. }
  4987. array[ offset ++ ] = color.r;
  4988. array[ offset ++ ] = color.g;
  4989. array[ offset ++ ] = color.b;
  4990. }
  4991. return this;
  4992. },
  4993. copyIndicesArray: function ( indices ) {
  4994. var array = this.array, offset = 0;
  4995. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  4996. var index = indices[ i ];
  4997. array[ offset ++ ] = index.a;
  4998. array[ offset ++ ] = index.b;
  4999. array[ offset ++ ] = index.c;
  5000. }
  5001. return this;
  5002. },
  5003. copyVector2sArray: function ( vectors ) {
  5004. var array = this.array, offset = 0;
  5005. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5006. var vector = vectors[ i ];
  5007. if ( vector === undefined ) {
  5008. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5009. vector = new THREE.Vector2();
  5010. }
  5011. array[ offset ++ ] = vector.x;
  5012. array[ offset ++ ] = vector.y;
  5013. }
  5014. return this;
  5015. },
  5016. copyVector3sArray: function ( vectors ) {
  5017. var array = this.array, offset = 0;
  5018. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5019. var vector = vectors[ i ];
  5020. if ( vector === undefined ) {
  5021. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5022. vector = new THREE.Vector3();
  5023. }
  5024. array[ offset ++ ] = vector.x;
  5025. array[ offset ++ ] = vector.y;
  5026. array[ offset ++ ] = vector.z;
  5027. }
  5028. return this;
  5029. },
  5030. copyVector4sArray: function ( vectors ) {
  5031. var array = this.array, offset = 0;
  5032. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5033. var vector = vectors[ i ];
  5034. if ( vector === undefined ) {
  5035. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5036. vector = new THREE.Vector4();
  5037. }
  5038. array[ offset ++ ] = vector.x;
  5039. array[ offset ++ ] = vector.y;
  5040. array[ offset ++ ] = vector.z;
  5041. array[ offset ++ ] = vector.w;
  5042. }
  5043. return this;
  5044. },
  5045. set: function ( value, offset ) {
  5046. if ( offset === undefined ) offset = 0;
  5047. this.array.set( value, offset );
  5048. return this;
  5049. },
  5050. getX: function ( index ) {
  5051. return this.array[ index * this.itemSize ];
  5052. },
  5053. setX: function ( index, x ) {
  5054. this.array[ index * this.itemSize ] = x;
  5055. return this;
  5056. },
  5057. getY: function ( index ) {
  5058. return this.array[ index * this.itemSize + 1 ];
  5059. },
  5060. setY: function ( index, y ) {
  5061. this.array[ index * this.itemSize + 1 ] = y;
  5062. return this;
  5063. },
  5064. getZ: function ( index ) {
  5065. return this.array[ index * this.itemSize + 2 ];
  5066. },
  5067. setZ: function ( index, z ) {
  5068. this.array[ index * this.itemSize + 2 ] = z;
  5069. return this;
  5070. },
  5071. getW: function ( index ) {
  5072. return this.array[ index * this.itemSize + 3 ];
  5073. },
  5074. setW: function ( index, w ) {
  5075. this.array[ index * this.itemSize + 3 ] = w;
  5076. return this;
  5077. },
  5078. setXY: function ( index, x, y ) {
  5079. index *= this.itemSize;
  5080. this.array[ index + 0 ] = x;
  5081. this.array[ index + 1 ] = y;
  5082. return this;
  5083. },
  5084. setXYZ: function ( index, x, y, z ) {
  5085. index *= this.itemSize;
  5086. this.array[ index + 0 ] = x;
  5087. this.array[ index + 1 ] = y;
  5088. this.array[ index + 2 ] = z;
  5089. return this;
  5090. },
  5091. setXYZW: function ( index, x, y, z, w ) {
  5092. index *= this.itemSize;
  5093. this.array[ index + 0 ] = x;
  5094. this.array[ index + 1 ] = y;
  5095. this.array[ index + 2 ] = z;
  5096. this.array[ index + 3 ] = w;
  5097. return this;
  5098. },
  5099. clone: function () {
  5100. return new this.constructor().copy( this );
  5101. }
  5102. };
  5103. //
  5104. THREE.Int8Attribute = function ( array, itemSize ) {
  5105. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5106. };
  5107. THREE.Uint8Attribute = function ( array, itemSize ) {
  5108. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5109. };
  5110. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5111. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5112. };
  5113. THREE.Int16Attribute = function ( array, itemSize ) {
  5114. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5115. };
  5116. THREE.Uint16Attribute = function ( array, itemSize ) {
  5117. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5118. };
  5119. THREE.Int32Attribute = function ( array, itemSize ) {
  5120. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5121. };
  5122. THREE.Uint32Attribute = function ( array, itemSize ) {
  5123. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5124. };
  5125. THREE.Float32Attribute = function ( array, itemSize ) {
  5126. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5127. };
  5128. THREE.Float64Attribute = function ( array, itemSize ) {
  5129. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5130. };
  5131. // Deprecated
  5132. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5133. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5134. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5135. };
  5136. // File:src/core/InstancedBufferAttribute.js
  5137. /**
  5138. * @author benaadams / https://twitter.com/ben_a_adams
  5139. */
  5140. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5141. THREE.BufferAttribute.call( this, array, itemSize );
  5142. this.meshPerAttribute = meshPerAttribute || 1;
  5143. };
  5144. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5145. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5146. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5147. THREE.BufferAttribute.prototype.copy.call( this, source );
  5148. this.meshPerAttribute = source.meshPerAttribute;
  5149. return this;
  5150. };
  5151. // File:src/core/InterleavedBuffer.js
  5152. /**
  5153. * @author benaadams / https://twitter.com/ben_a_adams
  5154. */
  5155. THREE.InterleavedBuffer = function ( array, stride ) {
  5156. this.uuid = THREE.Math.generateUUID();
  5157. this.array = array;
  5158. this.stride = stride;
  5159. this.dynamic = false;
  5160. this.updateRange = { offset: 0, count: - 1 };
  5161. this.version = 0;
  5162. };
  5163. THREE.InterleavedBuffer.prototype = {
  5164. constructor: THREE.InterleavedBuffer,
  5165. get length () {
  5166. return this.array.length;
  5167. },
  5168. get count () {
  5169. return this.array.length / this.stride;
  5170. },
  5171. set needsUpdate( value ) {
  5172. if ( value === true ) this.version ++;
  5173. },
  5174. setDynamic: function ( value ) {
  5175. this.dynamic = value;
  5176. return this;
  5177. },
  5178. copy: function ( source ) {
  5179. this.array = new source.array.constructor( source.array );
  5180. this.stride = source.stride;
  5181. this.dynamic = source.dynamic;
  5182. },
  5183. copyAt: function ( index1, attribute, index2 ) {
  5184. index1 *= this.stride;
  5185. index2 *= attribute.stride;
  5186. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5187. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5188. }
  5189. return this;
  5190. },
  5191. set: function ( value, offset ) {
  5192. if ( offset === undefined ) offset = 0;
  5193. this.array.set( value, offset );
  5194. return this;
  5195. },
  5196. clone: function () {
  5197. return new this.constructor().copy( this );
  5198. }
  5199. };
  5200. // File:src/core/InstancedInterleavedBuffer.js
  5201. /**
  5202. * @author benaadams / https://twitter.com/ben_a_adams
  5203. */
  5204. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5205. THREE.InterleavedBuffer.call( this, array, stride );
  5206. this.meshPerAttribute = meshPerAttribute || 1;
  5207. };
  5208. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5209. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5210. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5211. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5212. this.meshPerAttribute = source.meshPerAttribute;
  5213. return this;
  5214. };
  5215. // File:src/core/InterleavedBufferAttribute.js
  5216. /**
  5217. * @author benaadams / https://twitter.com/ben_a_adams
  5218. */
  5219. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5220. this.uuid = THREE.Math.generateUUID();
  5221. this.data = interleavedBuffer;
  5222. this.itemSize = itemSize;
  5223. this.offset = offset;
  5224. };
  5225. THREE.InterleavedBufferAttribute.prototype = {
  5226. constructor: THREE.InterleavedBufferAttribute,
  5227. get length() {
  5228. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5229. return this.array.length;
  5230. },
  5231. get count() {
  5232. return this.data.array.length / this.data.stride;
  5233. },
  5234. setX: function ( index, x ) {
  5235. this.data.array[ index * this.data.stride + this.offset ] = x;
  5236. return this;
  5237. },
  5238. setY: function ( index, y ) {
  5239. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5240. return this;
  5241. },
  5242. setZ: function ( index, z ) {
  5243. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5244. return this;
  5245. },
  5246. setW: function ( index, w ) {
  5247. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5248. return this;
  5249. },
  5250. getX: function ( index ) {
  5251. return this.data.array[ index * this.data.stride + this.offset ];
  5252. },
  5253. getY: function ( index ) {
  5254. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5255. },
  5256. getZ: function ( index ) {
  5257. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5258. },
  5259. getW: function ( index ) {
  5260. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5261. },
  5262. setXY: function ( index, x, y ) {
  5263. index = index * this.data.stride + this.offset;
  5264. this.data.array[ index + 0 ] = x;
  5265. this.data.array[ index + 1 ] = y;
  5266. return this;
  5267. },
  5268. setXYZ: function ( index, x, y, z ) {
  5269. index = index * this.data.stride + this.offset;
  5270. this.data.array[ index + 0 ] = x;
  5271. this.data.array[ index + 1 ] = y;
  5272. this.data.array[ index + 2 ] = z;
  5273. return this;
  5274. },
  5275. setXYZW: function ( index, x, y, z, w ) {
  5276. index = index * this.data.stride + this.offset;
  5277. this.data.array[ index + 0 ] = x;
  5278. this.data.array[ index + 1 ] = y;
  5279. this.data.array[ index + 2 ] = z;
  5280. this.data.array[ index + 3 ] = w;
  5281. return this;
  5282. }
  5283. };
  5284. // File:src/core/Geometry.js
  5285. /**
  5286. * @author mrdoob / http://mrdoob.com/
  5287. * @author kile / http://kile.stravaganza.org/
  5288. * @author alteredq / http://alteredqualia.com/
  5289. * @author mikael emtinger / http://gomo.se/
  5290. * @author zz85 / http://www.lab4games.net/zz85/blog
  5291. * @author bhouston / http://clara.io
  5292. */
  5293. THREE.Geometry = function () {
  5294. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5295. this.uuid = THREE.Math.generateUUID();
  5296. this.name = '';
  5297. this.type = 'Geometry';
  5298. this.vertices = [];
  5299. this.colors = [];
  5300. this.faces = [];
  5301. this.faceVertexUvs = [ [] ];
  5302. this.morphTargets = [];
  5303. this.morphNormals = [];
  5304. this.skinWeights = [];
  5305. this.skinIndices = [];
  5306. this.lineDistances = [];
  5307. this.boundingBox = null;
  5308. this.boundingSphere = null;
  5309. // update flags
  5310. this.verticesNeedUpdate = false;
  5311. this.elementsNeedUpdate = false;
  5312. this.uvsNeedUpdate = false;
  5313. this.normalsNeedUpdate = false;
  5314. this.colorsNeedUpdate = false;
  5315. this.lineDistancesNeedUpdate = false;
  5316. this.groupsNeedUpdate = false;
  5317. };
  5318. THREE.Geometry.prototype = {
  5319. constructor: THREE.Geometry,
  5320. applyMatrix: function ( matrix ) {
  5321. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5322. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5323. var vertex = this.vertices[ i ];
  5324. vertex.applyMatrix4( matrix );
  5325. }
  5326. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5327. var face = this.faces[ i ];
  5328. face.normal.applyMatrix3( normalMatrix ).normalize();
  5329. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5330. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5331. }
  5332. }
  5333. if ( this.boundingBox !== null ) {
  5334. this.computeBoundingBox();
  5335. }
  5336. if ( this.boundingSphere !== null ) {
  5337. this.computeBoundingSphere();
  5338. }
  5339. this.verticesNeedUpdate = true;
  5340. this.normalsNeedUpdate = true;
  5341. },
  5342. rotateX: function () {
  5343. // rotate geometry around world x-axis
  5344. var m1;
  5345. return function rotateX( angle ) {
  5346. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5347. m1.makeRotationX( angle );
  5348. this.applyMatrix( m1 );
  5349. return this;
  5350. };
  5351. }(),
  5352. rotateY: function () {
  5353. // rotate geometry around world y-axis
  5354. var m1;
  5355. return function rotateY( angle ) {
  5356. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5357. m1.makeRotationY( angle );
  5358. this.applyMatrix( m1 );
  5359. return this;
  5360. };
  5361. }(),
  5362. rotateZ: function () {
  5363. // rotate geometry around world z-axis
  5364. var m1;
  5365. return function rotateZ( angle ) {
  5366. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5367. m1.makeRotationZ( angle );
  5368. this.applyMatrix( m1 );
  5369. return this;
  5370. };
  5371. }(),
  5372. translate: function () {
  5373. // translate geometry
  5374. var m1;
  5375. return function translate( x, y, z ) {
  5376. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5377. m1.makeTranslation( x, y, z );
  5378. this.applyMatrix( m1 );
  5379. return this;
  5380. };
  5381. }(),
  5382. scale: function () {
  5383. // scale geometry
  5384. var m1;
  5385. return function scale( x, y, z ) {
  5386. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5387. m1.makeScale( x, y, z );
  5388. this.applyMatrix( m1 );
  5389. return this;
  5390. };
  5391. }(),
  5392. lookAt: function () {
  5393. var obj;
  5394. return function lookAt( vector ) {
  5395. if ( obj === undefined ) obj = new THREE.Object3D();
  5396. obj.lookAt( vector );
  5397. obj.updateMatrix();
  5398. this.applyMatrix( obj.matrix );
  5399. };
  5400. }(),
  5401. fromBufferGeometry: function ( geometry ) {
  5402. var scope = this;
  5403. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5404. var attributes = geometry.attributes;
  5405. var vertices = attributes.position.array;
  5406. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5407. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5408. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5409. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5410. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5411. var tempNormals = [];
  5412. var tempUVs = [];
  5413. var tempUVs2 = [];
  5414. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5415. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5416. if ( normals !== undefined ) {
  5417. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5418. }
  5419. if ( colors !== undefined ) {
  5420. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5421. }
  5422. if ( uvs !== undefined ) {
  5423. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5424. }
  5425. if ( uvs2 !== undefined ) {
  5426. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5427. }
  5428. }
  5429. function addFace( a, b, c ) {
  5430. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5431. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5432. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5433. scope.faces.push( face );
  5434. if ( uvs !== undefined ) {
  5435. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5436. }
  5437. if ( uvs2 !== undefined ) {
  5438. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5439. }
  5440. };
  5441. if ( indices !== undefined ) {
  5442. var groups = geometry.groups;
  5443. if ( groups.length > 0 ) {
  5444. for ( var i = 0; i < groups.length; i ++ ) {
  5445. var group = groups[ i ];
  5446. var start = group.start;
  5447. var count = group.count;
  5448. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5449. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5450. }
  5451. }
  5452. } else {
  5453. for ( var i = 0; i < indices.length; i += 3 ) {
  5454. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5455. }
  5456. }
  5457. } else {
  5458. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5459. addFace( i, i + 1, i + 2 );
  5460. }
  5461. }
  5462. this.computeFaceNormals();
  5463. if ( geometry.boundingBox !== null ) {
  5464. this.boundingBox = geometry.boundingBox.clone();
  5465. }
  5466. if ( geometry.boundingSphere !== null ) {
  5467. this.boundingSphere = geometry.boundingSphere.clone();
  5468. }
  5469. return this;
  5470. },
  5471. center: function () {
  5472. this.computeBoundingBox();
  5473. var offset = this.boundingBox.center().negate();
  5474. this.translate( offset.x, offset.y, offset.z );
  5475. return offset;
  5476. },
  5477. normalize: function () {
  5478. this.computeBoundingSphere();
  5479. var center = this.boundingSphere.center;
  5480. var radius = this.boundingSphere.radius;
  5481. var s = radius === 0 ? 1 : 1.0 / radius;
  5482. var matrix = new THREE.Matrix4();
  5483. matrix.set(
  5484. s, 0, 0, - s * center.x,
  5485. 0, s, 0, - s * center.y,
  5486. 0, 0, s, - s * center.z,
  5487. 0, 0, 0, 1
  5488. );
  5489. this.applyMatrix( matrix );
  5490. return this;
  5491. },
  5492. computeFaceNormals: function () {
  5493. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5494. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5495. var face = this.faces[ f ];
  5496. var vA = this.vertices[ face.a ];
  5497. var vB = this.vertices[ face.b ];
  5498. var vC = this.vertices[ face.c ];
  5499. cb.subVectors( vC, vB );
  5500. ab.subVectors( vA, vB );
  5501. cb.cross( ab );
  5502. cb.normalize();
  5503. face.normal.copy( cb );
  5504. }
  5505. },
  5506. computeVertexNormals: function ( areaWeighted ) {
  5507. var v, vl, f, fl, face, vertices;
  5508. vertices = new Array( this.vertices.length );
  5509. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5510. vertices[ v ] = new THREE.Vector3();
  5511. }
  5512. if ( areaWeighted ) {
  5513. // vertex normals weighted by triangle areas
  5514. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5515. var vA, vB, vC;
  5516. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5517. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5518. face = this.faces[ f ];
  5519. vA = this.vertices[ face.a ];
  5520. vB = this.vertices[ face.b ];
  5521. vC = this.vertices[ face.c ];
  5522. cb.subVectors( vC, vB );
  5523. ab.subVectors( vA, vB );
  5524. cb.cross( ab );
  5525. vertices[ face.a ].add( cb );
  5526. vertices[ face.b ].add( cb );
  5527. vertices[ face.c ].add( cb );
  5528. }
  5529. } else {
  5530. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5531. face = this.faces[ f ];
  5532. vertices[ face.a ].add( face.normal );
  5533. vertices[ face.b ].add( face.normal );
  5534. vertices[ face.c ].add( face.normal );
  5535. }
  5536. }
  5537. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5538. vertices[ v ].normalize();
  5539. }
  5540. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5541. face = this.faces[ f ];
  5542. var vertexNormals = face.vertexNormals;
  5543. if ( vertexNormals.length === 3 ) {
  5544. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5545. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5546. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5547. } else {
  5548. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5549. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5550. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5551. }
  5552. }
  5553. },
  5554. computeMorphNormals: function () {
  5555. var i, il, f, fl, face;
  5556. // save original normals
  5557. // - create temp variables on first access
  5558. // otherwise just copy (for faster repeated calls)
  5559. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5560. face = this.faces[ f ];
  5561. if ( ! face.__originalFaceNormal ) {
  5562. face.__originalFaceNormal = face.normal.clone();
  5563. } else {
  5564. face.__originalFaceNormal.copy( face.normal );
  5565. }
  5566. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5567. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5568. if ( ! face.__originalVertexNormals[ i ] ) {
  5569. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5570. } else {
  5571. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5572. }
  5573. }
  5574. }
  5575. // use temp geometry to compute face and vertex normals for each morph
  5576. var tmpGeo = new THREE.Geometry();
  5577. tmpGeo.faces = this.faces;
  5578. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5579. // create on first access
  5580. if ( ! this.morphNormals[ i ] ) {
  5581. this.morphNormals[ i ] = {};
  5582. this.morphNormals[ i ].faceNormals = [];
  5583. this.morphNormals[ i ].vertexNormals = [];
  5584. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5585. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5586. var faceNormal, vertexNormals;
  5587. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5588. faceNormal = new THREE.Vector3();
  5589. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5590. dstNormalsFace.push( faceNormal );
  5591. dstNormalsVertex.push( vertexNormals );
  5592. }
  5593. }
  5594. var morphNormals = this.morphNormals[ i ];
  5595. // set vertices to morph target
  5596. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5597. // compute morph normals
  5598. tmpGeo.computeFaceNormals();
  5599. tmpGeo.computeVertexNormals();
  5600. // store morph normals
  5601. var faceNormal, vertexNormals;
  5602. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5603. face = this.faces[ f ];
  5604. faceNormal = morphNormals.faceNormals[ f ];
  5605. vertexNormals = morphNormals.vertexNormals[ f ];
  5606. faceNormal.copy( face.normal );
  5607. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5608. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5609. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5610. }
  5611. }
  5612. // restore original normals
  5613. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5614. face = this.faces[ f ];
  5615. face.normal = face.__originalFaceNormal;
  5616. face.vertexNormals = face.__originalVertexNormals;
  5617. }
  5618. },
  5619. computeTangents: function () {
  5620. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  5621. },
  5622. computeLineDistances: function () {
  5623. var d = 0;
  5624. var vertices = this.vertices;
  5625. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5626. if ( i > 0 ) {
  5627. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5628. }
  5629. this.lineDistances[ i ] = d;
  5630. }
  5631. },
  5632. computeBoundingBox: function () {
  5633. if ( this.boundingBox === null ) {
  5634. this.boundingBox = new THREE.Box3();
  5635. }
  5636. this.boundingBox.setFromPoints( this.vertices );
  5637. },
  5638. computeBoundingSphere: function () {
  5639. if ( this.boundingSphere === null ) {
  5640. this.boundingSphere = new THREE.Sphere();
  5641. }
  5642. this.boundingSphere.setFromPoints( this.vertices );
  5643. },
  5644. merge: function ( geometry, matrix, materialIndexOffset ) {
  5645. if ( geometry instanceof THREE.Geometry === false ) {
  5646. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5647. return;
  5648. }
  5649. var normalMatrix,
  5650. vertexOffset = this.vertices.length,
  5651. vertices1 = this.vertices,
  5652. vertices2 = geometry.vertices,
  5653. faces1 = this.faces,
  5654. faces2 = geometry.faces,
  5655. uvs1 = this.faceVertexUvs[ 0 ],
  5656. uvs2 = geometry.faceVertexUvs[ 0 ];
  5657. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5658. if ( matrix !== undefined ) {
  5659. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5660. }
  5661. // vertices
  5662. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5663. var vertex = vertices2[ i ];
  5664. var vertexCopy = vertex.clone();
  5665. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5666. vertices1.push( vertexCopy );
  5667. }
  5668. // faces
  5669. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5670. var face = faces2[ i ], faceCopy, normal, color,
  5671. faceVertexNormals = face.vertexNormals,
  5672. faceVertexColors = face.vertexColors;
  5673. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5674. faceCopy.normal.copy( face.normal );
  5675. if ( normalMatrix !== undefined ) {
  5676. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5677. }
  5678. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5679. normal = faceVertexNormals[ j ].clone();
  5680. if ( normalMatrix !== undefined ) {
  5681. normal.applyMatrix3( normalMatrix ).normalize();
  5682. }
  5683. faceCopy.vertexNormals.push( normal );
  5684. }
  5685. faceCopy.color.copy( face.color );
  5686. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5687. color = faceVertexColors[ j ];
  5688. faceCopy.vertexColors.push( color.clone() );
  5689. }
  5690. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5691. faces1.push( faceCopy );
  5692. }
  5693. // uvs
  5694. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5695. var uv = uvs2[ i ], uvCopy = [];
  5696. if ( uv === undefined ) {
  5697. continue;
  5698. }
  5699. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5700. uvCopy.push( uv[ j ].clone() );
  5701. }
  5702. uvs1.push( uvCopy );
  5703. }
  5704. },
  5705. mergeMesh: function ( mesh ) {
  5706. if ( mesh instanceof THREE.Mesh === false ) {
  5707. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5708. return;
  5709. }
  5710. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5711. this.merge( mesh.geometry, mesh.matrix );
  5712. },
  5713. /*
  5714. * Checks for duplicate vertices with hashmap.
  5715. * Duplicated vertices are removed
  5716. * and faces' vertices are updated.
  5717. */
  5718. mergeVertices: function () {
  5719. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5720. var unique = [], changes = [];
  5721. var v, key;
  5722. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5723. var precision = Math.pow( 10, precisionPoints );
  5724. var i, il, face;
  5725. var indices, j, jl;
  5726. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5727. v = this.vertices[ i ];
  5728. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5729. if ( verticesMap[ key ] === undefined ) {
  5730. verticesMap[ key ] = i;
  5731. unique.push( this.vertices[ i ] );
  5732. changes[ i ] = unique.length - 1;
  5733. } else {
  5734. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5735. changes[ i ] = changes[ verticesMap[ key ] ];
  5736. }
  5737. }
  5738. // if faces are completely degenerate after merging vertices, we
  5739. // have to remove them from the geometry.
  5740. var faceIndicesToRemove = [];
  5741. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5742. face = this.faces[ i ];
  5743. face.a = changes[ face.a ];
  5744. face.b = changes[ face.b ];
  5745. face.c = changes[ face.c ];
  5746. indices = [ face.a, face.b, face.c ];
  5747. var dupIndex = - 1;
  5748. // if any duplicate vertices are found in a Face3
  5749. // we have to remove the face as nothing can be saved
  5750. for ( var n = 0; n < 3; n ++ ) {
  5751. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5752. dupIndex = n;
  5753. faceIndicesToRemove.push( i );
  5754. break;
  5755. }
  5756. }
  5757. }
  5758. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5759. var idx = faceIndicesToRemove[ i ];
  5760. this.faces.splice( idx, 1 );
  5761. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5762. this.faceVertexUvs[ j ].splice( idx, 1 );
  5763. }
  5764. }
  5765. // Use unique set of vertices
  5766. var diff = this.vertices.length - unique.length;
  5767. this.vertices = unique;
  5768. return diff;
  5769. },
  5770. sortFacesByMaterialIndex: function () {
  5771. var faces = this.faces;
  5772. var length = faces.length;
  5773. // tag faces
  5774. for ( var i = 0; i < length; i ++ ) {
  5775. faces[ i ]._id = i;
  5776. }
  5777. // sort faces
  5778. function materialIndexSort( a, b ) {
  5779. return a.materialIndex - b.materialIndex;
  5780. }
  5781. faces.sort( materialIndexSort );
  5782. // sort uvs
  5783. var uvs1 = this.faceVertexUvs[ 0 ];
  5784. var uvs2 = this.faceVertexUvs[ 1 ];
  5785. var newUvs1, newUvs2;
  5786. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5787. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5788. for ( var i = 0; i < length; i ++ ) {
  5789. var id = faces[ i ]._id;
  5790. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5791. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5792. }
  5793. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5794. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5795. },
  5796. toJSON: function () {
  5797. var data = {
  5798. metadata: {
  5799. version: 4.4,
  5800. type: 'Geometry',
  5801. generator: 'Geometry.toJSON'
  5802. }
  5803. };
  5804. // standard Geometry serialization
  5805. data.uuid = this.uuid;
  5806. data.type = this.type;
  5807. if ( this.name !== '' ) data.name = this.name;
  5808. if ( this.parameters !== undefined ) {
  5809. var parameters = this.parameters;
  5810. for ( var key in parameters ) {
  5811. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5812. }
  5813. return data;
  5814. }
  5815. var vertices = [];
  5816. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5817. var vertex = this.vertices[ i ];
  5818. vertices.push( vertex.x, vertex.y, vertex.z );
  5819. }
  5820. var faces = [];
  5821. var normals = [];
  5822. var normalsHash = {};
  5823. var colors = [];
  5824. var colorsHash = {};
  5825. var uvs = [];
  5826. var uvsHash = {};
  5827. for ( var i = 0; i < this.faces.length; i ++ ) {
  5828. var face = this.faces[ i ];
  5829. var hasMaterial = false; // face.materialIndex !== undefined;
  5830. var hasFaceUv = false; // deprecated
  5831. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5832. var hasFaceNormal = face.normal.length() > 0;
  5833. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5834. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5835. var hasFaceVertexColor = face.vertexColors.length > 0;
  5836. var faceType = 0;
  5837. faceType = setBit( faceType, 0, 0 );
  5838. faceType = setBit( faceType, 1, hasMaterial );
  5839. faceType = setBit( faceType, 2, hasFaceUv );
  5840. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5841. faceType = setBit( faceType, 4, hasFaceNormal );
  5842. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5843. faceType = setBit( faceType, 6, hasFaceColor );
  5844. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5845. faces.push( faceType );
  5846. faces.push( face.a, face.b, face.c );
  5847. if ( hasFaceVertexUv ) {
  5848. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5849. faces.push(
  5850. getUvIndex( faceVertexUvs[ 0 ] ),
  5851. getUvIndex( faceVertexUvs[ 1 ] ),
  5852. getUvIndex( faceVertexUvs[ 2 ] )
  5853. );
  5854. }
  5855. if ( hasFaceNormal ) {
  5856. faces.push( getNormalIndex( face.normal ) );
  5857. }
  5858. if ( hasFaceVertexNormal ) {
  5859. var vertexNormals = face.vertexNormals;
  5860. faces.push(
  5861. getNormalIndex( vertexNormals[ 0 ] ),
  5862. getNormalIndex( vertexNormals[ 1 ] ),
  5863. getNormalIndex( vertexNormals[ 2 ] )
  5864. );
  5865. }
  5866. if ( hasFaceColor ) {
  5867. faces.push( getColorIndex( face.color ) );
  5868. }
  5869. if ( hasFaceVertexColor ) {
  5870. var vertexColors = face.vertexColors;
  5871. faces.push(
  5872. getColorIndex( vertexColors[ 0 ] ),
  5873. getColorIndex( vertexColors[ 1 ] ),
  5874. getColorIndex( vertexColors[ 2 ] )
  5875. );
  5876. }
  5877. }
  5878. function setBit( value, position, enabled ) {
  5879. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5880. }
  5881. function getNormalIndex( normal ) {
  5882. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5883. if ( normalsHash[ hash ] !== undefined ) {
  5884. return normalsHash[ hash ];
  5885. }
  5886. normalsHash[ hash ] = normals.length / 3;
  5887. normals.push( normal.x, normal.y, normal.z );
  5888. return normalsHash[ hash ];
  5889. }
  5890. function getColorIndex( color ) {
  5891. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5892. if ( colorsHash[ hash ] !== undefined ) {
  5893. return colorsHash[ hash ];
  5894. }
  5895. colorsHash[ hash ] = colors.length;
  5896. colors.push( color.getHex() );
  5897. return colorsHash[ hash ];
  5898. }
  5899. function getUvIndex( uv ) {
  5900. var hash = uv.x.toString() + uv.y.toString();
  5901. if ( uvsHash[ hash ] !== undefined ) {
  5902. return uvsHash[ hash ];
  5903. }
  5904. uvsHash[ hash ] = uvs.length / 2;
  5905. uvs.push( uv.x, uv.y );
  5906. return uvsHash[ hash ];
  5907. }
  5908. data.data = {};
  5909. data.data.vertices = vertices;
  5910. data.data.normals = normals;
  5911. if ( colors.length > 0 ) data.data.colors = colors;
  5912. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  5913. data.data.faces = faces;
  5914. return data;
  5915. },
  5916. clone: function () {
  5917. return new this.constructor().copy( this );
  5918. },
  5919. copy: function ( source ) {
  5920. this.vertices = [];
  5921. this.faces = [];
  5922. this.faceVertexUvs = [ [] ];
  5923. var vertices = source.vertices;
  5924. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5925. this.vertices.push( vertices[ i ].clone() );
  5926. }
  5927. var faces = source.faces;
  5928. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  5929. this.faces.push( faces[ i ].clone() );
  5930. }
  5931. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  5932. var faceVertexUvs = source.faceVertexUvs[ i ];
  5933. if ( this.faceVertexUvs[ i ] === undefined ) {
  5934. this.faceVertexUvs[ i ] = [];
  5935. }
  5936. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  5937. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  5938. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  5939. var uv = uvs[ k ];
  5940. uvsCopy.push( uv.clone() );
  5941. }
  5942. this.faceVertexUvs[ i ].push( uvsCopy );
  5943. }
  5944. }
  5945. return this;
  5946. },
  5947. dispose: function () {
  5948. this.dispatchEvent( { type: 'dispose' } );
  5949. }
  5950. };
  5951. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  5952. THREE.GeometryIdCount = 0;
  5953. // File:src/core/DirectGeometry.js
  5954. /**
  5955. * @author mrdoob / http://mrdoob.com/
  5956. */
  5957. THREE.DirectGeometry = function () {
  5958. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5959. this.uuid = THREE.Math.generateUUID();
  5960. this.name = '';
  5961. this.type = 'DirectGeometry';
  5962. this.indices = [];
  5963. this.vertices = [];
  5964. this.normals = [];
  5965. this.colors = [];
  5966. this.uvs = [];
  5967. this.uvs2 = [];
  5968. this.groups = [];
  5969. this.morphTargets = {};
  5970. this.skinWeights = [];
  5971. this.skinIndices = [];
  5972. // this.lineDistances = [];
  5973. this.boundingBox = null;
  5974. this.boundingSphere = null;
  5975. // update flags
  5976. this.verticesNeedUpdate = false;
  5977. this.normalsNeedUpdate = false;
  5978. this.colorsNeedUpdate = false;
  5979. this.uvsNeedUpdate = false;
  5980. this.groupsNeedUpdate = false;
  5981. };
  5982. THREE.DirectGeometry.prototype = {
  5983. constructor: THREE.DirectGeometry,
  5984. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  5985. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  5986. computeFaceNormals: function () {
  5987. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  5988. },
  5989. computeVertexNormals: function () {
  5990. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  5991. },
  5992. computeGroups: function ( geometry ) {
  5993. var group;
  5994. var groups = [];
  5995. var materialIndex;
  5996. var faces = geometry.faces;
  5997. for ( var i = 0; i < faces.length; i ++ ) {
  5998. var face = faces[ i ];
  5999. // materials
  6000. if ( face.materialIndex !== materialIndex ) {
  6001. materialIndex = face.materialIndex;
  6002. if ( group !== undefined ) {
  6003. group.count = ( i * 3 ) - group.start;
  6004. groups.push( group );
  6005. }
  6006. group = {
  6007. start: i * 3,
  6008. materialIndex: materialIndex
  6009. };
  6010. }
  6011. }
  6012. if ( group !== undefined ) {
  6013. group.count = ( i * 3 ) - group.start;
  6014. groups.push( group );
  6015. }
  6016. this.groups = groups;
  6017. },
  6018. fromGeometry: function ( geometry ) {
  6019. var faces = geometry.faces;
  6020. var vertices = geometry.vertices;
  6021. var faceVertexUvs = geometry.faceVertexUvs;
  6022. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6023. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6024. // morphs
  6025. var morphTargets = geometry.morphTargets;
  6026. var morphTargetsLength = morphTargets.length;
  6027. if ( morphTargetsLength > 0 ) {
  6028. var morphTargetsPosition = [];
  6029. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6030. morphTargetsPosition[ i ] = [];
  6031. }
  6032. this.morphTargets.position = morphTargetsPosition;
  6033. }
  6034. var morphNormals = geometry.morphNormals;
  6035. var morphNormalsLength = morphNormals.length;
  6036. if ( morphNormalsLength > 0 ) {
  6037. var morphTargetsNormal = [];
  6038. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6039. morphTargetsNormal[ i ] = [];
  6040. }
  6041. this.morphTargets.normal = morphTargetsNormal;
  6042. }
  6043. // skins
  6044. var skinIndices = geometry.skinIndices;
  6045. var skinWeights = geometry.skinWeights;
  6046. var hasSkinIndices = skinIndices.length === vertices.length;
  6047. var hasSkinWeights = skinWeights.length === vertices.length;
  6048. //
  6049. for ( var i = 0; i < faces.length; i ++ ) {
  6050. var face = faces[ i ];
  6051. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6052. var vertexNormals = face.vertexNormals;
  6053. if ( vertexNormals.length === 3 ) {
  6054. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6055. } else {
  6056. var normal = face.normal;
  6057. this.normals.push( normal, normal, normal );
  6058. }
  6059. var vertexColors = face.vertexColors;
  6060. if ( vertexColors.length === 3 ) {
  6061. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6062. } else {
  6063. var color = face.color;
  6064. this.colors.push( color, color, color );
  6065. }
  6066. if ( hasFaceVertexUv === true ) {
  6067. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6068. if ( vertexUvs !== undefined ) {
  6069. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6070. } else {
  6071. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6072. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6073. }
  6074. }
  6075. if ( hasFaceVertexUv2 === true ) {
  6076. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6077. if ( vertexUvs !== undefined ) {
  6078. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6079. } else {
  6080. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6081. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6082. }
  6083. }
  6084. // morphs
  6085. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6086. var morphTarget = morphTargets[ j ].vertices;
  6087. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6088. }
  6089. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6090. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6091. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6092. }
  6093. // skins
  6094. if ( hasSkinIndices ) {
  6095. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6096. }
  6097. if ( hasSkinWeights ) {
  6098. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6099. }
  6100. }
  6101. this.computeGroups( geometry );
  6102. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6103. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6104. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6105. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6106. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6107. return this;
  6108. },
  6109. dispose: function () {
  6110. this.dispatchEvent( { type: 'dispose' } );
  6111. }
  6112. };
  6113. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6114. // File:src/core/BufferGeometry.js
  6115. /**
  6116. * @author alteredq / http://alteredqualia.com/
  6117. * @author mrdoob / http://mrdoob.com/
  6118. */
  6119. THREE.BufferGeometry = function () {
  6120. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6121. this.uuid = THREE.Math.generateUUID();
  6122. this.name = '';
  6123. this.type = 'BufferGeometry';
  6124. this.index = null;
  6125. this.attributes = {};
  6126. this.morphAttributes = {};
  6127. this.groups = [];
  6128. this.boundingBox = null;
  6129. this.boundingSphere = null;
  6130. this.drawRange = { start: 0, count: Infinity };
  6131. };
  6132. THREE.BufferGeometry.prototype = {
  6133. constructor: THREE.BufferGeometry,
  6134. addIndex: function ( index ) {
  6135. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  6136. this.setIndex( index );
  6137. },
  6138. getIndex: function () {
  6139. return this.index;
  6140. },
  6141. setIndex: function ( index ) {
  6142. this.index = index;
  6143. },
  6144. addAttribute: function ( name, attribute ) {
  6145. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6146. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6147. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6148. return;
  6149. }
  6150. if ( name === 'index' ) {
  6151. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6152. this.setIndex( attribute );
  6153. return;
  6154. }
  6155. this.attributes[ name ] = attribute;
  6156. },
  6157. getAttribute: function ( name ) {
  6158. return this.attributes[ name ];
  6159. },
  6160. removeAttribute: function ( name ) {
  6161. delete this.attributes[ name ];
  6162. },
  6163. get drawcalls() {
  6164. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  6165. return this.groups;
  6166. },
  6167. get offsets() {
  6168. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  6169. return this.groups;
  6170. },
  6171. addDrawCall: function ( start, count, indexOffset ) {
  6172. if ( indexOffset !== undefined ) {
  6173. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  6174. }
  6175. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  6176. this.addGroup( start, count );
  6177. },
  6178. clearDrawCalls: function () {
  6179. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  6180. this.clearGroups();
  6181. },
  6182. addGroup: function ( start, count, materialIndex ) {
  6183. this.groups.push( {
  6184. start: start,
  6185. count: count,
  6186. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6187. } );
  6188. },
  6189. clearGroups: function () {
  6190. this.groups = [];
  6191. },
  6192. setDrawRange: function ( start, count ) {
  6193. this.drawRange.start = start;
  6194. this.drawRange.count = count;
  6195. },
  6196. applyMatrix: function ( matrix ) {
  6197. var position = this.attributes.position;
  6198. if ( position !== undefined ) {
  6199. matrix.applyToVector3Array( position.array );
  6200. position.needsUpdate = true;
  6201. }
  6202. var normal = this.attributes.normal;
  6203. if ( normal !== undefined ) {
  6204. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6205. normalMatrix.applyToVector3Array( normal.array );
  6206. normal.needsUpdate = true;
  6207. }
  6208. if ( this.boundingBox !== null ) {
  6209. this.computeBoundingBox();
  6210. }
  6211. if ( this.boundingSphere !== null ) {
  6212. this.computeBoundingSphere();
  6213. }
  6214. },
  6215. rotateX: function () {
  6216. // rotate geometry around world x-axis
  6217. var m1;
  6218. return function rotateX( angle ) {
  6219. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6220. m1.makeRotationX( angle );
  6221. this.applyMatrix( m1 );
  6222. return this;
  6223. };
  6224. }(),
  6225. rotateY: function () {
  6226. // rotate geometry around world y-axis
  6227. var m1;
  6228. return function rotateY( angle ) {
  6229. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6230. m1.makeRotationY( angle );
  6231. this.applyMatrix( m1 );
  6232. return this;
  6233. };
  6234. }(),
  6235. rotateZ: function () {
  6236. // rotate geometry around world z-axis
  6237. var m1;
  6238. return function rotateZ( angle ) {
  6239. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6240. m1.makeRotationZ( angle );
  6241. this.applyMatrix( m1 );
  6242. return this;
  6243. };
  6244. }(),
  6245. translate: function () {
  6246. // translate geometry
  6247. var m1;
  6248. return function translate( x, y, z ) {
  6249. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6250. m1.makeTranslation( x, y, z );
  6251. this.applyMatrix( m1 );
  6252. return this;
  6253. };
  6254. }(),
  6255. scale: function () {
  6256. // scale geometry
  6257. var m1;
  6258. return function scale( x, y, z ) {
  6259. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6260. m1.makeScale( x, y, z );
  6261. this.applyMatrix( m1 );
  6262. return this;
  6263. };
  6264. }(),
  6265. lookAt: function () {
  6266. var obj;
  6267. return function lookAt( vector ) {
  6268. if ( obj === undefined ) obj = new THREE.Object3D();
  6269. obj.lookAt( vector );
  6270. obj.updateMatrix();
  6271. this.applyMatrix( obj.matrix );
  6272. };
  6273. }(),
  6274. center: function () {
  6275. this.computeBoundingBox();
  6276. var offset = this.boundingBox.center().negate();
  6277. this.translate( offset.x, offset.y, offset.z );
  6278. return offset;
  6279. },
  6280. setFromObject: function ( object ) {
  6281. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6282. var geometry = object.geometry;
  6283. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6284. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6285. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6286. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6287. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6288. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6289. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6290. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6291. }
  6292. if ( geometry.boundingSphere !== null ) {
  6293. this.boundingSphere = geometry.boundingSphere.clone();
  6294. }
  6295. if ( geometry.boundingBox !== null ) {
  6296. this.boundingBox = geometry.boundingBox.clone();
  6297. }
  6298. } else if ( object instanceof THREE.Mesh ) {
  6299. if ( geometry instanceof THREE.Geometry ) {
  6300. this.fromGeometry( geometry );
  6301. }
  6302. }
  6303. return this;
  6304. },
  6305. updateFromObject: function ( object ) {
  6306. var geometry = object.geometry;
  6307. if ( object instanceof THREE.Mesh ) {
  6308. var direct = geometry.__directGeometry;
  6309. if ( direct === undefined ) {
  6310. return this.fromGeometry( geometry );
  6311. }
  6312. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6313. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6314. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6315. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6316. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6317. geometry.verticesNeedUpdate = false;
  6318. geometry.normalsNeedUpdate = false;
  6319. geometry.colorsNeedUpdate = false;
  6320. geometry.uvsNeedUpdate = false;
  6321. geometry.groupsNeedUpdate = false;
  6322. geometry = direct;
  6323. }
  6324. if ( geometry.verticesNeedUpdate === true ) {
  6325. var attribute = this.attributes.position;
  6326. if ( attribute !== undefined ) {
  6327. attribute.copyVector3sArray( geometry.vertices );
  6328. attribute.needsUpdate = true;
  6329. }
  6330. geometry.verticesNeedUpdate = false;
  6331. }
  6332. if ( geometry.normalsNeedUpdate === true ) {
  6333. var attribute = this.attributes.normal;
  6334. if ( attribute !== undefined ) {
  6335. attribute.copyVector3sArray( geometry.normals );
  6336. attribute.needsUpdate = true;
  6337. }
  6338. geometry.normalsNeedUpdate = false;
  6339. }
  6340. if ( geometry.colorsNeedUpdate === true ) {
  6341. var attribute = this.attributes.color;
  6342. if ( attribute !== undefined ) {
  6343. attribute.copyColorsArray( geometry.colors );
  6344. attribute.needsUpdate = true;
  6345. }
  6346. geometry.colorsNeedUpdate = false;
  6347. }
  6348. if ( geometry.uvsNeedUpdate ) {
  6349. var attribute = this.attributes.uv;
  6350. if ( attribute !== undefined ) {
  6351. attribute.copyVector2sArray( geometry.uvs );
  6352. attribute.needsUpdate = true;
  6353. }
  6354. geometry.uvsNeedUpdate = false;
  6355. }
  6356. if ( geometry.lineDistancesNeedUpdate ) {
  6357. var attribute = this.attributes.lineDistance;
  6358. if ( attribute !== undefined ) {
  6359. attribute.copyArray( geometry.lineDistances );
  6360. attribute.needsUpdate = true;
  6361. }
  6362. geometry.lineDistancesNeedUpdate = false;
  6363. }
  6364. if ( geometry.groupsNeedUpdate ) {
  6365. geometry.computeGroups( object.geometry );
  6366. this.groups = geometry.groups;
  6367. geometry.groupsNeedUpdate = false;
  6368. }
  6369. return this;
  6370. },
  6371. fromGeometry: function ( geometry ) {
  6372. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6373. return this.fromDirectGeometry( geometry.__directGeometry );
  6374. },
  6375. fromDirectGeometry: function ( geometry ) {
  6376. var positions = new Float32Array( geometry.vertices.length * 3 );
  6377. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6378. if ( geometry.normals.length > 0 ) {
  6379. var normals = new Float32Array( geometry.normals.length * 3 );
  6380. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6381. }
  6382. if ( geometry.colors.length > 0 ) {
  6383. var colors = new Float32Array( geometry.colors.length * 3 );
  6384. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6385. }
  6386. if ( geometry.uvs.length > 0 ) {
  6387. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6388. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6389. }
  6390. if ( geometry.uvs2.length > 0 ) {
  6391. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6392. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6393. }
  6394. if ( geometry.indices.length > 0 ) {
  6395. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6396. var indices = new TypeArray( geometry.indices.length * 3 );
  6397. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6398. }
  6399. // groups
  6400. this.groups = geometry.groups;
  6401. // morphs
  6402. for ( var name in geometry.morphTargets ) {
  6403. var array = [];
  6404. var morphTargets = geometry.morphTargets[ name ];
  6405. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6406. var morphTarget = morphTargets[ i ];
  6407. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6408. array.push( attribute.copyVector3sArray( morphTarget ) );
  6409. }
  6410. this.morphAttributes[ name ] = array;
  6411. }
  6412. // skinning
  6413. if ( geometry.skinIndices.length > 0 ) {
  6414. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6415. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6416. }
  6417. if ( geometry.skinWeights.length > 0 ) {
  6418. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6419. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6420. }
  6421. //
  6422. if ( geometry.boundingSphere !== null ) {
  6423. this.boundingSphere = geometry.boundingSphere.clone();
  6424. }
  6425. if ( geometry.boundingBox !== null ) {
  6426. this.boundingBox = geometry.boundingBox.clone();
  6427. }
  6428. return this;
  6429. },
  6430. computeBoundingBox: function () {
  6431. var vector = new THREE.Vector3();
  6432. return function () {
  6433. if ( this.boundingBox === null ) {
  6434. this.boundingBox = new THREE.Box3();
  6435. }
  6436. var positions = this.attributes.position.array;
  6437. if ( positions ) {
  6438. var bb = this.boundingBox;
  6439. bb.makeEmpty();
  6440. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6441. vector.fromArray( positions, i );
  6442. bb.expandByPoint( vector );
  6443. }
  6444. }
  6445. if ( positions === undefined || positions.length === 0 ) {
  6446. this.boundingBox.min.set( 0, 0, 0 );
  6447. this.boundingBox.max.set( 0, 0, 0 );
  6448. }
  6449. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6450. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6451. }
  6452. };
  6453. }(),
  6454. computeBoundingSphere: function () {
  6455. var box = new THREE.Box3();
  6456. var vector = new THREE.Vector3();
  6457. return function () {
  6458. if ( this.boundingSphere === null ) {
  6459. this.boundingSphere = new THREE.Sphere();
  6460. }
  6461. var positions = this.attributes.position.array;
  6462. if ( positions ) {
  6463. box.makeEmpty();
  6464. var center = this.boundingSphere.center;
  6465. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6466. vector.fromArray( positions, i );
  6467. box.expandByPoint( vector );
  6468. }
  6469. box.center( center );
  6470. // hoping to find a boundingSphere with a radius smaller than the
  6471. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6472. var maxRadiusSq = 0;
  6473. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6474. vector.fromArray( positions, i );
  6475. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6476. }
  6477. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6478. if ( isNaN( this.boundingSphere.radius ) ) {
  6479. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6480. }
  6481. }
  6482. };
  6483. }(),
  6484. computeFaceNormals: function () {
  6485. // backwards compatibility
  6486. },
  6487. computeVertexNormals: function () {
  6488. var index = this.index;
  6489. var attributes = this.attributes;
  6490. var groups = this.groups;
  6491. if ( attributes.position ) {
  6492. var positions = attributes.position.array;
  6493. if ( attributes.normal === undefined ) {
  6494. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6495. } else {
  6496. // reset existing normals to zero
  6497. var normals = attributes.normal.array;
  6498. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6499. normals[ i ] = 0;
  6500. }
  6501. }
  6502. var normals = attributes.normal.array;
  6503. var vA, vB, vC,
  6504. pA = new THREE.Vector3(),
  6505. pB = new THREE.Vector3(),
  6506. pC = new THREE.Vector3(),
  6507. cb = new THREE.Vector3(),
  6508. ab = new THREE.Vector3();
  6509. // indexed elements
  6510. if ( index ) {
  6511. var indices = index.array;
  6512. if ( groups.length === 0 ) {
  6513. this.addGroup( 0, indices.length );
  6514. }
  6515. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6516. var group = groups[ j ];
  6517. var start = group.start;
  6518. var count = group.count;
  6519. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6520. vA = indices[ i + 0 ] * 3;
  6521. vB = indices[ i + 1 ] * 3;
  6522. vC = indices[ i + 2 ] * 3;
  6523. pA.fromArray( positions, vA );
  6524. pB.fromArray( positions, vB );
  6525. pC.fromArray( positions, vC );
  6526. cb.subVectors( pC, pB );
  6527. ab.subVectors( pA, pB );
  6528. cb.cross( ab );
  6529. normals[ vA ] += cb.x;
  6530. normals[ vA + 1 ] += cb.y;
  6531. normals[ vA + 2 ] += cb.z;
  6532. normals[ vB ] += cb.x;
  6533. normals[ vB + 1 ] += cb.y;
  6534. normals[ vB + 2 ] += cb.z;
  6535. normals[ vC ] += cb.x;
  6536. normals[ vC + 1 ] += cb.y;
  6537. normals[ vC + 2 ] += cb.z;
  6538. }
  6539. }
  6540. } else {
  6541. // non-indexed elements (unconnected triangle soup)
  6542. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6543. pA.fromArray( positions, i );
  6544. pB.fromArray( positions, i + 3 );
  6545. pC.fromArray( positions, i + 6 );
  6546. cb.subVectors( pC, pB );
  6547. ab.subVectors( pA, pB );
  6548. cb.cross( ab );
  6549. normals[ i ] = cb.x;
  6550. normals[ i + 1 ] = cb.y;
  6551. normals[ i + 2 ] = cb.z;
  6552. normals[ i + 3 ] = cb.x;
  6553. normals[ i + 4 ] = cb.y;
  6554. normals[ i + 5 ] = cb.z;
  6555. normals[ i + 6 ] = cb.x;
  6556. normals[ i + 7 ] = cb.y;
  6557. normals[ i + 8 ] = cb.z;
  6558. }
  6559. }
  6560. this.normalizeNormals();
  6561. attributes.normal.needsUpdate = true;
  6562. }
  6563. },
  6564. computeTangents: function () {
  6565. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  6566. },
  6567. computeOffsets: function ( size ) {
  6568. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.')
  6569. },
  6570. merge: function ( geometry, offset ) {
  6571. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6572. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6573. return;
  6574. }
  6575. if ( offset === undefined ) offset = 0;
  6576. var attributes = this.attributes;
  6577. for ( var key in attributes ) {
  6578. if ( geometry.attributes[ key ] === undefined ) continue;
  6579. var attribute1 = attributes[ key ];
  6580. var attributeArray1 = attribute1.array;
  6581. var attribute2 = geometry.attributes[ key ];
  6582. var attributeArray2 = attribute2.array;
  6583. var attributeSize = attribute2.itemSize;
  6584. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6585. attributeArray1[ j ] = attributeArray2[ i ];
  6586. }
  6587. }
  6588. return this;
  6589. },
  6590. normalizeNormals: function () {
  6591. var normals = this.attributes.normal.array;
  6592. var x, y, z, n;
  6593. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6594. x = normals[ i ];
  6595. y = normals[ i + 1 ];
  6596. z = normals[ i + 2 ];
  6597. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6598. normals[ i ] *= n;
  6599. normals[ i + 1 ] *= n;
  6600. normals[ i + 2 ] *= n;
  6601. }
  6602. },
  6603. toJSON: function () {
  6604. var data = {
  6605. metadata: {
  6606. version: 4.4,
  6607. type: 'BufferGeometry',
  6608. generator: 'BufferGeometry.toJSON'
  6609. }
  6610. };
  6611. // standard BufferGeometry serialization
  6612. data.uuid = this.uuid;
  6613. data.type = this.type;
  6614. if ( this.name !== '' ) data.name = this.name;
  6615. if ( this.parameters !== undefined ) {
  6616. var parameters = this.parameters;
  6617. for ( var key in parameters ) {
  6618. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6619. }
  6620. return data;
  6621. }
  6622. data.data = { attributes: {} };
  6623. var index = this.index;
  6624. if ( index !== null ) {
  6625. var array = Array.prototype.slice.call( index.array );
  6626. data.data.index = {
  6627. type: index.array.constructor.name,
  6628. array: array
  6629. };
  6630. }
  6631. var attributes = this.attributes;
  6632. for ( var key in attributes ) {
  6633. var attribute = attributes[ key ];
  6634. var array = Array.prototype.slice.call( attribute.array );
  6635. data.data.attributes[ key ] = {
  6636. itemSize: attribute.itemSize,
  6637. type: attribute.array.constructor.name,
  6638. array: array
  6639. };
  6640. }
  6641. var groups = this.groups;
  6642. if ( groups.length > 0 ) {
  6643. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6644. }
  6645. var boundingSphere = this.boundingSphere;
  6646. if ( boundingSphere !== null ) {
  6647. data.data.boundingSphere = {
  6648. center: boundingSphere.center.toArray(),
  6649. radius: boundingSphere.radius
  6650. };
  6651. }
  6652. return data;
  6653. },
  6654. clone: function () {
  6655. return new this.constructor().copy( this );
  6656. },
  6657. copy: function ( source ) {
  6658. var index = source.index;
  6659. if ( index !== null ) {
  6660. this.setIndex( index.clone() );
  6661. }
  6662. var attributes = source.attributes;
  6663. for ( var name in attributes ) {
  6664. var attribute = attributes[ name ];
  6665. this.addAttribute( name, attribute.clone() );
  6666. }
  6667. var groups = source.groups;
  6668. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6669. var group = groups[ i ];
  6670. this.addGroup( group.start, group.count );
  6671. }
  6672. return this;
  6673. },
  6674. dispose: function () {
  6675. this.dispatchEvent( { type: 'dispose' } );
  6676. }
  6677. };
  6678. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6679. THREE.BufferGeometry.MaxIndex = 65535;
  6680. // File:src/core/InstancedBufferGeometry.js
  6681. /**
  6682. * @author benaadams / https://twitter.com/ben_a_adams
  6683. */
  6684. THREE.InstancedBufferGeometry = function () {
  6685. THREE.BufferGeometry.call( this );
  6686. this.type = 'InstancedBufferGeometry';
  6687. this.maxInstancedCount = undefined;
  6688. };
  6689. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6690. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6691. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  6692. this.groups.push( {
  6693. start: start,
  6694. count: count,
  6695. instances: instances
  6696. } );
  6697. };
  6698. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  6699. var index = source.index;
  6700. if ( index !== null ) {
  6701. this.setIndex( index.clone() );
  6702. }
  6703. var attributes = source.attributes;
  6704. for ( var name in attributes ) {
  6705. var attribute = attributes[ name ];
  6706. this.addAttribute( name, attribute.clone() );
  6707. }
  6708. var groups = source.groups;
  6709. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6710. var group = groups[ i ];
  6711. this.addGroup( group.start, group.count, group.instances );
  6712. }
  6713. return this;
  6714. };
  6715. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6716. // File:src/animation/AnimationAction.js
  6717. /**
  6718. *
  6719. * A clip that has been explicitly scheduled.
  6720. *
  6721. * @author Ben Houston / http://clara.io/
  6722. * @author David Sarno / http://lighthaus.us/
  6723. */
  6724. THREE.AnimationAction = function ( clip, startTime, timeScale, weight, loop ) {
  6725. if ( clip === undefined ) throw new Error( 'clip is null' );
  6726. this.clip = clip;
  6727. this.localRoot = null;
  6728. this.startTime = startTime || 0;
  6729. this.timeScale = timeScale || 1;
  6730. this.weight = weight || 1;
  6731. this.loop = loop || THREE.LoopRepeat;
  6732. this.loopCount = 0;
  6733. this.enabled = true; // allow for easy disabling of the action.
  6734. this.actionTime = - this.startTime;
  6735. this.clipTime = 0;
  6736. this.propertyBindings = [];
  6737. };
  6738. /*
  6739. THREE.LoopOnce = 2200;
  6740. THREE.LoopRepeat = 2201;
  6741. THREE.LoopPingPing = 2202;
  6742. */
  6743. THREE.AnimationAction.prototype = {
  6744. constructor: THREE.AnimationAction,
  6745. setLocalRoot: function( localRoot ) {
  6746. this.localRoot = localRoot;
  6747. return this;
  6748. },
  6749. updateTime: function( clipDeltaTime ) {
  6750. var previousClipTime = this.clipTime;
  6751. var previousLoopCount = this.loopCount;
  6752. var previousActionTime = this.actionTime;
  6753. var duration = this.clip.duration;
  6754. this.actionTime = this.actionTime + clipDeltaTime;
  6755. if ( this.loop === THREE.LoopOnce ) {
  6756. this.loopCount = 0;
  6757. this.clipTime = Math.min( Math.max( this.actionTime, 0 ), duration );
  6758. // if time is changed since last time, see if we have hit a start/end limit
  6759. if ( this.clipTime !== previousClipTime ) {
  6760. if ( this.clipTime === duration ) {
  6761. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: 1 } );
  6762. } else if ( this.clipTime === 0 ) {
  6763. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: -1 } );
  6764. }
  6765. }
  6766. return this.clipTime;
  6767. }
  6768. this.loopCount = Math.floor( this.actionTime / duration );
  6769. var newClipTime = this.actionTime - this.loopCount * duration;
  6770. newClipTime = newClipTime % duration;
  6771. // if we are ping pong looping, ensure that we go backwards when appropriate
  6772. if ( this.loop == THREE.LoopPingPong ) {
  6773. if ( Math.abs( this.loopCount % 2 ) === 1 ) {
  6774. newClipTime = duration - newClipTime;
  6775. }
  6776. }
  6777. this.clipTime = newClipTime;
  6778. if ( this.loopCount !== previousLoopCount ) {
  6779. this.mixer.dispatchEvent( { type: 'loop', action: this, loopDelta: ( this.loopCount - this.loopCount ) } );
  6780. }
  6781. return this.clipTime;
  6782. },
  6783. syncWith: function( action ) {
  6784. this.actionTime = action.actionTime;
  6785. this.timeScale = action.timeScale;
  6786. return this;
  6787. },
  6788. warpToDuration: function( duration ) {
  6789. this.timeScale = this.clip.duration / duration;
  6790. return this;
  6791. },
  6792. init: function( time ) {
  6793. this.clipTime = time - this.startTime;
  6794. return this;
  6795. },
  6796. update: function( clipDeltaTime ) {
  6797. this.updateTime( clipDeltaTime );
  6798. var clipResults = this.clip.getAt( this.clipTime );
  6799. return clipResults;
  6800. },
  6801. getTimeScaleAt: function( time ) {
  6802. if ( this.timeScale.getAt ) {
  6803. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6804. return this.timeScale.getAt( time );
  6805. }
  6806. return this.timeScale;
  6807. },
  6808. getWeightAt: function( time ) {
  6809. if ( this.weight.getAt ) {
  6810. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6811. return this.weight.getAt( time );
  6812. }
  6813. return this.weight;
  6814. }
  6815. };
  6816. // File:src/animation/AnimationClip.js
  6817. /**
  6818. *
  6819. * Reusable set of Tracks that represent an animation.
  6820. *
  6821. * @author Ben Houston / http://clara.io/
  6822. * @author David Sarno / http://lighthaus.us/
  6823. */
  6824. THREE.AnimationClip = function ( name, duration, tracks ) {
  6825. this.name = name;
  6826. this.tracks = tracks;
  6827. this.duration = ( duration !== undefined ) ? duration : -1;
  6828. // this means it should figure out its duration by scanning the tracks
  6829. if ( this.duration < 0 ) {
  6830. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6831. var track = this.tracks[i];
  6832. this.duration = Math.max( track.keys[ track.keys.length - 1 ].time );
  6833. }
  6834. }
  6835. // maybe only do these on demand, as doing them here could potentially slow down loading
  6836. // but leaving these here during development as this ensures a lot of testing of these functions
  6837. this.trim();
  6838. this.optimize();
  6839. this.results = [];
  6840. };
  6841. THREE.AnimationClip.prototype = {
  6842. constructor: THREE.AnimationClip,
  6843. getAt: function( clipTime ) {
  6844. clipTime = Math.max( 0, Math.min( clipTime, this.duration ) );
  6845. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6846. var track = this.tracks[ i ];
  6847. this.results[ i ] = track.getAt( clipTime );
  6848. }
  6849. return this.results;
  6850. },
  6851. trim: function() {
  6852. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6853. this.tracks[ i ].trim( 0, this.duration );
  6854. }
  6855. return this;
  6856. },
  6857. optimize: function() {
  6858. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6859. this.tracks[ i ].optimize();
  6860. }
  6861. return this;
  6862. }
  6863. };
  6864. THREE.AnimationClip.CreateFromMorphTargetSequence = function( name, morphTargetSequence, fps ) {
  6865. var numMorphTargets = morphTargetSequence.length;
  6866. var tracks = [];
  6867. for ( var i = 0; i < numMorphTargets; i ++ ) {
  6868. var keys = [];
  6869. keys.push( { time: ( i + numMorphTargets - 1 ) % numMorphTargets, value: 0 } );
  6870. keys.push( { time: i, value: 1 } );
  6871. keys.push( { time: ( i + 1 ) % numMorphTargets, value: 0 } );
  6872. keys.sort( THREE.KeyframeTrack.keyComparer );
  6873. // if there is a key at the first frame, duplicate it as the last frame as well for perfect loop.
  6874. if ( keys[0].time === 0 ) {
  6875. keys.push( {
  6876. time: numMorphTargets,
  6877. value: keys[0].value
  6878. });
  6879. }
  6880. tracks.push( new THREE.NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetSequence[i].name + ']', keys ).scale( 1.0 / fps ) );
  6881. }
  6882. return new THREE.AnimationClip( name, -1, tracks );
  6883. };
  6884. THREE.AnimationClip.findByName = function( clipArray, name ) {
  6885. for ( var i = 0; i < clipArray.length; i ++ ) {
  6886. if ( clipArray[i].name === name ) {
  6887. return clipArray[i];
  6888. }
  6889. }
  6890. return null;
  6891. };
  6892. THREE.AnimationClip.CreateClipsFromMorphTargetSequences = function( morphTargets, fps ) {
  6893. var animationToMorphTargets = {};
  6894. // tested with https://regex101.com/ on trick sequences such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  6895. var pattern = /^([\w-]*?)([\d]+)$/;
  6896. // sort morph target names into animation groups based patterns like Walk_001, Walk_002, Run_001, Run_002
  6897. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  6898. var morphTarget = morphTargets[ i ];
  6899. var parts = morphTarget.name.match( pattern );
  6900. if ( parts && parts.length > 1 ) {
  6901. var name = parts[ 1 ];
  6902. var animationMorphTargets = animationToMorphTargets[ name ];
  6903. if ( ! animationMorphTargets ) {
  6904. animationToMorphTargets[ name ] = animationMorphTargets = [];
  6905. }
  6906. animationMorphTargets.push( morphTarget );
  6907. }
  6908. }
  6909. var clips = [];
  6910. for ( var name in animationToMorphTargets ) {
  6911. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  6912. }
  6913. return clips;
  6914. };
  6915. // parse the standard JSON format for clips
  6916. THREE.AnimationClip.parse = function( json ) {
  6917. var tracks = [];
  6918. for ( var i = 0; i < json.tracks.length; i ++ ) {
  6919. tracks.push( THREE.KeyframeTrack.parse( json.tracks[i] ).scale( 1.0 / json.fps ) );
  6920. }
  6921. return new THREE.AnimationClip( json.name, json.duration, tracks );
  6922. };
  6923. // parse the animation.hierarchy format
  6924. THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
  6925. if ( ! animation ) {
  6926. console.error( " no animation in JSONLoader data" );
  6927. return null;
  6928. }
  6929. var convertTrack = function( trackName, animationKeys, propertyName, trackType, animationKeyToValueFunc ) {
  6930. var keys = [];
  6931. for ( var k = 0; k < animationKeys.length; k ++ ) {
  6932. var animationKey = animationKeys[k];
  6933. if ( animationKey[propertyName] !== undefined ) {
  6934. keys.push( { time: animationKey.time, value: animationKeyToValueFunc( animationKey ) } );
  6935. }
  6936. }
  6937. // only return track if there are actually keys.
  6938. if ( keys.length > 0 ) {
  6939. return new trackType( trackName, keys );
  6940. }
  6941. return null;
  6942. };
  6943. var tracks = [];
  6944. var clipName = animation.name || 'default';
  6945. var duration = animation.length || -1; // automatic length determination in AnimationClip.
  6946. var fps = animation.fps || 30;
  6947. var hierarchyTracks = animation.hierarchy || [];
  6948. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  6949. var animationKeys = hierarchyTracks[ h ].keys;
  6950. // skip empty tracks
  6951. if ( ! animationKeys || animationKeys.length == 0 ) {
  6952. continue;
  6953. }
  6954. // process morph targets in a way exactly compatible with AnimationHandler.init( animation )
  6955. if ( animationKeys[0].morphTargets ) {
  6956. // figure out all morph targets used in this track
  6957. var morphTargetNames = {};
  6958. for ( var k = 0; k < animationKeys.length; k ++ ) {
  6959. if ( animationKeys[k].morphTargets ) {
  6960. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  6961. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  6962. }
  6963. }
  6964. }
  6965. // create a track for each morph target with all zero morphTargetInfluences except for the keys in which the morphTarget is named.
  6966. for ( var morphTargetName in morphTargetNames ) {
  6967. var keys = [];
  6968. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  6969. var animationKey = animationKeys[k];
  6970. keys.push( {
  6971. time: animationKey.time,
  6972. value: (( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  6973. });
  6974. }
  6975. tracks.push( new THREE.NumberKeyframeTrack( nodeName + '.morphTargetInfluence[' + morphTargetName + ']', keys ) );
  6976. }
  6977. duration = morphTargetNames.length * ( fps || 1.0 );
  6978. } else {
  6979. var boneName = nodeName + '.bones[' + bones[ h ].name + ']';
  6980. // track contains positions...
  6981. var positionTrack = convertTrack( boneName + '.position', animationKeys, 'pos', THREE.VectorKeyframeTrack, function( animationKey ) {
  6982. return new THREE.Vector3().fromArray( animationKey.pos )
  6983. } );
  6984. if ( positionTrack ) tracks.push( positionTrack );
  6985. // track contains quaternions...
  6986. var quaternionTrack = convertTrack( boneName + '.quaternion', animationKeys, 'rot', THREE.QuaternionKeyframeTrack, function( animationKey ) {
  6987. if ( animationKey.rot.slerp ) {
  6988. return animationKey.rot.clone();
  6989. } else {
  6990. return new THREE.Quaternion().fromArray( animationKey.rot );
  6991. }
  6992. } );
  6993. if ( quaternionTrack ) tracks.push( quaternionTrack );
  6994. // track contains quaternions...
  6995. var scaleTrack = convertTrack( boneName + '.scale', animationKeys, 'scl', THREE.VectorKeyframeTrack, function( animationKey ) {
  6996. return new THREE.Vector3().fromArray( animationKey.scl )
  6997. } );
  6998. if ( scaleTrack ) tracks.push( scaleTrack );
  6999. }
  7000. }
  7001. if ( tracks.length === 0 ) {
  7002. return null;
  7003. }
  7004. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7005. return clip;
  7006. };
  7007. // File:src/animation/AnimationMixer.js
  7008. /**
  7009. *
  7010. * Mixes together the AnimationClips scheduled by AnimationActions and applies them to the root and subtree
  7011. *
  7012. *
  7013. * @author Ben Houston / http://clara.io/
  7014. * @author David Sarno / http://lighthaus.us/
  7015. */
  7016. THREE.AnimationMixer = function( root ) {
  7017. this.root = root;
  7018. this.time = 0;
  7019. this.timeScale = 1.0;
  7020. this.actions = [];
  7021. this.propertyBindingMap = {};
  7022. };
  7023. THREE.AnimationMixer.prototype = {
  7024. constructor: THREE.AnimationMixer,
  7025. addAction: function( action ) {
  7026. // TODO: check for duplicate action names? Or provide each action with a UUID?
  7027. this.actions.push( action );
  7028. action.init( this.time );
  7029. action.mixer = this;
  7030. var tracks = action.clip.tracks;
  7031. var root = action.localRoot || this.root;
  7032. for ( var i = 0; i < tracks.length; i ++ ) {
  7033. var track = tracks[ i ];
  7034. var propertyBindingKey = root.uuid + '-' + track.name;
  7035. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7036. if ( propertyBinding === undefined ) {
  7037. propertyBinding = new THREE.PropertyBinding( root, track.name );
  7038. this.propertyBindingMap[ propertyBindingKey ] = propertyBinding;
  7039. }
  7040. // push in the same order as the tracks.
  7041. action.propertyBindings.push( propertyBinding );
  7042. // track usages of shared property bindings, because if we leave too many around, the mixer can get slow
  7043. propertyBinding.referenceCount += 1;
  7044. }
  7045. },
  7046. removeAllActions: function() {
  7047. for ( var i = 0; i < this.actions.length; i ++ ) {
  7048. this.actions[i].mixer = null;
  7049. }
  7050. // unbind all property bindings
  7051. for ( var properyBindingKey in this.propertyBindingMap ) {
  7052. this.propertyBindingMap[ properyBindingKey ].unbind();
  7053. }
  7054. this.actions = [];
  7055. this.propertyBindingMap = {};
  7056. return this;
  7057. },
  7058. removeAction: function( action ) {
  7059. var index = this.actions.indexOf( action );
  7060. if ( index !== - 1 ) {
  7061. this.actions.splice( index, 1 );
  7062. action.mixer = null;
  7063. }
  7064. // remove unused property bindings because if we leave them around the mixer can get slow
  7065. var root = action.localRoot || this.root;
  7066. var tracks = action.clip.tracks;
  7067. for ( var i = 0; i < tracks.length; i ++ ) {
  7068. var track = tracks[ i ];
  7069. var propertyBindingKey = root.uuid + '-' + track.name;
  7070. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7071. propertyBinding.referenceCount -= 1;
  7072. if ( propertyBinding.referenceCount <= 0 ) {
  7073. propertyBinding.unbind();
  7074. delete this.propertyBindingMap[ propertyBindingKey ];
  7075. }
  7076. }
  7077. return this;
  7078. },
  7079. // can be optimized if needed
  7080. findActionByName: function( name ) {
  7081. for ( var i = 0; i < this.actions.length; i ++ ) {
  7082. if ( this.actions[i].name === name ) return this.actions[i];
  7083. }
  7084. return null;
  7085. },
  7086. play: function( action, optionalFadeInDuration ) {
  7087. action.startTime = this.time;
  7088. this.addAction( action );
  7089. return this;
  7090. },
  7091. fadeOut: function( action, duration ) {
  7092. var keys = [];
  7093. keys.push( { time: this.time, value: 1 } );
  7094. keys.push( { time: this.time + duration, value: 0 } );
  7095. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7096. return this;
  7097. },
  7098. fadeIn: function( action, duration ) {
  7099. var keys = [];
  7100. keys.push( { time: this.time, value: 0 } );
  7101. keys.push( { time: this.time + duration, value: 1 } );
  7102. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7103. return this;
  7104. },
  7105. warp: function( action, startTimeScale, endTimeScale, duration ) {
  7106. var keys = [];
  7107. keys.push( { time: this.time, value: startTimeScale } );
  7108. keys.push( { time: this.time + duration, value: endTimeScale } );
  7109. action.timeScale = new THREE.NumberKeyframeTrack( "timeScale", keys );
  7110. return this;
  7111. },
  7112. crossFade: function( fadeOutAction, fadeInAction, duration, warp ) {
  7113. this.fadeOut( fadeOutAction, duration );
  7114. this.fadeIn( fadeInAction, duration );
  7115. if ( warp ) {
  7116. var startEndRatio = fadeOutAction.clip.duration / fadeInAction.clip.duration;
  7117. var endStartRatio = 1.0 / startEndRatio;
  7118. this.warp( fadeOutAction, 1.0, startEndRatio, duration );
  7119. this.warp( fadeInAction, endStartRatio, 1.0, duration );
  7120. }
  7121. return this;
  7122. },
  7123. update: function( deltaTime ) {
  7124. var mixerDeltaTime = deltaTime * this.timeScale;
  7125. this.time += mixerDeltaTime;
  7126. for ( var i = 0; i < this.actions.length; i ++ ) {
  7127. var action = this.actions[i];
  7128. var weight = action.getWeightAt( this.time );
  7129. var actionTimeScale = action.getTimeScaleAt( this.time );
  7130. var actionDeltaTime = mixerDeltaTime * actionTimeScale;
  7131. var actionResults = action.update( actionDeltaTime );
  7132. if ( action.weight <= 0 || ! action.enabled ) continue;
  7133. for ( var j = 0; j < actionResults.length; j ++ ) {
  7134. var name = action.clip.tracks[j].name;
  7135. action.propertyBindings[ j ].accumulate( actionResults[j], weight );
  7136. }
  7137. }
  7138. // apply to nodes
  7139. for ( var propertyBindingKey in this.propertyBindingMap ) {
  7140. this.propertyBindingMap[ propertyBindingKey ].apply();
  7141. }
  7142. return this;
  7143. }
  7144. };
  7145. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7146. // File:src/animation/AnimationUtils.js
  7147. /**
  7148. * @author Ben Houston / http://clara.io/
  7149. * @author David Sarno / http://lighthaus.us/
  7150. */
  7151. THREE.AnimationUtils = {
  7152. getEqualsFunc: function( exemplarValue ) {
  7153. if ( exemplarValue.equals ) {
  7154. return function equals_object( a, b ) {
  7155. return a.equals( b );
  7156. }
  7157. }
  7158. return function equals_primitive( a, b ) {
  7159. return ( a === b );
  7160. };
  7161. },
  7162. clone: function( exemplarValue ) {
  7163. var typeName = typeof exemplarValue;
  7164. if ( typeName === "object" ) {
  7165. if ( exemplarValue.clone ) {
  7166. return exemplarValue.clone();
  7167. }
  7168. console.error( "can not figure out how to copy exemplarValue", exemplarValue );
  7169. }
  7170. return exemplarValue;
  7171. },
  7172. lerp: function( a, b, alpha, interTrack ) {
  7173. var lerpFunc = THREE.AnimationUtils.getLerpFunc( a, interTrack );
  7174. return lerpFunc( a, b, alpha );
  7175. },
  7176. lerp_object: function( a, b, alpha ) {
  7177. return a.lerp( b, alpha );
  7178. },
  7179. slerp_object: function( a, b, alpha ) {
  7180. return a.slerp( b, alpha );
  7181. },
  7182. lerp_number: function( a, b, alpha ) {
  7183. return a * ( 1 - alpha ) + b * alpha;
  7184. },
  7185. lerp_boolean: function( a, b, alpha ) {
  7186. return ( alpha < 0.5 ) ? a : b;
  7187. },
  7188. lerp_boolean_immediate: function( a, b, alpha ) {
  7189. return a;
  7190. },
  7191. lerp_string: function( a, b, alpha ) {
  7192. return ( alpha < 0.5 ) ? a : b;
  7193. },
  7194. lerp_string_immediate: function( a, b, alpha ) {
  7195. return a;
  7196. },
  7197. // NOTE: this is an accumulator function that modifies the first argument (e.g. a). This is to minimize memory alocations.
  7198. getLerpFunc: function( exemplarValue, interTrack ) {
  7199. if ( exemplarValue === undefined || exemplarValue === null ) throw new Error( "examplarValue is null" );
  7200. var typeName = typeof exemplarValue;
  7201. switch( typeName ) {
  7202. case "object":
  7203. if ( exemplarValue.lerp ) {
  7204. return THREE.AnimationUtils.lerp_object;
  7205. }
  7206. if ( exemplarValue.slerp ) {
  7207. return THREE.AnimationUtils.slerp_object;
  7208. }
  7209. break;
  7210. case "number":
  7211. return THREE.AnimationUtils.lerp_number;
  7212. case "boolean":
  7213. if ( interTrack ) {
  7214. return THREE.AnimationUtils.lerp_boolean;
  7215. } else {
  7216. return THREE.AnimationUtils.lerp_boolean_immediate;
  7217. }
  7218. case "string":
  7219. if ( interTrack ) {
  7220. return THREE.AnimationUtils.lerp_string;
  7221. } else {
  7222. return THREE.AnimationUtils.lerp_string_immediate;
  7223. }
  7224. }
  7225. }
  7226. };
  7227. // File:src/animation/KeyframeTrack.js
  7228. /**
  7229. *
  7230. * A Track that returns a keyframe interpolated value, currently linearly interpolated
  7231. *
  7232. * @author Ben Houston / http://clara.io/
  7233. * @author David Sarno / http://lighthaus.us/
  7234. */
  7235. THREE.KeyframeTrack = function ( name, keys ) {
  7236. if ( name === undefined ) throw new Error( "track name is undefined" );
  7237. if ( keys === undefined || keys.length === 0 ) throw new Error( "no keys in track named " + name );
  7238. this.name = name;
  7239. this.keys = keys; // time in seconds, value as value
  7240. // the index of the last result, used as a starting point for local search.
  7241. this.lastIndex = 0;
  7242. this.validate();
  7243. this.optimize();
  7244. };
  7245. THREE.KeyframeTrack.prototype = {
  7246. constructor: THREE.KeyframeTrack,
  7247. getAt: function( time ) {
  7248. // this can not go higher than this.keys.length.
  7249. while( ( this.lastIndex < this.keys.length ) && ( time >= this.keys[this.lastIndex].time ) ) {
  7250. this.lastIndex ++;
  7251. };
  7252. // this can not go lower than 0.
  7253. while( ( this.lastIndex > 0 ) && ( time < this.keys[this.lastIndex - 1].time ) ) {
  7254. this.lastIndex --;
  7255. }
  7256. if ( this.lastIndex >= this.keys.length ) {
  7257. this.setResult( this.keys[ this.keys.length - 1 ].value );
  7258. return this.result;
  7259. }
  7260. if ( this.lastIndex === 0 ) {
  7261. this.setResult( this.keys[ 0 ].value );
  7262. return this.result;
  7263. }
  7264. var prevKey = this.keys[ this.lastIndex - 1 ];
  7265. this.setResult( prevKey.value );
  7266. // if true, means that prev/current keys are identical, thus no interpolation required.
  7267. if ( prevKey.constantToNext ) {
  7268. return this.result;
  7269. }
  7270. // linear interpolation to start with
  7271. var currentKey = this.keys[ this.lastIndex ];
  7272. var alpha = ( time - prevKey.time ) / ( currentKey.time - prevKey.time );
  7273. this.result = this.lerpValues( this.result, currentKey.value, alpha );
  7274. return this.result;
  7275. },
  7276. // move all keyframes either forwards or backwards in time
  7277. shift: function( timeOffset ) {
  7278. if ( timeOffset !== 0.0 ) {
  7279. for ( var i = 0; i < this.keys.length; i ++ ) {
  7280. this.keys[i].time += timeOffset;
  7281. }
  7282. }
  7283. return this;
  7284. },
  7285. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  7286. scale: function( timeScale ) {
  7287. if ( timeScale !== 1.0 ) {
  7288. for ( var i = 0; i < this.keys.length; i ++ ) {
  7289. this.keys[i].time *= timeScale;
  7290. }
  7291. }
  7292. return this;
  7293. },
  7294. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  7295. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  7296. trim: function( startTime, endTime ) {
  7297. var firstKeysToRemove = 0;
  7298. for ( var i = 1; i < this.keys.length; i ++ ) {
  7299. if ( this.keys[i] <= startTime ) {
  7300. firstKeysToRemove ++;
  7301. }
  7302. }
  7303. var lastKeysToRemove = 0;
  7304. for ( var i = this.keys.length - 2; i > 0; i ++ ) {
  7305. if ( this.keys[i] >= endTime ) {
  7306. lastKeysToRemove ++;
  7307. } else {
  7308. break;
  7309. }
  7310. }
  7311. // remove last keys first because it doesn't affect the position of the first keys (the otherway around doesn't work as easily)
  7312. if ( ( firstKeysToRemove + lastKeysToRemove ) > 0 ) {
  7313. this.keys = this.keys.splice( firstKeysToRemove, this.keys.length - lastKeysToRemove - firstKeysToRemove );;
  7314. }
  7315. return this;
  7316. },
  7317. /* NOTE: This is commented out because we really shouldn't have to handle unsorted key lists
  7318. Tracks with out of order keys should be considered to be invalid. - bhouston
  7319. sort: function() {
  7320. this.keys.sort( THREE.KeyframeTrack.keyComparer );
  7321. return this;
  7322. },*/
  7323. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  7324. // One could eventually ensure that all key.values in a track are all of the same type (otherwise interpolation makes no sense.)
  7325. validate: function() {
  7326. var prevKey = null;
  7327. if ( this.keys.length === 0 ) {
  7328. console.error( " track is empty, no keys", this );
  7329. return;
  7330. }
  7331. for ( var i = 0; i < this.keys.length; i ++ ) {
  7332. var currKey = this.keys[i];
  7333. if ( ! currKey ) {
  7334. console.error( " key is null in track", this, i );
  7335. return;
  7336. }
  7337. if ( ( typeof currKey.time ) !== 'number' || Number.isNaN( currKey.time ) ) {
  7338. console.error( " key.time is not a valid number", this, i, currKey );
  7339. return;
  7340. }
  7341. if ( currKey.value === undefined || currKey.value === null) {
  7342. console.error( " key.value is null in track", this, i, currKey );
  7343. return;
  7344. }
  7345. if ( prevKey && prevKey.time > currKey.time ) {
  7346. console.error( " key.time is less than previous key time, out of order keys", this, i, currKey, prevKey );
  7347. return;
  7348. }
  7349. prevKey = currKey;
  7350. }
  7351. return this;
  7352. },
  7353. // 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
  7354. optimize: function() {
  7355. var newKeys = [];
  7356. var prevKey = this.keys[0];
  7357. newKeys.push( prevKey );
  7358. var equalsFunc = THREE.AnimationUtils.getEqualsFunc( prevKey.value );
  7359. for ( var i = 1; i < this.keys.length - 1; i ++ ) {
  7360. var currKey = this.keys[i];
  7361. var nextKey = this.keys[i+1];
  7362. // if prevKey & currKey are the same time, remove currKey. If you want immediate adjacent keys, use an epsilon offset
  7363. // 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.
  7364. if ( ( prevKey.time === currKey.time ) ) {
  7365. continue;
  7366. }
  7367. // remove completely unnecessary keyframes that are the same as their prev and next keys
  7368. if ( this.compareValues( prevKey.value, currKey.value ) && this.compareValues( currKey.value, nextKey.value ) ) {
  7369. continue;
  7370. }
  7371. // determine if interpolation is required
  7372. prevKey.constantToNext = this.compareValues( prevKey.value, currKey.value );
  7373. newKeys.push( currKey );
  7374. prevKey = currKey;
  7375. }
  7376. newKeys.push( this.keys[ this.keys.length - 1 ] );
  7377. this.keys = newKeys;
  7378. return this;
  7379. }
  7380. };
  7381. THREE.KeyframeTrack.keyComparer = function keyComparator(key0, key1) {
  7382. return key0.time - key1.time;
  7383. };
  7384. THREE.KeyframeTrack.parse = function( json ) {
  7385. if ( json.type === undefined ) throw new Error( "track type undefined, can not parse" );
  7386. var trackType = THREE.KeyframeTrack.GetTrackTypeForTypeName( json.type );
  7387. return trackType.parse( json );
  7388. };
  7389. THREE.KeyframeTrack.GetTrackTypeForTypeName = function( typeName ) {
  7390. switch( typeName.toLowerCase() ) {
  7391. case "vector":
  7392. case "vector2":
  7393. case "vector3":
  7394. case "vector4":
  7395. return THREE.VectorKeyframeTrack;
  7396. case "quaternion":
  7397. return THREE.QuaternionKeyframeTrack;
  7398. case "integer":
  7399. case "scalar":
  7400. case "double":
  7401. case "float":
  7402. case "number":
  7403. return THREE.NumberKeyframeTrack;
  7404. case "bool":
  7405. case "boolean":
  7406. return THREE.BooleanKeyframeTrack;
  7407. case "string":
  7408. return THREE.StringKeyframeTrack;
  7409. };
  7410. throw new Error( "Unsupported typeName: " + typeName );
  7411. };
  7412. // File:src/animation/PropertyBinding.js
  7413. /**
  7414. *
  7415. * A track bound to a real value in the scene graph.
  7416. *
  7417. * @author Ben Houston / http://clara.io/
  7418. * @author David Sarno / http://lighthaus.us/
  7419. */
  7420. THREE.PropertyBinding = function ( rootNode, trackName ) {
  7421. this.rootNode = rootNode;
  7422. this.trackName = trackName;
  7423. this.referenceCount = 0;
  7424. this.originalValue = null; // the value of the property before it was controlled by this binding
  7425. var parseResults = THREE.PropertyBinding.parseTrackName( trackName );
  7426. this.directoryName = parseResults.directoryName;
  7427. this.nodeName = parseResults.nodeName;
  7428. this.objectName = parseResults.objectName;
  7429. this.objectIndex = parseResults.objectIndex;
  7430. this.propertyName = parseResults.propertyName;
  7431. this.propertyIndex = parseResults.propertyIndex;
  7432. this.node = THREE.PropertyBinding.findNode( rootNode, this.nodeName ) || rootNode;
  7433. this.cumulativeValue = null;
  7434. this.cumulativeWeight = 0;
  7435. };
  7436. THREE.PropertyBinding.prototype = {
  7437. constructor: THREE.PropertyBinding,
  7438. reset: function() {
  7439. this.cumulativeValue = null;
  7440. this.cumulativeWeight = 0;
  7441. },
  7442. accumulate: function( value, weight ) {
  7443. if ( ! this.isBound ) this.bind();
  7444. if ( this.cumulativeWeight === 0 ) {
  7445. if ( weight > 0 ) {
  7446. if ( this.cumulativeValue === null ) {
  7447. this.cumulativeValue = THREE.AnimationUtils.clone( value );
  7448. }
  7449. this.cumulativeWeight = weight;
  7450. }
  7451. } else {
  7452. var lerpAlpha = weight / ( this.cumulativeWeight + weight );
  7453. this.cumulativeValue = this.lerpValue( this.cumulativeValue, value, lerpAlpha );
  7454. this.cumulativeWeight += weight;
  7455. }
  7456. },
  7457. unbind: function() {
  7458. if ( ! this.isBound ) return;
  7459. this.setValue( this.originalValue );
  7460. this.setValue = null;
  7461. this.getValue = null;
  7462. this.lerpValue = null;
  7463. this.equalsValue = null;
  7464. this.triggerDirty = null;
  7465. this.isBound = false;
  7466. },
  7467. // bind to the real property in the scene graph, remember original value, memorize various accessors for speed/inefficiency
  7468. bind: function() {
  7469. if ( this.isBound ) return;
  7470. var targetObject = this.node;
  7471. // ensure there is a value node
  7472. if ( ! targetObject ) {
  7473. console.error( " trying to update node for track: " + this.trackName + " but it wasn't found." );
  7474. return;
  7475. }
  7476. if ( this.objectName ) {
  7477. // special case were we need to reach deeper into the hierarchy to get the face materials....
  7478. if ( this.objectName === "materials" ) {
  7479. if ( ! targetObject.material ) {
  7480. console.error( ' can not bind to material as node does not have a material', this );
  7481. return;
  7482. }
  7483. if ( ! targetObject.material.materials ) {
  7484. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  7485. return;
  7486. }
  7487. targetObject = targetObject.material.materials;
  7488. } else if ( this.objectName === "bones" ) {
  7489. if ( ! targetObject.skeleton ) {
  7490. console.error( ' can not bind to bones as node does not have a skeleton', this );
  7491. return;
  7492. }
  7493. // potential future optimization: skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7494. targetObject = targetObject.skeleton.bones;
  7495. // support resolving morphTarget names into indices.
  7496. for ( var i = 0; i < targetObject.length; i ++ ) {
  7497. if ( targetObject[i].name === this.objectIndex ) {
  7498. this.objectIndex = i;
  7499. break;
  7500. }
  7501. }
  7502. } else {
  7503. if ( targetObject[ this.objectName ] === undefined ) {
  7504. console.error( ' can not bind to objectName of node, undefined', this );
  7505. return;
  7506. }
  7507. targetObject = targetObject[ this.objectName ];
  7508. }
  7509. if ( this.objectIndex !== undefined ) {
  7510. if ( targetObject[ this.objectIndex ] === undefined ) {
  7511. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  7512. return;
  7513. }
  7514. targetObject = targetObject[ this.objectIndex ];
  7515. }
  7516. }
  7517. // special case mappings
  7518. var nodeProperty = targetObject[ this.propertyName ];
  7519. if ( ! nodeProperty ) {
  7520. console.error( " trying to update property for track: " + this.nodeName + '.' + this.propertyName + " but it wasn't found.", targetObject );
  7521. return;
  7522. }
  7523. // access a sub element of the property array (only primitives are supported right now)
  7524. if ( this.propertyIndex !== undefined ) {
  7525. if ( this.propertyName === "morphTargetInfluences" ) {
  7526. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7527. // support resolving morphTarget names into indices.
  7528. if ( ! targetObject.geometry ) {
  7529. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  7530. }
  7531. if ( ! targetObject.geometry.morphTargets ) {
  7532. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  7533. }
  7534. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  7535. if ( targetObject.geometry.morphTargets[i].name === this.propertyIndex ) {
  7536. this.propertyIndex = i;
  7537. break;
  7538. }
  7539. }
  7540. }
  7541. this.setValue = function setValue_propertyIndexed( value ) {
  7542. if ( ! this.equalsValue( nodeProperty[ this.propertyIndex ], value ) ) {
  7543. nodeProperty[ this.propertyIndex ] = value;
  7544. return true;
  7545. }
  7546. return false;
  7547. };
  7548. this.getValue = function getValue_propertyIndexed() {
  7549. return nodeProperty[ this.propertyIndex ];
  7550. };
  7551. }
  7552. // must use copy for Object3D.Euler/Quaternion
  7553. else if ( nodeProperty.copy ) {
  7554. this.setValue = function setValue_propertyObject( value ) {
  7555. if ( ! this.equalsValue( nodeProperty, value ) ) {
  7556. nodeProperty.copy( value );
  7557. return true;
  7558. }
  7559. return false;
  7560. }
  7561. this.getValue = function getValue_propertyObject() {
  7562. return nodeProperty;
  7563. };
  7564. }
  7565. // otherwise just set the property directly on the node (do not use nodeProperty as it may not be a reference object)
  7566. else {
  7567. this.setValue = function setValue_property( value ) {
  7568. if ( ! this.equalsValue( targetObject[ this.propertyName ], value ) ) {
  7569. targetObject[ this.propertyName ] = value;
  7570. return true;
  7571. }
  7572. return false;
  7573. }
  7574. this.getValue = function getValue_property() {
  7575. return targetObject[ this.propertyName ];
  7576. };
  7577. }
  7578. // trigger node dirty
  7579. if ( targetObject.needsUpdate !== undefined ) { // material
  7580. this.triggerDirty = function triggerDirty_needsUpdate() {
  7581. this.node.needsUpdate = true;
  7582. }
  7583. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  7584. this.triggerDirty = function triggerDirty_matrixWorldNeedsUpdate() {
  7585. targetObject.matrixWorldNeedsUpdate = true;
  7586. }
  7587. }
  7588. this.originalValue = this.getValue();
  7589. this.equalsValue = THREE.AnimationUtils.getEqualsFunc( this.originalValue );
  7590. this.lerpValue = THREE.AnimationUtils.getLerpFunc( this.originalValue, true );
  7591. this.isBound = true;
  7592. },
  7593. apply: function() {
  7594. // for speed capture the setter pattern as a closure (sort of a memoization pattern: https://en.wikipedia.org/wiki/Memoization)
  7595. if ( ! this.isBound ) this.bind();
  7596. // early exit if there is nothing to apply.
  7597. if ( this.cumulativeWeight > 0 ) {
  7598. // blend with original value
  7599. if ( this.cumulativeWeight < 1 ) {
  7600. var remainingWeight = 1 - this.cumulativeWeight;
  7601. var lerpAlpha = remainingWeight / ( this.cumulativeWeight + remainingWeight );
  7602. this.cumulativeValue = this.lerpValue( this.cumulativeValue, this.originalValue, lerpAlpha );
  7603. }
  7604. var valueChanged = this.setValue( this.cumulativeValue );
  7605. if ( valueChanged && this.triggerDirty ) {
  7606. this.triggerDirty();
  7607. }
  7608. // reset accumulator
  7609. this.cumulativeValue = null;
  7610. this.cumulativeWeight = 0;
  7611. }
  7612. }
  7613. };
  7614. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  7615. // matches strings in the form of:
  7616. // nodeName.property
  7617. // nodeName.property[accessor]
  7618. // nodeName.material.property[accessor]
  7619. // uuid.property[accessor]
  7620. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  7621. // parentName/nodeName.property
  7622. // parentName/parentName/nodeName.property[index]
  7623. // .bone[Armature.DEF_cog].position
  7624. // created and tested via https://regex101.com/#javascript
  7625. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  7626. var matches = re.exec(trackName);
  7627. if ( ! matches ) {
  7628. throw new Error( "cannot parse trackName at all: " + trackName );
  7629. }
  7630. if (matches.index === re.lastIndex) {
  7631. re.lastIndex++;
  7632. }
  7633. var results = {
  7634. directoryName: matches[1],
  7635. nodeName: matches[3], // allowed to be null, specified root node.
  7636. objectName: matches[5],
  7637. objectIndex: matches[7],
  7638. propertyName: matches[9],
  7639. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  7640. };
  7641. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  7642. throw new Error( "can not parse propertyName from trackName: " + trackName );
  7643. }
  7644. return results;
  7645. };
  7646. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  7647. function searchSkeleton( skeleton ) {
  7648. for ( var i = 0; i < skeleton.bones.length; i ++ ) {
  7649. var bone = skeleton.bones[i];
  7650. if ( bone.name === nodeName ) {
  7651. return bone;
  7652. }
  7653. }
  7654. return null;
  7655. }
  7656. function searchNodeSubtree( children ) {
  7657. for ( var i = 0; i < children.length; i ++ ) {
  7658. var childNode = children[i];
  7659. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  7660. return childNode;
  7661. }
  7662. var result = searchNodeSubtree( childNode.children );
  7663. if ( result ) return result;
  7664. }
  7665. return null;
  7666. }
  7667. //
  7668. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  7669. return root;
  7670. }
  7671. // search into skeleton bones.
  7672. if ( root.skeleton ) {
  7673. var bone = searchSkeleton( root.skeleton );
  7674. if ( bone ) {
  7675. return bone;
  7676. }
  7677. }
  7678. // search into node subtree.
  7679. if ( root.children ) {
  7680. var subTreeNode = searchNodeSubtree( root.children );
  7681. if ( subTreeNode ) {
  7682. return subTreeNode;
  7683. }
  7684. }
  7685. return null;
  7686. }
  7687. // File:src/animation/tracks/VectorKeyframeTrack.js
  7688. /**
  7689. *
  7690. * A Track that interpolates Vectors
  7691. *
  7692. * @author Ben Houston / http://clara.io/
  7693. * @author David Sarno / http://lighthaus.us/
  7694. */
  7695. THREE.VectorKeyframeTrack = function ( name, keys ) {
  7696. THREE.KeyframeTrack.call( this, name, keys );
  7697. // local cache of value type to avoid allocations during runtime.
  7698. this.result = this.keys[0].value.clone();
  7699. };
  7700. THREE.VectorKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7701. THREE.VectorKeyframeTrack.prototype.constructor = THREE.VectorKeyframeTrack;
  7702. THREE.VectorKeyframeTrack.prototype.setResult = function( value ) {
  7703. this.result.copy( value );
  7704. };
  7705. // memoization of the lerp function for speed.
  7706. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7707. THREE.VectorKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7708. return value0.lerp( value1, alpha );
  7709. };
  7710. THREE.VectorKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7711. return value0.equals( value1 );
  7712. };
  7713. THREE.VectorKeyframeTrack.prototype.clone = function() {
  7714. var clonedKeys = [];
  7715. for ( var i = 0; i < this.keys.length; i ++ ) {
  7716. var key = this.keys[i];
  7717. clonedKeys.push( {
  7718. time: key.time,
  7719. value: key.value.clone()
  7720. } );
  7721. }
  7722. return new THREE.VectorKeyframeTrack( this.name, clonedKeys );
  7723. };
  7724. THREE.VectorKeyframeTrack.parse = function( json ) {
  7725. var elementCount = json.keys[0].value.length;
  7726. var valueType = THREE[ 'Vector' + elementCount ];
  7727. var keys = [];
  7728. for ( var i = 0; i < json.keys.length; i ++ ) {
  7729. var jsonKey = json.keys[i];
  7730. keys.push( {
  7731. value: new valueType().fromArray( jsonKey.value ),
  7732. time: jsonKey.time
  7733. } );
  7734. }
  7735. return new THREE.VectorKeyframeTrack( json.name, keys );
  7736. };
  7737. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  7738. /**
  7739. *
  7740. * A Track that interpolates Quaternion
  7741. *
  7742. * @author Ben Houston / http://clara.io/
  7743. * @author David Sarno / http://lighthaus.us/
  7744. */
  7745. THREE.QuaternionKeyframeTrack = function ( name, keys ) {
  7746. THREE.KeyframeTrack.call( this, name, keys );
  7747. // local cache of value type to avoid allocations during runtime.
  7748. this.result = this.keys[0].value.clone();
  7749. };
  7750. THREE.QuaternionKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7751. THREE.QuaternionKeyframeTrack.prototype.constructor = THREE.QuaternionKeyframeTrack;
  7752. THREE.QuaternionKeyframeTrack.prototype.setResult = function( value ) {
  7753. this.result.copy( value );
  7754. };
  7755. // memoization of the lerp function for speed.
  7756. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7757. THREE.QuaternionKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7758. return value0.slerp( value1, alpha );
  7759. };
  7760. THREE.QuaternionKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7761. return value0.equals( value1 );
  7762. };
  7763. THREE.QuaternionKeyframeTrack.prototype.multiply = function( quat ) {
  7764. for ( var i = 0; i < this.keys.length; i ++ ) {
  7765. this.keys[i].value.multiply( quat );
  7766. }
  7767. return this;
  7768. };
  7769. THREE.QuaternionKeyframeTrack.prototype.clone = function() {
  7770. var clonedKeys = [];
  7771. for ( var i = 0; i < this.keys.length; i ++ ) {
  7772. var key = this.keys[i];
  7773. clonedKeys.push( {
  7774. time: key.time,
  7775. value: key.value.clone()
  7776. } );
  7777. }
  7778. return new THREE.QuaternionKeyframeTrack( this.name, clonedKeys );
  7779. };
  7780. THREE.QuaternionKeyframeTrack.parse = function( json ) {
  7781. var keys = [];
  7782. for ( var i = 0; i < json.keys.length; i ++ ) {
  7783. var jsonKey = json.keys[i];
  7784. keys.push( {
  7785. value: new THREE.Quaternion().fromArray( jsonKey.value ),
  7786. time: jsonKey.time
  7787. } );
  7788. }
  7789. return new THREE.QuaternionKeyframeTrack( json.name, keys );
  7790. };
  7791. // File:src/animation/tracks/StringKeyframeTrack.js
  7792. /**
  7793. *
  7794. * A Track that interpolates Strings
  7795. *
  7796. * @author Ben Houston / http://clara.io/
  7797. * @author David Sarno / http://lighthaus.us/
  7798. */
  7799. THREE.StringKeyframeTrack = function ( name, keys ) {
  7800. THREE.KeyframeTrack.call( this, name, keys );
  7801. // local cache of value type to avoid allocations during runtime.
  7802. this.result = this.keys[0].value;
  7803. };
  7804. THREE.StringKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7805. THREE.StringKeyframeTrack.prototype.constructor = THREE.StringKeyframeTrack;
  7806. THREE.StringKeyframeTrack.prototype.setResult = function( value ) {
  7807. this.result = value;
  7808. };
  7809. // memoization of the lerp function for speed.
  7810. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7811. THREE.StringKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7812. return ( alpha < 1.0 ) ? value0 : value1;
  7813. };
  7814. THREE.StringKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7815. return ( value0 === value1 );
  7816. };
  7817. THREE.StringKeyframeTrack.prototype.clone = function() {
  7818. var clonedKeys = [];
  7819. for ( var i = 0; i < this.keys.length; i ++ ) {
  7820. var key = this.keys[i];
  7821. clonedKeys.push( {
  7822. time: key.time,
  7823. value: key.value
  7824. } );
  7825. }
  7826. return new THREE.StringKeyframeTrack( this.name, clonedKeys );
  7827. };
  7828. THREE.StringKeyframeTrack.parse = function( json ) {
  7829. return new THREE.StringKeyframeTrack( json.name, json.keys );
  7830. };
  7831. // File:src/animation/tracks/BooleanKeyframeTrack.js
  7832. /**
  7833. *
  7834. * A Track that interpolates Boolean
  7835. *
  7836. * @author Ben Houston / http://clara.io/
  7837. * @author David Sarno / http://lighthaus.us/
  7838. */
  7839. THREE.BooleanKeyframeTrack = function ( name, keys ) {
  7840. THREE.KeyframeTrack.call( this, name, keys );
  7841. // local cache of value type to avoid allocations during runtime.
  7842. this.result = this.keys[0].value;
  7843. };
  7844. THREE.BooleanKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7845. THREE.BooleanKeyframeTrack.prototype.constructor = THREE.BooleanKeyframeTrack;
  7846. THREE.BooleanKeyframeTrack.prototype.setResult = function( value ) {
  7847. this.result = value;
  7848. };
  7849. // memoization of the lerp function for speed.
  7850. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7851. THREE.BooleanKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7852. return ( alpha < 1.0 ) ? value0 : value1;
  7853. };
  7854. THREE.BooleanKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7855. return ( value0 === value1 );
  7856. };
  7857. THREE.BooleanKeyframeTrack.prototype.clone = function() {
  7858. var clonedKeys = [];
  7859. for ( var i = 0; i < this.keys.length; i ++ ) {
  7860. var key = this.keys[i];
  7861. clonedKeys.push( {
  7862. time: key.time,
  7863. value: key.value
  7864. } );
  7865. }
  7866. return new THREE.BooleanKeyframeTrack( this.name, clonedKeys );
  7867. };
  7868. THREE.BooleanKeyframeTrack.parse = function( json ) {
  7869. return new THREE.BooleanKeyframeTrack( json.name, json.keys );
  7870. };
  7871. // File:src/animation/tracks/NumberKeyframeTrack.js
  7872. /**
  7873. *
  7874. * A Track that interpolates Numbers
  7875. *
  7876. * @author Ben Houston / http://clara.io/
  7877. * @author David Sarno / http://lighthaus.us/
  7878. */
  7879. THREE.NumberKeyframeTrack = function ( name, keys ) {
  7880. THREE.KeyframeTrack.call( this, name, keys );
  7881. // local cache of value type to avoid allocations during runtime.
  7882. this.result = this.keys[0].value;
  7883. };
  7884. THREE.NumberKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7885. THREE.NumberKeyframeTrack.prototype.constructor = THREE.NumberKeyframeTrack;
  7886. THREE.NumberKeyframeTrack.prototype.setResult = function( value ) {
  7887. this.result = value;
  7888. };
  7889. // memoization of the lerp function for speed.
  7890. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7891. THREE.NumberKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7892. return value0 * ( 1 - alpha ) + value1 * alpha;
  7893. };
  7894. THREE.NumberKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7895. return ( value0 === value1 );
  7896. };
  7897. THREE.NumberKeyframeTrack.prototype.clone = function() {
  7898. var clonedKeys = [];
  7899. for ( var i = 0; i < this.keys.length; i ++ ) {
  7900. var key = this.keys[i];
  7901. clonedKeys.push( {
  7902. time: key.time,
  7903. value: key.value
  7904. } );
  7905. }
  7906. return new THREE.NumberKeyframeTrack( this.name, clonedKeys );
  7907. };
  7908. THREE.NumberKeyframeTrack.parse = function( json ) {
  7909. return new THREE.NumberKeyframeTrack( json.name, json.keys );
  7910. };
  7911. // File:src/cameras/Camera.js
  7912. /**
  7913. * @author mrdoob / http://mrdoob.com/
  7914. * @author mikael emtinger / http://gomo.se/
  7915. * @author WestLangley / http://github.com/WestLangley
  7916. */
  7917. THREE.Camera = function () {
  7918. THREE.Object3D.call( this );
  7919. this.type = 'Camera';
  7920. this.matrixWorldInverse = new THREE.Matrix4();
  7921. this.projectionMatrix = new THREE.Matrix4();
  7922. };
  7923. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  7924. THREE.Camera.prototype.constructor = THREE.Camera;
  7925. THREE.Camera.prototype.getWorldDirection = function () {
  7926. var quaternion = new THREE.Quaternion();
  7927. return function ( optionalTarget ) {
  7928. var result = optionalTarget || new THREE.Vector3();
  7929. this.getWorldQuaternion( quaternion );
  7930. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  7931. };
  7932. }();
  7933. THREE.Camera.prototype.lookAt = function () {
  7934. // This routine does not support cameras with rotated and/or translated parent(s)
  7935. var m1 = new THREE.Matrix4();
  7936. return function ( vector ) {
  7937. m1.lookAt( this.position, vector, this.up );
  7938. this.quaternion.setFromRotationMatrix( m1 );
  7939. };
  7940. }();
  7941. THREE.Camera.prototype.clone = function () {
  7942. return new this.constructor().copy( this );
  7943. };
  7944. THREE.Camera.prototype.copy = function ( source ) {
  7945. THREE.Object3D.prototype.copy.call( this, source );
  7946. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  7947. this.projectionMatrix.copy( source.projectionMatrix );
  7948. return this;
  7949. };
  7950. // File:src/cameras/CubeCamera.js
  7951. /**
  7952. * Camera for rendering cube maps
  7953. * - renders scene into axis-aligned cube
  7954. *
  7955. * @author alteredq / http://alteredqualia.com/
  7956. */
  7957. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  7958. THREE.Object3D.call( this );
  7959. this.type = 'CubeCamera';
  7960. var fov = 90, aspect = 1;
  7961. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7962. cameraPX.up.set( 0, - 1, 0 );
  7963. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  7964. this.add( cameraPX );
  7965. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7966. cameraNX.up.set( 0, - 1, 0 );
  7967. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  7968. this.add( cameraNX );
  7969. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7970. cameraPY.up.set( 0, 0, 1 );
  7971. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  7972. this.add( cameraPY );
  7973. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7974. cameraNY.up.set( 0, 0, - 1 );
  7975. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  7976. this.add( cameraNY );
  7977. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7978. cameraPZ.up.set( 0, - 1, 0 );
  7979. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  7980. this.add( cameraPZ );
  7981. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  7982. cameraNZ.up.set( 0, - 1, 0 );
  7983. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  7984. this.add( cameraNZ );
  7985. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  7986. this.updateCubeMap = function ( renderer, scene ) {
  7987. if ( this.parent === null ) this.updateMatrixWorld();
  7988. var renderTarget = this.renderTarget;
  7989. var generateMipmaps = renderTarget.texture.generateMipmaps;
  7990. renderTarget.texture.generateMipmaps = false;
  7991. renderTarget.activeCubeFace = 0;
  7992. renderer.render( scene, cameraPX, renderTarget );
  7993. renderTarget.activeCubeFace = 1;
  7994. renderer.render( scene, cameraNX, renderTarget );
  7995. renderTarget.activeCubeFace = 2;
  7996. renderer.render( scene, cameraPY, renderTarget );
  7997. renderTarget.activeCubeFace = 3;
  7998. renderer.render( scene, cameraNY, renderTarget );
  7999. renderTarget.activeCubeFace = 4;
  8000. renderer.render( scene, cameraPZ, renderTarget );
  8001. renderTarget.texture.generateMipmaps = generateMipmaps;
  8002. renderTarget.activeCubeFace = 5;
  8003. renderer.render( scene, cameraNZ, renderTarget );
  8004. renderer.setRenderTarget( null );
  8005. };
  8006. };
  8007. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  8008. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  8009. // File:src/cameras/OrthographicCamera.js
  8010. /**
  8011. * @author alteredq / http://alteredqualia.com/
  8012. */
  8013. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  8014. THREE.Camera.call( this );
  8015. this.type = 'OrthographicCamera';
  8016. this.zoom = 1;
  8017. this.left = left;
  8018. this.right = right;
  8019. this.top = top;
  8020. this.bottom = bottom;
  8021. this.near = ( near !== undefined ) ? near : 0.1;
  8022. this.far = ( far !== undefined ) ? far : 2000;
  8023. this.updateProjectionMatrix();
  8024. };
  8025. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  8026. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  8027. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  8028. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  8029. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  8030. var cx = ( this.right + this.left ) / 2;
  8031. var cy = ( this.top + this.bottom ) / 2;
  8032. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  8033. };
  8034. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  8035. THREE.Camera.prototype.copy.call( this, source );
  8036. this.left = source.left;
  8037. this.right = source.right;
  8038. this.top = source.top;
  8039. this.bottom = source.bottom;
  8040. this.near = source.near;
  8041. this.far = source.far;
  8042. this.zoom = source.zoom;
  8043. return this;
  8044. };
  8045. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  8046. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8047. data.object.zoom = this.zoom;
  8048. data.object.left = this.left;
  8049. data.object.right = this.right;
  8050. data.object.top = this.top;
  8051. data.object.bottom = this.bottom;
  8052. data.object.near = this.near;
  8053. data.object.far = this.far;
  8054. return data;
  8055. };
  8056. // File:src/cameras/PerspectiveCamera.js
  8057. /**
  8058. * @author mrdoob / http://mrdoob.com/
  8059. * @author greggman / http://games.greggman.com/
  8060. * @author zz85 / http://www.lab4games.net/zz85/blog
  8061. */
  8062. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  8063. THREE.Camera.call( this );
  8064. this.type = 'PerspectiveCamera';
  8065. this.zoom = 1;
  8066. this.fov = fov !== undefined ? fov : 50;
  8067. this.aspect = aspect !== undefined ? aspect : 1;
  8068. this.near = near !== undefined ? near : 0.1;
  8069. this.far = far !== undefined ? far : 2000;
  8070. this.updateProjectionMatrix();
  8071. };
  8072. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  8073. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  8074. /**
  8075. * Uses Focal Length (in mm) to estimate and set FOV
  8076. * 35mm (full-frame) camera is used if frame size is not specified;
  8077. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  8078. */
  8079. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  8080. if ( frameHeight === undefined ) frameHeight = 24;
  8081. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  8082. this.updateProjectionMatrix();
  8083. };
  8084. /**
  8085. * Sets an offset in a larger frustum. This is useful for multi-window or
  8086. * multi-monitor/multi-machine setups.
  8087. *
  8088. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8089. * the monitors are in grid like this
  8090. *
  8091. * +---+---+---+
  8092. * | A | B | C |
  8093. * +---+---+---+
  8094. * | D | E | F |
  8095. * +---+---+---+
  8096. *
  8097. * then for each monitor you would call it like this
  8098. *
  8099. * var w = 1920;
  8100. * var h = 1080;
  8101. * var fullWidth = w * 3;
  8102. * var fullHeight = h * 2;
  8103. *
  8104. * --A--
  8105. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8106. * --B--
  8107. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8108. * --C--
  8109. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8110. * --D--
  8111. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8112. * --E--
  8113. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8114. * --F--
  8115. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8116. *
  8117. * Note there is no reason monitors have to be the same size or in a grid.
  8118. */
  8119. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  8120. this.fullWidth = fullWidth;
  8121. this.fullHeight = fullHeight;
  8122. this.x = x;
  8123. this.y = y;
  8124. this.width = width;
  8125. this.height = height;
  8126. this.updateProjectionMatrix();
  8127. };
  8128. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  8129. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  8130. if ( this.fullWidth ) {
  8131. var aspect = this.fullWidth / this.fullHeight;
  8132. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  8133. var bottom = - top;
  8134. var left = aspect * bottom;
  8135. var right = aspect * top;
  8136. var width = Math.abs( right - left );
  8137. var height = Math.abs( top - bottom );
  8138. this.projectionMatrix.makeFrustum(
  8139. left + this.x * width / this.fullWidth,
  8140. left + ( this.x + this.width ) * width / this.fullWidth,
  8141. top - ( this.y + this.height ) * height / this.fullHeight,
  8142. top - this.y * height / this.fullHeight,
  8143. this.near,
  8144. this.far
  8145. );
  8146. } else {
  8147. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  8148. }
  8149. };
  8150. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  8151. THREE.Camera.prototype.copy.call( this, source );
  8152. this.fov = source.fov;
  8153. this.aspect = source.aspect;
  8154. this.near = source.near;
  8155. this.far = source.far;
  8156. this.zoom = source.zoom;
  8157. return this;
  8158. };
  8159. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  8160. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8161. data.object.zoom = this.zoom;
  8162. data.object.fov = this.fov;
  8163. data.object.aspect = this.aspect;
  8164. data.object.near = this.near;
  8165. data.object.far = this.far;
  8166. return data;
  8167. };
  8168. // File:src/lights/Light.js
  8169. /**
  8170. * @author mrdoob / http://mrdoob.com/
  8171. * @author alteredq / http://alteredqualia.com/
  8172. */
  8173. THREE.Light = function ( color ) {
  8174. THREE.Object3D.call( this );
  8175. this.type = 'Light';
  8176. this.color = new THREE.Color( color );
  8177. this.receiveShadow = undefined;
  8178. };
  8179. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  8180. THREE.Light.prototype.constructor = THREE.Light;
  8181. Object.defineProperties( THREE.Light.prototype, {
  8182. onlyShadow: {
  8183. set: function ( value ) {
  8184. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  8185. }
  8186. },
  8187. shadowCameraFov: {
  8188. set: function ( value ) {
  8189. this.shadow.camera.fov = value;
  8190. }
  8191. },
  8192. shadowCameraLeft: {
  8193. set: function ( value ) {
  8194. this.shadow.camera.left = value;
  8195. }
  8196. },
  8197. shadowCameraRight: {
  8198. set: function ( value ) {
  8199. this.shadow.camera.right = value;
  8200. }
  8201. },
  8202. shadowCameraTop: {
  8203. set: function ( value ) {
  8204. this.shadow.camera.top = value;
  8205. }
  8206. },
  8207. shadowCameraBottom: {
  8208. set: function ( value ) {
  8209. this.shadow.camera.bottom = value;
  8210. }
  8211. },
  8212. shadowCameraNear: {
  8213. set: function ( value ) {
  8214. this.shadow.camera.near = value;
  8215. }
  8216. },
  8217. shadowCameraFar: {
  8218. set: function ( value ) {
  8219. this.shadow.camera.far = value;
  8220. }
  8221. },
  8222. shadowCameraVisible: {
  8223. set: function ( value ) {
  8224. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow ) instead.' );
  8225. }
  8226. },
  8227. shadowBias: {
  8228. set: function ( value ) {
  8229. this.shadow.bias = value;
  8230. }
  8231. },
  8232. shadowDarkness: {
  8233. set: function ( value ) {
  8234. this.shadow.darkness = value;
  8235. }
  8236. },
  8237. shadowMapWidth: {
  8238. set: function ( value ) {
  8239. this.shadow.mapSize.width = value;
  8240. }
  8241. },
  8242. shadowMapHeight: {
  8243. set: function ( value ) {
  8244. this.shadow.mapSize.height = value;
  8245. }
  8246. }
  8247. } );
  8248. THREE.Light.prototype.copy = function ( source ) {
  8249. THREE.Object3D.prototype.copy.call( this, source );
  8250. this.color.copy( source.color );
  8251. return this;
  8252. };
  8253. THREE.Light.prototype.toJSON = function ( meta ) {
  8254. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8255. data.object.color = this.color.getHex();
  8256. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  8257. if ( this.intensity !== undefined ) data.object.intensity = this.intensity;
  8258. if ( this.distance !== undefined ) data.object.distance = this.distance;
  8259. if ( this.angle !== undefined ) data.object.angle = this.angle;
  8260. if ( this.decay !== undefined ) data.object.decay = this.decay;
  8261. if ( this.exponent !== undefined ) data.object.exponent = this.exponent;
  8262. return data;
  8263. };
  8264. // File:src/lights/LightShadow.js
  8265. /**
  8266. * @author mrdoob / http://mrdoob.com/
  8267. */
  8268. THREE.LightShadow = function ( camera ) {
  8269. this.camera = camera;
  8270. this.bias = 0;
  8271. this.darkness = 1;
  8272. this.mapSize = new THREE.Vector2( 512, 512 );
  8273. this.map = null;
  8274. this.matrix = null;
  8275. };
  8276. THREE.LightShadow.prototype = {
  8277. constructor: THREE.LightShadow,
  8278. copy: function ( source ) {
  8279. this.camera = source.camera.clone();
  8280. this.bias = source.bias;
  8281. this.darkness = source.darkness;
  8282. this.mapSize.copy( source.mapSize );
  8283. },
  8284. clone: function () {
  8285. return new this.constructor().copy( this );
  8286. }
  8287. };
  8288. // File:src/lights/AmbientLight.js
  8289. /**
  8290. * @author mrdoob / http://mrdoob.com/
  8291. */
  8292. THREE.AmbientLight = function ( color ) {
  8293. THREE.Light.call( this, color );
  8294. this.type = 'AmbientLight';
  8295. this.castShadow = undefined;
  8296. };
  8297. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  8298. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  8299. // File:src/lights/DirectionalLight.js
  8300. /**
  8301. * @author mrdoob / http://mrdoob.com/
  8302. * @author alteredq / http://alteredqualia.com/
  8303. */
  8304. THREE.DirectionalLight = function ( color, intensity ) {
  8305. THREE.Light.call( this, color );
  8306. this.type = 'DirectionalLight';
  8307. this.position.set( 0, 1, 0 );
  8308. this.updateMatrix();
  8309. this.target = new THREE.Object3D();
  8310. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8311. this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 500, 500, 500, - 500, 50, 5000 ) );
  8312. };
  8313. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  8314. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  8315. THREE.DirectionalLight.prototype.copy = function ( source ) {
  8316. THREE.Light.prototype.copy.call( this, source );
  8317. this.intensity = source.intensity;
  8318. this.target = source.target.clone();
  8319. this.shadow = source.shadow.clone();
  8320. return this;
  8321. };
  8322. // File:src/lights/HemisphereLight.js
  8323. /**
  8324. * @author alteredq / http://alteredqualia.com/
  8325. */
  8326. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  8327. THREE.Light.call( this, skyColor );
  8328. this.type = 'HemisphereLight';
  8329. this.castShadow = undefined;
  8330. this.position.set( 0, 1, 0 );
  8331. this.updateMatrix();
  8332. this.groundColor = new THREE.Color( groundColor );
  8333. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8334. };
  8335. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  8336. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  8337. THREE.HemisphereLight.prototype.copy = function ( source ) {
  8338. THREE.Light.prototype.copy.call( this, source );
  8339. this.groundColor.copy( source.groundColor );
  8340. this.intensity = source.intensity;
  8341. return this;
  8342. };
  8343. // File:src/lights/PointLight.js
  8344. /**
  8345. * @author mrdoob / http://mrdoob.com/
  8346. */
  8347. THREE.PointLight = function ( color, intensity, distance, decay ) {
  8348. THREE.Light.call( this, color );
  8349. this.type = 'PointLight';
  8350. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8351. this.distance = ( distance !== undefined ) ? distance : 0;
  8352. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8353. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 1, 500 ) );
  8354. };
  8355. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  8356. THREE.PointLight.prototype.constructor = THREE.PointLight;
  8357. THREE.PointLight.prototype.copy = function ( source ) {
  8358. THREE.Light.prototype.copy.call( this, source );
  8359. this.intensity = source.intensity;
  8360. this.distance = source.distance;
  8361. this.decay = source.decay;
  8362. this.shadow = source.shadow.clone();
  8363. return this;
  8364. };
  8365. // File:src/lights/SpotLight.js
  8366. /**
  8367. * @author alteredq / http://alteredqualia.com/
  8368. */
  8369. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  8370. THREE.Light.call( this, color );
  8371. this.type = 'SpotLight';
  8372. this.position.set( 0, 1, 0 );
  8373. this.updateMatrix();
  8374. this.target = new THREE.Object3D();
  8375. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8376. this.distance = ( distance !== undefined ) ? distance : 0;
  8377. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  8378. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  8379. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8380. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 50, 5000 ) );
  8381. };
  8382. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  8383. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  8384. THREE.SpotLight.prototype.copy = function ( source ) {
  8385. THREE.Light.prototype.copy.call( this, source );
  8386. this.intensity = source.intensity;
  8387. this.distance = source.distance;
  8388. this.angle = source.angle;
  8389. this.exponent = source.exponent;
  8390. this.decay = source.decay;
  8391. this.target = source.target.clone();
  8392. this.shadow = source.shadow.clone();
  8393. return this;
  8394. };
  8395. // File:src/loaders/Cache.js
  8396. /**
  8397. * @author mrdoob / http://mrdoob.com/
  8398. */
  8399. THREE.Cache = {
  8400. enabled: false,
  8401. files: {},
  8402. add: function ( key, file ) {
  8403. if ( this.enabled === false ) return;
  8404. // console.log( 'THREE.Cache', 'Adding key:', key );
  8405. this.files[ key ] = file;
  8406. },
  8407. get: function ( key ) {
  8408. if ( this.enabled === false ) return;
  8409. // console.log( 'THREE.Cache', 'Checking key:', key );
  8410. return this.files[ key ];
  8411. },
  8412. remove: function ( key ) {
  8413. delete this.files[ key ];
  8414. },
  8415. clear: function () {
  8416. this.files = {};
  8417. }
  8418. };
  8419. // File:src/loaders/Loader.js
  8420. /**
  8421. * @author alteredq / http://alteredqualia.com/
  8422. */
  8423. THREE.Loader = function () {
  8424. this.onLoadStart = function () {};
  8425. this.onLoadProgress = function () {};
  8426. this.onLoadComplete = function () {};
  8427. };
  8428. THREE.Loader.prototype = {
  8429. constructor: THREE.Loader,
  8430. crossOrigin: undefined,
  8431. extractUrlBase: function ( url ) {
  8432. var parts = url.split( '/' );
  8433. if ( parts.length === 1 ) return './';
  8434. parts.pop();
  8435. return parts.join( '/' ) + '/';
  8436. },
  8437. initMaterials: function ( materials, texturePath, crossOrigin ) {
  8438. var array = [];
  8439. for ( var i = 0; i < materials.length; ++ i ) {
  8440. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  8441. }
  8442. return array;
  8443. },
  8444. createMaterial: ( function () {
  8445. var color, textureLoader, materialLoader;
  8446. return function ( m, texturePath, crossOrigin ) {
  8447. if ( color === undefined ) color = new THREE.Color();
  8448. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  8449. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  8450. // convert from old material format
  8451. var textures = {};
  8452. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  8453. var fullPath = texturePath + path;
  8454. var loader = THREE.Loader.Handlers.get( fullPath );
  8455. var texture;
  8456. if ( loader !== null ) {
  8457. texture = loader.load( fullPath );
  8458. } else {
  8459. textureLoader.setCrossOrigin( crossOrigin );
  8460. texture = textureLoader.load( fullPath );
  8461. }
  8462. if ( repeat !== undefined ) {
  8463. texture.repeat.fromArray( repeat );
  8464. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  8465. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  8466. }
  8467. if ( offset !== undefined ) {
  8468. texture.offset.fromArray( offset );
  8469. }
  8470. if ( wrap !== undefined ) {
  8471. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  8472. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  8473. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  8474. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  8475. }
  8476. if ( anisotropy !== undefined ) {
  8477. texture.anisotropy = anisotropy;
  8478. }
  8479. var uuid = THREE.Math.generateUUID();
  8480. textures[ uuid ] = texture;
  8481. return uuid;
  8482. }
  8483. //
  8484. var json = {
  8485. uuid: THREE.Math.generateUUID(),
  8486. type: 'MeshLambertMaterial'
  8487. };
  8488. for ( var name in m ) {
  8489. var value = m[ name ];
  8490. switch ( name ) {
  8491. case 'DbgColor':
  8492. json.color = value;
  8493. break;
  8494. case 'DbgIndex':
  8495. case 'opticalDensity':
  8496. case 'illumination':
  8497. // These were never supported
  8498. break;
  8499. case 'DbgName':
  8500. json.name = value;
  8501. break;
  8502. case 'blending':
  8503. json.blending = THREE[ value ];
  8504. break;
  8505. case 'colorDiffuse':
  8506. json.color = color.fromArray( value ).getHex();
  8507. break;
  8508. case 'colorSpecular':
  8509. json.specular = color.fromArray( value ).getHex();
  8510. break;
  8511. case 'colorEmissive':
  8512. json.emissive = color.fromArray( value ).getHex();
  8513. break;
  8514. case 'specularCoef':
  8515. json.shininess = value;
  8516. break;
  8517. case 'shading':
  8518. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  8519. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  8520. break;
  8521. case 'mapDiffuse':
  8522. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  8523. break;
  8524. case 'mapDiffuseRepeat':
  8525. case 'mapDiffuseOffset':
  8526. case 'mapDiffuseWrap':
  8527. case 'mapDiffuseAnisotropy':
  8528. break;
  8529. case 'mapLight':
  8530. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  8531. break;
  8532. case 'mapLightRepeat':
  8533. case 'mapLightOffset':
  8534. case 'mapLightWrap':
  8535. case 'mapLightAnisotropy':
  8536. break;
  8537. case 'mapAO':
  8538. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  8539. break;
  8540. case 'mapAORepeat':
  8541. case 'mapAOOffset':
  8542. case 'mapAOWrap':
  8543. case 'mapAOAnisotropy':
  8544. break;
  8545. case 'mapBump':
  8546. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  8547. break;
  8548. case 'mapBumpScale':
  8549. json.bumpScale = value;
  8550. break;
  8551. case 'mapBumpRepeat':
  8552. case 'mapBumpOffset':
  8553. case 'mapBumpWrap':
  8554. case 'mapBumpAnisotropy':
  8555. break;
  8556. case 'mapNormal':
  8557. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  8558. break;
  8559. case 'mapNormalFactor':
  8560. json.normalScale = [ value, value ];
  8561. break;
  8562. case 'mapNormalRepeat':
  8563. case 'mapNormalOffset':
  8564. case 'mapNormalWrap':
  8565. case 'mapNormalAnisotropy':
  8566. break;
  8567. case 'mapSpecular':
  8568. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  8569. break;
  8570. case 'mapSpecularRepeat':
  8571. case 'mapSpecularOffset':
  8572. case 'mapSpecularWrap':
  8573. case 'mapSpecularAnisotropy':
  8574. break;
  8575. case 'mapAlpha':
  8576. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  8577. break;
  8578. case 'mapAlphaRepeat':
  8579. case 'mapAlphaOffset':
  8580. case 'mapAlphaWrap':
  8581. case 'mapAlphaAnisotropy':
  8582. break;
  8583. case 'flipSided':
  8584. json.side = THREE.BackSide;
  8585. break;
  8586. case 'doubleSided':
  8587. json.side = THREE.DoubleSide;
  8588. break;
  8589. case 'transparency':
  8590. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  8591. json.opacity = value;
  8592. break;
  8593. case 'opacity':
  8594. case 'transparent':
  8595. case 'depthTest':
  8596. case 'depthWrite':
  8597. case 'transparent':
  8598. case 'visible':
  8599. case 'wireframe':
  8600. json[ name ] = value;
  8601. break;
  8602. case 'vertexColors':
  8603. if ( value === true ) json.vertexColors = THREE.VertexColors;
  8604. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  8605. break;
  8606. default:
  8607. console.error( 'Loader.createMaterial: Unsupported', name, value );
  8608. break;
  8609. }
  8610. }
  8611. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  8612. if ( json.opacity < 1 ) json.transparent = true;
  8613. materialLoader.setTextures( textures );
  8614. return materialLoader.parse( json );
  8615. };
  8616. } )()
  8617. };
  8618. THREE.Loader.Handlers = {
  8619. handlers: [],
  8620. add: function ( regex, loader ) {
  8621. this.handlers.push( regex, loader );
  8622. },
  8623. get: function ( file ) {
  8624. var handlers = this.handlers;
  8625. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  8626. var regex = handlers[ i ];
  8627. var loader = handlers[ i + 1 ];
  8628. if ( regex.test( file ) ) {
  8629. return loader;
  8630. }
  8631. }
  8632. return null;
  8633. }
  8634. };
  8635. // File:src/loaders/XHRLoader.js
  8636. /**
  8637. * @author mrdoob / http://mrdoob.com/
  8638. */
  8639. THREE.XHRLoader = function ( manager ) {
  8640. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8641. };
  8642. THREE.XHRLoader.prototype = {
  8643. constructor: THREE.XHRLoader,
  8644. load: function ( url, onLoad, onProgress, onError ) {
  8645. var scope = this;
  8646. var cached = THREE.Cache.get( url );
  8647. if ( cached !== undefined ) {
  8648. if ( onLoad ) {
  8649. setTimeout( function () {
  8650. onLoad( cached );
  8651. }, 0 );
  8652. }
  8653. return cached;
  8654. }
  8655. var request = new XMLHttpRequest();
  8656. request.open( 'GET', url, true );
  8657. request.addEventListener( 'load', function ( event ) {
  8658. var response = event.target.response;
  8659. THREE.Cache.add( url, response );
  8660. if ( onLoad ) onLoad( response );
  8661. scope.manager.itemEnd( url );
  8662. }, false );
  8663. if ( onProgress !== undefined ) {
  8664. request.addEventListener( 'progress', function ( event ) {
  8665. onProgress( event );
  8666. }, false );
  8667. }
  8668. request.addEventListener( 'error', function ( event ) {
  8669. if ( onError ) onError( event );
  8670. scope.manager.itemError( url );
  8671. }, false );
  8672. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  8673. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  8674. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  8675. request.send( null );
  8676. scope.manager.itemStart( url );
  8677. return request;
  8678. },
  8679. setResponseType: function ( value ) {
  8680. this.responseType = value;
  8681. },
  8682. setCrossOrigin: function ( value ) {
  8683. this.crossOrigin = value;
  8684. },
  8685. setWithCredentials: function ( value ) {
  8686. this.withCredentials = value;
  8687. }
  8688. };
  8689. // File:src/loaders/ImageLoader.js
  8690. /**
  8691. * @author mrdoob / http://mrdoob.com/
  8692. */
  8693. THREE.ImageLoader = function ( manager ) {
  8694. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8695. };
  8696. THREE.ImageLoader.prototype = {
  8697. constructor: THREE.ImageLoader,
  8698. load: function ( url, onLoad, onProgress, onError ) {
  8699. var scope = this;
  8700. var cached = THREE.Cache.get( url );
  8701. if ( cached !== undefined ) {
  8702. scope.manager.itemStart( url );
  8703. if ( onLoad ) {
  8704. setTimeout( function () {
  8705. onLoad( cached );
  8706. scope.manager.itemEnd( url );
  8707. }, 0 );
  8708. } else {
  8709. scope.manager.itemEnd( url );
  8710. }
  8711. return cached;
  8712. }
  8713. var image = document.createElement( 'img' );
  8714. image.addEventListener( 'load', function ( event ) {
  8715. THREE.Cache.add( url, this );
  8716. if ( onLoad ) onLoad( this );
  8717. scope.manager.itemEnd( url );
  8718. }, false );
  8719. if ( onProgress !== undefined ) {
  8720. image.addEventListener( 'progress', function ( event ) {
  8721. onProgress( event );
  8722. }, false );
  8723. }
  8724. image.addEventListener( 'error', function ( event ) {
  8725. if ( onError ) onError( event );
  8726. scope.manager.itemError( url );
  8727. }, false );
  8728. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  8729. scope.manager.itemStart( url );
  8730. image.src = url;
  8731. return image;
  8732. },
  8733. setCrossOrigin: function ( value ) {
  8734. this.crossOrigin = value;
  8735. }
  8736. };
  8737. // File:src/loaders/JSONLoader.js
  8738. /**
  8739. * @author mrdoob / http://mrdoob.com/
  8740. * @author alteredq / http://alteredqualia.com/
  8741. */
  8742. THREE.JSONLoader = function ( manager ) {
  8743. if ( typeof manager === 'boolean' ) {
  8744. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  8745. manager = undefined;
  8746. }
  8747. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8748. this.withCredentials = false;
  8749. };
  8750. THREE.JSONLoader.prototype = {
  8751. constructor: THREE.JSONLoader,
  8752. // Deprecated
  8753. get statusDomElement () {
  8754. if ( this._statusDomElement === undefined ) {
  8755. this._statusDomElement = document.createElement( 'div' );
  8756. }
  8757. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  8758. return this._statusDomElement;
  8759. },
  8760. load: function( url, onLoad, onProgress, onError ) {
  8761. var scope = this;
  8762. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  8763. var loader = new THREE.XHRLoader( this.manager );
  8764. loader.setCrossOrigin( this.crossOrigin );
  8765. loader.setWithCredentials( this.withCredentials );
  8766. loader.load( url, function ( text ) {
  8767. var json = JSON.parse( text );
  8768. var metadata = json.metadata;
  8769. if ( metadata !== undefined ) {
  8770. if ( metadata.type === 'object' ) {
  8771. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  8772. return;
  8773. }
  8774. if ( metadata.type === 'scene' ) {
  8775. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  8776. return;
  8777. }
  8778. }
  8779. var object = scope.parse( json, texturePath );
  8780. onLoad( object.geometry, object.materials );
  8781. } );
  8782. },
  8783. setCrossOrigin: function ( value ) {
  8784. this.crossOrigin = value;
  8785. },
  8786. setTexturePath: function ( value ) {
  8787. this.texturePath = value;
  8788. },
  8789. parse: function ( json, texturePath ) {
  8790. var geometry = new THREE.Geometry(),
  8791. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  8792. parseModel( scale );
  8793. parseSkin();
  8794. parseMorphing( scale );
  8795. parseAnimations();
  8796. geometry.computeFaceNormals();
  8797. geometry.computeBoundingSphere();
  8798. function parseModel( scale ) {
  8799. function isBitSet( value, position ) {
  8800. return value & ( 1 << position );
  8801. }
  8802. var i, j, fi,
  8803. offset, zLength,
  8804. colorIndex, normalIndex, uvIndex, materialIndex,
  8805. type,
  8806. isQuad,
  8807. hasMaterial,
  8808. hasFaceVertexUv,
  8809. hasFaceNormal, hasFaceVertexNormal,
  8810. hasFaceColor, hasFaceVertexColor,
  8811. vertex, face, faceA, faceB, hex, normal,
  8812. uvLayer, uv, u, v,
  8813. faces = json.faces,
  8814. vertices = json.vertices,
  8815. normals = json.normals,
  8816. colors = json.colors,
  8817. nUvLayers = 0;
  8818. if ( json.uvs !== undefined ) {
  8819. // disregard empty arrays
  8820. for ( i = 0; i < json.uvs.length; i ++ ) {
  8821. if ( json.uvs[ i ].length ) nUvLayers ++;
  8822. }
  8823. for ( i = 0; i < nUvLayers; i ++ ) {
  8824. geometry.faceVertexUvs[ i ] = [];
  8825. }
  8826. }
  8827. offset = 0;
  8828. zLength = vertices.length;
  8829. while ( offset < zLength ) {
  8830. vertex = new THREE.Vector3();
  8831. vertex.x = vertices[ offset ++ ] * scale;
  8832. vertex.y = vertices[ offset ++ ] * scale;
  8833. vertex.z = vertices[ offset ++ ] * scale;
  8834. geometry.vertices.push( vertex );
  8835. }
  8836. offset = 0;
  8837. zLength = faces.length;
  8838. while ( offset < zLength ) {
  8839. type = faces[ offset ++ ];
  8840. isQuad = isBitSet( type, 0 );
  8841. hasMaterial = isBitSet( type, 1 );
  8842. hasFaceVertexUv = isBitSet( type, 3 );
  8843. hasFaceNormal = isBitSet( type, 4 );
  8844. hasFaceVertexNormal = isBitSet( type, 5 );
  8845. hasFaceColor = isBitSet( type, 6 );
  8846. hasFaceVertexColor = isBitSet( type, 7 );
  8847. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  8848. if ( isQuad ) {
  8849. faceA = new THREE.Face3();
  8850. faceA.a = faces[ offset ];
  8851. faceA.b = faces[ offset + 1 ];
  8852. faceA.c = faces[ offset + 3 ];
  8853. faceB = new THREE.Face3();
  8854. faceB.a = faces[ offset + 1 ];
  8855. faceB.b = faces[ offset + 2 ];
  8856. faceB.c = faces[ offset + 3 ];
  8857. offset += 4;
  8858. if ( hasMaterial ) {
  8859. materialIndex = faces[ offset ++ ];
  8860. faceA.materialIndex = materialIndex;
  8861. faceB.materialIndex = materialIndex;
  8862. }
  8863. // to get face <=> uv index correspondence
  8864. fi = geometry.faces.length;
  8865. if ( hasFaceVertexUv ) {
  8866. for ( i = 0; i < nUvLayers; i ++ ) {
  8867. uvLayer = json.uvs[ i ];
  8868. geometry.faceVertexUvs[ i ][ fi ] = [];
  8869. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  8870. for ( j = 0; j < 4; j ++ ) {
  8871. uvIndex = faces[ offset ++ ];
  8872. u = uvLayer[ uvIndex * 2 ];
  8873. v = uvLayer[ uvIndex * 2 + 1 ];
  8874. uv = new THREE.Vector2( u, v );
  8875. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  8876. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  8877. }
  8878. }
  8879. }
  8880. if ( hasFaceNormal ) {
  8881. normalIndex = faces[ offset ++ ] * 3;
  8882. faceA.normal.set(
  8883. normals[ normalIndex ++ ],
  8884. normals[ normalIndex ++ ],
  8885. normals[ normalIndex ]
  8886. );
  8887. faceB.normal.copy( faceA.normal );
  8888. }
  8889. if ( hasFaceVertexNormal ) {
  8890. for ( i = 0; i < 4; i ++ ) {
  8891. normalIndex = faces[ offset ++ ] * 3;
  8892. normal = new THREE.Vector3(
  8893. normals[ normalIndex ++ ],
  8894. normals[ normalIndex ++ ],
  8895. normals[ normalIndex ]
  8896. );
  8897. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  8898. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  8899. }
  8900. }
  8901. if ( hasFaceColor ) {
  8902. colorIndex = faces[ offset ++ ];
  8903. hex = colors[ colorIndex ];
  8904. faceA.color.setHex( hex );
  8905. faceB.color.setHex( hex );
  8906. }
  8907. if ( hasFaceVertexColor ) {
  8908. for ( i = 0; i < 4; i ++ ) {
  8909. colorIndex = faces[ offset ++ ];
  8910. hex = colors[ colorIndex ];
  8911. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  8912. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  8913. }
  8914. }
  8915. geometry.faces.push( faceA );
  8916. geometry.faces.push( faceB );
  8917. } else {
  8918. face = new THREE.Face3();
  8919. face.a = faces[ offset ++ ];
  8920. face.b = faces[ offset ++ ];
  8921. face.c = faces[ offset ++ ];
  8922. if ( hasMaterial ) {
  8923. materialIndex = faces[ offset ++ ];
  8924. face.materialIndex = materialIndex;
  8925. }
  8926. // to get face <=> uv index correspondence
  8927. fi = geometry.faces.length;
  8928. if ( hasFaceVertexUv ) {
  8929. for ( i = 0; i < nUvLayers; i ++ ) {
  8930. uvLayer = json.uvs[ i ];
  8931. geometry.faceVertexUvs[ i ][ fi ] = [];
  8932. for ( j = 0; j < 3; j ++ ) {
  8933. uvIndex = faces[ offset ++ ];
  8934. u = uvLayer[ uvIndex * 2 ];
  8935. v = uvLayer[ uvIndex * 2 + 1 ];
  8936. uv = new THREE.Vector2( u, v );
  8937. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  8938. }
  8939. }
  8940. }
  8941. if ( hasFaceNormal ) {
  8942. normalIndex = faces[ offset ++ ] * 3;
  8943. face.normal.set(
  8944. normals[ normalIndex ++ ],
  8945. normals[ normalIndex ++ ],
  8946. normals[ normalIndex ]
  8947. );
  8948. }
  8949. if ( hasFaceVertexNormal ) {
  8950. for ( i = 0; i < 3; i ++ ) {
  8951. normalIndex = faces[ offset ++ ] * 3;
  8952. normal = new THREE.Vector3(
  8953. normals[ normalIndex ++ ],
  8954. normals[ normalIndex ++ ],
  8955. normals[ normalIndex ]
  8956. );
  8957. face.vertexNormals.push( normal );
  8958. }
  8959. }
  8960. if ( hasFaceColor ) {
  8961. colorIndex = faces[ offset ++ ];
  8962. face.color.setHex( colors[ colorIndex ] );
  8963. }
  8964. if ( hasFaceVertexColor ) {
  8965. for ( i = 0; i < 3; i ++ ) {
  8966. colorIndex = faces[ offset ++ ];
  8967. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  8968. }
  8969. }
  8970. geometry.faces.push( face );
  8971. }
  8972. }
  8973. };
  8974. function parseSkin() {
  8975. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  8976. if ( json.skinWeights ) {
  8977. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  8978. var x = json.skinWeights[ i ];
  8979. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  8980. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  8981. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  8982. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  8983. }
  8984. }
  8985. if ( json.skinIndices ) {
  8986. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  8987. var a = json.skinIndices[ i ];
  8988. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  8989. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  8990. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  8991. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  8992. }
  8993. }
  8994. geometry.bones = json.bones;
  8995. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  8996. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  8997. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  8998. }
  8999. };
  9000. function parseMorphing( scale ) {
  9001. if ( json.morphTargets !== undefined ) {
  9002. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  9003. geometry.morphTargets[ i ] = {};
  9004. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  9005. geometry.morphTargets[ i ].vertices = [];
  9006. var dstVertices = geometry.morphTargets[ i ].vertices;
  9007. var srcVertices = json.morphTargets[ i ].vertices;
  9008. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  9009. var vertex = new THREE.Vector3();
  9010. vertex.x = srcVertices[ v ] * scale;
  9011. vertex.y = srcVertices[ v + 1 ] * scale;
  9012. vertex.z = srcVertices[ v + 2 ] * scale;
  9013. dstVertices.push( vertex );
  9014. }
  9015. }
  9016. }
  9017. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  9018. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  9019. var faces = geometry.faces;
  9020. var morphColors = json.morphColors[ 0 ].colors;
  9021. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  9022. faces[ i ].color.fromArray( morphColors, i * 3 );
  9023. }
  9024. }
  9025. }
  9026. function parseAnimations() {
  9027. var outputAnimations = [];
  9028. // parse old style Bone/Hierarchy animations
  9029. var animations = [];
  9030. if ( json.animation !== undefined ) {
  9031. animations.push( json.animation );
  9032. }
  9033. if ( json.animations !== undefined ) {
  9034. if ( json.animations.length ) {
  9035. animations = animations.concat( json.animations );
  9036. } else {
  9037. animations.push( json.animations );
  9038. }
  9039. }
  9040. for ( var i = 0; i < animations.length; i ++ ) {
  9041. var clip = THREE.AnimationClip.parseAnimation( animations[i], geometry.bones );
  9042. if ( clip ) outputAnimations.push( clip );
  9043. }
  9044. // parse implicit morph animations
  9045. if ( geometry.morphTargets ) {
  9046. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  9047. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  9048. outputAnimations = outputAnimations.concat( morphAnimationClips );
  9049. }
  9050. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  9051. };
  9052. if ( json.materials === undefined || json.materials.length === 0 ) {
  9053. return { geometry: geometry };
  9054. } else {
  9055. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  9056. return { geometry: geometry, materials: materials };
  9057. }
  9058. }
  9059. };
  9060. // File:src/loaders/LoadingManager.js
  9061. /**
  9062. * @author mrdoob / http://mrdoob.com/
  9063. */
  9064. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  9065. var scope = this;
  9066. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  9067. this.onStart = undefined;
  9068. this.onLoad = onLoad;
  9069. this.onProgress = onProgress;
  9070. this.onError = onError;
  9071. this.itemStart = function ( url ) {
  9072. itemsTotal ++;
  9073. if ( isLoading === false ) {
  9074. if ( scope.onStart !== undefined ) {
  9075. scope.onStart( url, itemsLoaded, itemsTotal );
  9076. }
  9077. }
  9078. isLoading = true;
  9079. };
  9080. this.itemEnd = function ( url ) {
  9081. itemsLoaded ++;
  9082. if ( scope.onProgress !== undefined ) {
  9083. scope.onProgress( url, itemsLoaded, itemsTotal );
  9084. }
  9085. if ( itemsLoaded === itemsTotal ) {
  9086. isLoading = false;
  9087. if ( scope.onLoad !== undefined ) {
  9088. scope.onLoad();
  9089. }
  9090. }
  9091. };
  9092. this.itemError = function ( url ) {
  9093. if ( scope.onError !== undefined ) {
  9094. scope.onError( url );
  9095. }
  9096. };
  9097. };
  9098. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  9099. // File:src/loaders/BufferGeometryLoader.js
  9100. /**
  9101. * @author mrdoob / http://mrdoob.com/
  9102. */
  9103. THREE.BufferGeometryLoader = function ( manager ) {
  9104. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9105. };
  9106. THREE.BufferGeometryLoader.prototype = {
  9107. constructor: THREE.BufferGeometryLoader,
  9108. load: function ( url, onLoad, onProgress, onError ) {
  9109. var scope = this;
  9110. var loader = new THREE.XHRLoader( scope.manager );
  9111. loader.setCrossOrigin( this.crossOrigin );
  9112. loader.load( url, function ( text ) {
  9113. onLoad( scope.parse( JSON.parse( text ) ) );
  9114. }, onProgress, onError );
  9115. },
  9116. setCrossOrigin: function ( value ) {
  9117. this.crossOrigin = value;
  9118. },
  9119. parse: function ( json ) {
  9120. var geometry = new THREE.BufferGeometry();
  9121. var index = json.data.index;
  9122. if ( index !== undefined ) {
  9123. var typedArray = new self[ index.type ]( index.array );
  9124. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  9125. }
  9126. var attributes = json.data.attributes;
  9127. for ( var key in attributes ) {
  9128. var attribute = attributes[ key ];
  9129. var typedArray = new self[ attribute.type ]( attribute.array );
  9130. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  9131. }
  9132. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  9133. if ( groups !== undefined ) {
  9134. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  9135. var group = groups[ i ];
  9136. geometry.addGroup( group.start, group.count );
  9137. }
  9138. }
  9139. var boundingSphere = json.data.boundingSphere;
  9140. if ( boundingSphere !== undefined ) {
  9141. var center = new THREE.Vector3();
  9142. if ( boundingSphere.center !== undefined ) {
  9143. center.fromArray( boundingSphere.center );
  9144. }
  9145. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  9146. }
  9147. return geometry;
  9148. }
  9149. };
  9150. // File:src/loaders/MaterialLoader.js
  9151. /**
  9152. * @author mrdoob / http://mrdoob.com/
  9153. */
  9154. THREE.MaterialLoader = function ( manager ) {
  9155. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9156. this.textures = {};
  9157. };
  9158. THREE.MaterialLoader.prototype = {
  9159. constructor: THREE.MaterialLoader,
  9160. load: function ( url, onLoad, onProgress, onError ) {
  9161. var scope = this;
  9162. var loader = new THREE.XHRLoader( scope.manager );
  9163. loader.setCrossOrigin( this.crossOrigin );
  9164. loader.load( url, function ( text ) {
  9165. onLoad( scope.parse( JSON.parse( text ) ) );
  9166. }, onProgress, onError );
  9167. },
  9168. setCrossOrigin: function ( value ) {
  9169. this.crossOrigin = value;
  9170. },
  9171. setTextures: function ( value ) {
  9172. this.textures = value;
  9173. },
  9174. getTexture: function ( name ) {
  9175. var textures = this.textures;
  9176. if ( textures[ name ] === undefined ) {
  9177. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  9178. }
  9179. return textures[ name ];
  9180. },
  9181. parse: function ( json ) {
  9182. var material = new THREE[ json.type ];
  9183. material.uuid = json.uuid;
  9184. if ( json.name !== undefined ) material.name = json.name;
  9185. if ( json.color !== undefined ) material.color.setHex( json.color );
  9186. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  9187. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  9188. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  9189. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  9190. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  9191. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  9192. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  9193. if ( json.shading !== undefined ) material.shading = json.shading;
  9194. if ( json.blending !== undefined ) material.blending = json.blending;
  9195. if ( json.side !== undefined ) material.side = json.side;
  9196. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  9197. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  9198. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  9199. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  9200. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  9201. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  9202. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  9203. // for PointsMaterial
  9204. if ( json.size !== undefined ) material.size = json.size;
  9205. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  9206. // maps
  9207. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  9208. if ( json.alphaMap !== undefined ) {
  9209. material.alphaMap = this.getTexture( json.alphaMap );
  9210. material.transparent = true;
  9211. }
  9212. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  9213. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  9214. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  9215. if ( json.normalScale ) material.normalScale = new THREE.Vector2( json.normalScale, json.normalScale );
  9216. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  9217. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  9218. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  9219. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  9220. if ( json.envMap !== undefined ) {
  9221. material.envMap = this.getTexture( json.envMap );
  9222. material.combine = THREE.MultiplyOperation;
  9223. }
  9224. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  9225. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  9226. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  9227. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  9228. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  9229. // MeshFaceMaterial
  9230. if ( json.materials !== undefined ) {
  9231. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  9232. material.materials.push( this.parse( json.materials[ i ] ) );
  9233. }
  9234. }
  9235. return material;
  9236. }
  9237. };
  9238. // File:src/loaders/ObjectLoader.js
  9239. /**
  9240. * @author mrdoob / http://mrdoob.com/
  9241. */
  9242. THREE.ObjectLoader = function ( manager ) {
  9243. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9244. this.texturePath = '';
  9245. };
  9246. THREE.ObjectLoader.prototype = {
  9247. constructor: THREE.ObjectLoader,
  9248. load: function ( url, onLoad, onProgress, onError ) {
  9249. if ( this.texturePath === '' ) {
  9250. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  9251. }
  9252. var scope = this;
  9253. var loader = new THREE.XHRLoader( scope.manager );
  9254. loader.setCrossOrigin( this.crossOrigin );
  9255. loader.load( url, function ( text ) {
  9256. scope.parse( JSON.parse( text ), onLoad );
  9257. }, onProgress, onError );
  9258. },
  9259. setTexturePath: function ( value ) {
  9260. this.texturePath = value;
  9261. },
  9262. setCrossOrigin: function ( value ) {
  9263. this.crossOrigin = value;
  9264. },
  9265. parse: function ( json, onLoad ) {
  9266. var geometries = this.parseGeometries( json.geometries );
  9267. var images = this.parseImages( json.images, function () {
  9268. if ( onLoad !== undefined ) onLoad( object );
  9269. } );
  9270. var textures = this.parseTextures( json.textures, images );
  9271. var materials = this.parseMaterials( json.materials, textures );
  9272. var object = this.parseObject( json.object, geometries, materials );
  9273. if ( json.animations ) {
  9274. object.animations = this.parseAnimations( json.animations );
  9275. }
  9276. if ( json.images === undefined || json.images.length === 0 ) {
  9277. if ( onLoad !== undefined ) onLoad( object );
  9278. }
  9279. return object;
  9280. },
  9281. parseGeometries: function ( json ) {
  9282. var geometries = {};
  9283. if ( json !== undefined ) {
  9284. var geometryLoader = new THREE.JSONLoader();
  9285. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  9286. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9287. var geometry;
  9288. var data = json[ i ];
  9289. switch ( data.type ) {
  9290. case 'PlaneGeometry':
  9291. case 'PlaneBufferGeometry':
  9292. geometry = new THREE[ data.type ](
  9293. data.width,
  9294. data.height,
  9295. data.widthSegments,
  9296. data.heightSegments
  9297. );
  9298. break;
  9299. case 'BoxGeometry':
  9300. case 'CubeGeometry': // backwards compatible
  9301. geometry = new THREE.BoxGeometry(
  9302. data.width,
  9303. data.height,
  9304. data.depth,
  9305. data.widthSegments,
  9306. data.heightSegments,
  9307. data.depthSegments
  9308. );
  9309. break;
  9310. case 'CircleBufferGeometry':
  9311. geometry = new THREE.CircleBufferGeometry(
  9312. data.radius,
  9313. data.segments,
  9314. data.thetaStart,
  9315. data.thetaLength
  9316. );
  9317. break;
  9318. case 'CircleGeometry':
  9319. geometry = new THREE.CircleGeometry(
  9320. data.radius,
  9321. data.segments,
  9322. data.thetaStart,
  9323. data.thetaLength
  9324. );
  9325. break;
  9326. case 'CylinderGeometry':
  9327. geometry = new THREE.CylinderGeometry(
  9328. data.radiusTop,
  9329. data.radiusBottom,
  9330. data.height,
  9331. data.radialSegments,
  9332. data.heightSegments,
  9333. data.openEnded,
  9334. data.thetaStart,
  9335. data.thetaLength
  9336. );
  9337. break;
  9338. case 'SphereGeometry':
  9339. geometry = new THREE.SphereGeometry(
  9340. data.radius,
  9341. data.widthSegments,
  9342. data.heightSegments,
  9343. data.phiStart,
  9344. data.phiLength,
  9345. data.thetaStart,
  9346. data.thetaLength
  9347. );
  9348. break;
  9349. case 'SphereBufferGeometry':
  9350. geometry = new THREE.SphereBufferGeometry(
  9351. data.radius,
  9352. data.widthSegments,
  9353. data.heightSegments,
  9354. data.phiStart,
  9355. data.phiLength,
  9356. data.thetaStart,
  9357. data.thetaLength
  9358. );
  9359. break;
  9360. case 'DodecahedronGeometry':
  9361. geometry = new THREE.DodecahedronGeometry(
  9362. data.radius,
  9363. data.detail
  9364. );
  9365. break;
  9366. case 'IcosahedronGeometry':
  9367. geometry = new THREE.IcosahedronGeometry(
  9368. data.radius,
  9369. data.detail
  9370. );
  9371. break;
  9372. case 'OctahedronGeometry':
  9373. geometry = new THREE.OctahedronGeometry(
  9374. data.radius,
  9375. data.detail
  9376. );
  9377. break;
  9378. case 'TetrahedronGeometry':
  9379. geometry = new THREE.TetrahedronGeometry(
  9380. data.radius,
  9381. data.detail
  9382. );
  9383. break;
  9384. case 'RingGeometry':
  9385. geometry = new THREE.RingGeometry(
  9386. data.innerRadius,
  9387. data.outerRadius,
  9388. data.thetaSegments,
  9389. data.phiSegments,
  9390. data.thetaStart,
  9391. data.thetaLength
  9392. );
  9393. break;
  9394. case 'TorusGeometry':
  9395. geometry = new THREE.TorusGeometry(
  9396. data.radius,
  9397. data.tube,
  9398. data.radialSegments,
  9399. data.tubularSegments,
  9400. data.arc
  9401. );
  9402. break;
  9403. case 'TorusKnotGeometry':
  9404. geometry = new THREE.TorusKnotGeometry(
  9405. data.radius,
  9406. data.tube,
  9407. data.radialSegments,
  9408. data.tubularSegments,
  9409. data.p,
  9410. data.q,
  9411. data.heightScale
  9412. );
  9413. break;
  9414. case 'BufferGeometry':
  9415. geometry = bufferGeometryLoader.parse( data );
  9416. break;
  9417. case 'Geometry':
  9418. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  9419. break;
  9420. default:
  9421. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  9422. continue;
  9423. }
  9424. geometry.uuid = data.uuid;
  9425. if ( data.name !== undefined ) geometry.name = data.name;
  9426. geometries[ data.uuid ] = geometry;
  9427. }
  9428. }
  9429. return geometries;
  9430. },
  9431. parseMaterials: function ( json, textures ) {
  9432. var materials = {};
  9433. if ( json !== undefined ) {
  9434. var loader = new THREE.MaterialLoader();
  9435. loader.setTextures( textures );
  9436. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9437. var material = loader.parse( json[ i ] );
  9438. materials[ material.uuid ] = material;
  9439. }
  9440. }
  9441. return materials;
  9442. },
  9443. parseAnimations: function ( json ) {
  9444. var animations = [];
  9445. for ( var i = 0; i < json.length; i ++ ) {
  9446. var clip = THREE.AnimationClip.parse( json[i] );
  9447. animations.push( clip );
  9448. }
  9449. return animations;
  9450. },
  9451. parseImages: function ( json, onLoad ) {
  9452. var scope = this;
  9453. var images = {};
  9454. function loadImage( url ) {
  9455. scope.manager.itemStart( url );
  9456. return loader.load( url, function () {
  9457. scope.manager.itemEnd( url );
  9458. } );
  9459. }
  9460. if ( json !== undefined && json.length > 0 ) {
  9461. var manager = new THREE.LoadingManager( onLoad );
  9462. var loader = new THREE.ImageLoader( manager );
  9463. loader.setCrossOrigin( this.crossOrigin );
  9464. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9465. var image = json[ i ];
  9466. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  9467. images[ image.uuid ] = loadImage( path );
  9468. }
  9469. }
  9470. return images;
  9471. },
  9472. parseTextures: function ( json, images ) {
  9473. function parseConstant( value ) {
  9474. if ( typeof( value ) === 'number' ) return value;
  9475. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  9476. return THREE[ value ];
  9477. }
  9478. var textures = {};
  9479. if ( json !== undefined ) {
  9480. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9481. var data = json[ i ];
  9482. if ( data.image === undefined ) {
  9483. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  9484. }
  9485. if ( images[ data.image ] === undefined ) {
  9486. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  9487. }
  9488. var texture = new THREE.Texture( images[ data.image ] );
  9489. texture.needsUpdate = true;
  9490. texture.uuid = data.uuid;
  9491. if ( data.name !== undefined ) texture.name = data.name;
  9492. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  9493. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  9494. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  9495. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  9496. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  9497. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  9498. if ( Array.isArray( data.wrap ) ) {
  9499. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  9500. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  9501. }
  9502. textures[ data.uuid ] = texture;
  9503. }
  9504. }
  9505. return textures;
  9506. },
  9507. parseObject: function () {
  9508. var matrix = new THREE.Matrix4();
  9509. return function ( data, geometries, materials ) {
  9510. var object;
  9511. function getGeometry( name ) {
  9512. if ( geometries[ name ] === undefined ) {
  9513. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  9514. }
  9515. return geometries[ name ];
  9516. }
  9517. function getMaterial( name ) {
  9518. if ( name === undefined ) return undefined;
  9519. if ( materials[ name ] === undefined ) {
  9520. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  9521. }
  9522. return materials[ name ];
  9523. }
  9524. switch ( data.type ) {
  9525. case 'Scene':
  9526. object = new THREE.Scene();
  9527. break;
  9528. case 'PerspectiveCamera':
  9529. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  9530. break;
  9531. case 'OrthographicCamera':
  9532. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  9533. break;
  9534. case 'AmbientLight':
  9535. object = new THREE.AmbientLight( data.color );
  9536. break;
  9537. case 'DirectionalLight':
  9538. object = new THREE.DirectionalLight( data.color, data.intensity );
  9539. break;
  9540. case 'PointLight':
  9541. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  9542. break;
  9543. case 'SpotLight':
  9544. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  9545. break;
  9546. case 'HemisphereLight':
  9547. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  9548. break;
  9549. case 'Mesh':
  9550. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  9551. break;
  9552. case 'LOD':
  9553. object = new THREE.LOD();
  9554. break;
  9555. case 'Line':
  9556. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  9557. break;
  9558. case 'PointCloud':
  9559. case 'Points':
  9560. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  9561. break;
  9562. case 'Sprite':
  9563. object = new THREE.Sprite( getMaterial( data.material ) );
  9564. break;
  9565. case 'Group':
  9566. object = new THREE.Group();
  9567. break;
  9568. default:
  9569. object = new THREE.Object3D();
  9570. }
  9571. object.uuid = data.uuid;
  9572. if ( data.name !== undefined ) object.name = data.name;
  9573. if ( data.matrix !== undefined ) {
  9574. matrix.fromArray( data.matrix );
  9575. matrix.decompose( object.position, object.quaternion, object.scale );
  9576. } else {
  9577. if ( data.position !== undefined ) object.position.fromArray( data.position );
  9578. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  9579. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  9580. }
  9581. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  9582. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  9583. if ( data.visible !== undefined ) object.visible = data.visible;
  9584. if ( data.userData !== undefined ) object.userData = data.userData;
  9585. if ( data.children !== undefined ) {
  9586. for ( var child in data.children ) {
  9587. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  9588. }
  9589. }
  9590. if ( data.type === 'LOD' ) {
  9591. var levels = data.levels;
  9592. for ( var l = 0; l < levels.length; l ++ ) {
  9593. var level = levels[ l ];
  9594. var child = object.getObjectByProperty( 'uuid', level.object );
  9595. if ( child !== undefined ) {
  9596. object.addLevel( child, level.distance );
  9597. }
  9598. }
  9599. }
  9600. return object;
  9601. }
  9602. }()
  9603. };
  9604. // File:src/loaders/TextureLoader.js
  9605. /**
  9606. * @author mrdoob / http://mrdoob.com/
  9607. */
  9608. THREE.TextureLoader = function ( manager ) {
  9609. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9610. };
  9611. THREE.TextureLoader.prototype = {
  9612. constructor: THREE.TextureLoader,
  9613. load: function ( url, onLoad, onProgress, onError ) {
  9614. var texture = new THREE.Texture();
  9615. var loader = new THREE.ImageLoader( this.manager );
  9616. loader.setCrossOrigin( this.crossOrigin );
  9617. loader.load( url, function ( image ) {
  9618. texture.image = image;
  9619. texture.needsUpdate = true;
  9620. if ( onLoad !== undefined ) {
  9621. onLoad( texture );
  9622. }
  9623. }, onProgress, onError );
  9624. return texture;
  9625. },
  9626. setCrossOrigin: function ( value ) {
  9627. this.crossOrigin = value;
  9628. }
  9629. };
  9630. // File:src/loaders/CubeTextureLoader.js
  9631. /**
  9632. * @author mrdoob / http://mrdoob.com/
  9633. */
  9634. THREE.CubeTextureLoader = function ( manager ) {
  9635. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9636. };
  9637. THREE.CubeTextureLoader.prototype = {
  9638. constructor: THREE.CubeTextureLoader,
  9639. load: function ( urls, onLoad, onProgress, onError ) {
  9640. var texture = new THREE.CubeTexture( [] );
  9641. var loader = new THREE.ImageLoader();
  9642. loader.setCrossOrigin( this.crossOrigin );
  9643. var loaded = 0;
  9644. function loadTexture( i ) {
  9645. loader.load( urls[ i ], function ( image ) {
  9646. texture.images[ i ] = image;
  9647. loaded ++;
  9648. if ( loaded === 6 ) {
  9649. texture.needsUpdate = true;
  9650. if ( onLoad ) onLoad( texture );
  9651. }
  9652. }, undefined, onError );
  9653. }
  9654. for ( var i = 0; i < urls.length; ++ i ) {
  9655. loadTexture( i );
  9656. }
  9657. return texture;
  9658. },
  9659. setCrossOrigin: function ( value ) {
  9660. this.crossOrigin = value;
  9661. }
  9662. };
  9663. // File:src/loaders/BinaryTextureLoader.js
  9664. /**
  9665. * @author Nikos M. / https://github.com/foo123/
  9666. *
  9667. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  9668. */
  9669. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  9670. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9671. // override in sub classes
  9672. this._parser = null;
  9673. };
  9674. THREE.BinaryTextureLoader.prototype = {
  9675. constructor: THREE.BinaryTextureLoader,
  9676. load: function ( url, onLoad, onProgress, onError ) {
  9677. var scope = this;
  9678. var texture = new THREE.DataTexture();
  9679. var loader = new THREE.XHRLoader( this.manager );
  9680. loader.setCrossOrigin( this.crossOrigin );
  9681. loader.setResponseType( 'arraybuffer' );
  9682. loader.load( url, function ( buffer ) {
  9683. var texData = scope._parser( buffer );
  9684. if ( ! texData ) return;
  9685. if ( undefined !== texData.image ) {
  9686. texture.image = texData.image;
  9687. } else if ( undefined !== texData.data ) {
  9688. texture.image.width = texData.width;
  9689. texture.image.height = texData.height;
  9690. texture.image.data = texData.data;
  9691. }
  9692. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  9693. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  9694. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  9695. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  9696. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  9697. if ( undefined !== texData.format ) {
  9698. texture.format = texData.format;
  9699. }
  9700. if ( undefined !== texData.type ) {
  9701. texture.type = texData.type;
  9702. }
  9703. if ( undefined !== texData.mipmaps ) {
  9704. texture.mipmaps = texData.mipmaps;
  9705. }
  9706. if ( 1 === texData.mipmapCount ) {
  9707. texture.minFilter = THREE.LinearFilter;
  9708. }
  9709. texture.needsUpdate = true;
  9710. if ( onLoad ) onLoad( texture, texData );
  9711. }, onProgress, onError );
  9712. return texture;
  9713. },
  9714. setCrossOrigin: function ( value ) {
  9715. this.crossOrigin = value;
  9716. }
  9717. };
  9718. // File:src/loaders/CompressedTextureLoader.js
  9719. /**
  9720. * @author mrdoob / http://mrdoob.com/
  9721. *
  9722. * Abstract Base class to block based textures loader (dds, pvr, ...)
  9723. */
  9724. THREE.CompressedTextureLoader = function ( manager ) {
  9725. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9726. // override in sub classes
  9727. this._parser = null;
  9728. };
  9729. THREE.CompressedTextureLoader.prototype = {
  9730. constructor: THREE.CompressedTextureLoader,
  9731. load: function ( url, onLoad, onProgress, onError ) {
  9732. var scope = this;
  9733. var images = [];
  9734. var texture = new THREE.CompressedTexture();
  9735. texture.image = images;
  9736. var loader = new THREE.XHRLoader( this.manager );
  9737. loader.setCrossOrigin( this.crossOrigin );
  9738. loader.setResponseType( 'arraybuffer' );
  9739. if ( Array.isArray( url ) ) {
  9740. var loaded = 0;
  9741. var loadTexture = function ( i ) {
  9742. loader.load( url[ i ], function ( buffer ) {
  9743. var texDatas = scope._parser( buffer, true );
  9744. images[ i ] = {
  9745. width: texDatas.width,
  9746. height: texDatas.height,
  9747. format: texDatas.format,
  9748. mipmaps: texDatas.mipmaps
  9749. };
  9750. loaded += 1;
  9751. if ( loaded === 6 ) {
  9752. if ( texDatas.mipmapCount === 1 )
  9753. texture.minFilter = THREE.LinearFilter;
  9754. texture.format = texDatas.format;
  9755. texture.needsUpdate = true;
  9756. if ( onLoad ) onLoad( texture );
  9757. }
  9758. }, onProgress, onError );
  9759. };
  9760. for ( var i = 0, il = url.length; i < il; ++ i ) {
  9761. loadTexture( i );
  9762. }
  9763. } else {
  9764. // compressed cubemap texture stored in a single DDS file
  9765. loader.load( url, function ( buffer ) {
  9766. var texDatas = scope._parser( buffer, true );
  9767. if ( texDatas.isCubemap ) {
  9768. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  9769. for ( var f = 0; f < faces; f ++ ) {
  9770. images[ f ] = { mipmaps : [] };
  9771. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  9772. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  9773. images[ f ].format = texDatas.format;
  9774. images[ f ].width = texDatas.width;
  9775. images[ f ].height = texDatas.height;
  9776. }
  9777. }
  9778. } else {
  9779. texture.image.width = texDatas.width;
  9780. texture.image.height = texDatas.height;
  9781. texture.mipmaps = texDatas.mipmaps;
  9782. }
  9783. if ( texDatas.mipmapCount === 1 ) {
  9784. texture.minFilter = THREE.LinearFilter;
  9785. }
  9786. texture.format = texDatas.format;
  9787. texture.needsUpdate = true;
  9788. if ( onLoad ) onLoad( texture );
  9789. }, onProgress, onError );
  9790. }
  9791. return texture;
  9792. },
  9793. setCrossOrigin: function ( value ) {
  9794. this.crossOrigin = value;
  9795. }
  9796. };
  9797. // File:src/materials/Material.js
  9798. /**
  9799. * @author mrdoob / http://mrdoob.com/
  9800. * @author alteredq / http://alteredqualia.com/
  9801. */
  9802. THREE.Material = function () {
  9803. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  9804. this.uuid = THREE.Math.generateUUID();
  9805. this.name = '';
  9806. this.type = 'Material';
  9807. this.side = THREE.FrontSide;
  9808. this.opacity = 1;
  9809. this.transparent = false;
  9810. this.blending = THREE.NormalBlending;
  9811. this.blendSrc = THREE.SrcAlphaFactor;
  9812. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  9813. this.blendEquation = THREE.AddEquation;
  9814. this.blendSrcAlpha = null;
  9815. this.blendDstAlpha = null;
  9816. this.blendEquationAlpha = null;
  9817. this.depthFunc = THREE.LessEqualDepth;
  9818. this.depthTest = true;
  9819. this.depthWrite = true;
  9820. this.colorWrite = true;
  9821. this.precision = null; // override the renderer's default precision for this material
  9822. this.polygonOffset = false;
  9823. this.polygonOffsetFactor = 0;
  9824. this.polygonOffsetUnits = 0;
  9825. this.alphaTest = 0;
  9826. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  9827. this.visible = true;
  9828. this._needsUpdate = true;
  9829. };
  9830. THREE.Material.prototype = {
  9831. constructor: THREE.Material,
  9832. get needsUpdate () {
  9833. return this._needsUpdate;
  9834. },
  9835. set needsUpdate ( value ) {
  9836. if ( value === true ) this.update();
  9837. this._needsUpdate = value;
  9838. },
  9839. setValues: function ( values ) {
  9840. if ( values === undefined ) return;
  9841. for ( var key in values ) {
  9842. var newValue = values[ key ];
  9843. if ( newValue === undefined ) {
  9844. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  9845. continue;
  9846. }
  9847. var currentValue = this[ key ];
  9848. if ( currentValue === undefined ) {
  9849. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  9850. continue;
  9851. }
  9852. if ( currentValue instanceof THREE.Color ) {
  9853. currentValue.set( newValue );
  9854. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  9855. currentValue.copy( newValue );
  9856. } else if ( key === 'overdraw' ) {
  9857. // ensure overdraw is backwards-compatible with legacy boolean type
  9858. this[ key ] = Number( newValue );
  9859. } else {
  9860. this[ key ] = newValue;
  9861. }
  9862. }
  9863. },
  9864. toJSON: function ( meta ) {
  9865. var data = {
  9866. metadata: {
  9867. version: 4.4,
  9868. type: 'Material',
  9869. generator: 'Material.toJSON'
  9870. }
  9871. };
  9872. // standard Material serialization
  9873. data.uuid = this.uuid;
  9874. data.type = this.type;
  9875. if ( this.name !== '' ) data.name = this.name;
  9876. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  9877. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  9878. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  9879. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  9880. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  9881. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  9882. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  9883. if ( this.bumpMap instanceof THREE.Texture ) {
  9884. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  9885. data.bumpScale = this.bumpScale;
  9886. }
  9887. if ( this.normalMap instanceof THREE.Texture ) {
  9888. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  9889. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  9890. }
  9891. if ( this.displacementMap instanceof THREE.Texture ) {
  9892. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  9893. data.displacementScale = this.displacementScale;
  9894. data.displacementBias = this.displacementBias;
  9895. }
  9896. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  9897. if ( this.envMap instanceof THREE.Texture ) {
  9898. data.envMap = this.envMap.toJSON( meta ).uuid;
  9899. data.reflectivity = this.reflectivity; // Scale behind envMap
  9900. }
  9901. if ( this.size !== undefined ) data.size = this.size;
  9902. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  9903. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  9904. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  9905. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  9906. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  9907. if ( this.opacity < 1 ) data.opacity = this.opacity;
  9908. if ( this.transparent === true ) data.transparent = this.transparent;
  9909. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  9910. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  9911. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  9912. return data;
  9913. },
  9914. clone: function () {
  9915. return new this.constructor().copy( this );
  9916. },
  9917. copy: function ( source ) {
  9918. this.name = source.name;
  9919. this.side = source.side;
  9920. this.opacity = source.opacity;
  9921. this.transparent = source.transparent;
  9922. this.blending = source.blending;
  9923. this.blendSrc = source.blendSrc;
  9924. this.blendDst = source.blendDst;
  9925. this.blendEquation = source.blendEquation;
  9926. this.blendSrcAlpha = source.blendSrcAlpha;
  9927. this.blendDstAlpha = source.blendDstAlpha;
  9928. this.blendEquationAlpha = source.blendEquationAlpha;
  9929. this.depthFunc = source.depthFunc;
  9930. this.depthTest = source.depthTest;
  9931. this.depthWrite = source.depthWrite;
  9932. this.precision = source.precision;
  9933. this.polygonOffset = source.polygonOffset;
  9934. this.polygonOffsetFactor = source.polygonOffsetFactor;
  9935. this.polygonOffsetUnits = source.polygonOffsetUnits;
  9936. this.alphaTest = source.alphaTest;
  9937. this.overdraw = source.overdraw;
  9938. this.visible = source.visible;
  9939. return this;
  9940. },
  9941. update: function () {
  9942. this.dispatchEvent( { type: 'update' } );
  9943. },
  9944. dispose: function () {
  9945. this.dispatchEvent( { type: 'dispose' } );
  9946. },
  9947. // Deprecated
  9948. get wrapAround () {
  9949. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  9950. },
  9951. set wrapAround ( boolean ) {
  9952. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  9953. },
  9954. get wrapRGB () {
  9955. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  9956. return new THREE.Color();
  9957. }
  9958. };
  9959. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  9960. THREE.MaterialIdCount = 0;
  9961. // File:src/materials/LineBasicMaterial.js
  9962. /**
  9963. * @author mrdoob / http://mrdoob.com/
  9964. * @author alteredq / http://alteredqualia.com/
  9965. *
  9966. * parameters = {
  9967. * color: <hex>,
  9968. * opacity: <float>,
  9969. *
  9970. * blending: THREE.NormalBlending,
  9971. * depthTest: <bool>,
  9972. * depthWrite: <bool>,
  9973. *
  9974. * linewidth: <float>,
  9975. * linecap: "round",
  9976. * linejoin: "round",
  9977. *
  9978. * vertexColors: <bool>
  9979. *
  9980. * fog: <bool>
  9981. * }
  9982. */
  9983. THREE.LineBasicMaterial = function ( parameters ) {
  9984. THREE.Material.call( this );
  9985. this.type = 'LineBasicMaterial';
  9986. this.color = new THREE.Color( 0xffffff );
  9987. this.linewidth = 1;
  9988. this.linecap = 'round';
  9989. this.linejoin = 'round';
  9990. this.vertexColors = THREE.NoColors;
  9991. this.fog = true;
  9992. this.setValues( parameters );
  9993. };
  9994. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  9995. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  9996. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  9997. THREE.Material.prototype.copy.call( this, source );
  9998. this.color.copy( source.color );
  9999. this.linewidth = source.linewidth;
  10000. this.linecap = source.linecap;
  10001. this.linejoin = source.linejoin;
  10002. this.vertexColors = source.vertexColors;
  10003. this.fog = source.fog;
  10004. return this;
  10005. };
  10006. // File:src/materials/LineDashedMaterial.js
  10007. /**
  10008. * @author alteredq / http://alteredqualia.com/
  10009. *
  10010. * parameters = {
  10011. * color: <hex>,
  10012. * opacity: <float>,
  10013. *
  10014. * blending: THREE.NormalBlending,
  10015. * depthTest: <bool>,
  10016. * depthWrite: <bool>,
  10017. *
  10018. * linewidth: <float>,
  10019. *
  10020. * scale: <float>,
  10021. * dashSize: <float>,
  10022. * gapSize: <float>,
  10023. *
  10024. * vertexColors: <bool>
  10025. *
  10026. * fog: <bool>
  10027. * }
  10028. */
  10029. THREE.LineDashedMaterial = function ( parameters ) {
  10030. THREE.Material.call( this );
  10031. this.type = 'LineDashedMaterial';
  10032. this.color = new THREE.Color( 0xffffff );
  10033. this.linewidth = 1;
  10034. this.scale = 1;
  10035. this.dashSize = 3;
  10036. this.gapSize = 1;
  10037. this.vertexColors = false;
  10038. this.fog = true;
  10039. this.setValues( parameters );
  10040. };
  10041. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  10042. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  10043. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  10044. THREE.Material.prototype.copy.call( this, source );
  10045. this.color.copy( source.color );
  10046. this.linewidth = source.linewidth;
  10047. this.scale = source.scale;
  10048. this.dashSize = source.dashSize;
  10049. this.gapSize = source.gapSize;
  10050. this.vertexColors = source.vertexColors;
  10051. this.fog = source.fog;
  10052. return this;
  10053. };
  10054. // File:src/materials/MeshBasicMaterial.js
  10055. /**
  10056. * @author mrdoob / http://mrdoob.com/
  10057. * @author alteredq / http://alteredqualia.com/
  10058. *
  10059. * parameters = {
  10060. * color: <hex>,
  10061. * opacity: <float>,
  10062. * map: new THREE.Texture( <Image> ),
  10063. *
  10064. * aoMap: new THREE.Texture( <Image> ),
  10065. * aoMapIntensity: <float>
  10066. *
  10067. * specularMap: new THREE.Texture( <Image> ),
  10068. *
  10069. * alphaMap: new THREE.Texture( <Image> ),
  10070. *
  10071. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10072. * combine: THREE.Multiply,
  10073. * reflectivity: <float>,
  10074. * refractionRatio: <float>,
  10075. *
  10076. * shading: THREE.SmoothShading,
  10077. * blending: THREE.NormalBlending,
  10078. * depthTest: <bool>,
  10079. * depthWrite: <bool>,
  10080. *
  10081. * wireframe: <boolean>,
  10082. * wireframeLinewidth: <float>,
  10083. *
  10084. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10085. *
  10086. * skinning: <bool>,
  10087. * morphTargets: <bool>,
  10088. *
  10089. * fog: <bool>
  10090. * }
  10091. */
  10092. THREE.MeshBasicMaterial = function ( parameters ) {
  10093. THREE.Material.call( this );
  10094. this.type = 'MeshBasicMaterial';
  10095. this.color = new THREE.Color( 0xffffff ); // emissive
  10096. this.map = null;
  10097. this.aoMap = null;
  10098. this.aoMapIntensity = 1.0;
  10099. this.specularMap = null;
  10100. this.alphaMap = null;
  10101. this.envMap = null;
  10102. this.combine = THREE.MultiplyOperation;
  10103. this.reflectivity = 1;
  10104. this.refractionRatio = 0.98;
  10105. this.fog = true;
  10106. this.shading = THREE.SmoothShading;
  10107. this.wireframe = false;
  10108. this.wireframeLinewidth = 1;
  10109. this.wireframeLinecap = 'round';
  10110. this.wireframeLinejoin = 'round';
  10111. this.vertexColors = THREE.NoColors;
  10112. this.skinning = false;
  10113. this.morphTargets = false;
  10114. this.setValues( parameters );
  10115. };
  10116. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  10117. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  10118. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  10119. THREE.Material.prototype.copy.call( this, source );
  10120. this.color.copy( source.color );
  10121. this.map = source.map;
  10122. this.aoMap = source.aoMap;
  10123. this.aoMapIntensity = source.aoMapIntensity;
  10124. this.specularMap = source.specularMap;
  10125. this.alphaMap = source.alphaMap;
  10126. this.envMap = source.envMap;
  10127. this.combine = source.combine;
  10128. this.reflectivity = source.reflectivity;
  10129. this.refractionRatio = source.refractionRatio;
  10130. this.fog = source.fog;
  10131. this.shading = source.shading;
  10132. this.wireframe = source.wireframe;
  10133. this.wireframeLinewidth = source.wireframeLinewidth;
  10134. this.wireframeLinecap = source.wireframeLinecap;
  10135. this.wireframeLinejoin = source.wireframeLinejoin;
  10136. this.vertexColors = source.vertexColors;
  10137. this.skinning = source.skinning;
  10138. this.morphTargets = source.morphTargets;
  10139. return this;
  10140. };
  10141. // File:src/materials/MeshLambertMaterial.js
  10142. /**
  10143. * @author mrdoob / http://mrdoob.com/
  10144. * @author alteredq / http://alteredqualia.com/
  10145. *
  10146. * parameters = {
  10147. * color: <hex>,
  10148. * emissive: <hex>,
  10149. * opacity: <float>,
  10150. *
  10151. * map: new THREE.Texture( <Image> ),
  10152. *
  10153. * specularMap: new THREE.Texture( <Image> ),
  10154. *
  10155. * alphaMap: new THREE.Texture( <Image> ),
  10156. *
  10157. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10158. * combine: THREE.Multiply,
  10159. * reflectivity: <float>,
  10160. * refractionRatio: <float>,
  10161. *
  10162. * blending: THREE.NormalBlending,
  10163. * depthTest: <bool>,
  10164. * depthWrite: <bool>,
  10165. *
  10166. * wireframe: <boolean>,
  10167. * wireframeLinewidth: <float>,
  10168. *
  10169. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10170. *
  10171. * skinning: <bool>,
  10172. * morphTargets: <bool>,
  10173. * morphNormals: <bool>,
  10174. *
  10175. * fog: <bool>
  10176. * }
  10177. */
  10178. THREE.MeshLambertMaterial = function ( parameters ) {
  10179. THREE.Material.call( this );
  10180. this.type = 'MeshLambertMaterial';
  10181. this.color = new THREE.Color( 0xffffff ); // diffuse
  10182. this.emissive = new THREE.Color( 0x000000 );
  10183. this.map = null;
  10184. this.specularMap = null;
  10185. this.alphaMap = null;
  10186. this.envMap = null;
  10187. this.combine = THREE.MultiplyOperation;
  10188. this.reflectivity = 1;
  10189. this.refractionRatio = 0.98;
  10190. this.fog = true;
  10191. this.wireframe = false;
  10192. this.wireframeLinewidth = 1;
  10193. this.wireframeLinecap = 'round';
  10194. this.wireframeLinejoin = 'round';
  10195. this.vertexColors = THREE.NoColors;
  10196. this.skinning = false;
  10197. this.morphTargets = false;
  10198. this.morphNormals = false;
  10199. this.setValues( parameters );
  10200. };
  10201. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  10202. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  10203. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  10204. THREE.Material.prototype.copy.call( this, source );
  10205. this.color.copy( source.color );
  10206. this.emissive.copy( source.emissive );
  10207. this.map = source.map;
  10208. this.specularMap = source.specularMap;
  10209. this.alphaMap = source.alphaMap;
  10210. this.envMap = source.envMap;
  10211. this.combine = source.combine;
  10212. this.reflectivity = source.reflectivity;
  10213. this.refractionRatio = source.refractionRatio;
  10214. this.fog = source.fog;
  10215. this.wireframe = source.wireframe;
  10216. this.wireframeLinewidth = source.wireframeLinewidth;
  10217. this.wireframeLinecap = source.wireframeLinecap;
  10218. this.wireframeLinejoin = source.wireframeLinejoin;
  10219. this.vertexColors = source.vertexColors;
  10220. this.skinning = source.skinning;
  10221. this.morphTargets = source.morphTargets;
  10222. this.morphNormals = source.morphNormals;
  10223. return this;
  10224. };
  10225. // File:src/materials/MeshPhongMaterial.js
  10226. /**
  10227. * @author mrdoob / http://mrdoob.com/
  10228. * @author alteredq / http://alteredqualia.com/
  10229. *
  10230. * parameters = {
  10231. * color: <hex>,
  10232. * emissive: <hex>,
  10233. * specular: <hex>,
  10234. * shininess: <float>,
  10235. * opacity: <float>,
  10236. *
  10237. * map: new THREE.Texture( <Image> ),
  10238. *
  10239. * lightMap: new THREE.Texture( <Image> ),
  10240. * lightMapIntensity: <float>
  10241. *
  10242. * aoMap: new THREE.Texture( <Image> ),
  10243. * aoMapIntensity: <float>
  10244. *
  10245. * emissiveMap: new THREE.Texture( <Image> ),
  10246. *
  10247. * bumpMap: new THREE.Texture( <Image> ),
  10248. * bumpScale: <float>,
  10249. *
  10250. * normalMap: new THREE.Texture( <Image> ),
  10251. * normalScale: <Vector2>,
  10252. *
  10253. * displacementMap: new THREE.Texture( <Image> ),
  10254. * displacementScale: <float>,
  10255. * displacementBias: <float>,
  10256. *
  10257. * specularMap: new THREE.Texture( <Image> ),
  10258. *
  10259. * alphaMap: new THREE.Texture( <Image> ),
  10260. *
  10261. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10262. * combine: THREE.Multiply,
  10263. * reflectivity: <float>,
  10264. * refractionRatio: <float>,
  10265. *
  10266. * shading: THREE.SmoothShading,
  10267. * blending: THREE.NormalBlending,
  10268. * depthTest: <bool>,
  10269. * depthWrite: <bool>,
  10270. *
  10271. * wireframe: <boolean>,
  10272. * wireframeLinewidth: <float>,
  10273. *
  10274. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10275. *
  10276. * skinning: <bool>,
  10277. * morphTargets: <bool>,
  10278. * morphNormals: <bool>,
  10279. *
  10280. * fog: <bool>
  10281. * }
  10282. */
  10283. THREE.MeshPhongMaterial = function ( parameters ) {
  10284. THREE.Material.call( this );
  10285. this.type = 'MeshPhongMaterial';
  10286. this.color = new THREE.Color( 0xffffff ); // diffuse
  10287. this.emissive = new THREE.Color( 0x000000 );
  10288. this.specular = new THREE.Color( 0x111111 );
  10289. this.shininess = 30;
  10290. this.metal = false;
  10291. this.map = null;
  10292. this.lightMap = null;
  10293. this.lightMapIntensity = 1.0;
  10294. this.aoMap = null;
  10295. this.aoMapIntensity = 1.0;
  10296. this.emissiveMap = null;
  10297. this.bumpMap = null;
  10298. this.bumpScale = 1;
  10299. this.normalMap = null;
  10300. this.normalScale = new THREE.Vector2( 1, 1 );
  10301. this.displacementMap = null;
  10302. this.displacementScale = 1;
  10303. this.displacementBias = 0;
  10304. this.specularMap = null;
  10305. this.alphaMap = null;
  10306. this.envMap = null;
  10307. this.combine = THREE.MultiplyOperation;
  10308. this.reflectivity = 1;
  10309. this.refractionRatio = 0.98;
  10310. this.fog = true;
  10311. this.shading = THREE.SmoothShading;
  10312. this.wireframe = false;
  10313. this.wireframeLinewidth = 1;
  10314. this.wireframeLinecap = 'round';
  10315. this.wireframeLinejoin = 'round';
  10316. this.vertexColors = THREE.NoColors;
  10317. this.skinning = false;
  10318. this.morphTargets = false;
  10319. this.morphNormals = false;
  10320. this.setValues( parameters );
  10321. };
  10322. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  10323. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  10324. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  10325. THREE.Material.prototype.copy.call( this, source );
  10326. this.color.copy( source.color );
  10327. this.emissive.copy( source.emissive );
  10328. this.specular.copy( source.specular );
  10329. this.shininess = source.shininess;
  10330. this.metal = source.metal;
  10331. this.map = source.map;
  10332. this.lightMap = source.lightMap;
  10333. this.lightMapIntensity = source.lightMapIntensity;
  10334. this.aoMap = source.aoMap;
  10335. this.aoMapIntensity = source.aoMapIntensity;
  10336. this.emissiveMap = source.emissiveMap;
  10337. this.bumpMap = source.bumpMap;
  10338. this.bumpScale = source.bumpScale;
  10339. this.normalMap = source.normalMap;
  10340. this.normalScale.copy( source.normalScale );
  10341. this.displacementMap = source.displacementMap;
  10342. this.displacementScale = source.displacementScale;
  10343. this.displacementBias = source.displacementBias;
  10344. this.specularMap = source.specularMap;
  10345. this.alphaMap = source.alphaMap;
  10346. this.envMap = source.envMap;
  10347. this.combine = source.combine;
  10348. this.reflectivity = source.reflectivity;
  10349. this.refractionRatio = source.refractionRatio;
  10350. this.fog = source.fog;
  10351. this.shading = source.shading;
  10352. this.wireframe = source.wireframe;
  10353. this.wireframeLinewidth = source.wireframeLinewidth;
  10354. this.wireframeLinecap = source.wireframeLinecap;
  10355. this.wireframeLinejoin = source.wireframeLinejoin;
  10356. this.vertexColors = source.vertexColors;
  10357. this.skinning = source.skinning;
  10358. this.morphTargets = source.morphTargets;
  10359. this.morphNormals = source.morphNormals;
  10360. return this;
  10361. };
  10362. // File:src/materials/MeshDepthMaterial.js
  10363. /**
  10364. * @author mrdoob / http://mrdoob.com/
  10365. * @author alteredq / http://alteredqualia.com/
  10366. *
  10367. * parameters = {
  10368. * opacity: <float>,
  10369. *
  10370. * blending: THREE.NormalBlending,
  10371. * depthTest: <bool>,
  10372. * depthWrite: <bool>,
  10373. *
  10374. * wireframe: <boolean>,
  10375. * wireframeLinewidth: <float>
  10376. * }
  10377. */
  10378. THREE.MeshDepthMaterial = function ( parameters ) {
  10379. THREE.Material.call( this );
  10380. this.type = 'MeshDepthMaterial';
  10381. this.morphTargets = false;
  10382. this.wireframe = false;
  10383. this.wireframeLinewidth = 1;
  10384. this.setValues( parameters );
  10385. };
  10386. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  10387. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  10388. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  10389. THREE.Material.prototype.copy.call( this, source );
  10390. this.wireframe = source.wireframe;
  10391. this.wireframeLinewidth = source.wireframeLinewidth;
  10392. return this;
  10393. };
  10394. // File:src/materials/MeshNormalMaterial.js
  10395. /**
  10396. * @author mrdoob / http://mrdoob.com/
  10397. *
  10398. * parameters = {
  10399. * opacity: <float>,
  10400. *
  10401. * shading: THREE.FlatShading,
  10402. * blending: THREE.NormalBlending,
  10403. * depthTest: <bool>,
  10404. * depthWrite: <bool>,
  10405. *
  10406. * wireframe: <boolean>,
  10407. * wireframeLinewidth: <float>
  10408. * }
  10409. */
  10410. THREE.MeshNormalMaterial = function ( parameters ) {
  10411. THREE.Material.call( this, parameters );
  10412. this.type = 'MeshNormalMaterial';
  10413. this.wireframe = false;
  10414. this.wireframeLinewidth = 1;
  10415. this.morphTargets = false;
  10416. this.setValues( parameters );
  10417. };
  10418. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  10419. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  10420. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  10421. THREE.Material.prototype.copy.call( this, source );
  10422. this.wireframe = source.wireframe;
  10423. this.wireframeLinewidth = source.wireframeLinewidth;
  10424. return this;
  10425. };
  10426. // File:src/materials/MultiMaterial.js
  10427. /**
  10428. * @author mrdoob / http://mrdoob.com/
  10429. */
  10430. THREE.MultiMaterial = function ( materials ) {
  10431. this.uuid = THREE.Math.generateUUID();
  10432. this.type = 'MultiMaterial';
  10433. this.materials = materials instanceof Array ? materials : [];
  10434. this.visible = true;
  10435. };
  10436. THREE.MultiMaterial.prototype = {
  10437. constructor: THREE.MultiMaterial,
  10438. toJSON: function () {
  10439. var output = {
  10440. metadata: {
  10441. version: 4.2,
  10442. type: 'material',
  10443. generator: 'MaterialExporter'
  10444. },
  10445. uuid: this.uuid,
  10446. type: this.type,
  10447. materials: []
  10448. };
  10449. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  10450. output.materials.push( this.materials[ i ].toJSON() );
  10451. }
  10452. output.visible = this.visible;
  10453. return output;
  10454. },
  10455. clone: function () {
  10456. var material = new this.constructor();
  10457. for ( var i = 0; i < this.materials.length; i ++ ) {
  10458. material.materials.push( this.materials[ i ].clone() );
  10459. }
  10460. material.visible = this.visible;
  10461. return material;
  10462. }
  10463. };
  10464. // backwards compatibility
  10465. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  10466. // File:src/materials/PointsMaterial.js
  10467. /**
  10468. * @author mrdoob / http://mrdoob.com/
  10469. * @author alteredq / http://alteredqualia.com/
  10470. *
  10471. * parameters = {
  10472. * color: <hex>,
  10473. * opacity: <float>,
  10474. * map: new THREE.Texture( <Image> ),
  10475. *
  10476. * size: <float>,
  10477. * sizeAttenuation: <bool>,
  10478. *
  10479. * blending: THREE.NormalBlending,
  10480. * depthTest: <bool>,
  10481. * depthWrite: <bool>,
  10482. *
  10483. * vertexColors: <bool>,
  10484. *
  10485. * fog: <bool>
  10486. * }
  10487. */
  10488. THREE.PointsMaterial = function ( parameters ) {
  10489. THREE.Material.call( this );
  10490. this.type = 'PointsMaterial';
  10491. this.color = new THREE.Color( 0xffffff );
  10492. this.map = null;
  10493. this.size = 1;
  10494. this.sizeAttenuation = true;
  10495. this.vertexColors = THREE.NoColors;
  10496. this.fog = true;
  10497. this.setValues( parameters );
  10498. };
  10499. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  10500. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  10501. THREE.PointsMaterial.prototype.copy = function ( source ) {
  10502. THREE.Material.prototype.copy.call( this, source );
  10503. this.color.copy( source.color );
  10504. this.map = source.map;
  10505. this.size = source.size;
  10506. this.sizeAttenuation = source.sizeAttenuation;
  10507. this.vertexColors = source.vertexColors;
  10508. this.fog = source.fog;
  10509. return this;
  10510. };
  10511. // backwards compatibility
  10512. THREE.PointCloudMaterial = function ( parameters ) {
  10513. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  10514. return new THREE.PointsMaterial( parameters );
  10515. };
  10516. THREE.ParticleBasicMaterial = function ( parameters ) {
  10517. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  10518. return new THREE.PointsMaterial( parameters );
  10519. };
  10520. THREE.ParticleSystemMaterial = function ( parameters ) {
  10521. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  10522. return new THREE.PointsMaterial( parameters );
  10523. };
  10524. // File:src/materials/ShaderMaterial.js
  10525. /**
  10526. * @author alteredq / http://alteredqualia.com/
  10527. *
  10528. * parameters = {
  10529. * defines: { "label" : "value" },
  10530. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  10531. *
  10532. * fragmentShader: <string>,
  10533. * vertexShader: <string>,
  10534. *
  10535. * shading: THREE.SmoothShading,
  10536. * blending: THREE.NormalBlending,
  10537. * depthTest: <bool>,
  10538. * depthWrite: <bool>,
  10539. *
  10540. * wireframe: <boolean>,
  10541. * wireframeLinewidth: <float>,
  10542. *
  10543. * lights: <bool>,
  10544. *
  10545. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10546. *
  10547. * skinning: <bool>,
  10548. * morphTargets: <bool>,
  10549. * morphNormals: <bool>,
  10550. *
  10551. * fog: <bool>
  10552. * }
  10553. */
  10554. THREE.ShaderMaterial = function ( parameters ) {
  10555. THREE.Material.call( this );
  10556. this.type = 'ShaderMaterial';
  10557. this.defines = {};
  10558. this.uniforms = {};
  10559. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  10560. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  10561. this.shading = THREE.SmoothShading;
  10562. this.linewidth = 1;
  10563. this.wireframe = false;
  10564. this.wireframeLinewidth = 1;
  10565. this.fog = false; // set to use scene fog
  10566. this.lights = false; // set to use scene lights
  10567. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  10568. this.skinning = false; // set to use skinning attribute streams
  10569. this.morphTargets = false; // set to use morph targets
  10570. this.morphNormals = false; // set to use morph normals
  10571. this.derivatives = false; // set to use derivatives
  10572. // When rendered geometry doesn't include these attributes but the material does,
  10573. // use these default values in WebGL. This avoids errors when buffer data is missing.
  10574. this.defaultAttributeValues = {
  10575. 'color': [ 1, 1, 1 ],
  10576. 'uv': [ 0, 0 ],
  10577. 'uv2': [ 0, 0 ]
  10578. };
  10579. this.index0AttributeName = undefined;
  10580. if ( parameters !== undefined ) {
  10581. if ( parameters.attributes !== undefined ) {
  10582. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  10583. }
  10584. this.setValues( parameters );
  10585. }
  10586. };
  10587. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  10588. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  10589. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  10590. THREE.Material.prototype.copy.call( this, source );
  10591. this.fragmentShader = source.fragmentShader;
  10592. this.vertexShader = source.vertexShader;
  10593. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  10594. this.attributes = source.attributes;
  10595. this.defines = source.defines;
  10596. this.shading = source.shading;
  10597. this.wireframe = source.wireframe;
  10598. this.wireframeLinewidth = source.wireframeLinewidth;
  10599. this.fog = source.fog;
  10600. this.lights = source.lights;
  10601. this.vertexColors = source.vertexColors;
  10602. this.skinning = source.skinning;
  10603. this.morphTargets = source.morphTargets;
  10604. this.morphNormals = source.morphNormals;
  10605. this.derivatives = source.derivatives;
  10606. return this;
  10607. };
  10608. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  10609. var data = THREE.Material.prototype.toJSON.call( this, meta );
  10610. data.uniforms = this.uniforms;
  10611. data.attributes = this.attributes;
  10612. data.vertexShader = this.vertexShader;
  10613. data.fragmentShader = this.fragmentShader;
  10614. return data;
  10615. };
  10616. // File:src/materials/RawShaderMaterial.js
  10617. /**
  10618. * @author mrdoob / http://mrdoob.com/
  10619. */
  10620. THREE.RawShaderMaterial = function ( parameters ) {
  10621. THREE.ShaderMaterial.call( this, parameters );
  10622. this.type = 'RawShaderMaterial';
  10623. };
  10624. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  10625. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  10626. // File:src/materials/SpriteMaterial.js
  10627. /**
  10628. * @author alteredq / http://alteredqualia.com/
  10629. *
  10630. * parameters = {
  10631. * color: <hex>,
  10632. * opacity: <float>,
  10633. * map: new THREE.Texture( <Image> ),
  10634. *
  10635. * blending: THREE.NormalBlending,
  10636. * depthTest: <bool>,
  10637. * depthWrite: <bool>,
  10638. *
  10639. * uvOffset: new THREE.Vector2(),
  10640. * uvScale: new THREE.Vector2(),
  10641. *
  10642. * fog: <bool>
  10643. * }
  10644. */
  10645. THREE.SpriteMaterial = function ( parameters ) {
  10646. THREE.Material.call( this );
  10647. this.type = 'SpriteMaterial';
  10648. this.color = new THREE.Color( 0xffffff );
  10649. this.map = null;
  10650. this.rotation = 0;
  10651. this.fog = false;
  10652. // set parameters
  10653. this.setValues( parameters );
  10654. };
  10655. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  10656. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  10657. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  10658. THREE.Material.prototype.copy.call( this, source );
  10659. this.color.copy( source.color );
  10660. this.map = source.map;
  10661. this.rotation = source.rotation;
  10662. this.fog = source.fog;
  10663. return this;
  10664. };
  10665. // File:src/textures/Texture.js
  10666. /**
  10667. * @author mrdoob / http://mrdoob.com/
  10668. * @author alteredq / http://alteredqualia.com/
  10669. * @author szimek / https://github.com/szimek/
  10670. */
  10671. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10672. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  10673. this.uuid = THREE.Math.generateUUID();
  10674. this.name = '';
  10675. this.sourceFile = '';
  10676. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  10677. this.mipmaps = [];
  10678. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  10679. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  10680. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  10681. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  10682. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  10683. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  10684. this.format = format !== undefined ? format : THREE.RGBAFormat;
  10685. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  10686. this.offset = new THREE.Vector2( 0, 0 );
  10687. this.repeat = new THREE.Vector2( 1, 1 );
  10688. this.generateMipmaps = true;
  10689. this.premultiplyAlpha = false;
  10690. this.flipY = true;
  10691. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  10692. this.version = 0;
  10693. this.onUpdate = null;
  10694. };
  10695. THREE.Texture.DEFAULT_IMAGE = undefined;
  10696. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  10697. THREE.Texture.prototype = {
  10698. constructor: THREE.Texture,
  10699. set needsUpdate ( value ) {
  10700. if ( value === true ) this.version ++;
  10701. },
  10702. clone: function () {
  10703. return new this.constructor().copy( this );
  10704. },
  10705. copy: function ( source ) {
  10706. this.image = source.image;
  10707. this.mipmaps = source.mipmaps.slice( 0 );
  10708. this.mapping = source.mapping;
  10709. this.wrapS = source.wrapS;
  10710. this.wrapT = source.wrapT;
  10711. this.magFilter = source.magFilter;
  10712. this.minFilter = source.minFilter;
  10713. this.anisotropy = source.anisotropy;
  10714. this.format = source.format;
  10715. this.type = source.type;
  10716. this.offset.copy( source.offset );
  10717. this.repeat.copy( source.repeat );
  10718. this.generateMipmaps = source.generateMipmaps;
  10719. this.premultiplyAlpha = source.premultiplyAlpha;
  10720. this.flipY = source.flipY;
  10721. this.unpackAlignment = source.unpackAlignment;
  10722. return this;
  10723. },
  10724. toJSON: function ( meta ) {
  10725. if ( meta.textures[ this.uuid ] !== undefined ) {
  10726. return meta.textures[ this.uuid ];
  10727. }
  10728. function getDataURL( image ) {
  10729. var canvas;
  10730. if ( image.toDataURL !== undefined ) {
  10731. canvas = image;
  10732. } else {
  10733. canvas = document.createElement( 'canvas' );
  10734. canvas.width = image.width;
  10735. canvas.height = image.height;
  10736. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  10737. }
  10738. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  10739. return canvas.toDataURL( 'image/jpeg', 0.6 );
  10740. } else {
  10741. return canvas.toDataURL( 'image/png' );
  10742. }
  10743. }
  10744. var output = {
  10745. metadata: {
  10746. version: 4.4,
  10747. type: 'Texture',
  10748. generator: 'Texture.toJSON'
  10749. },
  10750. uuid: this.uuid,
  10751. name: this.name,
  10752. mapping: this.mapping,
  10753. repeat: [ this.repeat.x, this.repeat.y ],
  10754. offset: [ this.offset.x, this.offset.y ],
  10755. wrap: [ this.wrapS, this.wrapT ],
  10756. minFilter: this.minFilter,
  10757. magFilter: this.magFilter,
  10758. anisotropy: this.anisotropy
  10759. };
  10760. if ( this.image !== undefined ) {
  10761. // TODO: Move to THREE.Image
  10762. var image = this.image;
  10763. if ( image.uuid === undefined ) {
  10764. image.uuid = THREE.Math.generateUUID(); // UGH
  10765. }
  10766. if ( meta.images[ image.uuid ] === undefined ) {
  10767. meta.images[ image.uuid ] = {
  10768. uuid: image.uuid,
  10769. url: getDataURL( image )
  10770. };
  10771. }
  10772. output.image = image.uuid;
  10773. }
  10774. meta.textures[ this.uuid ] = output;
  10775. return output;
  10776. },
  10777. dispose: function () {
  10778. this.dispatchEvent( { type: 'dispose' } );
  10779. },
  10780. transformUv: function ( uv ) {
  10781. if ( this.mapping !== THREE.UVMapping ) return;
  10782. uv.multiply( this.repeat );
  10783. uv.add( this.offset );
  10784. if ( uv.x < 0 || uv.x > 1 ) {
  10785. switch ( this.wrapS ) {
  10786. case THREE.RepeatWrapping:
  10787. uv.x = uv.x - Math.floor( uv.x );
  10788. break;
  10789. case THREE.ClampToEdgeWrapping:
  10790. uv.x = uv.x < 0 ? 0 : 1;
  10791. break;
  10792. case THREE.MirroredRepeatWrapping:
  10793. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  10794. uv.x = Math.ceil( uv.x ) - uv.x;
  10795. } else {
  10796. uv.x = uv.x - Math.floor( uv.x );
  10797. }
  10798. break;
  10799. }
  10800. }
  10801. if ( uv.y < 0 || uv.y > 1 ) {
  10802. switch ( this.wrapT ) {
  10803. case THREE.RepeatWrapping:
  10804. uv.y = uv.y - Math.floor( uv.y );
  10805. break;
  10806. case THREE.ClampToEdgeWrapping:
  10807. uv.y = uv.y < 0 ? 0 : 1;
  10808. break;
  10809. case THREE.MirroredRepeatWrapping:
  10810. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  10811. uv.y = Math.ceil( uv.y ) - uv.y;
  10812. } else {
  10813. uv.y = uv.y - Math.floor( uv.y );
  10814. }
  10815. break;
  10816. }
  10817. }
  10818. if ( this.flipY ) {
  10819. uv.y = 1 - uv.y;
  10820. }
  10821. }
  10822. };
  10823. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  10824. THREE.TextureIdCount = 0;
  10825. // File:src/textures/CanvasTexture.js
  10826. /**
  10827. * @author mrdoob / http://mrdoob.com/
  10828. */
  10829. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10830. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10831. this.needsUpdate = true;
  10832. };
  10833. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  10834. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  10835. // File:src/textures/CubeTexture.js
  10836. /**
  10837. * @author mrdoob / http://mrdoob.com/
  10838. */
  10839. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10840. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  10841. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10842. this.images = images;
  10843. this.flipY = false;
  10844. };
  10845. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  10846. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  10847. THREE.CubeTexture.prototype.copy = function ( source ) {
  10848. THREE.Texture.prototype.copy.call( this, source );
  10849. this.images = source.images;
  10850. return this;
  10851. };
  10852. // File:src/textures/CompressedTexture.js
  10853. /**
  10854. * @author alteredq / http://alteredqualia.com/
  10855. */
  10856. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10857. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10858. this.image = { width: width, height: height };
  10859. this.mipmaps = mipmaps;
  10860. // no flipping for cube textures
  10861. // (also flipping doesn't work for compressed textures )
  10862. this.flipY = false;
  10863. // can't generate mipmaps for compressed textures
  10864. // mips must be embedded in DDS files
  10865. this.generateMipmaps = false;
  10866. };
  10867. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  10868. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  10869. // File:src/textures/DataTexture.js
  10870. /**
  10871. * @author alteredq / http://alteredqualia.com/
  10872. */
  10873. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10874. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10875. this.image = { data: data, width: width, height: height };
  10876. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  10877. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  10878. this.flipY = false;
  10879. this.generateMipmaps = false;
  10880. };
  10881. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  10882. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  10883. // File:src/textures/VideoTexture.js
  10884. /**
  10885. * @author mrdoob / http://mrdoob.com/
  10886. */
  10887. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10888. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10889. this.generateMipmaps = false;
  10890. var scope = this;
  10891. function update() {
  10892. requestAnimationFrame( update );
  10893. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  10894. scope.needsUpdate = true;
  10895. }
  10896. }
  10897. update();
  10898. };
  10899. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  10900. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  10901. // File:src/objects/Group.js
  10902. /**
  10903. * @author mrdoob / http://mrdoob.com/
  10904. */
  10905. THREE.Group = function () {
  10906. THREE.Object3D.call( this );
  10907. this.type = 'Group';
  10908. };
  10909. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  10910. THREE.Group.prototype.constructor = THREE.Group;
  10911. // File:src/objects/Points.js
  10912. /**
  10913. * @author alteredq / http://alteredqualia.com/
  10914. */
  10915. THREE.Points = function ( geometry, material ) {
  10916. THREE.Object3D.call( this );
  10917. this.type = 'Points';
  10918. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  10919. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  10920. };
  10921. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  10922. THREE.Points.prototype.constructor = THREE.Points;
  10923. THREE.Points.prototype.raycast = ( function () {
  10924. var inverseMatrix = new THREE.Matrix4();
  10925. var ray = new THREE.Ray();
  10926. return function raycast( raycaster, intersects ) {
  10927. var object = this;
  10928. var geometry = object.geometry;
  10929. var threshold = raycaster.params.Points.threshold;
  10930. inverseMatrix.getInverse( this.matrixWorld );
  10931. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10932. if ( geometry.boundingBox !== null ) {
  10933. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  10934. return;
  10935. }
  10936. }
  10937. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  10938. var localThresholdSq = localThreshold * localThreshold;
  10939. var position = new THREE.Vector3();
  10940. function testPoint( point, index ) {
  10941. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  10942. if ( rayPointDistanceSq < localThresholdSq ) {
  10943. var intersectPoint = ray.closestPointToPoint( point );
  10944. intersectPoint.applyMatrix4( object.matrixWorld );
  10945. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  10946. if ( distance < raycaster.near || distance > raycaster.far ) return;
  10947. intersects.push( {
  10948. distance: distance,
  10949. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  10950. point: intersectPoint.clone(),
  10951. index: index,
  10952. face: null,
  10953. object: object
  10954. } );
  10955. }
  10956. }
  10957. if ( geometry instanceof THREE.BufferGeometry ) {
  10958. var index = geometry.index;
  10959. var attributes = geometry.attributes;
  10960. var positions = attributes.position.array;
  10961. if ( index !== null ) {
  10962. var indices = index.array;
  10963. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  10964. var a = indices[ i ];
  10965. position.fromArray( positions, a * 3 );
  10966. testPoint( position, a );
  10967. }
  10968. } else {
  10969. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  10970. position.fromArray( positions, i * 3 );
  10971. testPoint( position, i );
  10972. }
  10973. }
  10974. } else {
  10975. var vertices = geometry.vertices;
  10976. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  10977. testPoint( vertices[ i ], i );
  10978. }
  10979. }
  10980. };
  10981. }() );
  10982. THREE.Points.prototype.clone = function () {
  10983. return new this.constructor( this.geometry, this.material ).copy( this );
  10984. };
  10985. // Backwards compatibility
  10986. THREE.PointCloud = function ( geometry, material ) {
  10987. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  10988. return new THREE.Points( geometry, material );
  10989. };
  10990. THREE.ParticleSystem = function ( geometry, material ) {
  10991. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  10992. return new THREE.Points( geometry, material );
  10993. };
  10994. // File:src/objects/Line.js
  10995. /**
  10996. * @author mrdoob / http://mrdoob.com/
  10997. */
  10998. THREE.Line = function ( geometry, material, mode ) {
  10999. if ( mode === 1 ) {
  11000. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  11001. return new THREE.LineSegments( geometry, material );
  11002. }
  11003. THREE.Object3D.call( this );
  11004. this.type = 'Line';
  11005. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11006. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  11007. };
  11008. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  11009. THREE.Line.prototype.constructor = THREE.Line;
  11010. THREE.Line.prototype.raycast = ( function () {
  11011. var inverseMatrix = new THREE.Matrix4();
  11012. var ray = new THREE.Ray();
  11013. var sphere = new THREE.Sphere();
  11014. return function raycast( raycaster, intersects ) {
  11015. var precision = raycaster.linePrecision;
  11016. var precisionSq = precision * precision;
  11017. var geometry = this.geometry;
  11018. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11019. // Checking boundingSphere distance to ray
  11020. sphere.copy( geometry.boundingSphere );
  11021. sphere.applyMatrix4( this.matrixWorld );
  11022. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  11023. return;
  11024. }
  11025. inverseMatrix.getInverse( this.matrixWorld );
  11026. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11027. var vStart = new THREE.Vector3();
  11028. var vEnd = new THREE.Vector3();
  11029. var interSegment = new THREE.Vector3();
  11030. var interRay = new THREE.Vector3();
  11031. var step = this instanceof THREE.LineSegments ? 2 : 1;
  11032. if ( geometry instanceof THREE.BufferGeometry ) {
  11033. var index = geometry.index;
  11034. var attributes = geometry.attributes;
  11035. if ( index !== null ) {
  11036. var indices = index.array;
  11037. var positions = attributes.position.array;
  11038. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  11039. var a = indices[ i ];
  11040. var b = indices[ i + 1 ];
  11041. vStart.fromArray( positions, a * 3 );
  11042. vEnd.fromArray( positions, b * 3 );
  11043. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11044. if ( distSq > precisionSq ) continue;
  11045. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11046. var distance = raycaster.ray.origin.distanceTo( interRay );
  11047. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11048. intersects.push( {
  11049. distance: distance,
  11050. // What do we want? intersection point on the ray or on the segment??
  11051. // point: raycaster.ray.at( distance ),
  11052. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11053. index: i,
  11054. face: null,
  11055. faceIndex: null,
  11056. object: this
  11057. } );
  11058. }
  11059. } else {
  11060. var positions = attributes.position.array;
  11061. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  11062. vStart.fromArray( positions, 3 * i );
  11063. vEnd.fromArray( positions, 3 * i + 3 );
  11064. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11065. if ( distSq > precisionSq ) continue;
  11066. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11067. var distance = raycaster.ray.origin.distanceTo( interRay );
  11068. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11069. intersects.push( {
  11070. distance: distance,
  11071. // What do we want? intersection point on the ray or on the segment??
  11072. // point: raycaster.ray.at( distance ),
  11073. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11074. index: i,
  11075. face: null,
  11076. faceIndex: null,
  11077. object: this
  11078. } );
  11079. }
  11080. }
  11081. } else if ( geometry instanceof THREE.Geometry ) {
  11082. var vertices = geometry.vertices;
  11083. var nbVertices = vertices.length;
  11084. for ( var i = 0; i < nbVertices - 1; i += step ) {
  11085. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  11086. if ( distSq > precisionSq ) continue;
  11087. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11088. var distance = raycaster.ray.origin.distanceTo( interRay );
  11089. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11090. intersects.push( {
  11091. distance: distance,
  11092. // What do we want? intersection point on the ray or on the segment??
  11093. // point: raycaster.ray.at( distance ),
  11094. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11095. index: i,
  11096. face: null,
  11097. faceIndex: null,
  11098. object: this
  11099. } );
  11100. }
  11101. }
  11102. };
  11103. }() );
  11104. THREE.Line.prototype.clone = function () {
  11105. return new this.constructor( this.geometry, this.material ).copy( this );
  11106. };
  11107. // DEPRECATED
  11108. THREE.LineStrip = 0;
  11109. THREE.LinePieces = 1;
  11110. // File:src/objects/LineSegments.js
  11111. /**
  11112. * @author mrdoob / http://mrdoob.com/
  11113. */
  11114. THREE.LineSegments = function ( geometry, material ) {
  11115. THREE.Line.call( this, geometry, material );
  11116. this.type = 'LineSegments';
  11117. };
  11118. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  11119. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  11120. // File:src/objects/Mesh.js
  11121. /**
  11122. * @author mrdoob / http://mrdoob.com/
  11123. * @author alteredq / http://alteredqualia.com/
  11124. * @author mikael emtinger / http://gomo.se/
  11125. * @author jonobr1 / http://jonobr1.com/
  11126. */
  11127. THREE.Mesh = function ( geometry, material ) {
  11128. THREE.Object3D.call( this );
  11129. this.type = 'Mesh';
  11130. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11131. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  11132. this.updateMorphTargets();
  11133. };
  11134. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  11135. THREE.Mesh.prototype.constructor = THREE.Mesh;
  11136. THREE.Mesh.prototype.updateMorphTargets = function () {
  11137. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  11138. this.morphTargetBase = - 1;
  11139. this.morphTargetInfluences = [];
  11140. this.morphTargetDictionary = {};
  11141. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  11142. this.morphTargetInfluences.push( 0 );
  11143. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  11144. }
  11145. }
  11146. };
  11147. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  11148. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  11149. return this.morphTargetDictionary[ name ];
  11150. }
  11151. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  11152. return 0;
  11153. };
  11154. THREE.Mesh.prototype.raycast = ( function () {
  11155. var inverseMatrix = new THREE.Matrix4();
  11156. var ray = new THREE.Ray();
  11157. var sphere = new THREE.Sphere();
  11158. var vA = new THREE.Vector3();
  11159. var vB = new THREE.Vector3();
  11160. var vC = new THREE.Vector3();
  11161. var tempA = new THREE.Vector3();
  11162. var tempB = new THREE.Vector3();
  11163. var tempC = new THREE.Vector3();
  11164. var uvA = new THREE.Vector2();
  11165. var uvB = new THREE.Vector2();
  11166. var uvC = new THREE.Vector2();
  11167. var barycoord = new THREE.Vector3();
  11168. var intersectionPoint = new THREE.Vector3();
  11169. var intersectionPointWorld = new THREE.Vector3();
  11170. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  11171. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  11172. uv1.multiplyScalar( barycoord.x );
  11173. uv2.multiplyScalar( barycoord.y );
  11174. uv3.multiplyScalar( barycoord.z );
  11175. uv1.add( uv2 ).add( uv3 );
  11176. return uv1.clone();
  11177. }
  11178. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ){
  11179. var intersect;
  11180. var material = object.material;
  11181. if ( material.side === THREE.BackSide ) {
  11182. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  11183. } else {
  11184. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  11185. }
  11186. if ( intersect === null ) return null;
  11187. intersectionPointWorld.copy( point );
  11188. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  11189. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11190. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  11191. return {
  11192. distance: distance,
  11193. point: intersectionPointWorld.clone(),
  11194. object: object
  11195. };
  11196. }
  11197. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  11198. vA.fromArray( positions, a * 3 );
  11199. vB.fromArray( positions, b * 3 );
  11200. vC.fromArray( positions, c * 3 );
  11201. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  11202. if ( intersection ) {
  11203. if ( uvs ) {
  11204. uvA.fromArray( uvs, a * 2 );
  11205. uvB.fromArray( uvs, b * 2 );
  11206. uvC.fromArray( uvs, c * 2 );
  11207. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  11208. }
  11209. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  11210. intersection.faceIndex = a;
  11211. }
  11212. return intersection;
  11213. }
  11214. return function raycast( raycaster, intersects ) {
  11215. var geometry = this.geometry;
  11216. var material = this.material;
  11217. if ( material === undefined ) return;
  11218. // Checking boundingSphere distance to ray
  11219. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11220. var matrixWorld = this.matrixWorld;
  11221. sphere.copy( geometry.boundingSphere );
  11222. sphere.applyMatrix4( matrixWorld );
  11223. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) return;
  11224. // Check boundingBox before continuing
  11225. inverseMatrix.getInverse( matrixWorld );
  11226. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11227. if ( geometry.boundingBox !== null ) {
  11228. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) return;
  11229. }
  11230. var uvs, intersection;
  11231. if ( geometry instanceof THREE.BufferGeometry ) {
  11232. var a, b, c;
  11233. var index = geometry.index;
  11234. var attributes = geometry.attributes;
  11235. var positions = attributes.position.array;
  11236. if ( attributes.uv !== undefined ){
  11237. uvs = attributes.uv.array;
  11238. }
  11239. if ( index !== null ) {
  11240. var indices = index.array;
  11241. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  11242. a = indices[ i ];
  11243. b = indices[ i + 1 ];
  11244. c = indices[ i + 2 ];
  11245. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  11246. if ( intersection ) {
  11247. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  11248. intersects.push( intersection );
  11249. }
  11250. }
  11251. } else {
  11252. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  11253. a = i / 3;
  11254. b = a + 1;
  11255. c = a + 2;
  11256. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  11257. if ( intersection ) {
  11258. intersection.index = a; // triangle number in positions buffer semantics
  11259. intersects.push( intersection );
  11260. }
  11261. }
  11262. }
  11263. } else if ( geometry instanceof THREE.Geometry ) {
  11264. var fvA, fvB, fvC;
  11265. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  11266. var materials = isFaceMaterial === true ? material.materials : null;
  11267. var vertices = geometry.vertices;
  11268. var faces = geometry.faces;
  11269. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  11270. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  11271. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  11272. var face = faces[ f ];
  11273. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  11274. if ( faceMaterial === undefined ) continue;
  11275. fvA = vertices[ face.a ];
  11276. fvB = vertices[ face.b ];
  11277. fvC = vertices[ face.c ];
  11278. if ( faceMaterial.morphTargets === true ) {
  11279. var morphTargets = geometry.morphTargets;
  11280. var morphInfluences = this.morphTargetInfluences;
  11281. vA.set( 0, 0, 0 );
  11282. vB.set( 0, 0, 0 );
  11283. vC.set( 0, 0, 0 );
  11284. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  11285. var influence = morphInfluences[ t ];
  11286. if ( influence === 0 ) continue;
  11287. var targets = morphTargets[ t ].vertices;
  11288. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  11289. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  11290. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  11291. }
  11292. vA.add( fvA );
  11293. vB.add( fvB );
  11294. vC.add( fvC );
  11295. fvA = vA;
  11296. fvB = vB;
  11297. fvC = vC;
  11298. }
  11299. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  11300. if ( intersection ) {
  11301. if ( uvs ) {
  11302. var uvs_f = uvs[ f ];
  11303. uvA.copy( uvs_f[ 0 ] );
  11304. uvB.copy( uvs_f[ 1 ] );
  11305. uvC.copy( uvs_f[ 2 ] );
  11306. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  11307. }
  11308. intersection.face = face;
  11309. intersection.faceIndex = f;
  11310. intersects.push( intersection );
  11311. }
  11312. }
  11313. }
  11314. };
  11315. }() );
  11316. THREE.Mesh.prototype.clone = function () {
  11317. return new this.constructor( this.geometry, this.material ).copy( this );
  11318. };
  11319. // File:src/objects/Bone.js
  11320. /**
  11321. * @author mikael emtinger / http://gomo.se/
  11322. * @author alteredq / http://alteredqualia.com/
  11323. * @author ikerr / http://verold.com
  11324. */
  11325. THREE.Bone = function ( skin ) {
  11326. THREE.Object3D.call( this );
  11327. this.type = 'Bone';
  11328. this.skin = skin;
  11329. };
  11330. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  11331. THREE.Bone.prototype.constructor = THREE.Bone;
  11332. THREE.Bone.prototype.copy = function ( source ) {
  11333. THREE.Object3D.prototype.copy.call( this, source );
  11334. this.skin = source.skin;
  11335. return this;
  11336. };
  11337. // File:src/objects/Skeleton.js
  11338. /**
  11339. * @author mikael emtinger / http://gomo.se/
  11340. * @author alteredq / http://alteredqualia.com/
  11341. * @author michael guerrero / http://realitymeltdown.com
  11342. * @author ikerr / http://verold.com
  11343. */
  11344. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  11345. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  11346. this.identityMatrix = new THREE.Matrix4();
  11347. // copy the bone array
  11348. bones = bones || [];
  11349. this.bones = bones.slice( 0 );
  11350. // create a bone texture or an array of floats
  11351. if ( this.useVertexTexture ) {
  11352. // layout (1 matrix = 4 pixels)
  11353. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  11354. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  11355. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  11356. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  11357. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  11358. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  11359. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  11360. size = Math.max( size, 4 );
  11361. this.boneTextureWidth = size;
  11362. this.boneTextureHeight = size;
  11363. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  11364. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  11365. } else {
  11366. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  11367. }
  11368. // use the supplied bone inverses or calculate the inverses
  11369. if ( boneInverses === undefined ) {
  11370. this.calculateInverses();
  11371. } else {
  11372. if ( this.bones.length === boneInverses.length ) {
  11373. this.boneInverses = boneInverses.slice( 0 );
  11374. } else {
  11375. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  11376. this.boneInverses = [];
  11377. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11378. this.boneInverses.push( new THREE.Matrix4() );
  11379. }
  11380. }
  11381. }
  11382. };
  11383. THREE.Skeleton.prototype.calculateInverses = function () {
  11384. this.boneInverses = [];
  11385. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11386. var inverse = new THREE.Matrix4();
  11387. if ( this.bones[ b ] ) {
  11388. inverse.getInverse( this.bones[ b ].matrixWorld );
  11389. }
  11390. this.boneInverses.push( inverse );
  11391. }
  11392. };
  11393. THREE.Skeleton.prototype.pose = function () {
  11394. var bone;
  11395. // recover the bind-time world matrices
  11396. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11397. bone = this.bones[ b ];
  11398. if ( bone ) {
  11399. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  11400. }
  11401. }
  11402. // compute the local matrices, positions, rotations and scales
  11403. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11404. bone = this.bones[ b ];
  11405. if ( bone ) {
  11406. if ( bone.parent ) {
  11407. bone.matrix.getInverse( bone.parent.matrixWorld );
  11408. bone.matrix.multiply( bone.matrixWorld );
  11409. } else {
  11410. bone.matrix.copy( bone.matrixWorld );
  11411. }
  11412. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  11413. }
  11414. }
  11415. };
  11416. THREE.Skeleton.prototype.update = ( function () {
  11417. var offsetMatrix = new THREE.Matrix4();
  11418. return function update() {
  11419. // flatten bone matrices to array
  11420. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11421. // compute the offset between the current and the original transform
  11422. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  11423. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  11424. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  11425. }
  11426. if ( this.useVertexTexture ) {
  11427. this.boneTexture.needsUpdate = true;
  11428. }
  11429. };
  11430. } )();
  11431. THREE.Skeleton.prototype.clone = function () {
  11432. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  11433. };
  11434. // File:src/objects/SkinnedMesh.js
  11435. /**
  11436. * @author mikael emtinger / http://gomo.se/
  11437. * @author alteredq / http://alteredqualia.com/
  11438. * @author ikerr / http://verold.com
  11439. */
  11440. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  11441. THREE.Mesh.call( this, geometry, material );
  11442. this.type = 'SkinnedMesh';
  11443. this.bindMode = "attached";
  11444. this.bindMatrix = new THREE.Matrix4();
  11445. this.bindMatrixInverse = new THREE.Matrix4();
  11446. // init bones
  11447. // TODO: remove bone creation as there is no reason (other than
  11448. // convenience) for THREE.SkinnedMesh to do this.
  11449. var bones = [];
  11450. if ( this.geometry && this.geometry.bones !== undefined ) {
  11451. var bone, gbone;
  11452. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11453. gbone = this.geometry.bones[ b ];
  11454. bone = new THREE.Bone( this );
  11455. bones.push( bone );
  11456. bone.name = gbone.name;
  11457. bone.position.fromArray( gbone.pos );
  11458. bone.quaternion.fromArray( gbone.rotq );
  11459. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  11460. }
  11461. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11462. gbone = this.geometry.bones[ b ];
  11463. if ( gbone.parent !== - 1 && gbone.parent !== null) {
  11464. bones[ gbone.parent ].add( bones[ b ] );
  11465. } else {
  11466. this.add( bones[ b ] );
  11467. }
  11468. }
  11469. }
  11470. this.normalizeSkinWeights();
  11471. this.updateMatrixWorld( true );
  11472. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  11473. };
  11474. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  11475. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  11476. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  11477. this.skeleton = skeleton;
  11478. if ( bindMatrix === undefined ) {
  11479. this.updateMatrixWorld( true );
  11480. this.skeleton.calculateInverses();
  11481. bindMatrix = this.matrixWorld;
  11482. }
  11483. this.bindMatrix.copy( bindMatrix );
  11484. this.bindMatrixInverse.getInverse( bindMatrix );
  11485. };
  11486. THREE.SkinnedMesh.prototype.pose = function () {
  11487. this.skeleton.pose();
  11488. };
  11489. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  11490. if ( this.geometry instanceof THREE.Geometry ) {
  11491. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  11492. var sw = this.geometry.skinWeights[ i ];
  11493. var scale = 1.0 / sw.lengthManhattan();
  11494. if ( scale !== Infinity ) {
  11495. sw.multiplyScalar( scale );
  11496. } else {
  11497. sw.set( 1 ); // this will be normalized by the shader anyway
  11498. }
  11499. }
  11500. } else {
  11501. // skinning weights assumed to be normalized for THREE.BufferGeometry
  11502. }
  11503. };
  11504. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  11505. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  11506. if ( this.bindMode === "attached" ) {
  11507. this.bindMatrixInverse.getInverse( this.matrixWorld );
  11508. } else if ( this.bindMode === "detached" ) {
  11509. this.bindMatrixInverse.getInverse( this.bindMatrix );
  11510. } else {
  11511. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  11512. }
  11513. };
  11514. THREE.SkinnedMesh.prototype.clone = function() {
  11515. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  11516. };
  11517. // File:src/objects/LOD.js
  11518. /**
  11519. * @author mikael emtinger / http://gomo.se/
  11520. * @author alteredq / http://alteredqualia.com/
  11521. * @author mrdoob / http://mrdoob.com/
  11522. */
  11523. THREE.LOD = function () {
  11524. THREE.Object3D.call( this );
  11525. this.type = 'LOD';
  11526. Object.defineProperties( this, {
  11527. levels: {
  11528. enumerable: true,
  11529. value: []
  11530. },
  11531. objects: {
  11532. get: function () {
  11533. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  11534. return this.levels;
  11535. }
  11536. }
  11537. } );
  11538. };
  11539. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  11540. THREE.LOD.prototype.constructor = THREE.LOD;
  11541. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  11542. if ( distance === undefined ) distance = 0;
  11543. distance = Math.abs( distance );
  11544. var levels = this.levels;
  11545. for ( var l = 0; l < levels.length; l ++ ) {
  11546. if ( distance < levels[ l ].distance ) {
  11547. break;
  11548. }
  11549. }
  11550. levels.splice( l, 0, { distance: distance, object: object } );
  11551. this.add( object );
  11552. };
  11553. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  11554. var levels = this.levels;
  11555. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11556. if ( distance < levels[ i ].distance ) {
  11557. break;
  11558. }
  11559. }
  11560. return levels[ i - 1 ].object;
  11561. };
  11562. THREE.LOD.prototype.raycast = ( function () {
  11563. var matrixPosition = new THREE.Vector3();
  11564. return function raycast( raycaster, intersects ) {
  11565. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11566. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  11567. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  11568. };
  11569. }() );
  11570. THREE.LOD.prototype.update = function () {
  11571. var v1 = new THREE.Vector3();
  11572. var v2 = new THREE.Vector3();
  11573. return function update( camera ) {
  11574. var levels = this.levels;
  11575. if ( levels.length > 1 ) {
  11576. v1.setFromMatrixPosition( camera.matrixWorld );
  11577. v2.setFromMatrixPosition( this.matrixWorld );
  11578. var distance = v1.distanceTo( v2 );
  11579. levels[ 0 ].object.visible = true;
  11580. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11581. if ( distance >= levels[ i ].distance ) {
  11582. levels[ i - 1 ].object.visible = false;
  11583. levels[ i ].object.visible = true;
  11584. } else {
  11585. break;
  11586. }
  11587. }
  11588. for ( ; i < l; i ++ ) {
  11589. levels[ i ].object.visible = false;
  11590. }
  11591. }
  11592. };
  11593. }();
  11594. THREE.LOD.prototype.copy = function ( source ) {
  11595. THREE.Object3D.prototype.copy.call( this, source, false );
  11596. var levels = source.levels;
  11597. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11598. var level = levels[ i ];
  11599. this.addLevel( level.object.clone(), level.distance );
  11600. }
  11601. return this;
  11602. };
  11603. THREE.LOD.prototype.toJSON = function ( meta ) {
  11604. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11605. data.object.levels = [];
  11606. var levels = this.levels;
  11607. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11608. var level = levels[ i ];
  11609. data.object.levels.push( {
  11610. object: level.object.uuid,
  11611. distance: level.distance
  11612. } );
  11613. }
  11614. return data;
  11615. };
  11616. // File:src/objects/Sprite.js
  11617. /**
  11618. * @author mikael emtinger / http://gomo.se/
  11619. * @author alteredq / http://alteredqualia.com/
  11620. */
  11621. THREE.Sprite = ( function () {
  11622. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  11623. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  11624. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  11625. var geometry = new THREE.BufferGeometry();
  11626. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  11627. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  11628. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  11629. return function Sprite( material ) {
  11630. THREE.Object3D.call( this );
  11631. this.type = 'Sprite';
  11632. this.geometry = geometry;
  11633. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  11634. };
  11635. } )();
  11636. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  11637. THREE.Sprite.prototype.constructor = THREE.Sprite;
  11638. THREE.Sprite.prototype.raycast = ( function () {
  11639. var matrixPosition = new THREE.Vector3();
  11640. return function raycast( raycaster, intersects ) {
  11641. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11642. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  11643. var guessSizeSq = this.scale.x * this.scale.y;
  11644. if ( distanceSq > guessSizeSq ) {
  11645. return;
  11646. }
  11647. intersects.push( {
  11648. distance: Math.sqrt( distanceSq ),
  11649. point: this.position,
  11650. face: null,
  11651. object: this
  11652. } );
  11653. };
  11654. }() );
  11655. THREE.Sprite.prototype.clone = function () {
  11656. return new this.constructor( this.material ).copy( this );
  11657. };
  11658. // Backwards compatibility
  11659. THREE.Particle = THREE.Sprite;
  11660. // File:src/objects/LensFlare.js
  11661. /**
  11662. * @author mikael emtinger / http://gomo.se/
  11663. * @author alteredq / http://alteredqualia.com/
  11664. */
  11665. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  11666. THREE.Object3D.call( this );
  11667. this.lensFlares = [];
  11668. this.positionScreen = new THREE.Vector3();
  11669. this.customUpdateCallback = undefined;
  11670. if ( texture !== undefined ) {
  11671. this.add( texture, size, distance, blending, color );
  11672. }
  11673. };
  11674. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  11675. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  11676. /*
  11677. * Add: adds another flare
  11678. */
  11679. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  11680. if ( size === undefined ) size = - 1;
  11681. if ( distance === undefined ) distance = 0;
  11682. if ( opacity === undefined ) opacity = 1;
  11683. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  11684. if ( blending === undefined ) blending = THREE.NormalBlending;
  11685. distance = Math.min( distance, Math.max( 0, distance ) );
  11686. this.lensFlares.push( {
  11687. texture: texture, // THREE.Texture
  11688. size: size, // size in pixels (-1 = use texture.width)
  11689. distance: distance, // distance (0-1) from light source (0=at light source)
  11690. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  11691. scale: 1, // scale
  11692. rotation: 0, // rotation
  11693. opacity: opacity, // opacity
  11694. color: color, // color
  11695. blending: blending // blending
  11696. } );
  11697. };
  11698. /*
  11699. * Update lens flares update positions on all flares based on the screen position
  11700. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  11701. */
  11702. THREE.LensFlare.prototype.updateLensFlares = function () {
  11703. var f, fl = this.lensFlares.length;
  11704. var flare;
  11705. var vecX = - this.positionScreen.x * 2;
  11706. var vecY = - this.positionScreen.y * 2;
  11707. for ( f = 0; f < fl; f ++ ) {
  11708. flare = this.lensFlares[ f ];
  11709. flare.x = this.positionScreen.x + vecX * flare.distance;
  11710. flare.y = this.positionScreen.y + vecY * flare.distance;
  11711. flare.wantedRotation = flare.x * Math.PI * 0.25;
  11712. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  11713. }
  11714. };
  11715. THREE.LensFlare.prototype.copy = function ( source ) {
  11716. THREE.Object3D.prototype.copy.call( this, source );
  11717. this.positionScreen.copy( source.positionScreen );
  11718. this.customUpdateCallback = source.customUpdateCallback;
  11719. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  11720. this.lensFlares.push( source.lensFlares[ i ] );
  11721. }
  11722. return this;
  11723. };
  11724. // File:src/scenes/Scene.js
  11725. /**
  11726. * @author mrdoob / http://mrdoob.com/
  11727. */
  11728. THREE.Scene = function () {
  11729. THREE.Object3D.call( this );
  11730. this.type = 'Scene';
  11731. this.fog = null;
  11732. this.overrideMaterial = null;
  11733. this.autoUpdate = true; // checked by the renderer
  11734. };
  11735. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  11736. THREE.Scene.prototype.constructor = THREE.Scene;
  11737. THREE.Scene.prototype.copy = function ( source ) {
  11738. THREE.Object3D.prototype.copy.call( this, source );
  11739. if ( source.fog !== null ) this.fog = source.fog.clone();
  11740. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  11741. this.autoUpdate = source.autoUpdate;
  11742. this.matrixAutoUpdate = source.matrixAutoUpdate;
  11743. return this;
  11744. };
  11745. // File:src/scenes/Fog.js
  11746. /**
  11747. * @author mrdoob / http://mrdoob.com/
  11748. * @author alteredq / http://alteredqualia.com/
  11749. */
  11750. THREE.Fog = function ( color, near, far ) {
  11751. this.name = '';
  11752. this.color = new THREE.Color( color );
  11753. this.near = ( near !== undefined ) ? near : 1;
  11754. this.far = ( far !== undefined ) ? far : 1000;
  11755. };
  11756. THREE.Fog.prototype.clone = function () {
  11757. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  11758. };
  11759. // File:src/scenes/FogExp2.js
  11760. /**
  11761. * @author mrdoob / http://mrdoob.com/
  11762. * @author alteredq / http://alteredqualia.com/
  11763. */
  11764. THREE.FogExp2 = function ( color, density ) {
  11765. this.name = '';
  11766. this.color = new THREE.Color( color );
  11767. this.density = ( density !== undefined ) ? density : 0.00025;
  11768. };
  11769. THREE.FogExp2.prototype.clone = function () {
  11770. return new THREE.FogExp2( this.color.getHex(), this.density );
  11771. };
  11772. // File:src/renderers/shaders/ShaderChunk.js
  11773. THREE.ShaderChunk = {};
  11774. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  11775. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  11776. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  11777. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  11778. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  11779. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  11780. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  11781. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  11782. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  11783. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  11784. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  11785. THREE.ShaderChunk[ 'begin_vertex'] = "\nvec3 transformed = vec3( position );\n";
  11786. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  11787. THREE.ShaderChunk[ 'beginnormal_vertex'] = "\nvec3 objectNormal = vec3( normal );\n";
  11788. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  11789. THREE.ShaderChunk[ 'bumpmap_pars_fragment'] = "#ifdef USE_BUMPMAP\n\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n\n\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;\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";
  11790. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  11791. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  11792. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  11793. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  11794. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  11795. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  11796. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  11797. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  11798. // File:src/renderers/shaders/ShaderChunk/common.glsl
  11799. 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\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\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\n return 0.25;\n\n}\n\nfloat D_BlinnPhong( in float shininess, in float dotNH ) {\n\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 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";
  11800. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  11801. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  11802. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  11803. THREE.ShaderChunk[ 'displacementmap_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n\n#endif\n";
  11804. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  11805. 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";
  11806. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  11807. 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";
  11808. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  11809. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  11810. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  11811. 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 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";
  11812. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  11813. 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";
  11814. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  11815. 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";
  11816. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  11817. 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";
  11818. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  11819. 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";
  11820. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  11821. 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";
  11822. // File:src/renderers/shaders/ShaderChunk/hemilight_fragment.glsl
  11823. 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";
  11824. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  11825. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  11826. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  11827. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  11828. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  11829. THREE.ShaderChunk[ 'lights_lambert_pars_vertex'] = "#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";
  11830. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  11831. 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\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\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\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\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\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\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";
  11832. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  11833. 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\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\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\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\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\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * cosineTerm;\n\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * cosineTerm;\n\n }\n\n#endif\n";
  11834. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  11835. 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";
  11836. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  11837. 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";
  11838. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  11839. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif\n";
  11840. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  11841. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  11842. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  11843. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  11844. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  11845. 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";
  11846. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  11847. 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";
  11848. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  11849. 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";
  11850. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  11851. 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";
  11852. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  11853. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  11854. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  11855. 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";
  11856. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  11857. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  11858. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  11859. 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";
  11860. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  11861. 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";
  11862. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  11863. 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";
  11864. // File:src/renderers/shaders/ShaderChunk/normal_phong_fragment.glsl
  11865. 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";
  11866. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  11867. THREE.ShaderChunk[ 'normalmap_pars_fragment'] = "#ifdef USE_NORMALMAP\n\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n\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";
  11868. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  11869. 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";
  11870. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  11871. THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\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 bool isPointLight = shadowDarkness[ i ] < 0.0;\n\n if ( isPointLight ) {\n\n float realShadowDarkness = abs( shadowDarkness[ i ] );\n\n vec3 lightToPosition = vShadowCoord[ i ].xyz;\n\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\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\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 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 \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 \n float texelSizeX = 1.0 / shadowMapSize[ i ].x;\n\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n\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\n /*\n for ( float y = -1.25; y <= 1.25; y += 1.25 )\n for ( float x = -1.25; x <= 1.25; x += 1.25 ) {\n vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\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\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 \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#endif\n";
  11872. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  11873. 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\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\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n\n\n vec3 absV = abs( v );\n\n\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n\n\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\n\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\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\n }\n\n #endif\n\n#endif\n";
  11874. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  11875. 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";
  11876. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  11877. 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";
  11878. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  11879. 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";
  11880. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  11881. 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";
  11882. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  11883. 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";
  11884. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  11885. 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";
  11886. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  11887. 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";
  11888. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  11889. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  11890. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  11891. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  11892. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  11893. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  11894. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  11895. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  11896. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  11897. 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";
  11898. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  11899. 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";
  11900. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  11901. 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";
  11902. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  11903. 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";
  11904. // File:src/renderers/shaders/UniformsUtils.js
  11905. /**
  11906. * Uniform Utilities
  11907. */
  11908. THREE.UniformsUtils = {
  11909. merge: function ( uniforms ) {
  11910. var merged = {};
  11911. for ( var u = 0; u < uniforms.length; u ++ ) {
  11912. var tmp = this.clone( uniforms[ u ] );
  11913. for ( var p in tmp ) {
  11914. merged[ p ] = tmp[ p ];
  11915. }
  11916. }
  11917. return merged;
  11918. },
  11919. clone: function ( uniforms_src ) {
  11920. var uniforms_dst = {};
  11921. for ( var u in uniforms_src ) {
  11922. uniforms_dst[ u ] = {};
  11923. for ( var p in uniforms_src[ u ] ) {
  11924. var parameter_src = uniforms_src[ u ][ p ];
  11925. if ( parameter_src instanceof THREE.Color ||
  11926. parameter_src instanceof THREE.Vector2 ||
  11927. parameter_src instanceof THREE.Vector3 ||
  11928. parameter_src instanceof THREE.Vector4 ||
  11929. parameter_src instanceof THREE.Matrix3 ||
  11930. parameter_src instanceof THREE.Matrix4 ||
  11931. parameter_src instanceof THREE.Texture ) {
  11932. uniforms_dst[ u ][ p ] = parameter_src.clone();
  11933. } else if ( Array.isArray( parameter_src ) ) {
  11934. uniforms_dst[ u ][ p ] = parameter_src.slice();
  11935. } else {
  11936. uniforms_dst[ u ][ p ] = parameter_src;
  11937. }
  11938. }
  11939. }
  11940. return uniforms_dst;
  11941. }
  11942. };
  11943. // File:src/renderers/shaders/UniformsLib.js
  11944. /**
  11945. * Uniforms library for shared webgl shaders
  11946. */
  11947. THREE.UniformsLib = {
  11948. common: {
  11949. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  11950. "opacity" : { type: "f", value: 1.0 },
  11951. "map" : { type: "t", value: null },
  11952. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  11953. "specularMap" : { type: "t", value: null },
  11954. "alphaMap" : { type: "t", value: null },
  11955. "envMap" : { type: "t", value: null },
  11956. "flipEnvMap" : { type: "f", value: - 1 },
  11957. "reflectivity" : { type: "f", value: 1.0 },
  11958. "refractionRatio" : { type: "f", value: 0.98 }
  11959. },
  11960. aomap: {
  11961. "aoMap" : { type: "t", value: null },
  11962. "aoMapIntensity" : { type: "f", value: 1 },
  11963. },
  11964. lightmap: {
  11965. "lightMap" : { type: "t", value: null },
  11966. "lightMapIntensity" : { type: "f", value: 1 },
  11967. },
  11968. emissivemap: {
  11969. "emissiveMap" : { type: "t", value: null },
  11970. },
  11971. bumpmap: {
  11972. "bumpMap" : { type: "t", value: null },
  11973. "bumpScale" : { type: "f", value: 1 }
  11974. },
  11975. normalmap: {
  11976. "normalMap" : { type: "t", value: null },
  11977. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  11978. },
  11979. displacementmap: {
  11980. "displacementMap" : { type: "t", value: null },
  11981. "displacementScale" : { type: "f", value: 1 },
  11982. "displacementBias" : { type: "f", value: 0 }
  11983. },
  11984. fog : {
  11985. "fogDensity" : { type: "f", value: 0.00025 },
  11986. "fogNear" : { type: "f", value: 1 },
  11987. "fogFar" : { type: "f", value: 2000 },
  11988. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  11989. },
  11990. lights: {
  11991. "ambientLightColor" : { type: "fv", value: [] },
  11992. "directionalLightDirection" : { type: "fv", value: [] },
  11993. "directionalLightColor" : { type: "fv", value: [] },
  11994. "hemisphereLightDirection" : { type: "fv", value: [] },
  11995. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  11996. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  11997. "pointLightColor" : { type: "fv", value: [] },
  11998. "pointLightPosition" : { type: "fv", value: [] },
  11999. "pointLightDistance" : { type: "fv1", value: [] },
  12000. "pointLightDecay" : { type: "fv1", value: [] },
  12001. "spotLightColor" : { type: "fv", value: [] },
  12002. "spotLightPosition" : { type: "fv", value: [] },
  12003. "spotLightDirection" : { type: "fv", value: [] },
  12004. "spotLightDistance" : { type: "fv1", value: [] },
  12005. "spotLightAngleCos" : { type: "fv1", value: [] },
  12006. "spotLightExponent" : { type: "fv1", value: [] },
  12007. "spotLightDecay" : { type: "fv1", value: [] }
  12008. },
  12009. points: {
  12010. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  12011. "opacity" : { type: "f", value: 1.0 },
  12012. "size" : { type: "f", value: 1.0 },
  12013. "scale" : { type: "f", value: 1.0 },
  12014. "map" : { type: "t", value: null },
  12015. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  12016. "fogDensity" : { type: "f", value: 0.00025 },
  12017. "fogNear" : { type: "f", value: 1 },
  12018. "fogFar" : { type: "f", value: 2000 },
  12019. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  12020. },
  12021. shadowmap: {
  12022. "shadowMap": { type: "tv", value: [] },
  12023. "shadowMapSize": { type: "v2v", value: [] },
  12024. "shadowBias" : { type: "fv1", value: [] },
  12025. "shadowDarkness": { type: "fv1", value: [] },
  12026. "shadowMatrix" : { type: "m4v", value: [] }
  12027. }
  12028. };
  12029. // File:src/renderers/shaders/ShaderLib.js
  12030. /**
  12031. * Webgl Shader Library for three.js
  12032. *
  12033. * @author alteredq / http://alteredqualia.com/
  12034. * @author mrdoob / http://mrdoob.com/
  12035. * @author mikael emtinger / http://gomo.se/
  12036. */
  12037. THREE.ShaderLib = {
  12038. 'basic': {
  12039. uniforms: THREE.UniformsUtils.merge( [
  12040. THREE.UniformsLib[ "common" ],
  12041. THREE.UniformsLib[ "aomap" ],
  12042. THREE.UniformsLib[ "fog" ],
  12043. THREE.UniformsLib[ "shadowmap" ]
  12044. ] ),
  12045. vertexShader: [
  12046. THREE.ShaderChunk[ "common" ],
  12047. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12048. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12049. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12050. THREE.ShaderChunk[ "color_pars_vertex" ],
  12051. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12052. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12053. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12054. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12055. "void main() {",
  12056. THREE.ShaderChunk[ "uv_vertex" ],
  12057. THREE.ShaderChunk[ "uv2_vertex" ],
  12058. THREE.ShaderChunk[ "color_vertex" ],
  12059. THREE.ShaderChunk[ "skinbase_vertex" ],
  12060. " #ifdef USE_ENVMAP",
  12061. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12062. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12063. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12064. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12065. " #endif",
  12066. THREE.ShaderChunk[ "begin_vertex" ],
  12067. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12068. THREE.ShaderChunk[ "skinning_vertex" ],
  12069. THREE.ShaderChunk[ "project_vertex" ],
  12070. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12071. THREE.ShaderChunk[ "worldpos_vertex" ],
  12072. THREE.ShaderChunk[ "envmap_vertex" ],
  12073. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12074. "}"
  12075. ].join( "\n" ),
  12076. fragmentShader: [
  12077. "uniform vec3 diffuse;",
  12078. "uniform float opacity;",
  12079. THREE.ShaderChunk[ "common" ],
  12080. THREE.ShaderChunk[ "color_pars_fragment" ],
  12081. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12082. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12083. THREE.ShaderChunk[ "map_pars_fragment" ],
  12084. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12085. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12086. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12087. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12088. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12089. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12090. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12091. "void main() {",
  12092. " vec3 outgoingLight = vec3( 0.0 );",
  12093. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12094. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  12095. " vec3 shadowMask = vec3( 1.0 );",
  12096. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12097. THREE.ShaderChunk[ "map_fragment" ],
  12098. THREE.ShaderChunk[ "color_fragment" ],
  12099. THREE.ShaderChunk[ "alphamap_fragment" ],
  12100. THREE.ShaderChunk[ "alphatest_fragment" ],
  12101. THREE.ShaderChunk[ "specularmap_fragment" ],
  12102. THREE.ShaderChunk[ "aomap_fragment" ],
  12103. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12104. " outgoingLight = diffuseColor.rgb * totalAmbientLight * shadowMask;",
  12105. THREE.ShaderChunk[ "envmap_fragment" ],
  12106. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12107. THREE.ShaderChunk[ "fog_fragment" ],
  12108. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12109. "}"
  12110. ].join( "\n" )
  12111. },
  12112. 'lambert': {
  12113. uniforms: THREE.UniformsUtils.merge( [
  12114. THREE.UniformsLib[ "common" ],
  12115. THREE.UniformsLib[ "fog" ],
  12116. THREE.UniformsLib[ "lights" ],
  12117. THREE.UniformsLib[ "shadowmap" ],
  12118. {
  12119. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  12120. }
  12121. ] ),
  12122. vertexShader: [
  12123. "#define LAMBERT",
  12124. "varying vec3 vLightFront;",
  12125. "#ifdef DOUBLE_SIDED",
  12126. " varying vec3 vLightBack;",
  12127. "#endif",
  12128. THREE.ShaderChunk[ "common" ],
  12129. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12130. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12131. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12132. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  12133. THREE.ShaderChunk[ "color_pars_vertex" ],
  12134. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12135. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12136. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12137. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12138. "void main() {",
  12139. THREE.ShaderChunk[ "uv_vertex" ],
  12140. THREE.ShaderChunk[ "uv2_vertex" ],
  12141. THREE.ShaderChunk[ "color_vertex" ],
  12142. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12143. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12144. THREE.ShaderChunk[ "skinbase_vertex" ],
  12145. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12146. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12147. THREE.ShaderChunk[ "begin_vertex" ],
  12148. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12149. THREE.ShaderChunk[ "skinning_vertex" ],
  12150. THREE.ShaderChunk[ "project_vertex" ],
  12151. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12152. THREE.ShaderChunk[ "worldpos_vertex" ],
  12153. THREE.ShaderChunk[ "envmap_vertex" ],
  12154. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  12155. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12156. "}"
  12157. ].join( "\n" ),
  12158. fragmentShader: [
  12159. "uniform vec3 diffuse;",
  12160. "uniform vec3 emissive;",
  12161. "uniform float opacity;",
  12162. "uniform vec3 ambientLightColor;",
  12163. "varying vec3 vLightFront;",
  12164. "#ifdef DOUBLE_SIDED",
  12165. " varying vec3 vLightBack;",
  12166. "#endif",
  12167. THREE.ShaderChunk[ "common" ],
  12168. THREE.ShaderChunk[ "color_pars_fragment" ],
  12169. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12170. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12171. THREE.ShaderChunk[ "map_pars_fragment" ],
  12172. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12173. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12174. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12175. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12176. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12177. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12178. "void main() {",
  12179. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  12180. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12181. " vec3 totalAmbientLight = ambientLightColor;",
  12182. " vec3 shadowMask = vec3( 1.0 );",
  12183. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12184. THREE.ShaderChunk[ "map_fragment" ],
  12185. THREE.ShaderChunk[ "color_fragment" ],
  12186. THREE.ShaderChunk[ "alphamap_fragment" ],
  12187. THREE.ShaderChunk[ "alphatest_fragment" ],
  12188. THREE.ShaderChunk[ "specularmap_fragment" ],
  12189. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12190. " #ifdef DOUBLE_SIDED",
  12191. " if ( gl_FrontFacing )",
  12192. " outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask + totalAmbientLight ) + emissive;",
  12193. " else",
  12194. " outgoingLight += diffuseColor.rgb * ( vLightBack * shadowMask + totalAmbientLight ) + emissive;",
  12195. " #else",
  12196. " outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask + totalAmbientLight ) + emissive;",
  12197. " #endif",
  12198. THREE.ShaderChunk[ "envmap_fragment" ],
  12199. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12200. THREE.ShaderChunk[ "fog_fragment" ],
  12201. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12202. "}"
  12203. ].join( "\n" )
  12204. },
  12205. 'phong': {
  12206. uniforms: THREE.UniformsUtils.merge( [
  12207. THREE.UniformsLib[ "common" ],
  12208. THREE.UniformsLib[ "aomap" ],
  12209. THREE.UniformsLib[ "lightmap" ],
  12210. THREE.UniformsLib[ "emissivemap" ],
  12211. THREE.UniformsLib[ "bumpmap" ],
  12212. THREE.UniformsLib[ "normalmap" ],
  12213. THREE.UniformsLib[ "displacementmap" ],
  12214. THREE.UniformsLib[ "fog" ],
  12215. THREE.UniformsLib[ "lights" ],
  12216. THREE.UniformsLib[ "shadowmap" ],
  12217. {
  12218. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  12219. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  12220. "shininess": { type: "f", value: 30 }
  12221. }
  12222. ] ),
  12223. vertexShader: [
  12224. "#define PHONG",
  12225. "varying vec3 vViewPosition;",
  12226. "#ifndef FLAT_SHADED",
  12227. " varying vec3 vNormal;",
  12228. "#endif",
  12229. THREE.ShaderChunk[ "common" ],
  12230. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12231. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12232. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  12233. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12234. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  12235. THREE.ShaderChunk[ "color_pars_vertex" ],
  12236. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12237. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12238. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12239. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12240. "void main() {",
  12241. THREE.ShaderChunk[ "uv_vertex" ],
  12242. THREE.ShaderChunk[ "uv2_vertex" ],
  12243. THREE.ShaderChunk[ "color_vertex" ],
  12244. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12245. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12246. THREE.ShaderChunk[ "skinbase_vertex" ],
  12247. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12248. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12249. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  12250. " vNormal = normalize( transformedNormal );",
  12251. "#endif",
  12252. THREE.ShaderChunk[ "begin_vertex" ],
  12253. THREE.ShaderChunk[ "displacementmap_vertex" ],
  12254. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12255. THREE.ShaderChunk[ "skinning_vertex" ],
  12256. THREE.ShaderChunk[ "project_vertex" ],
  12257. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12258. " vViewPosition = - mvPosition.xyz;",
  12259. THREE.ShaderChunk[ "worldpos_vertex" ],
  12260. THREE.ShaderChunk[ "envmap_vertex" ],
  12261. THREE.ShaderChunk[ "lights_phong_vertex" ],
  12262. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12263. "}"
  12264. ].join( "\n" ),
  12265. fragmentShader: [
  12266. "#define PHONG",
  12267. "uniform vec3 diffuse;",
  12268. "uniform vec3 emissive;",
  12269. "uniform vec3 specular;",
  12270. "uniform float shininess;",
  12271. "uniform float opacity;",
  12272. THREE.ShaderChunk[ "common" ],
  12273. THREE.ShaderChunk[ "color_pars_fragment" ],
  12274. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12275. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12276. THREE.ShaderChunk[ "map_pars_fragment" ],
  12277. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12278. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12279. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  12280. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  12281. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12282. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12283. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  12284. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12285. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  12286. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  12287. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12288. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12289. "void main() {",
  12290. " vec3 outgoingLight = vec3( 0.0 );",
  12291. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12292. " vec3 totalAmbientLight = ambientLightColor;",
  12293. " vec3 totalEmissiveLight = emissive;",
  12294. " vec3 shadowMask = vec3( 1.0 );",
  12295. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12296. THREE.ShaderChunk[ "map_fragment" ],
  12297. THREE.ShaderChunk[ "color_fragment" ],
  12298. THREE.ShaderChunk[ "alphamap_fragment" ],
  12299. THREE.ShaderChunk[ "alphatest_fragment" ],
  12300. THREE.ShaderChunk[ "specularmap_fragment" ],
  12301. THREE.ShaderChunk[ "normal_phong_fragment" ],
  12302. THREE.ShaderChunk[ "lightmap_fragment" ],
  12303. THREE.ShaderChunk[ "hemilight_fragment" ],
  12304. THREE.ShaderChunk[ "aomap_fragment" ],
  12305. THREE.ShaderChunk[ "emissivemap_fragment" ],
  12306. THREE.ShaderChunk[ "lights_phong_fragment" ],
  12307. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12308. "totalDiffuseLight *= shadowMask;",
  12309. "totalSpecularLight *= shadowMask;",
  12310. "#ifdef METAL",
  12311. " outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;",
  12312. "#else",
  12313. " outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;",
  12314. "#endif",
  12315. THREE.ShaderChunk[ "envmap_fragment" ],
  12316. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12317. THREE.ShaderChunk[ "fog_fragment" ],
  12318. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12319. "}"
  12320. ].join( "\n" )
  12321. },
  12322. 'points': {
  12323. uniforms: THREE.UniformsUtils.merge( [
  12324. THREE.UniformsLib[ "points" ],
  12325. THREE.UniformsLib[ "shadowmap" ]
  12326. ] ),
  12327. vertexShader: [
  12328. "uniform float size;",
  12329. "uniform float scale;",
  12330. THREE.ShaderChunk[ "common" ],
  12331. THREE.ShaderChunk[ "color_pars_vertex" ],
  12332. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12333. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12334. "void main() {",
  12335. THREE.ShaderChunk[ "color_vertex" ],
  12336. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12337. " #ifdef USE_SIZEATTENUATION",
  12338. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  12339. " #else",
  12340. " gl_PointSize = size;",
  12341. " #endif",
  12342. " gl_Position = projectionMatrix * mvPosition;",
  12343. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12344. THREE.ShaderChunk[ "worldpos_vertex" ],
  12345. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12346. "}"
  12347. ].join( "\n" ),
  12348. fragmentShader: [
  12349. "uniform vec3 psColor;",
  12350. "uniform float opacity;",
  12351. THREE.ShaderChunk[ "common" ],
  12352. THREE.ShaderChunk[ "color_pars_fragment" ],
  12353. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  12354. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12355. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12356. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12357. "void main() {",
  12358. " vec3 outgoingLight = vec3( 0.0 );",
  12359. " vec4 diffuseColor = vec4( psColor, opacity );",
  12360. " vec3 shadowMask = vec3( 1.0 );",
  12361. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12362. THREE.ShaderChunk[ "map_particle_fragment" ],
  12363. THREE.ShaderChunk[ "color_fragment" ],
  12364. THREE.ShaderChunk[ "alphatest_fragment" ],
  12365. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12366. " outgoingLight = diffuseColor.rgb * shadowMask;",
  12367. THREE.ShaderChunk[ "fog_fragment" ],
  12368. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12369. "}"
  12370. ].join( "\n" )
  12371. },
  12372. 'dashed': {
  12373. uniforms: THREE.UniformsUtils.merge( [
  12374. THREE.UniformsLib[ "common" ],
  12375. THREE.UniformsLib[ "fog" ],
  12376. {
  12377. "scale" : { type: "f", value: 1 },
  12378. "dashSize" : { type: "f", value: 1 },
  12379. "totalSize": { type: "f", value: 2 }
  12380. }
  12381. ] ),
  12382. vertexShader: [
  12383. "uniform float scale;",
  12384. "attribute float lineDistance;",
  12385. "varying float vLineDistance;",
  12386. THREE.ShaderChunk[ "common" ],
  12387. THREE.ShaderChunk[ "color_pars_vertex" ],
  12388. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12389. "void main() {",
  12390. THREE.ShaderChunk[ "color_vertex" ],
  12391. " vLineDistance = scale * lineDistance;",
  12392. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12393. " gl_Position = projectionMatrix * mvPosition;",
  12394. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12395. "}"
  12396. ].join( "\n" ),
  12397. fragmentShader: [
  12398. "uniform vec3 diffuse;",
  12399. "uniform float opacity;",
  12400. "uniform float dashSize;",
  12401. "uniform float totalSize;",
  12402. "varying float vLineDistance;",
  12403. THREE.ShaderChunk[ "common" ],
  12404. THREE.ShaderChunk[ "color_pars_fragment" ],
  12405. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12406. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12407. "void main() {",
  12408. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  12409. " discard;",
  12410. " }",
  12411. " vec3 outgoingLight = vec3( 0.0 );",
  12412. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12413. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12414. THREE.ShaderChunk[ "color_fragment" ],
  12415. " outgoingLight = diffuseColor.rgb;", // simple shader
  12416. THREE.ShaderChunk[ "fog_fragment" ],
  12417. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12418. "}"
  12419. ].join( "\n" )
  12420. },
  12421. 'depth': {
  12422. uniforms: {
  12423. "mNear": { type: "f", value: 1.0 },
  12424. "mFar" : { type: "f", value: 2000.0 },
  12425. "opacity" : { type: "f", value: 1.0 }
  12426. },
  12427. vertexShader: [
  12428. THREE.ShaderChunk[ "common" ],
  12429. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12430. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12431. "void main() {",
  12432. THREE.ShaderChunk[ "begin_vertex" ],
  12433. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12434. THREE.ShaderChunk[ "project_vertex" ],
  12435. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12436. "}"
  12437. ].join( "\n" ),
  12438. fragmentShader: [
  12439. "uniform float mNear;",
  12440. "uniform float mFar;",
  12441. "uniform float opacity;",
  12442. THREE.ShaderChunk[ "common" ],
  12443. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12444. "void main() {",
  12445. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12446. " #ifdef USE_LOGDEPTHBUF_EXT",
  12447. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  12448. " #else",
  12449. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  12450. " #endif",
  12451. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  12452. " gl_FragColor = vec4( vec3( color ), opacity );",
  12453. "}"
  12454. ].join( "\n" )
  12455. },
  12456. 'normal': {
  12457. uniforms: {
  12458. "opacity" : { type: "f", value: 1.0 }
  12459. },
  12460. vertexShader: [
  12461. "varying vec3 vNormal;",
  12462. THREE.ShaderChunk[ "common" ],
  12463. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12464. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12465. "void main() {",
  12466. " vNormal = normalize( normalMatrix * normal );",
  12467. THREE.ShaderChunk[ "begin_vertex" ],
  12468. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12469. THREE.ShaderChunk[ "project_vertex" ],
  12470. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12471. "}"
  12472. ].join( "\n" ),
  12473. fragmentShader: [
  12474. "uniform float opacity;",
  12475. "varying vec3 vNormal;",
  12476. THREE.ShaderChunk[ "common" ],
  12477. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12478. "void main() {",
  12479. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  12480. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12481. "}"
  12482. ].join( "\n" )
  12483. },
  12484. /* -------------------------------------------------------------------------
  12485. // Cube map shader
  12486. ------------------------------------------------------------------------- */
  12487. 'cube': {
  12488. uniforms: { "tCube": { type: "t", value: null },
  12489. "tFlip": { type: "f", value: - 1 } },
  12490. vertexShader: [
  12491. "varying vec3 vWorldPosition;",
  12492. THREE.ShaderChunk[ "common" ],
  12493. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12494. "void main() {",
  12495. " vWorldPosition = transformDirection( position, modelMatrix );",
  12496. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12497. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12498. "}"
  12499. ].join( "\n" ),
  12500. fragmentShader: [
  12501. "uniform samplerCube tCube;",
  12502. "uniform float tFlip;",
  12503. "varying vec3 vWorldPosition;",
  12504. THREE.ShaderChunk[ "common" ],
  12505. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12506. "void main() {",
  12507. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12508. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12509. "}"
  12510. ].join( "\n" )
  12511. },
  12512. /* -------------------------------------------------------------------------
  12513. // Cube map shader
  12514. ------------------------------------------------------------------------- */
  12515. 'equirect': {
  12516. uniforms: { "tEquirect": { type: "t", value: null },
  12517. "tFlip": { type: "f", value: - 1 } },
  12518. vertexShader: [
  12519. "varying vec3 vWorldPosition;",
  12520. THREE.ShaderChunk[ "common" ],
  12521. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12522. "void main() {",
  12523. " vWorldPosition = transformDirection( position, modelMatrix );",
  12524. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12525. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12526. "}"
  12527. ].join( "\n" ),
  12528. fragmentShader: [
  12529. "uniform sampler2D tEquirect;",
  12530. "uniform float tFlip;",
  12531. "varying vec3 vWorldPosition;",
  12532. THREE.ShaderChunk[ "common" ],
  12533. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12534. "void main() {",
  12535. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12536. "vec3 direction = normalize( vWorldPosition );",
  12537. "vec2 sampleUV;",
  12538. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  12539. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  12540. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  12541. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12542. "}"
  12543. ].join( "\n" )
  12544. },
  12545. /* Depth encoding into RGBA texture
  12546. *
  12547. * based on SpiderGL shadow map example
  12548. * http://spidergl.org/example.php?id=6
  12549. *
  12550. * originally from
  12551. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  12552. *
  12553. * see also
  12554. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  12555. */
  12556. 'depthRGBA': {
  12557. uniforms: {},
  12558. vertexShader: [
  12559. THREE.ShaderChunk[ "common" ],
  12560. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12561. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12562. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12563. "void main() {",
  12564. THREE.ShaderChunk[ "skinbase_vertex" ],
  12565. THREE.ShaderChunk[ "begin_vertex" ],
  12566. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12567. THREE.ShaderChunk[ "skinning_vertex" ],
  12568. THREE.ShaderChunk[ "project_vertex" ],
  12569. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12570. "}"
  12571. ].join( "\n" ),
  12572. fragmentShader: [
  12573. THREE.ShaderChunk[ "common" ],
  12574. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12575. "vec4 pack_depth( const in float depth ) {",
  12576. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12577. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12578. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  12579. " res -= res.xxyz * bit_mask;",
  12580. " return res;",
  12581. "}",
  12582. "void main() {",
  12583. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12584. " #ifdef USE_LOGDEPTHBUF_EXT",
  12585. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  12586. " #else",
  12587. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  12588. " #endif",
  12589. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  12590. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  12591. //"gl_FragData[ 0 ] = pack_depth( z );",
  12592. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  12593. "}"
  12594. ].join( "\n" )
  12595. },
  12596. 'distanceRGBA': {
  12597. uniforms: {
  12598. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  12599. },
  12600. vertexShader: [
  12601. "varying vec4 vWorldPosition;",
  12602. THREE.ShaderChunk[ "common" ],
  12603. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12604. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12605. "void main() {",
  12606. THREE.ShaderChunk[ "skinbase_vertex" ],
  12607. THREE.ShaderChunk[ "begin_vertex" ],
  12608. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12609. THREE.ShaderChunk[ "skinning_vertex" ],
  12610. THREE.ShaderChunk[ "project_vertex" ],
  12611. THREE.ShaderChunk[ "worldpos_vertex" ],
  12612. "vWorldPosition = worldPosition;",
  12613. "}"
  12614. ].join( "\n" ),
  12615. fragmentShader: [
  12616. "uniform vec3 lightPos;",
  12617. "varying vec4 vWorldPosition;",
  12618. THREE.ShaderChunk[ "common" ],
  12619. "vec4 pack1K ( float depth ) {",
  12620. " depth /= 1000.0;",
  12621. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12622. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12623. " vec4 res = fract( depth * bitSh );",
  12624. " res -= res.xxyz * bitMsk;",
  12625. " return res; ",
  12626. "}",
  12627. "float unpack1K ( vec4 color ) {",
  12628. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  12629. " return dot( color, bitSh ) * 1000.0;",
  12630. "}",
  12631. "void main () {",
  12632. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  12633. "}"
  12634. ].join( "\n" )
  12635. }
  12636. };
  12637. // File:src/renderers/WebGLRenderer.js
  12638. /**
  12639. * @author supereggbert / http://www.paulbrunt.co.uk/
  12640. * @author mrdoob / http://mrdoob.com/
  12641. * @author alteredq / http://alteredqualia.com/
  12642. * @author szimek / https://github.com/szimek/
  12643. */
  12644. THREE.WebGLRenderer = function ( parameters ) {
  12645. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  12646. parameters = parameters || {};
  12647. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  12648. _context = parameters.context !== undefined ? parameters.context : null,
  12649. _width = _canvas.width,
  12650. _height = _canvas.height,
  12651. pixelRatio = 1,
  12652. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  12653. _depth = parameters.depth !== undefined ? parameters.depth : true,
  12654. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  12655. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  12656. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  12657. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  12658. _clearColor = new THREE.Color( 0x000000 ),
  12659. _clearAlpha = 0;
  12660. var lights = [];
  12661. var opaqueObjects = [];
  12662. var opaqueObjectsLastIndex = - 1;
  12663. var transparentObjects = [];
  12664. var transparentObjectsLastIndex = - 1;
  12665. var morphInfluences = new Float32Array( 8 );
  12666. var sprites = [];
  12667. var lensFlares = [];
  12668. // public properties
  12669. this.domElement = _canvas;
  12670. this.context = null;
  12671. // clearing
  12672. this.autoClear = true;
  12673. this.autoClearColor = true;
  12674. this.autoClearDepth = true;
  12675. this.autoClearStencil = true;
  12676. // scene graph
  12677. this.sortObjects = true;
  12678. // physically based shading
  12679. this.gammaFactor = 2.0; // for backwards compatibility
  12680. this.gammaInput = false;
  12681. this.gammaOutput = false;
  12682. // morphs
  12683. this.maxMorphTargets = 8;
  12684. this.maxMorphNormals = 4;
  12685. // flags
  12686. this.autoScaleCubemaps = true;
  12687. // internal properties
  12688. var _this = this,
  12689. // internal state cache
  12690. _currentProgram = null,
  12691. _currentFramebuffer = null,
  12692. _currentMaterialId = - 1,
  12693. _currentGeometryProgram = '',
  12694. _currentCamera = null,
  12695. _usedTextureUnits = 0,
  12696. _viewportX = 0,
  12697. _viewportY = 0,
  12698. _viewportWidth = _canvas.width,
  12699. _viewportHeight = _canvas.height,
  12700. _currentWidth = 0,
  12701. _currentHeight = 0,
  12702. // frustum
  12703. _frustum = new THREE.Frustum(),
  12704. // camera matrices cache
  12705. _projScreenMatrix = new THREE.Matrix4(),
  12706. _vector3 = new THREE.Vector3(),
  12707. // light arrays cache
  12708. _direction = new THREE.Vector3(),
  12709. _lightsNeedUpdate = true,
  12710. _lights = {
  12711. ambient: [ 0, 0, 0 ],
  12712. directional: { length: 0, colors: [], positions: [] },
  12713. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  12714. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  12715. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  12716. },
  12717. // info
  12718. _infoMemory = {
  12719. geometries: 0,
  12720. textures: 0
  12721. },
  12722. _infoRender = {
  12723. calls: 0,
  12724. vertices: 0,
  12725. faces: 0,
  12726. points: 0
  12727. };
  12728. this.info = {
  12729. render: _infoRender,
  12730. memory: _infoMemory,
  12731. programs: null
  12732. };
  12733. // initialize
  12734. var _gl;
  12735. try {
  12736. var attributes = {
  12737. alpha: _alpha,
  12738. depth: _depth,
  12739. stencil: _stencil,
  12740. antialias: _antialias,
  12741. premultipliedAlpha: _premultipliedAlpha,
  12742. preserveDrawingBuffer: _preserveDrawingBuffer
  12743. };
  12744. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  12745. if ( _gl === null ) {
  12746. if ( _canvas.getContext( 'webgl' ) !== null ) {
  12747. throw 'Error creating WebGL context with your selected attributes.';
  12748. } else {
  12749. throw 'Error creating WebGL context.';
  12750. }
  12751. }
  12752. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  12753. } catch ( error ) {
  12754. console.error( 'THREE.WebGLRenderer: ' + error );
  12755. }
  12756. var extensions = new THREE.WebGLExtensions( _gl );
  12757. extensions.get( 'OES_texture_float' );
  12758. extensions.get( 'OES_texture_float_linear' );
  12759. extensions.get( 'OES_texture_half_float' );
  12760. extensions.get( 'OES_texture_half_float_linear' );
  12761. extensions.get( 'OES_standard_derivatives' );
  12762. extensions.get( 'ANGLE_instanced_arrays' );
  12763. if ( extensions.get( 'OES_element_index_uint' ) ) {
  12764. THREE.BufferGeometry.MaxIndex = 4294967296;
  12765. }
  12766. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  12767. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  12768. var properties = new THREE.WebGLProperties();
  12769. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  12770. var programCache = new THREE.WebGLPrograms( this, capabilities );
  12771. this.info.programs = programCache.programs;
  12772. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  12773. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  12774. //
  12775. function glClearColor( r, g, b, a ) {
  12776. if ( _premultipliedAlpha === true ) {
  12777. r *= a; g *= a; b *= a;
  12778. }
  12779. _gl.clearColor( r, g, b, a );
  12780. }
  12781. function setDefaultGLState() {
  12782. state.init();
  12783. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12784. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12785. }
  12786. function resetGLState() {
  12787. _currentProgram = null;
  12788. _currentCamera = null;
  12789. _currentGeometryProgram = '';
  12790. _currentMaterialId = - 1;
  12791. _lightsNeedUpdate = true;
  12792. state.reset();
  12793. }
  12794. setDefaultGLState();
  12795. this.context = _gl;
  12796. this.capabilities = capabilities;
  12797. this.extensions = extensions;
  12798. this.state = state;
  12799. // shadow map
  12800. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  12801. this.shadowMap = shadowMap;
  12802. // Plugins
  12803. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  12804. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  12805. // API
  12806. this.getContext = function () {
  12807. return _gl;
  12808. };
  12809. this.getContextAttributes = function () {
  12810. return _gl.getContextAttributes();
  12811. };
  12812. this.forceContextLoss = function () {
  12813. extensions.get( 'WEBGL_lose_context' ).loseContext();
  12814. };
  12815. this.getMaxAnisotropy = ( function () {
  12816. var value;
  12817. return function getMaxAnisotropy() {
  12818. if ( value !== undefined ) return value;
  12819. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12820. if ( extension !== null ) {
  12821. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  12822. } else {
  12823. value = 0;
  12824. }
  12825. return value;
  12826. }
  12827. } )();
  12828. this.getPrecision = function () {
  12829. return capabilities.precision;
  12830. };
  12831. this.getPixelRatio = function () {
  12832. return pixelRatio;
  12833. };
  12834. this.setPixelRatio = function ( value ) {
  12835. if ( value !== undefined ) pixelRatio = value;
  12836. };
  12837. this.getSize = function () {
  12838. return {
  12839. width: _width,
  12840. height: _height
  12841. };
  12842. };
  12843. this.setSize = function ( width, height, updateStyle ) {
  12844. _width = width;
  12845. _height = height;
  12846. _canvas.width = width * pixelRatio;
  12847. _canvas.height = height * pixelRatio;
  12848. if ( updateStyle !== false ) {
  12849. _canvas.style.width = width + 'px';
  12850. _canvas.style.height = height + 'px';
  12851. }
  12852. this.setViewport( 0, 0, width, height );
  12853. };
  12854. this.setViewport = function ( x, y, width, height ) {
  12855. _viewportX = x * pixelRatio;
  12856. _viewportY = y * pixelRatio;
  12857. _viewportWidth = width * pixelRatio;
  12858. _viewportHeight = height * pixelRatio;
  12859. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12860. };
  12861. this.getViewport = function ( dimensions ) {
  12862. dimensions.x = _viewportX / pixelRatio;
  12863. dimensions.y = _viewportY / pixelRatio;
  12864. dimensions.z = _viewportWidth / pixelRatio;
  12865. dimensions.w = _viewportHeight / pixelRatio;
  12866. };
  12867. this.setScissor = function ( x, y, width, height ) {
  12868. _gl.scissor(
  12869. x * pixelRatio,
  12870. y * pixelRatio,
  12871. width * pixelRatio,
  12872. height * pixelRatio
  12873. );
  12874. };
  12875. this.enableScissorTest = function ( boolean ) {
  12876. state.setScissorTest( boolean );
  12877. };
  12878. // Clearing
  12879. this.getClearColor = function () {
  12880. return _clearColor;
  12881. };
  12882. this.setClearColor = function ( color, alpha ) {
  12883. _clearColor.set( color );
  12884. _clearAlpha = alpha !== undefined ? alpha : 1;
  12885. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12886. };
  12887. this.getClearAlpha = function () {
  12888. return _clearAlpha;
  12889. };
  12890. this.setClearAlpha = function ( alpha ) {
  12891. _clearAlpha = alpha;
  12892. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12893. };
  12894. this.clear = function ( color, depth, stencil ) {
  12895. var bits = 0;
  12896. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  12897. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  12898. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  12899. _gl.clear( bits );
  12900. };
  12901. this.clearColor = function () {
  12902. _gl.clear( _gl.COLOR_BUFFER_BIT );
  12903. };
  12904. this.clearDepth = function () {
  12905. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  12906. };
  12907. this.clearStencil = function () {
  12908. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  12909. };
  12910. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  12911. this.setRenderTarget( renderTarget );
  12912. this.clear( color, depth, stencil );
  12913. };
  12914. // Reset
  12915. this.resetGLState = resetGLState;
  12916. this.dispose = function() {
  12917. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  12918. };
  12919. // Events
  12920. function onContextLost( event ) {
  12921. event.preventDefault();
  12922. resetGLState();
  12923. setDefaultGLState();
  12924. properties.clear();
  12925. };
  12926. function onTextureDispose( event ) {
  12927. var texture = event.target;
  12928. texture.removeEventListener( 'dispose', onTextureDispose );
  12929. deallocateTexture( texture );
  12930. _infoMemory.textures --;
  12931. }
  12932. function onRenderTargetDispose( event ) {
  12933. var renderTarget = event.target;
  12934. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  12935. deallocateRenderTarget( renderTarget );
  12936. _infoMemory.textures --;
  12937. }
  12938. function onMaterialDispose( event ) {
  12939. var material = event.target;
  12940. material.removeEventListener( 'dispose', onMaterialDispose );
  12941. deallocateMaterial( material );
  12942. }
  12943. // Buffer deallocation
  12944. function deallocateTexture( texture ) {
  12945. var textureProperties = properties.get( texture );
  12946. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  12947. // cube texture
  12948. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  12949. } else {
  12950. // 2D texture
  12951. if ( textureProperties.__webglInit === undefined ) return;
  12952. _gl.deleteTexture( textureProperties.__webglTexture );
  12953. }
  12954. // remove all webgl properties
  12955. properties.delete( texture );
  12956. }
  12957. function deallocateRenderTarget( renderTarget ) {
  12958. var renderTargetProperties = properties.get( renderTarget );
  12959. var textureProperties = properties.get( renderTarget.texture );
  12960. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  12961. _gl.deleteTexture( textureProperties.__webglTexture );
  12962. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  12963. for ( var i = 0; i < 6; i ++ ) {
  12964. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  12965. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  12966. }
  12967. } else {
  12968. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  12969. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  12970. }
  12971. properties.delete( renderTarget.texture );
  12972. properties.delete( renderTarget );
  12973. }
  12974. function deallocateMaterial( material ) {
  12975. releaseMaterialProgramReference( material );
  12976. properties.delete( material );
  12977. }
  12978. function releaseMaterialProgramReference( material ) {
  12979. var programInfo = properties.get( material ).program;
  12980. material.program = undefined;
  12981. if ( programInfo !== undefined ) {
  12982. programCache.releaseProgram( programInfo );
  12983. }
  12984. }
  12985. // Buffer rendering
  12986. this.renderBufferImmediate = function ( object, program, material ) {
  12987. state.initAttributes();
  12988. var buffers = properties.get( object );
  12989. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  12990. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  12991. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  12992. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  12993. var attributes = program.getAttributes();
  12994. if ( object.hasPositions ) {
  12995. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  12996. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  12997. state.enableAttribute( attributes.position );
  12998. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  12999. }
  13000. if ( object.hasNormals ) {
  13001. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  13002. if ( material.type !== 'MeshPhongMaterial' && material.shading === THREE.FlatShading ) {
  13003. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  13004. var array = object.normalArray;
  13005. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  13006. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  13007. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  13008. array[ i + 0 ] = nx;
  13009. array[ i + 1 ] = ny;
  13010. array[ i + 2 ] = nz;
  13011. array[ i + 3 ] = nx;
  13012. array[ i + 4 ] = ny;
  13013. array[ i + 5 ] = nz;
  13014. array[ i + 6 ] = nx;
  13015. array[ i + 7 ] = ny;
  13016. array[ i + 8 ] = nz;
  13017. }
  13018. }
  13019. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  13020. state.enableAttribute( attributes.normal );
  13021. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  13022. }
  13023. if ( object.hasUvs && material.map ) {
  13024. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  13025. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  13026. state.enableAttribute( attributes.uv );
  13027. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  13028. }
  13029. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  13030. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  13031. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  13032. state.enableAttribute( attributes.color );
  13033. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  13034. }
  13035. state.disableUnusedAttributes();
  13036. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  13037. object.count = 0;
  13038. };
  13039. this.renderBufferDirect = function ( camera, lights, fog, geometry, material, object, group ) {
  13040. setMaterial( material );
  13041. var program = setProgram( camera, lights, fog, material, object );
  13042. var updateBuffers = false;
  13043. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  13044. if ( geometryProgram !== _currentGeometryProgram ) {
  13045. _currentGeometryProgram = geometryProgram;
  13046. updateBuffers = true;
  13047. }
  13048. // morph targets
  13049. var morphTargetInfluences = object.morphTargetInfluences;
  13050. if ( morphTargetInfluences !== undefined ) {
  13051. var activeInfluences = [];
  13052. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  13053. var influence = morphTargetInfluences[ i ];
  13054. activeInfluences.push( [ influence, i ] );
  13055. }
  13056. activeInfluences.sort( numericalSort );
  13057. if ( activeInfluences.length > 8 ) {
  13058. activeInfluences.length = 8;
  13059. }
  13060. var morphAttributes = geometry.morphAttributes;
  13061. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  13062. var influence = activeInfluences[ i ];
  13063. morphInfluences[ i ] = influence[ 0 ];
  13064. if ( influence[ 0 ] !== 0 ) {
  13065. var index = influence[ 1 ];
  13066. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  13067. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  13068. } else {
  13069. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  13070. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  13071. }
  13072. }
  13073. var uniforms = program.getUniforms();
  13074. if ( uniforms.morphTargetInfluences !== null ) {
  13075. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  13076. }
  13077. updateBuffers = true;
  13078. }
  13079. //
  13080. var index = geometry.index;
  13081. var position = geometry.attributes.position;
  13082. if ( material.wireframe === true ) {
  13083. index = objects.getWireframeAttribute( geometry );
  13084. }
  13085. var renderer;
  13086. if ( index !== null ) {
  13087. renderer = indexedBufferRenderer;
  13088. renderer.setIndex( index );
  13089. } else {
  13090. renderer = bufferRenderer;
  13091. }
  13092. if ( updateBuffers ) {
  13093. setupVertexAttributes( material, program, geometry );
  13094. if ( index !== null ) {
  13095. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  13096. }
  13097. }
  13098. //
  13099. var dataStart = 0;
  13100. var dataCount = Infinity;
  13101. if ( index !== null ) {
  13102. dataCount = index.count
  13103. } else if ( position !== undefined ) {
  13104. dataCount = position.count;
  13105. }
  13106. var rangeStart = geometry.drawRange.start;
  13107. var rangeCount = geometry.drawRange.count;
  13108. var groupStart = group !== null ? group.start : 0;
  13109. var groupCount = group !== null ? group.count : Infinity;
  13110. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  13111. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13112. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13113. //
  13114. if ( object instanceof THREE.Mesh ) {
  13115. if ( material.wireframe === true ) {
  13116. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  13117. renderer.setMode( _gl.LINES );
  13118. } else {
  13119. renderer.setMode( _gl.TRIANGLES );
  13120. }
  13121. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  13122. renderer.renderInstances( geometry );
  13123. } else {
  13124. renderer.render( drawStart, drawCount );
  13125. }
  13126. } else if ( object instanceof THREE.Line ) {
  13127. var lineWidth = material.linewidth;
  13128. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13129. state.setLineWidth( lineWidth * pixelRatio );
  13130. if ( object instanceof THREE.LineSegments ) {
  13131. renderer.setMode( _gl.LINES );
  13132. } else {
  13133. renderer.setMode( _gl.LINE_STRIP );
  13134. }
  13135. renderer.render( drawStart, drawCount );
  13136. } else if ( object instanceof THREE.Points ) {
  13137. renderer.setMode( _gl.POINTS );
  13138. renderer.render( drawStart, drawCount );
  13139. }
  13140. };
  13141. function setupVertexAttributes( material, program, geometry, startIndex ) {
  13142. var extension;
  13143. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  13144. extension = extensions.get( 'ANGLE_instanced_arrays' );
  13145. if ( extension === null ) {
  13146. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13147. return;
  13148. }
  13149. }
  13150. if ( startIndex === undefined ) startIndex = 0;
  13151. state.initAttributes();
  13152. var geometryAttributes = geometry.attributes;
  13153. var programAttributes = program.getAttributes();
  13154. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13155. for ( var name in programAttributes ) {
  13156. var programAttribute = programAttributes[ name ];
  13157. if ( programAttribute >= 0 ) {
  13158. var geometryAttribute = geometryAttributes[ name ];
  13159. if ( geometryAttribute !== undefined ) {
  13160. var size = geometryAttribute.itemSize;
  13161. var buffer = objects.getAttributeBuffer( geometryAttribute );
  13162. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  13163. var data = geometryAttribute.data;
  13164. var stride = data.stride;
  13165. var offset = geometryAttribute.offset;
  13166. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  13167. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  13168. if ( geometry.maxInstancedCount === undefined ) {
  13169. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13170. }
  13171. } else {
  13172. state.enableAttribute( programAttribute );
  13173. }
  13174. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13175. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  13176. } else {
  13177. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  13178. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  13179. if ( geometry.maxInstancedCount === undefined ) {
  13180. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13181. }
  13182. } else {
  13183. state.enableAttribute( programAttribute );
  13184. }
  13185. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13186. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  13187. }
  13188. } else if ( materialDefaultAttributeValues !== undefined ) {
  13189. var value = materialDefaultAttributeValues[ name ];
  13190. if ( value !== undefined ) {
  13191. switch ( value.length ) {
  13192. case 2:
  13193. _gl.vertexAttrib2fv( programAttribute, value );
  13194. break;
  13195. case 3:
  13196. _gl.vertexAttrib3fv( programAttribute, value );
  13197. break;
  13198. case 4:
  13199. _gl.vertexAttrib4fv( programAttribute, value );
  13200. break;
  13201. default:
  13202. _gl.vertexAttrib1fv( programAttribute, value );
  13203. }
  13204. }
  13205. }
  13206. }
  13207. }
  13208. state.disableUnusedAttributes();
  13209. }
  13210. // Sorting
  13211. function numericalSort ( a, b ) {
  13212. return b[ 0 ] - a[ 0 ];
  13213. }
  13214. function painterSortStable ( a, b ) {
  13215. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13216. return a.object.renderOrder - b.object.renderOrder;
  13217. } else if ( a.material.id !== b.material.id ) {
  13218. return a.material.id - b.material.id;
  13219. } else if ( a.z !== b.z ) {
  13220. return a.z - b.z;
  13221. } else {
  13222. return a.id - b.id;
  13223. }
  13224. }
  13225. function reversePainterSortStable ( a, b ) {
  13226. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13227. return a.object.renderOrder - b.object.renderOrder;
  13228. } if ( a.z !== b.z ) {
  13229. return b.z - a.z;
  13230. } else {
  13231. return a.id - b.id;
  13232. }
  13233. }
  13234. // Rendering
  13235. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13236. if ( camera instanceof THREE.Camera === false ) {
  13237. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13238. return;
  13239. }
  13240. var fog = scene.fog;
  13241. // reset caching for this frame
  13242. _currentGeometryProgram = '';
  13243. _currentMaterialId = - 1;
  13244. _currentCamera = null;
  13245. _lightsNeedUpdate = true;
  13246. // update scene graph
  13247. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13248. // update camera matrices and frustum
  13249. if ( camera.parent === null ) camera.updateMatrixWorld();
  13250. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13251. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13252. _frustum.setFromMatrix( _projScreenMatrix );
  13253. lights.length = 0;
  13254. opaqueObjectsLastIndex = - 1;
  13255. transparentObjectsLastIndex = - 1;
  13256. sprites.length = 0;
  13257. lensFlares.length = 0;
  13258. projectObject( scene );
  13259. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  13260. transparentObjects.length = transparentObjectsLastIndex + 1;
  13261. if ( _this.sortObjects === true ) {
  13262. opaqueObjects.sort( painterSortStable );
  13263. transparentObjects.sort( reversePainterSortStable );
  13264. }
  13265. //
  13266. shadowMap.render( scene );
  13267. //
  13268. _infoRender.calls = 0;
  13269. _infoRender.vertices = 0;
  13270. _infoRender.faces = 0;
  13271. _infoRender.points = 0;
  13272. this.setRenderTarget( renderTarget );
  13273. if ( this.autoClear || forceClear ) {
  13274. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  13275. }
  13276. //
  13277. if ( scene.overrideMaterial ) {
  13278. var overrideMaterial = scene.overrideMaterial;
  13279. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  13280. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  13281. } else {
  13282. // opaque pass (front-to-back order)
  13283. state.setBlending( THREE.NoBlending );
  13284. renderObjects( opaqueObjects, camera, lights, fog );
  13285. // transparent pass (back-to-front order)
  13286. renderObjects( transparentObjects, camera, lights, fog );
  13287. }
  13288. // custom render plugins (post pass)
  13289. spritePlugin.render( scene, camera );
  13290. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  13291. // Generate mipmap if we're using any kind of mipmap filtering
  13292. if ( renderTarget ) {
  13293. var texture = renderTarget.texture;
  13294. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget );
  13295. if ( texture.generateMipmaps && isTargetPowerOfTwo && texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13296. updateRenderTargetMipmap( renderTarget );
  13297. }
  13298. }
  13299. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13300. state.setDepthTest( true );
  13301. state.setDepthWrite( true );
  13302. state.setColorWrite( true );
  13303. // _gl.finish();
  13304. };
  13305. function pushRenderItem( object, geometry, material, z, group ) {
  13306. var array, index;
  13307. // allocate the next position in the appropriate array
  13308. if ( material.transparent ) {
  13309. array = transparentObjects;
  13310. index = ++ transparentObjectsLastIndex;
  13311. } else {
  13312. array = opaqueObjects;
  13313. index = ++ opaqueObjectsLastIndex;
  13314. }
  13315. // recycle existing render item or grow the array
  13316. var renderItem = array[ index ];
  13317. if ( renderItem !== undefined ) {
  13318. renderItem.id = object.id;
  13319. renderItem.object = object;
  13320. renderItem.geometry = geometry;
  13321. renderItem.material = material;
  13322. renderItem.z = _vector3.z;
  13323. renderItem.group = group;
  13324. } else {
  13325. renderItem = {
  13326. id: object.id,
  13327. object: object,
  13328. geometry: geometry,
  13329. material: material,
  13330. z: _vector3.z,
  13331. group: group
  13332. };
  13333. // assert( index === array.length );
  13334. array.push( renderItem );
  13335. }
  13336. }
  13337. function projectObject( object ) {
  13338. if ( object.visible === false ) return;
  13339. if ( object instanceof THREE.Light ) {
  13340. lights.push( object );
  13341. } else if ( object instanceof THREE.Sprite ) {
  13342. sprites.push( object );
  13343. } else if ( object instanceof THREE.LensFlare ) {
  13344. lensFlares.push( object );
  13345. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  13346. if ( _this.sortObjects === true ) {
  13347. _vector3.setFromMatrixPosition( object.matrixWorld );
  13348. _vector3.applyProjection( _projScreenMatrix );
  13349. }
  13350. pushRenderItem( object, null, object.material, _vector3.z, null );
  13351. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  13352. if ( object instanceof THREE.SkinnedMesh ) {
  13353. object.skeleton.update();
  13354. }
  13355. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  13356. var material = object.material;
  13357. if ( material.visible === true ) {
  13358. if ( _this.sortObjects === true ) {
  13359. _vector3.setFromMatrixPosition( object.matrixWorld );
  13360. _vector3.applyProjection( _projScreenMatrix );
  13361. }
  13362. var geometry = objects.update( object );
  13363. if ( material instanceof THREE.MeshFaceMaterial ) {
  13364. var groups = geometry.groups;
  13365. var materials = material.materials;
  13366. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13367. var group = groups[ i ];
  13368. var groupMaterial = materials[ group.materialIndex ];
  13369. if ( groupMaterial.visible === true ) {
  13370. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  13371. }
  13372. }
  13373. } else {
  13374. pushRenderItem( object, geometry, material, _vector3.z, null );
  13375. }
  13376. }
  13377. }
  13378. }
  13379. var children = object.children;
  13380. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13381. projectObject( children[ i ] );
  13382. }
  13383. }
  13384. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  13385. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  13386. var renderItem = renderList[ i ];
  13387. var object = renderItem.object;
  13388. var geometry = renderItem.geometry;
  13389. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  13390. var group = renderItem.group;
  13391. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13392. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  13393. if ( object instanceof THREE.ImmediateRenderObject ) {
  13394. setMaterial( material );
  13395. var program = setProgram( camera, lights, fog, material, object );
  13396. _currentGeometryProgram = '';
  13397. object.render( function ( object ) {
  13398. _this.renderBufferImmediate( object, program, material );
  13399. } );
  13400. } else {
  13401. _this.renderBufferDirect( camera, lights, fog, geometry, material, object, group );
  13402. }
  13403. }
  13404. }
  13405. function initMaterial( material, lights, fog, object ) {
  13406. var materialProperties = properties.get( material );
  13407. var parameters = programCache.getParameters( material, lights, fog, object );
  13408. var code = programCache.getProgramCode( material, parameters );
  13409. var program = materialProperties.program;
  13410. var programChange = true;
  13411. if ( program === undefined ) {
  13412. // new material
  13413. material.addEventListener( 'dispose', onMaterialDispose );
  13414. } else if ( program.code !== code ) {
  13415. // changed glsl or parameters
  13416. releaseMaterialProgramReference( material );
  13417. } else if ( parameters.shaderID !== undefined ) {
  13418. // same glsl and uniform list
  13419. return;
  13420. } else {
  13421. // only rebuild uniform list
  13422. programChange = false;
  13423. }
  13424. if ( programChange ) {
  13425. if ( parameters.shaderID ) {
  13426. var shader = THREE.ShaderLib[ parameters.shaderID ];
  13427. materialProperties.__webglShader = {
  13428. name: material.type,
  13429. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  13430. vertexShader: shader.vertexShader,
  13431. fragmentShader: shader.fragmentShader
  13432. };
  13433. } else {
  13434. materialProperties.__webglShader = {
  13435. name: material.type,
  13436. uniforms: material.uniforms,
  13437. vertexShader: material.vertexShader,
  13438. fragmentShader: material.fragmentShader
  13439. };
  13440. }
  13441. material.__webglShader = materialProperties.__webglShader;
  13442. program = programCache.acquireProgram( material, parameters, code );
  13443. materialProperties.program = program;
  13444. material.program = program;
  13445. }
  13446. var attributes = program.getAttributes();
  13447. if ( material.morphTargets ) {
  13448. material.numSupportedMorphTargets = 0;
  13449. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  13450. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  13451. material.numSupportedMorphTargets ++;
  13452. }
  13453. }
  13454. }
  13455. if ( material.morphNormals ) {
  13456. material.numSupportedMorphNormals = 0;
  13457. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  13458. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  13459. material.numSupportedMorphNormals ++;
  13460. }
  13461. }
  13462. }
  13463. materialProperties.uniformsList = [];
  13464. var uniformLocations = materialProperties.program.getUniforms();
  13465. for ( var u in materialProperties.__webglShader.uniforms ) {
  13466. var location = uniformLocations[ u ];
  13467. if ( location ) {
  13468. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  13469. }
  13470. }
  13471. }
  13472. function setMaterial( material ) {
  13473. setMaterialFaces( material );
  13474. if ( material.transparent === true ) {
  13475. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  13476. } else {
  13477. state.setBlending( THREE.NoBlending );
  13478. }
  13479. state.setDepthFunc( material.depthFunc );
  13480. state.setDepthTest( material.depthTest );
  13481. state.setDepthWrite( material.depthWrite );
  13482. state.setColorWrite( material.colorWrite );
  13483. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  13484. }
  13485. function setMaterialFaces( material ) {
  13486. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  13487. state.setFlipSided( material.side === THREE.BackSide );
  13488. }
  13489. function setProgram( camera, lights, fog, material, object ) {
  13490. _usedTextureUnits = 0;
  13491. var materialProperties = properties.get( material );
  13492. if ( material.needsUpdate || ! materialProperties.program ) {
  13493. initMaterial( material, lights, fog, object );
  13494. material.needsUpdate = false;
  13495. }
  13496. var refreshProgram = false;
  13497. var refreshMaterial = false;
  13498. var refreshLights = false;
  13499. var program = materialProperties.program,
  13500. p_uniforms = program.getUniforms(),
  13501. m_uniforms = materialProperties.__webglShader.uniforms;
  13502. if ( program.id !== _currentProgram ) {
  13503. _gl.useProgram( program.program );
  13504. _currentProgram = program.id;
  13505. refreshProgram = true;
  13506. refreshMaterial = true;
  13507. refreshLights = true;
  13508. }
  13509. if ( material.id !== _currentMaterialId ) {
  13510. if ( _currentMaterialId === - 1 ) refreshLights = true;
  13511. _currentMaterialId = material.id;
  13512. refreshMaterial = true;
  13513. }
  13514. if ( refreshProgram || camera !== _currentCamera ) {
  13515. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  13516. if ( capabilities.logarithmicDepthBuffer ) {
  13517. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  13518. }
  13519. if ( camera !== _currentCamera ) _currentCamera = camera;
  13520. // load material specific uniforms
  13521. // (shader material also gets them for the sake of genericity)
  13522. if ( material instanceof THREE.ShaderMaterial ||
  13523. material instanceof THREE.MeshPhongMaterial ||
  13524. material.envMap ) {
  13525. if ( p_uniforms.cameraPosition !== undefined ) {
  13526. _vector3.setFromMatrixPosition( camera.matrixWorld );
  13527. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  13528. }
  13529. }
  13530. if ( material instanceof THREE.MeshPhongMaterial ||
  13531. material instanceof THREE.MeshLambertMaterial ||
  13532. material instanceof THREE.MeshBasicMaterial ||
  13533. material instanceof THREE.ShaderMaterial ||
  13534. material.skinning ) {
  13535. if ( p_uniforms.viewMatrix !== undefined ) {
  13536. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  13537. }
  13538. }
  13539. }
  13540. // skinning uniforms must be set even if material didn't change
  13541. // auto-setting of texture unit for bone texture must go before other textures
  13542. // not sure why, but otherwise weird things happen
  13543. if ( material.skinning ) {
  13544. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  13545. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  13546. }
  13547. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  13548. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  13549. }
  13550. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  13551. if ( p_uniforms.boneTexture !== undefined ) {
  13552. var textureUnit = getTextureUnit();
  13553. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  13554. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  13555. }
  13556. if ( p_uniforms.boneTextureWidth !== undefined ) {
  13557. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  13558. }
  13559. if ( p_uniforms.boneTextureHeight !== undefined ) {
  13560. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  13561. }
  13562. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  13563. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  13564. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  13565. }
  13566. }
  13567. }
  13568. if ( refreshMaterial ) {
  13569. // refresh uniforms common to several materials
  13570. if ( fog && material.fog ) {
  13571. refreshUniformsFog( m_uniforms, fog );
  13572. }
  13573. if ( material instanceof THREE.MeshPhongMaterial ||
  13574. material instanceof THREE.MeshLambertMaterial ||
  13575. material.lights ) {
  13576. if ( _lightsNeedUpdate ) {
  13577. refreshLights = true;
  13578. setupLights( lights, camera );
  13579. _lightsNeedUpdate = false;
  13580. }
  13581. if ( refreshLights ) {
  13582. refreshUniformsLights( m_uniforms, _lights );
  13583. markUniformsLightsNeedsUpdate( m_uniforms, true );
  13584. } else {
  13585. markUniformsLightsNeedsUpdate( m_uniforms, false );
  13586. }
  13587. }
  13588. if ( material instanceof THREE.MeshBasicMaterial ||
  13589. material instanceof THREE.MeshLambertMaterial ||
  13590. material instanceof THREE.MeshPhongMaterial ) {
  13591. refreshUniformsCommon( m_uniforms, material );
  13592. }
  13593. // refresh single material specific uniforms
  13594. if ( material instanceof THREE.LineBasicMaterial ) {
  13595. refreshUniformsLine( m_uniforms, material );
  13596. } else if ( material instanceof THREE.LineDashedMaterial ) {
  13597. refreshUniformsLine( m_uniforms, material );
  13598. refreshUniformsDash( m_uniforms, material );
  13599. } else if ( material instanceof THREE.PointsMaterial ) {
  13600. refreshUniformsParticle( m_uniforms, material );
  13601. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  13602. refreshUniformsPhong( m_uniforms, material );
  13603. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  13604. m_uniforms.mNear.value = camera.near;
  13605. m_uniforms.mFar.value = camera.far;
  13606. m_uniforms.opacity.value = material.opacity;
  13607. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  13608. m_uniforms.opacity.value = material.opacity;
  13609. }
  13610. if ( object.receiveShadow && ! material._shadowPass ) {
  13611. refreshUniformsShadow( m_uniforms, lights, camera );
  13612. }
  13613. // load common uniforms
  13614. loadUniformsGeneric( materialProperties.uniformsList );
  13615. }
  13616. loadUniformsMatrices( p_uniforms, object );
  13617. if ( p_uniforms.modelMatrix !== undefined ) {
  13618. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  13619. }
  13620. return program;
  13621. }
  13622. // Uniforms (refresh uniforms objects)
  13623. function refreshUniformsCommon ( uniforms, material ) {
  13624. uniforms.opacity.value = material.opacity;
  13625. uniforms.diffuse.value = material.color;
  13626. if ( material.emissive ) {
  13627. uniforms.emissive.value = material.emissive;
  13628. }
  13629. uniforms.map.value = material.map;
  13630. uniforms.specularMap.value = material.specularMap;
  13631. uniforms.alphaMap.value = material.alphaMap;
  13632. if ( material.aoMap ) {
  13633. uniforms.aoMap.value = material.aoMap;
  13634. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13635. }
  13636. // uv repeat and offset setting priorities
  13637. // 1. color map
  13638. // 2. specular map
  13639. // 3. normal map
  13640. // 4. bump map
  13641. // 5. alpha map
  13642. // 6. emissive map
  13643. var uvScaleMap;
  13644. if ( material.map ) {
  13645. uvScaleMap = material.map;
  13646. } else if ( material.specularMap ) {
  13647. uvScaleMap = material.specularMap;
  13648. } else if ( material.displacementMap ) {
  13649. uvScaleMap = material.displacementMap;
  13650. } else if ( material.normalMap ) {
  13651. uvScaleMap = material.normalMap;
  13652. } else if ( material.bumpMap ) {
  13653. uvScaleMap = material.bumpMap;
  13654. } else if ( material.alphaMap ) {
  13655. uvScaleMap = material.alphaMap;
  13656. } else if ( material.emissiveMap ) {
  13657. uvScaleMap = material.emissiveMap;
  13658. }
  13659. if ( uvScaleMap !== undefined ) {
  13660. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) uvScaleMap = uvScaleMap.texture;
  13661. var offset = uvScaleMap.offset;
  13662. var repeat = uvScaleMap.repeat;
  13663. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13664. }
  13665. uniforms.envMap.value = material.envMap;
  13666. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  13667. uniforms.reflectivity.value = material.reflectivity;
  13668. uniforms.refractionRatio.value = material.refractionRatio;
  13669. }
  13670. function refreshUniformsLine ( uniforms, material ) {
  13671. uniforms.diffuse.value = material.color;
  13672. uniforms.opacity.value = material.opacity;
  13673. }
  13674. function refreshUniformsDash ( uniforms, material ) {
  13675. uniforms.dashSize.value = material.dashSize;
  13676. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13677. uniforms.scale.value = material.scale;
  13678. }
  13679. function refreshUniformsParticle ( uniforms, material ) {
  13680. uniforms.psColor.value = material.color;
  13681. uniforms.opacity.value = material.opacity;
  13682. uniforms.size.value = material.size;
  13683. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  13684. uniforms.map.value = material.map;
  13685. if ( material.map !== null ) {
  13686. var offset = material.map.offset;
  13687. var repeat = material.map.repeat;
  13688. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13689. }
  13690. }
  13691. function refreshUniformsFog ( uniforms, fog ) {
  13692. uniforms.fogColor.value = fog.color;
  13693. if ( fog instanceof THREE.Fog ) {
  13694. uniforms.fogNear.value = fog.near;
  13695. uniforms.fogFar.value = fog.far;
  13696. } else if ( fog instanceof THREE.FogExp2 ) {
  13697. uniforms.fogDensity.value = fog.density;
  13698. }
  13699. }
  13700. function refreshUniformsPhong ( uniforms, material ) {
  13701. uniforms.specular.value = material.specular;
  13702. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13703. if ( material.lightMap ) {
  13704. uniforms.lightMap.value = material.lightMap;
  13705. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13706. }
  13707. if ( material.emissiveMap ) {
  13708. uniforms.emissiveMap.value = material.emissiveMap;
  13709. }
  13710. if ( material.bumpMap ) {
  13711. uniforms.bumpMap.value = material.bumpMap;
  13712. uniforms.bumpScale.value = material.bumpScale;
  13713. }
  13714. if ( material.normalMap ) {
  13715. uniforms.normalMap.value = material.normalMap;
  13716. uniforms.normalScale.value.copy( material.normalScale );
  13717. }
  13718. if ( material.displacementMap ) {
  13719. uniforms.displacementMap.value = material.displacementMap;
  13720. uniforms.displacementScale.value = material.displacementScale;
  13721. uniforms.displacementBias.value = material.displacementBias;
  13722. }
  13723. }
  13724. function refreshUniformsLights ( uniforms, lights ) {
  13725. uniforms.ambientLightColor.value = lights.ambient;
  13726. uniforms.directionalLightColor.value = lights.directional.colors;
  13727. uniforms.directionalLightDirection.value = lights.directional.positions;
  13728. uniforms.pointLightColor.value = lights.point.colors;
  13729. uniforms.pointLightPosition.value = lights.point.positions;
  13730. uniforms.pointLightDistance.value = lights.point.distances;
  13731. uniforms.pointLightDecay.value = lights.point.decays;
  13732. uniforms.spotLightColor.value = lights.spot.colors;
  13733. uniforms.spotLightPosition.value = lights.spot.positions;
  13734. uniforms.spotLightDistance.value = lights.spot.distances;
  13735. uniforms.spotLightDirection.value = lights.spot.directions;
  13736. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  13737. uniforms.spotLightExponent.value = lights.spot.exponents;
  13738. uniforms.spotLightDecay.value = lights.spot.decays;
  13739. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  13740. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  13741. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  13742. }
  13743. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13744. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  13745. uniforms.ambientLightColor.needsUpdate = value;
  13746. uniforms.directionalLightColor.needsUpdate = value;
  13747. uniforms.directionalLightDirection.needsUpdate = value;
  13748. uniforms.pointLightColor.needsUpdate = value;
  13749. uniforms.pointLightPosition.needsUpdate = value;
  13750. uniforms.pointLightDistance.needsUpdate = value;
  13751. uniforms.pointLightDecay.needsUpdate = value;
  13752. uniforms.spotLightColor.needsUpdate = value;
  13753. uniforms.spotLightPosition.needsUpdate = value;
  13754. uniforms.spotLightDistance.needsUpdate = value;
  13755. uniforms.spotLightDirection.needsUpdate = value;
  13756. uniforms.spotLightAngleCos.needsUpdate = value;
  13757. uniforms.spotLightExponent.needsUpdate = value;
  13758. uniforms.spotLightDecay.needsUpdate = value;
  13759. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  13760. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  13761. uniforms.hemisphereLightDirection.needsUpdate = value;
  13762. }
  13763. function refreshUniformsShadow ( uniforms, lights, camera ) {
  13764. if ( uniforms.shadowMatrix ) {
  13765. var j = 0;
  13766. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  13767. var light = lights[ i ];
  13768. if ( light.castShadow === true ) {
  13769. if ( light instanceof THREE.PointLight || light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) {
  13770. var shadow = light.shadow;
  13771. if ( light instanceof THREE.PointLight ) {
  13772. // for point lights we set the shadow matrix to be a translation-only matrix
  13773. // equal to inverse of the light's position
  13774. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  13775. shadow.matrix.identity().setPosition( _vector3 );
  13776. // for point lights we set the sign of the shadowDarkness uniform to be negative
  13777. uniforms.shadowDarkness.value[ j ] = - shadow.darkness;
  13778. } else {
  13779. uniforms.shadowDarkness.value[ j ] = shadow.darkness;
  13780. }
  13781. uniforms.shadowMatrix.value[ j ] = shadow.matrix;
  13782. uniforms.shadowMap.value[ j ] = shadow.map;
  13783. uniforms.shadowMapSize.value[ j ] = shadow.mapSize;
  13784. uniforms.shadowBias.value[ j ] = shadow.bias;
  13785. j ++;
  13786. }
  13787. }
  13788. }
  13789. }
  13790. }
  13791. // Uniforms (load to GPU)
  13792. function loadUniformsMatrices ( uniforms, object ) {
  13793. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  13794. if ( uniforms.normalMatrix ) {
  13795. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  13796. }
  13797. }
  13798. function getTextureUnit() {
  13799. var textureUnit = _usedTextureUnits;
  13800. if ( textureUnit >= capabilities.maxTextures ) {
  13801. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13802. }
  13803. _usedTextureUnits += 1;
  13804. return textureUnit;
  13805. }
  13806. function loadUniformsGeneric ( uniforms ) {
  13807. var texture, textureUnit;
  13808. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  13809. var uniform = uniforms[ j ][ 0 ];
  13810. // needsUpdate property is not added to all uniforms.
  13811. if ( uniform.needsUpdate === false ) continue;
  13812. var type = uniform.type;
  13813. var value = uniform.value;
  13814. var location = uniforms[ j ][ 1 ];
  13815. switch ( type ) {
  13816. case '1i':
  13817. _gl.uniform1i( location, value );
  13818. break;
  13819. case '1f':
  13820. _gl.uniform1f( location, value );
  13821. break;
  13822. case '2f':
  13823. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  13824. break;
  13825. case '3f':
  13826. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  13827. break;
  13828. case '4f':
  13829. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  13830. break;
  13831. case '1iv':
  13832. _gl.uniform1iv( location, value );
  13833. break;
  13834. case '3iv':
  13835. _gl.uniform3iv( location, value );
  13836. break;
  13837. case '1fv':
  13838. _gl.uniform1fv( location, value );
  13839. break;
  13840. case '2fv':
  13841. _gl.uniform2fv( location, value );
  13842. break;
  13843. case '3fv':
  13844. _gl.uniform3fv( location, value );
  13845. break;
  13846. case '4fv':
  13847. _gl.uniform4fv( location, value );
  13848. break;
  13849. case 'Matrix3fv':
  13850. _gl.uniformMatrix3fv( location, false, value );
  13851. break;
  13852. case 'Matrix4fv':
  13853. _gl.uniformMatrix4fv( location, false, value );
  13854. break;
  13855. //
  13856. case 'i':
  13857. // single integer
  13858. _gl.uniform1i( location, value );
  13859. break;
  13860. case 'f':
  13861. // single float
  13862. _gl.uniform1f( location, value );
  13863. break;
  13864. case 'v2':
  13865. // single THREE.Vector2
  13866. _gl.uniform2f( location, value.x, value.y );
  13867. break;
  13868. case 'v3':
  13869. // single THREE.Vector3
  13870. _gl.uniform3f( location, value.x, value.y, value.z );
  13871. break;
  13872. case 'v4':
  13873. // single THREE.Vector4
  13874. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  13875. break;
  13876. case 'c':
  13877. // single THREE.Color
  13878. _gl.uniform3f( location, value.r, value.g, value.b );
  13879. break;
  13880. case 'iv1':
  13881. // flat array of integers (JS or typed array)
  13882. _gl.uniform1iv( location, value );
  13883. break;
  13884. case 'iv':
  13885. // flat array of integers with 3 x N size (JS or typed array)
  13886. _gl.uniform3iv( location, value );
  13887. break;
  13888. case 'fv1':
  13889. // flat array of floats (JS or typed array)
  13890. _gl.uniform1fv( location, value );
  13891. break;
  13892. case 'fv':
  13893. // flat array of floats with 3 x N size (JS or typed array)
  13894. _gl.uniform3fv( location, value );
  13895. break;
  13896. case 'v2v':
  13897. // array of THREE.Vector2
  13898. if ( uniform._array === undefined ) {
  13899. uniform._array = new Float32Array( 2 * value.length );
  13900. }
  13901. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  13902. uniform._array[ i2 + 0 ] = value[ i ].x;
  13903. uniform._array[ i2 + 1 ] = value[ i ].y;
  13904. }
  13905. _gl.uniform2fv( location, uniform._array );
  13906. break;
  13907. case 'v3v':
  13908. // array of THREE.Vector3
  13909. if ( uniform._array === undefined ) {
  13910. uniform._array = new Float32Array( 3 * value.length );
  13911. }
  13912. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  13913. uniform._array[ i3 + 0 ] = value[ i ].x;
  13914. uniform._array[ i3 + 1 ] = value[ i ].y;
  13915. uniform._array[ i3 + 2 ] = value[ i ].z;
  13916. }
  13917. _gl.uniform3fv( location, uniform._array );
  13918. break;
  13919. case 'v4v':
  13920. // array of THREE.Vector4
  13921. if ( uniform._array === undefined ) {
  13922. uniform._array = new Float32Array( 4 * value.length );
  13923. }
  13924. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  13925. uniform._array[ i4 + 0 ] = value[ i ].x;
  13926. uniform._array[ i4 + 1 ] = value[ i ].y;
  13927. uniform._array[ i4 + 2 ] = value[ i ].z;
  13928. uniform._array[ i4 + 3 ] = value[ i ].w;
  13929. }
  13930. _gl.uniform4fv( location, uniform._array );
  13931. break;
  13932. case 'm3':
  13933. // single THREE.Matrix3
  13934. _gl.uniformMatrix3fv( location, false, value.elements );
  13935. break;
  13936. case 'm3v':
  13937. // array of THREE.Matrix3
  13938. if ( uniform._array === undefined ) {
  13939. uniform._array = new Float32Array( 9 * value.length );
  13940. }
  13941. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13942. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  13943. }
  13944. _gl.uniformMatrix3fv( location, false, uniform._array );
  13945. break;
  13946. case 'm4':
  13947. // single THREE.Matrix4
  13948. _gl.uniformMatrix4fv( location, false, value.elements );
  13949. break;
  13950. case 'm4v':
  13951. // array of THREE.Matrix4
  13952. if ( uniform._array === undefined ) {
  13953. uniform._array = new Float32Array( 16 * value.length );
  13954. }
  13955. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13956. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  13957. }
  13958. _gl.uniformMatrix4fv( location, false, uniform._array );
  13959. break;
  13960. case 't':
  13961. // single THREE.Texture (2d or cube)
  13962. texture = value;
  13963. textureUnit = getTextureUnit();
  13964. _gl.uniform1i( location, textureUnit );
  13965. if ( ! texture ) continue;
  13966. if ( texture instanceof THREE.CubeTexture ||
  13967. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  13968. // CompressedTexture can have Array in image :/
  13969. setCubeTexture( texture, textureUnit );
  13970. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  13971. setCubeTextureDynamic( texture.texture, textureUnit );
  13972. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  13973. _this.setTexture( texture.texture, textureUnit );
  13974. } else {
  13975. _this.setTexture( texture, textureUnit );
  13976. }
  13977. break;
  13978. case 'tv':
  13979. // array of THREE.Texture (2d or cube)
  13980. if ( uniform._array === undefined ) {
  13981. uniform._array = [];
  13982. }
  13983. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13984. uniform._array[ i ] = getTextureUnit();
  13985. }
  13986. _gl.uniform1iv( location, uniform._array );
  13987. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13988. texture = uniform.value[ i ];
  13989. textureUnit = uniform._array[ i ];
  13990. if ( ! texture ) continue;
  13991. if ( texture instanceof THREE.CubeTexture ||
  13992. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  13993. // CompressedTexture can have Array in image :/
  13994. setCubeTexture( texture, textureUnit );
  13995. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  13996. _this.setTexture( texture.texture, textureUnit );
  13997. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  13998. setCubeTextureDynamic( texture.texture, textureUnit );
  13999. } else {
  14000. _this.setTexture( texture, textureUnit );
  14001. }
  14002. }
  14003. break;
  14004. default:
  14005. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  14006. }
  14007. }
  14008. }
  14009. function setColorLinear( array, offset, color, intensity ) {
  14010. array[ offset + 0 ] = color.r * intensity;
  14011. array[ offset + 1 ] = color.g * intensity;
  14012. array[ offset + 2 ] = color.b * intensity;
  14013. }
  14014. function setupLights ( lights, camera ) {
  14015. var l, ll, light,
  14016. r = 0, g = 0, b = 0,
  14017. color, skyColor, groundColor,
  14018. intensity,
  14019. distance,
  14020. zlights = _lights,
  14021. viewMatrix = camera.matrixWorldInverse,
  14022. dirColors = zlights.directional.colors,
  14023. dirPositions = zlights.directional.positions,
  14024. pointColors = zlights.point.colors,
  14025. pointPositions = zlights.point.positions,
  14026. pointDistances = zlights.point.distances,
  14027. pointDecays = zlights.point.decays,
  14028. spotColors = zlights.spot.colors,
  14029. spotPositions = zlights.spot.positions,
  14030. spotDistances = zlights.spot.distances,
  14031. spotDirections = zlights.spot.directions,
  14032. spotAnglesCos = zlights.spot.anglesCos,
  14033. spotExponents = zlights.spot.exponents,
  14034. spotDecays = zlights.spot.decays,
  14035. hemiSkyColors = zlights.hemi.skyColors,
  14036. hemiGroundColors = zlights.hemi.groundColors,
  14037. hemiPositions = zlights.hemi.positions,
  14038. dirLength = 0,
  14039. pointLength = 0,
  14040. spotLength = 0,
  14041. hemiLength = 0,
  14042. dirCount = 0,
  14043. pointCount = 0,
  14044. spotCount = 0,
  14045. hemiCount = 0,
  14046. dirOffset = 0,
  14047. pointOffset = 0,
  14048. spotOffset = 0,
  14049. hemiOffset = 0;
  14050. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  14051. light = lights[ l ];
  14052. color = light.color;
  14053. intensity = light.intensity;
  14054. distance = light.distance;
  14055. if ( light instanceof THREE.AmbientLight ) {
  14056. if ( ! light.visible ) continue;
  14057. r += color.r;
  14058. g += color.g;
  14059. b += color.b;
  14060. } else if ( light instanceof THREE.DirectionalLight ) {
  14061. dirCount += 1;
  14062. if ( ! light.visible ) continue;
  14063. _direction.setFromMatrixPosition( light.matrixWorld );
  14064. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14065. _direction.sub( _vector3 );
  14066. _direction.transformDirection( viewMatrix );
  14067. dirOffset = dirLength * 3;
  14068. dirPositions[ dirOffset + 0 ] = _direction.x;
  14069. dirPositions[ dirOffset + 1 ] = _direction.y;
  14070. dirPositions[ dirOffset + 2 ] = _direction.z;
  14071. setColorLinear( dirColors, dirOffset, color, intensity );
  14072. dirLength += 1;
  14073. } else if ( light instanceof THREE.PointLight ) {
  14074. pointCount += 1;
  14075. if ( ! light.visible ) continue;
  14076. pointOffset = pointLength * 3;
  14077. setColorLinear( pointColors, pointOffset, color, intensity );
  14078. _vector3.setFromMatrixPosition( light.matrixWorld );
  14079. _vector3.applyMatrix4( viewMatrix );
  14080. pointPositions[ pointOffset + 0 ] = _vector3.x;
  14081. pointPositions[ pointOffset + 1 ] = _vector3.y;
  14082. pointPositions[ pointOffset + 2 ] = _vector3.z;
  14083. // distance is 0 if decay is 0, because there is no attenuation at all.
  14084. pointDistances[ pointLength ] = distance;
  14085. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14086. pointLength += 1;
  14087. } else if ( light instanceof THREE.SpotLight ) {
  14088. spotCount += 1;
  14089. if ( ! light.visible ) continue;
  14090. spotOffset = spotLength * 3;
  14091. setColorLinear( spotColors, spotOffset, color, intensity );
  14092. _direction.setFromMatrixPosition( light.matrixWorld );
  14093. _vector3.copy( _direction ).applyMatrix4( viewMatrix );
  14094. spotPositions[ spotOffset + 0 ] = _vector3.x;
  14095. spotPositions[ spotOffset + 1 ] = _vector3.y;
  14096. spotPositions[ spotOffset + 2 ] = _vector3.z;
  14097. spotDistances[ spotLength ] = distance;
  14098. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14099. _direction.sub( _vector3 );
  14100. _direction.transformDirection( viewMatrix );
  14101. spotDirections[ spotOffset + 0 ] = _direction.x;
  14102. spotDirections[ spotOffset + 1 ] = _direction.y;
  14103. spotDirections[ spotOffset + 2 ] = _direction.z;
  14104. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  14105. spotExponents[ spotLength ] = light.exponent;
  14106. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14107. spotLength += 1;
  14108. } else if ( light instanceof THREE.HemisphereLight ) {
  14109. hemiCount += 1;
  14110. if ( ! light.visible ) continue;
  14111. _direction.setFromMatrixPosition( light.matrixWorld );
  14112. _direction.transformDirection( viewMatrix );
  14113. hemiOffset = hemiLength * 3;
  14114. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  14115. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  14116. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  14117. skyColor = light.color;
  14118. groundColor = light.groundColor;
  14119. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  14120. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  14121. hemiLength += 1;
  14122. }
  14123. }
  14124. // null eventual remains from removed lights
  14125. // (this is to avoid if in shader)
  14126. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  14127. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  14128. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  14129. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  14130. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  14131. zlights.directional.length = dirLength;
  14132. zlights.point.length = pointLength;
  14133. zlights.spot.length = spotLength;
  14134. zlights.hemi.length = hemiLength;
  14135. zlights.ambient[ 0 ] = r;
  14136. zlights.ambient[ 1 ] = g;
  14137. zlights.ambient[ 2 ] = b;
  14138. }
  14139. // GL state setting
  14140. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  14141. if ( cullFace === THREE.CullFaceNone ) {
  14142. state.disable( _gl.CULL_FACE );
  14143. } else {
  14144. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  14145. _gl.frontFace( _gl.CW );
  14146. } else {
  14147. _gl.frontFace( _gl.CCW );
  14148. }
  14149. if ( cullFace === THREE.CullFaceBack ) {
  14150. _gl.cullFace( _gl.BACK );
  14151. } else if ( cullFace === THREE.CullFaceFront ) {
  14152. _gl.cullFace( _gl.FRONT );
  14153. } else {
  14154. _gl.cullFace( _gl.FRONT_AND_BACK );
  14155. }
  14156. state.enable( _gl.CULL_FACE );
  14157. }
  14158. };
  14159. // Textures
  14160. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  14161. var extension;
  14162. if ( isImagePowerOfTwo ) {
  14163. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  14164. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  14165. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  14166. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  14167. } else {
  14168. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  14169. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  14170. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  14171. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  14172. }
  14173. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  14174. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  14175. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  14176. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  14177. }
  14178. }
  14179. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14180. if ( extension ) {
  14181. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  14182. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  14183. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  14184. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  14185. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  14186. }
  14187. }
  14188. }
  14189. function uploadTexture( textureProperties, texture, slot ) {
  14190. if ( textureProperties.__webglInit === undefined ) {
  14191. textureProperties.__webglInit = true;
  14192. texture.addEventListener( 'dispose', onTextureDispose );
  14193. textureProperties.__webglTexture = _gl.createTexture();
  14194. _infoMemory.textures ++;
  14195. }
  14196. state.activeTexture( _gl.TEXTURE0 + slot );
  14197. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14198. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14199. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  14200. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  14201. texture.image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  14202. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( texture.image ) === false ) {
  14203. texture.image = makePowerOfTwo( texture.image );
  14204. }
  14205. var image = texture.image,
  14206. isImagePowerOfTwo = isPowerOfTwo( image ),
  14207. glFormat = paramThreeToGL( texture.format ),
  14208. glType = paramThreeToGL( texture.type );
  14209. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  14210. var mipmap, mipmaps = texture.mipmaps;
  14211. if ( texture instanceof THREE.DataTexture ) {
  14212. // use manually created mipmaps if available
  14213. // if there are no manual mipmaps
  14214. // set 0 level mipmap and then use GL to generate other mipmap levels
  14215. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14216. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14217. mipmap = mipmaps[ i ];
  14218. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14219. }
  14220. texture.generateMipmaps = false;
  14221. } else {
  14222. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  14223. }
  14224. } else if ( texture instanceof THREE.CompressedTexture ) {
  14225. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14226. mipmap = mipmaps[ i ];
  14227. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14228. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14229. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14230. } else {
  14231. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  14232. }
  14233. } else {
  14234. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14235. }
  14236. }
  14237. } else {
  14238. // regular Texture (image, video, canvas)
  14239. // use manually created mipmaps if available
  14240. // if there are no manual mipmaps
  14241. // set 0 level mipmap and then use GL to generate other mipmap levels
  14242. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14243. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14244. mipmap = mipmaps[ i ];
  14245. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  14246. }
  14247. texture.generateMipmaps = false;
  14248. } else {
  14249. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  14250. }
  14251. }
  14252. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14253. textureProperties.__version = texture.version;
  14254. if ( texture.onUpdate ) texture.onUpdate( texture );
  14255. }
  14256. this.setTexture = function ( texture, slot ) {
  14257. var textureProperties = properties.get( texture );
  14258. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14259. var image = texture.image;
  14260. if ( image === undefined ) {
  14261. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  14262. return;
  14263. }
  14264. if ( image.complete === false ) {
  14265. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  14266. return;
  14267. }
  14268. uploadTexture( textureProperties, texture, slot );
  14269. return;
  14270. }
  14271. state.activeTexture( _gl.TEXTURE0 + slot );
  14272. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14273. };
  14274. function clampToMaxSize ( image, maxSize ) {
  14275. if ( image.width > maxSize || image.height > maxSize ) {
  14276. // Warning: Scaling through the canvas will only work with images that use
  14277. // premultiplied alpha.
  14278. var scale = maxSize / Math.max( image.width, image.height );
  14279. var canvas = document.createElement( 'canvas' );
  14280. canvas.width = Math.floor( image.width * scale );
  14281. canvas.height = Math.floor( image.height * scale );
  14282. var context = canvas.getContext( '2d' );
  14283. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  14284. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  14285. return canvas;
  14286. }
  14287. return image;
  14288. }
  14289. function isPowerOfTwo( image ) {
  14290. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  14291. }
  14292. function textureNeedsPowerOfTwo( texture ) {
  14293. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  14294. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  14295. return false;
  14296. }
  14297. function makePowerOfTwo( image ) {
  14298. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  14299. var canvas = document.createElement( 'canvas' );
  14300. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  14301. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  14302. var context = canvas.getContext( '2d' );
  14303. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  14304. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  14305. return canvas;
  14306. }
  14307. return image;
  14308. }
  14309. function setCubeTexture ( texture, slot ) {
  14310. var textureProperties = properties.get( texture );
  14311. if ( texture.image.length === 6 ) {
  14312. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14313. if ( ! textureProperties.__image__webglTextureCube ) {
  14314. texture.addEventListener( 'dispose', onTextureDispose );
  14315. textureProperties.__image__webglTextureCube = _gl.createTexture();
  14316. _infoMemory.textures ++;
  14317. }
  14318. state.activeTexture( _gl.TEXTURE0 + slot );
  14319. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14320. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14321. var isCompressed = texture instanceof THREE.CompressedTexture;
  14322. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  14323. var cubeImage = [];
  14324. for ( var i = 0; i < 6; i ++ ) {
  14325. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  14326. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  14327. } else {
  14328. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  14329. }
  14330. }
  14331. var image = cubeImage[ 0 ],
  14332. isImagePowerOfTwo = isPowerOfTwo( image ),
  14333. glFormat = paramThreeToGL( texture.format ),
  14334. glType = paramThreeToGL( texture.type );
  14335. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  14336. for ( var i = 0; i < 6; i ++ ) {
  14337. if ( ! isCompressed ) {
  14338. if ( isDataTexture ) {
  14339. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  14340. } else {
  14341. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  14342. }
  14343. } else {
  14344. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  14345. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  14346. mipmap = mipmaps[ j ];
  14347. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14348. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14349. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14350. } else {
  14351. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  14352. }
  14353. } else {
  14354. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14355. }
  14356. }
  14357. }
  14358. }
  14359. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  14360. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14361. }
  14362. textureProperties.__version = texture.version;
  14363. if ( texture.onUpdate ) texture.onUpdate( texture );
  14364. } else {
  14365. state.activeTexture( _gl.TEXTURE0 + slot );
  14366. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14367. }
  14368. }
  14369. }
  14370. function setCubeTextureDynamic ( texture, slot ) {
  14371. state.activeTexture( _gl.TEXTURE0 + slot );
  14372. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  14373. }
  14374. // Render targets
  14375. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  14376. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14377. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  14378. }
  14379. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  14380. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  14381. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14382. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  14383. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14384. /* For some reason this is not working. Defaulting to RGBA4.
  14385. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14386. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  14387. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14388. */
  14389. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14390. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  14391. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14392. } else {
  14393. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  14394. }
  14395. }
  14396. this.setRenderTarget = function ( renderTarget ) {
  14397. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  14398. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14399. var renderTargetProperties = properties.get( renderTarget );
  14400. var textureProperties = properties.get( renderTarget.texture );
  14401. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  14402. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  14403. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  14404. textureProperties.__webglTexture = _gl.createTexture();
  14405. _infoMemory.textures ++;
  14406. // Setup texture, create render and frame buffers
  14407. var isTargetPowerOfTwo = isPowerOfTwo( renderTarget ),
  14408. glFormat = paramThreeToGL( renderTarget.texture.format ),
  14409. glType = paramThreeToGL( renderTarget.texture.type );
  14410. if ( isCube ) {
  14411. renderTargetProperties.__webglFramebuffer = [];
  14412. renderTargetProperties.__webglRenderbuffer = [];
  14413. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  14414. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  14415. for ( var i = 0; i < 6; i ++ ) {
  14416. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  14417. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  14418. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14419. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  14420. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  14421. }
  14422. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14423. } else {
  14424. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  14425. if ( renderTarget.shareDepthFrom ) {
  14426. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  14427. } else {
  14428. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  14429. }
  14430. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14431. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  14432. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14433. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  14434. if ( renderTarget.shareDepthFrom ) {
  14435. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14436. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14437. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14438. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14439. }
  14440. } else {
  14441. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  14442. }
  14443. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14444. }
  14445. // Release everything
  14446. if ( isCube ) {
  14447. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  14448. } else {
  14449. state.bindTexture( _gl.TEXTURE_2D, null );
  14450. }
  14451. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  14452. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  14453. }
  14454. var framebuffer, width, height, vx, vy;
  14455. if ( renderTarget ) {
  14456. var renderTargetProperties = properties.get( renderTarget );
  14457. if ( isCube ) {
  14458. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  14459. } else {
  14460. framebuffer = renderTargetProperties.__webglFramebuffer;
  14461. }
  14462. width = renderTarget.width;
  14463. height = renderTarget.height;
  14464. vx = 0;
  14465. vy = 0;
  14466. } else {
  14467. framebuffer = null;
  14468. width = _viewportWidth;
  14469. height = _viewportHeight;
  14470. vx = _viewportX;
  14471. vy = _viewportY;
  14472. }
  14473. if ( framebuffer !== _currentFramebuffer ) {
  14474. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14475. _gl.viewport( vx, vy, width, height );
  14476. _currentFramebuffer = framebuffer;
  14477. }
  14478. if ( isCube ) {
  14479. var textureProperties = properties.get( renderTarget.texture );
  14480. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, 0 );
  14481. }
  14482. _currentWidth = width;
  14483. _currentHeight = height;
  14484. };
  14485. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14486. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  14487. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14488. return;
  14489. }
  14490. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14491. if ( framebuffer ) {
  14492. var restore = false;
  14493. if ( framebuffer !== _currentFramebuffer ) {
  14494. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14495. restore = true;
  14496. }
  14497. try {
  14498. var texture = renderTarget.texture;
  14499. if ( texture.format !== THREE.RGBAFormat
  14500. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  14501. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14502. return;
  14503. }
  14504. if ( texture.type !== THREE.UnsignedByteType
  14505. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  14506. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  14507. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  14508. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14509. return;
  14510. }
  14511. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  14512. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  14513. } else {
  14514. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14515. }
  14516. } finally {
  14517. if ( restore ) {
  14518. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  14519. }
  14520. }
  14521. }
  14522. };
  14523. function updateRenderTargetMipmap( renderTarget ) {
  14524. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  14525. var texture = properties.get( renderTarget.texture ).__webglTexture;
  14526. state.bindTexture( target, texture );
  14527. _gl.generateMipmap( target );
  14528. state.bindTexture( target, null );
  14529. }
  14530. // Fallback filters for non-power-of-2 textures
  14531. function filterFallback ( f ) {
  14532. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  14533. return _gl.NEAREST;
  14534. }
  14535. return _gl.LINEAR;
  14536. }
  14537. // Map three.js constants to WebGL constants
  14538. function paramThreeToGL ( p ) {
  14539. var extension;
  14540. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  14541. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  14542. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  14543. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  14544. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  14545. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  14546. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  14547. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  14548. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  14549. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  14550. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  14551. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  14552. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  14553. if ( p === THREE.ByteType ) return _gl.BYTE;
  14554. if ( p === THREE.ShortType ) return _gl.SHORT;
  14555. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  14556. if ( p === THREE.IntType ) return _gl.INT;
  14557. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  14558. if ( p === THREE.FloatType ) return _gl.FLOAT;
  14559. extension = extensions.get( 'OES_texture_half_float' );
  14560. if ( extension !== null ) {
  14561. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  14562. }
  14563. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  14564. if ( p === THREE.RGBFormat ) return _gl.RGB;
  14565. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  14566. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  14567. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  14568. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  14569. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  14570. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  14571. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  14572. if ( p === THREE.OneFactor ) return _gl.ONE;
  14573. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  14574. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  14575. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  14576. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  14577. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  14578. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  14579. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  14580. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  14581. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  14582. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14583. if ( extension !== null ) {
  14584. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  14585. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  14586. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  14587. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  14588. }
  14589. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14590. if ( extension !== null ) {
  14591. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  14592. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  14593. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  14594. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  14595. }
  14596. extension = extensions.get( 'EXT_blend_minmax' );
  14597. if ( extension !== null ) {
  14598. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  14599. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  14600. }
  14601. return 0;
  14602. }
  14603. // DEPRECATED
  14604. this.supportsFloatTextures = function () {
  14605. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  14606. return extensions.get( 'OES_texture_float' );
  14607. };
  14608. this.supportsHalfFloatTextures = function () {
  14609. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  14610. return extensions.get( 'OES_texture_half_float' );
  14611. };
  14612. this.supportsStandardDerivatives = function () {
  14613. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  14614. return extensions.get( 'OES_standard_derivatives' );
  14615. };
  14616. this.supportsCompressedTextureS3TC = function () {
  14617. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  14618. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14619. };
  14620. this.supportsCompressedTexturePVRTC = function () {
  14621. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  14622. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14623. };
  14624. this.supportsBlendMinMax = function () {
  14625. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  14626. return extensions.get( 'EXT_blend_minmax' );
  14627. };
  14628. this.supportsVertexTextures = function () {
  14629. return capabilities.vertexTextures;
  14630. };
  14631. this.supportsInstancedArrays = function () {
  14632. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  14633. return extensions.get( 'ANGLE_instanced_arrays' );
  14634. };
  14635. //
  14636. this.initMaterial = function () {
  14637. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  14638. };
  14639. this.addPrePlugin = function () {
  14640. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  14641. };
  14642. this.addPostPlugin = function () {
  14643. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  14644. };
  14645. this.updateShadowMap = function () {
  14646. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  14647. };
  14648. Object.defineProperties( this, {
  14649. shadowMapEnabled: {
  14650. get: function () {
  14651. return shadowMap.enabled;
  14652. },
  14653. set: function ( value ) {
  14654. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  14655. shadowMap.enabled = value;
  14656. }
  14657. },
  14658. shadowMapType: {
  14659. get: function () {
  14660. return shadowMap.type;
  14661. },
  14662. set: function ( value ) {
  14663. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  14664. shadowMap.type = value;
  14665. }
  14666. },
  14667. shadowMapCullFace: {
  14668. get: function () {
  14669. return shadowMap.cullFace;
  14670. },
  14671. set: function ( value ) {
  14672. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  14673. shadowMap.cullFace = value;
  14674. }
  14675. },
  14676. shadowMapDebug: {
  14677. get: function () {
  14678. return shadowMap.debug;
  14679. },
  14680. set: function ( value ) {
  14681. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  14682. shadowMap.debug = value;
  14683. }
  14684. }
  14685. } );
  14686. };
  14687. // File:src/renderers/WebGLRenderTarget.js
  14688. /**
  14689. * @author szimek / https://github.com/szimek/
  14690. * @author alteredq / http://alteredqualia.com/
  14691. */
  14692. THREE.WebGLRenderTarget = function ( width, height, options ) {
  14693. this.uuid = THREE.Math.generateUUID();
  14694. this.width = width;
  14695. this.height = height;
  14696. options = options || {};
  14697. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  14698. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  14699. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  14700. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  14701. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  14702. };
  14703. THREE.WebGLRenderTarget.prototype = {
  14704. constructor: THREE.WebGLRenderTarget,
  14705. get wrapS() {
  14706. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  14707. return this.texture.wrapS;
  14708. },
  14709. set wrapS( value ) {
  14710. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  14711. this.texture.wrapS = value;
  14712. },
  14713. get wrapT() {
  14714. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  14715. return this.texture.wrapT;
  14716. },
  14717. set wrapT( value ) {
  14718. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  14719. this.texture.wrapT = value;
  14720. },
  14721. get magFilter() {
  14722. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  14723. return this.texture.magFilter;
  14724. },
  14725. set magFilter( value ) {
  14726. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  14727. this.texture.magFilter = value;
  14728. },
  14729. get minFilter() {
  14730. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  14731. return this.texture.minFilter;
  14732. },
  14733. set minFilter( value ) {
  14734. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  14735. this.texture.minFilter = value;
  14736. },
  14737. get anisotropy() {
  14738. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  14739. return this.texture.anisotropy;
  14740. },
  14741. set anisotropy( value ) {
  14742. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  14743. this.texture.anisotropy = value;
  14744. },
  14745. get offset() {
  14746. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  14747. return this.texture.offset;
  14748. },
  14749. set offset( value ) {
  14750. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  14751. this.texture.offset = value;
  14752. },
  14753. get repeat() {
  14754. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  14755. return this.texture.repeat;
  14756. },
  14757. set repeat( value ) {
  14758. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  14759. this.texture.repeat = value;
  14760. },
  14761. get format() {
  14762. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  14763. return this.texture.format;
  14764. },
  14765. set format( value ) {
  14766. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  14767. this.texture.format = value;
  14768. },
  14769. get type() {
  14770. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  14771. return this.texture.type;
  14772. },
  14773. set type( value ) {
  14774. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  14775. this.texture.type = value;
  14776. },
  14777. get generateMipmaps() {
  14778. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  14779. return this.texture.generateMipmaps;
  14780. },
  14781. set generateMipmaps( value ) {
  14782. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  14783. this.texture.generateMipmaps = value;
  14784. },
  14785. //
  14786. setSize: function ( width, height ) {
  14787. if ( this.width !== width || this.height !== height ) {
  14788. this.width = width;
  14789. this.height = height;
  14790. this.dispose();
  14791. }
  14792. },
  14793. clone: function () {
  14794. return new this.constructor().copy( this );
  14795. },
  14796. copy: function ( source ) {
  14797. this.width = source.width;
  14798. this.height = source.height;
  14799. this.texture = source.texture.clone();
  14800. this.depthBuffer = source.depthBuffer;
  14801. this.stencilBuffer = source.stencilBuffer;
  14802. this.shareDepthFrom = source.shareDepthFrom;
  14803. return this;
  14804. },
  14805. dispose: function () {
  14806. this.dispatchEvent( { type: 'dispose' } );
  14807. }
  14808. };
  14809. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  14810. // File:src/renderers/WebGLRenderTargetCube.js
  14811. /**
  14812. * @author alteredq / http://alteredqualia.com
  14813. */
  14814. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  14815. THREE.WebGLRenderTarget.call( this, width, height, options );
  14816. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  14817. };
  14818. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  14819. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  14820. // File:src/renderers/webgl/WebGLBufferRenderer.js
  14821. /**
  14822. * @author mrdoob / http://mrdoob.com/
  14823. */
  14824. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14825. var mode;
  14826. function setMode( value ) {
  14827. mode = value;
  14828. }
  14829. function render( start, count ) {
  14830. _gl.drawArrays( mode, start, count );
  14831. _infoRender.calls ++;
  14832. _infoRender.vertices += count;
  14833. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14834. }
  14835. function renderInstances( geometry ) {
  14836. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14837. if ( extension === null ) {
  14838. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14839. return;
  14840. }
  14841. var position = geometry.attributes.position;
  14842. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  14843. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount );
  14844. } else {
  14845. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount );
  14846. }
  14847. }
  14848. this.setMode = setMode;
  14849. this.render = render;
  14850. this.renderInstances = renderInstances;
  14851. };
  14852. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  14853. /**
  14854. * @author mrdoob / http://mrdoob.com/
  14855. */
  14856. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14857. var mode;
  14858. function setMode( value ) {
  14859. mode = value;
  14860. }
  14861. var type, size;
  14862. function setIndex( index ) {
  14863. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  14864. type = _gl.UNSIGNED_INT;
  14865. size = 4;
  14866. } else {
  14867. type = _gl.UNSIGNED_SHORT;
  14868. size = 2;
  14869. }
  14870. }
  14871. function render( start, count ) {
  14872. _gl.drawElements( mode, count, type, start * size );
  14873. _infoRender.calls ++;
  14874. _infoRender.vertices += count;
  14875. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14876. }
  14877. function renderInstances( geometry ) {
  14878. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14879. if ( extension === null ) {
  14880. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14881. return;
  14882. }
  14883. var index = geometry.index;
  14884. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount );
  14885. }
  14886. this.setMode = setMode;
  14887. this.setIndex = setIndex;
  14888. this.render = render;
  14889. this.renderInstances = renderInstances;
  14890. };
  14891. // File:src/renderers/webgl/WebGLExtensions.js
  14892. /**
  14893. * @author mrdoob / http://mrdoob.com/
  14894. */
  14895. THREE.WebGLExtensions = function ( gl ) {
  14896. var extensions = {};
  14897. this.get = function ( name ) {
  14898. if ( extensions[ name ] !== undefined ) {
  14899. return extensions[ name ];
  14900. }
  14901. var extension;
  14902. switch ( name ) {
  14903. case 'EXT_texture_filter_anisotropic':
  14904. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  14905. break;
  14906. case 'WEBGL_compressed_texture_s3tc':
  14907. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  14908. break;
  14909. case 'WEBGL_compressed_texture_pvrtc':
  14910. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  14911. break;
  14912. default:
  14913. extension = gl.getExtension( name );
  14914. }
  14915. if ( extension === null ) {
  14916. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  14917. }
  14918. extensions[ name ] = extension;
  14919. return extension;
  14920. };
  14921. };
  14922. // File:src/renderers/webgl/WebGLCapabilities.js
  14923. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  14924. function getMaxPrecision( precision ) {
  14925. if ( precision === 'highp' ) {
  14926. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  14927. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  14928. return 'highp';
  14929. }
  14930. precision = 'mediump';
  14931. }
  14932. if ( precision === 'mediump' ) {
  14933. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  14934. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  14935. return 'mediump';
  14936. }
  14937. }
  14938. return 'lowp';
  14939. }
  14940. this.getMaxPrecision = getMaxPrecision;
  14941. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  14942. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  14943. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14944. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  14945. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  14946. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  14947. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  14948. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  14949. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  14950. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  14951. this.vertexTextures = this.maxVertexTextures > 0;
  14952. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  14953. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  14954. var _maxPrecision = getMaxPrecision( this.precision );
  14955. if ( _maxPrecision !== this.precision ) {
  14956. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  14957. this.precision = _maxPrecision;
  14958. }
  14959. if ( this.logarithmicDepthBuffer ) {
  14960. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  14961. }
  14962. };
  14963. // File:src/renderers/webgl/WebGLGeometries.js
  14964. /**
  14965. * @author mrdoob / http://mrdoob.com/
  14966. */
  14967. THREE.WebGLGeometries = function ( gl, properties, info ) {
  14968. var geometries = {};
  14969. function get( object ) {
  14970. var geometry = object.geometry;
  14971. if ( geometries[ geometry.id ] !== undefined ) {
  14972. return geometries[ geometry.id ];
  14973. }
  14974. geometry.addEventListener( 'dispose', onGeometryDispose );
  14975. var buffergeometry;
  14976. if ( geometry instanceof THREE.BufferGeometry ) {
  14977. buffergeometry = geometry;
  14978. } else if ( geometry instanceof THREE.Geometry ) {
  14979. if ( geometry._bufferGeometry === undefined ) {
  14980. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  14981. }
  14982. buffergeometry = geometry._bufferGeometry;
  14983. }
  14984. geometries[ geometry.id ] = buffergeometry;
  14985. info.memory.geometries ++;
  14986. return buffergeometry;
  14987. }
  14988. function onGeometryDispose( event ) {
  14989. var geometry = event.target;
  14990. var buffergeometry = geometries[ geometry.id ];
  14991. deleteAttributes( buffergeometry.attributes );
  14992. geometry.removeEventListener( 'dispose', onGeometryDispose );
  14993. delete geometries[ geometry.id ];
  14994. var property = properties.get( geometry );
  14995. if ( property.wireframe ) deleteAttribute( property.wireframe );
  14996. info.memory.geometries --;
  14997. }
  14998. function getAttributeBuffer( attribute ) {
  14999. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15000. return properties.get( attribute.data ).__webglBuffer;
  15001. }
  15002. return properties.get( attribute ).__webglBuffer;
  15003. }
  15004. function deleteAttribute( attribute ) {
  15005. var buffer = getAttributeBuffer( attribute );
  15006. if ( buffer !== undefined ) {
  15007. gl.deleteBuffer( buffer );
  15008. removeAttributeBuffer( attribute );
  15009. }
  15010. }
  15011. function deleteAttributes( attributes ) {
  15012. for ( var name in attributes ) {
  15013. deleteAttribute( attributes[ name ] );
  15014. }
  15015. }
  15016. function removeAttributeBuffer( attribute ) {
  15017. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15018. properties.delete( attribute.data );
  15019. } else {
  15020. properties.delete( attribute );
  15021. }
  15022. }
  15023. this.get = get;
  15024. };
  15025. // File:src/renderers/webgl/WebGLObjects.js
  15026. /**
  15027. * @author mrdoob / http://mrdoob.com/
  15028. */
  15029. THREE.WebGLObjects = function ( gl, properties, info ) {
  15030. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  15031. //
  15032. function update( object ) {
  15033. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  15034. var geometry = geometries.get( object );
  15035. if ( object.geometry instanceof THREE.Geometry ) {
  15036. geometry.updateFromObject( object );
  15037. }
  15038. var index = geometry.index;
  15039. var attributes = geometry.attributes;
  15040. if ( index !== null ) {
  15041. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  15042. }
  15043. for ( var name in attributes ) {
  15044. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  15045. }
  15046. // morph targets
  15047. var morphAttributes = geometry.morphAttributes;
  15048. for ( var name in morphAttributes ) {
  15049. var array = morphAttributes[ name ];
  15050. for ( var i = 0, l = array.length; i < l; i ++ ) {
  15051. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  15052. }
  15053. }
  15054. return geometry;
  15055. }
  15056. function updateAttribute( attribute, bufferType ) {
  15057. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  15058. var attributeProperties = properties.get( data );
  15059. if ( attributeProperties.__webglBuffer === undefined ) {
  15060. createBuffer( attributeProperties, data, bufferType );
  15061. } else if ( attributeProperties.version !== data.version ) {
  15062. updateBuffer( attributeProperties, data, bufferType );
  15063. }
  15064. }
  15065. function createBuffer( attributeProperties, data, bufferType ) {
  15066. attributeProperties.__webglBuffer = gl.createBuffer();
  15067. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15068. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  15069. gl.bufferData( bufferType, data.array, usage );
  15070. attributeProperties.version = data.version;
  15071. }
  15072. function updateBuffer( attributeProperties, data, bufferType ) {
  15073. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15074. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  15075. // Not using update ranges
  15076. gl.bufferSubData( bufferType, 0, data.array );
  15077. } else if ( data.updateRange.count === 0 ) {
  15078. 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.' );
  15079. } else {
  15080. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  15081. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  15082. data.updateRange.count = 0; // reset range
  15083. }
  15084. attributeProperties.version = data.version;
  15085. }
  15086. function getAttributeBuffer( attribute ) {
  15087. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15088. return properties.get( attribute.data ).__webglBuffer;
  15089. }
  15090. return properties.get( attribute ).__webglBuffer;
  15091. }
  15092. function getWireframeAttribute( geometry ) {
  15093. var property = properties.get( geometry );
  15094. if ( property.wireframe !== undefined ) {
  15095. return property.wireframe;
  15096. }
  15097. var indices = [];
  15098. var index = geometry.index;
  15099. var attributes = geometry.attributes;
  15100. var position = attributes.position;
  15101. // console.time( 'wireframe' );
  15102. if ( index !== null ) {
  15103. var edges = {};
  15104. var array = index.array;
  15105. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  15106. var a = array[ i + 0 ];
  15107. var b = array[ i + 1 ];
  15108. var c = array[ i + 2 ];
  15109. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  15110. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  15111. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  15112. }
  15113. } else {
  15114. var array = attributes.position.array;
  15115. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  15116. var a = i + 0;
  15117. var b = i + 1;
  15118. var c = i + 2;
  15119. indices.push( a, b, b, c, c, a );
  15120. }
  15121. }
  15122. // console.timeEnd( 'wireframe' );
  15123. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  15124. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  15125. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  15126. property.wireframe = attribute;
  15127. return attribute;
  15128. }
  15129. function checkEdge( edges, a, b ) {
  15130. if ( a > b ) {
  15131. var tmp = a;
  15132. a = b;
  15133. b = tmp;
  15134. }
  15135. var list = edges[ a ];
  15136. if ( list === undefined ) {
  15137. edges[ a ] = [ b ];
  15138. return true;
  15139. } else if ( list.indexOf( b ) === -1 ) {
  15140. list.push( b );
  15141. return true;
  15142. }
  15143. return false;
  15144. }
  15145. this.getAttributeBuffer = getAttributeBuffer;
  15146. this.getWireframeAttribute = getWireframeAttribute;
  15147. this.update = update;
  15148. };
  15149. // File:src/renderers/webgl/WebGLProgram.js
  15150. THREE.WebGLProgram = ( function () {
  15151. var programIdCount = 0;
  15152. function generateDefines( defines ) {
  15153. var chunks = [];
  15154. for ( var name in defines ) {
  15155. var value = defines[ name ];
  15156. if ( value === false ) continue;
  15157. chunks.push( '#define ' + name + ' ' + value );
  15158. }
  15159. return chunks.join( '\n' );
  15160. }
  15161. function fetchUniformLocations( gl, program, identifiers ) {
  15162. var uniforms = {};
  15163. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  15164. for ( var i = 0; i < n; i ++ ) {
  15165. var info = gl.getActiveUniform( program, i );
  15166. var name = info.name;
  15167. var location = gl.getUniformLocation( program, name );
  15168. // console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  15169. var suffixPos = name.lastIndexOf( '[0]' );
  15170. if ( suffixPos !== - 1 && suffixPos === name.length - 3 ) {
  15171. uniforms[ name.substr( 0, suffixPos ) ] = location;
  15172. }
  15173. uniforms[ name ] = location;
  15174. }
  15175. return uniforms;
  15176. }
  15177. function fetchAttributeLocations( gl, program, identifiers ) {
  15178. var attributes = {};
  15179. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  15180. for ( var i = 0; i < n; i ++ ) {
  15181. var info = gl.getActiveAttrib( program, i );
  15182. var name = info.name;
  15183. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  15184. attributes[ name ] = gl.getAttribLocation( program, name );
  15185. }
  15186. return attributes;
  15187. }
  15188. function filterEmptyLine( string ) {
  15189. return string !== '';
  15190. }
  15191. return function WebGLProgram( renderer, code, material, parameters ) {
  15192. var gl = renderer.context;
  15193. var defines = material.defines;
  15194. var vertexShader = material.__webglShader.vertexShader;
  15195. var fragmentShader = material.__webglShader.fragmentShader;
  15196. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  15197. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  15198. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  15199. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  15200. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  15201. }
  15202. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15203. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  15204. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15205. if ( parameters.envMap ) {
  15206. switch ( material.envMap.mapping ) {
  15207. case THREE.CubeReflectionMapping:
  15208. case THREE.CubeRefractionMapping:
  15209. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15210. break;
  15211. case THREE.EquirectangularReflectionMapping:
  15212. case THREE.EquirectangularRefractionMapping:
  15213. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  15214. break;
  15215. case THREE.SphericalReflectionMapping:
  15216. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  15217. break;
  15218. }
  15219. switch ( material.envMap.mapping ) {
  15220. case THREE.CubeRefractionMapping:
  15221. case THREE.EquirectangularRefractionMapping:
  15222. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  15223. break;
  15224. }
  15225. switch ( material.combine ) {
  15226. case THREE.MultiplyOperation:
  15227. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15228. break;
  15229. case THREE.MixOperation:
  15230. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  15231. break;
  15232. case THREE.AddOperation:
  15233. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  15234. break;
  15235. }
  15236. }
  15237. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  15238. // console.log( 'building new program ' );
  15239. //
  15240. var customDefines = generateDefines( defines );
  15241. //
  15242. var program = gl.createProgram();
  15243. var prefixVertex, prefixFragment;
  15244. if ( material instanceof THREE.RawShaderMaterial ) {
  15245. prefixVertex = '';
  15246. prefixFragment = '';
  15247. } else {
  15248. prefixVertex = [
  15249. 'precision ' + parameters.precision + ' float;',
  15250. 'precision ' + parameters.precision + ' int;',
  15251. '#define SHADER_NAME ' + material.__webglShader.name,
  15252. customDefines,
  15253. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  15254. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15255. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15256. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15257. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15258. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15259. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15260. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15261. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15262. '#define MAX_BONES ' + parameters.maxBones,
  15263. parameters.map ? '#define USE_MAP' : '',
  15264. parameters.envMap ? '#define USE_ENVMAP' : '',
  15265. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15266. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15267. parameters.aoMap ? '#define USE_AOMAP' : '',
  15268. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15269. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15270. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15271. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  15272. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15273. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15274. parameters.vertexColors ? '#define USE_COLOR' : '',
  15275. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15276. parameters.skinning ? '#define USE_SKINNING' : '',
  15277. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  15278. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  15279. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  15280. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15281. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15282. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15283. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15284. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15285. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15286. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  15287. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15288. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15289. 'uniform mat4 modelMatrix;',
  15290. 'uniform mat4 modelViewMatrix;',
  15291. 'uniform mat4 projectionMatrix;',
  15292. 'uniform mat4 viewMatrix;',
  15293. 'uniform mat3 normalMatrix;',
  15294. 'uniform vec3 cameraPosition;',
  15295. 'attribute vec3 position;',
  15296. 'attribute vec3 normal;',
  15297. 'attribute vec2 uv;',
  15298. '#ifdef USE_COLOR',
  15299. ' attribute vec3 color;',
  15300. '#endif',
  15301. '#ifdef USE_MORPHTARGETS',
  15302. ' attribute vec3 morphTarget0;',
  15303. ' attribute vec3 morphTarget1;',
  15304. ' attribute vec3 morphTarget2;',
  15305. ' attribute vec3 morphTarget3;',
  15306. ' #ifdef USE_MORPHNORMALS',
  15307. ' attribute vec3 morphNormal0;',
  15308. ' attribute vec3 morphNormal1;',
  15309. ' attribute vec3 morphNormal2;',
  15310. ' attribute vec3 morphNormal3;',
  15311. ' #else',
  15312. ' attribute vec3 morphTarget4;',
  15313. ' attribute vec3 morphTarget5;',
  15314. ' attribute vec3 morphTarget6;',
  15315. ' attribute vec3 morphTarget7;',
  15316. ' #endif',
  15317. '#endif',
  15318. '#ifdef USE_SKINNING',
  15319. ' attribute vec4 skinIndex;',
  15320. ' attribute vec4 skinWeight;',
  15321. '#endif',
  15322. '\n'
  15323. ].filter( filterEmptyLine ).join( '\n' );
  15324. prefixFragment = [
  15325. parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ? '#extension GL_OES_standard_derivatives : enable' : '',
  15326. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  15327. 'precision ' + parameters.precision + ' float;',
  15328. 'precision ' + parameters.precision + ' int;',
  15329. '#define SHADER_NAME ' + material.__webglShader.name,
  15330. customDefines,
  15331. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15332. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15333. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15334. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15335. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15336. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  15337. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15338. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15339. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15340. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  15341. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  15342. parameters.map ? '#define USE_MAP' : '',
  15343. parameters.envMap ? '#define USE_ENVMAP' : '',
  15344. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  15345. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15346. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  15347. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15348. parameters.aoMap ? '#define USE_AOMAP' : '',
  15349. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15350. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15351. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15352. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15353. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15354. parameters.vertexColors ? '#define USE_COLOR' : '',
  15355. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15356. parameters.metal ? '#define METAL' : '',
  15357. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15358. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15359. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15360. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15361. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15362. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15363. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15364. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15365. 'uniform mat4 viewMatrix;',
  15366. 'uniform vec3 cameraPosition;',
  15367. '\n'
  15368. ].filter( filterEmptyLine ).join( '\n' );
  15369. }
  15370. var vertexGlsl = prefixVertex + vertexShader;
  15371. var fragmentGlsl = prefixFragment + fragmentShader;
  15372. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  15373. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  15374. gl.attachShader( program, glVertexShader );
  15375. gl.attachShader( program, glFragmentShader );
  15376. // Force a particular attribute to index 0.
  15377. if ( material.index0AttributeName !== undefined ) {
  15378. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  15379. } else if ( parameters.morphTargets === true ) {
  15380. // programs with morphTargets displace position out of attribute 0
  15381. gl.bindAttribLocation( program, 0, 'position' );
  15382. }
  15383. gl.linkProgram( program );
  15384. var programLog = gl.getProgramInfoLog( program );
  15385. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  15386. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  15387. var runnable = true;
  15388. var haveDiagnostics = true;
  15389. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  15390. runnable = false;
  15391. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  15392. } else if ( programLog !== '' ) {
  15393. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  15394. } else if ( vertexLog === '' || fragmentLog === '' ) {
  15395. haveDiagnostics = false;
  15396. }
  15397. if ( haveDiagnostics ) {
  15398. this.diagnostics = {
  15399. runnable: runnable,
  15400. material: material,
  15401. programLog: programLog,
  15402. vertexShader: {
  15403. log: vertexLog,
  15404. prefix: prefixVertex
  15405. },
  15406. fragmentShader: {
  15407. log: fragmentLog,
  15408. prefix: prefixFragment
  15409. }
  15410. };
  15411. }
  15412. // clean up
  15413. gl.deleteShader( glVertexShader );
  15414. gl.deleteShader( glFragmentShader );
  15415. // set up caching for uniform locations
  15416. var cachedUniforms;
  15417. this.getUniforms = function() {
  15418. if ( cachedUniforms === undefined ) {
  15419. cachedUniforms = fetchUniformLocations( gl, program );
  15420. }
  15421. return cachedUniforms;
  15422. };
  15423. // set up caching for attribute locations
  15424. var cachedAttributes;
  15425. this.getAttributes = function() {
  15426. if ( cachedAttributes === undefined ) {
  15427. cachedAttributes = fetchAttributeLocations( gl, program );
  15428. }
  15429. return cachedAttributes;
  15430. };
  15431. // free resource
  15432. this.destroy = function() {
  15433. gl.deleteProgram( program );
  15434. this.program = undefined;
  15435. };
  15436. // DEPRECATED
  15437. Object.defineProperties( this, {
  15438. uniforms: {
  15439. get: function() {
  15440. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  15441. return this.getUniforms();
  15442. }
  15443. },
  15444. attributes: {
  15445. get: function() {
  15446. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  15447. return this.getAttributes();
  15448. }
  15449. }
  15450. } );
  15451. //
  15452. this.id = programIdCount ++;
  15453. this.code = code;
  15454. this.usedTimes = 1;
  15455. this.program = program;
  15456. this.vertexShader = glVertexShader;
  15457. this.fragmentShader = glFragmentShader;
  15458. return this;
  15459. };
  15460. } )();
  15461. // File:src/renderers/webgl/WebGLPrograms.js
  15462. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  15463. var programs = [];
  15464. var shaderIDs = {
  15465. MeshDepthMaterial: 'depth',
  15466. MeshNormalMaterial: 'normal',
  15467. MeshBasicMaterial: 'basic',
  15468. MeshLambertMaterial: 'lambert',
  15469. MeshPhongMaterial: 'phong',
  15470. LineBasicMaterial: 'basic',
  15471. LineDashedMaterial: 'dashed',
  15472. PointsMaterial: 'points'
  15473. };
  15474. var parameterNames = [
  15475. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  15476. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "displacementMap", "specularMap",
  15477. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  15478. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  15479. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  15480. "maxMorphTargets", "maxMorphNormals", "maxDirLights", "maxPointLights",
  15481. "maxSpotLights", "maxHemiLights", "maxShadows", "shadowMapEnabled", "pointLightShadows",
  15482. "shadowMapType", "shadowMapDebug", "alphaTest", "metal", "doubleSided",
  15483. "flipSided"
  15484. ];
  15485. function allocateBones ( object ) {
  15486. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  15487. return 1024;
  15488. } else {
  15489. // default for when object is not specified
  15490. // ( for example when prebuilding shader to be used with multiple objects )
  15491. //
  15492. // - leave some extra space for other uniforms
  15493. // - limit here is ANGLE's 254 max uniform vectors
  15494. // (up to 54 should be safe)
  15495. var nVertexUniforms = capabilities.maxVertexUniforms;
  15496. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  15497. var maxBones = nVertexMatrices;
  15498. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  15499. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  15500. if ( maxBones < object.skeleton.bones.length ) {
  15501. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  15502. }
  15503. }
  15504. return maxBones;
  15505. }
  15506. }
  15507. function allocateLights( lights ) {
  15508. var dirLights = 0;
  15509. var pointLights = 0;
  15510. var spotLights = 0;
  15511. var hemiLights = 0;
  15512. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15513. var light = lights[ l ];
  15514. if ( light.visible === false ) continue;
  15515. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  15516. if ( light instanceof THREE.PointLight ) pointLights ++;
  15517. if ( light instanceof THREE.SpotLight ) spotLights ++;
  15518. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  15519. }
  15520. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  15521. }
  15522. function allocateShadows( lights ) {
  15523. var maxShadows = 0;
  15524. var pointLightShadows = 0;
  15525. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15526. var light = lights[ l ];
  15527. if ( ! light.castShadow ) continue;
  15528. if ( light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) maxShadows ++;
  15529. if ( light instanceof THREE.PointLight ) {
  15530. maxShadows ++;
  15531. pointLightShadows ++;
  15532. }
  15533. }
  15534. return { 'maxShadows': maxShadows, 'pointLightShadows': pointLightShadows };
  15535. }
  15536. this.getParameters = function ( material, lights, fog, object ) {
  15537. var shaderID = shaderIDs[ material.type ];
  15538. // heuristics to create shader parameters according to lights in the scene
  15539. // (not to blow over maxLights budget)
  15540. var maxLightCount = allocateLights( lights );
  15541. var allocatedShadows = allocateShadows( lights );
  15542. var maxBones = allocateBones( object );
  15543. var precision = renderer.getPrecision();
  15544. if ( material.precision !== null ) {
  15545. precision = capabilities.getMaxPrecision( material.precision );
  15546. if ( precision !== material.precision ) {
  15547. console.warn( 'THREE.WebGLRenderer.initMaterial:', material.precision, 'not supported, using', precision, 'instead.' );
  15548. }
  15549. }
  15550. var parameters = {
  15551. shaderID: shaderID,
  15552. precision: precision,
  15553. supportsVertexTextures: capabilities.vertexTextures,
  15554. map: !! material.map,
  15555. envMap: !! material.envMap,
  15556. envMapMode: material.envMap && material.envMap.mapping,
  15557. lightMap: !! material.lightMap,
  15558. aoMap: !! material.aoMap,
  15559. emissiveMap: !! material.emissiveMap,
  15560. bumpMap: !! material.bumpMap,
  15561. normalMap: !! material.normalMap,
  15562. displacementMap: !! material.displacementMap,
  15563. specularMap: !! material.specularMap,
  15564. alphaMap: !! material.alphaMap,
  15565. combine: material.combine,
  15566. vertexColors: material.vertexColors,
  15567. fog: fog,
  15568. useFog: material.fog,
  15569. fogExp: fog instanceof THREE.FogExp2,
  15570. flatShading: material.shading === THREE.FlatShading,
  15571. sizeAttenuation: material.sizeAttenuation,
  15572. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  15573. skinning: material.skinning,
  15574. maxBones: maxBones,
  15575. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  15576. morphTargets: material.morphTargets,
  15577. morphNormals: material.morphNormals,
  15578. maxMorphTargets: renderer.maxMorphTargets,
  15579. maxMorphNormals: renderer.maxMorphNormals,
  15580. maxDirLights: maxLightCount.directional,
  15581. maxPointLights: maxLightCount.point,
  15582. maxSpotLights: maxLightCount.spot,
  15583. maxHemiLights: maxLightCount.hemi,
  15584. maxShadows: allocatedShadows.maxShadows,
  15585. pointLightShadows: allocatedShadows.pointLightShadows,
  15586. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && allocatedShadows.maxShadows > 0,
  15587. shadowMapType: renderer.shadowMap.type,
  15588. shadowMapDebug: renderer.shadowMap.debug,
  15589. alphaTest: material.alphaTest,
  15590. metal: material.metal,
  15591. doubleSided: material.side === THREE.DoubleSide,
  15592. flipSided: material.side === THREE.BackSide
  15593. };
  15594. return parameters;
  15595. };
  15596. this.getProgramCode = function ( material, parameters ) {
  15597. var chunks = [];
  15598. if ( parameters.shaderID ) {
  15599. chunks.push( parameters.shaderID );
  15600. } else {
  15601. chunks.push( material.fragmentShader );
  15602. chunks.push( material.vertexShader );
  15603. }
  15604. if ( material.defines !== undefined ) {
  15605. for ( var name in material.defines ) {
  15606. chunks.push( name );
  15607. chunks.push( material.defines[ name ] );
  15608. }
  15609. }
  15610. for ( var i = 0; i < parameterNames.length; i ++ ) {
  15611. var parameterName = parameterNames[ i ];
  15612. chunks.push( parameterName );
  15613. chunks.push( parameters[ parameterName ] );
  15614. }
  15615. return chunks.join();
  15616. };
  15617. this.acquireProgram = function ( material, parameters, code ) {
  15618. var program;
  15619. // Check if code has been already compiled
  15620. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  15621. var programInfo = programs[ p ];
  15622. if ( programInfo.code === code ) {
  15623. program = programInfo;
  15624. ++ program.usedTimes;
  15625. break;
  15626. }
  15627. }
  15628. if ( program === undefined ) {
  15629. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  15630. programs.push( program );
  15631. }
  15632. return program;
  15633. };
  15634. this.releaseProgram = function( program ) {
  15635. if ( -- program.usedTimes === 0 ) {
  15636. // Remove from unordered set
  15637. var i = programs.indexOf( program );
  15638. programs[ i ] = programs[ programs.length - 1 ];
  15639. programs.pop();
  15640. // Free WebGL resources
  15641. program.destroy();
  15642. }
  15643. };
  15644. // Exposed for resource monitoring & error feedback via renderer.info:
  15645. this.programs = programs;
  15646. };
  15647. // File:src/renderers/webgl/WebGLProperties.js
  15648. /**
  15649. * @author fordacious / fordacious.github.io
  15650. */
  15651. THREE.WebGLProperties = function () {
  15652. var properties = {};
  15653. this.get = function ( object ) {
  15654. var uuid = object.uuid;
  15655. var map = properties[ uuid ];
  15656. if ( map === undefined ) {
  15657. map = {};
  15658. properties[ uuid ] = map;
  15659. }
  15660. return map;
  15661. };
  15662. this.delete = function ( object ) {
  15663. delete properties[ object.uuid ];
  15664. };
  15665. this.clear = function () {
  15666. properties = {};
  15667. };
  15668. };
  15669. // File:src/renderers/webgl/WebGLShader.js
  15670. THREE.WebGLShader = ( function () {
  15671. function addLineNumbers( string ) {
  15672. var lines = string.split( '\n' );
  15673. for ( var i = 0; i < lines.length; i ++ ) {
  15674. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  15675. }
  15676. return lines.join( '\n' );
  15677. }
  15678. return function WebGLShader( gl, type, string ) {
  15679. var shader = gl.createShader( type );
  15680. gl.shaderSource( shader, string );
  15681. gl.compileShader( shader );
  15682. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  15683. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  15684. }
  15685. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  15686. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  15687. }
  15688. // --enable-privileged-webgl-extension
  15689. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  15690. return shader;
  15691. };
  15692. } )();
  15693. // File:src/renderers/webgl/WebGLShadowMap.js
  15694. /**
  15695. * @author alteredq / http://alteredqualia.com/
  15696. * @author mrdoob / http://mrdoob.com/
  15697. */
  15698. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  15699. var _gl = _renderer.context,
  15700. _state = _renderer.state,
  15701. _frustum = new THREE.Frustum(),
  15702. _projScreenMatrix = new THREE.Matrix4(),
  15703. _min = new THREE.Vector3(),
  15704. _max = new THREE.Vector3(),
  15705. _lookTarget = new THREE.Vector3(),
  15706. _lightPositionWorld = new THREE.Vector3(),
  15707. _renderList = [],
  15708. _MorphingFlag = 1,
  15709. _SkinningFlag = 2,
  15710. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  15711. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  15712. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  15713. var cubeDirections = [
  15714. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  15715. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  15716. ];
  15717. var cubeUps = [
  15718. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  15719. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  15720. ];
  15721. var cube2DViewPorts = [
  15722. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  15723. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  15724. ];
  15725. var _vector4 = new THREE.Vector4();
  15726. // init
  15727. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  15728. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  15729. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  15730. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  15731. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  15732. var useMorphing = ( i & _MorphingFlag ) !== 0;
  15733. var useSkinning = ( i & _SkinningFlag ) !== 0;
  15734. var depthMaterial = new THREE.ShaderMaterial( {
  15735. uniforms: depthUniforms,
  15736. vertexShader: depthShader.vertexShader,
  15737. fragmentShader: depthShader.fragmentShader,
  15738. morphTargets: useMorphing,
  15739. skinning: useSkinning
  15740. } );
  15741. depthMaterial._shadowPass = true;
  15742. _depthMaterials[ i ] = depthMaterial;
  15743. var distanceMaterial = new THREE.ShaderMaterial( {
  15744. uniforms: distanceUniforms,
  15745. vertexShader: distanceShader.vertexShader,
  15746. fragmentShader: distanceShader.fragmentShader,
  15747. morphTargets: useMorphing,
  15748. skinning: useSkinning
  15749. } );
  15750. distanceMaterial._shadowPass = true;
  15751. _distanceMaterials[ i ] = distanceMaterial;
  15752. }
  15753. //
  15754. var scope = this;
  15755. this.enabled = false;
  15756. this.autoUpdate = true;
  15757. this.needsUpdate = false;
  15758. this.type = THREE.PCFShadowMap;
  15759. this.cullFace = THREE.CullFaceFront;
  15760. this.render = function ( scene ) {
  15761. var faceCount, isPointLight;
  15762. if ( scope.enabled === false ) return;
  15763. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  15764. // Set GL state for depth map.
  15765. _gl.clearColor( 1, 1, 1, 1 );
  15766. _state.disable( _gl.BLEND );
  15767. _state.enable( _gl.CULL_FACE );
  15768. _gl.frontFace( _gl.CCW );
  15769. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  15770. _state.setDepthTest( true );
  15771. // save the existing viewport so it can be restored later
  15772. _renderer.getViewport( _vector4 );
  15773. // render depth map
  15774. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  15775. var light = _lights[ i ];
  15776. if ( light.castShadow === true ) {
  15777. var shadow = light.shadow;
  15778. var shadowCamera = shadow.camera;
  15779. var shadowMapSize = shadow.mapSize;
  15780. if ( light instanceof THREE.PointLight ) {
  15781. faceCount = 6;
  15782. isPointLight = true;
  15783. var vpWidth = shadowMapSize.x / 4.0;
  15784. var vpHeight = shadowMapSize.y / 2.0;
  15785. // These viewports map a cube-map onto a 2D texture with the
  15786. // following orientation:
  15787. //
  15788. // xzXZ
  15789. // y Y
  15790. //
  15791. // X - Positive x direction
  15792. // x - Negative x direction
  15793. // Y - Positive y direction
  15794. // y - Negative y direction
  15795. // Z - Positive z direction
  15796. // z - Negative z direction
  15797. // positive X
  15798. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  15799. // negative X
  15800. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  15801. // positive Z
  15802. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  15803. // negative Z
  15804. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  15805. // positive Y
  15806. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  15807. // negative Y
  15808. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  15809. } else {
  15810. faceCount = 1;
  15811. isPointLight = false;
  15812. }
  15813. if ( shadow.map === null ) {
  15814. var shadowFilter = THREE.LinearFilter;
  15815. if ( scope.type === THREE.PCFSoftShadowMap ) {
  15816. shadowFilter = THREE.NearestFilter;
  15817. }
  15818. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  15819. shadow.map = new THREE.WebGLRenderTarget( shadowMapSize.x, shadowMapSize.y, pars );
  15820. shadow.matrix = new THREE.Matrix4();
  15821. //
  15822. if ( light instanceof THREE.SpotLight ) {
  15823. shadowCamera.aspect = shadowMapSize.x / shadowMapSize.y;
  15824. }
  15825. shadowCamera.updateProjectionMatrix();
  15826. }
  15827. var shadowMap = shadow.map;
  15828. var shadowMatrix = shadow.matrix;
  15829. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  15830. shadowCamera.position.copy( _lightPositionWorld );
  15831. _renderer.setRenderTarget( shadowMap );
  15832. _renderer.clear();
  15833. // render shadow map for each cube face (if omni-directional) or
  15834. // run a single pass if not
  15835. for ( var face = 0; face < faceCount; face ++ ) {
  15836. if ( isPointLight ) {
  15837. _lookTarget.copy( shadowCamera.position );
  15838. _lookTarget.add( cubeDirections[ face ] );
  15839. shadowCamera.up.copy( cubeUps[ face ] );
  15840. shadowCamera.lookAt( _lookTarget );
  15841. var vpDimensions = cube2DViewPorts[ face ];
  15842. _renderer.setViewport( vpDimensions.x, vpDimensions.y, vpDimensions.z, vpDimensions.w );
  15843. } else {
  15844. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  15845. shadowCamera.lookAt( _lookTarget );
  15846. }
  15847. shadowCamera.updateMatrixWorld();
  15848. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  15849. // compute shadow matrix
  15850. shadowMatrix.set(
  15851. 0.5, 0.0, 0.0, 0.5,
  15852. 0.0, 0.5, 0.0, 0.5,
  15853. 0.0, 0.0, 0.5, 0.5,
  15854. 0.0, 0.0, 0.0, 1.0
  15855. );
  15856. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  15857. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  15858. // update camera matrices and frustum
  15859. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  15860. _frustum.setFromMatrix( _projScreenMatrix );
  15861. // set object matrices & frustum culling
  15862. _renderList.length = 0;
  15863. projectObject( scene, shadowCamera );
  15864. // render shadow map
  15865. // render regular objects
  15866. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  15867. var object = _renderList[ j ];
  15868. var geometry = _objects.update( object );
  15869. var material = object.material;
  15870. if ( material instanceof THREE.MeshFaceMaterial ) {
  15871. var groups = geometry.groups;
  15872. var materials = material.materials;
  15873. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  15874. var group = groups[ k ];
  15875. var groupMaterial = materials[ group.materialIndex ];
  15876. if ( groupMaterial.visible === true ) {
  15877. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  15878. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, group );
  15879. }
  15880. }
  15881. } else {
  15882. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  15883. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, null );
  15884. }
  15885. }
  15886. }
  15887. // We must call _renderer.resetGLState() at the end of each iteration of
  15888. // the light loop in order to force material updates for each light.
  15889. _renderer.resetGLState();
  15890. }
  15891. }
  15892. _renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
  15893. // Restore GL state.
  15894. var clearColor = _renderer.getClearColor(),
  15895. clearAlpha = _renderer.getClearAlpha();
  15896. _renderer.setClearColor( clearColor, clearAlpha );
  15897. _state.enable( _gl.BLEND );
  15898. if ( scope.cullFace === THREE.CullFaceFront ) {
  15899. _gl.cullFace( _gl.BACK );
  15900. }
  15901. _renderer.resetGLState();
  15902. scope.needsUpdate = false;
  15903. };
  15904. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  15905. var geometry = object.geometry;
  15906. var newMaterial = null;
  15907. var materialVariants = _depthMaterials;
  15908. var customMaterial = object.customDepthMaterial;
  15909. if ( isPointLight ) {
  15910. materialVariants = _distanceMaterials;
  15911. customMaterial = object.customDistanceMaterial;
  15912. }
  15913. if ( ! customMaterial ) {
  15914. var useMorphing = geometry.morphTargets !== undefined &&
  15915. geometry.morphTargets.length > 0 && material.morphTargets;
  15916. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  15917. var variantIndex = 0;
  15918. if ( useMorphing ) variantIndex |= _MorphingFlag;
  15919. if ( useSkinning ) variantIndex |= _SkinningFlag;
  15920. newMaterial = materialVariants[ variantIndex ];
  15921. } else {
  15922. newMaterial = customMaterial;
  15923. }
  15924. newMaterial.visible = material.visible;
  15925. newMaterial.wireframe = material.wireframe;
  15926. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  15927. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  15928. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  15929. }
  15930. return newMaterial;
  15931. }
  15932. function projectObject( object, camera ) {
  15933. if ( object.visible === false ) return;
  15934. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15935. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  15936. var material = object.material;
  15937. if ( material.visible === true ) {
  15938. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15939. _renderList.push( object );
  15940. }
  15941. }
  15942. }
  15943. var children = object.children;
  15944. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15945. projectObject( children[ i ], camera );
  15946. }
  15947. }
  15948. };
  15949. // File:src/renderers/webgl/WebGLState.js
  15950. /**
  15951. * @author mrdoob / http://mrdoob.com/
  15952. */
  15953. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  15954. var _this = this;
  15955. var newAttributes = new Uint8Array( 16 );
  15956. var enabledAttributes = new Uint8Array( 16 );
  15957. var attributeDivisors = new Uint8Array( 16 );
  15958. var capabilities = {};
  15959. var compressedTextureFormats = null;
  15960. var currentBlending = null;
  15961. var currentBlendEquation = null;
  15962. var currentBlendSrc = null;
  15963. var currentBlendDst = null;
  15964. var currentBlendEquationAlpha = null;
  15965. var currentBlendSrcAlpha = null;
  15966. var currentBlendDstAlpha = null;
  15967. var currentDepthFunc = null;
  15968. var currentDepthWrite = null;
  15969. var currentColorWrite = null;
  15970. var currentFlipSided = null;
  15971. var currentLineWidth = null;
  15972. var currentPolygonOffsetFactor = null;
  15973. var currentPolygonOffsetUnits = null;
  15974. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  15975. var currentTextureSlot = undefined;
  15976. var currentBoundTextures = {};
  15977. this.init = function () {
  15978. gl.clearColor( 0, 0, 0, 1 );
  15979. gl.clearDepth( 1 );
  15980. gl.clearStencil( 0 );
  15981. this.enable( gl.DEPTH_TEST );
  15982. gl.depthFunc( gl.LEQUAL );
  15983. gl.frontFace( gl.CCW );
  15984. gl.cullFace( gl.BACK );
  15985. this.enable( gl.CULL_FACE );
  15986. this.enable( gl.BLEND );
  15987. gl.blendEquation( gl.FUNC_ADD );
  15988. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  15989. };
  15990. this.initAttributes = function () {
  15991. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  15992. newAttributes[ i ] = 0;
  15993. }
  15994. };
  15995. this.enableAttribute = function ( attribute ) {
  15996. newAttributes[ attribute ] = 1;
  15997. if ( enabledAttributes[ attribute ] === 0 ) {
  15998. gl.enableVertexAttribArray( attribute );
  15999. enabledAttributes[ attribute ] = 1;
  16000. }
  16001. if ( attributeDivisors[ attribute ] !== 0 ) {
  16002. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16003. extension.vertexAttribDivisorANGLE( attribute, 0 );
  16004. attributeDivisors[ attribute ] = 0;
  16005. }
  16006. };
  16007. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  16008. newAttributes[ attribute ] = 1;
  16009. if ( enabledAttributes[ attribute ] === 0 ) {
  16010. gl.enableVertexAttribArray( attribute );
  16011. enabledAttributes[ attribute ] = 1;
  16012. }
  16013. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  16014. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  16015. attributeDivisors[ attribute ] = meshPerAttribute;
  16016. }
  16017. };
  16018. this.disableUnusedAttributes = function () {
  16019. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  16020. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  16021. gl.disableVertexAttribArray( i );
  16022. enabledAttributes[ i ] = 0;
  16023. }
  16024. }
  16025. };
  16026. this.enable = function ( id ) {
  16027. if ( capabilities[ id ] !== true ) {
  16028. gl.enable( id );
  16029. capabilities[ id ] = true;
  16030. }
  16031. };
  16032. this.disable = function ( id ) {
  16033. if ( capabilities[ id ] !== false ) {
  16034. gl.disable( id );
  16035. capabilities[ id ] = false;
  16036. }
  16037. };
  16038. this.getCompressedTextureFormats = function () {
  16039. if ( compressedTextureFormats === null ) {
  16040. compressedTextureFormats = [];
  16041. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  16042. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  16043. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  16044. for ( var i = 0; i < formats.length; i ++ ) {
  16045. compressedTextureFormats.push( formats[ i ] );
  16046. }
  16047. }
  16048. }
  16049. return compressedTextureFormats;
  16050. };
  16051. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  16052. if ( blending !== currentBlending ) {
  16053. if ( blending === THREE.NoBlending ) {
  16054. this.disable( gl.BLEND );
  16055. } else if ( blending === THREE.AdditiveBlending ) {
  16056. this.enable( gl.BLEND );
  16057. gl.blendEquation( gl.FUNC_ADD );
  16058. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  16059. } else if ( blending === THREE.SubtractiveBlending ) {
  16060. // TODO: Find blendFuncSeparate() combination
  16061. this.enable( gl.BLEND );
  16062. gl.blendEquation( gl.FUNC_ADD );
  16063. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  16064. } else if ( blending === THREE.MultiplyBlending ) {
  16065. // TODO: Find blendFuncSeparate() combination
  16066. this.enable( gl.BLEND );
  16067. gl.blendEquation( gl.FUNC_ADD );
  16068. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  16069. } else if ( blending === THREE.CustomBlending ) {
  16070. this.enable( gl.BLEND );
  16071. } else {
  16072. this.enable( gl.BLEND );
  16073. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  16074. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  16075. }
  16076. currentBlending = blending;
  16077. }
  16078. if ( blending === THREE.CustomBlending ) {
  16079. blendEquationAlpha = blendEquationAlpha || blendEquation;
  16080. blendSrcAlpha = blendSrcAlpha || blendSrc;
  16081. blendDstAlpha = blendDstAlpha || blendDst;
  16082. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  16083. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  16084. currentBlendEquation = blendEquation;
  16085. currentBlendEquationAlpha = blendEquationAlpha;
  16086. }
  16087. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  16088. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  16089. currentBlendSrc = blendSrc;
  16090. currentBlendDst = blendDst;
  16091. currentBlendSrcAlpha = blendSrcAlpha;
  16092. currentBlendDstAlpha = blendDstAlpha;
  16093. }
  16094. } else {
  16095. currentBlendEquation = null;
  16096. currentBlendSrc = null;
  16097. currentBlendDst = null;
  16098. currentBlendEquationAlpha = null;
  16099. currentBlendSrcAlpha = null;
  16100. currentBlendDstAlpha = null;
  16101. }
  16102. };
  16103. this.setDepthFunc = function ( depthFunc ) {
  16104. if ( currentDepthFunc !== depthFunc ) {
  16105. if ( depthFunc ) {
  16106. switch ( depthFunc ) {
  16107. case THREE.NeverDepth:
  16108. gl.depthFunc( gl.NEVER );
  16109. break;
  16110. case THREE.AlwaysDepth:
  16111. gl.depthFunc( gl.ALWAYS );
  16112. break;
  16113. case THREE.LessDepth:
  16114. gl.depthFunc( gl.LESS );
  16115. break;
  16116. case THREE.LessEqualDepth:
  16117. gl.depthFunc( gl.LEQUAL );
  16118. break;
  16119. case THREE.EqualDepth:
  16120. gl.depthFunc( gl.EQUAL );
  16121. break;
  16122. case THREE.GreaterEqualDepth:
  16123. gl.depthFunc( gl.GEQUAL );
  16124. break;
  16125. case THREE.GreaterDepth:
  16126. gl.depthFunc( gl.GREATER );
  16127. break;
  16128. case THREE.NotEqualDepth:
  16129. gl.depthFunc( gl.NOTEQUAL );
  16130. break;
  16131. default:
  16132. gl.depthFunc( gl.LEQUAL );
  16133. }
  16134. } else {
  16135. gl.depthFunc( gl.LEQUAL );
  16136. }
  16137. currentDepthFunc = depthFunc;
  16138. }
  16139. };
  16140. this.setDepthTest = function ( depthTest ) {
  16141. if ( depthTest ) {
  16142. this.enable( gl.DEPTH_TEST );
  16143. } else {
  16144. this.disable( gl.DEPTH_TEST );
  16145. }
  16146. };
  16147. this.setDepthWrite = function ( depthWrite ) {
  16148. if ( currentDepthWrite !== depthWrite ) {
  16149. gl.depthMask( depthWrite );
  16150. currentDepthWrite = depthWrite;
  16151. }
  16152. };
  16153. this.setColorWrite = function ( colorWrite ) {
  16154. if ( currentColorWrite !== colorWrite ) {
  16155. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  16156. currentColorWrite = colorWrite;
  16157. }
  16158. };
  16159. this.setFlipSided = function ( flipSided ) {
  16160. if ( currentFlipSided !== flipSided ) {
  16161. if ( flipSided ) {
  16162. gl.frontFace( gl.CW );
  16163. } else {
  16164. gl.frontFace( gl.CCW );
  16165. }
  16166. currentFlipSided = flipSided;
  16167. }
  16168. };
  16169. this.setLineWidth = function ( width ) {
  16170. if ( width !== currentLineWidth ) {
  16171. gl.lineWidth( width );
  16172. currentLineWidth = width;
  16173. }
  16174. };
  16175. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  16176. if ( polygonOffset ) {
  16177. this.enable( gl.POLYGON_OFFSET_FILL );
  16178. } else {
  16179. this.disable( gl.POLYGON_OFFSET_FILL );
  16180. }
  16181. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  16182. gl.polygonOffset( factor, units );
  16183. currentPolygonOffsetFactor = factor;
  16184. currentPolygonOffsetUnits = units;
  16185. }
  16186. };
  16187. this.setScissorTest = function ( scissorTest ) {
  16188. if ( scissorTest ) {
  16189. this.enable( gl.SCISSOR_TEST );
  16190. } else {
  16191. this.disable( gl.SCISSOR_TEST );
  16192. }
  16193. };
  16194. // texture
  16195. this.activeTexture = function ( webglSlot ) {
  16196. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  16197. if ( currentTextureSlot !== webglSlot ) {
  16198. gl.activeTexture( webglSlot );
  16199. currentTextureSlot = webglSlot;
  16200. }
  16201. }
  16202. this.bindTexture = function ( webglType, webglTexture ) {
  16203. if ( currentTextureSlot === undefined ) {
  16204. _this.activeTexture();
  16205. }
  16206. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  16207. if ( boundTexture === undefined ) {
  16208. boundTexture = { type: undefined, texture: undefined };
  16209. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  16210. }
  16211. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  16212. gl.bindTexture( webglType, webglTexture );
  16213. boundTexture.type = webglType;
  16214. boundTexture.texture = webglTexture;
  16215. }
  16216. };
  16217. this.compressedTexImage2D = function () {
  16218. try {
  16219. gl.compressedTexImage2D.apply( gl, arguments );
  16220. } catch ( error ) {
  16221. console.error( error );
  16222. }
  16223. };
  16224. this.texImage2D = function () {
  16225. try {
  16226. gl.texImage2D.apply( gl, arguments );
  16227. } catch ( error ) {
  16228. console.error( error );
  16229. }
  16230. };
  16231. //
  16232. this.reset = function () {
  16233. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  16234. if ( enabledAttributes[ i ] === 1 ) {
  16235. gl.disableVertexAttribArray( i );
  16236. enabledAttributes[ i ] = 0;
  16237. }
  16238. }
  16239. capabilities = {};
  16240. compressedTextureFormats = null;
  16241. currentBlending = null;
  16242. currentDepthWrite = null;
  16243. currentColorWrite = null;
  16244. currentFlipSided = null;
  16245. };
  16246. };
  16247. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  16248. /**
  16249. * @author mikael emtinger / http://gomo.se/
  16250. * @author alteredq / http://alteredqualia.com/
  16251. */
  16252. THREE.LensFlarePlugin = function ( renderer, flares ) {
  16253. var gl = renderer.context;
  16254. var state = renderer.state;
  16255. var vertexBuffer, elementBuffer;
  16256. var program, attributes, uniforms;
  16257. var hasVertexTexture;
  16258. var tempTexture, occlusionTexture;
  16259. function init() {
  16260. var vertices = new Float32Array( [
  16261. - 1, - 1, 0, 0,
  16262. 1, - 1, 1, 0,
  16263. 1, 1, 1, 1,
  16264. - 1, 1, 0, 1
  16265. ] );
  16266. var faces = new Uint16Array( [
  16267. 0, 1, 2,
  16268. 0, 2, 3
  16269. ] );
  16270. // buffers
  16271. vertexBuffer = gl.createBuffer();
  16272. elementBuffer = gl.createBuffer();
  16273. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16274. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16275. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16276. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16277. // textures
  16278. tempTexture = gl.createTexture();
  16279. occlusionTexture = gl.createTexture();
  16280. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16281. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  16282. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16283. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16284. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16285. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16286. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16287. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  16288. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16289. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16290. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16291. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16292. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  16293. var shader;
  16294. if ( hasVertexTexture ) {
  16295. shader = {
  16296. vertexShader: [
  16297. "uniform lowp int renderType;",
  16298. "uniform vec3 screenPosition;",
  16299. "uniform vec2 scale;",
  16300. "uniform float rotation;",
  16301. "uniform sampler2D occlusionMap;",
  16302. "attribute vec2 position;",
  16303. "attribute vec2 uv;",
  16304. "varying vec2 vUV;",
  16305. "varying float vVisibility;",
  16306. "void main() {",
  16307. "vUV = uv;",
  16308. "vec2 pos = position;",
  16309. "if ( renderType == 2 ) {",
  16310. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  16311. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  16312. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  16313. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  16314. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  16315. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  16316. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  16317. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  16318. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  16319. "vVisibility = visibility.r / 9.0;",
  16320. "vVisibility *= 1.0 - visibility.g / 9.0;",
  16321. "vVisibility *= visibility.b / 9.0;",
  16322. "vVisibility *= 1.0 - visibility.a / 9.0;",
  16323. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16324. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16325. "}",
  16326. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16327. "}"
  16328. ].join( "\n" ),
  16329. fragmentShader: [
  16330. "uniform lowp int renderType;",
  16331. "uniform sampler2D map;",
  16332. "uniform float opacity;",
  16333. "uniform vec3 color;",
  16334. "varying vec2 vUV;",
  16335. "varying float vVisibility;",
  16336. "void main() {",
  16337. // pink square
  16338. "if ( renderType == 0 ) {",
  16339. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  16340. // restore
  16341. "} else if ( renderType == 1 ) {",
  16342. "gl_FragColor = texture2D( map, vUV );",
  16343. // flare
  16344. "} else {",
  16345. "vec4 texture = texture2D( map, vUV );",
  16346. "texture.a *= opacity * vVisibility;",
  16347. "gl_FragColor = texture;",
  16348. "gl_FragColor.rgb *= color;",
  16349. "}",
  16350. "}"
  16351. ].join( "\n" )
  16352. };
  16353. } else {
  16354. shader = {
  16355. vertexShader: [
  16356. "uniform lowp int renderType;",
  16357. "uniform vec3 screenPosition;",
  16358. "uniform vec2 scale;",
  16359. "uniform float rotation;",
  16360. "attribute vec2 position;",
  16361. "attribute vec2 uv;",
  16362. "varying vec2 vUV;",
  16363. "void main() {",
  16364. "vUV = uv;",
  16365. "vec2 pos = position;",
  16366. "if ( renderType == 2 ) {",
  16367. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16368. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16369. "}",
  16370. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16371. "}"
  16372. ].join( "\n" ),
  16373. fragmentShader: [
  16374. "precision mediump float;",
  16375. "uniform lowp int renderType;",
  16376. "uniform sampler2D map;",
  16377. "uniform sampler2D occlusionMap;",
  16378. "uniform float opacity;",
  16379. "uniform vec3 color;",
  16380. "varying vec2 vUV;",
  16381. "void main() {",
  16382. // pink square
  16383. "if ( renderType == 0 ) {",
  16384. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  16385. // restore
  16386. "} else if ( renderType == 1 ) {",
  16387. "gl_FragColor = texture2D( map, vUV );",
  16388. // flare
  16389. "} else {",
  16390. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  16391. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  16392. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  16393. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  16394. "visibility = ( 1.0 - visibility / 4.0 );",
  16395. "vec4 texture = texture2D( map, vUV );",
  16396. "texture.a *= opacity * visibility;",
  16397. "gl_FragColor = texture;",
  16398. "gl_FragColor.rgb *= color;",
  16399. "}",
  16400. "}"
  16401. ].join( "\n" )
  16402. };
  16403. }
  16404. program = createProgram( shader );
  16405. attributes = {
  16406. vertex: gl.getAttribLocation ( program, "position" ),
  16407. uv: gl.getAttribLocation ( program, "uv" )
  16408. };
  16409. uniforms = {
  16410. renderType: gl.getUniformLocation( program, "renderType" ),
  16411. map: gl.getUniformLocation( program, "map" ),
  16412. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  16413. opacity: gl.getUniformLocation( program, "opacity" ),
  16414. color: gl.getUniformLocation( program, "color" ),
  16415. scale: gl.getUniformLocation( program, "scale" ),
  16416. rotation: gl.getUniformLocation( program, "rotation" ),
  16417. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  16418. };
  16419. }
  16420. /*
  16421. * Render lens flares
  16422. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  16423. * reads these back and calculates occlusion.
  16424. */
  16425. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  16426. if ( flares.length === 0 ) return;
  16427. var tempPosition = new THREE.Vector3();
  16428. var invAspect = viewportHeight / viewportWidth,
  16429. halfViewportWidth = viewportWidth * 0.5,
  16430. halfViewportHeight = viewportHeight * 0.5;
  16431. var size = 16 / viewportHeight,
  16432. scale = new THREE.Vector2( size * invAspect, size );
  16433. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  16434. screenPositionPixels = new THREE.Vector2( 1, 1 );
  16435. if ( program === undefined ) {
  16436. init();
  16437. }
  16438. gl.useProgram( program );
  16439. state.initAttributes();
  16440. state.enableAttribute( attributes.vertex );
  16441. state.enableAttribute( attributes.uv );
  16442. state.disableUnusedAttributes();
  16443. // loop through all lens flares to update their occlusion and positions
  16444. // setup gl and common used attribs/uniforms
  16445. gl.uniform1i( uniforms.occlusionMap, 0 );
  16446. gl.uniform1i( uniforms.map, 1 );
  16447. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16448. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  16449. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16450. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16451. state.disable( gl.CULL_FACE );
  16452. gl.depthMask( false );
  16453. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  16454. size = 16 / viewportHeight;
  16455. scale.set( size * invAspect, size );
  16456. // calc object screen position
  16457. var flare = flares[ i ];
  16458. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  16459. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  16460. tempPosition.applyProjection( camera.projectionMatrix );
  16461. // setup arrays for gl programs
  16462. screenPosition.copy( tempPosition );
  16463. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  16464. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  16465. // screen cull
  16466. if ( hasVertexTexture || (
  16467. screenPositionPixels.x > 0 &&
  16468. screenPositionPixels.x < viewportWidth &&
  16469. screenPositionPixels.y > 0 &&
  16470. screenPositionPixels.y < viewportHeight ) ) {
  16471. // save current RGB to temp texture
  16472. state.activeTexture( gl.TEXTURE0 );
  16473. state.bindTexture( gl.TEXTURE_2D, null );
  16474. state.activeTexture( gl.TEXTURE1 );
  16475. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16476. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16477. // render pink quad
  16478. gl.uniform1i( uniforms.renderType, 0 );
  16479. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16480. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16481. state.disable( gl.BLEND );
  16482. state.enable( gl.DEPTH_TEST );
  16483. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16484. // copy result to occlusionMap
  16485. state.activeTexture( gl.TEXTURE0 );
  16486. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16487. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16488. // restore graphics
  16489. gl.uniform1i( uniforms.renderType, 1 );
  16490. state.disable( gl.DEPTH_TEST );
  16491. state.activeTexture( gl.TEXTURE1 );
  16492. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16493. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16494. // update object positions
  16495. flare.positionScreen.copy( screenPosition );
  16496. if ( flare.customUpdateCallback ) {
  16497. flare.customUpdateCallback( flare );
  16498. } else {
  16499. flare.updateLensFlares();
  16500. }
  16501. // render flares
  16502. gl.uniform1i( uniforms.renderType, 2 );
  16503. state.enable( gl.BLEND );
  16504. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  16505. var sprite = flare.lensFlares[ j ];
  16506. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  16507. screenPosition.x = sprite.x;
  16508. screenPosition.y = sprite.y;
  16509. screenPosition.z = sprite.z;
  16510. size = sprite.size * sprite.scale / viewportHeight;
  16511. scale.x = size * invAspect;
  16512. scale.y = size;
  16513. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16514. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16515. gl.uniform1f( uniforms.rotation, sprite.rotation );
  16516. gl.uniform1f( uniforms.opacity, sprite.opacity );
  16517. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  16518. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  16519. renderer.setTexture( sprite.texture, 1 );
  16520. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16521. }
  16522. }
  16523. }
  16524. }
  16525. // restore gl
  16526. state.enable( gl.CULL_FACE );
  16527. state.enable( gl.DEPTH_TEST );
  16528. gl.depthMask( true );
  16529. renderer.resetGLState();
  16530. };
  16531. function createProgram ( shader ) {
  16532. var program = gl.createProgram();
  16533. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16534. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16535. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  16536. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  16537. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  16538. gl.compileShader( fragmentShader );
  16539. gl.compileShader( vertexShader );
  16540. gl.attachShader( program, fragmentShader );
  16541. gl.attachShader( program, vertexShader );
  16542. gl.linkProgram( program );
  16543. return program;
  16544. }
  16545. };
  16546. // File:src/renderers/webgl/plugins/SpritePlugin.js
  16547. /**
  16548. * @author mikael emtinger / http://gomo.se/
  16549. * @author alteredq / http://alteredqualia.com/
  16550. */
  16551. THREE.SpritePlugin = function ( renderer, sprites ) {
  16552. var gl = renderer.context;
  16553. var state = renderer.state;
  16554. var vertexBuffer, elementBuffer;
  16555. var program, attributes, uniforms;
  16556. var texture;
  16557. // decompose matrixWorld
  16558. var spritePosition = new THREE.Vector3();
  16559. var spriteRotation = new THREE.Quaternion();
  16560. var spriteScale = new THREE.Vector3();
  16561. function init() {
  16562. var vertices = new Float32Array( [
  16563. - 0.5, - 0.5, 0, 0,
  16564. 0.5, - 0.5, 1, 0,
  16565. 0.5, 0.5, 1, 1,
  16566. - 0.5, 0.5, 0, 1
  16567. ] );
  16568. var faces = new Uint16Array( [
  16569. 0, 1, 2,
  16570. 0, 2, 3
  16571. ] );
  16572. vertexBuffer = gl.createBuffer();
  16573. elementBuffer = gl.createBuffer();
  16574. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16575. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16576. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16577. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16578. program = createProgram();
  16579. attributes = {
  16580. position: gl.getAttribLocation ( program, 'position' ),
  16581. uv: gl.getAttribLocation ( program, 'uv' )
  16582. };
  16583. uniforms = {
  16584. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  16585. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  16586. rotation: gl.getUniformLocation( program, 'rotation' ),
  16587. scale: gl.getUniformLocation( program, 'scale' ),
  16588. color: gl.getUniformLocation( program, 'color' ),
  16589. map: gl.getUniformLocation( program, 'map' ),
  16590. opacity: gl.getUniformLocation( program, 'opacity' ),
  16591. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  16592. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  16593. fogType: gl.getUniformLocation( program, 'fogType' ),
  16594. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  16595. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  16596. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  16597. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  16598. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  16599. };
  16600. var canvas = document.createElement( 'canvas' );
  16601. canvas.width = 8;
  16602. canvas.height = 8;
  16603. var context = canvas.getContext( '2d' );
  16604. context.fillStyle = 'white';
  16605. context.fillRect( 0, 0, 8, 8 );
  16606. texture = new THREE.Texture( canvas );
  16607. texture.needsUpdate = true;
  16608. }
  16609. this.render = function ( scene, camera ) {
  16610. if ( sprites.length === 0 ) return;
  16611. // setup gl
  16612. if ( program === undefined ) {
  16613. init();
  16614. }
  16615. gl.useProgram( program );
  16616. state.initAttributes();
  16617. state.enableAttribute( attributes.position );
  16618. state.enableAttribute( attributes.uv );
  16619. state.disableUnusedAttributes();
  16620. state.disable( gl.CULL_FACE );
  16621. state.enable( gl.BLEND );
  16622. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16623. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  16624. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16625. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16626. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  16627. state.activeTexture( gl.TEXTURE0 );
  16628. gl.uniform1i( uniforms.map, 0 );
  16629. var oldFogType = 0;
  16630. var sceneFogType = 0;
  16631. var fog = scene.fog;
  16632. if ( fog ) {
  16633. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  16634. if ( fog instanceof THREE.Fog ) {
  16635. gl.uniform1f( uniforms.fogNear, fog.near );
  16636. gl.uniform1f( uniforms.fogFar, fog.far );
  16637. gl.uniform1i( uniforms.fogType, 1 );
  16638. oldFogType = 1;
  16639. sceneFogType = 1;
  16640. } else if ( fog instanceof THREE.FogExp2 ) {
  16641. gl.uniform1f( uniforms.fogDensity, fog.density );
  16642. gl.uniform1i( uniforms.fogType, 2 );
  16643. oldFogType = 2;
  16644. sceneFogType = 2;
  16645. }
  16646. } else {
  16647. gl.uniform1i( uniforms.fogType, 0 );
  16648. oldFogType = 0;
  16649. sceneFogType = 0;
  16650. }
  16651. // update positions and sort
  16652. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16653. var sprite = sprites[ i ];
  16654. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  16655. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  16656. }
  16657. sprites.sort( painterSortStable );
  16658. // render all sprites
  16659. var scale = [];
  16660. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16661. var sprite = sprites[ i ];
  16662. var material = sprite.material;
  16663. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  16664. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  16665. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  16666. scale[ 0 ] = spriteScale.x;
  16667. scale[ 1 ] = spriteScale.y;
  16668. var fogType = 0;
  16669. if ( scene.fog && material.fog ) {
  16670. fogType = sceneFogType;
  16671. }
  16672. if ( oldFogType !== fogType ) {
  16673. gl.uniform1i( uniforms.fogType, fogType );
  16674. oldFogType = fogType;
  16675. }
  16676. if ( material.map !== null ) {
  16677. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  16678. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  16679. } else {
  16680. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  16681. gl.uniform2f( uniforms.uvScale, 1, 1 );
  16682. }
  16683. gl.uniform1f( uniforms.opacity, material.opacity );
  16684. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  16685. gl.uniform1f( uniforms.rotation, material.rotation );
  16686. gl.uniform2fv( uniforms.scale, scale );
  16687. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  16688. state.setDepthTest( material.depthTest );
  16689. state.setDepthWrite( material.depthWrite );
  16690. if ( material.map && material.map.image && material.map.image.width ) {
  16691. renderer.setTexture( material.map, 0 );
  16692. } else {
  16693. renderer.setTexture( texture, 0 );
  16694. }
  16695. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16696. }
  16697. // restore gl
  16698. state.enable( gl.CULL_FACE );
  16699. renderer.resetGLState();
  16700. };
  16701. function createProgram () {
  16702. var program = gl.createProgram();
  16703. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16704. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16705. gl.shaderSource( vertexShader, [
  16706. 'precision ' + renderer.getPrecision() + ' float;',
  16707. 'uniform mat4 modelViewMatrix;',
  16708. 'uniform mat4 projectionMatrix;',
  16709. 'uniform float rotation;',
  16710. 'uniform vec2 scale;',
  16711. 'uniform vec2 uvOffset;',
  16712. 'uniform vec2 uvScale;',
  16713. 'attribute vec2 position;',
  16714. 'attribute vec2 uv;',
  16715. 'varying vec2 vUV;',
  16716. 'void main() {',
  16717. 'vUV = uvOffset + uv * uvScale;',
  16718. 'vec2 alignedPosition = position * scale;',
  16719. 'vec2 rotatedPosition;',
  16720. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  16721. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  16722. 'vec4 finalPosition;',
  16723. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  16724. 'finalPosition.xy += rotatedPosition;',
  16725. 'finalPosition = projectionMatrix * finalPosition;',
  16726. 'gl_Position = finalPosition;',
  16727. '}'
  16728. ].join( '\n' ) );
  16729. gl.shaderSource( fragmentShader, [
  16730. 'precision ' + renderer.getPrecision() + ' float;',
  16731. 'uniform vec3 color;',
  16732. 'uniform sampler2D map;',
  16733. 'uniform float opacity;',
  16734. 'uniform int fogType;',
  16735. 'uniform vec3 fogColor;',
  16736. 'uniform float fogDensity;',
  16737. 'uniform float fogNear;',
  16738. 'uniform float fogFar;',
  16739. 'uniform float alphaTest;',
  16740. 'varying vec2 vUV;',
  16741. 'void main() {',
  16742. 'vec4 texture = texture2D( map, vUV );',
  16743. 'if ( texture.a < alphaTest ) discard;',
  16744. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  16745. 'if ( fogType > 0 ) {',
  16746. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  16747. 'float fogFactor = 0.0;',
  16748. 'if ( fogType == 1 ) {',
  16749. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  16750. '} else {',
  16751. 'const float LOG2 = 1.442695;',
  16752. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  16753. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  16754. '}',
  16755. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  16756. '}',
  16757. '}'
  16758. ].join( '\n' ) );
  16759. gl.compileShader( vertexShader );
  16760. gl.compileShader( fragmentShader );
  16761. gl.attachShader( program, vertexShader );
  16762. gl.attachShader( program, fragmentShader );
  16763. gl.linkProgram( program );
  16764. return program;
  16765. }
  16766. function painterSortStable ( a, b ) {
  16767. if ( a.z !== b.z ) {
  16768. return b.z - a.z;
  16769. } else {
  16770. return b.id - a.id;
  16771. }
  16772. }
  16773. };
  16774. // File:src/extras/CurveUtils.js
  16775. /**
  16776. * @author zz85 / http://www.lab4games.net/zz85/blog
  16777. */
  16778. THREE.CurveUtils = {
  16779. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  16780. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  16781. },
  16782. // Puay Bing, thanks for helping with this derivative!
  16783. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  16784. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  16785. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  16786. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  16787. 3 * t * t * p3;
  16788. },
  16789. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  16790. // To check if my formulas are correct
  16791. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  16792. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  16793. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  16794. var h11 = 3 * t * t - 2 * t; // t3 − t2
  16795. return h00 + h10 + h01 + h11;
  16796. },
  16797. // Catmull-Rom
  16798. interpolate: function( p0, p1, p2, p3, t ) {
  16799. var v0 = ( p2 - p0 ) * 0.5;
  16800. var v1 = ( p3 - p1 ) * 0.5;
  16801. var t2 = t * t;
  16802. var t3 = t * t2;
  16803. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  16804. }
  16805. };
  16806. // File:src/extras/GeometryUtils.js
  16807. /**
  16808. * @author mrdoob / http://mrdoob.com/
  16809. */
  16810. THREE.GeometryUtils = {
  16811. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  16812. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  16813. var matrix;
  16814. if ( geometry2 instanceof THREE.Mesh ) {
  16815. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  16816. matrix = geometry2.matrix;
  16817. geometry2 = geometry2.geometry;
  16818. }
  16819. geometry1.merge( geometry2, matrix, materialIndexOffset );
  16820. },
  16821. center: function ( geometry ) {
  16822. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  16823. return geometry.center();
  16824. }
  16825. };
  16826. // File:src/extras/ImageUtils.js
  16827. /**
  16828. * @author alteredq / http://alteredqualia.com/
  16829. * @author mrdoob / http://mrdoob.com/
  16830. * @author Daosheng Mu / https://github.com/DaoshengMu/
  16831. */
  16832. THREE.ImageUtils = {
  16833. crossOrigin: undefined,
  16834. loadTexture: function ( url, mapping, onLoad, onError ) {
  16835. console.warn( 'THREE.ImageUtils.loadTexture is being deprecated. Use THREE.TextureLoader() instead.' );
  16836. var loader = new THREE.TextureLoader();
  16837. loader.setCrossOrigin( this.crossOrigin );
  16838. var texture = loader.load( url, onLoad, undefined, onError );
  16839. if ( mapping ) texture.mapping = mapping;
  16840. return texture;
  16841. },
  16842. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  16843. console.warn( 'THREE.ImageUtils.loadTextureCube is being deprecated. Use THREE.CubeTextureLoader() instead.' );
  16844. var loader = new THREE.CubeTextureLoader();
  16845. loader.setCrossOrigin( this.crossOrigin );
  16846. var texture = loader.load( urls, onLoad, undefined, onError );
  16847. if ( mapping ) texture.mapping = mapping;
  16848. return texture;
  16849. },
  16850. loadCompressedTexture: function () {
  16851. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  16852. },
  16853. loadCompressedTextureCube: function () {
  16854. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  16855. }
  16856. };
  16857. // File:src/extras/SceneUtils.js
  16858. /**
  16859. * @author alteredq / http://alteredqualia.com/
  16860. */
  16861. THREE.SceneUtils = {
  16862. createMultiMaterialObject: function ( geometry, materials ) {
  16863. var group = new THREE.Group();
  16864. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  16865. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  16866. }
  16867. return group;
  16868. },
  16869. detach: function ( child, parent, scene ) {
  16870. child.applyMatrix( parent.matrixWorld );
  16871. parent.remove( child );
  16872. scene.add( child );
  16873. },
  16874. attach: function ( child, scene, parent ) {
  16875. var matrixWorldInverse = new THREE.Matrix4();
  16876. matrixWorldInverse.getInverse( parent.matrixWorld );
  16877. child.applyMatrix( matrixWorldInverse );
  16878. scene.remove( child );
  16879. parent.add( child );
  16880. }
  16881. };
  16882. // File:src/extras/ShapeUtils.js
  16883. /**
  16884. * @author zz85 / http://www.lab4games.net/zz85/blog
  16885. */
  16886. THREE.ShapeUtils = {
  16887. // calculate area of the contour polygon
  16888. area: function ( contour ) {
  16889. var n = contour.length;
  16890. var a = 0.0;
  16891. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  16892. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  16893. }
  16894. return a * 0.5;
  16895. },
  16896. triangulate: ( function () {
  16897. /**
  16898. * This code is a quick port of code written in C++ which was submitted to
  16899. * flipcode.com by John W. Ratcliff // July 22, 2000
  16900. * See original code and more information here:
  16901. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  16902. *
  16903. * ported to actionscript by Zevan Rosser
  16904. * www.actionsnippet.com
  16905. *
  16906. * ported to javascript by Joshua Koo
  16907. * http://www.lab4games.net/zz85/blog
  16908. *
  16909. */
  16910. function snip( contour, u, v, w, n, verts ) {
  16911. var p;
  16912. var ax, ay, bx, by;
  16913. var cx, cy, px, py;
  16914. ax = contour[ verts[ u ] ].x;
  16915. ay = contour[ verts[ u ] ].y;
  16916. bx = contour[ verts[ v ] ].x;
  16917. by = contour[ verts[ v ] ].y;
  16918. cx = contour[ verts[ w ] ].x;
  16919. cy = contour[ verts[ w ] ].y;
  16920. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  16921. var aX, aY, bX, bY, cX, cY;
  16922. var apx, apy, bpx, bpy, cpx, cpy;
  16923. var cCROSSap, bCROSScp, aCROSSbp;
  16924. aX = cx - bx; aY = cy - by;
  16925. bX = ax - cx; bY = ay - cy;
  16926. cX = bx - ax; cY = by - ay;
  16927. for ( p = 0; p < n; p ++ ) {
  16928. px = contour[ verts[ p ] ].x;
  16929. py = contour[ verts[ p ] ].y;
  16930. if ( ( ( px === ax ) && ( py === ay ) ) ||
  16931. ( ( px === bx ) && ( py === by ) ) ||
  16932. ( ( px === cx ) && ( py === cy ) ) ) continue;
  16933. apx = px - ax; apy = py - ay;
  16934. bpx = px - bx; bpy = py - by;
  16935. cpx = px - cx; cpy = py - cy;
  16936. // see if p is inside triangle abc
  16937. aCROSSbp = aX * bpy - aY * bpx;
  16938. cCROSSap = cX * apy - cY * apx;
  16939. bCROSScp = bX * cpy - bY * cpx;
  16940. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  16941. }
  16942. return true;
  16943. }
  16944. // takes in an contour array and returns
  16945. return function ( contour, indices ) {
  16946. var n = contour.length;
  16947. if ( n < 3 ) return null;
  16948. var result = [],
  16949. verts = [],
  16950. vertIndices = [];
  16951. /* we want a counter-clockwise polygon in verts */
  16952. var u, v, w;
  16953. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  16954. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  16955. } else {
  16956. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  16957. }
  16958. var nv = n;
  16959. /* remove nv - 2 vertices, creating 1 triangle every time */
  16960. var count = 2 * nv; /* error detection */
  16961. for ( v = nv - 1; nv > 2; ) {
  16962. /* if we loop, it is probably a non-simple polygon */
  16963. if ( ( count -- ) <= 0 ) {
  16964. //** Triangulate: ERROR - probable bad polygon!
  16965. //throw ( "Warning, unable to triangulate polygon!" );
  16966. //return null;
  16967. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  16968. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  16969. if ( indices ) return vertIndices;
  16970. return result;
  16971. }
  16972. /* three consecutive vertices in current polygon, <u,v,w> */
  16973. u = v; if ( nv <= u ) u = 0; /* previous */
  16974. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  16975. w = v + 1; if ( nv <= w ) w = 0; /* next */
  16976. if ( snip( contour, u, v, w, nv, verts ) ) {
  16977. var a, b, c, s, t;
  16978. /* true names of the vertices */
  16979. a = verts[ u ];
  16980. b = verts[ v ];
  16981. c = verts[ w ];
  16982. /* output Triangle */
  16983. result.push( [ contour[ a ],
  16984. contour[ b ],
  16985. contour[ c ] ] );
  16986. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  16987. /* remove v from the remaining polygon */
  16988. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  16989. verts[ s ] = verts[ t ];
  16990. }
  16991. nv --;
  16992. /* reset error detection counter */
  16993. count = 2 * nv;
  16994. }
  16995. }
  16996. if ( indices ) return vertIndices;
  16997. return result;
  16998. }
  16999. } )(),
  17000. triangulateShape: function ( contour, holes ) {
  17001. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  17002. // inOtherPt needs to be collinear to the inSegment
  17003. if ( inSegPt1.x !== inSegPt2.x ) {
  17004. if ( inSegPt1.x < inSegPt2.x ) {
  17005. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  17006. } else {
  17007. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  17008. }
  17009. } else {
  17010. if ( inSegPt1.y < inSegPt2.y ) {
  17011. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  17012. } else {
  17013. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  17014. }
  17015. }
  17016. }
  17017. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  17018. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  17019. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  17020. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  17021. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  17022. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  17023. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  17024. if ( Math.abs( limit ) > Number.EPSILON ) {
  17025. // not parallel
  17026. var perpSeg2;
  17027. if ( limit > 0 ) {
  17028. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  17029. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17030. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  17031. } else {
  17032. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  17033. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17034. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  17035. }
  17036. // i.e. to reduce rounding errors
  17037. // intersection at endpoint of segment#1?
  17038. if ( perpSeg2 === 0 ) {
  17039. if ( ( inExcludeAdjacentSegs ) &&
  17040. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17041. return [ inSeg1Pt1 ];
  17042. }
  17043. if ( perpSeg2 === limit ) {
  17044. if ( ( inExcludeAdjacentSegs ) &&
  17045. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17046. return [ inSeg1Pt2 ];
  17047. }
  17048. // intersection at endpoint of segment#2?
  17049. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  17050. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  17051. // return real intersection point
  17052. var factorSeg1 = perpSeg2 / limit;
  17053. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  17054. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  17055. } else {
  17056. // parallel or collinear
  17057. if ( ( perpSeg1 !== 0 ) ||
  17058. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  17059. // they are collinear or degenerate
  17060. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  17061. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  17062. // both segments are points
  17063. if ( seg1Pt && seg2Pt ) {
  17064. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  17065. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  17066. return [ inSeg1Pt1 ]; // they are the same point
  17067. }
  17068. // segment#1 is a single point
  17069. if ( seg1Pt ) {
  17070. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  17071. return [ inSeg1Pt1 ];
  17072. }
  17073. // segment#2 is a single point
  17074. if ( seg2Pt ) {
  17075. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  17076. return [ inSeg2Pt1 ];
  17077. }
  17078. // they are collinear segments, which might overlap
  17079. var seg1min, seg1max, seg1minVal, seg1maxVal;
  17080. var seg2min, seg2max, seg2minVal, seg2maxVal;
  17081. if ( seg1dx !== 0 ) {
  17082. // the segments are NOT on a vertical line
  17083. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  17084. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  17085. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  17086. } else {
  17087. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  17088. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  17089. }
  17090. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  17091. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  17092. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  17093. } else {
  17094. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  17095. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  17096. }
  17097. } else {
  17098. // the segments are on a vertical line
  17099. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  17100. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  17101. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  17102. } else {
  17103. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  17104. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  17105. }
  17106. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  17107. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  17108. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  17109. } else {
  17110. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  17111. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  17112. }
  17113. }
  17114. if ( seg1minVal <= seg2minVal ) {
  17115. if ( seg1maxVal < seg2minVal ) return [];
  17116. if ( seg1maxVal === seg2minVal ) {
  17117. if ( inExcludeAdjacentSegs ) return [];
  17118. return [ seg2min ];
  17119. }
  17120. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  17121. return [ seg2min, seg2max ];
  17122. } else {
  17123. if ( seg1minVal > seg2maxVal ) return [];
  17124. if ( seg1minVal === seg2maxVal ) {
  17125. if ( inExcludeAdjacentSegs ) return [];
  17126. return [ seg1min ];
  17127. }
  17128. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  17129. return [ seg1min, seg2max ];
  17130. }
  17131. }
  17132. }
  17133. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  17134. // The order of legs is important
  17135. // translation of all points, so that Vertex is at (0,0)
  17136. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  17137. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  17138. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  17139. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  17140. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  17141. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  17142. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  17143. // angle != 180 deg.
  17144. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  17145. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  17146. if ( from2toAngle > 0 ) {
  17147. // main angle < 180 deg.
  17148. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  17149. } else {
  17150. // main angle > 180 deg.
  17151. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  17152. }
  17153. } else {
  17154. // angle == 180 deg.
  17155. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  17156. return ( from2otherAngle > 0 );
  17157. }
  17158. }
  17159. function removeHoles( contour, holes ) {
  17160. var shape = contour.concat(); // work on this shape
  17161. var hole;
  17162. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  17163. // Check if hole point lies within angle around shape point
  17164. var lastShapeIdx = shape.length - 1;
  17165. var prevShapeIdx = inShapeIdx - 1;
  17166. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  17167. var nextShapeIdx = inShapeIdx + 1;
  17168. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  17169. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  17170. if ( ! insideAngle ) {
  17171. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  17172. return false;
  17173. }
  17174. // Check if shape point lies within angle around hole point
  17175. var lastHoleIdx = hole.length - 1;
  17176. var prevHoleIdx = inHoleIdx - 1;
  17177. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  17178. var nextHoleIdx = inHoleIdx + 1;
  17179. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  17180. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  17181. if ( ! insideAngle ) {
  17182. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  17183. return false;
  17184. }
  17185. return true;
  17186. }
  17187. function intersectsShapeEdge( inShapePt, inHolePt ) {
  17188. // checks for intersections with shape edges
  17189. var sIdx, nextIdx, intersection;
  17190. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  17191. nextIdx = sIdx + 1; nextIdx %= shape.length;
  17192. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  17193. if ( intersection.length > 0 ) return true;
  17194. }
  17195. return false;
  17196. }
  17197. var indepHoles = [];
  17198. function intersectsHoleEdge( inShapePt, inHolePt ) {
  17199. // checks for intersections with hole edges
  17200. var ihIdx, chkHole,
  17201. hIdx, nextIdx, intersection;
  17202. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  17203. chkHole = holes[ indepHoles[ ihIdx ]];
  17204. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  17205. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  17206. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  17207. if ( intersection.length > 0 ) return true;
  17208. }
  17209. }
  17210. return false;
  17211. }
  17212. var holeIndex, shapeIndex,
  17213. shapePt, holePt,
  17214. holeIdx, cutKey, failedCuts = [],
  17215. tmpShape1, tmpShape2,
  17216. tmpHole1, tmpHole2;
  17217. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17218. indepHoles.push( h );
  17219. }
  17220. var minShapeIndex = 0;
  17221. var counter = indepHoles.length * 2;
  17222. while ( indepHoles.length > 0 ) {
  17223. counter --;
  17224. if ( counter < 0 ) {
  17225. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  17226. break;
  17227. }
  17228. // search for shape-vertex and hole-vertex,
  17229. // which can be connected without intersections
  17230. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  17231. shapePt = shape[ shapeIndex ];
  17232. holeIndex = - 1;
  17233. // search for hole which can be reached without intersections
  17234. for ( var h = 0; h < indepHoles.length; h ++ ) {
  17235. holeIdx = indepHoles[ h ];
  17236. // prevent multiple checks
  17237. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  17238. if ( failedCuts[ cutKey ] !== undefined ) continue;
  17239. hole = holes[ holeIdx ];
  17240. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  17241. holePt = hole[ h2 ];
  17242. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  17243. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17244. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17245. holeIndex = h2;
  17246. indepHoles.splice( h, 1 );
  17247. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17248. tmpShape2 = shape.slice( shapeIndex );
  17249. tmpHole1 = hole.slice( holeIndex );
  17250. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17251. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17252. minShapeIndex = shapeIndex;
  17253. // Debug only, to show the selected cuts
  17254. // glob_CutLines.push( [ shapePt, holePt ] );
  17255. break;
  17256. }
  17257. if ( holeIndex >= 0 ) break; // hole-vertex found
  17258. failedCuts[ cutKey ] = true; // remember failure
  17259. }
  17260. if ( holeIndex >= 0 ) break; // hole-vertex found
  17261. }
  17262. }
  17263. return shape; /* shape with no holes */
  17264. }
  17265. var i, il, f, face,
  17266. key, index,
  17267. allPointsMap = {};
  17268. // 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.
  17269. var allpoints = contour.concat();
  17270. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17271. Array.prototype.push.apply( allpoints, holes[ h ] );
  17272. }
  17273. //console.log( "allpoints",allpoints, allpoints.length );
  17274. // prepare all points map
  17275. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17276. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  17277. if ( allPointsMap[ key ] !== undefined ) {
  17278. console.warn( "THREE.Shape: Duplicate point", key );
  17279. }
  17280. allPointsMap[ key ] = i;
  17281. }
  17282. // remove holes by cutting paths to holes and adding them to the shape
  17283. var shapeWithoutHoles = removeHoles( contour, holes );
  17284. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17285. //console.log( "triangles",triangles, triangles.length );
  17286. // check all face vertices against all points map
  17287. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17288. face = triangles[ i ];
  17289. for ( f = 0; f < 3; f ++ ) {
  17290. key = face[ f ].x + ":" + face[ f ].y;
  17291. index = allPointsMap[ key ];
  17292. if ( index !== undefined ) {
  17293. face[ f ] = index;
  17294. }
  17295. }
  17296. }
  17297. return triangles.concat();
  17298. },
  17299. isClockWise: function ( pts ) {
  17300. return THREE.ShapeUtils.area( pts ) < 0;
  17301. },
  17302. // Bezier Curves formulas obtained from
  17303. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  17304. // Quad Bezier Functions
  17305. b2: ( function () {
  17306. function b2p0( t, p ) {
  17307. var k = 1 - t;
  17308. return k * k * p;
  17309. }
  17310. function b2p1( t, p ) {
  17311. return 2 * ( 1 - t ) * t * p;
  17312. }
  17313. function b2p2( t, p ) {
  17314. return t * t * p;
  17315. }
  17316. return function ( t, p0, p1, p2 ) {
  17317. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  17318. };
  17319. } )(),
  17320. // Cubic Bezier Functions
  17321. b3: ( function () {
  17322. function b3p0( t, p ) {
  17323. var k = 1 - t;
  17324. return k * k * k * p;
  17325. }
  17326. function b3p1( t, p ) {
  17327. var k = 1 - t;
  17328. return 3 * k * k * t * p;
  17329. }
  17330. function b3p2( t, p ) {
  17331. var k = 1 - t;
  17332. return 3 * k * t * t * p;
  17333. }
  17334. function b3p3( t, p ) {
  17335. return t * t * t * p;
  17336. }
  17337. return function ( t, p0, p1, p2, p3 ) {
  17338. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  17339. };
  17340. } )()
  17341. };
  17342. // File:src/extras/audio/Audio.js
  17343. /**
  17344. * @author mrdoob / http://mrdoob.com/
  17345. */
  17346. THREE.Audio = function ( listener ) {
  17347. THREE.Object3D.call( this );
  17348. this.type = 'Audio';
  17349. this.context = listener.context;
  17350. this.source = this.context.createBufferSource();
  17351. this.source.onended = this.onEnded.bind( this );
  17352. this.gain = this.context.createGain();
  17353. this.gain.connect( this.context.destination );
  17354. this.panner = this.context.createPanner();
  17355. this.panner.connect( this.gain );
  17356. this.autoplay = false;
  17357. this.startTime = 0;
  17358. this.playbackRate = 1;
  17359. this.isPlaying = false;
  17360. };
  17361. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  17362. THREE.Audio.prototype.constructor = THREE.Audio;
  17363. THREE.Audio.prototype.load = function ( file ) {
  17364. var scope = this;
  17365. var request = new XMLHttpRequest();
  17366. request.open( 'GET', file, true );
  17367. request.responseType = 'arraybuffer';
  17368. request.onload = function ( e ) {
  17369. scope.context.decodeAudioData( this.response, function ( buffer ) {
  17370. scope.source.buffer = buffer;
  17371. if ( scope.autoplay ) scope.play();
  17372. } );
  17373. };
  17374. request.send();
  17375. return this;
  17376. };
  17377. THREE.Audio.prototype.play = function () {
  17378. if ( this.isPlaying === true ) {
  17379. console.warn( 'THREE.Audio: Audio is already playing.' );
  17380. return;
  17381. }
  17382. var source = this.context.createBufferSource();
  17383. source.buffer = this.source.buffer;
  17384. source.loop = this.source.loop;
  17385. source.onended = this.source.onended;
  17386. source.start( 0, this.startTime );
  17387. source.playbackRate.value = this.playbackRate;
  17388. this.isPlaying = true;
  17389. this.source = source;
  17390. this.connect();
  17391. };
  17392. THREE.Audio.prototype.pause = function () {
  17393. this.source.stop();
  17394. this.startTime = this.context.currentTime;
  17395. };
  17396. THREE.Audio.prototype.stop = function () {
  17397. this.source.stop();
  17398. this.startTime = 0;
  17399. };
  17400. THREE.Audio.prototype.connect = function () {
  17401. if ( this.filter !== undefined ) {
  17402. this.source.connect( this.filter );
  17403. this.filter.connect( this.panner );
  17404. } else {
  17405. this.source.connect( this.panner );
  17406. }
  17407. };
  17408. THREE.Audio.prototype.disconnect = function () {
  17409. if ( this.filter !== undefined ) {
  17410. this.source.disconnect( this.filter );
  17411. this.filter.disconnect( this.panner );
  17412. } else {
  17413. this.source.disconnect( this.panner );
  17414. }
  17415. };
  17416. THREE.Audio.prototype.setFilter = function ( value ) {
  17417. if ( this.isPlaying === true ) {
  17418. this.disconnect();
  17419. this.filter = value;
  17420. this.connect();
  17421. } else {
  17422. this.filter = value;
  17423. }
  17424. };
  17425. THREE.Audio.prototype.getFilter = function () {
  17426. return this.filter;
  17427. };
  17428. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  17429. this.playbackRate = value;
  17430. if ( this.isPlaying === true ) {
  17431. this.source.playbackRate.value = this.playbackRate;
  17432. }
  17433. };
  17434. THREE.Audio.prototype.getPlaybackRate = function () {
  17435. return this.playbackRate;
  17436. };
  17437. THREE.Audio.prototype.onEnded = function() {
  17438. this.isPlaying = false;
  17439. };
  17440. THREE.Audio.prototype.setLoop = function ( value ) {
  17441. this.source.loop = value;
  17442. };
  17443. THREE.Audio.prototype.getLoop = function () {
  17444. return this.source.loop;
  17445. };
  17446. THREE.Audio.prototype.setRefDistance = function ( value ) {
  17447. this.panner.refDistance = value;
  17448. };
  17449. THREE.Audio.prototype.getRefDistance = function () {
  17450. return this.panner.refDistance;
  17451. };
  17452. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  17453. this.panner.rolloffFactor = value;
  17454. };
  17455. THREE.Audio.prototype.getRolloffFactor = function () {
  17456. return this.panner.rolloffFactor;
  17457. };
  17458. THREE.Audio.prototype.setVolume = function ( value ) {
  17459. this.gain.gain.value = value;
  17460. };
  17461. THREE.Audio.prototype.getVolume = function () {
  17462. return this.gain.gain.value;
  17463. };
  17464. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  17465. var position = new THREE.Vector3();
  17466. return function updateMatrixWorld( force ) {
  17467. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17468. position.setFromMatrixPosition( this.matrixWorld );
  17469. this.panner.setPosition( position.x, position.y, position.z );
  17470. };
  17471. } )();
  17472. // File:src/extras/audio/AudioListener.js
  17473. /**
  17474. * @author mrdoob / http://mrdoob.com/
  17475. */
  17476. THREE.AudioListener = function () {
  17477. THREE.Object3D.call( this );
  17478. this.type = 'AudioListener';
  17479. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  17480. };
  17481. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  17482. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  17483. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  17484. var position = new THREE.Vector3();
  17485. var quaternion = new THREE.Quaternion();
  17486. var scale = new THREE.Vector3();
  17487. var orientation = new THREE.Vector3();
  17488. return function updateMatrixWorld( force ) {
  17489. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17490. var listener = this.context.listener;
  17491. var up = this.up;
  17492. this.matrixWorld.decompose( position, quaternion, scale );
  17493. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  17494. listener.setPosition( position.x, position.y, position.z );
  17495. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  17496. };
  17497. } )();
  17498. // File:src/extras/core/Curve.js
  17499. /**
  17500. * @author zz85 / http://www.lab4games.net/zz85/blog
  17501. * Extensible curve object
  17502. *
  17503. * Some common of Curve methods
  17504. * .getPoint(t), getTangent(t)
  17505. * .getPointAt(u), getTagentAt(u)
  17506. * .getPoints(), .getSpacedPoints()
  17507. * .getLength()
  17508. * .updateArcLengths()
  17509. *
  17510. * This following classes subclasses THREE.Curve:
  17511. *
  17512. * -- 2d classes --
  17513. * THREE.LineCurve
  17514. * THREE.QuadraticBezierCurve
  17515. * THREE.CubicBezierCurve
  17516. * THREE.SplineCurve
  17517. * THREE.ArcCurve
  17518. * THREE.EllipseCurve
  17519. *
  17520. * -- 3d classes --
  17521. * THREE.LineCurve3
  17522. * THREE.QuadraticBezierCurve3
  17523. * THREE.CubicBezierCurve3
  17524. * THREE.SplineCurve3
  17525. * THREE.ClosedSplineCurve3
  17526. *
  17527. * A series of curves can be represented as a THREE.CurvePath
  17528. *
  17529. **/
  17530. /**************************************************************
  17531. * Abstract Curve base class
  17532. **************************************************************/
  17533. THREE.Curve = function () {
  17534. };
  17535. THREE.Curve.prototype = {
  17536. constructor: THREE.Curve,
  17537. // Virtual base class method to overwrite and implement in subclasses
  17538. // - t [0 .. 1]
  17539. getPoint: function ( t ) {
  17540. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  17541. return null;
  17542. },
  17543. // Get point at relative position in curve according to arc length
  17544. // - u [0 .. 1]
  17545. getPointAt: function ( u ) {
  17546. var t = this.getUtoTmapping( u );
  17547. return this.getPoint( t );
  17548. },
  17549. // Get sequence of points using getPoint( t )
  17550. getPoints: function ( divisions ) {
  17551. if ( ! divisions ) divisions = 5;
  17552. var d, pts = [];
  17553. for ( d = 0; d <= divisions; d ++ ) {
  17554. pts.push( this.getPoint( d / divisions ) );
  17555. }
  17556. return pts;
  17557. },
  17558. // Get sequence of points using getPointAt( u )
  17559. getSpacedPoints: function ( divisions ) {
  17560. if ( ! divisions ) divisions = 5;
  17561. var d, pts = [];
  17562. for ( d = 0; d <= divisions; d ++ ) {
  17563. pts.push( this.getPointAt( d / divisions ) );
  17564. }
  17565. return pts;
  17566. },
  17567. // Get total curve arc length
  17568. getLength: function () {
  17569. var lengths = this.getLengths();
  17570. return lengths[ lengths.length - 1 ];
  17571. },
  17572. // Get list of cumulative segment lengths
  17573. getLengths: function ( divisions ) {
  17574. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  17575. if ( this.cacheArcLengths
  17576. && ( this.cacheArcLengths.length === divisions + 1 )
  17577. && ! this.needsUpdate ) {
  17578. //console.log( "cached", this.cacheArcLengths );
  17579. return this.cacheArcLengths;
  17580. }
  17581. this.needsUpdate = false;
  17582. var cache = [];
  17583. var current, last = this.getPoint( 0 );
  17584. var p, sum = 0;
  17585. cache.push( 0 );
  17586. for ( p = 1; p <= divisions; p ++ ) {
  17587. current = this.getPoint ( p / divisions );
  17588. sum += current.distanceTo( last );
  17589. cache.push( sum );
  17590. last = current;
  17591. }
  17592. this.cacheArcLengths = cache;
  17593. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  17594. },
  17595. updateArcLengths: function() {
  17596. this.needsUpdate = true;
  17597. this.getLengths();
  17598. },
  17599. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  17600. getUtoTmapping: function ( u, distance ) {
  17601. var arcLengths = this.getLengths();
  17602. var i = 0, il = arcLengths.length;
  17603. var targetArcLength; // The targeted u distance value to get
  17604. if ( distance ) {
  17605. targetArcLength = distance;
  17606. } else {
  17607. targetArcLength = u * arcLengths[ il - 1 ];
  17608. }
  17609. //var time = Date.now();
  17610. // binary search for the index with largest value smaller than target u distance
  17611. var low = 0, high = il - 1, comparison;
  17612. while ( low <= high ) {
  17613. 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
  17614. comparison = arcLengths[ i ] - targetArcLength;
  17615. if ( comparison < 0 ) {
  17616. low = i + 1;
  17617. } else if ( comparison > 0 ) {
  17618. high = i - 1;
  17619. } else {
  17620. high = i;
  17621. break;
  17622. // DONE
  17623. }
  17624. }
  17625. i = high;
  17626. //console.log('b' , i, low, high, Date.now()- time);
  17627. if ( arcLengths[ i ] === targetArcLength ) {
  17628. var t = i / ( il - 1 );
  17629. return t;
  17630. }
  17631. // we could get finer grain at lengths, or use simple interpolation between two points
  17632. var lengthBefore = arcLengths[ i ];
  17633. var lengthAfter = arcLengths[ i + 1 ];
  17634. var segmentLength = lengthAfter - lengthBefore;
  17635. // determine where we are between the 'before' and 'after' points
  17636. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  17637. // add that fractional amount to t
  17638. var t = ( i + segmentFraction ) / ( il - 1 );
  17639. return t;
  17640. },
  17641. // Returns a unit vector tangent at t
  17642. // In case any sub curve does not implement its tangent derivation,
  17643. // 2 points a small delta apart will be used to find its gradient
  17644. // which seems to give a reasonable approximation
  17645. getTangent: function( t ) {
  17646. var delta = 0.0001;
  17647. var t1 = t - delta;
  17648. var t2 = t + delta;
  17649. // Capping in case of danger
  17650. if ( t1 < 0 ) t1 = 0;
  17651. if ( t2 > 1 ) t2 = 1;
  17652. var pt1 = this.getPoint( t1 );
  17653. var pt2 = this.getPoint( t2 );
  17654. var vec = pt2.clone().sub( pt1 );
  17655. return vec.normalize();
  17656. },
  17657. getTangentAt: function ( u ) {
  17658. var t = this.getUtoTmapping( u );
  17659. return this.getTangent( t );
  17660. }
  17661. }
  17662. THREE.Curve.Utils = THREE.CurveUtils; // backwards compatibility
  17663. // TODO: Transformation for Curves?
  17664. /**************************************************************
  17665. * 3D Curves
  17666. **************************************************************/
  17667. // A Factory method for creating new curve subclasses
  17668. THREE.Curve.create = function ( constructor, getPointFunc ) {
  17669. constructor.prototype = Object.create( THREE.Curve.prototype );
  17670. constructor.prototype.constructor = constructor;
  17671. constructor.prototype.getPoint = getPointFunc;
  17672. return constructor;
  17673. };
  17674. // File:src/extras/core/CurvePath.js
  17675. /**
  17676. * @author zz85 / http://www.lab4games.net/zz85/blog
  17677. *
  17678. **/
  17679. /**************************************************************
  17680. * Curved Path - a curve path is simply a array of connected
  17681. * curves, but retains the api of a curve
  17682. **************************************************************/
  17683. THREE.CurvePath = function () {
  17684. this.curves = [];
  17685. this.autoClose = false; // Automatically closes the path
  17686. };
  17687. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  17688. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  17689. THREE.CurvePath.prototype.add = function ( curve ) {
  17690. this.curves.push( curve );
  17691. };
  17692. /*
  17693. THREE.CurvePath.prototype.checkConnection = function() {
  17694. // TODO
  17695. // If the ending of curve is not connected to the starting
  17696. // or the next curve, then, this is not a real path
  17697. };
  17698. */
  17699. THREE.CurvePath.prototype.closePath = function() {
  17700. // TODO Test
  17701. // and verify for vector3 (needs to implement equals)
  17702. // Add a line curve if start and end of lines are not connected
  17703. var startPoint = this.curves[ 0 ].getPoint( 0 );
  17704. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  17705. if ( ! startPoint.equals( endPoint ) ) {
  17706. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  17707. }
  17708. };
  17709. // To get accurate point with reference to
  17710. // entire path distance at time t,
  17711. // following has to be done:
  17712. // 1. Length of each sub path have to be known
  17713. // 2. Locate and identify type of curve
  17714. // 3. Get t for the curve
  17715. // 4. Return curve.getPointAt(t')
  17716. THREE.CurvePath.prototype.getPoint = function( t ) {
  17717. var d = t * this.getLength();
  17718. var curveLengths = this.getCurveLengths();
  17719. var i = 0;
  17720. // To think about boundaries points.
  17721. while ( i < curveLengths.length ) {
  17722. if ( curveLengths[ i ] >= d ) {
  17723. var diff = curveLengths[ i ] - d;
  17724. var curve = this.curves[ i ];
  17725. var u = 1 - diff / curve.getLength();
  17726. return curve.getPointAt( u );
  17727. }
  17728. i ++;
  17729. }
  17730. return null;
  17731. // loop where sum != 0, sum > d , sum+1 <d
  17732. };
  17733. /*
  17734. THREE.CurvePath.prototype.getTangent = function( t ) {
  17735. };
  17736. */
  17737. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  17738. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  17739. // getPoint() depends on getLength
  17740. THREE.CurvePath.prototype.getLength = function() {
  17741. var lens = this.getCurveLengths();
  17742. return lens[ lens.length - 1 ];
  17743. };
  17744. // Compute lengths and cache them
  17745. // We cannot overwrite getLengths() because UtoT mapping uses it.
  17746. THREE.CurvePath.prototype.getCurveLengths = function() {
  17747. // We use cache values if curves and cache array are same length
  17748. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  17749. return this.cacheLengths;
  17750. }
  17751. // Get length of sub-curve
  17752. // Push sums into cached array
  17753. var lengths = [], sums = 0;
  17754. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  17755. sums += this.curves[ i ].getLength();
  17756. lengths.push( sums );
  17757. }
  17758. this.cacheLengths = lengths;
  17759. return lengths;
  17760. };
  17761. /**************************************************************
  17762. * Create Geometries Helpers
  17763. **************************************************************/
  17764. /// Generate geometry from path points (for Line or Points objects)
  17765. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  17766. var pts = this.getPoints( divisions, true );
  17767. return this.createGeometry( pts );
  17768. };
  17769. // Generate geometry from equidistant sampling along the path
  17770. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  17771. var pts = this.getSpacedPoints( divisions, true );
  17772. return this.createGeometry( pts );
  17773. };
  17774. THREE.CurvePath.prototype.createGeometry = function( points ) {
  17775. var geometry = new THREE.Geometry();
  17776. for ( var i = 0, l = points.length; i < l; i ++ ) {
  17777. var point = points[ i ];
  17778. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  17779. }
  17780. return geometry;
  17781. };
  17782. // File:src/extras/core/Path.js
  17783. /**
  17784. * @author zz85 / http://www.lab4games.net/zz85/blog
  17785. * Creates free form 2d path using series of points, lines or curves.
  17786. *
  17787. **/
  17788. THREE.Path = function ( points ) {
  17789. THREE.CurvePath.call( this );
  17790. this.actions = [];
  17791. if ( points ) {
  17792. this.fromPoints( points );
  17793. }
  17794. };
  17795. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  17796. THREE.Path.prototype.constructor = THREE.Path;
  17797. // TODO Clean up PATH API
  17798. // Create path using straight lines to connect all points
  17799. // - vectors: array of Vector2
  17800. THREE.Path.prototype.fromPoints = function ( vectors ) {
  17801. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  17802. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  17803. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  17804. }
  17805. };
  17806. // startPath() endPath()?
  17807. THREE.Path.prototype.moveTo = function ( x, y ) {
  17808. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  17809. };
  17810. THREE.Path.prototype.lineTo = function ( x, y ) {
  17811. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17812. var x0 = lastargs[ lastargs.length - 2 ];
  17813. var y0 = lastargs[ lastargs.length - 1 ];
  17814. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  17815. this.curves.push( curve );
  17816. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  17817. };
  17818. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  17819. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17820. var x0 = lastargs[ lastargs.length - 2 ];
  17821. var y0 = lastargs[ lastargs.length - 1 ];
  17822. var curve = new THREE.QuadraticBezierCurve(
  17823. new THREE.Vector2( x0, y0 ),
  17824. new THREE.Vector2( aCPx, aCPy ),
  17825. new THREE.Vector2( aX, aY )
  17826. );
  17827. this.curves.push( curve );
  17828. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  17829. };
  17830. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  17831. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17832. var x0 = lastargs[ lastargs.length - 2 ];
  17833. var y0 = lastargs[ lastargs.length - 1 ];
  17834. var curve = new THREE.CubicBezierCurve(
  17835. new THREE.Vector2( x0, y0 ),
  17836. new THREE.Vector2( aCP1x, aCP1y ),
  17837. new THREE.Vector2( aCP2x, aCP2y ),
  17838. new THREE.Vector2( aX, aY )
  17839. );
  17840. this.curves.push( curve );
  17841. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  17842. };
  17843. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  17844. var args = Array.prototype.slice.call( arguments );
  17845. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17846. var x0 = lastargs[ lastargs.length - 2 ];
  17847. var y0 = lastargs[ lastargs.length - 1 ];
  17848. var npts = [ new THREE.Vector2( x0, y0 ) ];
  17849. Array.prototype.push.apply( npts, pts );
  17850. var curve = new THREE.SplineCurve( npts );
  17851. this.curves.push( curve );
  17852. this.actions.push( { action: 'splineThru', args: args } );
  17853. };
  17854. // FUTURE: Change the API or follow canvas API?
  17855. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17856. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17857. var x0 = lastargs[ lastargs.length - 2 ];
  17858. var y0 = lastargs[ lastargs.length - 1 ];
  17859. this.absarc( aX + x0, aY + y0, aRadius,
  17860. aStartAngle, aEndAngle, aClockwise );
  17861. };
  17862. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17863. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17864. };
  17865. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17866. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17867. var x0 = lastargs[ lastargs.length - 2 ];
  17868. var y0 = lastargs[ lastargs.length - 1 ];
  17869. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  17870. };
  17871. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17872. var args = [
  17873. aX, aY,
  17874. xRadius, yRadius,
  17875. aStartAngle, aEndAngle,
  17876. aClockwise,
  17877. aRotation || 0 // aRotation is optional.
  17878. ];
  17879. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  17880. this.curves.push( curve );
  17881. var lastPoint = curve.getPoint( 1 );
  17882. args.push( lastPoint.x );
  17883. args.push( lastPoint.y );
  17884. this.actions.push( { action: 'ellipse', args: args } );
  17885. };
  17886. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  17887. if ( ! divisions ) divisions = 40;
  17888. var points = [];
  17889. for ( var i = 0; i < divisions; i ++ ) {
  17890. points.push( this.getPoint( i / divisions ) );
  17891. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  17892. }
  17893. // if ( closedPath ) {
  17894. //
  17895. // points.push( points[ 0 ] );
  17896. //
  17897. // }
  17898. return points;
  17899. };
  17900. /* Return an array of vectors based on contour of the path */
  17901. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  17902. divisions = divisions || 12;
  17903. var b2 = THREE.ShapeUtils.b2;
  17904. var b3 = THREE.ShapeUtils.b3;
  17905. var points = [];
  17906. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  17907. laste, tx, ty;
  17908. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  17909. var item = this.actions[ i ];
  17910. var action = item.action;
  17911. var args = item.args;
  17912. switch ( action ) {
  17913. case 'moveTo':
  17914. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17915. break;
  17916. case 'lineTo':
  17917. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17918. break;
  17919. case 'quadraticCurveTo':
  17920. cpx = args[ 2 ];
  17921. cpy = args[ 3 ];
  17922. cpx1 = args[ 0 ];
  17923. cpy1 = args[ 1 ];
  17924. if ( points.length > 0 ) {
  17925. laste = points[ points.length - 1 ];
  17926. cpx0 = laste.x;
  17927. cpy0 = laste.y;
  17928. } else {
  17929. laste = this.actions[ i - 1 ].args;
  17930. cpx0 = laste[ laste.length - 2 ];
  17931. cpy0 = laste[ laste.length - 1 ];
  17932. }
  17933. for ( var j = 1; j <= divisions; j ++ ) {
  17934. var t = j / divisions;
  17935. tx = b2( t, cpx0, cpx1, cpx );
  17936. ty = b2( t, cpy0, cpy1, cpy );
  17937. points.push( new THREE.Vector2( tx, ty ) );
  17938. }
  17939. break;
  17940. case 'bezierCurveTo':
  17941. cpx = args[ 4 ];
  17942. cpy = args[ 5 ];
  17943. cpx1 = args[ 0 ];
  17944. cpy1 = args[ 1 ];
  17945. cpx2 = args[ 2 ];
  17946. cpy2 = args[ 3 ];
  17947. if ( points.length > 0 ) {
  17948. laste = points[ points.length - 1 ];
  17949. cpx0 = laste.x;
  17950. cpy0 = laste.y;
  17951. } else {
  17952. laste = this.actions[ i - 1 ].args;
  17953. cpx0 = laste[ laste.length - 2 ];
  17954. cpy0 = laste[ laste.length - 1 ];
  17955. }
  17956. for ( var j = 1; j <= divisions; j ++ ) {
  17957. var t = j / divisions;
  17958. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  17959. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  17960. points.push( new THREE.Vector2( tx, ty ) );
  17961. }
  17962. break;
  17963. case 'splineThru':
  17964. laste = this.actions[ i - 1 ].args;
  17965. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  17966. var spts = [ last ];
  17967. var n = divisions * args[ 0 ].length;
  17968. spts = spts.concat( args[ 0 ] );
  17969. var spline = new THREE.SplineCurve( spts );
  17970. for ( var j = 1; j <= n; j ++ ) {
  17971. points.push( spline.getPointAt( j / n ) );
  17972. }
  17973. break;
  17974. case 'arc':
  17975. var aX = args[ 0 ], aY = args[ 1 ],
  17976. aRadius = args[ 2 ],
  17977. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  17978. aClockwise = !! args[ 5 ];
  17979. var deltaAngle = aEndAngle - aStartAngle;
  17980. var angle;
  17981. var tdivisions = divisions * 2;
  17982. for ( var j = 1; j <= tdivisions; j ++ ) {
  17983. var t = j / tdivisions;
  17984. if ( ! aClockwise ) {
  17985. t = 1 - t;
  17986. }
  17987. angle = aStartAngle + t * deltaAngle;
  17988. tx = aX + aRadius * Math.cos( angle );
  17989. ty = aY + aRadius * Math.sin( angle );
  17990. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  17991. points.push( new THREE.Vector2( tx, ty ) );
  17992. }
  17993. //console.log(points);
  17994. break;
  17995. case 'ellipse':
  17996. var aX = args[ 0 ], aY = args[ 1 ],
  17997. xRadius = args[ 2 ],
  17998. yRadius = args[ 3 ],
  17999. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  18000. aClockwise = !! args[ 6 ],
  18001. aRotation = args[ 7 ];
  18002. var deltaAngle = aEndAngle - aStartAngle;
  18003. var angle;
  18004. var tdivisions = divisions * 2;
  18005. var cos, sin;
  18006. if ( aRotation !== 0 ) {
  18007. cos = Math.cos( aRotation );
  18008. sin = Math.sin( aRotation );
  18009. }
  18010. for ( var j = 1; j <= tdivisions; j ++ ) {
  18011. var t = j / tdivisions;
  18012. if ( ! aClockwise ) {
  18013. t = 1 - t;
  18014. }
  18015. angle = aStartAngle + t * deltaAngle;
  18016. tx = aX + xRadius * Math.cos( angle );
  18017. ty = aY + yRadius * Math.sin( angle );
  18018. if ( aRotation !== 0 ) {
  18019. var x = tx, y = ty;
  18020. // Rotate the point about the center of the ellipse.
  18021. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  18022. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  18023. }
  18024. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  18025. points.push( new THREE.Vector2( tx, ty ) );
  18026. }
  18027. //console.log(points);
  18028. break;
  18029. } // end switch
  18030. }
  18031. // Normalize to remove the closing point by default.
  18032. var lastPoint = points[ points.length - 1 ];
  18033. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  18034. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  18035. points.splice( points.length - 1, 1 );
  18036. if ( closedPath ) {
  18037. points.push( points[ 0 ] );
  18038. }
  18039. return points;
  18040. };
  18041. //
  18042. // Breaks path into shapes
  18043. //
  18044. // Assumptions (if parameter isCCW==true the opposite holds):
  18045. // - solid shapes are defined clockwise (CW)
  18046. // - holes are defined counterclockwise (CCW)
  18047. //
  18048. // If parameter noHoles==true:
  18049. // - all subPaths are regarded as solid shapes
  18050. // - definition order CW/CCW has no relevance
  18051. //
  18052. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  18053. function extractSubpaths( inActions ) {
  18054. var subPaths = [], lastPath = new THREE.Path();
  18055. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  18056. var item = inActions[ i ];
  18057. var args = item.args;
  18058. var action = item.action;
  18059. if ( action === 'moveTo' ) {
  18060. if ( lastPath.actions.length !== 0 ) {
  18061. subPaths.push( lastPath );
  18062. lastPath = new THREE.Path();
  18063. }
  18064. }
  18065. lastPath[ action ].apply( lastPath, args );
  18066. }
  18067. if ( lastPath.actions.length !== 0 ) {
  18068. subPaths.push( lastPath );
  18069. }
  18070. // console.log(subPaths);
  18071. return subPaths;
  18072. }
  18073. function toShapesNoHoles( inSubpaths ) {
  18074. var shapes = [];
  18075. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  18076. var tmpPath = inSubpaths[ i ];
  18077. var tmpShape = new THREE.Shape();
  18078. tmpShape.actions = tmpPath.actions;
  18079. tmpShape.curves = tmpPath.curves;
  18080. shapes.push( tmpShape );
  18081. }
  18082. //console.log("shape", shapes);
  18083. return shapes;
  18084. }
  18085. function isPointInsidePolygon( inPt, inPolygon ) {
  18086. var polyLen = inPolygon.length;
  18087. // inPt on polygon contour => immediate success or
  18088. // toggling of inside/outside at every single! intersection point of an edge
  18089. // with the horizontal line through inPt, left of inPt
  18090. // not counting lowerY endpoints of edges and whole edges on that line
  18091. var inside = false;
  18092. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  18093. var edgeLowPt = inPolygon[ p ];
  18094. var edgeHighPt = inPolygon[ q ];
  18095. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  18096. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  18097. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  18098. // not parallel
  18099. if ( edgeDy < 0 ) {
  18100. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  18101. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  18102. }
  18103. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  18104. if ( inPt.y === edgeLowPt.y ) {
  18105. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  18106. // continue; // no intersection or edgeLowPt => doesn't count !!!
  18107. } else {
  18108. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  18109. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  18110. if ( perpEdge < 0 ) continue;
  18111. inside = ! inside; // true intersection left of inPt
  18112. }
  18113. } else {
  18114. // parallel or collinear
  18115. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  18116. // edge lies on the same horizontal line as inPt
  18117. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  18118. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  18119. // continue;
  18120. }
  18121. }
  18122. return inside;
  18123. }
  18124. var isClockWise = THREE.ShapeUtils.isClockWise;
  18125. var subPaths = extractSubpaths( this.actions );
  18126. if ( subPaths.length === 0 ) return [];
  18127. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  18128. var solid, tmpPath, tmpShape, shapes = [];
  18129. if ( subPaths.length === 1 ) {
  18130. tmpPath = subPaths[ 0 ];
  18131. tmpShape = new THREE.Shape();
  18132. tmpShape.actions = tmpPath.actions;
  18133. tmpShape.curves = tmpPath.curves;
  18134. shapes.push( tmpShape );
  18135. return shapes;
  18136. }
  18137. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  18138. holesFirst = isCCW ? ! holesFirst : holesFirst;
  18139. // console.log("Holes first", holesFirst);
  18140. var betterShapeHoles = [];
  18141. var newShapes = [];
  18142. var newShapeHoles = [];
  18143. var mainIdx = 0;
  18144. var tmpPoints;
  18145. newShapes[ mainIdx ] = undefined;
  18146. newShapeHoles[ mainIdx ] = [];
  18147. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  18148. tmpPath = subPaths[ i ];
  18149. tmpPoints = tmpPath.getPoints();
  18150. solid = isClockWise( tmpPoints );
  18151. solid = isCCW ? ! solid : solid;
  18152. if ( solid ) {
  18153. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  18154. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  18155. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  18156. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  18157. if ( holesFirst ) mainIdx ++;
  18158. newShapeHoles[ mainIdx ] = [];
  18159. //console.log('cw', i);
  18160. } else {
  18161. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  18162. //console.log('ccw', i);
  18163. }
  18164. }
  18165. // only Holes? -> probably all Shapes with wrong orientation
  18166. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  18167. if ( newShapes.length > 1 ) {
  18168. var ambiguous = false;
  18169. var toChange = [];
  18170. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18171. betterShapeHoles[ sIdx ] = [];
  18172. }
  18173. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18174. var sho = newShapeHoles[ sIdx ];
  18175. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  18176. var ho = sho[ hIdx ];
  18177. var hole_unassigned = true;
  18178. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  18179. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  18180. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  18181. if ( hole_unassigned ) {
  18182. hole_unassigned = false;
  18183. betterShapeHoles[ s2Idx ].push( ho );
  18184. } else {
  18185. ambiguous = true;
  18186. }
  18187. }
  18188. }
  18189. if ( hole_unassigned ) {
  18190. betterShapeHoles[ sIdx ].push( ho );
  18191. }
  18192. }
  18193. }
  18194. // console.log("ambiguous: ", ambiguous);
  18195. if ( toChange.length > 0 ) {
  18196. // console.log("to change: ", toChange);
  18197. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  18198. }
  18199. }
  18200. var tmpHoles;
  18201. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  18202. tmpShape = newShapes[ i ].s;
  18203. shapes.push( tmpShape );
  18204. tmpHoles = newShapeHoles[ i ];
  18205. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  18206. tmpShape.holes.push( tmpHoles[ j ].h );
  18207. }
  18208. }
  18209. //console.log("shape", shapes);
  18210. return shapes;
  18211. };
  18212. // File:src/extras/core/Shape.js
  18213. /**
  18214. * @author zz85 / http://www.lab4games.net/zz85/blog
  18215. * Defines a 2d shape plane using paths.
  18216. **/
  18217. // STEP 1 Create a path.
  18218. // STEP 2 Turn path into shape.
  18219. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  18220. // STEP 3a - Extract points from each shape, turn to vertices
  18221. // STEP 3b - Triangulate each shape, add faces.
  18222. THREE.Shape = function () {
  18223. THREE.Path.apply( this, arguments );
  18224. this.holes = [];
  18225. };
  18226. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  18227. THREE.Shape.prototype.constructor = THREE.Shape;
  18228. // Convenience method to return ExtrudeGeometry
  18229. THREE.Shape.prototype.extrude = function ( options ) {
  18230. return new THREE.ExtrudeGeometry( this, options );
  18231. };
  18232. // Convenience method to return ShapeGeometry
  18233. THREE.Shape.prototype.makeGeometry = function ( options ) {
  18234. return new THREE.ShapeGeometry( this, options );
  18235. };
  18236. // Get points of holes
  18237. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  18238. var holesPts = [];
  18239. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  18240. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  18241. }
  18242. return holesPts;
  18243. };
  18244. // Get points of shape and holes (keypoints based on segments parameter)
  18245. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  18246. return {
  18247. shape: this.getPoints( divisions ),
  18248. holes: this.getPointsHoles( divisions )
  18249. };
  18250. };
  18251. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  18252. return this.extractAllPoints( divisions );
  18253. };
  18254. THREE.Shape.Utils = THREE.ShapeUtils; // backwards compatibility
  18255. // File:src/extras/curves/LineCurve.js
  18256. /**************************************************************
  18257. * Line
  18258. **************************************************************/
  18259. THREE.LineCurve = function ( v1, v2 ) {
  18260. this.v1 = v1;
  18261. this.v2 = v2;
  18262. };
  18263. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  18264. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  18265. THREE.LineCurve.prototype.getPoint = function ( t ) {
  18266. var point = this.v2.clone().sub( this.v1 );
  18267. point.multiplyScalar( t ).add( this.v1 );
  18268. return point;
  18269. };
  18270. // Line curve is linear, so we can overwrite default getPointAt
  18271. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  18272. return this.getPoint( u );
  18273. };
  18274. THREE.LineCurve.prototype.getTangent = function( t ) {
  18275. var tangent = this.v2.clone().sub( this.v1 );
  18276. return tangent.normalize();
  18277. };
  18278. // File:src/extras/curves/QuadraticBezierCurve.js
  18279. /**************************************************************
  18280. * Quadratic Bezier curve
  18281. **************************************************************/
  18282. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  18283. this.v0 = v0;
  18284. this.v1 = v1;
  18285. this.v2 = v2;
  18286. };
  18287. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18288. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  18289. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  18290. var b2 = THREE.ShapeUtils.b2;
  18291. return new THREE.Vector2(
  18292. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  18293. b2( t, this.v0.y, this.v1.y, this.v2.y )
  18294. );
  18295. };
  18296. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  18297. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  18298. return new THREE.Vector2(
  18299. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  18300. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  18301. ).normalize();
  18302. };
  18303. // File:src/extras/curves/CubicBezierCurve.js
  18304. /**************************************************************
  18305. * Cubic Bezier curve
  18306. **************************************************************/
  18307. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  18308. this.v0 = v0;
  18309. this.v1 = v1;
  18310. this.v2 = v2;
  18311. this.v3 = v3;
  18312. };
  18313. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18314. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  18315. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  18316. var b3 = THREE.ShapeUtils.b3;
  18317. return new THREE.Vector2(
  18318. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  18319. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  18320. );
  18321. };
  18322. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  18323. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  18324. return new THREE.Vector2(
  18325. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  18326. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  18327. ).normalize();
  18328. };
  18329. // File:src/extras/curves/SplineCurve.js
  18330. /**************************************************************
  18331. * Spline curve
  18332. **************************************************************/
  18333. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  18334. this.points = ( points == undefined ) ? [] : points;
  18335. };
  18336. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  18337. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  18338. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  18339. var points = this.points;
  18340. var point = ( points.length - 1 ) * t;
  18341. var intPoint = Math.floor( point );
  18342. var weight = point - intPoint;
  18343. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  18344. var point1 = points[ intPoint ];
  18345. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18346. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18347. var interpolate = THREE.CurveUtils.interpolate;
  18348. return new THREE.Vector2(
  18349. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  18350. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  18351. );
  18352. };
  18353. // File:src/extras/curves/EllipseCurve.js
  18354. /**************************************************************
  18355. * Ellipse curve
  18356. **************************************************************/
  18357. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18358. this.aX = aX;
  18359. this.aY = aY;
  18360. this.xRadius = xRadius;
  18361. this.yRadius = yRadius;
  18362. this.aStartAngle = aStartAngle;
  18363. this.aEndAngle = aEndAngle;
  18364. this.aClockwise = aClockwise;
  18365. this.aRotation = aRotation || 0;
  18366. };
  18367. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  18368. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  18369. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  18370. var deltaAngle = this.aEndAngle - this.aStartAngle;
  18371. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  18372. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  18373. var angle;
  18374. if ( this.aClockwise === true ) {
  18375. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  18376. } else {
  18377. angle = this.aStartAngle + t * deltaAngle;
  18378. }
  18379. var x = this.aX + this.xRadius * Math.cos( angle );
  18380. var y = this.aY + this.yRadius * Math.sin( angle );
  18381. if ( this.aRotation !== 0 ) {
  18382. var cos = Math.cos( this.aRotation );
  18383. var sin = Math.sin( this.aRotation );
  18384. var tx = x, ty = y;
  18385. // Rotate the point about the center of the ellipse.
  18386. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  18387. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  18388. }
  18389. return new THREE.Vector2( x, y );
  18390. };
  18391. // File:src/extras/curves/ArcCurve.js
  18392. /**************************************************************
  18393. * Arc curve
  18394. **************************************************************/
  18395. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18396. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  18397. };
  18398. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  18399. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  18400. // File:src/extras/curves/LineCurve3.js
  18401. /**************************************************************
  18402. * Line3D
  18403. **************************************************************/
  18404. THREE.LineCurve3 = THREE.Curve.create(
  18405. function ( v1, v2 ) {
  18406. this.v1 = v1;
  18407. this.v2 = v2;
  18408. },
  18409. function ( t ) {
  18410. var vector = new THREE.Vector3();
  18411. vector.subVectors( this.v2, this.v1 ); // diff
  18412. vector.multiplyScalar( t );
  18413. vector.add( this.v1 );
  18414. return vector;
  18415. }
  18416. );
  18417. // File:src/extras/curves/QuadraticBezierCurve3.js
  18418. /**************************************************************
  18419. * Quadratic Bezier 3D curve
  18420. **************************************************************/
  18421. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  18422. function ( v0, v1, v2 ) {
  18423. this.v0 = v0;
  18424. this.v1 = v1;
  18425. this.v2 = v2;
  18426. },
  18427. function ( t ) {
  18428. var b2 = THREE.ShapeUtils.b2;
  18429. return new THREE.Vector3(
  18430. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  18431. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  18432. b2( t, this.v0.z, this.v1.z, this.v2.z )
  18433. );
  18434. }
  18435. );
  18436. // File:src/extras/curves/CubicBezierCurve3.js
  18437. /**************************************************************
  18438. * Cubic Bezier 3D curve
  18439. **************************************************************/
  18440. THREE.CubicBezierCurve3 = THREE.Curve.create(
  18441. function ( v0, v1, v2, v3 ) {
  18442. this.v0 = v0;
  18443. this.v1 = v1;
  18444. this.v2 = v2;
  18445. this.v3 = v3;
  18446. },
  18447. function ( t ) {
  18448. var b3 = THREE.ShapeUtils.b3;
  18449. return new THREE.Vector3(
  18450. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  18451. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  18452. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  18453. );
  18454. }
  18455. );
  18456. // File:src/extras/curves/SplineCurve3.js
  18457. /**************************************************************
  18458. * Spline 3D curve
  18459. **************************************************************/
  18460. THREE.SplineCurve3 = THREE.Curve.create(
  18461. function ( points /* array of Vector3 */ ) {
  18462. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  18463. this.points = ( points == undefined ) ? [] : points;
  18464. },
  18465. function ( t ) {
  18466. var points = this.points;
  18467. var point = ( points.length - 1 ) * t;
  18468. var intPoint = Math.floor( point );
  18469. var weight = point - intPoint;
  18470. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  18471. var point1 = points[ intPoint ];
  18472. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18473. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18474. var interpolate = THREE.CurveUtils.interpolate;
  18475. return new THREE.Vector3(
  18476. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  18477. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  18478. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  18479. );
  18480. }
  18481. );
  18482. // File:src/extras/curves/CatmullRomCurve3.js
  18483. /**
  18484. * @author zz85 https://github.com/zz85
  18485. *
  18486. * Centripetal CatmullRom Curve - which is useful for avoiding
  18487. * cusps and self-intersections in non-uniform catmull rom curves.
  18488. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18489. *
  18490. * curve.type accepts centripetal(default), chordal and catmullrom
  18491. * curve.tension is used for catmullrom which defaults to 0.5
  18492. */
  18493. THREE.CatmullRomCurve3 = ( function() {
  18494. var
  18495. tmp = new THREE.Vector3(),
  18496. px = new CubicPoly(),
  18497. py = new CubicPoly(),
  18498. pz = new CubicPoly();
  18499. /*
  18500. Based on an optimized c++ solution in
  18501. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  18502. - http://ideone.com/NoEbVM
  18503. This CubicPoly class could be used for reusing some variables and calculations,
  18504. but for three.js curve use, it could be possible inlined and flatten into a single function call
  18505. which can be placed in CurveUtils.
  18506. */
  18507. function CubicPoly() {
  18508. }
  18509. /*
  18510. * Compute coefficients for a cubic polynomial
  18511. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18512. * such that
  18513. * p(0) = x0, p(1) = x1
  18514. * and
  18515. * p'(0) = t0, p'(1) = t1.
  18516. */
  18517. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  18518. this.c0 = x0;
  18519. this.c1 = t0;
  18520. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18521. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18522. };
  18523. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18524. // compute tangents when parameterized in [t1,t2]
  18525. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18526. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18527. // rescale tangents for parametrization in [0,1]
  18528. t1 *= dt1;
  18529. t2 *= dt1;
  18530. // initCubicPoly
  18531. this.init( x1, x2, t1, t2 );
  18532. };
  18533. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  18534. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  18535. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18536. };
  18537. CubicPoly.prototype.calc = function( t ) {
  18538. var t2 = t * t;
  18539. var t3 = t2 * t;
  18540. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  18541. };
  18542. // Subclass Three.js curve
  18543. return THREE.Curve.create(
  18544. function ( p /* array of Vector3 */ ) {
  18545. this.points = p || [];
  18546. },
  18547. function ( t ) {
  18548. var points = this.points,
  18549. point, intPoint, weight, l;
  18550. l = points.length;
  18551. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  18552. point = ( l - 1 ) * t;
  18553. intPoint = Math.floor( point );
  18554. weight = point - intPoint;
  18555. if ( weight === 0 && intPoint === l - 1 ) {
  18556. intPoint = l - 2;
  18557. weight = 1;
  18558. }
  18559. var p0, p1, p2, p3;
  18560. if ( intPoint === 0 ) {
  18561. // extrapolate first point
  18562. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  18563. p0 = tmp;
  18564. } else {
  18565. p0 = points[ intPoint - 1 ];
  18566. }
  18567. p1 = points[ intPoint ];
  18568. p2 = points[ intPoint + 1 ];
  18569. if ( intPoint + 2 < l ) {
  18570. p3 = points[ intPoint + 2 ]
  18571. } else {
  18572. // extrapolate last point
  18573. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  18574. p3 = tmp;
  18575. }
  18576. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  18577. // init Centripetal / Chordal Catmull-Rom
  18578. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  18579. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  18580. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  18581. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  18582. // safety check for repeated points
  18583. if ( dt1 < 1e-4 ) dt1 = 1.0;
  18584. if ( dt0 < 1e-4 ) dt0 = dt1;
  18585. if ( dt2 < 1e-4 ) dt2 = dt1;
  18586. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  18587. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  18588. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  18589. } else if ( this.type === 'catmullrom' ) {
  18590. var tension = this.tension !== undefined ? this.tension : 0.5;
  18591. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  18592. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  18593. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  18594. }
  18595. var v = new THREE.Vector3(
  18596. px.calc( weight ),
  18597. py.calc( weight ),
  18598. pz.calc( weight )
  18599. );
  18600. return v;
  18601. }
  18602. );
  18603. } )();
  18604. // File:src/extras/curves/ClosedSplineCurve3.js
  18605. /**************************************************************
  18606. * Closed Spline 3D curve
  18607. **************************************************************/
  18608. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  18609. function ( points /* array of Vector3 */ ) {
  18610. this.points = ( points == undefined ) ? [] : points;
  18611. },
  18612. function ( t ) {
  18613. var points = this.points;
  18614. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  18615. var intPoint = Math.floor( point );
  18616. var weight = point - intPoint;
  18617. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  18618. var point0 = points[ ( intPoint - 1 ) % points.length ];
  18619. var point1 = points[ ( intPoint ) % points.length ];
  18620. var point2 = points[ ( intPoint + 1 ) % points.length ];
  18621. var point3 = points[ ( intPoint + 2 ) % points.length ];
  18622. var interpolate = THREE.CurveUtils.interpolate;
  18623. return new THREE.Vector3(
  18624. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  18625. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  18626. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  18627. );
  18628. }
  18629. );
  18630. // File:src/extras/geometries/BoxGeometry.js
  18631. /**
  18632. * @author mrdoob / http://mrdoob.com/
  18633. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  18634. */
  18635. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  18636. THREE.Geometry.call( this );
  18637. this.type = 'BoxGeometry';
  18638. this.parameters = {
  18639. width: width,
  18640. height: height,
  18641. depth: depth,
  18642. widthSegments: widthSegments,
  18643. heightSegments: heightSegments,
  18644. depthSegments: depthSegments
  18645. };
  18646. this.widthSegments = widthSegments || 1;
  18647. this.heightSegments = heightSegments || 1;
  18648. this.depthSegments = depthSegments || 1;
  18649. var scope = this;
  18650. var width_half = width / 2;
  18651. var height_half = height / 2;
  18652. var depth_half = depth / 2;
  18653. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  18654. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  18655. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  18656. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  18657. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  18658. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  18659. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  18660. var w, ix, iy,
  18661. gridX = scope.widthSegments,
  18662. gridY = scope.heightSegments,
  18663. width_half = width / 2,
  18664. height_half = height / 2,
  18665. offset = scope.vertices.length;
  18666. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  18667. w = 'z';
  18668. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  18669. w = 'y';
  18670. gridY = scope.depthSegments;
  18671. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  18672. w = 'x';
  18673. gridX = scope.depthSegments;
  18674. }
  18675. var gridX1 = gridX + 1,
  18676. gridY1 = gridY + 1,
  18677. segment_width = width / gridX,
  18678. segment_height = height / gridY,
  18679. normal = new THREE.Vector3();
  18680. normal[ w ] = depth > 0 ? 1 : - 1;
  18681. for ( iy = 0; iy < gridY1; iy ++ ) {
  18682. for ( ix = 0; ix < gridX1; ix ++ ) {
  18683. var vector = new THREE.Vector3();
  18684. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  18685. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  18686. vector[ w ] = depth;
  18687. scope.vertices.push( vector );
  18688. }
  18689. }
  18690. for ( iy = 0; iy < gridY; iy ++ ) {
  18691. for ( ix = 0; ix < gridX; ix ++ ) {
  18692. var a = ix + gridX1 * iy;
  18693. var b = ix + gridX1 * ( iy + 1 );
  18694. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  18695. var d = ( ix + 1 ) + gridX1 * iy;
  18696. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  18697. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  18698. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  18699. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  18700. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  18701. face.normal.copy( normal );
  18702. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18703. face.materialIndex = materialIndex;
  18704. scope.faces.push( face );
  18705. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  18706. face = new THREE.Face3( b + offset, c + offset, d + offset );
  18707. face.normal.copy( normal );
  18708. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18709. face.materialIndex = materialIndex;
  18710. scope.faces.push( face );
  18711. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  18712. }
  18713. }
  18714. }
  18715. this.mergeVertices();
  18716. };
  18717. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18718. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  18719. THREE.BoxGeometry.prototype.clone = function () {
  18720. var parameters = this.parameters;
  18721. return new THREE.BoxGeometry(
  18722. parameters.width,
  18723. parameters.height,
  18724. parameters.depth,
  18725. parameters.widthSegments,
  18726. parameters.heightSegments,
  18727. parameters.depthSegments
  18728. );
  18729. };
  18730. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  18731. // File:src/extras/geometries/CircleGeometry.js
  18732. /**
  18733. * @author hughes
  18734. */
  18735. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18736. THREE.Geometry.call( this );
  18737. this.type = 'CircleGeometry';
  18738. this.parameters = {
  18739. radius: radius,
  18740. segments: segments,
  18741. thetaStart: thetaStart,
  18742. thetaLength: thetaLength
  18743. };
  18744. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  18745. };
  18746. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18747. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  18748. THREE.CircleGeometry.prototype.clone = function () {
  18749. var parameters = this.parameters;
  18750. return new THREE.CircleGeometry(
  18751. parameters.radius,
  18752. parameters.segments,
  18753. parameters.thetaStart,
  18754. parameters.thetaLength
  18755. );
  18756. };
  18757. // File:src/extras/geometries/CircleBufferGeometry.js
  18758. /**
  18759. * @author benaadams / https://twitter.com/ben_a_adams
  18760. */
  18761. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18762. THREE.BufferGeometry.call( this );
  18763. this.type = 'CircleBufferGeometry';
  18764. this.parameters = {
  18765. radius: radius,
  18766. segments: segments,
  18767. thetaStart: thetaStart,
  18768. thetaLength: thetaLength
  18769. };
  18770. radius = radius || 50;
  18771. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18772. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18773. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18774. var vertices = segments + 2;
  18775. var positions = new Float32Array( vertices * 3 );
  18776. var normals = new Float32Array( vertices * 3 );
  18777. var uvs = new Float32Array( vertices * 2 );
  18778. // center data is already zero, but need to set a few extras
  18779. normals[ 2 ] = 1.0;
  18780. uvs[ 0 ] = 0.5;
  18781. uvs[ 1 ] = 0.5;
  18782. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  18783. var segment = thetaStart + s / segments * thetaLength;
  18784. positions[ i ] = radius * Math.cos( segment );
  18785. positions[ i + 1 ] = radius * Math.sin( segment );
  18786. normals[ i + 2 ] = 1; // normal z
  18787. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  18788. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  18789. }
  18790. var indices = [];
  18791. for ( var i = 1; i <= segments; i ++ ) {
  18792. indices.push( i, i + 1, 0 );
  18793. }
  18794. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  18795. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  18796. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  18797. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  18798. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18799. };
  18800. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18801. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  18802. THREE.CircleBufferGeometry.prototype.clone = function () {
  18803. var parameters = this.parameters;
  18804. return new THREE.CircleBufferGeometry(
  18805. parameters.radius,
  18806. parameters.segments,
  18807. parameters.thetaStart,
  18808. parameters.thetaLength
  18809. );
  18810. };
  18811. // File:src/extras/geometries/CylinderGeometry.js
  18812. /**
  18813. * @author mrdoob / http://mrdoob.com/
  18814. */
  18815. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18816. THREE.Geometry.call( this );
  18817. this.type = 'CylinderGeometry';
  18818. this.parameters = {
  18819. radiusTop: radiusTop,
  18820. radiusBottom: radiusBottom,
  18821. height: height,
  18822. radialSegments: radialSegments,
  18823. heightSegments: heightSegments,
  18824. openEnded: openEnded,
  18825. thetaStart: thetaStart,
  18826. thetaLength: thetaLength
  18827. };
  18828. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  18829. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  18830. height = height !== undefined ? height : 100;
  18831. radialSegments = radialSegments || 8;
  18832. heightSegments = heightSegments || 1;
  18833. openEnded = openEnded !== undefined ? openEnded : false;
  18834. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18835. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  18836. var heightHalf = height / 2;
  18837. var x, y, vertices = [], uvs = [];
  18838. for ( y = 0; y <= heightSegments; y ++ ) {
  18839. var verticesRow = [];
  18840. var uvsRow = [];
  18841. var v = y / heightSegments;
  18842. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18843. for ( x = 0; x <= radialSegments; x ++ ) {
  18844. var u = x / radialSegments;
  18845. var vertex = new THREE.Vector3();
  18846. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  18847. vertex.y = - v * height + heightHalf;
  18848. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  18849. this.vertices.push( vertex );
  18850. verticesRow.push( this.vertices.length - 1 );
  18851. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  18852. }
  18853. vertices.push( verticesRow );
  18854. uvs.push( uvsRow );
  18855. }
  18856. var tanTheta = ( radiusBottom - radiusTop ) / height;
  18857. var na, nb;
  18858. for ( x = 0; x < radialSegments; x ++ ) {
  18859. if ( radiusTop !== 0 ) {
  18860. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  18861. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  18862. } else {
  18863. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  18864. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  18865. }
  18866. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  18867. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  18868. for ( y = 0; y < heightSegments; y ++ ) {
  18869. var v1 = vertices[ y ][ x ];
  18870. var v2 = vertices[ y + 1 ][ x ];
  18871. var v3 = vertices[ y + 1 ][ x + 1 ];
  18872. var v4 = vertices[ y ][ x + 1 ];
  18873. var n1 = na.clone();
  18874. var n2 = na.clone();
  18875. var n3 = nb.clone();
  18876. var n4 = nb.clone();
  18877. var uv1 = uvs[ y ][ x ].clone();
  18878. var uv2 = uvs[ y + 1 ][ x ].clone();
  18879. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  18880. var uv4 = uvs[ y ][ x + 1 ].clone();
  18881. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  18882. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  18883. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  18884. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  18885. }
  18886. }
  18887. // top cap
  18888. if ( openEnded === false && radiusTop > 0 ) {
  18889. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  18890. for ( x = 0; x < radialSegments; x ++ ) {
  18891. var v1 = vertices[ 0 ][ x ];
  18892. var v2 = vertices[ 0 ][ x + 1 ];
  18893. var v3 = this.vertices.length - 1;
  18894. var n1 = new THREE.Vector3( 0, 1, 0 );
  18895. var n2 = new THREE.Vector3( 0, 1, 0 );
  18896. var n3 = new THREE.Vector3( 0, 1, 0 );
  18897. var uv1 = uvs[ 0 ][ x ].clone();
  18898. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  18899. var uv3 = new THREE.Vector2( uv2.x, 0 );
  18900. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  18901. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18902. }
  18903. }
  18904. // bottom cap
  18905. if ( openEnded === false && radiusBottom > 0 ) {
  18906. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  18907. for ( x = 0; x < radialSegments; x ++ ) {
  18908. var v1 = vertices[ heightSegments ][ x + 1 ];
  18909. var v2 = vertices[ heightSegments ][ x ];
  18910. var v3 = this.vertices.length - 1;
  18911. var n1 = new THREE.Vector3( 0, - 1, 0 );
  18912. var n2 = new THREE.Vector3( 0, - 1, 0 );
  18913. var n3 = new THREE.Vector3( 0, - 1, 0 );
  18914. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  18915. var uv2 = uvs[ heightSegments ][ x ].clone();
  18916. var uv3 = new THREE.Vector2( uv2.x, 1 );
  18917. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  18918. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18919. }
  18920. }
  18921. this.computeFaceNormals();
  18922. };
  18923. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18924. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  18925. THREE.CylinderGeometry.prototype.clone = function () {
  18926. var parameters = this.parameters;
  18927. return new THREE.CylinderGeometry(
  18928. parameters.radiusTop,
  18929. parameters.radiusBottom,
  18930. parameters.height,
  18931. parameters.radialSegments,
  18932. parameters.heightSegments,
  18933. parameters.openEnded,
  18934. parameters.thetaStart,
  18935. parameters.thetaLength
  18936. );
  18937. };
  18938. // File:src/extras/geometries/EdgesGeometry.js
  18939. /**
  18940. * @author WestLangley / http://github.com/WestLangley
  18941. */
  18942. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  18943. THREE.BufferGeometry.call( this );
  18944. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18945. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  18946. var edge = [ 0, 0 ], hash = {};
  18947. function sortFunction( a, b ) {
  18948. return a - b;
  18949. }
  18950. var keys = [ 'a', 'b', 'c' ];
  18951. var geometry2;
  18952. if ( geometry instanceof THREE.BufferGeometry ) {
  18953. geometry2 = new THREE.Geometry();
  18954. geometry2.fromBufferGeometry( geometry );
  18955. } else {
  18956. geometry2 = geometry.clone();
  18957. }
  18958. geometry2.mergeVertices();
  18959. geometry2.computeFaceNormals();
  18960. var vertices = geometry2.vertices;
  18961. var faces = geometry2.faces;
  18962. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18963. var face = faces[ i ];
  18964. for ( var j = 0; j < 3; j ++ ) {
  18965. edge[ 0 ] = face[ keys[ j ] ];
  18966. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  18967. edge.sort( sortFunction );
  18968. var key = edge.toString();
  18969. if ( hash[ key ] === undefined ) {
  18970. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  18971. } else {
  18972. hash[ key ].face2 = i;
  18973. }
  18974. }
  18975. }
  18976. var coords = [];
  18977. for ( var key in hash ) {
  18978. var h = hash[ key ];
  18979. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  18980. var vertex = vertices[ h.vert1 ];
  18981. coords.push( vertex.x );
  18982. coords.push( vertex.y );
  18983. coords.push( vertex.z );
  18984. vertex = vertices[ h.vert2 ];
  18985. coords.push( vertex.x );
  18986. coords.push( vertex.y );
  18987. coords.push( vertex.z );
  18988. }
  18989. }
  18990. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  18991. };
  18992. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18993. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  18994. // File:src/extras/geometries/ExtrudeGeometry.js
  18995. /**
  18996. * @author zz85 / http://www.lab4games.net/zz85/blog
  18997. *
  18998. * Creates extruded geometry from a path shape.
  18999. *
  19000. * parameters = {
  19001. *
  19002. * curveSegments: <int>, // number of points on the curves
  19003. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  19004. * amount: <int>, // Depth to extrude the shape
  19005. *
  19006. * bevelEnabled: <bool>, // turn on bevel
  19007. * bevelThickness: <float>, // how deep into the original shape bevel goes
  19008. * bevelSize: <float>, // how far from shape outline is bevel
  19009. * bevelSegments: <int>, // number of bevel layers
  19010. *
  19011. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  19012. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  19013. *
  19014. * uvGenerator: <Object> // object that provides UV generator functions
  19015. *
  19016. * }
  19017. **/
  19018. THREE.ExtrudeGeometry = function ( shapes, options ) {
  19019. if ( typeof( shapes ) === "undefined" ) {
  19020. shapes = [];
  19021. return;
  19022. }
  19023. THREE.Geometry.call( this );
  19024. this.type = 'ExtrudeGeometry';
  19025. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  19026. this.addShapeList( shapes, options );
  19027. this.computeFaceNormals();
  19028. // can't really use automatic vertex normals
  19029. // as then front and back sides get smoothed too
  19030. // should do separate smoothing just for sides
  19031. //this.computeVertexNormals();
  19032. //console.log( "took", ( Date.now() - startTime ) );
  19033. };
  19034. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19035. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  19036. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19037. var sl = shapes.length;
  19038. for ( var s = 0; s < sl; s ++ ) {
  19039. var shape = shapes[ s ];
  19040. this.addShape( shape, options );
  19041. }
  19042. };
  19043. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  19044. var amount = options.amount !== undefined ? options.amount : 100;
  19045. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  19046. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  19047. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  19048. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  19049. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19050. var steps = options.steps !== undefined ? options.steps : 1;
  19051. var extrudePath = options.extrudePath;
  19052. var extrudePts, extrudeByPath = false;
  19053. // Use default WorldUVGenerator if no UV generators are specified.
  19054. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  19055. var splineTube, binormal, normal, position2;
  19056. if ( extrudePath ) {
  19057. extrudePts = extrudePath.getSpacedPoints( steps );
  19058. extrudeByPath = true;
  19059. bevelEnabled = false; // bevels not supported for path extrusion
  19060. // SETUP TNB variables
  19061. // Reuse TNB from TubeGeomtry for now.
  19062. // TODO1 - have a .isClosed in spline?
  19063. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  19064. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  19065. binormal = new THREE.Vector3();
  19066. normal = new THREE.Vector3();
  19067. position2 = new THREE.Vector3();
  19068. }
  19069. // Safeguards if bevels are not enabled
  19070. if ( ! bevelEnabled ) {
  19071. bevelSegments = 0;
  19072. bevelThickness = 0;
  19073. bevelSize = 0;
  19074. }
  19075. // Variables initialization
  19076. var ahole, h, hl; // looping of holes
  19077. var scope = this;
  19078. var shapesOffset = this.vertices.length;
  19079. var shapePoints = shape.extractPoints( curveSegments );
  19080. var vertices = shapePoints.shape;
  19081. var holes = shapePoints.holes;
  19082. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  19083. if ( reverse ) {
  19084. vertices = vertices.reverse();
  19085. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  19086. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19087. ahole = holes[ h ];
  19088. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  19089. holes[ h ] = ahole.reverse();
  19090. }
  19091. }
  19092. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  19093. }
  19094. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  19095. /* Vertices */
  19096. var contour = vertices; // vertices has all points but contour has only points of circumference
  19097. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19098. ahole = holes[ h ];
  19099. vertices = vertices.concat( ahole );
  19100. }
  19101. function scalePt2 ( pt, vec, size ) {
  19102. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  19103. return vec.clone().multiplyScalar( size ).add( pt );
  19104. }
  19105. var b, bs, t, z,
  19106. vert, vlen = vertices.length,
  19107. face, flen = faces.length;
  19108. // Find directions for point movement
  19109. function getBevelVec( inPt, inPrev, inNext ) {
  19110. // computes for inPt the corresponding point inPt' on a new contour
  19111. // shifted by 1 unit (length of normalized vector) to the left
  19112. // if we walk along contour clockwise, this new contour is outside the old one
  19113. //
  19114. // inPt' is the intersection of the two lines parallel to the two
  19115. // adjacent edges of inPt at a distance of 1 unit on the left side.
  19116. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  19117. // good reading for geometry algorithms (here: line-line intersection)
  19118. // http://geomalgorithms.com/a05-_intersect-1.html
  19119. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  19120. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  19121. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  19122. // check for collinear edges
  19123. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19124. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  19125. // not collinear
  19126. // length of vectors for normalizing
  19127. var v_prev_len = Math.sqrt( v_prev_lensq );
  19128. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  19129. // shift adjacent points by unit vectors to the left
  19130. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  19131. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  19132. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  19133. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  19134. // scaling factor for v_prev to intersection point
  19135. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  19136. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  19137. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19138. // vector from inPt to intersection point
  19139. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  19140. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  19141. // Don't normalize!, otherwise sharp corners become ugly
  19142. // but prevent crazy spikes
  19143. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  19144. if ( v_trans_lensq <= 2 ) {
  19145. return new THREE.Vector2( v_trans_x, v_trans_y );
  19146. } else {
  19147. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  19148. }
  19149. } else {
  19150. // handle special case of collinear edges
  19151. var direction_eq = false; // assumes: opposite
  19152. if ( v_prev_x > Number.EPSILON ) {
  19153. if ( v_next_x > Number.EPSILON ) {
  19154. direction_eq = true;
  19155. }
  19156. } else {
  19157. if ( v_prev_x < - Number.EPSILON ) {
  19158. if ( v_next_x < - Number.EPSILON ) {
  19159. direction_eq = true;
  19160. }
  19161. } else {
  19162. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  19163. direction_eq = true;
  19164. }
  19165. }
  19166. }
  19167. if ( direction_eq ) {
  19168. // console.log("Warning: lines are a straight sequence");
  19169. v_trans_x = - v_prev_y;
  19170. v_trans_y = v_prev_x;
  19171. shrink_by = Math.sqrt( v_prev_lensq );
  19172. } else {
  19173. // console.log("Warning: lines are a straight spike");
  19174. v_trans_x = v_prev_x;
  19175. v_trans_y = v_prev_y;
  19176. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  19177. }
  19178. }
  19179. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  19180. }
  19181. var contourMovements = [];
  19182. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19183. if ( j === il ) j = 0;
  19184. if ( k === il ) k = 0;
  19185. // (j)---(i)---(k)
  19186. // console.log('i,j,k', i, j , k)
  19187. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  19188. }
  19189. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  19190. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19191. ahole = holes[ h ];
  19192. oneHoleMovements = [];
  19193. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19194. if ( j === il ) j = 0;
  19195. if ( k === il ) k = 0;
  19196. // (j)---(i)---(k)
  19197. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  19198. }
  19199. holesMovements.push( oneHoleMovements );
  19200. verticesMovements = verticesMovements.concat( oneHoleMovements );
  19201. }
  19202. // Loop bevelSegments, 1 for the front, 1 for the back
  19203. for ( b = 0; b < bevelSegments; b ++ ) {
  19204. //for ( b = bevelSegments; b > 0; b -- ) {
  19205. t = b / bevelSegments;
  19206. z = bevelThickness * ( 1 - t );
  19207. //z = bevelThickness * t;
  19208. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  19209. //bs = bevelSize * t; // linear
  19210. // contract shape
  19211. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19212. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19213. v( vert.x, vert.y, - z );
  19214. }
  19215. // expand holes
  19216. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19217. ahole = holes[ h ];
  19218. oneHoleMovements = holesMovements[ h ];
  19219. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19220. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19221. v( vert.x, vert.y, - z );
  19222. }
  19223. }
  19224. }
  19225. bs = bevelSize;
  19226. // Back facing vertices
  19227. for ( i = 0; i < vlen; i ++ ) {
  19228. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19229. if ( ! extrudeByPath ) {
  19230. v( vert.x, vert.y, 0 );
  19231. } else {
  19232. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  19233. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  19234. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  19235. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  19236. v( position2.x, position2.y, position2.z );
  19237. }
  19238. }
  19239. // Add stepped vertices...
  19240. // Including front facing vertices
  19241. var s;
  19242. for ( s = 1; s <= steps; s ++ ) {
  19243. for ( i = 0; i < vlen; i ++ ) {
  19244. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19245. if ( ! extrudeByPath ) {
  19246. v( vert.x, vert.y, amount / steps * s );
  19247. } else {
  19248. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  19249. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  19250. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  19251. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  19252. v( position2.x, position2.y, position2.z );
  19253. }
  19254. }
  19255. }
  19256. // Add bevel segments planes
  19257. //for ( b = 1; b <= bevelSegments; b ++ ) {
  19258. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  19259. t = b / bevelSegments;
  19260. z = bevelThickness * ( 1 - t );
  19261. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  19262. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  19263. // contract shape
  19264. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19265. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19266. v( vert.x, vert.y, amount + z );
  19267. }
  19268. // expand holes
  19269. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19270. ahole = holes[ h ];
  19271. oneHoleMovements = holesMovements[ h ];
  19272. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19273. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19274. if ( ! extrudeByPath ) {
  19275. v( vert.x, vert.y, amount + z );
  19276. } else {
  19277. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19278. }
  19279. }
  19280. }
  19281. }
  19282. /* Faces */
  19283. // Top and bottom faces
  19284. buildLidFaces();
  19285. // Sides faces
  19286. buildSideFaces();
  19287. ///// Internal functions
  19288. function buildLidFaces() {
  19289. if ( bevelEnabled ) {
  19290. var layer = 0; // steps + 1
  19291. var offset = vlen * layer;
  19292. // Bottom faces
  19293. for ( i = 0; i < flen; i ++ ) {
  19294. face = faces[ i ];
  19295. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19296. }
  19297. layer = steps + bevelSegments * 2;
  19298. offset = vlen * layer;
  19299. // Top faces
  19300. for ( i = 0; i < flen; i ++ ) {
  19301. face = faces[ i ];
  19302. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19303. }
  19304. } else {
  19305. // Bottom faces
  19306. for ( i = 0; i < flen; i ++ ) {
  19307. face = faces[ i ];
  19308. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19309. }
  19310. // Top faces
  19311. for ( i = 0; i < flen; i ++ ) {
  19312. face = faces[ i ];
  19313. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19314. }
  19315. }
  19316. }
  19317. // Create faces for the z-sides of the shape
  19318. function buildSideFaces() {
  19319. var layeroffset = 0;
  19320. sidewalls( contour, layeroffset );
  19321. layeroffset += contour.length;
  19322. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19323. ahole = holes[ h ];
  19324. sidewalls( ahole, layeroffset );
  19325. //, true
  19326. layeroffset += ahole.length;
  19327. }
  19328. }
  19329. function sidewalls( contour, layeroffset ) {
  19330. var j, k;
  19331. i = contour.length;
  19332. while ( -- i >= 0 ) {
  19333. j = i;
  19334. k = i - 1;
  19335. if ( k < 0 ) k = contour.length - 1;
  19336. //console.log('b', i,j, i-1, k,vertices.length);
  19337. var s = 0, sl = steps + bevelSegments * 2;
  19338. for ( s = 0; s < sl; s ++ ) {
  19339. var slen1 = vlen * s;
  19340. var slen2 = vlen * ( s + 1 );
  19341. var a = layeroffset + j + slen1,
  19342. b = layeroffset + k + slen1,
  19343. c = layeroffset + k + slen2,
  19344. d = layeroffset + j + slen2;
  19345. f4( a, b, c, d, contour, s, sl, j, k );
  19346. }
  19347. }
  19348. }
  19349. function v( x, y, z ) {
  19350. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  19351. }
  19352. function f3( a, b, c ) {
  19353. a += shapesOffset;
  19354. b += shapesOffset;
  19355. c += shapesOffset;
  19356. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  19357. var uvs = uvgen.generateTopUV( scope, a, b, c );
  19358. scope.faceVertexUvs[ 0 ].push( uvs );
  19359. }
  19360. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  19361. a += shapesOffset;
  19362. b += shapesOffset;
  19363. c += shapesOffset;
  19364. d += shapesOffset;
  19365. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  19366. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  19367. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  19368. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  19369. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  19370. }
  19371. };
  19372. THREE.ExtrudeGeometry.WorldUVGenerator = {
  19373. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  19374. var vertices = geometry.vertices;
  19375. var a = vertices[ indexA ];
  19376. var b = vertices[ indexB ];
  19377. var c = vertices[ indexC ];
  19378. return [
  19379. new THREE.Vector2( a.x, a.y ),
  19380. new THREE.Vector2( b.x, b.y ),
  19381. new THREE.Vector2( c.x, c.y )
  19382. ];
  19383. },
  19384. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  19385. var vertices = geometry.vertices;
  19386. var a = vertices[ indexA ];
  19387. var b = vertices[ indexB ];
  19388. var c = vertices[ indexC ];
  19389. var d = vertices[ indexD ];
  19390. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  19391. return [
  19392. new THREE.Vector2( a.x, 1 - a.z ),
  19393. new THREE.Vector2( b.x, 1 - b.z ),
  19394. new THREE.Vector2( c.x, 1 - c.z ),
  19395. new THREE.Vector2( d.x, 1 - d.z )
  19396. ];
  19397. } else {
  19398. return [
  19399. new THREE.Vector2( a.y, 1 - a.z ),
  19400. new THREE.Vector2( b.y, 1 - b.z ),
  19401. new THREE.Vector2( c.y, 1 - c.z ),
  19402. new THREE.Vector2( d.y, 1 - d.z )
  19403. ];
  19404. }
  19405. }
  19406. };
  19407. // File:src/extras/geometries/ShapeGeometry.js
  19408. /**
  19409. * @author jonobr1 / http://jonobr1.com
  19410. *
  19411. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19412. * ExtrudeGeometry.
  19413. *
  19414. * parameters = {
  19415. *
  19416. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19417. *
  19418. * material: <int> // material index for front and back faces
  19419. * uvGenerator: <Object> // object that provides UV generator functions
  19420. *
  19421. * }
  19422. **/
  19423. THREE.ShapeGeometry = function ( shapes, options ) {
  19424. THREE.Geometry.call( this );
  19425. this.type = 'ShapeGeometry';
  19426. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19427. this.addShapeList( shapes, options );
  19428. this.computeFaceNormals();
  19429. };
  19430. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19431. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19432. /**
  19433. * Add an array of shapes to THREE.ShapeGeometry.
  19434. */
  19435. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19436. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19437. this.addShape( shapes[ i ], options );
  19438. }
  19439. return this;
  19440. };
  19441. /**
  19442. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19443. */
  19444. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19445. if ( options === undefined ) options = {};
  19446. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19447. var material = options.material;
  19448. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19449. //
  19450. var i, l, hole;
  19451. var shapesOffset = this.vertices.length;
  19452. var shapePoints = shape.extractPoints( curveSegments );
  19453. var vertices = shapePoints.shape;
  19454. var holes = shapePoints.holes;
  19455. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  19456. if ( reverse ) {
  19457. vertices = vertices.reverse();
  19458. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19459. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19460. hole = holes[ i ];
  19461. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  19462. holes[ i ] = hole.reverse();
  19463. }
  19464. }
  19465. reverse = false;
  19466. }
  19467. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  19468. // Vertices
  19469. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19470. hole = holes[ i ];
  19471. vertices = vertices.concat( hole );
  19472. }
  19473. //
  19474. var vert, vlen = vertices.length;
  19475. var face, flen = faces.length;
  19476. for ( i = 0; i < vlen; i ++ ) {
  19477. vert = vertices[ i ];
  19478. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19479. }
  19480. for ( i = 0; i < flen; i ++ ) {
  19481. face = faces[ i ];
  19482. var a = face[ 0 ] + shapesOffset;
  19483. var b = face[ 1 ] + shapesOffset;
  19484. var c = face[ 2 ] + shapesOffset;
  19485. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19486. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19487. }
  19488. };
  19489. // File:src/extras/geometries/LatheGeometry.js
  19490. /**
  19491. * @author astrodud / http://astrodud.isgreat.org/
  19492. * @author zz85 / https://github.com/zz85
  19493. * @author bhouston / http://clara.io
  19494. */
  19495. // points - to create a closed torus, one must use a set of points
  19496. // like so: [ a, b, c, d, a ], see first is the same as last.
  19497. // segments - the number of circumference segments to create
  19498. // phiStart - the starting radian
  19499. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19500. // 2*pi is a closed lathe, less than 2PI is a portion.
  19501. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19502. THREE.Geometry.call( this );
  19503. this.type = 'LatheGeometry';
  19504. this.parameters = {
  19505. points: points,
  19506. segments: segments,
  19507. phiStart: phiStart,
  19508. phiLength: phiLength
  19509. };
  19510. segments = segments || 12;
  19511. phiStart = phiStart || 0;
  19512. phiLength = phiLength || 2 * Math.PI;
  19513. var inversePointLength = 1.0 / ( points.length - 1 );
  19514. var inverseSegments = 1.0 / segments;
  19515. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19516. var phi = phiStart + i * inverseSegments * phiLength;
  19517. var c = Math.cos( phi ),
  19518. s = Math.sin( phi );
  19519. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19520. var pt = points[ j ];
  19521. var vertex = new THREE.Vector3();
  19522. vertex.x = c * pt.x - s * pt.y;
  19523. vertex.y = s * pt.x + c * pt.y;
  19524. vertex.z = pt.z;
  19525. this.vertices.push( vertex );
  19526. }
  19527. }
  19528. var np = points.length;
  19529. for ( var i = 0, il = segments; i < il; i ++ ) {
  19530. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19531. var base = j + np * i;
  19532. var a = base;
  19533. var b = base + np;
  19534. var c = base + 1 + np;
  19535. var d = base + 1;
  19536. var u0 = i * inverseSegments;
  19537. var v0 = j * inversePointLength;
  19538. var u1 = u0 + inverseSegments;
  19539. var v1 = v0 + inversePointLength;
  19540. this.faces.push( new THREE.Face3( a, b, d ) );
  19541. this.faceVertexUvs[ 0 ].push( [
  19542. new THREE.Vector2( u0, v0 ),
  19543. new THREE.Vector2( u1, v0 ),
  19544. new THREE.Vector2( u0, v1 )
  19545. ] );
  19546. this.faces.push( new THREE.Face3( b, c, d ) );
  19547. this.faceVertexUvs[ 0 ].push( [
  19548. new THREE.Vector2( u1, v0 ),
  19549. new THREE.Vector2( u1, v1 ),
  19550. new THREE.Vector2( u0, v1 )
  19551. ] );
  19552. }
  19553. }
  19554. this.mergeVertices();
  19555. this.computeFaceNormals();
  19556. this.computeVertexNormals();
  19557. };
  19558. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19559. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19560. // File:src/extras/geometries/PlaneGeometry.js
  19561. /**
  19562. * @author mrdoob / http://mrdoob.com/
  19563. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19564. */
  19565. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19566. THREE.Geometry.call( this );
  19567. this.type = 'PlaneGeometry';
  19568. this.parameters = {
  19569. width: width,
  19570. height: height,
  19571. widthSegments: widthSegments,
  19572. heightSegments: heightSegments
  19573. };
  19574. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  19575. };
  19576. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19577. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  19578. THREE.PlaneGeometry.prototype.clone = function () {
  19579. var parameters = this.parameters;
  19580. return new THREE.PlaneGeometry(
  19581. parameters.width,
  19582. parameters.height,
  19583. parameters.widthSegments,
  19584. parameters.heightSegments
  19585. );
  19586. };
  19587. // File:src/extras/geometries/PlaneBufferGeometry.js
  19588. /**
  19589. * @author mrdoob / http://mrdoob.com/
  19590. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19591. */
  19592. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  19593. THREE.BufferGeometry.call( this );
  19594. this.type = 'PlaneBufferGeometry';
  19595. this.parameters = {
  19596. width: width,
  19597. height: height,
  19598. widthSegments: widthSegments,
  19599. heightSegments: heightSegments
  19600. };
  19601. var width_half = width / 2;
  19602. var height_half = height / 2;
  19603. var gridX = Math.floor( widthSegments ) || 1;
  19604. var gridY = Math.floor( heightSegments ) || 1;
  19605. var gridX1 = gridX + 1;
  19606. var gridY1 = gridY + 1;
  19607. var segment_width = width / gridX;
  19608. var segment_height = height / gridY;
  19609. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  19610. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  19611. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  19612. var offset = 0;
  19613. var offset2 = 0;
  19614. for ( var iy = 0; iy < gridY1; iy ++ ) {
  19615. var y = iy * segment_height - height_half;
  19616. for ( var ix = 0; ix < gridX1; ix ++ ) {
  19617. var x = ix * segment_width - width_half;
  19618. vertices[ offset ] = x;
  19619. vertices[ offset + 1 ] = - y;
  19620. normals[ offset + 2 ] = 1;
  19621. uvs[ offset2 ] = ix / gridX;
  19622. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  19623. offset += 3;
  19624. offset2 += 2;
  19625. }
  19626. }
  19627. offset = 0;
  19628. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  19629. for ( var iy = 0; iy < gridY; iy ++ ) {
  19630. for ( var ix = 0; ix < gridX; ix ++ ) {
  19631. var a = ix + gridX1 * iy;
  19632. var b = ix + gridX1 * ( iy + 1 );
  19633. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19634. var d = ( ix + 1 ) + gridX1 * iy;
  19635. indices[ offset ] = a;
  19636. indices[ offset + 1 ] = b;
  19637. indices[ offset + 2 ] = d;
  19638. indices[ offset + 3 ] = b;
  19639. indices[ offset + 4 ] = c;
  19640. indices[ offset + 5 ] = d;
  19641. offset += 6;
  19642. }
  19643. }
  19644. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  19645. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  19646. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19647. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19648. };
  19649. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19650. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  19651. THREE.PlaneBufferGeometry.prototype.clone = function () {
  19652. var parameters = this.parameters;
  19653. return new THREE.PlaneBufferGeometry(
  19654. parameters.width,
  19655. parameters.height,
  19656. parameters.widthSegments,
  19657. parameters.heightSegments
  19658. );
  19659. };
  19660. // File:src/extras/geometries/RingGeometry.js
  19661. /**
  19662. * @author Kaleb Murphy
  19663. */
  19664. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19665. THREE.Geometry.call( this );
  19666. this.type = 'RingGeometry';
  19667. this.parameters = {
  19668. innerRadius: innerRadius,
  19669. outerRadius: outerRadius,
  19670. thetaSegments: thetaSegments,
  19671. phiSegments: phiSegments,
  19672. thetaStart: thetaStart,
  19673. thetaLength: thetaLength
  19674. };
  19675. innerRadius = innerRadius || 0;
  19676. outerRadius = outerRadius || 50;
  19677. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19678. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19679. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19680. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  19681. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19682. for ( i = 0; i < phiSegments + 1; i ++ ) {
  19683. // concentric circles inside ring
  19684. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  19685. // number of segments per circle
  19686. var vertex = new THREE.Vector3();
  19687. var segment = thetaStart + o / thetaSegments * thetaLength;
  19688. vertex.x = radius * Math.cos( segment );
  19689. vertex.y = radius * Math.sin( segment );
  19690. this.vertices.push( vertex );
  19691. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  19692. }
  19693. radius += radiusStep;
  19694. }
  19695. var n = new THREE.Vector3( 0, 0, 1 );
  19696. for ( i = 0; i < phiSegments; i ++ ) {
  19697. // concentric circles inside ring
  19698. var thetaSegment = i * ( thetaSegments + 1 );
  19699. for ( o = 0; o < thetaSegments ; o ++ ) {
  19700. // number of segments per circle
  19701. var segment = o + thetaSegment;
  19702. var v1 = segment;
  19703. var v2 = segment + thetaSegments + 1;
  19704. var v3 = segment + thetaSegments + 2;
  19705. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19706. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  19707. v1 = segment;
  19708. v2 = segment + thetaSegments + 2;
  19709. v3 = segment + 1;
  19710. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19711. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  19712. }
  19713. }
  19714. this.computeFaceNormals();
  19715. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19716. };
  19717. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19718. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  19719. THREE.RingGeometry.prototype.clone = function () {
  19720. var parameters = this.parameters;
  19721. return new THREE.RingGeometry(
  19722. parameters.innerRadius,
  19723. parameters.outerRadius,
  19724. parameters.thetaSegments,
  19725. parameters.phiSegments,
  19726. parameters.thetaStart,
  19727. parameters.thetaLength
  19728. );
  19729. };
  19730. // File:src/extras/geometries/SphereGeometry.js
  19731. /**
  19732. * @author mrdoob / http://mrdoob.com/
  19733. */
  19734. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19735. THREE.Geometry.call( this );
  19736. this.type = 'SphereGeometry';
  19737. this.parameters = {
  19738. radius: radius,
  19739. widthSegments: widthSegments,
  19740. heightSegments: heightSegments,
  19741. phiStart: phiStart,
  19742. phiLength: phiLength,
  19743. thetaStart: thetaStart,
  19744. thetaLength: thetaLength
  19745. };
  19746. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  19747. };
  19748. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19749. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  19750. THREE.SphereGeometry.prototype.clone = function () {
  19751. var parameters = this.parameters;
  19752. return new THREE.SphereGeometry(
  19753. parameters.radius,
  19754. parameters.widthSegments,
  19755. parameters.heightSegments,
  19756. parameters.phiStart,
  19757. parameters.phiLength,
  19758. parameters.thetaStart,
  19759. parameters.thetaLength
  19760. );
  19761. };
  19762. // File:src/extras/geometries/SphereBufferGeometry.js
  19763. /**
  19764. * @author benaadams / https://twitter.com/ben_a_adams
  19765. * based on THREE.SphereGeometry
  19766. */
  19767. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19768. THREE.BufferGeometry.call( this );
  19769. this.type = 'SphereBufferGeometry';
  19770. this.parameters = {
  19771. radius: radius,
  19772. widthSegments: widthSegments,
  19773. heightSegments: heightSegments,
  19774. phiStart: phiStart,
  19775. phiLength: phiLength,
  19776. thetaStart: thetaStart,
  19777. thetaLength: thetaLength
  19778. };
  19779. radius = radius || 50;
  19780. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19781. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19782. phiStart = phiStart !== undefined ? phiStart : 0;
  19783. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19784. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19785. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19786. var thetaEnd = thetaStart + thetaLength;
  19787. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  19788. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19789. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19790. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  19791. var index = 0, vertices = [], normal = new THREE.Vector3();
  19792. for ( var y = 0; y <= heightSegments; y ++ ) {
  19793. var verticesRow = [];
  19794. var v = y / heightSegments;
  19795. for ( var x = 0; x <= widthSegments; x ++ ) {
  19796. var u = x / widthSegments;
  19797. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19798. var py = radius * Math.cos( thetaStart + v * thetaLength );
  19799. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19800. normal.set( px, py, pz ).normalize();
  19801. positions.setXYZ( index, px, py, pz );
  19802. normals.setXYZ( index, normal.x, normal.y, normal.z );
  19803. uvs.setXY( index, u, 1 - v );
  19804. verticesRow.push( index );
  19805. index ++;
  19806. }
  19807. vertices.push( verticesRow );
  19808. }
  19809. var indices = [];
  19810. for ( var y = 0; y < heightSegments; y ++ ) {
  19811. for ( var x = 0; x < widthSegments; x ++ ) {
  19812. var v1 = vertices[ y ][ x + 1 ];
  19813. var v2 = vertices[ y ][ x ];
  19814. var v3 = vertices[ y + 1 ][ x ];
  19815. var v4 = vertices[ y + 1 ][ x + 1 ];
  19816. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  19817. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  19818. }
  19819. }
  19820. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  19821. this.addAttribute( 'position', positions );
  19822. this.addAttribute( 'normal', normals );
  19823. this.addAttribute( 'uv', uvs );
  19824. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19825. };
  19826. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19827. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  19828. THREE.SphereBufferGeometry.prototype.clone = function () {
  19829. var parameters = this.parameters;
  19830. return new THREE.SphereBufferGeometry(
  19831. parameters.radius,
  19832. parameters.widthSegments,
  19833. parameters.heightSegments,
  19834. parameters.phiStart,
  19835. parameters.phiLength,
  19836. parameters.thetaStart,
  19837. parameters.thetaLength
  19838. );
  19839. };
  19840. // File:src/extras/geometries/TorusGeometry.js
  19841. /**
  19842. * @author oosmoxiecode
  19843. * @author mrdoob / http://mrdoob.com/
  19844. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  19845. */
  19846. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  19847. THREE.Geometry.call( this );
  19848. this.type = 'TorusGeometry';
  19849. this.parameters = {
  19850. radius: radius,
  19851. tube: tube,
  19852. radialSegments: radialSegments,
  19853. tubularSegments: tubularSegments,
  19854. arc: arc
  19855. };
  19856. radius = radius || 100;
  19857. tube = tube || 40;
  19858. radialSegments = radialSegments || 8;
  19859. tubularSegments = tubularSegments || 6;
  19860. arc = arc || Math.PI * 2;
  19861. var center = new THREE.Vector3(), uvs = [], normals = [];
  19862. for ( var j = 0; j <= radialSegments; j ++ ) {
  19863. for ( var i = 0; i <= tubularSegments; i ++ ) {
  19864. var u = i / tubularSegments * arc;
  19865. var v = j / radialSegments * Math.PI * 2;
  19866. center.x = radius * Math.cos( u );
  19867. center.y = radius * Math.sin( u );
  19868. var vertex = new THREE.Vector3();
  19869. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  19870. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  19871. vertex.z = tube * Math.sin( v );
  19872. this.vertices.push( vertex );
  19873. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  19874. normals.push( vertex.clone().sub( center ).normalize() );
  19875. }
  19876. }
  19877. for ( var j = 1; j <= radialSegments; j ++ ) {
  19878. for ( var i = 1; i <= tubularSegments; i ++ ) {
  19879. var a = ( tubularSegments + 1 ) * j + i - 1;
  19880. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  19881. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  19882. var d = ( tubularSegments + 1 ) * j + i;
  19883. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  19884. this.faces.push( face );
  19885. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  19886. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  19887. this.faces.push( face );
  19888. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  19889. }
  19890. }
  19891. this.computeFaceNormals();
  19892. };
  19893. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19894. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  19895. THREE.TorusGeometry.prototype.clone = function () {
  19896. var parameters = this.parameters;
  19897. return new THREE.TorusGeometry(
  19898. parameters.radius,
  19899. parameters.tube,
  19900. parameters.radialSegments,
  19901. parameters.tubularSegments,
  19902. parameters.arc
  19903. );
  19904. };
  19905. // File:src/extras/geometries/TorusKnotGeometry.js
  19906. /**
  19907. * @author oosmoxiecode
  19908. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  19909. */
  19910. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  19911. THREE.Geometry.call( this );
  19912. this.type = 'TorusKnotGeometry';
  19913. this.parameters = {
  19914. radius: radius,
  19915. tube: tube,
  19916. radialSegments: radialSegments,
  19917. tubularSegments: tubularSegments,
  19918. p: p,
  19919. q: q,
  19920. heightScale: heightScale
  19921. };
  19922. radius = radius || 100;
  19923. tube = tube || 40;
  19924. radialSegments = radialSegments || 64;
  19925. tubularSegments = tubularSegments || 8;
  19926. p = p || 2;
  19927. q = q || 3;
  19928. heightScale = heightScale || 1;
  19929. var grid = new Array( radialSegments );
  19930. var tang = new THREE.Vector3();
  19931. var n = new THREE.Vector3();
  19932. var bitan = new THREE.Vector3();
  19933. for ( var i = 0; i < radialSegments; ++ i ) {
  19934. grid[ i ] = new Array( tubularSegments );
  19935. var u = i / radialSegments * 2 * p * Math.PI;
  19936. var p1 = getPos( u, q, p, radius, heightScale );
  19937. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  19938. tang.subVectors( p2, p1 );
  19939. n.addVectors( p2, p1 );
  19940. bitan.crossVectors( tang, n );
  19941. n.crossVectors( bitan, tang );
  19942. bitan.normalize();
  19943. n.normalize();
  19944. for ( var j = 0; j < tubularSegments; ++ j ) {
  19945. var v = j / tubularSegments * 2 * Math.PI;
  19946. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19947. var cy = tube * Math.sin( v );
  19948. var pos = new THREE.Vector3();
  19949. pos.x = p1.x + cx * n.x + cy * bitan.x;
  19950. pos.y = p1.y + cx * n.y + cy * bitan.y;
  19951. pos.z = p1.z + cx * n.z + cy * bitan.z;
  19952. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  19953. }
  19954. }
  19955. for ( var i = 0; i < radialSegments; ++ i ) {
  19956. for ( var j = 0; j < tubularSegments; ++ j ) {
  19957. var ip = ( i + 1 ) % radialSegments;
  19958. var jp = ( j + 1 ) % tubularSegments;
  19959. var a = grid[ i ][ j ];
  19960. var b = grid[ ip ][ j ];
  19961. var c = grid[ ip ][ jp ];
  19962. var d = grid[ i ][ jp ];
  19963. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  19964. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  19965. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  19966. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  19967. this.faces.push( new THREE.Face3( a, b, d ) );
  19968. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19969. this.faces.push( new THREE.Face3( b, c, d ) );
  19970. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19971. }
  19972. }
  19973. this.computeFaceNormals();
  19974. this.computeVertexNormals();
  19975. function getPos( u, in_q, in_p, radius, heightScale ) {
  19976. var cu = Math.cos( u );
  19977. var su = Math.sin( u );
  19978. var quOverP = in_q / in_p * u;
  19979. var cs = Math.cos( quOverP );
  19980. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  19981. var ty = radius * ( 2 + cs ) * su * 0.5;
  19982. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  19983. return new THREE.Vector3( tx, ty, tz );
  19984. }
  19985. };
  19986. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19987. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  19988. THREE.TorusKnotGeometry.prototype.clone = function () {
  19989. var parameters = this.parameters;
  19990. return new THREE.TorusKnotGeometry(
  19991. parameters.radius,
  19992. parameters.tube,
  19993. parameters.radialSegments,
  19994. parameters.tubularSegments,
  19995. parameters.p,
  19996. parameters.q,
  19997. parameters.heightScale
  19998. );
  19999. };
  20000. // File:src/extras/geometries/TubeGeometry.js
  20001. /**
  20002. * @author WestLangley / https://github.com/WestLangley
  20003. * @author zz85 / https://github.com/zz85
  20004. * @author miningold / https://github.com/miningold
  20005. * @author jonobr1 / https://github.com/jonobr1
  20006. *
  20007. * Modified from the TorusKnotGeometry by @oosmoxiecode
  20008. *
  20009. * Creates a tube which extrudes along a 3d spline
  20010. *
  20011. * Uses parallel transport frames as described in
  20012. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  20013. */
  20014. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  20015. THREE.Geometry.call( this );
  20016. this.type = 'TubeGeometry';
  20017. this.parameters = {
  20018. path: path,
  20019. segments: segments,
  20020. radius: radius,
  20021. radialSegments: radialSegments,
  20022. closed: closed,
  20023. taper: taper
  20024. };
  20025. segments = segments || 64;
  20026. radius = radius || 1;
  20027. radialSegments = radialSegments || 8;
  20028. closed = closed || false;
  20029. taper = taper || THREE.TubeGeometry.NoTaper;
  20030. var grid = [];
  20031. var scope = this,
  20032. tangent,
  20033. normal,
  20034. binormal,
  20035. numpoints = segments + 1,
  20036. u, v, r,
  20037. cx, cy,
  20038. pos, pos2 = new THREE.Vector3(),
  20039. i, j,
  20040. ip, jp,
  20041. a, b, c, d,
  20042. uva, uvb, uvc, uvd;
  20043. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  20044. tangents = frames.tangents,
  20045. normals = frames.normals,
  20046. binormals = frames.binormals;
  20047. // proxy internals
  20048. this.tangents = tangents;
  20049. this.normals = normals;
  20050. this.binormals = binormals;
  20051. function vert( x, y, z ) {
  20052. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  20053. }
  20054. // construct the grid
  20055. for ( i = 0; i < numpoints; i ++ ) {
  20056. grid[ i ] = [];
  20057. u = i / ( numpoints - 1 );
  20058. pos = path.getPointAt( u );
  20059. tangent = tangents[ i ];
  20060. normal = normals[ i ];
  20061. binormal = binormals[ i ];
  20062. r = radius * taper( u );
  20063. for ( j = 0; j < radialSegments; j ++ ) {
  20064. v = j / radialSegments * 2 * Math.PI;
  20065. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20066. cy = r * Math.sin( v );
  20067. pos2.copy( pos );
  20068. pos2.x += cx * normal.x + cy * binormal.x;
  20069. pos2.y += cx * normal.y + cy * binormal.y;
  20070. pos2.z += cx * normal.z + cy * binormal.z;
  20071. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  20072. }
  20073. }
  20074. // construct the mesh
  20075. for ( i = 0; i < segments; i ++ ) {
  20076. for ( j = 0; j < radialSegments; j ++ ) {
  20077. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  20078. jp = ( j + 1 ) % radialSegments;
  20079. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  20080. b = grid[ ip ][ j ];
  20081. c = grid[ ip ][ jp ];
  20082. d = grid[ i ][ jp ];
  20083. uva = new THREE.Vector2( i / segments, j / radialSegments );
  20084. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  20085. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  20086. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  20087. this.faces.push( new THREE.Face3( a, b, d ) );
  20088. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20089. this.faces.push( new THREE.Face3( b, c, d ) );
  20090. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20091. }
  20092. }
  20093. this.computeFaceNormals();
  20094. this.computeVertexNormals();
  20095. };
  20096. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20097. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  20098. THREE.TubeGeometry.prototype.clone = function() {
  20099. return new this.constructor( this.parameters.path,
  20100. this.parameters.segments, this.parameters.radius, this.parameters.radialSegments,
  20101. this.parameters.closed, this.parameters.taper
  20102. );
  20103. };
  20104. THREE.TubeGeometry.NoTaper = function ( u ) {
  20105. return 1;
  20106. };
  20107. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  20108. return Math.sin( Math.PI * u );
  20109. };
  20110. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  20111. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  20112. var normal = new THREE.Vector3(),
  20113. tangents = [],
  20114. normals = [],
  20115. binormals = [],
  20116. vec = new THREE.Vector3(),
  20117. mat = new THREE.Matrix4(),
  20118. numpoints = segments + 1,
  20119. theta,
  20120. smallest,
  20121. tx, ty, tz,
  20122. i, u;
  20123. // expose internals
  20124. this.tangents = tangents;
  20125. this.normals = normals;
  20126. this.binormals = binormals;
  20127. // compute the tangent vectors for each segment on the path
  20128. for ( i = 0; i < numpoints; i ++ ) {
  20129. u = i / ( numpoints - 1 );
  20130. tangents[ i ] = path.getTangentAt( u );
  20131. tangents[ i ].normalize();
  20132. }
  20133. initialNormal3();
  20134. /*
  20135. function initialNormal1(lastBinormal) {
  20136. // fixed start binormal. Has dangers of 0 vectors
  20137. normals[ 0 ] = new THREE.Vector3();
  20138. binormals[ 0 ] = new THREE.Vector3();
  20139. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  20140. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  20141. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20142. }
  20143. function initialNormal2() {
  20144. // This uses the Frenet-Serret formula for deriving binormal
  20145. var t2 = path.getTangentAt( epsilon );
  20146. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  20147. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  20148. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  20149. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20150. }
  20151. */
  20152. function initialNormal3() {
  20153. // select an initial normal vector perpendicular to the first tangent vector,
  20154. // and in the direction of the smallest tangent xyz component
  20155. normals[ 0 ] = new THREE.Vector3();
  20156. binormals[ 0 ] = new THREE.Vector3();
  20157. smallest = Number.MAX_VALUE;
  20158. tx = Math.abs( tangents[ 0 ].x );
  20159. ty = Math.abs( tangents[ 0 ].y );
  20160. tz = Math.abs( tangents[ 0 ].z );
  20161. if ( tx <= smallest ) {
  20162. smallest = tx;
  20163. normal.set( 1, 0, 0 );
  20164. }
  20165. if ( ty <= smallest ) {
  20166. smallest = ty;
  20167. normal.set( 0, 1, 0 );
  20168. }
  20169. if ( tz <= smallest ) {
  20170. normal.set( 0, 0, 1 );
  20171. }
  20172. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20173. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20174. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20175. }
  20176. // compute the slowly-varying normal and binormal vectors for each segment on the path
  20177. for ( i = 1; i < numpoints; i ++ ) {
  20178. normals[ i ] = normals[ i - 1 ].clone();
  20179. binormals[ i ] = binormals[ i - 1 ].clone();
  20180. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20181. if ( vec.length() > Number.EPSILON ) {
  20182. vec.normalize();
  20183. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20184. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20185. }
  20186. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20187. }
  20188. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20189. if ( closed ) {
  20190. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  20191. theta /= ( numpoints - 1 );
  20192. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  20193. theta = - theta;
  20194. }
  20195. for ( i = 1; i < numpoints; i ++ ) {
  20196. // twist a little...
  20197. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20198. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20199. }
  20200. }
  20201. };
  20202. // File:src/extras/geometries/PolyhedronGeometry.js
  20203. /**
  20204. * @author clockworkgeek / https://github.com/clockworkgeek
  20205. * @author timothypratley / https://github.com/timothypratley
  20206. * @author WestLangley / http://github.com/WestLangley
  20207. */
  20208. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  20209. THREE.Geometry.call( this );
  20210. this.type = 'PolyhedronGeometry';
  20211. this.parameters = {
  20212. vertices: vertices,
  20213. indices: indices,
  20214. radius: radius,
  20215. detail: detail
  20216. };
  20217. radius = radius || 1;
  20218. detail = detail || 0;
  20219. var that = this;
  20220. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  20221. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  20222. }
  20223. var p = this.vertices;
  20224. var faces = [];
  20225. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  20226. var v1 = p[ indices[ i ] ];
  20227. var v2 = p[ indices[ i + 1 ] ];
  20228. var v3 = p[ indices[ i + 2 ] ];
  20229. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  20230. }
  20231. var centroid = new THREE.Vector3();
  20232. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20233. subdivide( faces[ i ], detail );
  20234. }
  20235. // Handle case when face straddles the seam
  20236. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  20237. var uvs = this.faceVertexUvs[ 0 ][ i ];
  20238. var x0 = uvs[ 0 ].x;
  20239. var x1 = uvs[ 1 ].x;
  20240. var x2 = uvs[ 2 ].x;
  20241. var max = Math.max( x0, x1, x2 );
  20242. var min = Math.min( x0, x1, x2 );
  20243. if ( max > 0.9 && min < 0.1 ) {
  20244. // 0.9 is somewhat arbitrary
  20245. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  20246. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  20247. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  20248. }
  20249. }
  20250. // Apply radius
  20251. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  20252. this.vertices[ i ].multiplyScalar( radius );
  20253. }
  20254. // Merge vertices
  20255. this.mergeVertices();
  20256. this.computeFaceNormals();
  20257. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20258. // Project vector onto sphere's surface
  20259. function prepare( vector ) {
  20260. var vertex = vector.normalize().clone();
  20261. vertex.index = that.vertices.push( vertex ) - 1;
  20262. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  20263. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  20264. var v = inclination( vector ) / Math.PI + 0.5;
  20265. vertex.uv = new THREE.Vector2( u, 1 - v );
  20266. return vertex;
  20267. }
  20268. // Approximate a curved face with recursively sub-divided triangles.
  20269. function make( v1, v2, v3, materialIndex ) {
  20270. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  20271. that.faces.push( face );
  20272. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  20273. var azi = azimuth( centroid );
  20274. that.faceVertexUvs[ 0 ].push( [
  20275. correctUV( v1.uv, v1, azi ),
  20276. correctUV( v2.uv, v2, azi ),
  20277. correctUV( v3.uv, v3, azi )
  20278. ] );
  20279. }
  20280. // Analytically subdivide a face to the required detail level.
  20281. function subdivide( face, detail ) {
  20282. var cols = Math.pow( 2, detail );
  20283. var a = prepare( that.vertices[ face.a ] );
  20284. var b = prepare( that.vertices[ face.b ] );
  20285. var c = prepare( that.vertices[ face.c ] );
  20286. var v = [];
  20287. var materialIndex = face.materialIndex;
  20288. // Construct all of the vertices for this subdivision.
  20289. for ( var i = 0 ; i <= cols; i ++ ) {
  20290. v[ i ] = [];
  20291. var aj = prepare( a.clone().lerp( c, i / cols ) );
  20292. var bj = prepare( b.clone().lerp( c, i / cols ) );
  20293. var rows = cols - i;
  20294. for ( var j = 0; j <= rows; j ++ ) {
  20295. if ( j === 0 && i === cols ) {
  20296. v[ i ][ j ] = aj;
  20297. } else {
  20298. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  20299. }
  20300. }
  20301. }
  20302. // Construct all of the faces.
  20303. for ( var i = 0; i < cols ; i ++ ) {
  20304. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  20305. var k = Math.floor( j / 2 );
  20306. if ( j % 2 === 0 ) {
  20307. make(
  20308. v[ i ][ k + 1 ],
  20309. v[ i + 1 ][ k ],
  20310. v[ i ][ k ],
  20311. materialIndex
  20312. );
  20313. } else {
  20314. make(
  20315. v[ i ][ k + 1 ],
  20316. v[ i + 1 ][ k + 1 ],
  20317. v[ i + 1 ][ k ],
  20318. materialIndex
  20319. );
  20320. }
  20321. }
  20322. }
  20323. }
  20324. // Angle around the Y axis, counter-clockwise when looking from above.
  20325. function azimuth( vector ) {
  20326. return Math.atan2( vector.z, - vector.x );
  20327. }
  20328. // Angle above the XZ plane.
  20329. function inclination( vector ) {
  20330. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  20331. }
  20332. // Texture fixing helper. Spheres have some odd behaviours.
  20333. function correctUV( uv, vector, azimuth ) {
  20334. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  20335. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  20336. return uv.clone();
  20337. }
  20338. };
  20339. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20340. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  20341. THREE.PolyhedronGeometry.prototype.clone = function () {
  20342. var parameters = this.parameters;
  20343. return new THREE.PolyhedronGeometry(
  20344. parameters.vertices,
  20345. parameters.indices,
  20346. parameters.radius,
  20347. parameters.detail
  20348. );
  20349. };
  20350. // File:src/extras/geometries/DodecahedronGeometry.js
  20351. /**
  20352. * @author Abe Pazos / https://hamoid.com
  20353. */
  20354. THREE.DodecahedronGeometry = function ( radius, detail ) {
  20355. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20356. var r = 1 / t;
  20357. var vertices = [
  20358. // (±1, ±1, ±1)
  20359. - 1, - 1, - 1, - 1, - 1, 1,
  20360. - 1, 1, - 1, - 1, 1, 1,
  20361. 1, - 1, - 1, 1, - 1, 1,
  20362. 1, 1, - 1, 1, 1, 1,
  20363. // (0, ±1/φ, ±φ)
  20364. 0, - r, - t, 0, - r, t,
  20365. 0, r, - t, 0, r, t,
  20366. // (±1/φ, ±φ, 0)
  20367. - r, - t, 0, - r, t, 0,
  20368. r, - t, 0, r, t, 0,
  20369. // (±φ, 0, ±1/φ)
  20370. - t, 0, - r, t, 0, - r,
  20371. - t, 0, r, t, 0, r
  20372. ];
  20373. var indices = [
  20374. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  20375. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  20376. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  20377. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  20378. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  20379. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  20380. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  20381. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  20382. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  20383. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  20384. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  20385. 1, 12, 14, 1, 14, 5, 1, 5, 9
  20386. ];
  20387. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20388. this.type = 'DodecahedronGeometry';
  20389. this.parameters = {
  20390. radius: radius,
  20391. detail: detail
  20392. };
  20393. };
  20394. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20395. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  20396. THREE.DodecahedronGeometry.prototype.clone = function () {
  20397. var parameters = this.parameters;
  20398. return new THREE.DodecahedronGeometry(
  20399. parameters.radius,
  20400. parameters.detail
  20401. );
  20402. };
  20403. // File:src/extras/geometries/IcosahedronGeometry.js
  20404. /**
  20405. * @author timothypratley / https://github.com/timothypratley
  20406. */
  20407. THREE.IcosahedronGeometry = function ( radius, detail ) {
  20408. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20409. var vertices = [
  20410. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20411. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20412. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20413. ];
  20414. var indices = [
  20415. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20416. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20417. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20418. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20419. ];
  20420. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20421. this.type = 'IcosahedronGeometry';
  20422. this.parameters = {
  20423. radius: radius,
  20424. detail: detail
  20425. };
  20426. };
  20427. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20428. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20429. THREE.IcosahedronGeometry.prototype.clone = function () {
  20430. var parameters = this.parameters;
  20431. return new THREE.IcosahedronGeometry(
  20432. parameters.radius,
  20433. parameters.detail
  20434. );
  20435. };
  20436. // File:src/extras/geometries/OctahedronGeometry.js
  20437. /**
  20438. * @author timothypratley / https://github.com/timothypratley
  20439. */
  20440. THREE.OctahedronGeometry = function ( radius, detail ) {
  20441. var vertices = [
  20442. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  20443. ];
  20444. var indices = [
  20445. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20446. ];
  20447. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20448. this.type = 'OctahedronGeometry';
  20449. this.parameters = {
  20450. radius: radius,
  20451. detail: detail
  20452. };
  20453. };
  20454. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20455. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20456. THREE.OctahedronGeometry.prototype.clone = function () {
  20457. var parameters = this.parameters;
  20458. return new THREE.OctahedronGeometry(
  20459. parameters.radius,
  20460. parameters.detail
  20461. );
  20462. };
  20463. // File:src/extras/geometries/TetrahedronGeometry.js
  20464. /**
  20465. * @author timothypratley / https://github.com/timothypratley
  20466. */
  20467. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20468. var vertices = [
  20469. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20470. ];
  20471. var indices = [
  20472. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20473. ];
  20474. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20475. this.type = 'TetrahedronGeometry';
  20476. this.parameters = {
  20477. radius: radius,
  20478. detail: detail
  20479. };
  20480. };
  20481. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20482. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20483. THREE.TetrahedronGeometry.prototype.clone = function () {
  20484. var parameters = this.parameters;
  20485. return new THREE.TetrahedronGeometry(
  20486. parameters.radius,
  20487. parameters.detail
  20488. );
  20489. };
  20490. // File:src/extras/geometries/ParametricGeometry.js
  20491. /**
  20492. * @author zz85 / https://github.com/zz85
  20493. * Parametric Surfaces Geometry
  20494. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20495. *
  20496. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20497. *
  20498. */
  20499. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20500. THREE.Geometry.call( this );
  20501. this.type = 'ParametricGeometry';
  20502. this.parameters = {
  20503. func: func,
  20504. slices: slices,
  20505. stacks: stacks
  20506. };
  20507. var verts = this.vertices;
  20508. var faces = this.faces;
  20509. var uvs = this.faceVertexUvs[ 0 ];
  20510. var i, j, p;
  20511. var u, v;
  20512. var sliceCount = slices + 1;
  20513. for ( i = 0; i <= stacks; i ++ ) {
  20514. v = i / stacks;
  20515. for ( j = 0; j <= slices; j ++ ) {
  20516. u = j / slices;
  20517. p = func( u, v );
  20518. verts.push( p );
  20519. }
  20520. }
  20521. var a, b, c, d;
  20522. var uva, uvb, uvc, uvd;
  20523. for ( i = 0; i < stacks; i ++ ) {
  20524. for ( j = 0; j < slices; j ++ ) {
  20525. a = i * sliceCount + j;
  20526. b = i * sliceCount + j + 1;
  20527. c = ( i + 1 ) * sliceCount + j + 1;
  20528. d = ( i + 1 ) * sliceCount + j;
  20529. uva = new THREE.Vector2( j / slices, i / stacks );
  20530. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  20531. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  20532. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  20533. faces.push( new THREE.Face3( a, b, d ) );
  20534. uvs.push( [ uva, uvb, uvd ] );
  20535. faces.push( new THREE.Face3( b, c, d ) );
  20536. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  20537. }
  20538. }
  20539. // console.log(this);
  20540. // magic bullet
  20541. // var diff = this.mergeVertices();
  20542. // console.log('removed ', diff, ' vertices by merging');
  20543. this.computeFaceNormals();
  20544. this.computeVertexNormals();
  20545. };
  20546. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20547. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  20548. // File:src/extras/geometries/WireframeGeometry.js
  20549. /**
  20550. * @author mrdoob / http://mrdoob.com/
  20551. */
  20552. THREE.WireframeGeometry = function ( geometry ) {
  20553. THREE.BufferGeometry.call( this );
  20554. var edge = [ 0, 0 ], hash = {};
  20555. function sortFunction( a, b ) {
  20556. return a - b;
  20557. }
  20558. var keys = [ 'a', 'b', 'c' ];
  20559. if ( geometry instanceof THREE.Geometry ) {
  20560. var vertices = geometry.vertices;
  20561. var faces = geometry.faces;
  20562. var numEdges = 0;
  20563. // allocate maximal size
  20564. var edges = new Uint32Array( 6 * faces.length );
  20565. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20566. var face = faces[ i ];
  20567. for ( var j = 0; j < 3; j ++ ) {
  20568. edge[ 0 ] = face[ keys[ j ] ];
  20569. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  20570. edge.sort( sortFunction );
  20571. var key = edge.toString();
  20572. if ( hash[ key ] === undefined ) {
  20573. edges[ 2 * numEdges ] = edge[ 0 ];
  20574. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20575. hash[ key ] = true;
  20576. numEdges ++;
  20577. }
  20578. }
  20579. }
  20580. var coords = new Float32Array( numEdges * 2 * 3 );
  20581. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20582. for ( var j = 0; j < 2; j ++ ) {
  20583. var vertex = vertices[ edges [ 2 * i + j ] ];
  20584. var index = 6 * i + 3 * j;
  20585. coords[ index + 0 ] = vertex.x;
  20586. coords[ index + 1 ] = vertex.y;
  20587. coords[ index + 2 ] = vertex.z;
  20588. }
  20589. }
  20590. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20591. } else if ( geometry instanceof THREE.BufferGeometry ) {
  20592. if ( geometry.index !== null ) {
  20593. // Indexed BufferGeometry
  20594. var indices = geometry.index.array;
  20595. var vertices = geometry.attributes.position;
  20596. var drawcalls = geometry.drawcalls;
  20597. var numEdges = 0;
  20598. if ( drawcalls.length === 0 ) {
  20599. geometry.addGroup( 0, indices.length );
  20600. }
  20601. // allocate maximal size
  20602. var edges = new Uint32Array( 2 * indices.length );
  20603. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  20604. var drawcall = drawcalls[ o ];
  20605. var start = drawcall.start;
  20606. var count = drawcall.count;
  20607. for ( var i = start, il = start + count; i < il; i += 3 ) {
  20608. for ( var j = 0; j < 3; j ++ ) {
  20609. edge[ 0 ] = indices[ i + j ];
  20610. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  20611. edge.sort( sortFunction );
  20612. var key = edge.toString();
  20613. if ( hash[ key ] === undefined ) {
  20614. edges[ 2 * numEdges ] = edge[ 0 ];
  20615. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20616. hash[ key ] = true;
  20617. numEdges ++;
  20618. }
  20619. }
  20620. }
  20621. }
  20622. var coords = new Float32Array( numEdges * 2 * 3 );
  20623. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20624. for ( var j = 0; j < 2; j ++ ) {
  20625. var index = 6 * i + 3 * j;
  20626. var index2 = edges[ 2 * i + j ];
  20627. coords[ index + 0 ] = vertices.getX( index2 );
  20628. coords[ index + 1 ] = vertices.getY( index2 );
  20629. coords[ index + 2 ] = vertices.getZ( index2 );
  20630. }
  20631. }
  20632. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20633. } else {
  20634. // non-indexed BufferGeometry
  20635. var vertices = geometry.attributes.position.array;
  20636. var numEdges = vertices.length / 3;
  20637. var numTris = numEdges / 3;
  20638. var coords = new Float32Array( numEdges * 2 * 3 );
  20639. for ( var i = 0, l = numTris; i < l; i ++ ) {
  20640. for ( var j = 0; j < 3; j ++ ) {
  20641. var index = 18 * i + 6 * j;
  20642. var index1 = 9 * i + 3 * j;
  20643. coords[ index + 0 ] = vertices[ index1 ];
  20644. coords[ index + 1 ] = vertices[ index1 + 1 ];
  20645. coords[ index + 2 ] = vertices[ index1 + 2 ];
  20646. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  20647. coords[ index + 3 ] = vertices[ index2 ];
  20648. coords[ index + 4 ] = vertices[ index2 + 1 ];
  20649. coords[ index + 5 ] = vertices[ index2 + 2 ];
  20650. }
  20651. }
  20652. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20653. }
  20654. }
  20655. };
  20656. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20657. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  20658. // File:src/extras/helpers/AxisHelper.js
  20659. /**
  20660. * @author sroucheray / http://sroucheray.org/
  20661. * @author mrdoob / http://mrdoob.com/
  20662. */
  20663. THREE.AxisHelper = function ( size ) {
  20664. size = size || 1;
  20665. var vertices = new Float32Array( [
  20666. 0, 0, 0, size, 0, 0,
  20667. 0, 0, 0, 0, size, 0,
  20668. 0, 0, 0, 0, 0, size
  20669. ] );
  20670. var colors = new Float32Array( [
  20671. 1, 0, 0, 1, 0.6, 0,
  20672. 0, 1, 0, 0.6, 1, 0,
  20673. 0, 0, 1, 0, 0.6, 1
  20674. ] );
  20675. var geometry = new THREE.BufferGeometry();
  20676. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20677. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  20678. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20679. THREE.LineSegments.call( this, geometry, material );
  20680. };
  20681. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20682. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  20683. // File:src/extras/helpers/ArrowHelper.js
  20684. /**
  20685. * @author WestLangley / http://github.com/WestLangley
  20686. * @author zz85 / http://github.com/zz85
  20687. * @author bhouston / http://clara.io
  20688. *
  20689. * Creates an arrow for visualizing directions
  20690. *
  20691. * Parameters:
  20692. * dir - Vector3
  20693. * origin - Vector3
  20694. * length - Number
  20695. * color - color in hex value
  20696. * headLength - Number
  20697. * headWidth - Number
  20698. */
  20699. THREE.ArrowHelper = ( function () {
  20700. var lineGeometry = new THREE.Geometry();
  20701. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  20702. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  20703. coneGeometry.translate( 0, - 0.5, 0 );
  20704. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  20705. // dir is assumed to be normalized
  20706. THREE.Object3D.call( this );
  20707. if ( color === undefined ) color = 0xffff00;
  20708. if ( length === undefined ) length = 1;
  20709. if ( headLength === undefined ) headLength = 0.2 * length;
  20710. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20711. this.position.copy( origin );
  20712. if ( headLength < length ) {
  20713. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  20714. this.line.matrixAutoUpdate = false;
  20715. this.add( this.line );
  20716. }
  20717. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  20718. this.cone.matrixAutoUpdate = false;
  20719. this.add( this.cone );
  20720. this.setDirection( dir );
  20721. this.setLength( length, headLength, headWidth );
  20722. }
  20723. }() );
  20724. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  20725. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  20726. THREE.ArrowHelper.prototype.setDirection = ( function () {
  20727. var axis = new THREE.Vector3();
  20728. var radians;
  20729. return function setDirection( dir ) {
  20730. // dir is assumed to be normalized
  20731. if ( dir.y > 0.99999 ) {
  20732. this.quaternion.set( 0, 0, 0, 1 );
  20733. } else if ( dir.y < - 0.99999 ) {
  20734. this.quaternion.set( 1, 0, 0, 0 );
  20735. } else {
  20736. axis.set( dir.z, 0, - dir.x ).normalize();
  20737. radians = Math.acos( dir.y );
  20738. this.quaternion.setFromAxisAngle( axis, radians );
  20739. }
  20740. };
  20741. }() );
  20742. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  20743. if ( headLength === undefined ) headLength = 0.2 * length;
  20744. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20745. if ( headLength < length ){
  20746. this.line.scale.set( 1, length - headLength, 1 );
  20747. this.line.updateMatrix();
  20748. }
  20749. this.cone.scale.set( headWidth, headLength, headWidth );
  20750. this.cone.position.y = length;
  20751. this.cone.updateMatrix();
  20752. };
  20753. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  20754. if ( this.line !== undefined ) this.line.material.color.set( color );
  20755. this.cone.material.color.set( color );
  20756. };
  20757. // File:src/extras/helpers/BoxHelper.js
  20758. /**
  20759. * @author mrdoob / http://mrdoob.com/
  20760. */
  20761. THREE.BoxHelper = function ( object ) {
  20762. 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 ] );
  20763. var positions = new Float32Array( 8 * 3 );
  20764. var geometry = new THREE.BufferGeometry();
  20765. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  20766. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  20767. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  20768. if ( object !== undefined ) {
  20769. this.update( object );
  20770. }
  20771. };
  20772. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20773. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  20774. THREE.BoxHelper.prototype.update = ( function () {
  20775. var box = new THREE.Box3();
  20776. return function ( object ) {
  20777. box.setFromObject( object );
  20778. if ( box.empty() ) return;
  20779. var min = box.min;
  20780. var max = box.max;
  20781. /*
  20782. 5____4
  20783. 1/___0/|
  20784. | 6__|_7
  20785. 2/___3/
  20786. 0: max.x, max.y, max.z
  20787. 1: min.x, max.y, max.z
  20788. 2: min.x, min.y, max.z
  20789. 3: max.x, min.y, max.z
  20790. 4: max.x, max.y, min.z
  20791. 5: min.x, max.y, min.z
  20792. 6: min.x, min.y, min.z
  20793. 7: max.x, min.y, min.z
  20794. */
  20795. var position = this.geometry.attributes.position;
  20796. var array = position.array;
  20797. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  20798. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  20799. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  20800. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  20801. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  20802. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  20803. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  20804. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  20805. position.needsUpdate = true;
  20806. this.geometry.computeBoundingSphere();
  20807. }
  20808. } )();
  20809. // File:src/extras/helpers/BoundingBoxHelper.js
  20810. /**
  20811. * @author WestLangley / http://github.com/WestLangley
  20812. */
  20813. // a helper to show the world-axis-aligned bounding box for an object
  20814. THREE.BoundingBoxHelper = function ( object, hex ) {
  20815. var color = ( hex !== undefined ) ? hex : 0x888888;
  20816. this.object = object;
  20817. this.box = new THREE.Box3();
  20818. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  20819. };
  20820. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  20821. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  20822. THREE.BoundingBoxHelper.prototype.update = function () {
  20823. this.box.setFromObject( this.object );
  20824. this.box.size( this.scale );
  20825. this.box.center( this.position );
  20826. };
  20827. // File:src/extras/helpers/CameraHelper.js
  20828. /**
  20829. * @author alteredq / http://alteredqualia.com/
  20830. *
  20831. * - shows frustum, line of sight and up of the camera
  20832. * - suitable for fast updates
  20833. * - based on frustum visualization in lightgl.js shadowmap example
  20834. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  20835. */
  20836. THREE.CameraHelper = function ( camera ) {
  20837. var geometry = new THREE.Geometry();
  20838. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  20839. var pointMap = {};
  20840. // colors
  20841. var hexFrustum = 0xffaa00;
  20842. var hexCone = 0xff0000;
  20843. var hexUp = 0x00aaff;
  20844. var hexTarget = 0xffffff;
  20845. var hexCross = 0x333333;
  20846. // near
  20847. addLine( "n1", "n2", hexFrustum );
  20848. addLine( "n2", "n4", hexFrustum );
  20849. addLine( "n4", "n3", hexFrustum );
  20850. addLine( "n3", "n1", hexFrustum );
  20851. // far
  20852. addLine( "f1", "f2", hexFrustum );
  20853. addLine( "f2", "f4", hexFrustum );
  20854. addLine( "f4", "f3", hexFrustum );
  20855. addLine( "f3", "f1", hexFrustum );
  20856. // sides
  20857. addLine( "n1", "f1", hexFrustum );
  20858. addLine( "n2", "f2", hexFrustum );
  20859. addLine( "n3", "f3", hexFrustum );
  20860. addLine( "n4", "f4", hexFrustum );
  20861. // cone
  20862. addLine( "p", "n1", hexCone );
  20863. addLine( "p", "n2", hexCone );
  20864. addLine( "p", "n3", hexCone );
  20865. addLine( "p", "n4", hexCone );
  20866. // up
  20867. addLine( "u1", "u2", hexUp );
  20868. addLine( "u2", "u3", hexUp );
  20869. addLine( "u3", "u1", hexUp );
  20870. // target
  20871. addLine( "c", "t", hexTarget );
  20872. addLine( "p", "c", hexCross );
  20873. // cross
  20874. addLine( "cn1", "cn2", hexCross );
  20875. addLine( "cn3", "cn4", hexCross );
  20876. addLine( "cf1", "cf2", hexCross );
  20877. addLine( "cf3", "cf4", hexCross );
  20878. function addLine( a, b, hex ) {
  20879. addPoint( a, hex );
  20880. addPoint( b, hex );
  20881. }
  20882. function addPoint( id, hex ) {
  20883. geometry.vertices.push( new THREE.Vector3() );
  20884. geometry.colors.push( new THREE.Color( hex ) );
  20885. if ( pointMap[ id ] === undefined ) {
  20886. pointMap[ id ] = [];
  20887. }
  20888. pointMap[ id ].push( geometry.vertices.length - 1 );
  20889. }
  20890. THREE.LineSegments.call( this, geometry, material );
  20891. this.camera = camera;
  20892. this.camera.updateProjectionMatrix();
  20893. this.matrix = camera.matrixWorld;
  20894. this.matrixAutoUpdate = false;
  20895. this.pointMap = pointMap;
  20896. this.update();
  20897. };
  20898. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20899. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  20900. THREE.CameraHelper.prototype.update = function () {
  20901. var geometry, pointMap;
  20902. var vector = new THREE.Vector3();
  20903. var camera = new THREE.Camera();
  20904. function setPoint( point, x, y, z ) {
  20905. vector.set( x, y, z ).unproject( camera );
  20906. var points = pointMap[ point ];
  20907. if ( points !== undefined ) {
  20908. for ( var i = 0, il = points.length; i < il; i ++ ) {
  20909. geometry.vertices[ points[ i ] ].copy( vector );
  20910. }
  20911. }
  20912. }
  20913. return function () {
  20914. geometry = this.geometry;
  20915. pointMap = this.pointMap;
  20916. var w = 1, h = 1;
  20917. // we need just camera projection matrix
  20918. // world matrix must be identity
  20919. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  20920. // center / target
  20921. setPoint( "c", 0, 0, - 1 );
  20922. setPoint( "t", 0, 0, 1 );
  20923. // near
  20924. setPoint( "n1", - w, - h, - 1 );
  20925. setPoint( "n2", w, - h, - 1 );
  20926. setPoint( "n3", - w, h, - 1 );
  20927. setPoint( "n4", w, h, - 1 );
  20928. // far
  20929. setPoint( "f1", - w, - h, 1 );
  20930. setPoint( "f2", w, - h, 1 );
  20931. setPoint( "f3", - w, h, 1 );
  20932. setPoint( "f4", w, h, 1 );
  20933. // up
  20934. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  20935. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  20936. setPoint( "u3", 0, h * 2, - 1 );
  20937. // cross
  20938. setPoint( "cf1", - w, 0, 1 );
  20939. setPoint( "cf2", w, 0, 1 );
  20940. setPoint( "cf3", 0, - h, 1 );
  20941. setPoint( "cf4", 0, h, 1 );
  20942. setPoint( "cn1", - w, 0, - 1 );
  20943. setPoint( "cn2", w, 0, - 1 );
  20944. setPoint( "cn3", 0, - h, - 1 );
  20945. setPoint( "cn4", 0, h, - 1 );
  20946. geometry.verticesNeedUpdate = true;
  20947. };
  20948. }();
  20949. // File:src/extras/helpers/DirectionalLightHelper.js
  20950. /**
  20951. * @author alteredq / http://alteredqualia.com/
  20952. * @author mrdoob / http://mrdoob.com/
  20953. * @author WestLangley / http://github.com/WestLangley
  20954. */
  20955. THREE.DirectionalLightHelper = function ( light, size ) {
  20956. THREE.Object3D.call( this );
  20957. this.light = light;
  20958. this.light.updateMatrixWorld();
  20959. this.matrix = light.matrixWorld;
  20960. this.matrixAutoUpdate = false;
  20961. size = size || 1;
  20962. var geometry = new THREE.Geometry();
  20963. geometry.vertices.push(
  20964. new THREE.Vector3( - size, size, 0 ),
  20965. new THREE.Vector3( size, size, 0 ),
  20966. new THREE.Vector3( size, - size, 0 ),
  20967. new THREE.Vector3( - size, - size, 0 ),
  20968. new THREE.Vector3( - size, size, 0 )
  20969. );
  20970. var material = new THREE.LineBasicMaterial( { fog: false } );
  20971. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20972. this.lightPlane = new THREE.Line( geometry, material );
  20973. this.add( this.lightPlane );
  20974. geometry = new THREE.Geometry();
  20975. geometry.vertices.push(
  20976. new THREE.Vector3(),
  20977. new THREE.Vector3()
  20978. );
  20979. material = new THREE.LineBasicMaterial( { fog: false } );
  20980. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20981. this.targetLine = new THREE.Line( geometry, material );
  20982. this.add( this.targetLine );
  20983. this.update();
  20984. };
  20985. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20986. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  20987. THREE.DirectionalLightHelper.prototype.dispose = function () {
  20988. this.lightPlane.geometry.dispose();
  20989. this.lightPlane.material.dispose();
  20990. this.targetLine.geometry.dispose();
  20991. this.targetLine.material.dispose();
  20992. };
  20993. THREE.DirectionalLightHelper.prototype.update = function () {
  20994. var v1 = new THREE.Vector3();
  20995. var v2 = new THREE.Vector3();
  20996. var v3 = new THREE.Vector3();
  20997. return function () {
  20998. v1.setFromMatrixPosition( this.light.matrixWorld );
  20999. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21000. v3.subVectors( v2, v1 );
  21001. this.lightPlane.lookAt( v3 );
  21002. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21003. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  21004. this.targetLine.geometry.verticesNeedUpdate = true;
  21005. this.targetLine.material.color.copy( this.lightPlane.material.color );
  21006. };
  21007. }();
  21008. // File:src/extras/helpers/EdgesHelper.js
  21009. /**
  21010. * @author WestLangley / http://github.com/WestLangley
  21011. * @param object THREE.Mesh whose geometry will be used
  21012. * @param hex line color
  21013. * @param thresholdAngle the minimum angle (in degrees),
  21014. * between the face normals of adjacent faces,
  21015. * that is required to render an edge. A value of 10 means
  21016. * an edge is only rendered if the angle is at least 10 degrees.
  21017. */
  21018. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  21019. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21020. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  21021. this.matrix = object.matrixWorld;
  21022. this.matrixAutoUpdate = false;
  21023. };
  21024. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21025. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  21026. // File:src/extras/helpers/FaceNormalsHelper.js
  21027. /**
  21028. * @author mrdoob / http://mrdoob.com/
  21029. * @author WestLangley / http://github.com/WestLangley
  21030. */
  21031. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  21032. // FaceNormalsHelper only supports THREE.Geometry
  21033. this.object = object;
  21034. this.size = ( size !== undefined ) ? size : 1;
  21035. var color = ( hex !== undefined ) ? hex : 0xffff00;
  21036. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21037. //
  21038. var nNormals = 0;
  21039. var objGeometry = this.object.geometry;
  21040. if ( objGeometry instanceof THREE.Geometry ) {
  21041. nNormals = objGeometry.faces.length;
  21042. } else {
  21043. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  21044. }
  21045. //
  21046. var geometry = new THREE.BufferGeometry();
  21047. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21048. geometry.addAttribute( 'position', positions );
  21049. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21050. //
  21051. this.matrixAutoUpdate = false;
  21052. this.update();
  21053. };
  21054. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21055. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  21056. THREE.FaceNormalsHelper.prototype.update = ( function () {
  21057. var v1 = new THREE.Vector3();
  21058. var v2 = new THREE.Vector3();
  21059. var normalMatrix = new THREE.Matrix3();
  21060. return function update() {
  21061. this.object.updateMatrixWorld( true );
  21062. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21063. var matrixWorld = this.object.matrixWorld;
  21064. var position = this.geometry.attributes.position;
  21065. //
  21066. var objGeometry = this.object.geometry;
  21067. var vertices = objGeometry.vertices;
  21068. var faces = objGeometry.faces;
  21069. var idx = 0;
  21070. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21071. var face = faces[ i ];
  21072. var normal = face.normal;
  21073. v1.copy( vertices[ face.a ] )
  21074. .add( vertices[ face.b ] )
  21075. .add( vertices[ face.c ] )
  21076. .divideScalar( 3 )
  21077. .applyMatrix4( matrixWorld );
  21078. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21079. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21080. idx = idx + 1;
  21081. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21082. idx = idx + 1;
  21083. }
  21084. position.needsUpdate = true;
  21085. return this;
  21086. }
  21087. }() );
  21088. // File:src/extras/helpers/GridHelper.js
  21089. /**
  21090. * @author mrdoob / http://mrdoob.com/
  21091. */
  21092. THREE.GridHelper = function ( size, step ) {
  21093. var geometry = new THREE.Geometry();
  21094. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21095. this.color1 = new THREE.Color( 0x444444 );
  21096. this.color2 = new THREE.Color( 0x888888 );
  21097. for ( var i = - size; i <= size; i += step ) {
  21098. geometry.vertices.push(
  21099. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  21100. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  21101. );
  21102. var color = i === 0 ? this.color1 : this.color2;
  21103. geometry.colors.push( color, color, color, color );
  21104. }
  21105. THREE.LineSegments.call( this, geometry, material );
  21106. };
  21107. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21108. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  21109. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  21110. this.color1.set( colorCenterLine );
  21111. this.color2.set( colorGrid );
  21112. this.geometry.colorsNeedUpdate = true;
  21113. };
  21114. // File:src/extras/helpers/HemisphereLightHelper.js
  21115. /**
  21116. * @author alteredq / http://alteredqualia.com/
  21117. * @author mrdoob / http://mrdoob.com/
  21118. */
  21119. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  21120. THREE.Object3D.call( this );
  21121. this.light = light;
  21122. this.light.updateMatrixWorld();
  21123. this.matrix = light.matrixWorld;
  21124. this.matrixAutoUpdate = false;
  21125. this.colors = [ new THREE.Color(), new THREE.Color() ];
  21126. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21127. geometry.rotateX( - Math.PI / 2 );
  21128. for ( var i = 0, il = 8; i < il; i ++ ) {
  21129. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  21130. }
  21131. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  21132. this.lightSphere = new THREE.Mesh( geometry, material );
  21133. this.add( this.lightSphere );
  21134. this.update();
  21135. };
  21136. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21137. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  21138. THREE.HemisphereLightHelper.prototype.dispose = function () {
  21139. this.lightSphere.geometry.dispose();
  21140. this.lightSphere.material.dispose();
  21141. };
  21142. THREE.HemisphereLightHelper.prototype.update = function () {
  21143. var vector = new THREE.Vector3();
  21144. return function () {
  21145. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  21146. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  21147. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  21148. this.lightSphere.geometry.colorsNeedUpdate = true;
  21149. }
  21150. }();
  21151. // File:src/extras/helpers/PointLightHelper.js
  21152. /**
  21153. * @author alteredq / http://alteredqualia.com/
  21154. * @author mrdoob / http://mrdoob.com/
  21155. */
  21156. THREE.PointLightHelper = function ( light, sphereSize ) {
  21157. this.light = light;
  21158. this.light.updateMatrixWorld();
  21159. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21160. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21161. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21162. THREE.Mesh.call( this, geometry, material );
  21163. this.matrix = this.light.matrixWorld;
  21164. this.matrixAutoUpdate = false;
  21165. /*
  21166. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21167. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21168. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21169. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21170. var d = light.distance;
  21171. if ( d === 0.0 ) {
  21172. this.lightDistance.visible = false;
  21173. } else {
  21174. this.lightDistance.scale.set( d, d, d );
  21175. }
  21176. this.add( this.lightDistance );
  21177. */
  21178. };
  21179. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  21180. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  21181. THREE.PointLightHelper.prototype.dispose = function () {
  21182. this.geometry.dispose();
  21183. this.material.dispose();
  21184. };
  21185. THREE.PointLightHelper.prototype.update = function () {
  21186. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21187. /*
  21188. var d = this.light.distance;
  21189. if ( d === 0.0 ) {
  21190. this.lightDistance.visible = false;
  21191. } else {
  21192. this.lightDistance.visible = true;
  21193. this.lightDistance.scale.set( d, d, d );
  21194. }
  21195. */
  21196. };
  21197. // File:src/extras/helpers/SkeletonHelper.js
  21198. /**
  21199. * @author Sean Griffin / http://twitter.com/sgrif
  21200. * @author Michael Guerrero / http://realitymeltdown.com
  21201. * @author mrdoob / http://mrdoob.com/
  21202. * @author ikerr / http://verold.com
  21203. */
  21204. THREE.SkeletonHelper = function ( object ) {
  21205. this.bones = this.getBoneList( object );
  21206. var geometry = new THREE.Geometry();
  21207. for ( var i = 0; i < this.bones.length; i ++ ) {
  21208. var bone = this.bones[ i ];
  21209. if ( bone.parent instanceof THREE.Bone ) {
  21210. geometry.vertices.push( new THREE.Vector3() );
  21211. geometry.vertices.push( new THREE.Vector3() );
  21212. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  21213. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  21214. }
  21215. }
  21216. geometry.dynamic = true;
  21217. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  21218. THREE.LineSegments.call( this, geometry, material );
  21219. this.root = object;
  21220. this.matrix = object.matrixWorld;
  21221. this.matrixAutoUpdate = false;
  21222. this.update();
  21223. };
  21224. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21225. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  21226. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  21227. var boneList = [];
  21228. if ( object instanceof THREE.Bone ) {
  21229. boneList.push( object );
  21230. }
  21231. for ( var i = 0; i < object.children.length; i ++ ) {
  21232. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  21233. }
  21234. return boneList;
  21235. };
  21236. THREE.SkeletonHelper.prototype.update = function () {
  21237. var geometry = this.geometry;
  21238. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  21239. var boneMatrix = new THREE.Matrix4();
  21240. var j = 0;
  21241. for ( var i = 0; i < this.bones.length; i ++ ) {
  21242. var bone = this.bones[ i ];
  21243. if ( bone.parent instanceof THREE.Bone ) {
  21244. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  21245. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  21246. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  21247. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  21248. j += 2;
  21249. }
  21250. }
  21251. geometry.verticesNeedUpdate = true;
  21252. geometry.computeBoundingSphere();
  21253. };
  21254. // File:src/extras/helpers/SpotLightHelper.js
  21255. /**
  21256. * @author alteredq / http://alteredqualia.com/
  21257. * @author mrdoob / http://mrdoob.com/
  21258. * @author WestLangley / http://github.com/WestLangley
  21259. */
  21260. THREE.SpotLightHelper = function ( light ) {
  21261. THREE.Object3D.call( this );
  21262. this.light = light;
  21263. this.light.updateMatrixWorld();
  21264. this.matrix = light.matrixWorld;
  21265. this.matrixAutoUpdate = false;
  21266. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  21267. geometry.translate( 0, - 0.5, 0 );
  21268. geometry.rotateX( - Math.PI / 2 );
  21269. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21270. this.cone = new THREE.Mesh( geometry, material );
  21271. this.add( this.cone );
  21272. this.update();
  21273. };
  21274. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21275. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  21276. THREE.SpotLightHelper.prototype.dispose = function () {
  21277. this.cone.geometry.dispose();
  21278. this.cone.material.dispose();
  21279. };
  21280. THREE.SpotLightHelper.prototype.update = function () {
  21281. var vector = new THREE.Vector3();
  21282. var vector2 = new THREE.Vector3();
  21283. return function () {
  21284. var coneLength = this.light.distance ? this.light.distance : 10000;
  21285. var coneWidth = coneLength * Math.tan( this.light.angle );
  21286. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21287. vector.setFromMatrixPosition( this.light.matrixWorld );
  21288. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  21289. this.cone.lookAt( vector2.sub( vector ) );
  21290. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21291. };
  21292. }();
  21293. // File:src/extras/helpers/VertexNormalsHelper.js
  21294. /**
  21295. * @author mrdoob / http://mrdoob.com/
  21296. * @author WestLangley / http://github.com/WestLangley
  21297. */
  21298. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  21299. this.object = object;
  21300. this.size = ( size !== undefined ) ? size : 1;
  21301. var color = ( hex !== undefined ) ? hex : 0xff0000;
  21302. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21303. //
  21304. var nNormals = 0;
  21305. var objGeometry = this.object.geometry;
  21306. if ( objGeometry instanceof THREE.Geometry ) {
  21307. nNormals = objGeometry.faces.length * 3;
  21308. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21309. nNormals = objGeometry.attributes.normal.count
  21310. }
  21311. //
  21312. var geometry = new THREE.BufferGeometry();
  21313. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21314. geometry.addAttribute( 'position', positions );
  21315. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21316. //
  21317. this.matrixAutoUpdate = false;
  21318. this.update();
  21319. };
  21320. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21321. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  21322. THREE.VertexNormalsHelper.prototype.update = ( function () {
  21323. var v1 = new THREE.Vector3();
  21324. var v2 = new THREE.Vector3();
  21325. var normalMatrix = new THREE.Matrix3();
  21326. return function update() {
  21327. var keys = [ 'a', 'b', 'c' ];
  21328. this.object.updateMatrixWorld( true );
  21329. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21330. var matrixWorld = this.object.matrixWorld;
  21331. var position = this.geometry.attributes.position;
  21332. //
  21333. var objGeometry = this.object.geometry;
  21334. if ( objGeometry instanceof THREE.Geometry ) {
  21335. var vertices = objGeometry.vertices;
  21336. var faces = objGeometry.faces;
  21337. var idx = 0;
  21338. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21339. var face = faces[ i ];
  21340. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  21341. var vertex = vertices[ face[ keys[ j ] ] ];
  21342. var normal = face.vertexNormals[ j ];
  21343. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21344. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21345. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21346. idx = idx + 1;
  21347. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21348. idx = idx + 1;
  21349. }
  21350. }
  21351. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21352. var objPos = objGeometry.attributes.position;
  21353. var objNorm = objGeometry.attributes.normal;
  21354. var idx = 0;
  21355. // for simplicity, ignore index and drawcalls, and render every normal
  21356. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21357. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21358. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  21359. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21360. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21361. idx = idx + 1;
  21362. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21363. idx = idx + 1;
  21364. }
  21365. }
  21366. position.needsUpdate = true;
  21367. return this;
  21368. }
  21369. }() );
  21370. // File:src/extras/helpers/WireframeHelper.js
  21371. /**
  21372. * @author mrdoob / http://mrdoob.com/
  21373. */
  21374. THREE.WireframeHelper = function ( object, hex ) {
  21375. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21376. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21377. this.matrix = object.matrixWorld;
  21378. this.matrixAutoUpdate = false;
  21379. };
  21380. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21381. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21382. // File:src/extras/objects/ImmediateRenderObject.js
  21383. /**
  21384. * @author alteredq / http://alteredqualia.com/
  21385. */
  21386. THREE.ImmediateRenderObject = function ( material ) {
  21387. THREE.Object3D.call( this );
  21388. this.material = material;
  21389. this.render = function ( renderCallback ) {};
  21390. };
  21391. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21392. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21393. // File:src/extras/objects/MorphBlendMesh.js
  21394. /**
  21395. * @author alteredq / http://alteredqualia.com/
  21396. */
  21397. THREE.MorphBlendMesh = function( geometry, material ) {
  21398. THREE.Mesh.call( this, geometry, material );
  21399. this.animationsMap = {};
  21400. this.animationsList = [];
  21401. // prepare default animation
  21402. // (all frames played together in 1 second)
  21403. var numFrames = this.geometry.morphTargets.length;
  21404. var name = "__default";
  21405. var startFrame = 0;
  21406. var endFrame = numFrames - 1;
  21407. var fps = numFrames / 1;
  21408. this.createAnimation( name, startFrame, endFrame, fps );
  21409. this.setAnimationWeight( name, 1 );
  21410. };
  21411. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21412. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21413. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21414. var animation = {
  21415. start: start,
  21416. end: end,
  21417. length: end - start + 1,
  21418. fps: fps,
  21419. duration: ( end - start ) / fps,
  21420. lastFrame: 0,
  21421. currentFrame: 0,
  21422. active: false,
  21423. time: 0,
  21424. direction: 1,
  21425. weight: 1,
  21426. directionBackwards: false,
  21427. mirroredLoop: false
  21428. };
  21429. this.animationsMap[ name ] = animation;
  21430. this.animationsList.push( animation );
  21431. };
  21432. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21433. var pattern = /([a-z]+)_?(\d+)/;
  21434. var firstAnimation, frameRanges = {};
  21435. var geometry = this.geometry;
  21436. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21437. var morph = geometry.morphTargets[ i ];
  21438. var chunks = morph.name.match( pattern );
  21439. if ( chunks && chunks.length > 1 ) {
  21440. var name = chunks[ 1 ];
  21441. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21442. var range = frameRanges[ name ];
  21443. if ( i < range.start ) range.start = i;
  21444. if ( i > range.end ) range.end = i;
  21445. if ( ! firstAnimation ) firstAnimation = name;
  21446. }
  21447. }
  21448. for ( var name in frameRanges ) {
  21449. var range = frameRanges[ name ];
  21450. this.createAnimation( name, range.start, range.end, fps );
  21451. }
  21452. this.firstAnimation = firstAnimation;
  21453. };
  21454. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21455. var animation = this.animationsMap[ name ];
  21456. if ( animation ) {
  21457. animation.direction = 1;
  21458. animation.directionBackwards = false;
  21459. }
  21460. };
  21461. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21462. var animation = this.animationsMap[ name ];
  21463. if ( animation ) {
  21464. animation.direction = - 1;
  21465. animation.directionBackwards = true;
  21466. }
  21467. };
  21468. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21469. var animation = this.animationsMap[ name ];
  21470. if ( animation ) {
  21471. animation.fps = fps;
  21472. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21473. }
  21474. };
  21475. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21476. var animation = this.animationsMap[ name ];
  21477. if ( animation ) {
  21478. animation.duration = duration;
  21479. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21480. }
  21481. };
  21482. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21483. var animation = this.animationsMap[ name ];
  21484. if ( animation ) {
  21485. animation.weight = weight;
  21486. }
  21487. };
  21488. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21489. var animation = this.animationsMap[ name ];
  21490. if ( animation ) {
  21491. animation.time = time;
  21492. }
  21493. };
  21494. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21495. var time = 0;
  21496. var animation = this.animationsMap[ name ];
  21497. if ( animation ) {
  21498. time = animation.time;
  21499. }
  21500. return time;
  21501. };
  21502. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21503. var duration = - 1;
  21504. var animation = this.animationsMap[ name ];
  21505. if ( animation ) {
  21506. duration = animation.duration;
  21507. }
  21508. return duration;
  21509. };
  21510. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21511. var animation = this.animationsMap[ name ];
  21512. if ( animation ) {
  21513. animation.time = 0;
  21514. animation.active = true;
  21515. } else {
  21516. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21517. }
  21518. };
  21519. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21520. var animation = this.animationsMap[ name ];
  21521. if ( animation ) {
  21522. animation.active = false;
  21523. }
  21524. };
  21525. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  21526. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  21527. var animation = this.animationsList[ i ];
  21528. if ( ! animation.active ) continue;
  21529. var frameTime = animation.duration / animation.length;
  21530. animation.time += animation.direction * delta;
  21531. if ( animation.mirroredLoop ) {
  21532. if ( animation.time > animation.duration || animation.time < 0 ) {
  21533. animation.direction *= - 1;
  21534. if ( animation.time > animation.duration ) {
  21535. animation.time = animation.duration;
  21536. animation.directionBackwards = true;
  21537. }
  21538. if ( animation.time < 0 ) {
  21539. animation.time = 0;
  21540. animation.directionBackwards = false;
  21541. }
  21542. }
  21543. } else {
  21544. animation.time = animation.time % animation.duration;
  21545. if ( animation.time < 0 ) animation.time += animation.duration;
  21546. }
  21547. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  21548. var weight = animation.weight;
  21549. if ( keyframe !== animation.currentFrame ) {
  21550. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  21551. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  21552. this.morphTargetInfluences[ keyframe ] = 0;
  21553. animation.lastFrame = animation.currentFrame;
  21554. animation.currentFrame = keyframe;
  21555. }
  21556. var mix = ( animation.time % frameTime ) / frameTime;
  21557. if ( animation.directionBackwards ) mix = 1 - mix;
  21558. if ( animation.currentFrame !== animation.lastFrame ) {
  21559. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  21560. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  21561. } else {
  21562. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  21563. }
  21564. }
  21565. };