three.js 794 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347213482134921350213512135221353213542135521356213572135821359213602136121362213632136421365213662136721368213692137021371213722137321374213752137621377213782137921380213812138221383213842138521386213872138821389213902139121392213932139421395213962139721398213992140021401214022140321404214052140621407214082140921410214112141221413214142141521416214172141821419214202142121422214232142421425214262142721428214292143021431214322143321434214352143621437214382143921440214412144221443214442144521446214472144821449214502145121452214532145421455214562145721458214592146021461214622146321464214652146621467214682146921470214712147221473214742147521476214772147821479214802148121482214832148421485214862148721488214892149021491214922149321494214952149621497214982149921500215012150221503215042150521506215072150821509215102151121512215132151421515215162151721518215192152021521215222152321524215252152621527215282152921530215312153221533215342153521536215372153821539215402154121542215432154421545215462154721548215492155021551215522155321554215552155621557215582155921560215612156221563215642156521566215672156821569215702157121572215732157421575215762157721578215792158021581215822158321584215852158621587215882158921590215912159221593215942159521596215972159821599216002160121602216032160421605216062160721608216092161021611216122161321614216152161621617216182161921620216212162221623216242162521626216272162821629216302163121632216332163421635216362163721638216392164021641216422164321644216452164621647216482164921650216512165221653216542165521656216572165821659216602166121662216632166421665216662166721668216692167021671216722167321674216752167621677216782167921680216812168221683216842168521686216872168821689216902169121692216932169421695216962169721698216992170021701217022170321704217052170621707217082170921710217112171221713217142171521716217172171821719217202172121722217232172421725217262172721728217292173021731217322173321734217352173621737217382173921740217412174221743217442174521746217472174821749217502175121752217532175421755217562175721758217592176021761217622176321764217652176621767217682176921770217712177221773217742177521776217772177821779217802178121782217832178421785217862178721788217892179021791217922179321794217952179621797217982179921800218012180221803218042180521806218072180821809218102181121812218132181421815218162181721818218192182021821218222182321824218252182621827218282182921830218312183221833218342183521836218372183821839218402184121842218432184421845218462184721848218492185021851218522185321854218552185621857218582185921860218612186221863218642186521866218672186821869218702187121872218732187421875218762187721878218792188021881218822188321884218852188621887218882188921890218912189221893218942189521896218972189821899219002190121902219032190421905219062190721908219092191021911219122191321914219152191621917219182191921920219212192221923219242192521926219272192821929219302193121932219332193421935219362193721938219392194021941219422194321944219452194621947219482194921950219512195221953219542195521956219572195821959219602196121962219632196421965219662196721968219692197021971219722197321974219752197621977219782197921980219812198221983219842198521986219872198821989219902199121992219932199421995219962199721998219992200022001220022200322004220052200622007220082200922010220112201222013220142201522016220172201822019220202202122022220232202422025220262202722028220292203022031220322203322034220352203622037220382203922040220412204222043220442204522046220472204822049220502205122052220532205422055220562205722058220592206022061220622206322064220652206622067220682206922070220712207222073220742207522076220772207822079220802208122082220832208422085220862208722088220892209022091220922209322094220952209622097220982209922100221012210222103221042210522106221072210822109221102211122112221132211422115221162211722118221192212022121221222212322124221252212622127221282212922130221312213222133221342213522136221372213822139221402214122142221432214422145221462214722148221492215022151221522215322154221552215622157221582215922160221612216222163221642216522166221672216822169221702217122172221732217422175221762217722178221792218022181221822218322184221852218622187221882218922190221912219222193221942219522196221972219822199222002220122202222032220422205222062220722208222092221022211222122221322214222152221622217222182221922220222212222222223222242222522226222272222822229222302223122232222332223422235222362223722238222392224022241222422224322244222452224622247222482224922250222512225222253222542225522256222572225822259222602226122262222632226422265222662226722268222692227022271222722227322274222752227622277222782227922280222812228222283222842228522286222872228822289222902229122292222932229422295222962229722298222992230022301223022230322304223052230622307223082230922310223112231222313223142231522316223172231822319223202232122322223232232422325223262232722328223292233022331223322233322334223352233622337223382233922340223412234222343223442234522346223472234822349223502235122352223532235422355223562235722358223592236022361223622236322364223652236622367223682236922370223712237222373223742237522376223772237822379223802238122382223832238422385223862238722388223892239022391223922239322394223952239622397223982239922400224012240222403224042240522406224072240822409224102241122412224132241422415224162241722418224192242022421224222242322424224252242622427224282242922430224312243222433224342243522436224372243822439224402244122442224432244422445224462244722448224492245022451224522245322454224552245622457224582245922460224612246222463224642246522466224672246822469224702247122472224732247422475224762247722478224792248022481224822248322484224852248622487224882248922490224912249222493224942249522496224972249822499225002250122502225032250422505225062250722508225092251022511225122251322514225152251622517225182251922520225212252222523225242252522526225272252822529225302253122532225332253422535225362253722538225392254022541225422254322544225452254622547225482254922550225512255222553225542255522556225572255822559225602256122562225632256422565225662256722568225692257022571225722257322574225752257622577225782257922580225812258222583225842258522586225872258822589225902259122592225932259422595225962259722598225992260022601226022260322604226052260622607226082260922610226112261222613226142261522616226172261822619226202262122622226232262422625226262262722628226292263022631226322263322634226352263622637226382263922640226412264222643226442264522646226472264822649226502265122652226532265422655226562265722658226592266022661226622266322664226652266622667226682266922670226712267222673226742267522676226772267822679226802268122682226832268422685226862268722688226892269022691226922269322694226952269622697226982269922700227012270222703227042270522706227072270822709227102271122712227132271422715227162271722718227192272022721227222272322724227252272622727227282272922730227312273222733227342273522736227372273822739227402274122742227432274422745227462274722748227492275022751227522275322754227552275622757227582275922760227612276222763227642276522766227672276822769227702277122772227732277422775227762277722778227792278022781227822278322784227852278622787227882278922790227912279222793227942279522796227972279822799228002280122802228032280422805228062280722808228092281022811228122281322814228152281622817228182281922820228212282222823228242282522826228272282822829228302283122832228332283422835228362283722838228392284022841228422284322844228452284622847228482284922850228512285222853228542285522856228572285822859228602286122862228632286422865228662286722868228692287022871228722287322874228752287622877228782287922880228812288222883228842288522886228872288822889228902289122892228932289422895228962289722898228992290022901229022290322904229052290622907229082290922910229112291222913229142291522916229172291822919229202292122922229232292422925229262292722928229292293022931229322293322934229352293622937229382293922940229412294222943229442294522946229472294822949229502295122952229532295422955229562295722958229592296022961229622296322964229652296622967229682296922970229712297222973229742297522976229772297822979229802298122982229832298422985229862298722988229892299022991229922299322994229952299622997229982299923000230012300223003230042300523006230072300823009230102301123012230132301423015230162301723018230192302023021230222302323024230252302623027230282302923030230312303223033230342303523036230372303823039230402304123042230432304423045230462304723048230492305023051230522305323054230552305623057230582305923060230612306223063230642306523066230672306823069230702307123072230732307423075230762307723078230792308023081230822308323084230852308623087230882308923090230912309223093230942309523096230972309823099231002310123102231032310423105231062310723108231092311023111231122311323114231152311623117231182311923120231212312223123231242312523126231272312823129231302313123132231332313423135231362313723138231392314023141231422314323144231452314623147231482314923150231512315223153231542315523156231572315823159231602316123162231632316423165231662316723168231692317023171231722317323174231752317623177231782317923180231812318223183231842318523186231872318823189231902319123192231932319423195231962319723198231992320023201232022320323204232052320623207232082320923210232112321223213232142321523216232172321823219232202322123222232232322423225232262322723228232292323023231232322323323234232352323623237232382323923240232412324223243232442324523246232472324823249232502325123252232532325423255232562325723258232592326023261232622326323264232652326623267232682326923270232712327223273232742327523276232772327823279232802328123282232832328423285232862328723288232892329023291232922329323294232952329623297232982329923300233012330223303233042330523306233072330823309233102331123312233132331423315233162331723318233192332023321233222332323324233252332623327233282332923330233312333223333233342333523336233372333823339233402334123342233432334423345233462334723348233492335023351233522335323354233552335623357233582335923360233612336223363233642336523366233672336823369233702337123372233732337423375233762337723378233792338023381233822338323384233852338623387233882338923390233912339223393233942339523396233972339823399234002340123402234032340423405234062340723408234092341023411234122341323414234152341623417234182341923420234212342223423234242342523426234272342823429234302343123432234332343423435234362343723438234392344023441234422344323444234452344623447234482344923450234512345223453234542345523456234572345823459234602346123462234632346423465234662346723468234692347023471234722347323474234752347623477234782347923480234812348223483234842348523486234872348823489234902349123492234932349423495234962349723498234992350023501235022350323504235052350623507235082350923510235112351223513235142351523516235172351823519235202352123522235232352423525235262352723528235292353023531235322353323534235352353623537235382353923540235412354223543235442354523546235472354823549235502355123552235532355423555235562355723558235592356023561235622356323564235652356623567235682356923570235712357223573235742357523576235772357823579235802358123582235832358423585235862358723588235892359023591235922359323594235952359623597235982359923600236012360223603236042360523606236072360823609236102361123612236132361423615236162361723618236192362023621236222362323624236252362623627236282362923630236312363223633236342363523636236372363823639236402364123642236432364423645236462364723648236492365023651236522365323654236552365623657236582365923660236612366223663236642366523666236672366823669236702367123672236732367423675236762367723678236792368023681236822368323684236852368623687236882368923690236912369223693236942369523696236972369823699237002370123702237032370423705237062370723708237092371023711237122371323714237152371623717237182371923720237212372223723237242372523726237272372823729237302373123732237332373423735237362373723738237392374023741237422374323744237452374623747237482374923750237512375223753237542375523756237572375823759237602376123762237632376423765237662376723768237692377023771237722377323774237752377623777237782377923780237812378223783237842378523786237872378823789237902379123792237932379423795237962379723798237992380023801238022380323804238052380623807238082380923810238112381223813238142381523816238172381823819238202382123822238232382423825238262382723828238292383023831238322383323834238352383623837238382383923840238412384223843238442384523846238472384823849238502385123852238532385423855238562385723858238592386023861238622386323864238652386623867238682386923870238712387223873238742387523876238772387823879238802388123882238832388423885238862388723888238892389023891238922389323894238952389623897238982389923900239012390223903239042390523906239072390823909239102391123912239132391423915239162391723918239192392023921239222392323924239252392623927239282392923930239312393223933239342393523936239372393823939239402394123942239432394423945239462394723948239492395023951239522395323954239552395623957239582395923960239612396223963239642396523966239672396823969239702397123972239732397423975239762397723978239792398023981239822398323984239852398623987239882398923990239912399223993239942399523996239972399823999240002400124002240032400424005240062400724008240092401024011240122401324014240152401624017240182401924020240212402224023240242402524026240272402824029240302403124032240332403424035240362403724038240392404024041240422404324044240452404624047240482404924050240512405224053240542405524056240572405824059240602406124062240632406424065240662406724068240692407024071240722407324074240752407624077240782407924080240812408224083240842408524086240872408824089240902409124092240932409424095240962409724098240992410024101241022410324104241052410624107241082410924110241112411224113241142411524116241172411824119241202412124122241232412424125241262412724128241292413024131241322413324134241352413624137241382413924140241412414224143241442414524146241472414824149241502415124152241532415424155241562415724158241592416024161241622416324164241652416624167241682416924170241712417224173241742417524176241772417824179241802418124182241832418424185241862418724188241892419024191241922419324194241952419624197241982419924200242012420224203242042420524206242072420824209242102421124212242132421424215242162421724218242192422024221242222422324224242252422624227242282422924230242312423224233242342423524236242372423824239242402424124242242432424424245242462424724248242492425024251242522425324254242552425624257242582425924260242612426224263242642426524266242672426824269242702427124272242732427424275242762427724278242792428024281242822428324284242852428624287242882428924290242912429224293242942429524296242972429824299243002430124302243032430424305243062430724308243092431024311243122431324314243152431624317243182431924320243212432224323243242432524326243272432824329243302433124332243332433424335243362433724338243392434024341243422434324344243452434624347243482434924350243512435224353243542435524356243572435824359243602436124362243632436424365243662436724368243692437024371243722437324374243752437624377243782437924380243812438224383243842438524386243872438824389243902439124392243932439424395243962439724398243992440024401244022440324404244052440624407244082440924410244112441224413244142441524416244172441824419244202442124422244232442424425244262442724428244292443024431244322443324434244352443624437244382443924440244412444224443244442444524446244472444824449244502445124452244532445424455244562445724458244592446024461244622446324464244652446624467244682446924470244712447224473244742447524476244772447824479244802448124482244832448424485244862448724488244892449024491244922449324494244952449624497244982449924500245012450224503245042450524506245072450824509245102451124512245132451424515245162451724518245192452024521245222452324524245252452624527245282452924530245312453224533245342453524536245372453824539245402454124542245432454424545245462454724548245492455024551245522455324554245552455624557245582455924560245612456224563245642456524566245672456824569245702457124572245732457424575245762457724578245792458024581245822458324584245852458624587245882458924590245912459224593245942459524596245972459824599246002460124602246032460424605246062460724608246092461024611246122461324614246152461624617246182461924620246212462224623246242462524626246272462824629246302463124632246332463424635246362463724638246392464024641246422464324644246452464624647246482464924650246512465224653246542465524656246572465824659246602466124662246632466424665246662466724668246692467024671246722467324674246752467624677246782467924680246812468224683246842468524686246872468824689246902469124692246932469424695246962469724698246992470024701247022470324704247052470624707247082470924710247112471224713247142471524716247172471824719247202472124722247232472424725247262472724728247292473024731247322473324734247352473624737247382473924740247412474224743247442474524746247472474824749247502475124752247532475424755247562475724758247592476024761247622476324764247652476624767247682476924770247712477224773247742477524776247772477824779247802478124782247832478424785247862478724788247892479024791247922479324794247952479624797247982479924800248012480224803248042480524806248072480824809248102481124812248132481424815248162481724818248192482024821248222482324824248252482624827248282482924830248312483224833248342483524836248372483824839248402484124842248432484424845248462484724848248492485024851248522485324854248552485624857248582485924860248612486224863248642486524866248672486824869248702487124872248732487424875248762487724878248792488024881248822488324884248852488624887248882488924890248912489224893248942489524896248972489824899249002490124902249032490424905249062490724908249092491024911249122491324914249152491624917249182491924920249212492224923249242492524926249272492824929249302493124932249332493424935249362493724938249392494024941249422494324944249452494624947249482494924950249512495224953249542495524956249572495824959249602496124962249632496424965249662496724968249692497024971249722497324974249752497624977249782497924980249812498224983249842498524986249872498824989249902499124992249932499424995249962499724998249992500025001250022500325004250052500625007250082500925010250112501225013250142501525016250172501825019250202502125022250232502425025250262502725028250292503025031250322503325034250352503625037250382503925040250412504225043250442504525046250472504825049250502505125052250532505425055250562505725058250592506025061250622506325064250652506625067250682506925070250712507225073250742507525076250772507825079250802508125082250832508425085250862508725088250892509025091250922509325094250952509625097250982509925100251012510225103251042510525106251072510825109251102511125112251132511425115251162511725118251192512025121251222512325124251252512625127251282512925130251312513225133251342513525136251372513825139251402514125142251432514425145251462514725148251492515025151251522515325154251552515625157251582515925160251612516225163251642516525166251672516825169251702517125172251732517425175251762517725178251792518025181251822518325184251852518625187251882518925190251912519225193251942519525196251972519825199252002520125202252032520425205252062520725208252092521025211252122521325214252152521625217252182521925220252212522225223252242522525226252272522825229252302523125232252332523425235252362523725238252392524025241252422524325244252452524625247252482524925250252512525225253252542525525256252572525825259252602526125262252632526425265252662526725268252692527025271252722527325274252752527625277252782527925280252812528225283252842528525286252872528825289252902529125292252932529425295252962529725298252992530025301253022530325304253052530625307253082530925310253112531225313253142531525316253172531825319253202532125322253232532425325253262532725328253292533025331253322533325334253352533625337253382533925340253412534225343253442534525346253472534825349253502535125352253532535425355253562535725358253592536025361253622536325364253652536625367253682536925370253712537225373253742537525376253772537825379253802538125382253832538425385253862538725388253892539025391253922539325394253952539625397253982539925400254012540225403254042540525406254072540825409254102541125412254132541425415254162541725418254192542025421254222542325424254252542625427254282542925430254312543225433254342543525436254372543825439254402544125442254432544425445254462544725448254492545025451254522545325454254552545625457254582545925460254612546225463254642546525466254672546825469254702547125472254732547425475254762547725478254792548025481254822548325484254852548625487254882548925490254912549225493254942549525496254972549825499255002550125502255032550425505255062550725508255092551025511255122551325514255152551625517255182551925520255212552225523255242552525526255272552825529255302553125532255332553425535255362553725538255392554025541255422554325544255452554625547255482554925550255512555225553255542555525556255572555825559255602556125562255632556425565255662556725568255692557025571255722557325574255752557625577255782557925580255812558225583255842558525586255872558825589255902559125592255932559425595255962559725598255992560025601256022560325604256052560625607256082560925610256112561225613256142561525616256172561825619256202562125622256232562425625256262562725628256292563025631256322563325634256352563625637256382563925640256412564225643256442564525646256472564825649256502565125652256532565425655256562565725658256592566025661256622566325664256652566625667256682566925670256712567225673256742567525676256772567825679256802568125682256832568425685256862568725688256892569025691256922569325694256952569625697256982569925700257012570225703257042570525706257072570825709257102571125712257132571425715257162571725718257192572025721257222572325724257252572625727257282572925730257312573225733257342573525736257372573825739257402574125742257432574425745257462574725748257492575025751257522575325754257552575625757257582575925760257612576225763257642576525766257672576825769257702577125772257732577425775257762577725778257792578025781257822578325784257852578625787257882578925790257912579225793257942579525796257972579825799258002580125802258032580425805258062580725808258092581025811258122581325814258152581625817258182581925820258212582225823258242582525826258272582825829258302583125832258332583425835258362583725838258392584025841258422584325844258452584625847258482584925850258512585225853258542585525856258572585825859258602586125862258632586425865258662586725868258692587025871258722587325874258752587625877258782587925880258812588225883258842588525886258872588825889258902589125892258932589425895258962589725898258992590025901259022590325904259052590625907259082590925910259112591225913259142591525916259172591825919259202592125922259232592425925259262592725928259292593025931259322593325934259352593625937259382593925940259412594225943259442594525946259472594825949259502595125952259532595425955259562595725958259592596025961259622596325964259652596625967259682596925970259712597225973259742597525976259772597825979259802598125982259832598425985259862598725988259892599025991259922599325994259952599625997259982599926000260012600226003260042600526006260072600826009260102601126012260132601426015260162601726018260192602026021260222602326024260252602626027260282602926030260312603226033260342603526036260372603826039260402604126042260432604426045260462604726048260492605026051260522605326054260552605626057260582605926060260612606226063260642606526066260672606826069260702607126072260732607426075260762607726078260792608026081260822608326084260852608626087260882608926090260912609226093260942609526096260972609826099261002610126102261032610426105261062610726108261092611026111261122611326114261152611626117261182611926120261212612226123261242612526126261272612826129261302613126132261332613426135261362613726138261392614026141261422614326144261452614626147261482614926150261512615226153261542615526156261572615826159261602616126162261632616426165261662616726168261692617026171261722617326174261752617626177261782617926180261812618226183261842618526186261872618826189261902619126192261932619426195261962619726198261992620026201262022620326204262052620626207262082620926210262112621226213262142621526216262172621826219262202622126222262232622426225262262622726228262292623026231262322623326234262352623626237262382623926240262412624226243262442624526246262472624826249262502625126252262532625426255262562625726258262592626026261262622626326264262652626626267262682626926270262712627226273262742627526276262772627826279262802628126282262832628426285262862628726288262892629026291262922629326294262952629626297262982629926300263012630226303263042630526306263072630826309263102631126312263132631426315263162631726318263192632026321263222632326324263252632626327263282632926330263312633226333263342633526336263372633826339263402634126342263432634426345263462634726348263492635026351263522635326354263552635626357263582635926360263612636226363263642636526366263672636826369263702637126372263732637426375263762637726378263792638026381263822638326384263852638626387263882638926390263912639226393263942639526396263972639826399264002640126402264032640426405264062640726408264092641026411264122641326414264152641626417264182641926420264212642226423264242642526426264272642826429264302643126432264332643426435264362643726438264392644026441264422644326444264452644626447264482644926450264512645226453264542645526456264572645826459264602646126462264632646426465264662646726468264692647026471264722647326474264752647626477264782647926480264812648226483264842648526486264872648826489264902649126492264932649426495264962649726498264992650026501265022650326504265052650626507265082650926510265112651226513265142651526516265172651826519265202652126522265232652426525265262652726528265292653026531265322653326534265352653626537265382653926540265412654226543265442654526546265472654826549265502655126552265532655426555265562655726558265592656026561265622656326564265652656626567265682656926570265712657226573265742657526576265772657826579265802658126582265832658426585265862658726588265892659026591265922659326594265952659626597265982659926600266012660226603266042660526606266072660826609266102661126612266132661426615266162661726618266192662026621266222662326624266252662626627266282662926630266312663226633266342663526636266372663826639266402664126642266432664426645266462664726648266492665026651266522665326654266552665626657266582665926660266612666226663266642666526666266672666826669266702667126672266732667426675266762667726678266792668026681266822668326684266852668626687266882668926690266912669226693266942669526696266972669826699267002670126702267032670426705267062670726708267092671026711267122671326714267152671626717267182671926720267212672226723267242672526726267272672826729267302673126732267332673426735267362673726738267392674026741267422674326744267452674626747267482674926750267512675226753267542675526756267572675826759267602676126762267632676426765267662676726768267692677026771267722677326774267752677626777267782677926780267812678226783267842678526786267872678826789267902679126792267932679426795267962679726798267992680026801268022680326804268052680626807268082680926810268112681226813268142681526816268172681826819268202682126822268232682426825268262682726828268292683026831268322683326834268352683626837268382683926840268412684226843268442684526846268472684826849268502685126852268532685426855268562685726858268592686026861268622686326864268652686626867268682686926870268712687226873268742687526876268772687826879268802688126882268832688426885268862688726888268892689026891268922689326894268952689626897268982689926900269012690226903269042690526906269072690826909269102691126912269132691426915269162691726918269192692026921269222692326924269252692626927269282692926930269312693226933269342693526936269372693826939269402694126942269432694426945269462694726948269492695026951269522695326954269552695626957269582695926960269612696226963269642696526966269672696826969269702697126972269732697426975269762697726978269792698026981269822698326984269852698626987269882698926990269912699226993269942699526996269972699826999270002700127002270032700427005270062700727008270092701027011270122701327014270152701627017270182701927020270212702227023270242702527026270272702827029270302703127032270332703427035270362703727038270392704027041270422704327044270452704627047270482704927050270512705227053270542705527056270572705827059270602706127062270632706427065270662706727068270692707027071270722707327074270752707627077270782707927080270812708227083270842708527086270872708827089270902709127092270932709427095270962709727098270992710027101271022710327104271052710627107271082710927110271112711227113271142711527116271172711827119271202712127122271232712427125271262712727128271292713027131271322713327134271352713627137271382713927140271412714227143271442714527146271472714827149271502715127152271532715427155271562715727158271592716027161271622716327164271652716627167271682716927170271712717227173271742717527176271772717827179271802718127182271832718427185271862718727188271892719027191271922719327194271952719627197271982719927200272012720227203272042720527206272072720827209272102721127212272132721427215272162721727218272192722027221272222722327224272252722627227272282722927230272312723227233272342723527236272372723827239272402724127242272432724427245272462724727248272492725027251272522725327254272552725627257272582725927260272612726227263272642726527266272672726827269272702727127272272732727427275272762727727278272792728027281272822728327284272852728627287272882728927290272912729227293272942729527296272972729827299273002730127302273032730427305273062730727308273092731027311273122731327314273152731627317273182731927320273212732227323273242732527326273272732827329273302733127332273332733427335273362733727338273392734027341273422734327344273452734627347273482734927350273512735227353273542735527356273572735827359273602736127362273632736427365273662736727368273692737027371273722737327374273752737627377273782737927380273812738227383273842738527386273872738827389273902739127392273932739427395273962739727398273992740027401274022740327404274052740627407274082740927410274112741227413274142741527416274172741827419274202742127422274232742427425274262742727428274292743027431274322743327434274352743627437274382743927440274412744227443274442744527446274472744827449274502745127452274532745427455274562745727458274592746027461274622746327464274652746627467274682746927470274712747227473274742747527476274772747827479274802748127482274832748427485274862748727488274892749027491274922749327494274952749627497274982749927500275012750227503275042750527506275072750827509275102751127512275132751427515275162751727518275192752027521275222752327524275252752627527275282752927530275312753227533275342753527536275372753827539275402754127542275432754427545275462754727548275492755027551275522755327554275552755627557275582755927560275612756227563275642756527566275672756827569275702757127572275732757427575275762757727578275792758027581275822758327584275852758627587275882758927590275912759227593275942759527596275972759827599276002760127602276032760427605276062760727608276092761027611276122761327614276152761627617276182761927620276212762227623276242762527626276272762827629276302763127632276332763427635276362763727638276392764027641276422764327644276452764627647276482764927650276512765227653276542765527656276572765827659276602766127662276632766427665276662766727668276692767027671276722767327674276752767627677276782767927680276812768227683276842768527686276872768827689276902769127692276932769427695276962769727698276992770027701277022770327704277052770627707277082770927710277112771227713277142771527716277172771827719277202772127722277232772427725277262772727728277292773027731277322773327734277352773627737277382773927740277412774227743277442774527746277472774827749277502775127752277532775427755277562775727758277592776027761277622776327764277652776627767277682776927770277712777227773277742777527776277772777827779277802778127782277832778427785277862778727788277892779027791277922779327794277952779627797277982779927800278012780227803278042780527806278072780827809278102781127812278132781427815278162781727818278192782027821278222782327824278252782627827278282782927830278312783227833278342783527836278372783827839278402784127842278432784427845278462784727848278492785027851278522785327854278552785627857278582785927860278612786227863278642786527866278672786827869278702787127872278732787427875278762787727878278792788027881278822788327884278852788627887278882788927890278912789227893278942789527896278972789827899279002790127902279032790427905279062790727908279092791027911279122791327914279152791627917279182791927920279212792227923279242792527926279272792827929279302793127932279332793427935279362793727938279392794027941279422794327944279452794627947279482794927950279512795227953279542795527956279572795827959279602796127962279632796427965279662796727968279692797027971279722797327974279752797627977279782797927980279812798227983279842798527986279872798827989279902799127992279932799427995279962799727998279992800028001280022800328004280052800628007280082800928010280112801228013280142801528016280172801828019280202802128022280232802428025280262802728028280292803028031280322803328034280352803628037280382803928040280412804228043280442804528046280472804828049280502805128052280532805428055280562805728058280592806028061280622806328064280652806628067280682806928070280712807228073280742807528076280772807828079280802808128082280832808428085280862808728088280892809028091280922809328094280952809628097280982809928100281012810228103281042810528106281072810828109281102811128112281132811428115281162811728118281192812028121281222812328124281252812628127281282812928130281312813228133281342813528136281372813828139281402814128142281432814428145281462814728148281492815028151281522815328154281552815628157281582815928160281612816228163281642816528166281672816828169281702817128172281732817428175281762817728178281792818028181281822818328184281852818628187281882818928190281912819228193281942819528196281972819828199282002820128202282032820428205282062820728208282092821028211282122821328214282152821628217282182821928220282212822228223282242822528226282272822828229282302823128232282332823428235282362823728238282392824028241282422824328244282452824628247282482824928250282512825228253282542825528256282572825828259282602826128262282632826428265282662826728268282692827028271282722827328274282752827628277282782827928280282812828228283282842828528286282872828828289282902829128292282932829428295282962829728298282992830028301283022830328304283052830628307283082830928310283112831228313283142831528316283172831828319283202832128322283232832428325283262832728328283292833028331283322833328334283352833628337283382833928340283412834228343283442834528346283472834828349283502835128352283532835428355283562835728358283592836028361283622836328364283652836628367283682836928370283712837228373283742837528376283772837828379283802838128382283832838428385283862838728388283892839028391283922839328394283952839628397283982839928400284012840228403284042840528406284072840828409284102841128412284132841428415284162841728418284192842028421284222842328424284252842628427284282842928430284312843228433284342843528436284372843828439284402844128442284432844428445284462844728448284492845028451284522845328454284552845628457284582845928460284612846228463284642846528466284672846828469284702847128472284732847428475284762847728478284792848028481284822848328484284852848628487284882848928490284912849228493284942849528496284972849828499285002850128502285032850428505285062850728508285092851028511285122851328514285152851628517285182851928520285212852228523285242852528526285272852828529285302853128532285332853428535285362853728538285392854028541285422854328544285452854628547285482854928550285512855228553285542855528556285572855828559285602856128562285632856428565285662856728568285692857028571285722857328574285752857628577285782857928580285812858228583285842858528586285872858828589285902859128592285932859428595285962859728598285992860028601286022860328604286052860628607286082860928610286112861228613286142861528616286172861828619286202862128622286232862428625286262862728628286292863028631286322863328634286352863628637286382863928640286412864228643286442864528646286472864828649286502865128652286532865428655286562865728658286592866028661286622866328664286652866628667286682866928670286712867228673286742867528676286772867828679286802868128682286832868428685286862868728688286892869028691286922869328694286952869628697286982869928700287012870228703287042870528706287072870828709287102871128712287132871428715287162871728718287192872028721287222872328724287252872628727287282872928730287312873228733287342873528736287372873828739287402874128742287432874428745287462874728748287492875028751287522875328754287552875628757287582875928760287612876228763287642876528766287672876828769287702877128772287732877428775287762877728778287792878028781287822878328784287852878628787287882878928790287912879228793287942879528796287972879828799288002880128802288032880428805288062880728808288092881028811288122881328814288152881628817288182881928820288212882228823288242882528826288272882828829288302883128832288332883428835288362883728838288392884028841288422884328844288452884628847288482884928850288512885228853288542885528856288572885828859288602886128862288632886428865288662886728868288692887028871288722887328874288752887628877288782887928880288812888228883288842888528886288872888828889288902889128892288932889428895288962889728898288992890028901289022890328904289052890628907289082890928910289112891228913289142891528916289172891828919289202892128922289232892428925289262892728928289292893028931289322893328934289352893628937289382893928940289412894228943289442894528946289472894828949289502895128952289532895428955289562895728958289592896028961289622896328964289652896628967289682896928970289712897228973289742897528976289772897828979289802898128982289832898428985289862898728988289892899028991289922899328994289952899628997289982899929000290012900229003290042900529006290072900829009290102901129012290132901429015290162901729018290192902029021290222902329024290252902629027290282902929030290312903229033290342903529036290372903829039290402904129042290432904429045290462904729048290492905029051290522905329054290552905629057290582905929060290612906229063290642906529066290672906829069290702907129072290732907429075290762907729078290792908029081290822908329084290852908629087290882908929090290912909229093290942909529096290972909829099291002910129102291032910429105291062910729108291092911029111291122911329114291152911629117291182911929120291212912229123291242912529126291272912829129291302913129132291332913429135291362913729138291392914029141291422914329144291452914629147291482914929150291512915229153291542915529156291572915829159291602916129162291632916429165291662916729168291692917029171291722917329174291752917629177291782917929180291812918229183291842918529186291872918829189291902919129192291932919429195291962919729198291992920029201292022920329204292052920629207292082920929210292112921229213292142921529216292172921829219292202922129222292232922429225292262922729228292292923029231292322923329234292352923629237292382923929240292412924229243292442924529246292472924829249292502925129252292532925429255292562925729258292592926029261292622926329264292652926629267292682926929270292712927229273292742927529276292772927829279292802928129282292832928429285292862928729288292892929029291292922929329294292952929629297292982929929300293012930229303293042930529306293072930829309293102931129312293132931429315293162931729318293192932029321293222932329324293252932629327293282932929330293312933229333293342933529336293372933829339293402934129342293432934429345293462934729348293492935029351293522935329354293552935629357293582935929360293612936229363293642936529366293672936829369293702937129372293732937429375293762937729378293792938029381293822938329384293852938629387293882938929390293912939229393293942939529396293972939829399294002940129402294032940429405294062940729408294092941029411294122941329414294152941629417294182941929420294212942229423294242942529426294272942829429294302943129432294332943429435294362943729438294392944029441294422944329444294452944629447294482944929450294512945229453294542945529456294572945829459294602946129462294632946429465294662946729468294692947029471294722947329474294752947629477294782947929480294812948229483294842948529486294872948829489294902949129492294932949429495294962949729498294992950029501295022950329504295052950629507295082950929510295112951229513295142951529516295172951829519295202952129522295232952429525295262952729528295292953029531295322953329534295352953629537295382953929540295412954229543295442954529546295472954829549295502955129552295532955429555295562955729558295592956029561295622956329564295652956629567295682956929570295712957229573295742957529576295772957829579295802958129582295832958429585295862958729588295892959029591295922959329594295952959629597295982959929600296012960229603296042960529606296072960829609296102961129612296132961429615296162961729618296192962029621296222962329624296252962629627296282962929630296312963229633296342963529636296372963829639296402964129642296432964429645296462964729648296492965029651296522965329654296552965629657296582965929660296612966229663296642966529666296672966829669296702967129672296732967429675296762967729678296792968029681296822968329684296852968629687296882968929690296912969229693296942969529696296972969829699297002970129702297032970429705297062970729708297092971029711297122971329714297152971629717297182971929720297212972229723297242972529726297272972829729297302973129732297332973429735297362973729738297392974029741297422974329744297452974629747297482974929750297512975229753297542975529756297572975829759297602976129762297632976429765297662976729768297692977029771297722977329774297752977629777297782977929780297812978229783297842978529786297872978829789297902979129792297932979429795297962979729798297992980029801298022980329804298052980629807298082980929810298112981229813298142981529816298172981829819298202982129822298232982429825298262982729828298292983029831298322983329834298352983629837298382983929840298412984229843298442984529846298472984829849298502985129852298532985429855298562985729858298592986029861298622986329864298652986629867298682986929870298712987229873298742987529876298772987829879298802988129882298832988429885298862988729888298892989029891298922989329894298952989629897298982989929900299012990229903299042990529906299072990829909299102991129912299132991429915299162991729918299192992029921299222992329924299252992629927299282992929930299312993229933299342993529936299372993829939299402994129942299432994429945299462994729948299492995029951299522995329954299552995629957299582995929960299612996229963299642996529966299672996829969299702997129972299732997429975299762997729978299792998029981299822998329984299852998629987299882998929990299912999229993299942999529996299972999829999300003000130002300033000430005300063000730008300093001030011300123001330014300153001630017300183001930020300213002230023300243002530026300273002830029300303003130032300333003430035300363003730038300393004030041300423004330044300453004630047300483004930050300513005230053300543005530056300573005830059300603006130062300633006430065300663006730068300693007030071300723007330074300753007630077300783007930080300813008230083300843008530086300873008830089300903009130092300933009430095300963009730098300993010030101301023010330104301053010630107301083010930110301113011230113301143011530116301173011830119301203012130122301233012430125301263012730128301293013030131301323013330134301353013630137301383013930140301413014230143301443014530146301473014830149301503015130152301533015430155301563015730158301593016030161301623016330164301653016630167301683016930170301713017230173301743017530176301773017830179301803018130182301833018430185301863018730188301893019030191301923019330194301953019630197301983019930200302013020230203302043020530206302073020830209302103021130212302133021430215302163021730218302193022030221302223022330224302253022630227302283022930230302313023230233302343023530236302373023830239302403024130242302433024430245302463024730248302493025030251302523025330254302553025630257302583025930260302613026230263302643026530266302673026830269302703027130272302733027430275302763027730278302793028030281302823028330284302853028630287302883028930290302913029230293302943029530296302973029830299303003030130302303033030430305303063030730308303093031030311303123031330314303153031630317303183031930320303213032230323303243032530326303273032830329303303033130332303333033430335303363033730338303393034030341303423034330344303453034630347303483034930350303513035230353303543035530356303573035830359303603036130362303633036430365303663036730368303693037030371303723037330374303753037630377303783037930380303813038230383303843038530386303873038830389303903039130392303933039430395303963039730398303993040030401304023040330404304053040630407304083040930410304113041230413304143041530416304173041830419304203042130422304233042430425304263042730428304293043030431304323043330434304353043630437304383043930440304413044230443304443044530446304473044830449304503045130452304533045430455304563045730458304593046030461304623046330464304653046630467304683046930470304713047230473304743047530476304773047830479304803048130482304833048430485304863048730488304893049030491304923049330494304953049630497304983049930500305013050230503305043050530506305073050830509305103051130512305133051430515305163051730518305193052030521305223052330524305253052630527305283052930530305313053230533305343053530536305373053830539305403054130542305433054430545305463054730548305493055030551305523055330554305553055630557305583055930560305613056230563305643056530566305673056830569305703057130572305733057430575305763057730578305793058030581305823058330584305853058630587305883058930590305913059230593305943059530596305973059830599306003060130602306033060430605306063060730608306093061030611306123061330614306153061630617306183061930620306213062230623306243062530626306273062830629306303063130632306333063430635306363063730638306393064030641306423064330644306453064630647306483064930650306513065230653306543065530656306573065830659306603066130662306633066430665306663066730668306693067030671306723067330674306753067630677306783067930680306813068230683306843068530686306873068830689306903069130692306933069430695306963069730698306993070030701307023070330704307053070630707307083070930710307113071230713307143071530716307173071830719307203072130722307233072430725307263072730728307293073030731307323073330734307353073630737307383073930740307413074230743307443074530746307473074830749307503075130752307533075430755307563075730758307593076030761307623076330764307653076630767307683076930770307713077230773307743077530776307773077830779307803078130782307833078430785307863078730788307893079030791307923079330794307953079630797307983079930800308013080230803308043080530806308073080830809308103081130812308133081430815308163081730818308193082030821308223082330824308253082630827308283082930830308313083230833308343083530836308373083830839308403084130842308433084430845308463084730848308493085030851308523085330854308553085630857308583085930860308613086230863308643086530866308673086830869308703087130872308733087430875308763087730878308793088030881308823088330884308853088630887308883088930890308913089230893308943089530896308973089830899309003090130902309033090430905309063090730908309093091030911309123091330914309153091630917309183091930920309213092230923309243092530926309273092830929309303093130932309333093430935309363093730938309393094030941309423094330944309453094630947309483094930950309513095230953309543095530956309573095830959309603096130962309633096430965309663096730968309693097030971309723097330974309753097630977309783097930980309813098230983309843098530986309873098830989309903099130992309933099430995309963099730998309993100031001310023100331004310053100631007310083100931010310113101231013310143101531016310173101831019310203102131022310233102431025310263102731028310293103031031310323103331034310353103631037310383103931040310413104231043310443104531046310473104831049310503105131052310533105431055310563105731058310593106031061310623106331064310653106631067310683106931070310713107231073310743107531076310773107831079310803108131082310833108431085310863108731088310893109031091310923109331094310953109631097310983109931100311013110231103311043110531106311073110831109311103111131112311133111431115311163111731118311193112031121311223112331124311253112631127311283112931130311313113231133311343113531136311373113831139311403114131142311433114431145311463114731148311493115031151311523115331154311553115631157311583115931160311613116231163311643116531166311673116831169311703117131172311733117431175311763117731178311793118031181311823118331184311853118631187311883118931190311913119231193311943119531196311973119831199312003120131202312033120431205312063120731208312093121031211312123121331214312153121631217312183121931220312213122231223312243122531226312273122831229312303123131232312333123431235312363123731238312393124031241312423124331244312453124631247312483124931250312513125231253312543125531256312573125831259312603126131262312633126431265312663126731268312693127031271312723127331274312753127631277312783127931280312813128231283312843128531286312873128831289312903129131292312933129431295312963129731298312993130031301313023130331304313053130631307313083130931310313113131231313313143131531316313173131831319313203132131322313233132431325313263132731328313293133031331313323133331334313353133631337313383133931340313413134231343313443134531346313473134831349313503135131352313533135431355313563135731358313593136031361313623136331364313653136631367313683136931370313713137231373313743137531376313773137831379313803138131382313833138431385313863138731388313893139031391313923139331394313953139631397313983139931400314013140231403314043140531406314073140831409314103141131412314133141431415314163141731418314193142031421314223142331424314253142631427314283142931430314313143231433314343143531436314373143831439314403144131442314433144431445314463144731448314493145031451314523145331454314553145631457314583145931460314613146231463314643146531466314673146831469314703147131472314733147431475314763147731478314793148031481314823148331484314853148631487314883148931490314913149231493314943149531496314973149831499315003150131502315033150431505315063150731508315093151031511315123151331514315153151631517315183151931520315213152231523315243152531526315273152831529315303153131532315333153431535315363153731538315393154031541315423154331544315453154631547315483154931550315513155231553315543155531556315573155831559315603156131562315633156431565315663156731568315693157031571315723157331574315753157631577315783157931580315813158231583315843158531586315873158831589315903159131592315933159431595315963159731598315993160031601316023160331604316053160631607316083160931610316113161231613316143161531616316173161831619316203162131622316233162431625316263162731628316293163031631316323163331634316353163631637316383163931640316413164231643316443164531646316473164831649316503165131652316533165431655316563165731658316593166031661316623166331664316653166631667316683166931670316713167231673316743167531676316773167831679316803168131682316833168431685316863168731688316893169031691316923169331694316953169631697316983169931700317013170231703317043170531706317073170831709317103171131712317133171431715317163171731718317193172031721317223172331724317253172631727317283172931730317313173231733317343173531736317373173831739317403174131742317433174431745317463174731748317493175031751317523175331754317553175631757317583175931760317613176231763317643176531766317673176831769317703177131772317733177431775317763177731778317793178031781317823178331784317853178631787317883178931790317913179231793317943179531796317973179831799318003180131802318033180431805318063180731808318093181031811318123181331814318153181631817318183181931820318213182231823318243182531826318273182831829318303183131832318333183431835318363183731838318393184031841318423184331844318453184631847318483184931850318513185231853318543185531856318573185831859318603186131862318633186431865318663186731868318693187031871318723187331874318753187631877318783187931880318813188231883318843188531886318873188831889318903189131892318933189431895318963189731898318993190031901319023190331904319053190631907319083190931910319113191231913319143191531916319173191831919319203192131922319233192431925319263192731928319293193031931319323193331934319353193631937319383193931940319413194231943319443194531946319473194831949319503195131952319533195431955319563195731958319593196031961319623196331964319653196631967319683196931970319713197231973319743197531976319773197831979319803198131982319833198431985319863198731988319893199031991319923199331994319953199631997319983199932000320013200232003320043200532006320073200832009320103201132012320133201432015320163201732018320193202032021320223202332024320253202632027320283202932030320313203232033320343203532036320373203832039320403204132042320433204432045320463204732048320493205032051320523205332054320553205632057320583205932060320613206232063320643206532066320673206832069320703207132072320733207432075320763207732078320793208032081320823208332084320853208632087320883208932090320913209232093320943209532096320973209832099321003210132102321033210432105321063210732108321093211032111321123211332114321153211632117321183211932120321213212232123321243212532126321273212832129321303213132132321333213432135321363213732138321393214032141321423214332144321453214632147321483214932150321513215232153321543215532156321573215832159321603216132162321633216432165321663216732168321693217032171321723217332174321753217632177321783217932180321813218232183321843218532186321873218832189321903219132192321933219432195321963219732198321993220032201322023220332204322053220632207322083220932210322113221232213322143221532216322173221832219322203222132222322233222432225322263222732228322293223032231322323223332234322353223632237322383223932240322413224232243322443224532246322473224832249322503225132252322533225432255322563225732258322593226032261322623226332264322653226632267322683226932270322713227232273322743227532276322773227832279322803228132282322833228432285322863228732288322893229032291322923229332294322953229632297322983229932300323013230232303323043230532306323073230832309323103231132312323133231432315323163231732318323193232032321323223232332324323253232632327323283232932330323313233232333323343233532336323373233832339323403234132342323433234432345323463234732348323493235032351323523235332354323553235632357323583235932360323613236232363323643236532366323673236832369323703237132372323733237432375323763237732378323793238032381323823238332384323853238632387323883238932390323913239232393323943239532396323973239832399324003240132402324033240432405324063240732408324093241032411324123241332414324153241632417324183241932420324213242232423324243242532426324273242832429324303243132432324333243432435324363243732438324393244032441324423244332444324453244632447324483244932450324513245232453324543245532456324573245832459324603246132462324633246432465324663246732468324693247032471324723247332474324753247632477324783247932480324813248232483324843248532486324873248832489324903249132492324933249432495324963249732498324993250032501325023250332504325053250632507325083250932510325113251232513325143251532516325173251832519325203252132522325233252432525325263252732528325293253032531325323253332534325353253632537325383253932540325413254232543325443254532546325473254832549325503255132552325533255432555325563255732558325593256032561325623256332564325653256632567325683256932570325713257232573325743257532576325773257832579325803258132582325833258432585325863258732588325893259032591325923259332594325953259632597325983259932600326013260232603326043260532606326073260832609326103261132612326133261432615326163261732618326193262032621326223262332624326253262632627326283262932630326313263232633326343263532636326373263832639326403264132642326433264432645326463264732648326493265032651326523265332654326553265632657326583265932660326613266232663326643266532666326673266832669326703267132672326733267432675326763267732678326793268032681326823268332684326853268632687326883268932690326913269232693326943269532696326973269832699327003270132702327033270432705327063270732708327093271032711327123271332714327153271632717327183271932720327213272232723327243272532726327273272832729327303273132732327333273432735327363273732738327393274032741327423274332744327453274632747327483274932750327513275232753327543275532756327573275832759327603276132762327633276432765327663276732768327693277032771327723277332774327753277632777327783277932780327813278232783327843278532786327873278832789327903279132792327933279432795327963279732798327993280032801328023280332804328053280632807328083280932810328113281232813328143281532816328173281832819328203282132822328233282432825328263282732828328293283032831328323283332834328353283632837328383283932840328413284232843328443284532846328473284832849328503285132852328533285432855328563285732858328593286032861328623286332864328653286632867328683286932870328713287232873328743287532876328773287832879328803288132882328833288432885328863288732888328893289032891328923289332894328953289632897328983289932900329013290232903329043290532906329073290832909329103291132912329133291432915329163291732918329193292032921329223292332924329253292632927329283292932930329313293232933329343293532936329373293832939329403294132942329433294432945329463294732948329493295032951329523295332954329553295632957329583295932960329613296232963329643296532966329673296832969329703297132972329733297432975329763297732978329793298032981329823298332984329853298632987329883298932990329913299232993329943299532996329973299832999330003300133002330033300433005330063300733008330093301033011330123301333014330153301633017330183301933020330213302233023330243302533026330273302833029330303303133032330333303433035330363303733038330393304033041330423304333044330453304633047330483304933050330513305233053330543305533056330573305833059330603306133062330633306433065330663306733068330693307033071330723307333074330753307633077330783307933080330813308233083330843308533086330873308833089330903309133092330933309433095330963309733098330993310033101331023310333104331053310633107331083310933110331113311233113331143311533116331173311833119331203312133122331233312433125331263312733128331293313033131331323313333134331353313633137331383313933140331413314233143331443314533146331473314833149331503315133152331533315433155331563315733158331593316033161331623316333164331653316633167331683316933170331713317233173331743317533176331773317833179331803318133182331833318433185331863318733188331893319033191331923319333194331953319633197331983319933200332013320233203332043320533206332073320833209332103321133212332133321433215332163321733218332193322033221332223322333224332253322633227332283322933230332313323233233332343323533236332373323833239332403324133242332433324433245332463324733248332493325033251332523325333254332553325633257332583325933260332613326233263332643326533266332673326833269332703327133272332733327433275332763327733278332793328033281332823328333284332853328633287332883328933290332913329233293332943329533296332973329833299333003330133302333033330433305333063330733308333093331033311333123331333314333153331633317333183331933320333213332233323333243332533326333273332833329333303333133332333333333433335333363333733338333393334033341333423334333344333453334633347333483334933350333513335233353333543335533356333573335833359333603336133362333633336433365333663336733368333693337033371333723337333374333753337633377333783337933380333813338233383333843338533386333873338833389333903339133392333933339433395333963339733398333993340033401334023340333404334053340633407334083340933410334113341233413334143341533416334173341833419334203342133422334233342433425334263342733428334293343033431334323343333434334353343633437334383343933440334413344233443334443344533446334473344833449334503345133452334533345433455334563345733458334593346033461334623346333464334653346633467334683346933470334713347233473334743347533476334773347833479334803348133482334833348433485334863348733488334893349033491334923349333494334953349633497334983349933500335013350233503335043350533506335073350833509335103351133512335133351433515335163351733518335193352033521335223352333524335253352633527335283352933530335313353233533335343353533536335373353833539335403354133542335433354433545335463354733548335493355033551335523355333554335553355633557335583355933560335613356233563335643356533566335673356833569335703357133572335733357433575335763357733578335793358033581335823358333584335853358633587335883358933590335913359233593335943359533596335973359833599336003360133602336033360433605336063360733608336093361033611336123361333614336153361633617336183361933620336213362233623336243362533626336273362833629336303363133632336333363433635336363363733638336393364033641336423364333644336453364633647336483364933650336513365233653336543365533656336573365833659336603366133662336633366433665336663366733668336693367033671336723367333674336753367633677336783367933680336813368233683336843368533686336873368833689336903369133692336933369433695336963369733698336993370033701337023370333704337053370633707337083370933710337113371233713337143371533716337173371833719337203372133722337233372433725337263372733728337293373033731337323373333734337353373633737337383373933740337413374233743337443374533746337473374833749337503375133752337533375433755337563375733758337593376033761337623376333764337653376633767337683376933770337713377233773337743377533776337773377833779337803378133782337833378433785337863378733788337893379033791337923379333794337953379633797337983379933800338013380233803338043380533806338073380833809338103381133812338133381433815338163381733818338193382033821338223382333824338253382633827338283382933830338313383233833338343383533836338373383833839338403384133842338433384433845338463384733848338493385033851338523385333854338553385633857338583385933860338613386233863338643386533866338673386833869338703387133872338733387433875338763387733878338793388033881338823388333884338853388633887338883388933890338913389233893338943389533896338973389833899339003390133902339033390433905339063390733908339093391033911339123391333914339153391633917339183391933920339213392233923339243392533926339273392833929339303393133932339333393433935339363393733938339393394033941339423394333944339453394633947339483394933950339513395233953339543395533956339573395833959339603396133962339633396433965339663396733968339693397033971339723397333974339753397633977339783397933980339813398233983339843398533986339873398833989339903399133992339933399433995339963399733998339993400034001340023400334004340053400634007340083400934010340113401234013340143401534016340173401834019340203402134022340233402434025340263402734028340293403034031340323403334034340353403634037340383403934040340413404234043340443404534046340473404834049340503405134052340533405434055340563405734058340593406034061340623406334064340653406634067340683406934070340713407234073340743407534076340773407834079340803408134082340833408434085340863408734088340893409034091340923409334094340953409634097340983409934100341013410234103341043410534106341073410834109341103411134112341133411434115341163411734118341193412034121341223412334124341253412634127341283412934130341313413234133341343413534136341373413834139341403414134142341433414434145341463414734148341493415034151341523415334154341553415634157341583415934160341613416234163341643416534166341673416834169341703417134172341733417434175341763417734178341793418034181341823418334184341853418634187341883418934190341913419234193341943419534196341973419834199342003420134202342033420434205342063420734208342093421034211342123421334214342153421634217342183421934220342213422234223342243422534226342273422834229342303423134232342333423434235342363423734238342393424034241342423424334244342453424634247342483424934250342513425234253342543425534256342573425834259342603426134262342633426434265342663426734268342693427034271342723427334274342753427634277342783427934280342813428234283342843428534286342873428834289342903429134292342933429434295342963429734298342993430034301343023430334304343053430634307343083430934310343113431234313343143431534316343173431834319343203432134322343233432434325343263432734328343293433034331343323433334334343353433634337343383433934340343413434234343343443434534346343473434834349343503435134352343533435434355343563435734358343593436034361343623436334364343653436634367343683436934370343713437234373343743437534376343773437834379343803438134382343833438434385343863438734388343893439034391343923439334394343953439634397343983439934400344013440234403344043440534406344073440834409344103441134412344133441434415344163441734418344193442034421344223442334424344253442634427344283442934430344313443234433344343443534436344373443834439344403444134442344433444434445344463444734448344493445034451344523445334454344553445634457344583445934460344613446234463344643446534466344673446834469344703447134472344733447434475344763447734478344793448034481344823448334484344853448634487344883448934490344913449234493344943449534496344973449834499345003450134502345033450434505345063450734508345093451034511345123451334514345153451634517345183451934520345213452234523345243452534526345273452834529345303453134532345333453434535345363453734538345393454034541345423454334544345453454634547345483454934550345513455234553345543455534556345573455834559345603456134562345633456434565345663456734568345693457034571345723457334574345753457634577345783457934580345813458234583345843458534586345873458834589345903459134592345933459434595345963459734598345993460034601346023460334604346053460634607346083460934610346113461234613346143461534616346173461834619346203462134622346233462434625346263462734628346293463034631346323463334634346353463634637346383463934640346413464234643346443464534646346473464834649346503465134652346533465434655346563465734658346593466034661346623466334664346653466634667346683466934670346713467234673346743467534676346773467834679346803468134682346833468434685346863468734688346893469034691346923469334694346953469634697346983469934700347013470234703347043470534706347073470834709347103471134712347133471434715347163471734718347193472034721347223472334724347253472634727347283472934730347313473234733347343473534736347373473834739347403474134742347433474434745347463474734748347493475034751347523475334754347553475634757347583475934760347613476234763347643476534766347673476834769347703477134772347733477434775347763477734778347793478034781347823478334784347853478634787347883478934790347913479234793347943479534796347973479834799348003480134802348033480434805348063480734808348093481034811348123481334814348153481634817348183481934820348213482234823348243482534826348273482834829348303483134832348333483434835348363483734838348393484034841348423484334844348453484634847348483484934850348513485234853348543485534856348573485834859348603486134862348633486434865348663486734868348693487034871348723487334874348753487634877348783487934880348813488234883348843488534886348873488834889348903489134892348933489434895348963489734898348993490034901349023490334904349053490634907349083490934910349113491234913349143491534916349173491834919349203492134922349233492434925349263492734928349293493034931349323493334934349353493634937349383493934940349413494234943349443494534946349473494834949349503495134952349533495434955349563495734958349593496034961349623496334964349653496634967349683496934970349713497234973349743497534976349773497834979349803498134982349833498434985349863498734988349893499034991349923499334994349953499634997349983499935000350013500235003350043500535006350073500835009350103501135012350133501435015350163501735018350193502035021350223502335024350253502635027350283502935030350313503235033350343503535036350373503835039350403504135042350433504435045350463504735048350493505035051350523505335054350553505635057350583505935060350613506235063350643506535066350673506835069350703507135072350733507435075350763507735078350793508035081350823508335084350853508635087350883508935090350913509235093350943509535096350973509835099351003510135102351033510435105351063510735108351093511035111351123511335114351153511635117351183511935120351213512235123351243512535126351273512835129351303513135132351333513435135351363513735138351393514035141351423514335144351453514635147351483514935150351513515235153351543515535156351573515835159351603516135162351633516435165351663516735168351693517035171351723517335174351753517635177351783517935180351813518235183351843518535186351873518835189351903519135192351933519435195351963519735198351993520035201352023520335204352053520635207352083520935210352113521235213352143521535216352173521835219352203522135222352233522435225352263522735228352293523035231352323523335234352353523635237352383523935240352413524235243352443524535246352473524835249352503525135252352533525435255352563525735258352593526035261352623526335264352653526635267352683526935270352713527235273352743527535276352773527835279352803528135282352833528435285352863528735288352893529035291352923529335294352953529635297352983529935300353013530235303353043530535306353073530835309353103531135312353133531435315353163531735318353193532035321353223532335324353253532635327353283532935330353313533235333353343533535336353373533835339353403534135342353433534435345353463534735348353493535035351353523535335354353553535635357353583535935360353613536235363353643536535366353673536835369353703537135372353733537435375353763537735378353793538035381353823538335384353853538635387353883538935390353913539235393353943539535396353973539835399354003540135402354033540435405354063540735408354093541035411354123541335414354153541635417354183541935420354213542235423354243542535426354273542835429354303543135432354333543435435354363543735438354393544035441354423544335444354453544635447354483544935450354513545235453354543545535456354573545835459354603546135462354633546435465354663546735468354693547035471354723547335474354753547635477354783547935480354813548235483354843548535486354873548835489354903549135492354933549435495354963549735498354993550035501355023550335504355053550635507355083550935510355113551235513355143551535516355173551835519355203552135522355233552435525355263552735528355293553035531355323553335534355353553635537355383553935540355413554235543355443554535546355473554835549355503555135552355533555435555355563555735558355593556035561355623556335564355653556635567355683556935570355713557235573355743557535576355773557835579355803558135582355833558435585355863558735588355893559035591355923559335594355953559635597355983559935600356013560235603356043560535606356073560835609356103561135612356133561435615356163561735618356193562035621356223562335624356253562635627356283562935630356313563235633356343563535636356373563835639356403564135642356433564435645356463564735648356493565035651356523565335654356553565635657356583565935660356613566235663356643566535666356673566835669356703567135672356733567435675356763567735678356793568035681356823568335684356853568635687356883568935690356913569235693356943569535696356973569835699357003570135702357033570435705357063570735708357093571035711357123571335714357153571635717357183571935720357213572235723357243572535726357273572835729357303573135732357333573435735357363573735738357393574035741357423574335744357453574635747357483574935750357513575235753357543575535756357573575835759357603576135762357633576435765357663576735768357693577035771357723577335774357753577635777357783577935780357813578235783357843578535786357873578835789357903579135792357933579435795357963579735798357993580035801358023580335804358053580635807358083580935810358113581235813358143581535816358173581835819358203582135822358233582435825358263582735828358293583035831358323583335834358353583635837358383583935840358413584235843358443584535846358473584835849358503585135852358533585435855358563585735858358593586035861358623586335864358653586635867358683586935870358713587235873358743587535876358773587835879358803588135882358833588435885358863588735888358893589035891358923589335894358953589635897358983589935900359013590235903359043590535906359073590835909359103591135912359133591435915359163591735918359193592035921359223592335924359253592635927359283592935930359313593235933359343593535936359373593835939359403594135942
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '72dev' };
  6. // browserify support
  7. if ( typeof module === 'object' ) {
  8. module.exports = THREE;
  9. }
  10. // polyfills
  11. ( function () {
  12. var lastTime = 0;
  13. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  14. for ( var x = 0; x < vendors.length && !self.requestAnimationFrame; ++ x ) {
  15. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  16. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  17. }
  18. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  19. self.requestAnimationFrame = function ( callback ) {
  20. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  21. var id = self.setTimeout( function () { callback( currTime + timeToCall ) }, timeToCall );
  22. lastTime = currTime + timeToCall;
  23. return id;
  24. };
  25. }
  26. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  27. self.cancelAnimationFrame = function ( id ) { self.clearTimeout( id ) };
  28. }
  29. }() );
  30. if ( Math.sign === undefined ) {
  31. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  32. Math.sign = function ( x ) {
  33. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : +x;
  34. };
  35. }
  36. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  37. // Missing in IE9-11.
  38. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  39. Object.defineProperty( Function.prototype, 'name', {
  40. get: function () {
  41. return this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
  42. }
  43. } );
  44. }
  45. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  46. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  47. // GL STATE CONSTANTS
  48. THREE.CullFaceNone = 0;
  49. THREE.CullFaceBack = 1;
  50. THREE.CullFaceFront = 2;
  51. THREE.CullFaceFrontBack = 3;
  52. THREE.FrontFaceDirectionCW = 0;
  53. THREE.FrontFaceDirectionCCW = 1;
  54. // SHADOWING TYPES
  55. THREE.BasicShadowMap = 0;
  56. THREE.PCFShadowMap = 1;
  57. THREE.PCFSoftShadowMap = 2;
  58. // MATERIAL CONSTANTS
  59. // side
  60. THREE.FrontSide = 0;
  61. THREE.BackSide = 1;
  62. THREE.DoubleSide = 2;
  63. // shading
  64. THREE.NoShading = 0;
  65. THREE.FlatShading = 1;
  66. THREE.SmoothShading = 2;
  67. // colors
  68. THREE.NoColors = 0;
  69. THREE.FaceColors = 1;
  70. THREE.VertexColors = 2;
  71. // blending modes
  72. THREE.NoBlending = 0;
  73. THREE.NormalBlending = 1;
  74. THREE.AdditiveBlending = 2;
  75. THREE.SubtractiveBlending = 3;
  76. THREE.MultiplyBlending = 4;
  77. THREE.CustomBlending = 5;
  78. // custom blending equations
  79. // (numbers start from 100 not to clash with other
  80. // mappings to OpenGL constants defined in Texture.js)
  81. THREE.AddEquation = 100;
  82. THREE.SubtractEquation = 101;
  83. THREE.ReverseSubtractEquation = 102;
  84. THREE.MinEquation = 103;
  85. THREE.MaxEquation = 104;
  86. // custom blending destination factors
  87. THREE.ZeroFactor = 200;
  88. THREE.OneFactor = 201;
  89. THREE.SrcColorFactor = 202;
  90. THREE.OneMinusSrcColorFactor = 203;
  91. THREE.SrcAlphaFactor = 204;
  92. THREE.OneMinusSrcAlphaFactor = 205;
  93. THREE.DstAlphaFactor = 206;
  94. THREE.OneMinusDstAlphaFactor = 207;
  95. // custom blending source factors
  96. //THREE.ZeroFactor = 200;
  97. //THREE.OneFactor = 201;
  98. //THREE.SrcAlphaFactor = 204;
  99. //THREE.OneMinusSrcAlphaFactor = 205;
  100. //THREE.DstAlphaFactor = 206;
  101. //THREE.OneMinusDstAlphaFactor = 207;
  102. THREE.DstColorFactor = 208;
  103. THREE.OneMinusDstColorFactor = 209;
  104. THREE.SrcAlphaSaturateFactor = 210;
  105. // depth modes
  106. THREE.NeverDepth = 0;
  107. THREE.AlwaysDepth = 1;
  108. THREE.LessDepth = 2;
  109. THREE.LessEqualDepth = 3;
  110. THREE.EqualDepth = 4;
  111. THREE.GreaterEqualDepth = 5;
  112. THREE.GreaterDepth = 6;
  113. THREE.NotEqualDepth = 7;
  114. // TEXTURE CONSTANTS
  115. THREE.MultiplyOperation = 0;
  116. THREE.MixOperation = 1;
  117. THREE.AddOperation = 2;
  118. // Mapping modes
  119. THREE.UVMapping = 300;
  120. THREE.CubeReflectionMapping = 301;
  121. THREE.CubeRefractionMapping = 302;
  122. THREE.EquirectangularReflectionMapping = 303;
  123. THREE.EquirectangularRefractionMapping = 304;
  124. THREE.SphericalReflectionMapping = 305;
  125. // Wrapping modes
  126. THREE.RepeatWrapping = 1000;
  127. THREE.ClampToEdgeWrapping = 1001;
  128. THREE.MirroredRepeatWrapping = 1002;
  129. // Filters
  130. THREE.NearestFilter = 1003;
  131. THREE.NearestMipMapNearestFilter = 1004;
  132. THREE.NearestMipMapLinearFilter = 1005;
  133. THREE.LinearFilter = 1006;
  134. THREE.LinearMipMapNearestFilter = 1007;
  135. THREE.LinearMipMapLinearFilter = 1008;
  136. // Data types
  137. THREE.UnsignedByteType = 1009;
  138. THREE.ByteType = 1010;
  139. THREE.ShortType = 1011;
  140. THREE.UnsignedShortType = 1012;
  141. THREE.IntType = 1013;
  142. THREE.UnsignedIntType = 1014;
  143. THREE.FloatType = 1015;
  144. THREE.HalfFloatType = 1025;
  145. // Pixel types
  146. //THREE.UnsignedByteType = 1009;
  147. THREE.UnsignedShort4444Type = 1016;
  148. THREE.UnsignedShort5551Type = 1017;
  149. THREE.UnsignedShort565Type = 1018;
  150. // Pixel formats
  151. THREE.AlphaFormat = 1019;
  152. THREE.RGBFormat = 1020;
  153. THREE.RGBAFormat = 1021;
  154. THREE.LuminanceFormat = 1022;
  155. THREE.LuminanceAlphaFormat = 1023;
  156. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  157. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  158. // DDS / ST3C Compressed texture formats
  159. THREE.RGB_S3TC_DXT1_Format = 2001;
  160. THREE.RGBA_S3TC_DXT1_Format = 2002;
  161. THREE.RGBA_S3TC_DXT3_Format = 2003;
  162. THREE.RGBA_S3TC_DXT5_Format = 2004;
  163. // PVRTC compressed texture formats
  164. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  165. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  166. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  167. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  168. // DEPRECATED
  169. THREE.Projector = function () {
  170. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  171. this.projectVector = function ( vector, camera ) {
  172. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  173. vector.project( camera );
  174. };
  175. this.unprojectVector = function ( vector, camera ) {
  176. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  177. vector.unproject( camera );
  178. };
  179. this.pickingRay = function ( vector, camera ) {
  180. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  181. };
  182. };
  183. THREE.CanvasRenderer = function () {
  184. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  185. this.domElement = document.createElement( 'canvas' );
  186. this.clear = function () {};
  187. this.render = function () {};
  188. this.setClearColor = function () {};
  189. this.setSize = function () {};
  190. };
  191. // File:src/math/Color.js
  192. /**
  193. * @author mrdoob / http://mrdoob.com/
  194. */
  195. THREE.Color = function ( color ) {
  196. if ( arguments.length === 3 ) {
  197. return this.setRGB( arguments[ 0 ], arguments[ 1 ], arguments[ 2 ] );
  198. }
  199. return this.set( color );
  200. };
  201. THREE.Color.prototype = {
  202. constructor: THREE.Color,
  203. r: 1, g: 1, b: 1,
  204. set: function ( value ) {
  205. if ( value instanceof THREE.Color ) {
  206. this.copy( value );
  207. } else if ( typeof value === 'number' ) {
  208. this.setHex( value );
  209. } else if ( typeof value === 'string' ) {
  210. this.setStyle( value );
  211. }
  212. return this;
  213. },
  214. setHex: function ( hex ) {
  215. hex = Math.floor( hex );
  216. this.r = ( hex >> 16 & 255 ) / 255;
  217. this.g = ( hex >> 8 & 255 ) / 255;
  218. this.b = ( hex & 255 ) / 255;
  219. return this;
  220. },
  221. setRGB: function ( r, g, b ) {
  222. this.r = r;
  223. this.g = g;
  224. this.b = b;
  225. return this;
  226. },
  227. setHSL: function () {
  228. function hue2rgb ( p, q, t ) {
  229. if ( t < 0 ) t += 1;
  230. if ( t > 1 ) t -= 1;
  231. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  232. if ( t < 1 / 2 ) return q;
  233. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  234. return p;
  235. }
  236. return function ( h, s, l ) {
  237. // h,s,l ranges are in 0.0 - 1.0
  238. h = THREE.Math.euclideanModulo( h, 1 );
  239. s = THREE.Math.clamp( s, 0, 1 );
  240. l = THREE.Math.clamp( l, 0, 1 );
  241. if ( s === 0 ) {
  242. this.r = this.g = this.b = l;
  243. } else {
  244. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  245. var q = ( 2 * l ) - p;
  246. this.r = hue2rgb( q, p, h + 1 / 3 );
  247. this.g = hue2rgb( q, p, h );
  248. this.b = hue2rgb( q, p, h - 1 / 3 );
  249. }
  250. return this;
  251. };
  252. }(),
  253. setStyle: function ( style ) {
  254. var m;
  255. // rgb / hsl
  256. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  257. var color;
  258. var name = m[ 1 ];
  259. var components = m[ 2 ];
  260. switch ( name ) {
  261. case 'rgb':
  262. case 'rgba':
  263. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/.exec( components ) ) {
  264. // rgb(255,0,0)
  265. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  266. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  267. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  268. return this;
  269. }
  270. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%/.exec( components ) ) {
  271. // rgb(100%,0%,0%)
  272. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  273. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  274. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  275. return this;
  276. }
  277. break;
  278. case 'hsl':
  279. case 'hsla':
  280. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%/.exec( components ) ) {
  281. // hsl(120,50%,50%)
  282. var h = parseFloat( color[ 1 ], 10 );
  283. var s = parseInt( color[ 2 ], 10 ) / 100;
  284. var l = parseInt( color[ 3 ], 10 ) / 100;
  285. return this.setHSL( h, s, l );
  286. }
  287. break;
  288. }
  289. // unknown color
  290. return this;
  291. }
  292. // hex
  293. if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  294. var hex = m[ 1 ];
  295. var size = hex.length;
  296. if ( size === 3 ) {
  297. // # ff0
  298. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  299. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  300. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  301. return this;
  302. }
  303. if ( size === 6 ) {
  304. // #fa11ac
  305. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  306. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  307. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  308. return this;
  309. }
  310. // unknown color
  311. return this;
  312. }
  313. // color keywords
  314. if ( /^\w+$/i.test( style ) ) {
  315. // red
  316. this.setHex( THREE.ColorKeywords[ style ] );
  317. return this;
  318. }
  319. // unknown color
  320. return this;
  321. },
  322. copy: function ( color ) {
  323. this.r = color.r;
  324. this.g = color.g;
  325. this.b = color.b;
  326. return this;
  327. },
  328. copyGammaToLinear: function ( color, gammaFactor ) {
  329. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  330. this.r = Math.pow( color.r, gammaFactor );
  331. this.g = Math.pow( color.g, gammaFactor );
  332. this.b = Math.pow( color.b, gammaFactor );
  333. return this;
  334. },
  335. copyLinearToGamma: function ( color, gammaFactor ) {
  336. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  337. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  338. this.r = Math.pow( color.r, safeInverse );
  339. this.g = Math.pow( color.g, safeInverse );
  340. this.b = Math.pow( color.b, safeInverse );
  341. return this;
  342. },
  343. convertGammaToLinear: function () {
  344. var r = this.r, g = this.g, b = this.b;
  345. this.r = r * r;
  346. this.g = g * g;
  347. this.b = b * b;
  348. return this;
  349. },
  350. convertLinearToGamma: function () {
  351. this.r = Math.sqrt( this.r );
  352. this.g = Math.sqrt( this.g );
  353. this.b = Math.sqrt( this.b );
  354. return this;
  355. },
  356. getHex: function () {
  357. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  358. },
  359. getHexString: function () {
  360. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  361. },
  362. getHSL: function ( optionalTarget ) {
  363. // h,s,l ranges are in 0.0 - 1.0
  364. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  365. var r = this.r, g = this.g, b = this.b;
  366. var max = Math.max( r, g, b );
  367. var min = Math.min( r, g, b );
  368. var hue, saturation;
  369. var lightness = ( min + max ) / 2.0;
  370. if ( min === max ) {
  371. hue = 0;
  372. saturation = 0;
  373. } else {
  374. var delta = max - min;
  375. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  376. switch ( max ) {
  377. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  378. case g: hue = ( b - r ) / delta + 2; break;
  379. case b: hue = ( r - g ) / delta + 4; break;
  380. }
  381. hue /= 6;
  382. }
  383. hsl.h = hue;
  384. hsl.s = saturation;
  385. hsl.l = lightness;
  386. return hsl;
  387. },
  388. getStyle: function () {
  389. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  390. },
  391. offsetHSL: function ( h, s, l ) {
  392. var hsl = this.getHSL();
  393. hsl.h += h; hsl.s += s; hsl.l += l;
  394. this.setHSL( hsl.h, hsl.s, hsl.l );
  395. return this;
  396. },
  397. add: function ( color ) {
  398. this.r += color.r;
  399. this.g += color.g;
  400. this.b += color.b;
  401. return this;
  402. },
  403. addColors: function ( color1, color2 ) {
  404. this.r = color1.r + color2.r;
  405. this.g = color1.g + color2.g;
  406. this.b = color1.b + color2.b;
  407. return this;
  408. },
  409. addScalar: function ( s ) {
  410. this.r += s;
  411. this.g += s;
  412. this.b += s;
  413. return this;
  414. },
  415. multiply: function ( color ) {
  416. this.r *= color.r;
  417. this.g *= color.g;
  418. this.b *= color.b;
  419. return this;
  420. },
  421. multiplyScalar: function ( s ) {
  422. this.r *= s;
  423. this.g *= s;
  424. this.b *= s;
  425. return this;
  426. },
  427. lerp: function ( color, alpha ) {
  428. this.r += ( color.r - this.r ) * alpha;
  429. this.g += ( color.g - this.g ) * alpha;
  430. this.b += ( color.b - this.b ) * alpha;
  431. return this;
  432. },
  433. equals: function ( c ) {
  434. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  435. },
  436. fromArray: function ( array ) {
  437. this.r = array[ 0 ];
  438. this.g = array[ 1 ];
  439. this.b = array[ 2 ];
  440. return this;
  441. },
  442. toArray: function ( array, offset ) {
  443. if ( array === undefined ) array = [];
  444. if ( offset === undefined ) offset = 0;
  445. array[ offset ] = this.r;
  446. array[ offset + 1 ] = this.g;
  447. array[ offset + 2 ] = this.b;
  448. return array;
  449. },
  450. clone: function () {
  451. return new THREE.Color().setRGB( this.r, this.g, this.b );
  452. }
  453. };
  454. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  455. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  456. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  457. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  458. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  459. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  460. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  461. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  462. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  463. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  464. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  465. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  466. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  467. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  468. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  469. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  470. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  471. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  472. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  473. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  474. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  475. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  476. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  477. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  478. // File:src/math/Quaternion.js
  479. /**
  480. * @author mikael emtinger / http://gomo.se/
  481. * @author alteredq / http://alteredqualia.com/
  482. * @author WestLangley / http://github.com/WestLangley
  483. * @author bhouston / http://exocortex.com
  484. */
  485. THREE.Quaternion = function ( x, y, z, w ) {
  486. this._x = x || 0;
  487. this._y = y || 0;
  488. this._z = z || 0;
  489. this._w = ( w !== undefined ) ? w : 1;
  490. };
  491. THREE.Quaternion.prototype = {
  492. constructor: THREE.Quaternion,
  493. _x: 0,_y: 0, _z: 0, _w: 0,
  494. get x () {
  495. return this._x;
  496. },
  497. set x ( value ) {
  498. this._x = value;
  499. this.onChangeCallback();
  500. },
  501. get y () {
  502. return this._y;
  503. },
  504. set y ( value ) {
  505. this._y = value;
  506. this.onChangeCallback();
  507. },
  508. get z () {
  509. return this._z;
  510. },
  511. set z ( value ) {
  512. this._z = value;
  513. this.onChangeCallback();
  514. },
  515. get w () {
  516. return this._w;
  517. },
  518. set w ( value ) {
  519. this._w = value;
  520. this.onChangeCallback();
  521. },
  522. set: function ( x, y, z, w ) {
  523. this._x = x;
  524. this._y = y;
  525. this._z = z;
  526. this._w = w;
  527. this.onChangeCallback();
  528. return this;
  529. },
  530. copy: function ( quaternion ) {
  531. this._x = quaternion.x;
  532. this._y = quaternion.y;
  533. this._z = quaternion.z;
  534. this._w = quaternion.w;
  535. this.onChangeCallback();
  536. return this;
  537. },
  538. setFromEuler: function ( euler, update ) {
  539. if ( euler instanceof THREE.Euler === false ) {
  540. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  541. }
  542. // http://www.mathworks.com/matlabcentral/fileexchange/
  543. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  544. // content/SpinCalc.m
  545. var c1 = Math.cos( euler._x / 2 );
  546. var c2 = Math.cos( euler._y / 2 );
  547. var c3 = Math.cos( euler._z / 2 );
  548. var s1 = Math.sin( euler._x / 2 );
  549. var s2 = Math.sin( euler._y / 2 );
  550. var s3 = Math.sin( euler._z / 2 );
  551. if ( euler.order === 'XYZ' ) {
  552. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  553. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  554. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  555. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  556. } else if ( euler.order === 'YXZ' ) {
  557. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  558. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  559. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  560. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  561. } else if ( euler.order === 'ZXY' ) {
  562. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  563. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  564. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  565. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  566. } else if ( euler.order === 'ZYX' ) {
  567. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  568. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  569. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  570. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  571. } else if ( euler.order === 'YZX' ) {
  572. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  573. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  574. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  575. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  576. } else if ( euler.order === 'XZY' ) {
  577. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  578. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  579. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  580. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  581. }
  582. if ( update !== false ) this.onChangeCallback();
  583. return this;
  584. },
  585. setFromAxisAngle: function ( axis, angle ) {
  586. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  587. // assumes axis is normalized
  588. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  589. this._x = axis.x * s;
  590. this._y = axis.y * s;
  591. this._z = axis.z * s;
  592. this._w = Math.cos( halfAngle );
  593. this.onChangeCallback();
  594. return this;
  595. },
  596. setFromRotationMatrix: function ( m ) {
  597. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  598. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  599. var te = m.elements,
  600. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  601. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  602. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  603. trace = m11 + m22 + m33,
  604. s;
  605. if ( trace > 0 ) {
  606. s = 0.5 / Math.sqrt( trace + 1.0 );
  607. this._w = 0.25 / s;
  608. this._x = ( m32 - m23 ) * s;
  609. this._y = ( m13 - m31 ) * s;
  610. this._z = ( m21 - m12 ) * s;
  611. } else if ( m11 > m22 && m11 > m33 ) {
  612. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  613. this._w = ( m32 - m23 ) / s;
  614. this._x = 0.25 * s;
  615. this._y = ( m12 + m21 ) / s;
  616. this._z = ( m13 + m31 ) / s;
  617. } else if ( m22 > m33 ) {
  618. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  619. this._w = ( m13 - m31 ) / s;
  620. this._x = ( m12 + m21 ) / s;
  621. this._y = 0.25 * s;
  622. this._z = ( m23 + m32 ) / s;
  623. } else {
  624. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  625. this._w = ( m21 - m12 ) / s;
  626. this._x = ( m13 + m31 ) / s;
  627. this._y = ( m23 + m32 ) / s;
  628. this._z = 0.25 * s;
  629. }
  630. this.onChangeCallback();
  631. return this;
  632. },
  633. setFromUnitVectors: function () {
  634. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  635. // assumes direction vectors vFrom and vTo are normalized
  636. var v1, r;
  637. var EPS = 0.000001;
  638. return function ( vFrom, vTo ) {
  639. if ( v1 === undefined ) v1 = new THREE.Vector3();
  640. r = vFrom.dot( vTo ) + 1;
  641. if ( r < EPS ) {
  642. r = 0;
  643. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  644. v1.set( - vFrom.y, vFrom.x, 0 );
  645. } else {
  646. v1.set( 0, - vFrom.z, vFrom.y );
  647. }
  648. } else {
  649. v1.crossVectors( vFrom, vTo );
  650. }
  651. this._x = v1.x;
  652. this._y = v1.y;
  653. this._z = v1.z;
  654. this._w = r;
  655. this.normalize();
  656. return this;
  657. }
  658. }(),
  659. inverse: function () {
  660. this.conjugate().normalize();
  661. return this;
  662. },
  663. conjugate: function () {
  664. this._x *= - 1;
  665. this._y *= - 1;
  666. this._z *= - 1;
  667. this.onChangeCallback();
  668. return this;
  669. },
  670. dot: function ( v ) {
  671. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  672. },
  673. lengthSq: function () {
  674. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  675. },
  676. length: function () {
  677. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  678. },
  679. normalize: function () {
  680. var l = this.length();
  681. if ( l === 0 ) {
  682. this._x = 0;
  683. this._y = 0;
  684. this._z = 0;
  685. this._w = 1;
  686. } else {
  687. l = 1 / l;
  688. this._x = this._x * l;
  689. this._y = this._y * l;
  690. this._z = this._z * l;
  691. this._w = this._w * l;
  692. }
  693. this.onChangeCallback();
  694. return this;
  695. },
  696. multiply: function ( q, p ) {
  697. if ( p !== undefined ) {
  698. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  699. return this.multiplyQuaternions( q, p );
  700. }
  701. return this.multiplyQuaternions( this, q );
  702. },
  703. multiplyQuaternions: function ( a, b ) {
  704. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  705. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  706. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  707. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  708. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  709. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  710. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  711. this.onChangeCallback();
  712. return this;
  713. },
  714. multiplyVector3: function ( vector ) {
  715. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  716. return vector.applyQuaternion( this );
  717. },
  718. slerp: function ( qb, t ) {
  719. if ( t === 0 ) return this;
  720. if ( t === 1 ) return this.copy( qb );
  721. var x = this._x, y = this._y, z = this._z, w = this._w;
  722. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  723. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  724. if ( cosHalfTheta < 0 ) {
  725. this._w = - qb._w;
  726. this._x = - qb._x;
  727. this._y = - qb._y;
  728. this._z = - qb._z;
  729. cosHalfTheta = - cosHalfTheta;
  730. } else {
  731. this.copy( qb );
  732. }
  733. if ( cosHalfTheta >= 1.0 ) {
  734. this._w = w;
  735. this._x = x;
  736. this._y = y;
  737. this._z = z;
  738. return this;
  739. }
  740. var halfTheta = Math.acos( cosHalfTheta );
  741. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  742. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  743. this._w = 0.5 * ( w + this._w );
  744. this._x = 0.5 * ( x + this._x );
  745. this._y = 0.5 * ( y + this._y );
  746. this._z = 0.5 * ( z + this._z );
  747. return this;
  748. }
  749. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  750. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  751. this._w = ( w * ratioA + this._w * ratioB );
  752. this._x = ( x * ratioA + this._x * ratioB );
  753. this._y = ( y * ratioA + this._y * ratioB );
  754. this._z = ( z * ratioA + this._z * ratioB );
  755. this.onChangeCallback();
  756. return this;
  757. },
  758. equals: function ( quaternion ) {
  759. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  760. },
  761. fromArray: function ( array, offset ) {
  762. if ( offset === undefined ) offset = 0;
  763. this._x = array[ offset ];
  764. this._y = array[ offset + 1 ];
  765. this._z = array[ offset + 2 ];
  766. this._w = array[ offset + 3 ];
  767. this.onChangeCallback();
  768. return this;
  769. },
  770. toArray: function ( array, offset ) {
  771. if ( array === undefined ) array = [];
  772. if ( offset === undefined ) offset = 0;
  773. array[ offset ] = this._x;
  774. array[ offset + 1 ] = this._y;
  775. array[ offset + 2 ] = this._z;
  776. array[ offset + 3 ] = this._w;
  777. return array;
  778. },
  779. onChange: function ( callback ) {
  780. this.onChangeCallback = callback;
  781. return this;
  782. },
  783. onChangeCallback: function () {},
  784. clone: function () {
  785. return new THREE.Quaternion( this._x, this._y, this._z, this._w );
  786. }
  787. };
  788. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  789. return qm.copy( qa ).slerp( qb, t );
  790. };
  791. // File:src/math/Vector2.js
  792. /**
  793. * @author mrdoob / http://mrdoob.com/
  794. * @author philogb / http://blog.thejit.org/
  795. * @author egraether / http://egraether.com/
  796. * @author zz85 / http://www.lab4games.net/zz85/blog
  797. */
  798. THREE.Vector2 = function ( x, y ) {
  799. this.x = x || 0;
  800. this.y = y || 0;
  801. };
  802. THREE.Vector2.prototype = {
  803. constructor: THREE.Vector2,
  804. set: function ( x, y ) {
  805. this.x = x;
  806. this.y = y;
  807. return this;
  808. },
  809. setX: function ( x ) {
  810. this.x = x;
  811. return this;
  812. },
  813. setY: function ( y ) {
  814. this.y = y;
  815. return this;
  816. },
  817. setComponent: function ( index, value ) {
  818. switch ( index ) {
  819. case 0: this.x = value; break;
  820. case 1: this.y = value; break;
  821. default: throw new Error( 'index is out of range: ' + index );
  822. }
  823. },
  824. getComponent: function ( index ) {
  825. switch ( index ) {
  826. case 0: return this.x;
  827. case 1: return this.y;
  828. default: throw new Error( 'index is out of range: ' + index );
  829. }
  830. },
  831. copy: function ( v ) {
  832. this.x = v.x;
  833. this.y = v.y;
  834. return this;
  835. },
  836. add: function ( v, w ) {
  837. if ( w !== undefined ) {
  838. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  839. return this.addVectors( v, w );
  840. }
  841. this.x += v.x;
  842. this.y += v.y;
  843. return this;
  844. },
  845. addScalar: function ( s ) {
  846. this.x += s;
  847. this.y += s;
  848. return this;
  849. },
  850. addVectors: function ( a, b ) {
  851. this.x = a.x + b.x;
  852. this.y = a.y + b.y;
  853. return this;
  854. },
  855. addScaledVector: function ( v, s ) {
  856. this.x += v.x * s;
  857. this.y += v.y * s;
  858. return this;
  859. },
  860. sub: function ( v, w ) {
  861. if ( w !== undefined ) {
  862. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  863. return this.subVectors( v, w );
  864. }
  865. this.x -= v.x;
  866. this.y -= v.y;
  867. return this;
  868. },
  869. subScalar: function ( s ) {
  870. this.x -= s;
  871. this.y -= s;
  872. return this;
  873. },
  874. subVectors: function ( a, b ) {
  875. this.x = a.x - b.x;
  876. this.y = a.y - b.y;
  877. return this;
  878. },
  879. multiply: function ( v ) {
  880. this.x *= v.x;
  881. this.y *= v.y;
  882. return this;
  883. },
  884. multiplyScalar: function ( s ) {
  885. this.x *= s;
  886. this.y *= s;
  887. return this;
  888. },
  889. divide: function ( v ) {
  890. this.x /= v.x;
  891. this.y /= v.y;
  892. return this;
  893. },
  894. divideScalar: function ( scalar ) {
  895. if ( scalar !== 0 ) {
  896. var invScalar = 1 / scalar;
  897. this.x *= invScalar;
  898. this.y *= invScalar;
  899. } else {
  900. this.x = 0;
  901. this.y = 0;
  902. }
  903. return this;
  904. },
  905. min: function ( v ) {
  906. if ( this.x > v.x ) {
  907. this.x = v.x;
  908. }
  909. if ( this.y > v.y ) {
  910. this.y = v.y;
  911. }
  912. return this;
  913. },
  914. max: function ( v ) {
  915. if ( this.x < v.x ) {
  916. this.x = v.x;
  917. }
  918. if ( this.y < v.y ) {
  919. this.y = v.y;
  920. }
  921. return this;
  922. },
  923. clamp: function ( min, max ) {
  924. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  925. if ( this.x < min.x ) {
  926. this.x = min.x;
  927. } else if ( this.x > max.x ) {
  928. this.x = max.x;
  929. }
  930. if ( this.y < min.y ) {
  931. this.y = min.y;
  932. } else if ( this.y > max.y ) {
  933. this.y = max.y;
  934. }
  935. return this;
  936. },
  937. clampScalar: function () {
  938. var min, max;
  939. return function clampScalar( minVal, maxVal ) {
  940. if ( min === undefined ) {
  941. min = new THREE.Vector2();
  942. max = new THREE.Vector2();
  943. }
  944. min.set( minVal, minVal );
  945. max.set( maxVal, maxVal );
  946. return this.clamp( min, max );
  947. };
  948. }(),
  949. floor: function () {
  950. this.x = Math.floor( this.x );
  951. this.y = Math.floor( this.y );
  952. return this;
  953. },
  954. ceil: function () {
  955. this.x = Math.ceil( this.x );
  956. this.y = Math.ceil( this.y );
  957. return this;
  958. },
  959. round: function () {
  960. this.x = Math.round( this.x );
  961. this.y = Math.round( this.y );
  962. return this;
  963. },
  964. roundToZero: function () {
  965. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  966. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  967. return this;
  968. },
  969. negate: function () {
  970. this.x = - this.x;
  971. this.y = - this.y;
  972. return this;
  973. },
  974. dot: function ( v ) {
  975. return this.x * v.x + this.y * v.y;
  976. },
  977. lengthSq: function () {
  978. return this.x * this.x + this.y * this.y;
  979. },
  980. length: function () {
  981. return Math.sqrt( this.x * this.x + this.y * this.y );
  982. },
  983. lengthManhattan: function() {
  984. return Math.abs( this.x ) + Math.abs( this.y );
  985. },
  986. normalize: function () {
  987. return this.divideScalar( this.length() );
  988. },
  989. distanceTo: function ( v ) {
  990. return Math.sqrt( this.distanceToSquared( v ) );
  991. },
  992. distanceToSquared: function ( v ) {
  993. var dx = this.x - v.x, dy = this.y - v.y;
  994. return dx * dx + dy * dy;
  995. },
  996. setLength: function ( l ) {
  997. var oldLength = this.length();
  998. if ( oldLength !== 0 && l !== oldLength ) {
  999. this.multiplyScalar( l / oldLength );
  1000. }
  1001. return this;
  1002. },
  1003. lerp: function ( v, alpha ) {
  1004. this.x += ( v.x - this.x ) * alpha;
  1005. this.y += ( v.y - this.y ) * alpha;
  1006. return this;
  1007. },
  1008. lerpVectors: function ( v1, v2, alpha ) {
  1009. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1010. return this;
  1011. },
  1012. equals: function ( v ) {
  1013. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1014. },
  1015. fromArray: function ( array, offset ) {
  1016. if ( offset === undefined ) offset = 0;
  1017. this.x = array[ offset ];
  1018. this.y = array[ offset + 1 ];
  1019. return this;
  1020. },
  1021. toArray: function ( array, offset ) {
  1022. if ( array === undefined ) array = [];
  1023. if ( offset === undefined ) offset = 0;
  1024. array[ offset ] = this.x;
  1025. array[ offset + 1 ] = this.y;
  1026. return array;
  1027. },
  1028. fromAttribute: function ( attribute, index, offset ) {
  1029. if ( offset === undefined ) offset = 0;
  1030. index = index * attribute.itemSize + offset;
  1031. this.x = attribute.array[ index ];
  1032. this.y = attribute.array[ index + 1 ];
  1033. return this;
  1034. },
  1035. clone: function () {
  1036. return new THREE.Vector2( this.x, this.y );
  1037. }
  1038. };
  1039. // File:src/math/Vector3.js
  1040. /**
  1041. * @author mrdoob / http://mrdoob.com/
  1042. * @author *kile / http://kile.stravaganza.org/
  1043. * @author philogb / http://blog.thejit.org/
  1044. * @author mikael emtinger / http://gomo.se/
  1045. * @author egraether / http://egraether.com/
  1046. * @author WestLangley / http://github.com/WestLangley
  1047. */
  1048. THREE.Vector3 = function ( x, y, z ) {
  1049. this.x = x || 0;
  1050. this.y = y || 0;
  1051. this.z = z || 0;
  1052. };
  1053. THREE.Vector3.prototype = {
  1054. constructor: THREE.Vector3,
  1055. set: function ( x, y, z ) {
  1056. this.x = x;
  1057. this.y = y;
  1058. this.z = z;
  1059. return this;
  1060. },
  1061. setX: function ( x ) {
  1062. this.x = x;
  1063. return this;
  1064. },
  1065. setY: function ( y ) {
  1066. this.y = y;
  1067. return this;
  1068. },
  1069. setZ: function ( z ) {
  1070. this.z = z;
  1071. return this;
  1072. },
  1073. setComponent: function ( index, value ) {
  1074. switch ( index ) {
  1075. case 0: this.x = value; break;
  1076. case 1: this.y = value; break;
  1077. case 2: this.z = value; break;
  1078. default: throw new Error( 'index is out of range: ' + index );
  1079. }
  1080. },
  1081. getComponent: function ( index ) {
  1082. switch ( index ) {
  1083. case 0: return this.x;
  1084. case 1: return this.y;
  1085. case 2: return this.z;
  1086. default: throw new Error( 'index is out of range: ' + index );
  1087. }
  1088. },
  1089. copy: function ( v ) {
  1090. this.x = v.x;
  1091. this.y = v.y;
  1092. this.z = v.z;
  1093. return this;
  1094. },
  1095. add: function ( v, w ) {
  1096. if ( w !== undefined ) {
  1097. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1098. return this.addVectors( v, w );
  1099. }
  1100. this.x += v.x;
  1101. this.y += v.y;
  1102. this.z += v.z;
  1103. return this;
  1104. },
  1105. addScalar: function ( s ) {
  1106. this.x += s;
  1107. this.y += s;
  1108. this.z += s;
  1109. return this;
  1110. },
  1111. addVectors: function ( a, b ) {
  1112. this.x = a.x + b.x;
  1113. this.y = a.y + b.y;
  1114. this.z = a.z + b.z;
  1115. return this;
  1116. },
  1117. addScaledVector: function ( v, s ) {
  1118. this.x += v.x * s;
  1119. this.y += v.y * s;
  1120. this.z += v.z * s;
  1121. return this;
  1122. },
  1123. sub: function ( v, w ) {
  1124. if ( w !== undefined ) {
  1125. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1126. return this.subVectors( v, w );
  1127. }
  1128. this.x -= v.x;
  1129. this.y -= v.y;
  1130. this.z -= v.z;
  1131. return this;
  1132. },
  1133. subScalar: function ( s ) {
  1134. this.x -= s;
  1135. this.y -= s;
  1136. this.z -= s;
  1137. return this;
  1138. },
  1139. subVectors: function ( a, b ) {
  1140. this.x = a.x - b.x;
  1141. this.y = a.y - b.y;
  1142. this.z = a.z - b.z;
  1143. return this;
  1144. },
  1145. multiply: function ( v, w ) {
  1146. if ( w !== undefined ) {
  1147. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1148. return this.multiplyVectors( v, w );
  1149. }
  1150. this.x *= v.x;
  1151. this.y *= v.y;
  1152. this.z *= v.z;
  1153. return this;
  1154. },
  1155. multiplyScalar: function ( scalar ) {
  1156. this.x *= scalar;
  1157. this.y *= scalar;
  1158. this.z *= scalar;
  1159. return this;
  1160. },
  1161. multiplyVectors: function ( a, b ) {
  1162. this.x = a.x * b.x;
  1163. this.y = a.y * b.y;
  1164. this.z = a.z * b.z;
  1165. return this;
  1166. },
  1167. applyEuler: function () {
  1168. var quaternion;
  1169. return function applyEuler( euler ) {
  1170. if ( euler instanceof THREE.Euler === false ) {
  1171. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1172. }
  1173. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1174. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1175. return this;
  1176. };
  1177. }(),
  1178. applyAxisAngle: function () {
  1179. var quaternion;
  1180. return function applyAxisAngle( axis, angle ) {
  1181. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1182. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1183. return this;
  1184. };
  1185. }(),
  1186. applyMatrix3: function ( m ) {
  1187. var x = this.x;
  1188. var y = this.y;
  1189. var z = this.z;
  1190. var e = m.elements;
  1191. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1192. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1193. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1194. return this;
  1195. },
  1196. applyMatrix4: function ( m ) {
  1197. // input: THREE.Matrix4 affine matrix
  1198. var x = this.x, y = this.y, z = this.z;
  1199. var e = m.elements;
  1200. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1201. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1202. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1203. return this;
  1204. },
  1205. applyProjection: function ( m ) {
  1206. // input: THREE.Matrix4 projection matrix
  1207. var x = this.x, y = this.y, z = this.z;
  1208. var e = m.elements;
  1209. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1210. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1211. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1212. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1213. return this;
  1214. },
  1215. applyQuaternion: function ( q ) {
  1216. var x = this.x;
  1217. var y = this.y;
  1218. var z = this.z;
  1219. var qx = q.x;
  1220. var qy = q.y;
  1221. var qz = q.z;
  1222. var qw = q.w;
  1223. // calculate quat * vector
  1224. var ix = qw * x + qy * z - qz * y;
  1225. var iy = qw * y + qz * x - qx * z;
  1226. var iz = qw * z + qx * y - qy * x;
  1227. var iw = - qx * x - qy * y - qz * z;
  1228. // calculate result * inverse quat
  1229. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1230. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1231. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1232. return this;
  1233. },
  1234. project: function () {
  1235. var matrix;
  1236. return function project( camera ) {
  1237. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1238. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1239. return this.applyProjection( matrix );
  1240. };
  1241. }(),
  1242. unproject: function () {
  1243. var matrix;
  1244. return function unproject( camera ) {
  1245. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1246. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1247. return this.applyProjection( matrix );
  1248. };
  1249. }(),
  1250. transformDirection: function ( m ) {
  1251. // input: THREE.Matrix4 affine matrix
  1252. // vector interpreted as a direction
  1253. var x = this.x, y = this.y, z = this.z;
  1254. var e = m.elements;
  1255. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1256. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1257. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1258. this.normalize();
  1259. return this;
  1260. },
  1261. divide: function ( v ) {
  1262. this.x /= v.x;
  1263. this.y /= v.y;
  1264. this.z /= v.z;
  1265. return this;
  1266. },
  1267. divideScalar: function ( scalar ) {
  1268. if ( scalar !== 0 ) {
  1269. var invScalar = 1 / scalar;
  1270. this.x *= invScalar;
  1271. this.y *= invScalar;
  1272. this.z *= invScalar;
  1273. } else {
  1274. this.x = 0;
  1275. this.y = 0;
  1276. this.z = 0;
  1277. }
  1278. return this;
  1279. },
  1280. min: function ( v ) {
  1281. if ( this.x > v.x ) {
  1282. this.x = v.x;
  1283. }
  1284. if ( this.y > v.y ) {
  1285. this.y = v.y;
  1286. }
  1287. if ( this.z > v.z ) {
  1288. this.z = v.z;
  1289. }
  1290. return this;
  1291. },
  1292. max: function ( v ) {
  1293. if ( this.x < v.x ) {
  1294. this.x = v.x;
  1295. }
  1296. if ( this.y < v.y ) {
  1297. this.y = v.y;
  1298. }
  1299. if ( this.z < v.z ) {
  1300. this.z = v.z;
  1301. }
  1302. return this;
  1303. },
  1304. clamp: function ( min, max ) {
  1305. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1306. if ( this.x < min.x ) {
  1307. this.x = min.x;
  1308. } else if ( this.x > max.x ) {
  1309. this.x = max.x;
  1310. }
  1311. if ( this.y < min.y ) {
  1312. this.y = min.y;
  1313. } else if ( this.y > max.y ) {
  1314. this.y = max.y;
  1315. }
  1316. if ( this.z < min.z ) {
  1317. this.z = min.z;
  1318. } else if ( this.z > max.z ) {
  1319. this.z = max.z;
  1320. }
  1321. return this;
  1322. },
  1323. clampScalar: function () {
  1324. var min, max;
  1325. return function clampScalar( minVal, maxVal ) {
  1326. if ( min === undefined ) {
  1327. min = new THREE.Vector3();
  1328. max = new THREE.Vector3();
  1329. }
  1330. min.set( minVal, minVal, minVal );
  1331. max.set( maxVal, maxVal, maxVal );
  1332. return this.clamp( min, max );
  1333. };
  1334. }(),
  1335. floor: function () {
  1336. this.x = Math.floor( this.x );
  1337. this.y = Math.floor( this.y );
  1338. this.z = Math.floor( this.z );
  1339. return this;
  1340. },
  1341. ceil: function () {
  1342. this.x = Math.ceil( this.x );
  1343. this.y = Math.ceil( this.y );
  1344. this.z = Math.ceil( this.z );
  1345. return this;
  1346. },
  1347. round: function () {
  1348. this.x = Math.round( this.x );
  1349. this.y = Math.round( this.y );
  1350. this.z = Math.round( this.z );
  1351. return this;
  1352. },
  1353. roundToZero: function () {
  1354. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1355. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1356. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1357. return this;
  1358. },
  1359. negate: function () {
  1360. this.x = - this.x;
  1361. this.y = - this.y;
  1362. this.z = - this.z;
  1363. return this;
  1364. },
  1365. dot: function ( v ) {
  1366. return this.x * v.x + this.y * v.y + this.z * v.z;
  1367. },
  1368. lengthSq: function () {
  1369. return this.x * this.x + this.y * this.y + this.z * this.z;
  1370. },
  1371. length: function () {
  1372. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1373. },
  1374. lengthManhattan: function () {
  1375. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1376. },
  1377. normalize: function () {
  1378. return this.divideScalar( this.length() );
  1379. },
  1380. setLength: function ( l ) {
  1381. var oldLength = this.length();
  1382. if ( oldLength !== 0 && l !== oldLength ) {
  1383. this.multiplyScalar( l / oldLength );
  1384. }
  1385. return this;
  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. clone: function () {
  1524. return new THREE.Vector3( this.x, this.y, this.z );
  1525. }
  1526. };
  1527. // File:src/math/Vector4.js
  1528. /**
  1529. * @author supereggbert / http://www.paulbrunt.co.uk/
  1530. * @author philogb / http://blog.thejit.org/
  1531. * @author mikael emtinger / http://gomo.se/
  1532. * @author egraether / http://egraether.com/
  1533. * @author WestLangley / http://github.com/WestLangley
  1534. */
  1535. THREE.Vector4 = function ( x, y, z, w ) {
  1536. this.x = x || 0;
  1537. this.y = y || 0;
  1538. this.z = z || 0;
  1539. this.w = ( w !== undefined ) ? w : 1;
  1540. };
  1541. THREE.Vector4.prototype = {
  1542. constructor: THREE.Vector4,
  1543. set: function ( x, y, z, w ) {
  1544. this.x = x;
  1545. this.y = y;
  1546. this.z = z;
  1547. this.w = w;
  1548. return this;
  1549. },
  1550. setX: function ( x ) {
  1551. this.x = x;
  1552. return this;
  1553. },
  1554. setY: function ( y ) {
  1555. this.y = y;
  1556. return this;
  1557. },
  1558. setZ: function ( z ) {
  1559. this.z = z;
  1560. return this;
  1561. },
  1562. setW: function ( w ) {
  1563. this.w = w;
  1564. return this;
  1565. },
  1566. setComponent: function ( index, value ) {
  1567. switch ( index ) {
  1568. case 0: this.x = value; break;
  1569. case 1: this.y = value; break;
  1570. case 2: this.z = value; break;
  1571. case 3: this.w = value; break;
  1572. default: throw new Error( 'index is out of range: ' + index );
  1573. }
  1574. },
  1575. getComponent: function ( index ) {
  1576. switch ( index ) {
  1577. case 0: return this.x;
  1578. case 1: return this.y;
  1579. case 2: return this.z;
  1580. case 3: return this.w;
  1581. default: throw new Error( 'index is out of range: ' + index );
  1582. }
  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. this.x *= scalar;
  1650. this.y *= scalar;
  1651. this.z *= scalar;
  1652. this.w *= scalar;
  1653. return this;
  1654. },
  1655. applyMatrix4: function ( m ) {
  1656. var x = this.x;
  1657. var y = this.y;
  1658. var z = this.z;
  1659. var w = this.w;
  1660. var e = m.elements;
  1661. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1662. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1663. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1664. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1665. return this;
  1666. },
  1667. divideScalar: function ( scalar ) {
  1668. if ( scalar !== 0 ) {
  1669. var invScalar = 1 / scalar;
  1670. this.x *= invScalar;
  1671. this.y *= invScalar;
  1672. this.z *= invScalar;
  1673. this.w *= invScalar;
  1674. } else {
  1675. this.x = 0;
  1676. this.y = 0;
  1677. this.z = 0;
  1678. this.w = 1;
  1679. }
  1680. return this;
  1681. },
  1682. setAxisAngleFromQuaternion: function ( q ) {
  1683. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1684. // q is assumed to be normalized
  1685. this.w = 2 * Math.acos( q.w );
  1686. var s = Math.sqrt( 1 - q.w * q.w );
  1687. if ( s < 0.0001 ) {
  1688. this.x = 1;
  1689. this.y = 0;
  1690. this.z = 0;
  1691. } else {
  1692. this.x = q.x / s;
  1693. this.y = q.y / s;
  1694. this.z = q.z / s;
  1695. }
  1696. return this;
  1697. },
  1698. setAxisAngleFromRotationMatrix: function ( m ) {
  1699. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1700. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1701. var angle, x, y, z, // variables for result
  1702. epsilon = 0.01, // margin to allow for rounding errors
  1703. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1704. te = m.elements,
  1705. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1706. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1707. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1708. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1709. && ( Math.abs( m13 - m31 ) < epsilon )
  1710. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1711. // singularity found
  1712. // first check for identity matrix which must have +1 for all terms
  1713. // in leading diagonal and zero in other terms
  1714. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1715. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1716. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1717. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1718. // this singularity is identity matrix so angle = 0
  1719. this.set( 1, 0, 0, 0 );
  1720. return this; // zero angle, arbitrary axis
  1721. }
  1722. // otherwise this singularity is angle = 180
  1723. angle = Math.PI;
  1724. var xx = ( m11 + 1 ) / 2;
  1725. var yy = ( m22 + 1 ) / 2;
  1726. var zz = ( m33 + 1 ) / 2;
  1727. var xy = ( m12 + m21 ) / 4;
  1728. var xz = ( m13 + m31 ) / 4;
  1729. var yz = ( m23 + m32 ) / 4;
  1730. if ( ( xx > yy ) && ( xx > zz ) ) { // m11 is the largest diagonal term
  1731. if ( xx < epsilon ) {
  1732. x = 0;
  1733. y = 0.707106781;
  1734. z = 0.707106781;
  1735. } else {
  1736. x = Math.sqrt( xx );
  1737. y = xy / x;
  1738. z = xz / x;
  1739. }
  1740. } else if ( yy > zz ) { // m22 is the largest diagonal term
  1741. if ( yy < epsilon ) {
  1742. x = 0.707106781;
  1743. y = 0;
  1744. z = 0.707106781;
  1745. } else {
  1746. y = Math.sqrt( yy );
  1747. x = xy / y;
  1748. z = yz / y;
  1749. }
  1750. } else { // m33 is the largest diagonal term so base result on this
  1751. if ( zz < epsilon ) {
  1752. x = 0.707106781;
  1753. y = 0.707106781;
  1754. z = 0;
  1755. } else {
  1756. z = Math.sqrt( zz );
  1757. x = xz / z;
  1758. y = yz / z;
  1759. }
  1760. }
  1761. this.set( x, y, z, angle );
  1762. return this; // return 180 deg rotation
  1763. }
  1764. // as we have reached here there are no singularities so we can handle normally
  1765. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1766. + ( m13 - m31 ) * ( m13 - m31 )
  1767. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1768. if ( Math.abs( s ) < 0.001 ) s = 1;
  1769. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1770. // caught by singularity test above, but I've left it in just in case
  1771. this.x = ( m32 - m23 ) / s;
  1772. this.y = ( m13 - m31 ) / s;
  1773. this.z = ( m21 - m12 ) / s;
  1774. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1775. return this;
  1776. },
  1777. min: function ( v ) {
  1778. if ( this.x > v.x ) {
  1779. this.x = v.x;
  1780. }
  1781. if ( this.y > v.y ) {
  1782. this.y = v.y;
  1783. }
  1784. if ( this.z > v.z ) {
  1785. this.z = v.z;
  1786. }
  1787. if ( this.w > v.w ) {
  1788. this.w = v.w;
  1789. }
  1790. return this;
  1791. },
  1792. max: function ( v ) {
  1793. if ( this.x < v.x ) {
  1794. this.x = v.x;
  1795. }
  1796. if ( this.y < v.y ) {
  1797. this.y = v.y;
  1798. }
  1799. if ( this.z < v.z ) {
  1800. this.z = v.z;
  1801. }
  1802. if ( this.w < v.w ) {
  1803. this.w = v.w;
  1804. }
  1805. return this;
  1806. },
  1807. clamp: function ( min, max ) {
  1808. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1809. if ( this.x < min.x ) {
  1810. this.x = min.x;
  1811. } else if ( this.x > max.x ) {
  1812. this.x = max.x;
  1813. }
  1814. if ( this.y < min.y ) {
  1815. this.y = min.y;
  1816. } else if ( this.y > max.y ) {
  1817. this.y = max.y;
  1818. }
  1819. if ( this.z < min.z ) {
  1820. this.z = min.z;
  1821. } else if ( this.z > max.z ) {
  1822. this.z = max.z;
  1823. }
  1824. if ( this.w < min.w ) {
  1825. this.w = min.w;
  1826. } else if ( this.w > max.w ) {
  1827. this.w = max.w;
  1828. }
  1829. return this;
  1830. },
  1831. clampScalar: function () {
  1832. var min, max;
  1833. return function clampScalar( minVal, maxVal ) {
  1834. if ( min === undefined ) {
  1835. min = new THREE.Vector4();
  1836. max = new THREE.Vector4();
  1837. }
  1838. min.set( minVal, minVal, minVal, minVal );
  1839. max.set( maxVal, maxVal, maxVal, maxVal );
  1840. return this.clamp( min, max );
  1841. };
  1842. }(),
  1843. floor: function () {
  1844. this.x = Math.floor( this.x );
  1845. this.y = Math.floor( this.y );
  1846. this.z = Math.floor( this.z );
  1847. this.w = Math.floor( this.w );
  1848. return this;
  1849. },
  1850. ceil: function () {
  1851. this.x = Math.ceil( this.x );
  1852. this.y = Math.ceil( this.y );
  1853. this.z = Math.ceil( this.z );
  1854. this.w = Math.ceil( this.w );
  1855. return this;
  1856. },
  1857. round: function () {
  1858. this.x = Math.round( this.x );
  1859. this.y = Math.round( this.y );
  1860. this.z = Math.round( this.z );
  1861. this.w = Math.round( this.w );
  1862. return this;
  1863. },
  1864. roundToZero: function () {
  1865. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1866. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1867. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1868. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1869. return this;
  1870. },
  1871. negate: function () {
  1872. this.x = - this.x;
  1873. this.y = - this.y;
  1874. this.z = - this.z;
  1875. this.w = - this.w;
  1876. return this;
  1877. },
  1878. dot: function ( v ) {
  1879. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1880. },
  1881. lengthSq: function () {
  1882. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1883. },
  1884. length: function () {
  1885. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1886. },
  1887. lengthManhattan: function () {
  1888. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1889. },
  1890. normalize: function () {
  1891. return this.divideScalar( this.length() );
  1892. },
  1893. setLength: function ( l ) {
  1894. var oldLength = this.length();
  1895. if ( oldLength !== 0 && l !== oldLength ) {
  1896. this.multiplyScalar( l / oldLength );
  1897. }
  1898. return this;
  1899. },
  1900. lerp: function ( v, alpha ) {
  1901. this.x += ( v.x - this.x ) * alpha;
  1902. this.y += ( v.y - this.y ) * alpha;
  1903. this.z += ( v.z - this.z ) * alpha;
  1904. this.w += ( v.w - this.w ) * alpha;
  1905. return this;
  1906. },
  1907. lerpVectors: function ( v1, v2, alpha ) {
  1908. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1909. return this;
  1910. },
  1911. equals: function ( v ) {
  1912. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1913. },
  1914. fromArray: function ( array, offset ) {
  1915. if ( offset === undefined ) offset = 0;
  1916. this.x = array[ offset ];
  1917. this.y = array[ offset + 1 ];
  1918. this.z = array[ offset + 2 ];
  1919. this.w = array[ offset + 3 ];
  1920. return this;
  1921. },
  1922. toArray: function ( array, offset ) {
  1923. if ( array === undefined ) array = [];
  1924. if ( offset === undefined ) offset = 0;
  1925. array[ offset ] = this.x;
  1926. array[ offset + 1 ] = this.y;
  1927. array[ offset + 2 ] = this.z;
  1928. array[ offset + 3 ] = this.w;
  1929. return array;
  1930. },
  1931. fromAttribute: function ( attribute, index, offset ) {
  1932. if ( offset === undefined ) offset = 0;
  1933. index = index * attribute.itemSize + offset;
  1934. this.x = attribute.array[ index ];
  1935. this.y = attribute.array[ index + 1 ];
  1936. this.z = attribute.array[ index + 2 ];
  1937. this.w = attribute.array[ index + 3 ];
  1938. return this;
  1939. },
  1940. clone: function () {
  1941. return new THREE.Vector4( this.x, this.y, this.z, this.w );
  1942. }
  1943. };
  1944. // File:src/math/Euler.js
  1945. /**
  1946. * @author mrdoob / http://mrdoob.com/
  1947. * @author WestLangley / http://github.com/WestLangley
  1948. * @author bhouston / http://exocortex.com
  1949. */
  1950. THREE.Euler = function ( x, y, z, order ) {
  1951. this._x = x || 0;
  1952. this._y = y || 0;
  1953. this._z = z || 0;
  1954. this._order = order || THREE.Euler.DefaultOrder;
  1955. };
  1956. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1957. THREE.Euler.DefaultOrder = 'XYZ';
  1958. THREE.Euler.prototype = {
  1959. constructor: THREE.Euler,
  1960. _x: 0, _y: 0, _z: 0, _order: THREE.Euler.DefaultOrder,
  1961. get x () {
  1962. return this._x;
  1963. },
  1964. set x ( value ) {
  1965. this._x = value;
  1966. this.onChangeCallback();
  1967. },
  1968. get y () {
  1969. return this._y;
  1970. },
  1971. set y ( value ) {
  1972. this._y = value;
  1973. this.onChangeCallback();
  1974. },
  1975. get z () {
  1976. return this._z;
  1977. },
  1978. set z ( value ) {
  1979. this._z = value;
  1980. this.onChangeCallback();
  1981. },
  1982. get order () {
  1983. return this._order;
  1984. },
  1985. set order ( value ) {
  1986. this._order = value;
  1987. this.onChangeCallback();
  1988. },
  1989. set: function ( x, y, z, order ) {
  1990. this._x = x;
  1991. this._y = y;
  1992. this._z = z;
  1993. this._order = order || this._order;
  1994. this.onChangeCallback();
  1995. return this;
  1996. },
  1997. copy: function ( euler ) {
  1998. this._x = euler._x;
  1999. this._y = euler._y;
  2000. this._z = euler._z;
  2001. this._order = euler._order;
  2002. this.onChangeCallback();
  2003. return this;
  2004. },
  2005. setFromRotationMatrix: function ( m, order, update ) {
  2006. var clamp = THREE.Math.clamp;
  2007. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2008. var te = m.elements;
  2009. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2010. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2011. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2012. order = order || this._order;
  2013. if ( order === 'XYZ' ) {
  2014. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2015. if ( Math.abs( m13 ) < 0.99999 ) {
  2016. this._x = Math.atan2( - m23, m33 );
  2017. this._z = Math.atan2( - m12, m11 );
  2018. } else {
  2019. this._x = Math.atan2( m32, m22 );
  2020. this._z = 0;
  2021. }
  2022. } else if ( order === 'YXZ' ) {
  2023. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2024. if ( Math.abs( m23 ) < 0.99999 ) {
  2025. this._y = Math.atan2( m13, m33 );
  2026. this._z = Math.atan2( m21, m22 );
  2027. } else {
  2028. this._y = Math.atan2( - m31, m11 );
  2029. this._z = 0;
  2030. }
  2031. } else if ( order === 'ZXY' ) {
  2032. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2033. if ( Math.abs( m32 ) < 0.99999 ) {
  2034. this._y = Math.atan2( - m31, m33 );
  2035. this._z = Math.atan2( - m12, m22 );
  2036. } else {
  2037. this._y = 0;
  2038. this._z = Math.atan2( m21, m11 );
  2039. }
  2040. } else if ( order === 'ZYX' ) {
  2041. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2042. if ( Math.abs( m31 ) < 0.99999 ) {
  2043. this._x = Math.atan2( m32, m33 );
  2044. this._z = Math.atan2( m21, m11 );
  2045. } else {
  2046. this._x = 0;
  2047. this._z = Math.atan2( - m12, m22 );
  2048. }
  2049. } else if ( order === 'YZX' ) {
  2050. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2051. if ( Math.abs( m21 ) < 0.99999 ) {
  2052. this._x = Math.atan2( - m23, m22 );
  2053. this._y = Math.atan2( - m31, m11 );
  2054. } else {
  2055. this._x = 0;
  2056. this._y = Math.atan2( m13, m33 );
  2057. }
  2058. } else if ( order === 'XZY' ) {
  2059. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2060. if ( Math.abs( m12 ) < 0.99999 ) {
  2061. this._x = Math.atan2( m32, m22 );
  2062. this._y = Math.atan2( m13, m11 );
  2063. } else {
  2064. this._x = Math.atan2( - m23, m33 );
  2065. this._y = 0;
  2066. }
  2067. } else {
  2068. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2069. }
  2070. this._order = order;
  2071. if ( update !== false ) this.onChangeCallback();
  2072. return this;
  2073. },
  2074. setFromQuaternion: function () {
  2075. var matrix;
  2076. return function ( q, order, update ) {
  2077. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2078. matrix.makeRotationFromQuaternion( q );
  2079. this.setFromRotationMatrix( matrix, order, update );
  2080. return this;
  2081. };
  2082. }(),
  2083. setFromVector3: function ( v, order ) {
  2084. return this.set( v.x, v.y, v.z, order || this._order );
  2085. },
  2086. reorder: function () {
  2087. // WARNING: this discards revolution information -bhouston
  2088. var q = new THREE.Quaternion();
  2089. return function ( newOrder ) {
  2090. q.setFromEuler( this );
  2091. this.setFromQuaternion( q, newOrder );
  2092. };
  2093. }(),
  2094. equals: function ( euler ) {
  2095. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2096. },
  2097. fromArray: function ( array ) {
  2098. this._x = array[ 0 ];
  2099. this._y = array[ 1 ];
  2100. this._z = array[ 2 ];
  2101. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2102. this.onChangeCallback();
  2103. return this;
  2104. },
  2105. toArray: function ( array, offset ) {
  2106. if ( array === undefined ) array = [];
  2107. if ( offset === undefined ) offset = 0;
  2108. array[ offset ] = this._x;
  2109. array[ offset + 1 ] = this._y;
  2110. array[ offset + 2 ] = this._z;
  2111. array[ offset + 3 ] = this._order;
  2112. return array;
  2113. },
  2114. toVector3: function ( optionalResult ) {
  2115. if ( optionalResult ) {
  2116. return optionalResult.set( this._x, this._y, this._z );
  2117. } else {
  2118. return new THREE.Vector3( this._x, this._y, this._z );
  2119. }
  2120. },
  2121. onChange: function ( callback ) {
  2122. this.onChangeCallback = callback;
  2123. return this;
  2124. },
  2125. onChangeCallback: function () {},
  2126. clone: function () {
  2127. return new THREE.Euler( this._x, this._y, this._z, this._order );
  2128. }
  2129. };
  2130. // File:src/math/Line3.js
  2131. /**
  2132. * @author bhouston / http://exocortex.com
  2133. */
  2134. THREE.Line3 = function ( start, end ) {
  2135. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2136. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2137. };
  2138. THREE.Line3.prototype = {
  2139. constructor: THREE.Line3,
  2140. set: function ( start, end ) {
  2141. this.start.copy( start );
  2142. this.end.copy( end );
  2143. return this;
  2144. },
  2145. copy: function ( line ) {
  2146. this.start.copy( line.start );
  2147. this.end.copy( line.end );
  2148. return this;
  2149. },
  2150. center: function ( optionalTarget ) {
  2151. var result = optionalTarget || new THREE.Vector3();
  2152. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2153. },
  2154. delta: function ( optionalTarget ) {
  2155. var result = optionalTarget || new THREE.Vector3();
  2156. return result.subVectors( this.end, this.start );
  2157. },
  2158. distanceSq: function () {
  2159. return this.start.distanceToSquared( this.end );
  2160. },
  2161. distance: function () {
  2162. return this.start.distanceTo( this.end );
  2163. },
  2164. at: function ( t, optionalTarget ) {
  2165. var result = optionalTarget || new THREE.Vector3();
  2166. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2167. },
  2168. closestPointToPointParameter: function () {
  2169. var startP = new THREE.Vector3();
  2170. var startEnd = new THREE.Vector3();
  2171. return function ( point, clampToLine ) {
  2172. startP.subVectors( point, this.start );
  2173. startEnd.subVectors( this.end, this.start );
  2174. var startEnd2 = startEnd.dot( startEnd );
  2175. var startEnd_startP = startEnd.dot( startP );
  2176. var t = startEnd_startP / startEnd2;
  2177. if ( clampToLine ) {
  2178. t = THREE.Math.clamp( t, 0, 1 );
  2179. }
  2180. return t;
  2181. };
  2182. }(),
  2183. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2184. var t = this.closestPointToPointParameter( point, clampToLine );
  2185. var result = optionalTarget || new THREE.Vector3();
  2186. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2187. },
  2188. applyMatrix4: function ( matrix ) {
  2189. this.start.applyMatrix4( matrix );
  2190. this.end.applyMatrix4( matrix );
  2191. return this;
  2192. },
  2193. equals: function ( line ) {
  2194. return line.start.equals( this.start ) && line.end.equals( this.end );
  2195. },
  2196. clone: function () {
  2197. return new THREE.Line3().copy( this );
  2198. }
  2199. };
  2200. // File:src/math/Box2.js
  2201. /**
  2202. * @author bhouston / http://exocortex.com
  2203. */
  2204. THREE.Box2 = function ( min, max ) {
  2205. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2206. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2207. };
  2208. THREE.Box2.prototype = {
  2209. constructor: THREE.Box2,
  2210. set: function ( min, max ) {
  2211. this.min.copy( min );
  2212. this.max.copy( max );
  2213. return this;
  2214. },
  2215. setFromPoints: function ( points ) {
  2216. this.makeEmpty();
  2217. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2218. this.expandByPoint( points[ i ] )
  2219. }
  2220. return this;
  2221. },
  2222. setFromCenterAndSize: function () {
  2223. var v1 = new THREE.Vector2();
  2224. return function ( center, size ) {
  2225. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2226. this.min.copy( center ).sub( halfSize );
  2227. this.max.copy( center ).add( halfSize );
  2228. return this;
  2229. };
  2230. }(),
  2231. copy: function ( box ) {
  2232. this.min.copy( box.min );
  2233. this.max.copy( box.max );
  2234. return this;
  2235. },
  2236. makeEmpty: function () {
  2237. this.min.x = this.min.y = Infinity;
  2238. this.max.x = this.max.y = - Infinity;
  2239. return this;
  2240. },
  2241. empty: function () {
  2242. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2243. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2244. },
  2245. center: function ( optionalTarget ) {
  2246. var result = optionalTarget || new THREE.Vector2();
  2247. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2248. },
  2249. size: function ( optionalTarget ) {
  2250. var result = optionalTarget || new THREE.Vector2();
  2251. return result.subVectors( this.max, this.min );
  2252. },
  2253. expandByPoint: function ( point ) {
  2254. this.min.min( point );
  2255. this.max.max( point );
  2256. return this;
  2257. },
  2258. expandByVector: function ( vector ) {
  2259. this.min.sub( vector );
  2260. this.max.add( vector );
  2261. return this;
  2262. },
  2263. expandByScalar: function ( scalar ) {
  2264. this.min.addScalar( - scalar );
  2265. this.max.addScalar( scalar );
  2266. return this;
  2267. },
  2268. containsPoint: function ( point ) {
  2269. if ( point.x < this.min.x || point.x > this.max.x ||
  2270. point.y < this.min.y || point.y > this.max.y ) {
  2271. return false;
  2272. }
  2273. return true;
  2274. },
  2275. containsBox: function ( box ) {
  2276. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2277. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2278. return true;
  2279. }
  2280. return false;
  2281. },
  2282. getParameter: function ( point, optionalTarget ) {
  2283. // This can potentially have a divide by zero if the box
  2284. // has a size dimension of 0.
  2285. var result = optionalTarget || new THREE.Vector2();
  2286. return result.set(
  2287. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2288. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2289. );
  2290. },
  2291. isIntersectionBox: function ( box ) {
  2292. // using 6 splitting planes to rule out intersections.
  2293. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2294. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2295. return false;
  2296. }
  2297. return true;
  2298. },
  2299. clampPoint: function ( point, optionalTarget ) {
  2300. var result = optionalTarget || new THREE.Vector2();
  2301. return result.copy( point ).clamp( this.min, this.max );
  2302. },
  2303. distanceToPoint: function () {
  2304. var v1 = new THREE.Vector2();
  2305. return function ( point ) {
  2306. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2307. return clampedPoint.sub( point ).length();
  2308. };
  2309. }(),
  2310. intersect: function ( box ) {
  2311. this.min.max( box.min );
  2312. this.max.min( box.max );
  2313. return this;
  2314. },
  2315. union: function ( box ) {
  2316. this.min.min( box.min );
  2317. this.max.max( box.max );
  2318. return this;
  2319. },
  2320. translate: function ( offset ) {
  2321. this.min.add( offset );
  2322. this.max.add( offset );
  2323. return this;
  2324. },
  2325. equals: function ( box ) {
  2326. return box.min.equals( this.min ) && box.max.equals( this.max );
  2327. },
  2328. clone: function () {
  2329. return new THREE.Box2().copy( this );
  2330. }
  2331. };
  2332. // File:src/math/Box3.js
  2333. /**
  2334. * @author bhouston / http://exocortex.com
  2335. * @author WestLangley / http://github.com/WestLangley
  2336. */
  2337. THREE.Box3 = function ( min, max ) {
  2338. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2339. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2340. };
  2341. THREE.Box3.prototype = {
  2342. constructor: THREE.Box3,
  2343. set: function ( min, max ) {
  2344. this.min.copy( min );
  2345. this.max.copy( max );
  2346. return this;
  2347. },
  2348. setFromPoints: function ( points ) {
  2349. this.makeEmpty();
  2350. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2351. this.expandByPoint( points[ i ] );
  2352. }
  2353. return this;
  2354. },
  2355. setFromCenterAndSize: function () {
  2356. var v1 = new THREE.Vector3();
  2357. return function ( center, size ) {
  2358. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2359. this.min.copy( center ).sub( halfSize );
  2360. this.max.copy( center ).add( halfSize );
  2361. return this;
  2362. };
  2363. }(),
  2364. setFromObject: function () {
  2365. // Computes the world-axis-aligned bounding box of an object (including its children),
  2366. // accounting for both the object's, and children's, world transforms
  2367. var v1 = new THREE.Vector3();
  2368. return function ( object ) {
  2369. var scope = this;
  2370. object.updateMatrixWorld( true );
  2371. this.makeEmpty();
  2372. object.traverse( function ( node ) {
  2373. var geometry = node.geometry;
  2374. if ( geometry !== undefined ) {
  2375. if ( geometry instanceof THREE.Geometry ) {
  2376. var vertices = geometry.vertices;
  2377. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2378. v1.copy( vertices[ i ] );
  2379. v1.applyMatrix4( node.matrixWorld );
  2380. scope.expandByPoint( v1 );
  2381. }
  2382. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2383. var positions = geometry.attributes[ 'position' ].array;
  2384. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2385. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2386. v1.applyMatrix4( node.matrixWorld );
  2387. scope.expandByPoint( v1 );
  2388. }
  2389. }
  2390. }
  2391. } );
  2392. return this;
  2393. };
  2394. }(),
  2395. copy: function ( box ) {
  2396. this.min.copy( box.min );
  2397. this.max.copy( box.max );
  2398. return this;
  2399. },
  2400. makeEmpty: function () {
  2401. this.min.x = this.min.y = this.min.z = Infinity;
  2402. this.max.x = this.max.y = this.max.z = - Infinity;
  2403. return this;
  2404. },
  2405. empty: function () {
  2406. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2407. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2408. },
  2409. center: function ( optionalTarget ) {
  2410. var result = optionalTarget || new THREE.Vector3();
  2411. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2412. },
  2413. size: function ( optionalTarget ) {
  2414. var result = optionalTarget || new THREE.Vector3();
  2415. return result.subVectors( this.max, this.min );
  2416. },
  2417. expandByPoint: function ( point ) {
  2418. this.min.min( point );
  2419. this.max.max( point );
  2420. return this;
  2421. },
  2422. expandByVector: function ( vector ) {
  2423. this.min.sub( vector );
  2424. this.max.add( vector );
  2425. return this;
  2426. },
  2427. expandByScalar: function ( scalar ) {
  2428. this.min.addScalar( - scalar );
  2429. this.max.addScalar( scalar );
  2430. return this;
  2431. },
  2432. containsPoint: function ( point ) {
  2433. if ( point.x < this.min.x || point.x > this.max.x ||
  2434. point.y < this.min.y || point.y > this.max.y ||
  2435. point.z < this.min.z || point.z > this.max.z ) {
  2436. return false;
  2437. }
  2438. return true;
  2439. },
  2440. containsBox: function ( box ) {
  2441. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2442. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2443. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2444. return true;
  2445. }
  2446. return false;
  2447. },
  2448. getParameter: function ( point, optionalTarget ) {
  2449. // This can potentially have a divide by zero if the box
  2450. // has a size dimension of 0.
  2451. var result = optionalTarget || new THREE.Vector3();
  2452. return result.set(
  2453. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2454. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2455. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2456. );
  2457. },
  2458. isIntersectionBox: function ( box ) {
  2459. // using 6 splitting planes to rule out intersections.
  2460. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2461. box.max.y < this.min.y || box.min.y > this.max.y ||
  2462. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2463. return false;
  2464. }
  2465. return true;
  2466. },
  2467. clampPoint: function ( point, optionalTarget ) {
  2468. var result = optionalTarget || new THREE.Vector3();
  2469. return result.copy( point ).clamp( this.min, this.max );
  2470. },
  2471. distanceToPoint: function () {
  2472. var v1 = new THREE.Vector3();
  2473. return function ( point ) {
  2474. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2475. return clampedPoint.sub( point ).length();
  2476. };
  2477. }(),
  2478. getBoundingSphere: function () {
  2479. var v1 = new THREE.Vector3();
  2480. return function ( optionalTarget ) {
  2481. var result = optionalTarget || new THREE.Sphere();
  2482. result.center = this.center();
  2483. result.radius = this.size( v1 ).length() * 0.5;
  2484. return result;
  2485. };
  2486. }(),
  2487. intersect: function ( box ) {
  2488. this.min.max( box.min );
  2489. this.max.min( box.max );
  2490. return this;
  2491. },
  2492. union: function ( box ) {
  2493. this.min.min( box.min );
  2494. this.max.max( box.max );
  2495. return this;
  2496. },
  2497. applyMatrix4: function () {
  2498. var points = [
  2499. new THREE.Vector3(),
  2500. new THREE.Vector3(),
  2501. new THREE.Vector3(),
  2502. new THREE.Vector3(),
  2503. new THREE.Vector3(),
  2504. new THREE.Vector3(),
  2505. new THREE.Vector3(),
  2506. new THREE.Vector3()
  2507. ];
  2508. return function ( matrix ) {
  2509. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2510. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2511. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2512. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2513. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2514. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2515. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2516. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2517. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2518. this.makeEmpty();
  2519. this.setFromPoints( points );
  2520. return this;
  2521. };
  2522. }(),
  2523. translate: function ( offset ) {
  2524. this.min.add( offset );
  2525. this.max.add( offset );
  2526. return this;
  2527. },
  2528. equals: function ( box ) {
  2529. return box.min.equals( this.min ) && box.max.equals( this.max );
  2530. },
  2531. clone: function () {
  2532. return new THREE.Box3().copy( this );
  2533. }
  2534. };
  2535. // File:src/math/Matrix3.js
  2536. /**
  2537. * @author alteredq / http://alteredqualia.com/
  2538. * @author WestLangley / http://github.com/WestLangley
  2539. * @author bhouston / http://exocortex.com
  2540. */
  2541. THREE.Matrix3 = function () {
  2542. this.elements = new Float32Array( [
  2543. 1, 0, 0,
  2544. 0, 1, 0,
  2545. 0, 0, 1
  2546. ] );
  2547. if ( arguments.length > 0 ) {
  2548. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2549. }
  2550. };
  2551. THREE.Matrix3.prototype = {
  2552. constructor: THREE.Matrix3,
  2553. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2554. var te = this.elements;
  2555. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2556. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2557. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2558. return this;
  2559. },
  2560. identity: function () {
  2561. this.set(
  2562. 1, 0, 0,
  2563. 0, 1, 0,
  2564. 0, 0, 1
  2565. );
  2566. return this;
  2567. },
  2568. copy: function ( m ) {
  2569. var me = m.elements;
  2570. this.set(
  2571. me[ 0 ], me[ 3 ], me[ 6 ],
  2572. me[ 1 ], me[ 4 ], me[ 7 ],
  2573. me[ 2 ], me[ 5 ], me[ 8 ]
  2574. );
  2575. return this;
  2576. },
  2577. multiplyVector3: function ( vector ) {
  2578. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2579. return vector.applyMatrix3( this );
  2580. },
  2581. multiplyVector3Array: function ( a ) {
  2582. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2583. return this.applyToVector3Array( a );
  2584. },
  2585. applyToVector3Array: function () {
  2586. var v1;
  2587. return function ( array, offset, length ) {
  2588. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2589. if ( offset === undefined ) offset = 0;
  2590. if ( length === undefined ) length = array.length;
  2591. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2592. v1.fromArray( array, j );
  2593. v1.applyMatrix3( this );
  2594. v1.toArray( array, j );
  2595. }
  2596. return array;
  2597. };
  2598. }(),
  2599. applyToBuffer: function () {
  2600. var v1;
  2601. return function applyToBuffer( buffer, offset, length ) {
  2602. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2603. if ( offset === undefined ) offset = 0;
  2604. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2605. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2606. v1.x = buffer.getX( j );
  2607. v1.y = buffer.getY( j );
  2608. v1.z = buffer.getZ( j );
  2609. v1.applyMatrix3( this );
  2610. buffer.setXYZ( v1.x, v1.y, v1.z );
  2611. }
  2612. return buffer;
  2613. };
  2614. }(),
  2615. multiplyScalar: function ( s ) {
  2616. var te = this.elements;
  2617. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2618. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2619. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2620. return this;
  2621. },
  2622. determinant: function () {
  2623. var te = this.elements;
  2624. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2625. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2626. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2627. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2628. },
  2629. getInverse: function ( matrix, throwOnInvertible ) {
  2630. // input: THREE.Matrix4
  2631. // ( based on http://code.google.com/p/webgl-mjs/ )
  2632. var me = matrix.elements;
  2633. var te = this.elements;
  2634. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2635. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2636. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2637. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2638. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2639. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2640. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2641. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2642. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2643. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2644. // no inverse
  2645. if ( det === 0 ) {
  2646. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2647. if ( throwOnInvertible || false ) {
  2648. throw new Error( msg );
  2649. } else {
  2650. console.warn( msg );
  2651. }
  2652. this.identity();
  2653. return this;
  2654. }
  2655. this.multiplyScalar( 1.0 / det );
  2656. return this;
  2657. },
  2658. transpose: function () {
  2659. var tmp, m = this.elements;
  2660. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2661. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2662. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2663. return this;
  2664. },
  2665. flattenToArrayOffset: function ( array, offset ) {
  2666. var te = this.elements;
  2667. array[ offset ] = te[ 0 ];
  2668. array[ offset + 1 ] = te[ 1 ];
  2669. array[ offset + 2 ] = te[ 2 ];
  2670. array[ offset + 3 ] = te[ 3 ];
  2671. array[ offset + 4 ] = te[ 4 ];
  2672. array[ offset + 5 ] = te[ 5 ];
  2673. array[ offset + 6 ] = te[ 6 ];
  2674. array[ offset + 7 ] = te[ 7 ];
  2675. array[ offset + 8 ] = te[ 8 ];
  2676. return array;
  2677. },
  2678. getNormalMatrix: function ( m ) {
  2679. // input: THREE.Matrix4
  2680. this.getInverse( m ).transpose();
  2681. return this;
  2682. },
  2683. transposeIntoArray: function ( r ) {
  2684. var m = this.elements;
  2685. r[ 0 ] = m[ 0 ];
  2686. r[ 1 ] = m[ 3 ];
  2687. r[ 2 ] = m[ 6 ];
  2688. r[ 3 ] = m[ 1 ];
  2689. r[ 4 ] = m[ 4 ];
  2690. r[ 5 ] = m[ 7 ];
  2691. r[ 6 ] = m[ 2 ];
  2692. r[ 7 ] = m[ 5 ];
  2693. r[ 8 ] = m[ 8 ];
  2694. return this;
  2695. },
  2696. fromArray: function ( array ) {
  2697. this.elements.set( array );
  2698. return this;
  2699. },
  2700. toArray: function () {
  2701. var te = this.elements;
  2702. return [
  2703. te[ 0 ], te[ 1 ], te[ 2 ],
  2704. te[ 3 ], te[ 4 ], te[ 5 ],
  2705. te[ 6 ], te[ 7 ], te[ 8 ]
  2706. ];
  2707. },
  2708. clone: function () {
  2709. return new THREE.Matrix3().fromArray( this.elements );
  2710. }
  2711. };
  2712. // File:src/math/Matrix4.js
  2713. /**
  2714. * @author mrdoob / http://mrdoob.com/
  2715. * @author supereggbert / http://www.paulbrunt.co.uk/
  2716. * @author philogb / http://blog.thejit.org/
  2717. * @author jordi_ros / http://plattsoft.com
  2718. * @author D1plo1d / http://github.com/D1plo1d
  2719. * @author alteredq / http://alteredqualia.com/
  2720. * @author mikael emtinger / http://gomo.se/
  2721. * @author timknip / http://www.floorplanner.com/
  2722. * @author bhouston / http://exocortex.com
  2723. * @author WestLangley / http://github.com/WestLangley
  2724. */
  2725. THREE.Matrix4 = function () {
  2726. this.elements = new Float32Array( [
  2727. 1, 0, 0, 0,
  2728. 0, 1, 0, 0,
  2729. 0, 0, 1, 0,
  2730. 0, 0, 0, 1
  2731. ] );
  2732. if ( arguments.length > 0 ) {
  2733. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2734. }
  2735. };
  2736. THREE.Matrix4.prototype = {
  2737. constructor: THREE.Matrix4,
  2738. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2739. var te = this.elements;
  2740. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2741. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2742. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2743. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2744. return this;
  2745. },
  2746. identity: function () {
  2747. this.set(
  2748. 1, 0, 0, 0,
  2749. 0, 1, 0, 0,
  2750. 0, 0, 1, 0,
  2751. 0, 0, 0, 1
  2752. );
  2753. return this;
  2754. },
  2755. copy: function ( m ) {
  2756. this.elements.set( m.elements );
  2757. return this;
  2758. },
  2759. extractPosition: function ( m ) {
  2760. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2761. return this.copyPosition( m );
  2762. },
  2763. copyPosition: function ( m ) {
  2764. var te = this.elements;
  2765. var me = m.elements;
  2766. te[ 12 ] = me[ 12 ];
  2767. te[ 13 ] = me[ 13 ];
  2768. te[ 14 ] = me[ 14 ];
  2769. return this;
  2770. },
  2771. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2772. var te = this.elements;
  2773. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2774. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2775. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2776. return this;
  2777. },
  2778. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2779. this.set(
  2780. xAxis.x, yAxis.x, zAxis.x, 0,
  2781. xAxis.y, yAxis.y, zAxis.y, 0,
  2782. xAxis.z, yAxis.z, zAxis.z, 0,
  2783. 0, 0, 0, 1
  2784. );
  2785. return this;
  2786. },
  2787. extractRotation: function () {
  2788. var v1;
  2789. return function ( m ) {
  2790. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2791. var te = this.elements;
  2792. var me = m.elements;
  2793. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2794. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2795. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2796. te[ 0 ] = me[ 0 ] * scaleX;
  2797. te[ 1 ] = me[ 1 ] * scaleX;
  2798. te[ 2 ] = me[ 2 ] * scaleX;
  2799. te[ 4 ] = me[ 4 ] * scaleY;
  2800. te[ 5 ] = me[ 5 ] * scaleY;
  2801. te[ 6 ] = me[ 6 ] * scaleY;
  2802. te[ 8 ] = me[ 8 ] * scaleZ;
  2803. te[ 9 ] = me[ 9 ] * scaleZ;
  2804. te[ 10 ] = me[ 10 ] * scaleZ;
  2805. return this;
  2806. };
  2807. }(),
  2808. makeRotationFromEuler: function ( euler ) {
  2809. if ( euler instanceof THREE.Euler === false ) {
  2810. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2811. }
  2812. var te = this.elements;
  2813. var x = euler.x, y = euler.y, z = euler.z;
  2814. var a = Math.cos( x ), b = Math.sin( x );
  2815. var c = Math.cos( y ), d = Math.sin( y );
  2816. var e = Math.cos( z ), f = Math.sin( z );
  2817. if ( euler.order === 'XYZ' ) {
  2818. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2819. te[ 0 ] = c * e;
  2820. te[ 4 ] = - c * f;
  2821. te[ 8 ] = d;
  2822. te[ 1 ] = af + be * d;
  2823. te[ 5 ] = ae - bf * d;
  2824. te[ 9 ] = - b * c;
  2825. te[ 2 ] = bf - ae * d;
  2826. te[ 6 ] = be + af * d;
  2827. te[ 10 ] = a * c;
  2828. } else if ( euler.order === 'YXZ' ) {
  2829. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2830. te[ 0 ] = ce + df * b;
  2831. te[ 4 ] = de * b - cf;
  2832. te[ 8 ] = a * d;
  2833. te[ 1 ] = a * f;
  2834. te[ 5 ] = a * e;
  2835. te[ 9 ] = - b;
  2836. te[ 2 ] = cf * b - de;
  2837. te[ 6 ] = df + ce * b;
  2838. te[ 10 ] = a * c;
  2839. } else if ( euler.order === 'ZXY' ) {
  2840. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2841. te[ 0 ] = ce - df * b;
  2842. te[ 4 ] = - a * f;
  2843. te[ 8 ] = de + cf * b;
  2844. te[ 1 ] = cf + de * b;
  2845. te[ 5 ] = a * e;
  2846. te[ 9 ] = df - ce * b;
  2847. te[ 2 ] = - a * d;
  2848. te[ 6 ] = b;
  2849. te[ 10 ] = a * c;
  2850. } else if ( euler.order === 'ZYX' ) {
  2851. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2852. te[ 0 ] = c * e;
  2853. te[ 4 ] = be * d - af;
  2854. te[ 8 ] = ae * d + bf;
  2855. te[ 1 ] = c * f;
  2856. te[ 5 ] = bf * d + ae;
  2857. te[ 9 ] = af * d - be;
  2858. te[ 2 ] = - d;
  2859. te[ 6 ] = b * c;
  2860. te[ 10 ] = a * c;
  2861. } else if ( euler.order === 'YZX' ) {
  2862. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2863. te[ 0 ] = c * e;
  2864. te[ 4 ] = bd - ac * f;
  2865. te[ 8 ] = bc * f + ad;
  2866. te[ 1 ] = f;
  2867. te[ 5 ] = a * e;
  2868. te[ 9 ] = - b * e;
  2869. te[ 2 ] = - d * e;
  2870. te[ 6 ] = ad * f + bc;
  2871. te[ 10 ] = ac - bd * f;
  2872. } else if ( euler.order === 'XZY' ) {
  2873. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2874. te[ 0 ] = c * e;
  2875. te[ 4 ] = - f;
  2876. te[ 8 ] = d * e;
  2877. te[ 1 ] = ac * f + bd;
  2878. te[ 5 ] = a * e;
  2879. te[ 9 ] = ad * f - bc;
  2880. te[ 2 ] = bc * f - ad;
  2881. te[ 6 ] = b * e;
  2882. te[ 10 ] = bd * f + ac;
  2883. }
  2884. // last column
  2885. te[ 3 ] = 0;
  2886. te[ 7 ] = 0;
  2887. te[ 11 ] = 0;
  2888. // bottom row
  2889. te[ 12 ] = 0;
  2890. te[ 13 ] = 0;
  2891. te[ 14 ] = 0;
  2892. te[ 15 ] = 1;
  2893. return this;
  2894. },
  2895. setRotationFromQuaternion: function ( q ) {
  2896. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2897. return this.makeRotationFromQuaternion( q );
  2898. },
  2899. makeRotationFromQuaternion: function ( q ) {
  2900. var te = this.elements;
  2901. var x = q.x, y = q.y, z = q.z, w = q.w;
  2902. var x2 = x + x, y2 = y + y, z2 = z + z;
  2903. var xx = x * x2, xy = x * y2, xz = x * z2;
  2904. var yy = y * y2, yz = y * z2, zz = z * z2;
  2905. var wx = w * x2, wy = w * y2, wz = w * z2;
  2906. te[ 0 ] = 1 - ( yy + zz );
  2907. te[ 4 ] = xy - wz;
  2908. te[ 8 ] = xz + wy;
  2909. te[ 1 ] = xy + wz;
  2910. te[ 5 ] = 1 - ( xx + zz );
  2911. te[ 9 ] = yz - wx;
  2912. te[ 2 ] = xz - wy;
  2913. te[ 6 ] = yz + wx;
  2914. te[ 10 ] = 1 - ( xx + yy );
  2915. // last column
  2916. te[ 3 ] = 0;
  2917. te[ 7 ] = 0;
  2918. te[ 11 ] = 0;
  2919. // bottom row
  2920. te[ 12 ] = 0;
  2921. te[ 13 ] = 0;
  2922. te[ 14 ] = 0;
  2923. te[ 15 ] = 1;
  2924. return this;
  2925. },
  2926. lookAt: function () {
  2927. var x, y, z;
  2928. return function ( eye, target, up ) {
  2929. if ( x === undefined ) x = new THREE.Vector3();
  2930. if ( y === undefined ) y = new THREE.Vector3();
  2931. if ( z === undefined ) z = new THREE.Vector3();
  2932. var te = this.elements;
  2933. z.subVectors( eye, target ).normalize();
  2934. if ( z.length() === 0 ) {
  2935. z.z = 1;
  2936. }
  2937. x.crossVectors( up, z ).normalize();
  2938. if ( x.length() === 0 ) {
  2939. z.x += 0.0001;
  2940. x.crossVectors( up, z ).normalize();
  2941. }
  2942. y.crossVectors( z, x );
  2943. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2944. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2945. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2946. return this;
  2947. };
  2948. }(),
  2949. multiply: function ( m, n ) {
  2950. if ( n !== undefined ) {
  2951. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2952. return this.multiplyMatrices( m, n );
  2953. }
  2954. return this.multiplyMatrices( this, m );
  2955. },
  2956. multiplyMatrices: function ( a, b ) {
  2957. var ae = a.elements;
  2958. var be = b.elements;
  2959. var te = this.elements;
  2960. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  2961. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  2962. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  2963. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  2964. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  2965. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  2966. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  2967. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  2968. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  2969. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  2970. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  2971. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  2972. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  2973. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  2974. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  2975. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  2976. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  2977. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  2978. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  2979. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  2980. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  2981. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  2982. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  2983. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  2984. return this;
  2985. },
  2986. multiplyToArray: function ( a, b, r ) {
  2987. var te = this.elements;
  2988. this.multiplyMatrices( a, b );
  2989. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  2990. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  2991. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  2992. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  2993. return this;
  2994. },
  2995. multiplyScalar: function ( s ) {
  2996. var te = this.elements;
  2997. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  2998. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  2999. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3000. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3001. return this;
  3002. },
  3003. multiplyVector3: function ( vector ) {
  3004. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  3005. return vector.applyProjection( this );
  3006. },
  3007. multiplyVector4: function ( vector ) {
  3008. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3009. return vector.applyMatrix4( this );
  3010. },
  3011. multiplyVector3Array: function ( a ) {
  3012. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  3013. return this.applyToVector3Array( a );
  3014. },
  3015. applyToVector3Array: function () {
  3016. var v1;
  3017. return function ( array, offset, length ) {
  3018. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3019. if ( offset === undefined ) offset = 0;
  3020. if ( length === undefined ) length = array.length;
  3021. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3022. v1.fromArray( array, j );
  3023. v1.applyMatrix4( this );
  3024. v1.toArray( array, j );
  3025. }
  3026. return array;
  3027. };
  3028. }(),
  3029. applyToBuffer: function () {
  3030. var v1;
  3031. return function applyToBuffer( buffer, offset, length ) {
  3032. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3033. if ( offset === undefined ) offset = 0;
  3034. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3035. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3036. v1.x = buffer.getX( j );
  3037. v1.y = buffer.getY( j );
  3038. v1.z = buffer.getZ( j );
  3039. v1.applyMatrix4( this );
  3040. buffer.setXYZ( v1.x, v1.y, v1.z );
  3041. }
  3042. return buffer;
  3043. };
  3044. }(),
  3045. rotateAxis: function ( v ) {
  3046. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3047. v.transformDirection( this );
  3048. },
  3049. crossVector: function ( vector ) {
  3050. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3051. return vector.applyMatrix4( this );
  3052. },
  3053. determinant: function () {
  3054. var te = this.elements;
  3055. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3056. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3057. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3058. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3059. //TODO: make this more efficient
  3060. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3061. return (
  3062. n41 * (
  3063. + n14 * n23 * n32
  3064. - n13 * n24 * n32
  3065. - n14 * n22 * n33
  3066. + n12 * n24 * n33
  3067. + n13 * n22 * n34
  3068. - n12 * n23 * n34
  3069. ) +
  3070. n42 * (
  3071. + n11 * n23 * n34
  3072. - n11 * n24 * n33
  3073. + n14 * n21 * n33
  3074. - n13 * n21 * n34
  3075. + n13 * n24 * n31
  3076. - n14 * n23 * n31
  3077. ) +
  3078. n43 * (
  3079. + n11 * n24 * n32
  3080. - n11 * n22 * n34
  3081. - n14 * n21 * n32
  3082. + n12 * n21 * n34
  3083. + n14 * n22 * n31
  3084. - n12 * n24 * n31
  3085. ) +
  3086. n44 * (
  3087. - n13 * n22 * n31
  3088. - n11 * n23 * n32
  3089. + n11 * n22 * n33
  3090. + n13 * n21 * n32
  3091. - n12 * n21 * n33
  3092. + n12 * n23 * n31
  3093. )
  3094. );
  3095. },
  3096. transpose: function () {
  3097. var te = this.elements;
  3098. var tmp;
  3099. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3100. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3101. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3102. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3103. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3104. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3105. return this;
  3106. },
  3107. flattenToArrayOffset: function ( array, offset ) {
  3108. var te = this.elements;
  3109. array[ offset ] = te[ 0 ];
  3110. array[ offset + 1 ] = te[ 1 ];
  3111. array[ offset + 2 ] = te[ 2 ];
  3112. array[ offset + 3 ] = te[ 3 ];
  3113. array[ offset + 4 ] = te[ 4 ];
  3114. array[ offset + 5 ] = te[ 5 ];
  3115. array[ offset + 6 ] = te[ 6 ];
  3116. array[ offset + 7 ] = te[ 7 ];
  3117. array[ offset + 8 ] = te[ 8 ];
  3118. array[ offset + 9 ] = te[ 9 ];
  3119. array[ offset + 10 ] = te[ 10 ];
  3120. array[ offset + 11 ] = te[ 11 ];
  3121. array[ offset + 12 ] = te[ 12 ];
  3122. array[ offset + 13 ] = te[ 13 ];
  3123. array[ offset + 14 ] = te[ 14 ];
  3124. array[ offset + 15 ] = te[ 15 ];
  3125. return array;
  3126. },
  3127. getPosition: function () {
  3128. var v1;
  3129. return function () {
  3130. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3131. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3132. var te = this.elements;
  3133. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3134. };
  3135. }(),
  3136. setPosition: function ( v ) {
  3137. var te = this.elements;
  3138. te[ 12 ] = v.x;
  3139. te[ 13 ] = v.y;
  3140. te[ 14 ] = v.z;
  3141. return this;
  3142. },
  3143. getInverse: function ( m, throwOnInvertible ) {
  3144. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3145. var te = this.elements;
  3146. var me = m.elements;
  3147. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3148. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3149. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3150. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3151. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3152. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3153. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3154. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3155. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3156. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3157. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3158. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3159. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3160. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3161. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3162. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3163. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3164. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3165. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3166. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3167. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3168. if ( det === 0 ) {
  3169. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3170. if ( throwOnInvertible || false ) {
  3171. throw new Error( msg );
  3172. } else {
  3173. console.warn( msg );
  3174. }
  3175. this.identity();
  3176. return this;
  3177. }
  3178. this.multiplyScalar( 1 / det );
  3179. return this;
  3180. },
  3181. translate: function ( v ) {
  3182. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3183. },
  3184. rotateX: function ( angle ) {
  3185. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3186. },
  3187. rotateY: function ( angle ) {
  3188. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3189. },
  3190. rotateZ: function ( angle ) {
  3191. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3192. },
  3193. rotateByAxis: function ( axis, angle ) {
  3194. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3195. },
  3196. scale: function ( v ) {
  3197. var te = this.elements;
  3198. var x = v.x, y = v.y, z = v.z;
  3199. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3200. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3201. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3202. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3203. return this;
  3204. },
  3205. getMaxScaleOnAxis: function () {
  3206. var te = this.elements;
  3207. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3208. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3209. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3210. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3211. },
  3212. makeTranslation: function ( x, y, z ) {
  3213. this.set(
  3214. 1, 0, 0, x,
  3215. 0, 1, 0, y,
  3216. 0, 0, 1, z,
  3217. 0, 0, 0, 1
  3218. );
  3219. return this;
  3220. },
  3221. makeRotationX: function ( theta ) {
  3222. var c = Math.cos( theta ), s = Math.sin( theta );
  3223. this.set(
  3224. 1, 0, 0, 0,
  3225. 0, c, - s, 0,
  3226. 0, s, c, 0,
  3227. 0, 0, 0, 1
  3228. );
  3229. return this;
  3230. },
  3231. makeRotationY: function ( theta ) {
  3232. var c = Math.cos( theta ), s = Math.sin( theta );
  3233. this.set(
  3234. c, 0, s, 0,
  3235. 0, 1, 0, 0,
  3236. - s, 0, c, 0,
  3237. 0, 0, 0, 1
  3238. );
  3239. return this;
  3240. },
  3241. makeRotationZ: function ( theta ) {
  3242. var c = Math.cos( theta ), s = Math.sin( theta );
  3243. this.set(
  3244. c, - s, 0, 0,
  3245. s, c, 0, 0,
  3246. 0, 0, 1, 0,
  3247. 0, 0, 0, 1
  3248. );
  3249. return this;
  3250. },
  3251. makeRotationAxis: function ( axis, angle ) {
  3252. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3253. var c = Math.cos( angle );
  3254. var s = Math.sin( angle );
  3255. var t = 1 - c;
  3256. var x = axis.x, y = axis.y, z = axis.z;
  3257. var tx = t * x, ty = t * y;
  3258. this.set(
  3259. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3260. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3261. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3262. 0, 0, 0, 1
  3263. );
  3264. return this;
  3265. },
  3266. makeScale: function ( x, y, z ) {
  3267. this.set(
  3268. x, 0, 0, 0,
  3269. 0, y, 0, 0,
  3270. 0, 0, z, 0,
  3271. 0, 0, 0, 1
  3272. );
  3273. return this;
  3274. },
  3275. compose: function ( position, quaternion, scale ) {
  3276. this.makeRotationFromQuaternion( quaternion );
  3277. this.scale( scale );
  3278. this.setPosition( position );
  3279. return this;
  3280. },
  3281. decompose: function () {
  3282. var vector, matrix;
  3283. return function ( position, quaternion, scale ) {
  3284. if ( vector === undefined ) vector = new THREE.Vector3();
  3285. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3286. var te = this.elements;
  3287. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3288. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3289. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3290. // if determine is negative, we need to invert one scale
  3291. var det = this.determinant();
  3292. if ( det < 0 ) {
  3293. sx = - sx;
  3294. }
  3295. position.x = te[ 12 ];
  3296. position.y = te[ 13 ];
  3297. position.z = te[ 14 ];
  3298. // scale the rotation part
  3299. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3300. var invSX = 1 / sx;
  3301. var invSY = 1 / sy;
  3302. var invSZ = 1 / sz;
  3303. matrix.elements[ 0 ] *= invSX;
  3304. matrix.elements[ 1 ] *= invSX;
  3305. matrix.elements[ 2 ] *= invSX;
  3306. matrix.elements[ 4 ] *= invSY;
  3307. matrix.elements[ 5 ] *= invSY;
  3308. matrix.elements[ 6 ] *= invSY;
  3309. matrix.elements[ 8 ] *= invSZ;
  3310. matrix.elements[ 9 ] *= invSZ;
  3311. matrix.elements[ 10 ] *= invSZ;
  3312. quaternion.setFromRotationMatrix( matrix );
  3313. scale.x = sx;
  3314. scale.y = sy;
  3315. scale.z = sz;
  3316. return this;
  3317. };
  3318. }(),
  3319. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3320. var te = this.elements;
  3321. var x = 2 * near / ( right - left );
  3322. var y = 2 * near / ( top - bottom );
  3323. var a = ( right + left ) / ( right - left );
  3324. var b = ( top + bottom ) / ( top - bottom );
  3325. var c = - ( far + near ) / ( far - near );
  3326. var d = - 2 * far * near / ( far - near );
  3327. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3328. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3329. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3330. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3331. return this;
  3332. },
  3333. makePerspective: function ( fov, aspect, near, far ) {
  3334. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3335. var ymin = - ymax;
  3336. var xmin = ymin * aspect;
  3337. var xmax = ymax * aspect;
  3338. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3339. },
  3340. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3341. var te = this.elements;
  3342. var w = right - left;
  3343. var h = top - bottom;
  3344. var p = far - near;
  3345. var x = ( right + left ) / w;
  3346. var y = ( top + bottom ) / h;
  3347. var z = ( far + near ) / p;
  3348. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3349. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3350. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3351. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3352. return this;
  3353. },
  3354. fromArray: function ( array ) {
  3355. this.elements.set( array );
  3356. return this;
  3357. },
  3358. toArray: function () {
  3359. var te = this.elements;
  3360. return [
  3361. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3362. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3363. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3364. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3365. ];
  3366. },
  3367. clone: function () {
  3368. return new THREE.Matrix4().fromArray( this.elements );
  3369. }
  3370. };
  3371. // File:src/math/Ray.js
  3372. /**
  3373. * @author bhouston / http://exocortex.com
  3374. */
  3375. THREE.Ray = function ( origin, direction ) {
  3376. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3377. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3378. };
  3379. THREE.Ray.prototype = {
  3380. constructor: THREE.Ray,
  3381. set: function ( origin, direction ) {
  3382. this.origin.copy( origin );
  3383. this.direction.copy( direction );
  3384. return this;
  3385. },
  3386. copy: function ( ray ) {
  3387. this.origin.copy( ray.origin );
  3388. this.direction.copy( ray.direction );
  3389. return this;
  3390. },
  3391. at: function ( t, optionalTarget ) {
  3392. var result = optionalTarget || new THREE.Vector3();
  3393. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3394. },
  3395. recast: function () {
  3396. var v1 = new THREE.Vector3();
  3397. return function ( t ) {
  3398. this.origin.copy( this.at( t, v1 ) );
  3399. return this;
  3400. };
  3401. }(),
  3402. closestPointToPoint: function ( point, optionalTarget ) {
  3403. var result = optionalTarget || new THREE.Vector3();
  3404. result.subVectors( point, this.origin );
  3405. var directionDistance = result.dot( this.direction );
  3406. if ( directionDistance < 0 ) {
  3407. return result.copy( this.origin );
  3408. }
  3409. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3410. },
  3411. distanceToPoint: function ( point ) {
  3412. return Math.sqrt( this.distanceSqToPoint( point ) );
  3413. },
  3414. distanceSqToPoint: function () {
  3415. var v1 = new THREE.Vector3();
  3416. return function ( point ) {
  3417. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3418. // point behind the ray
  3419. if ( directionDistance < 0 ) {
  3420. return this.origin.distanceToSquared( point );
  3421. }
  3422. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3423. return v1.distanceToSquared( point );
  3424. };
  3425. }(),
  3426. distanceSqToSegment: function () {
  3427. var segCenter = new THREE.Vector3();
  3428. var segDir = new THREE.Vector3();
  3429. var diff = new THREE.Vector3();
  3430. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3431. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3432. // It returns the min distance between the ray and the segment
  3433. // defined by v0 and v1
  3434. // It can also set two optional targets :
  3435. // - The closest point on the ray
  3436. // - The closest point on the segment
  3437. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3438. segDir.copy( v1 ).sub( v0 ).normalize();
  3439. diff.copy( this.origin ).sub( segCenter );
  3440. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3441. var a01 = - this.direction.dot( segDir );
  3442. var b0 = diff.dot( this.direction );
  3443. var b1 = - diff.dot( segDir );
  3444. var c = diff.lengthSq();
  3445. var det = Math.abs( 1 - a01 * a01 );
  3446. var s0, s1, sqrDist, extDet;
  3447. if ( det > 0 ) {
  3448. // The ray and segment are not parallel.
  3449. s0 = a01 * b1 - b0;
  3450. s1 = a01 * b0 - b1;
  3451. extDet = segExtent * det;
  3452. if ( s0 >= 0 ) {
  3453. if ( s1 >= - extDet ) {
  3454. if ( s1 <= extDet ) {
  3455. // region 0
  3456. // Minimum at interior points of ray and segment.
  3457. var invDet = 1 / det;
  3458. s0 *= invDet;
  3459. s1 *= invDet;
  3460. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3461. } else {
  3462. // region 1
  3463. s1 = segExtent;
  3464. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3465. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3466. }
  3467. } else {
  3468. // region 5
  3469. s1 = - segExtent;
  3470. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3471. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3472. }
  3473. } else {
  3474. if ( s1 <= - extDet ) {
  3475. // region 4
  3476. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3477. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3478. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3479. } else if ( s1 <= extDet ) {
  3480. // region 3
  3481. s0 = 0;
  3482. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3483. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3484. } else {
  3485. // region 2
  3486. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3487. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3488. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3489. }
  3490. }
  3491. } else {
  3492. // Ray and segment are parallel.
  3493. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3494. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3495. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3496. }
  3497. if ( optionalPointOnRay ) {
  3498. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3499. }
  3500. if ( optionalPointOnSegment ) {
  3501. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3502. }
  3503. return sqrDist;
  3504. };
  3505. }(),
  3506. isIntersectionSphere: function ( sphere ) {
  3507. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3508. },
  3509. intersectSphere: function () {
  3510. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3511. var v1 = new THREE.Vector3();
  3512. return function ( sphere, optionalTarget ) {
  3513. v1.subVectors( sphere.center, this.origin );
  3514. var tca = v1.dot( this.direction );
  3515. var d2 = v1.dot( v1 ) - tca * tca;
  3516. var radius2 = sphere.radius * sphere.radius;
  3517. if ( d2 > radius2 ) return null;
  3518. var thc = Math.sqrt( radius2 - d2 );
  3519. // t0 = first intersect point - entrance on front of sphere
  3520. var t0 = tca - thc;
  3521. // t1 = second intersect point - exit point on back of sphere
  3522. var t1 = tca + thc;
  3523. // test to see if both t0 and t1 are behind the ray - if so, return null
  3524. if ( t0 < 0 && t1 < 0 ) return null;
  3525. // test to see if t0 is behind the ray:
  3526. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3527. // in order to always return an intersect point that is in front of the ray.
  3528. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3529. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3530. return this.at( t0, optionalTarget );
  3531. }
  3532. }(),
  3533. isIntersectionPlane: function ( plane ) {
  3534. // check if the ray lies on the plane first
  3535. var distToPoint = plane.distanceToPoint( this.origin );
  3536. if ( distToPoint === 0 ) {
  3537. return true;
  3538. }
  3539. var denominator = plane.normal.dot( this.direction );
  3540. if ( denominator * distToPoint < 0 ) {
  3541. return true;
  3542. }
  3543. // ray origin is behind the plane (and is pointing behind it)
  3544. return false;
  3545. },
  3546. distanceToPlane: function ( plane ) {
  3547. var denominator = plane.normal.dot( this.direction );
  3548. if ( denominator === 0 ) {
  3549. // line is coplanar, return origin
  3550. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3551. return 0;
  3552. }
  3553. // Null is preferable to undefined since undefined means.... it is undefined
  3554. return null;
  3555. }
  3556. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3557. // Return if the ray never intersects the plane
  3558. return t >= 0 ? t : null;
  3559. },
  3560. intersectPlane: function ( plane, optionalTarget ) {
  3561. var t = this.distanceToPlane( plane );
  3562. if ( t === null ) {
  3563. return null;
  3564. }
  3565. return this.at( t, optionalTarget );
  3566. },
  3567. isIntersectionBox: function () {
  3568. var v = new THREE.Vector3();
  3569. return function ( box ) {
  3570. return this.intersectBox( box, v ) !== null;
  3571. };
  3572. }(),
  3573. intersectBox: function ( box, optionalTarget ) {
  3574. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3575. var tmin,tmax,tymin,tymax,tzmin,tzmax;
  3576. var invdirx = 1 / this.direction.x,
  3577. invdiry = 1 / this.direction.y,
  3578. invdirz = 1 / this.direction.z;
  3579. var origin = this.origin;
  3580. if ( invdirx >= 0 ) {
  3581. tmin = ( box.min.x - origin.x ) * invdirx;
  3582. tmax = ( box.max.x - origin.x ) * invdirx;
  3583. } else {
  3584. tmin = ( box.max.x - origin.x ) * invdirx;
  3585. tmax = ( box.min.x - origin.x ) * invdirx;
  3586. }
  3587. if ( invdiry >= 0 ) {
  3588. tymin = ( box.min.y - origin.y ) * invdiry;
  3589. tymax = ( box.max.y - origin.y ) * invdiry;
  3590. } else {
  3591. tymin = ( box.max.y - origin.y ) * invdiry;
  3592. tymax = ( box.min.y - origin.y ) * invdiry;
  3593. }
  3594. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3595. // These lines also handle the case where tmin or tmax is NaN
  3596. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3597. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3598. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3599. if ( invdirz >= 0 ) {
  3600. tzmin = ( box.min.z - origin.z ) * invdirz;
  3601. tzmax = ( box.max.z - origin.z ) * invdirz;
  3602. } else {
  3603. tzmin = ( box.max.z - origin.z ) * invdirz;
  3604. tzmax = ( box.min.z - origin.z ) * invdirz;
  3605. }
  3606. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3607. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3608. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3609. //return point closest to the ray (positive side)
  3610. if ( tmax < 0 ) return null;
  3611. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3612. },
  3613. intersectTriangle: function () {
  3614. // Compute the offset origin, edges, and normal.
  3615. var diff = new THREE.Vector3();
  3616. var edge1 = new THREE.Vector3();
  3617. var edge2 = new THREE.Vector3();
  3618. var normal = new THREE.Vector3();
  3619. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3620. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3621. edge1.subVectors( b, a );
  3622. edge2.subVectors( c, a );
  3623. normal.crossVectors( edge1, edge2 );
  3624. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3625. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3626. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3627. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3628. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3629. var DdN = this.direction.dot( normal );
  3630. var sign;
  3631. if ( DdN > 0 ) {
  3632. if ( backfaceCulling ) return null;
  3633. sign = 1;
  3634. } else if ( DdN < 0 ) {
  3635. sign = - 1;
  3636. DdN = - DdN;
  3637. } else {
  3638. return null;
  3639. }
  3640. diff.subVectors( this.origin, a );
  3641. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3642. // b1 < 0, no intersection
  3643. if ( DdQxE2 < 0 ) {
  3644. return null;
  3645. }
  3646. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3647. // b2 < 0, no intersection
  3648. if ( DdE1xQ < 0 ) {
  3649. return null;
  3650. }
  3651. // b1+b2 > 1, no intersection
  3652. if ( DdQxE2 + DdE1xQ > DdN ) {
  3653. return null;
  3654. }
  3655. // Line intersects triangle, check if ray does.
  3656. var QdN = - sign * diff.dot( normal );
  3657. // t < 0, no intersection
  3658. if ( QdN < 0 ) {
  3659. return null;
  3660. }
  3661. // Ray intersects triangle.
  3662. return this.at( QdN / DdN, optionalTarget );
  3663. };
  3664. }(),
  3665. applyMatrix4: function ( matrix4 ) {
  3666. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3667. this.origin.applyMatrix4( matrix4 );
  3668. this.direction.sub( this.origin );
  3669. this.direction.normalize();
  3670. return this;
  3671. },
  3672. equals: function ( ray ) {
  3673. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3674. },
  3675. clone: function () {
  3676. return new THREE.Ray().copy( this );
  3677. }
  3678. };
  3679. // File:src/math/Sphere.js
  3680. /**
  3681. * @author bhouston / http://exocortex.com
  3682. * @author mrdoob / http://mrdoob.com/
  3683. */
  3684. THREE.Sphere = function ( center, radius ) {
  3685. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3686. this.radius = ( radius !== undefined ) ? radius : 0;
  3687. };
  3688. THREE.Sphere.prototype = {
  3689. constructor: THREE.Sphere,
  3690. set: function ( center, radius ) {
  3691. this.center.copy( center );
  3692. this.radius = radius;
  3693. return this;
  3694. },
  3695. setFromPoints: function () {
  3696. var box = new THREE.Box3();
  3697. return function ( points, optionalCenter ) {
  3698. var center = this.center;
  3699. if ( optionalCenter !== undefined ) {
  3700. center.copy( optionalCenter );
  3701. } else {
  3702. box.setFromPoints( points ).center( center );
  3703. }
  3704. var maxRadiusSq = 0;
  3705. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3706. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3707. }
  3708. this.radius = Math.sqrt( maxRadiusSq );
  3709. return this;
  3710. };
  3711. }(),
  3712. copy: function ( sphere ) {
  3713. this.center.copy( sphere.center );
  3714. this.radius = sphere.radius;
  3715. return this;
  3716. },
  3717. empty: function () {
  3718. return ( this.radius <= 0 );
  3719. },
  3720. containsPoint: function ( point ) {
  3721. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3722. },
  3723. distanceToPoint: function ( point ) {
  3724. return ( point.distanceTo( this.center ) - this.radius );
  3725. },
  3726. intersectsSphere: function ( sphere ) {
  3727. var radiusSum = this.radius + sphere.radius;
  3728. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3729. },
  3730. clampPoint: function ( point, optionalTarget ) {
  3731. var deltaLengthSq = this.center.distanceToSquared( point );
  3732. var result = optionalTarget || new THREE.Vector3();
  3733. result.copy( point );
  3734. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3735. result.sub( this.center ).normalize();
  3736. result.multiplyScalar( this.radius ).add( this.center );
  3737. }
  3738. return result;
  3739. },
  3740. getBoundingBox: function ( optionalTarget ) {
  3741. var box = optionalTarget || new THREE.Box3();
  3742. box.set( this.center, this.center );
  3743. box.expandByScalar( this.radius );
  3744. return box;
  3745. },
  3746. applyMatrix4: function ( matrix ) {
  3747. this.center.applyMatrix4( matrix );
  3748. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3749. return this;
  3750. },
  3751. translate: function ( offset ) {
  3752. this.center.add( offset );
  3753. return this;
  3754. },
  3755. equals: function ( sphere ) {
  3756. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3757. },
  3758. clone: function () {
  3759. return new THREE.Sphere().copy( this );
  3760. }
  3761. };
  3762. // File:src/math/Frustum.js
  3763. /**
  3764. * @author mrdoob / http://mrdoob.com/
  3765. * @author alteredq / http://alteredqualia.com/
  3766. * @author bhouston / http://exocortex.com
  3767. */
  3768. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3769. this.planes = [
  3770. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3771. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3772. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3773. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3774. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3775. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3776. ];
  3777. };
  3778. THREE.Frustum.prototype = {
  3779. constructor: THREE.Frustum,
  3780. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3781. var planes = this.planes;
  3782. planes[ 0 ].copy( p0 );
  3783. planes[ 1 ].copy( p1 );
  3784. planes[ 2 ].copy( p2 );
  3785. planes[ 3 ].copy( p3 );
  3786. planes[ 4 ].copy( p4 );
  3787. planes[ 5 ].copy( p5 );
  3788. return this;
  3789. },
  3790. copy: function ( frustum ) {
  3791. var planes = this.planes;
  3792. for ( var i = 0; i < 6; i ++ ) {
  3793. planes[ i ].copy( frustum.planes[ i ] );
  3794. }
  3795. return this;
  3796. },
  3797. setFromMatrix: function ( m ) {
  3798. var planes = this.planes;
  3799. var me = m.elements;
  3800. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3801. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3802. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3803. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3804. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3805. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3806. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3807. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3808. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3809. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3810. return this;
  3811. },
  3812. intersectsObject: function () {
  3813. var sphere = new THREE.Sphere();
  3814. return function ( object ) {
  3815. var geometry = object.geometry;
  3816. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3817. sphere.copy( geometry.boundingSphere );
  3818. sphere.applyMatrix4( object.matrixWorld );
  3819. return this.intersectsSphere( sphere );
  3820. };
  3821. }(),
  3822. intersectsSphere: function ( sphere ) {
  3823. var planes = this.planes;
  3824. var center = sphere.center;
  3825. var negRadius = - sphere.radius;
  3826. for ( var i = 0; i < 6; i ++ ) {
  3827. var distance = planes[ i ].distanceToPoint( center );
  3828. if ( distance < negRadius ) {
  3829. return false;
  3830. }
  3831. }
  3832. return true;
  3833. },
  3834. intersectsBox: function () {
  3835. var p1 = new THREE.Vector3(),
  3836. p2 = new THREE.Vector3();
  3837. return function ( box ) {
  3838. var planes = this.planes;
  3839. for ( var i = 0; i < 6 ; i ++ ) {
  3840. var plane = planes[ i ];
  3841. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3842. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3843. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3844. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3845. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3846. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3847. var d1 = plane.distanceToPoint( p1 );
  3848. var d2 = plane.distanceToPoint( p2 );
  3849. // if both outside plane, no intersection
  3850. if ( d1 < 0 && d2 < 0 ) {
  3851. return false;
  3852. }
  3853. }
  3854. return true;
  3855. };
  3856. }(),
  3857. containsPoint: function ( point ) {
  3858. var planes = this.planes;
  3859. for ( var i = 0; i < 6; i ++ ) {
  3860. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3861. return false;
  3862. }
  3863. }
  3864. return true;
  3865. },
  3866. clone: function () {
  3867. return new THREE.Frustum().copy( this );
  3868. }
  3869. };
  3870. // File:src/math/Plane.js
  3871. /**
  3872. * @author bhouston / http://exocortex.com
  3873. */
  3874. THREE.Plane = function ( normal, constant ) {
  3875. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3876. this.constant = ( constant !== undefined ) ? constant : 0;
  3877. };
  3878. THREE.Plane.prototype = {
  3879. constructor: THREE.Plane,
  3880. set: function ( normal, constant ) {
  3881. this.normal.copy( normal );
  3882. this.constant = constant;
  3883. return this;
  3884. },
  3885. setComponents: function ( x, y, z, w ) {
  3886. this.normal.set( x, y, z );
  3887. this.constant = w;
  3888. return this;
  3889. },
  3890. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3891. this.normal.copy( normal );
  3892. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3893. return this;
  3894. },
  3895. setFromCoplanarPoints: function () {
  3896. var v1 = new THREE.Vector3();
  3897. var v2 = new THREE.Vector3();
  3898. return function ( a, b, c ) {
  3899. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3900. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3901. this.setFromNormalAndCoplanarPoint( normal, a );
  3902. return this;
  3903. };
  3904. }(),
  3905. copy: function ( plane ) {
  3906. this.normal.copy( plane.normal );
  3907. this.constant = plane.constant;
  3908. return this;
  3909. },
  3910. normalize: function () {
  3911. // Note: will lead to a divide by zero if the plane is invalid.
  3912. var inverseNormalLength = 1.0 / this.normal.length();
  3913. this.normal.multiplyScalar( inverseNormalLength );
  3914. this.constant *= inverseNormalLength;
  3915. return this;
  3916. },
  3917. negate: function () {
  3918. this.constant *= - 1;
  3919. this.normal.negate();
  3920. return this;
  3921. },
  3922. distanceToPoint: function ( point ) {
  3923. return this.normal.dot( point ) + this.constant;
  3924. },
  3925. distanceToSphere: function ( sphere ) {
  3926. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3927. },
  3928. projectPoint: function ( point, optionalTarget ) {
  3929. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3930. },
  3931. orthoPoint: function ( point, optionalTarget ) {
  3932. var perpendicularMagnitude = this.distanceToPoint( point );
  3933. var result = optionalTarget || new THREE.Vector3();
  3934. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3935. },
  3936. isIntersectionLine: function ( line ) {
  3937. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3938. var startSign = this.distanceToPoint( line.start );
  3939. var endSign = this.distanceToPoint( line.end );
  3940. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3941. },
  3942. intersectLine: function () {
  3943. var v1 = new THREE.Vector3();
  3944. return function ( line, optionalTarget ) {
  3945. var result = optionalTarget || new THREE.Vector3();
  3946. var direction = line.delta( v1 );
  3947. var denominator = this.normal.dot( direction );
  3948. if ( denominator === 0 ) {
  3949. // line is coplanar, return origin
  3950. if ( this.distanceToPoint( line.start ) === 0 ) {
  3951. return result.copy( line.start );
  3952. }
  3953. // Unsure if this is the correct method to handle this case.
  3954. return undefined;
  3955. }
  3956. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3957. if ( t < 0 || t > 1 ) {
  3958. return undefined;
  3959. }
  3960. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3961. };
  3962. }(),
  3963. coplanarPoint: function ( optionalTarget ) {
  3964. var result = optionalTarget || new THREE.Vector3();
  3965. return result.copy( this.normal ).multiplyScalar( - this.constant );
  3966. },
  3967. applyMatrix4: function () {
  3968. var v1 = new THREE.Vector3();
  3969. var v2 = new THREE.Vector3();
  3970. var m1 = new THREE.Matrix3();
  3971. return function ( matrix, optionalNormalMatrix ) {
  3972. // compute new normal based on theory here:
  3973. // http://www.songho.ca/opengl/gl_normaltransform.html
  3974. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  3975. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  3976. var newCoplanarPoint = this.coplanarPoint( v2 );
  3977. newCoplanarPoint.applyMatrix4( matrix );
  3978. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  3979. return this;
  3980. };
  3981. }(),
  3982. translate: function ( offset ) {
  3983. this.constant = this.constant - offset.dot( this.normal );
  3984. return this;
  3985. },
  3986. equals: function ( plane ) {
  3987. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  3988. },
  3989. clone: function () {
  3990. return new THREE.Plane().copy( this );
  3991. }
  3992. };
  3993. // File:src/math/Math.js
  3994. /**
  3995. * @author alteredq / http://alteredqualia.com/
  3996. * @author mrdoob / http://mrdoob.com/
  3997. */
  3998. THREE.Math = {
  3999. generateUUID: function () {
  4000. // http://www.broofa.com/Tools/Math.uuid.htm
  4001. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4002. var uuid = new Array( 36 );
  4003. var rnd = 0, r;
  4004. return function () {
  4005. for ( var i = 0; i < 36; i ++ ) {
  4006. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4007. uuid[ i ] = '-';
  4008. } else if ( i === 14 ) {
  4009. uuid[ i ] = '4';
  4010. } else {
  4011. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4012. r = rnd & 0xf;
  4013. rnd = rnd >> 4;
  4014. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4015. }
  4016. }
  4017. return uuid.join( '' );
  4018. };
  4019. }(),
  4020. // Clamp value to range <a, b>
  4021. clamp: function ( x, a, b ) {
  4022. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  4023. },
  4024. // Clamp value to range <a, inf)
  4025. clampBottom: function ( x, a ) {
  4026. return x < a ? a : x;
  4027. },
  4028. // compute euclidian modulo of m % n
  4029. // https://en.wikipedia.org/wiki/Modulo_operation
  4030. euclideanModulo: function ( n, m ) {
  4031. return ( ( n % m ) + m ) % m;
  4032. },
  4033. // Linear mapping from range <a1, a2> to range <b1, b2>
  4034. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4035. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4036. },
  4037. // http://en.wikipedia.org/wiki/Smoothstep
  4038. smoothstep: function ( x, min, max ) {
  4039. if ( x <= min ) return 0;
  4040. if ( x >= max ) return 1;
  4041. x = ( x - min ) / ( max - min );
  4042. return x * x * ( 3 - 2 * x );
  4043. },
  4044. smootherstep: function ( x, min, max ) {
  4045. if ( x <= min ) return 0;
  4046. if ( x >= max ) return 1;
  4047. x = ( x - min ) / ( max - min );
  4048. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4049. },
  4050. // Random float from <0, 1> with 16 bits of randomness
  4051. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4052. random16: function () {
  4053. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4054. },
  4055. // Random integer from <low, high> interval
  4056. randInt: function ( low, high ) {
  4057. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4058. },
  4059. // Random float from <low, high> interval
  4060. randFloat: function ( low, high ) {
  4061. return low + Math.random() * ( high - low );
  4062. },
  4063. // Random float from <-range/2, range/2> interval
  4064. randFloatSpread: function ( range ) {
  4065. return range * ( 0.5 - Math.random() );
  4066. },
  4067. degToRad: function () {
  4068. var degreeToRadiansFactor = Math.PI / 180;
  4069. return function ( degrees ) {
  4070. return degrees * degreeToRadiansFactor;
  4071. };
  4072. }(),
  4073. radToDeg: function () {
  4074. var radianToDegreesFactor = 180 / Math.PI;
  4075. return function ( radians ) {
  4076. return radians * radianToDegreesFactor;
  4077. };
  4078. }(),
  4079. isPowerOfTwo: function ( value ) {
  4080. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4081. },
  4082. nextPowerOfTwo: function ( value ) {
  4083. value --;
  4084. value |= value >> 1;
  4085. value |= value >> 2;
  4086. value |= value >> 4;
  4087. value |= value >> 8;
  4088. value |= value >> 16;
  4089. value ++;
  4090. return value;
  4091. }
  4092. };
  4093. // File:src/math/Spline.js
  4094. /**
  4095. * Spline from Tween.js, slightly optimized (and trashed)
  4096. * http://sole.github.com/tween.js/examples/05_spline.html
  4097. *
  4098. * @author mrdoob / http://mrdoob.com/
  4099. * @author alteredq / http://alteredqualia.com/
  4100. */
  4101. THREE.Spline = function ( points ) {
  4102. this.points = points;
  4103. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4104. point, intPoint, weight, w2, w3,
  4105. pa, pb, pc, pd;
  4106. this.initFromArray = function ( a ) {
  4107. this.points = [];
  4108. for ( var i = 0; i < a.length; i ++ ) {
  4109. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4110. }
  4111. };
  4112. this.getPoint = function ( k ) {
  4113. point = ( this.points.length - 1 ) * k;
  4114. intPoint = Math.floor( point );
  4115. weight = point - intPoint;
  4116. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4117. c[ 1 ] = intPoint;
  4118. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4119. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4120. pa = this.points[ c[ 0 ] ];
  4121. pb = this.points[ c[ 1 ] ];
  4122. pc = this.points[ c[ 2 ] ];
  4123. pd = this.points[ c[ 3 ] ];
  4124. w2 = weight * weight;
  4125. w3 = weight * w2;
  4126. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4127. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4128. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4129. return v3;
  4130. };
  4131. this.getControlPointsArray = function () {
  4132. var i, p, l = this.points.length,
  4133. coords = [];
  4134. for ( i = 0; i < l; i ++ ) {
  4135. p = this.points[ i ];
  4136. coords[ i ] = [ p.x, p.y, p.z ];
  4137. }
  4138. return coords;
  4139. };
  4140. // approximate length by summing linear segments
  4141. this.getLength = function ( nSubDivisions ) {
  4142. var i, index, nSamples, position,
  4143. point = 0, intPoint = 0, oldIntPoint = 0,
  4144. oldPosition = new THREE.Vector3(),
  4145. tmpVec = new THREE.Vector3(),
  4146. chunkLengths = [],
  4147. totalLength = 0;
  4148. // first point has 0 length
  4149. chunkLengths[ 0 ] = 0;
  4150. if ( ! nSubDivisions ) nSubDivisions = 100;
  4151. nSamples = this.points.length * nSubDivisions;
  4152. oldPosition.copy( this.points[ 0 ] );
  4153. for ( i = 1; i < nSamples; i ++ ) {
  4154. index = i / nSamples;
  4155. position = this.getPoint( index );
  4156. tmpVec.copy( position );
  4157. totalLength += tmpVec.distanceTo( oldPosition );
  4158. oldPosition.copy( position );
  4159. point = ( this.points.length - 1 ) * index;
  4160. intPoint = Math.floor( point );
  4161. if ( intPoint !== oldIntPoint ) {
  4162. chunkLengths[ intPoint ] = totalLength;
  4163. oldIntPoint = intPoint;
  4164. }
  4165. }
  4166. // last point ends with total length
  4167. chunkLengths[ chunkLengths.length ] = totalLength;
  4168. return { chunks: chunkLengths, total: totalLength };
  4169. };
  4170. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4171. var i, j,
  4172. index, indexCurrent, indexNext,
  4173. realDistance,
  4174. sampling, position,
  4175. newpoints = [],
  4176. tmpVec = new THREE.Vector3(),
  4177. sl = this.getLength();
  4178. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4179. for ( i = 1; i < this.points.length; i ++ ) {
  4180. //tmpVec.copy( this.points[ i - 1 ] );
  4181. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4182. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4183. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4184. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4185. indexNext = i / ( this.points.length - 1 );
  4186. for ( j = 1; j < sampling - 1; j ++ ) {
  4187. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4188. position = this.getPoint( index );
  4189. newpoints.push( tmpVec.copy( position ).clone() );
  4190. }
  4191. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4192. }
  4193. this.points = newpoints;
  4194. };
  4195. // Catmull-Rom
  4196. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4197. var v0 = ( p2 - p0 ) * 0.5,
  4198. v1 = ( p3 - p1 ) * 0.5;
  4199. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4200. }
  4201. };
  4202. // File:src/math/Triangle.js
  4203. /**
  4204. * @author bhouston / http://exocortex.com
  4205. * @author mrdoob / http://mrdoob.com/
  4206. */
  4207. THREE.Triangle = function ( a, b, c ) {
  4208. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4209. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4210. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4211. };
  4212. THREE.Triangle.normal = function () {
  4213. var v0 = new THREE.Vector3();
  4214. return function ( a, b, c, optionalTarget ) {
  4215. var result = optionalTarget || new THREE.Vector3();
  4216. result.subVectors( c, b );
  4217. v0.subVectors( a, b );
  4218. result.cross( v0 );
  4219. var resultLengthSq = result.lengthSq();
  4220. if ( resultLengthSq > 0 ) {
  4221. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4222. }
  4223. return result.set( 0, 0, 0 );
  4224. };
  4225. }();
  4226. // static/instance method to calculate barycentric coordinates
  4227. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4228. THREE.Triangle.barycoordFromPoint = function () {
  4229. var v0 = new THREE.Vector3();
  4230. var v1 = new THREE.Vector3();
  4231. var v2 = new THREE.Vector3();
  4232. return function ( point, a, b, c, optionalTarget ) {
  4233. v0.subVectors( c, a );
  4234. v1.subVectors( b, a );
  4235. v2.subVectors( point, a );
  4236. var dot00 = v0.dot( v0 );
  4237. var dot01 = v0.dot( v1 );
  4238. var dot02 = v0.dot( v2 );
  4239. var dot11 = v1.dot( v1 );
  4240. var dot12 = v1.dot( v2 );
  4241. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4242. var result = optionalTarget || new THREE.Vector3();
  4243. // collinear or singular triangle
  4244. if ( denom === 0 ) {
  4245. // arbitrary location outside of triangle?
  4246. // not sure if this is the best idea, maybe should be returning undefined
  4247. return result.set( - 2, - 1, - 1 );
  4248. }
  4249. var invDenom = 1 / denom;
  4250. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4251. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4252. // barycentric coordinates must always sum to 1
  4253. return result.set( 1 - u - v, v, u );
  4254. };
  4255. }();
  4256. THREE.Triangle.containsPoint = function () {
  4257. var v1 = new THREE.Vector3();
  4258. return function ( point, a, b, c ) {
  4259. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4260. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4261. };
  4262. }();
  4263. THREE.Triangle.prototype = {
  4264. constructor: THREE.Triangle,
  4265. set: function ( a, b, c ) {
  4266. this.a.copy( a );
  4267. this.b.copy( b );
  4268. this.c.copy( c );
  4269. return this;
  4270. },
  4271. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4272. this.a.copy( points[ i0 ] );
  4273. this.b.copy( points[ i1 ] );
  4274. this.c.copy( points[ i2 ] );
  4275. return this;
  4276. },
  4277. copy: function ( triangle ) {
  4278. this.a.copy( triangle.a );
  4279. this.b.copy( triangle.b );
  4280. this.c.copy( triangle.c );
  4281. return this;
  4282. },
  4283. area: function () {
  4284. var v0 = new THREE.Vector3();
  4285. var v1 = new THREE.Vector3();
  4286. return function () {
  4287. v0.subVectors( this.c, this.b );
  4288. v1.subVectors( this.a, this.b );
  4289. return v0.cross( v1 ).length() * 0.5;
  4290. };
  4291. }(),
  4292. midpoint: function ( optionalTarget ) {
  4293. var result = optionalTarget || new THREE.Vector3();
  4294. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4295. },
  4296. normal: function ( optionalTarget ) {
  4297. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4298. },
  4299. plane: function ( optionalTarget ) {
  4300. var result = optionalTarget || new THREE.Plane();
  4301. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4302. },
  4303. barycoordFromPoint: function ( point, optionalTarget ) {
  4304. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4305. },
  4306. containsPoint: function ( point ) {
  4307. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4308. },
  4309. equals: function ( triangle ) {
  4310. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4311. },
  4312. clone: function () {
  4313. return new THREE.Triangle().copy( this );
  4314. }
  4315. };
  4316. // File:src/core/Clock.js
  4317. /**
  4318. * @author alteredq / http://alteredqualia.com/
  4319. */
  4320. THREE.Clock = function ( autoStart ) {
  4321. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4322. this.startTime = 0;
  4323. this.oldTime = 0;
  4324. this.elapsedTime = 0;
  4325. this.running = false;
  4326. };
  4327. THREE.Clock.prototype = {
  4328. constructor: THREE.Clock,
  4329. start: function () {
  4330. this.startTime = self.performance !== undefined && self.performance.now !== undefined
  4331. ? self.performance.now()
  4332. : Date.now();
  4333. this.oldTime = this.startTime;
  4334. this.running = true;
  4335. },
  4336. stop: function () {
  4337. this.getElapsedTime();
  4338. this.running = false;
  4339. },
  4340. getElapsedTime: function () {
  4341. this.getDelta();
  4342. return this.elapsedTime;
  4343. },
  4344. getDelta: function () {
  4345. var diff = 0;
  4346. if ( this.autoStart && ! this.running ) {
  4347. this.start();
  4348. }
  4349. if ( this.running ) {
  4350. var newTime = self.performance !== undefined && self.performance.now !== undefined
  4351. ? self.performance.now()
  4352. : Date.now();
  4353. diff = 0.001 * ( newTime - this.oldTime );
  4354. this.oldTime = newTime;
  4355. this.elapsedTime += diff;
  4356. }
  4357. return diff;
  4358. }
  4359. };
  4360. // File:src/core/EventDispatcher.js
  4361. /**
  4362. * https://github.com/mrdoob/eventdispatcher.js/
  4363. */
  4364. THREE.EventDispatcher = function () {};
  4365. THREE.EventDispatcher.prototype = {
  4366. constructor: THREE.EventDispatcher,
  4367. apply: function ( object ) {
  4368. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4369. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4370. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4371. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4372. },
  4373. addEventListener: function ( type, listener ) {
  4374. if ( this._listeners === undefined ) this._listeners = {};
  4375. var listeners = this._listeners;
  4376. if ( listeners[ type ] === undefined ) {
  4377. listeners[ type ] = [];
  4378. }
  4379. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4380. listeners[ type ].push( listener );
  4381. }
  4382. },
  4383. hasEventListener: function ( type, listener ) {
  4384. if ( this._listeners === undefined ) return false;
  4385. var listeners = this._listeners;
  4386. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4387. return true;
  4388. }
  4389. return false;
  4390. },
  4391. removeEventListener: function ( type, listener ) {
  4392. if ( this._listeners === undefined ) return;
  4393. var listeners = this._listeners;
  4394. var listenerArray = listeners[ type ];
  4395. if ( listenerArray !== undefined ) {
  4396. var index = listenerArray.indexOf( listener );
  4397. if ( index !== - 1 ) {
  4398. listenerArray.splice( index, 1 );
  4399. }
  4400. }
  4401. },
  4402. dispatchEvent: function ( event ) {
  4403. if ( this._listeners === undefined ) return;
  4404. var listeners = this._listeners;
  4405. var listenerArray = listeners[ event.type ];
  4406. if ( listenerArray !== undefined ) {
  4407. event.target = this;
  4408. var array = [];
  4409. var length = listenerArray.length;
  4410. for ( var i = 0; i < length; i ++ ) {
  4411. array[ i ] = listenerArray[ i ];
  4412. }
  4413. for ( var i = 0; i < length; i ++ ) {
  4414. array[ i ].call( this, event );
  4415. }
  4416. }
  4417. }
  4418. };
  4419. // File:src/core/Raycaster.js
  4420. /**
  4421. * @author mrdoob / http://mrdoob.com/
  4422. * @author bhouston / http://exocortex.com/
  4423. * @author stephomi / http://stephaneginier.com/
  4424. */
  4425. ( function ( THREE ) {
  4426. THREE.Raycaster = function ( origin, direction, near, far ) {
  4427. this.ray = new THREE.Ray( origin, direction );
  4428. // direction is assumed to be normalized (for accurate distance calculations)
  4429. this.near = near || 0;
  4430. this.far = far || Infinity;
  4431. this.params = {
  4432. Sprite: {},
  4433. Mesh: {},
  4434. PointCloud: { threshold: 1 },
  4435. LOD: {},
  4436. Line: {}
  4437. };
  4438. };
  4439. var descSort = function ( a, b ) {
  4440. return a.distance - b.distance;
  4441. };
  4442. var intersectObject = function ( object, raycaster, intersects, recursive ) {
  4443. if ( object.visible === false ) return;
  4444. object.raycast( raycaster, intersects );
  4445. if ( recursive === true ) {
  4446. var children = object.children;
  4447. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4448. intersectObject( children[ i ], raycaster, intersects, true );
  4449. }
  4450. }
  4451. };
  4452. //
  4453. THREE.Raycaster.prototype = {
  4454. constructor: THREE.Raycaster,
  4455. linePrecision: 1,
  4456. set: function ( origin, direction ) {
  4457. // direction is assumed to be normalized (for accurate distance calculations)
  4458. this.ray.set( origin, direction );
  4459. },
  4460. setFromCamera: function ( coords, camera ) {
  4461. if ( camera instanceof THREE.PerspectiveCamera ) {
  4462. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4463. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4464. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4465. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4466. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4467. } else {
  4468. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4469. }
  4470. },
  4471. intersectObject: function ( object, recursive ) {
  4472. var intersects = [];
  4473. intersectObject( object, this, intersects, recursive );
  4474. intersects.sort( descSort );
  4475. return intersects;
  4476. },
  4477. intersectObjects: function ( objects, recursive ) {
  4478. var intersects = [];
  4479. if ( Array.isArray( objects ) === false ) {
  4480. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4481. return intersects;
  4482. }
  4483. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4484. intersectObject( objects[ i ], this, intersects, recursive );
  4485. }
  4486. intersects.sort( descSort );
  4487. return intersects;
  4488. }
  4489. };
  4490. }( THREE ) );
  4491. // File:src/core/Object3D.js
  4492. /**
  4493. * @author mrdoob / http://mrdoob.com/
  4494. * @author mikael emtinger / http://gomo.se/
  4495. * @author alteredq / http://alteredqualia.com/
  4496. * @author WestLangley / http://github.com/WestLangley
  4497. * @author elephantatwork / www.elephantatwork.ch
  4498. */
  4499. THREE.Object3D = function () {
  4500. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4501. this.uuid = THREE.Math.generateUUID();
  4502. this.name = '';
  4503. this.type = 'Object3D';
  4504. this.parent = undefined;
  4505. this.children = [];
  4506. this.up = THREE.Object3D.DefaultUp.clone();
  4507. var position = new THREE.Vector3();
  4508. var rotation = new THREE.Euler();
  4509. var quaternion = new THREE.Quaternion();
  4510. var scale = new THREE.Vector3( 1, 1, 1 );
  4511. var onRotationChange = function () {
  4512. quaternion.setFromEuler( rotation, false );
  4513. };
  4514. var onQuaternionChange = function () {
  4515. rotation.setFromQuaternion( quaternion, undefined, false );
  4516. };
  4517. rotation.onChange( onRotationChange );
  4518. quaternion.onChange( onQuaternionChange );
  4519. Object.defineProperties( this, {
  4520. position: {
  4521. enumerable: true,
  4522. value: position
  4523. },
  4524. rotation: {
  4525. enumerable: true,
  4526. value: rotation
  4527. },
  4528. quaternion: {
  4529. enumerable: true,
  4530. value: quaternion
  4531. },
  4532. scale: {
  4533. enumerable: true,
  4534. value: scale
  4535. }
  4536. } );
  4537. this.rotationAutoUpdate = true;
  4538. this.matrix = new THREE.Matrix4();
  4539. this.matrixWorld = new THREE.Matrix4();
  4540. this.matrixAutoUpdate = true;
  4541. this.matrixWorldNeedsUpdate = false;
  4542. this.visible = true;
  4543. this.castShadow = false;
  4544. this.receiveShadow = false;
  4545. this.frustumCulled = true;
  4546. this.renderOrder = 0;
  4547. this.userData = {};
  4548. };
  4549. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4550. THREE.Object3D.prototype = {
  4551. constructor: THREE.Object3D,
  4552. get eulerOrder () {
  4553. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4554. return this.rotation.order;
  4555. },
  4556. set eulerOrder ( value ) {
  4557. console.warn( 'THREE.Object3D: .eulerOrder has been moved to .rotation.order.' );
  4558. this.rotation.order = value;
  4559. },
  4560. get useQuaternion () {
  4561. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4562. },
  4563. set useQuaternion ( value ) {
  4564. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4565. },
  4566. set renderDepth ( value ) {
  4567. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4568. },
  4569. applyMatrix: function ( matrix ) {
  4570. this.matrix.multiplyMatrices( matrix, this.matrix );
  4571. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4572. },
  4573. setRotationFromAxisAngle: function ( axis, angle ) {
  4574. // assumes axis is normalized
  4575. this.quaternion.setFromAxisAngle( axis, angle );
  4576. },
  4577. setRotationFromEuler: function ( euler ) {
  4578. this.quaternion.setFromEuler( euler, true );
  4579. },
  4580. setRotationFromMatrix: function ( m ) {
  4581. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4582. this.quaternion.setFromRotationMatrix( m );
  4583. },
  4584. setRotationFromQuaternion: function ( q ) {
  4585. // assumes q is normalized
  4586. this.quaternion.copy( q );
  4587. },
  4588. rotateOnAxis: function () {
  4589. // rotate object on axis in object space
  4590. // axis is assumed to be normalized
  4591. var q1 = new THREE.Quaternion();
  4592. return function ( axis, angle ) {
  4593. q1.setFromAxisAngle( axis, angle );
  4594. this.quaternion.multiply( q1 );
  4595. return this;
  4596. }
  4597. }(),
  4598. rotateX: function () {
  4599. var v1 = new THREE.Vector3( 1, 0, 0 );
  4600. return function ( angle ) {
  4601. return this.rotateOnAxis( v1, angle );
  4602. };
  4603. }(),
  4604. rotateY: function () {
  4605. var v1 = new THREE.Vector3( 0, 1, 0 );
  4606. return function ( angle ) {
  4607. return this.rotateOnAxis( v1, angle );
  4608. };
  4609. }(),
  4610. rotateZ: function () {
  4611. var v1 = new THREE.Vector3( 0, 0, 1 );
  4612. return function ( angle ) {
  4613. return this.rotateOnAxis( v1, angle );
  4614. };
  4615. }(),
  4616. translateOnAxis: function () {
  4617. // translate object by distance along axis in object space
  4618. // axis is assumed to be normalized
  4619. var v1 = new THREE.Vector3();
  4620. return function ( axis, distance ) {
  4621. v1.copy( axis ).applyQuaternion( this.quaternion );
  4622. this.position.add( v1.multiplyScalar( distance ) );
  4623. return this;
  4624. }
  4625. }(),
  4626. translate: function ( distance, axis ) {
  4627. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4628. return this.translateOnAxis( axis, distance );
  4629. },
  4630. translateX: function () {
  4631. var v1 = new THREE.Vector3( 1, 0, 0 );
  4632. return function ( distance ) {
  4633. return this.translateOnAxis( v1, distance );
  4634. };
  4635. }(),
  4636. translateY: function () {
  4637. var v1 = new THREE.Vector3( 0, 1, 0 );
  4638. return function ( distance ) {
  4639. return this.translateOnAxis( v1, distance );
  4640. };
  4641. }(),
  4642. translateZ: function () {
  4643. var v1 = new THREE.Vector3( 0, 0, 1 );
  4644. return function ( distance ) {
  4645. return this.translateOnAxis( v1, distance );
  4646. };
  4647. }(),
  4648. localToWorld: function ( vector ) {
  4649. return vector.applyMatrix4( this.matrixWorld );
  4650. },
  4651. worldToLocal: function () {
  4652. var m1 = new THREE.Matrix4();
  4653. return function ( vector ) {
  4654. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4655. };
  4656. }(),
  4657. lookAt: function () {
  4658. // This routine does not support objects with rotated and/or translated parent(s)
  4659. var m1 = new THREE.Matrix4();
  4660. return function ( vector ) {
  4661. m1.lookAt( vector, this.position, this.up );
  4662. this.quaternion.setFromRotationMatrix( m1 );
  4663. };
  4664. }(),
  4665. add: function ( object ) {
  4666. if ( arguments.length > 1 ) {
  4667. for ( var i = 0; i < arguments.length; i ++ ) {
  4668. this.add( arguments[ i ] );
  4669. }
  4670. return this;
  4671. }
  4672. if ( object === this ) {
  4673. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4674. return this;
  4675. }
  4676. if ( object instanceof THREE.Object3D ) {
  4677. if ( object.parent !== undefined ) {
  4678. object.parent.remove( object );
  4679. }
  4680. object.parent = this;
  4681. object.dispatchEvent( { type: 'added' } );
  4682. this.children.push( object );
  4683. } else {
  4684. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4685. }
  4686. return this;
  4687. },
  4688. remove: function ( object ) {
  4689. if ( arguments.length > 1 ) {
  4690. for ( var i = 0; i < arguments.length; i ++ ) {
  4691. this.remove( arguments[ i ] );
  4692. }
  4693. }
  4694. var index = this.children.indexOf( object );
  4695. if ( index !== - 1 ) {
  4696. object.parent = undefined;
  4697. object.dispatchEvent( { type: 'removed' } );
  4698. this.children.splice( index, 1 );
  4699. }
  4700. },
  4701. getChildByName: function ( name ) {
  4702. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4703. return this.getObjectByName( name );
  4704. },
  4705. getObjectById: function ( id ) {
  4706. return this.getObjectByProperty( 'id', id );
  4707. },
  4708. getObjectByName: function ( name ) {
  4709. return this.getObjectByProperty( 'name', name );
  4710. },
  4711. getObjectByProperty: function ( name, value ) {
  4712. if ( this[ name ] === value ) return this;
  4713. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4714. var child = this.children[ i ];
  4715. var object = child.getObjectByProperty( name, value );
  4716. if ( object !== undefined ) {
  4717. return object;
  4718. }
  4719. }
  4720. return undefined;
  4721. },
  4722. getWorldPosition: function ( optionalTarget ) {
  4723. var result = optionalTarget || new THREE.Vector3();
  4724. this.updateMatrixWorld( true );
  4725. return result.setFromMatrixPosition( this.matrixWorld );
  4726. },
  4727. getWorldQuaternion: function () {
  4728. var position = new THREE.Vector3();
  4729. var scale = new THREE.Vector3();
  4730. return function ( optionalTarget ) {
  4731. var result = optionalTarget || new THREE.Quaternion();
  4732. this.updateMatrixWorld( true );
  4733. this.matrixWorld.decompose( position, result, scale );
  4734. return result;
  4735. }
  4736. }(),
  4737. getWorldRotation: function () {
  4738. var quaternion = new THREE.Quaternion();
  4739. return function ( optionalTarget ) {
  4740. var result = optionalTarget || new THREE.Euler();
  4741. this.getWorldQuaternion( quaternion );
  4742. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4743. }
  4744. }(),
  4745. getWorldScale: function () {
  4746. var position = new THREE.Vector3();
  4747. var quaternion = new THREE.Quaternion();
  4748. return function ( optionalTarget ) {
  4749. var result = optionalTarget || new THREE.Vector3();
  4750. this.updateMatrixWorld( true );
  4751. this.matrixWorld.decompose( position, quaternion, result );
  4752. return result;
  4753. }
  4754. }(),
  4755. getWorldDirection: function () {
  4756. var quaternion = new THREE.Quaternion();
  4757. return function ( optionalTarget ) {
  4758. var result = optionalTarget || new THREE.Vector3();
  4759. this.getWorldQuaternion( quaternion );
  4760. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4761. }
  4762. }(),
  4763. raycast: function () {},
  4764. traverse: function ( callback ) {
  4765. callback( this );
  4766. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4767. this.children[ i ].traverse( callback );
  4768. }
  4769. },
  4770. traverseVisible: function ( callback ) {
  4771. if ( this.visible === false ) return;
  4772. callback( this );
  4773. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4774. this.children[ i ].traverseVisible( callback );
  4775. }
  4776. },
  4777. traverseAncestors: function ( callback ) {
  4778. if ( this.parent ) {
  4779. callback( this.parent );
  4780. this.parent.traverseAncestors( callback );
  4781. }
  4782. },
  4783. updateMatrix: function () {
  4784. this.matrix.compose( this.position, this.quaternion, this.scale );
  4785. this.matrixWorldNeedsUpdate = true;
  4786. },
  4787. updateMatrixWorld: function ( force ) {
  4788. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4789. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4790. if ( this.parent === undefined ) {
  4791. this.matrixWorld.copy( this.matrix );
  4792. } else {
  4793. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4794. }
  4795. this.matrixWorldNeedsUpdate = false;
  4796. force = true;
  4797. }
  4798. // update children
  4799. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4800. this.children[ i ].updateMatrixWorld( force );
  4801. }
  4802. },
  4803. toJSON: function ( meta ) {
  4804. var isRootObject = ( meta === undefined );
  4805. var data = {};
  4806. // meta is a hash used to collect geometries, materials.
  4807. // not providing it implies that this is the root object
  4808. // being serialized.
  4809. if ( isRootObject ) {
  4810. // initialize meta obj
  4811. meta = {
  4812. geometries: {},
  4813. materials: {},
  4814. textures: {},
  4815. images: {}
  4816. };
  4817. data.metadata = {
  4818. version: 4.4,
  4819. type: 'Object',
  4820. generator: 'Object3D.toJSON'
  4821. };
  4822. }
  4823. // standard Object3D serialization
  4824. data.uuid = this.uuid;
  4825. data.type = this.type;
  4826. if ( this.name !== '' ) data.name = this.name;
  4827. if ( JSON.stringify( this.userData ) !== '{}' ) data.userData = this.userData;
  4828. if ( this.visible !== true ) data.visible = this.visible;
  4829. data.matrix = this.matrix.toArray();
  4830. if ( this.children.length > 0 ) {
  4831. data.children = [];
  4832. for ( var i = 0; i < this.children.length; i ++ ) {
  4833. data.children.push( this.children[ i ].toJSON( meta ).object );
  4834. }
  4835. }
  4836. var output = {};
  4837. if ( isRootObject ) {
  4838. var geometries = extractFromCache( meta.geometries );
  4839. var materials = extractFromCache( meta.materials );
  4840. var textures = extractFromCache( meta.textures );
  4841. var images = extractFromCache( meta.images );
  4842. if ( geometries.length > 0 ) output.geometries = geometries;
  4843. if ( materials.length > 0 ) output.materials = materials;
  4844. if ( textures.length > 0 ) output.textures = textures;
  4845. if ( images.length > 0 ) output.images = images;
  4846. }
  4847. output.object = data;
  4848. return output;
  4849. // extract data from the cache hash
  4850. // remove metadata on each item
  4851. // and return as array
  4852. function extractFromCache ( cache ) {
  4853. var values = [];
  4854. for ( var key in cache ) {
  4855. var data = cache[ key ];
  4856. delete data.metadata;
  4857. values.push( data );
  4858. }
  4859. return values;
  4860. }
  4861. },
  4862. clone: function ( recursive ) {
  4863. var object = new THREE.Object3D();
  4864. return object.copy( this, recursive );
  4865. },
  4866. copy: function ( source, recursive ) {
  4867. if ( recursive === undefined ) recursive = true;
  4868. this.name = source.name;
  4869. this.up.copy( source.up );
  4870. this.position.copy( source.position );
  4871. this.quaternion.copy( source.quaternion );
  4872. this.scale.copy( source.scale );
  4873. this.rotationAutoUpdate = source.rotationAutoUpdate;
  4874. this.matrix.copy( source.matrix );
  4875. this.matrixWorld.copy( source.matrixWorld );
  4876. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4877. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4878. this.visible = source.visible;
  4879. this.castShadow = source.castShadow;
  4880. this.receiveShadow = source.receiveShadow;
  4881. this.frustumCulled = source.frustumCulled;
  4882. this.renderOrder = source.renderOrder;
  4883. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4884. if ( recursive === true ) {
  4885. for ( var i = 0; i < source.children.length; i ++ ) {
  4886. var child = source.children[ i ];
  4887. this.add( child.clone() );
  4888. }
  4889. }
  4890. return this;
  4891. }
  4892. };
  4893. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4894. THREE.Object3DIdCount = 0;
  4895. // File:src/core/Face3.js
  4896. /**
  4897. * @author mrdoob / http://mrdoob.com/
  4898. * @author alteredq / http://alteredqualia.com/
  4899. */
  4900. THREE.Face3 = function ( a, b, c, normal, color ) {
  4901. this.a = a;
  4902. this.b = b;
  4903. this.c = c;
  4904. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  4905. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  4906. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  4907. this.vertexColors = Array.isArray( color ) ? color : [];
  4908. this.vertexTangents = [];
  4909. };
  4910. THREE.Face3.prototype = {
  4911. constructor: THREE.Face3,
  4912. clone: function () {
  4913. var face = new THREE.Face3( this.a, this.b, this.c );
  4914. face.normal.copy( this.normal );
  4915. face.color.copy( this.color );
  4916. for ( var i = 0, il = this.vertexNormals.length; i < il; i ++ ) {
  4917. face.vertexNormals[ i ] = this.vertexNormals[ i ].clone();
  4918. }
  4919. for ( var i = 0, il = this.vertexColors.length; i < il; i ++ ) {
  4920. face.vertexColors[ i ] = this.vertexColors[ i ].clone();
  4921. }
  4922. for ( var i = 0, il = this.vertexTangents.length; i < il; i ++ ) {
  4923. face.vertexTangents[ i ] = this.vertexTangents[ i ].clone();
  4924. }
  4925. return face;
  4926. }
  4927. };
  4928. // File:src/core/Face4.js
  4929. /**
  4930. * @author mrdoob / http://mrdoob.com/
  4931. */
  4932. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  4933. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  4934. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  4935. };
  4936. // File:src/core/BufferAttribute.js
  4937. /**
  4938. * @author mrdoob / http://mrdoob.com/
  4939. */
  4940. THREE.BufferAttribute = function ( array, itemSize ) {
  4941. this.uuid = THREE.Math.generateUUID();
  4942. this.array = array;
  4943. this.itemSize = itemSize;
  4944. this.version = 0;
  4945. };
  4946. THREE.BufferAttribute.prototype = {
  4947. constructor: THREE.BufferAttribute,
  4948. get length () {
  4949. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  4950. return this.array.length;
  4951. },
  4952. get count() {
  4953. return this.array.length / this.itemSize;
  4954. },
  4955. set needsUpdate( value ) {
  4956. if ( value === true ) this.version ++;
  4957. },
  4958. copyAt: function ( index1, attribute, index2 ) {
  4959. index1 *= this.itemSize;
  4960. index2 *= attribute.itemSize;
  4961. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  4962. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  4963. }
  4964. return this;
  4965. },
  4966. copyArray: function ( array ) {
  4967. this.array.set( array );
  4968. return this;
  4969. },
  4970. copyColorsArray: function ( colors ) {
  4971. var array = this.array, offset = 0;
  4972. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  4973. var color = colors[ i ];
  4974. if ( color === undefined ) {
  4975. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  4976. color = new THREE.Color();
  4977. }
  4978. array[ offset ++ ] = color.r;
  4979. array[ offset ++ ] = color.g;
  4980. array[ offset ++ ] = color.b;
  4981. }
  4982. return this;
  4983. },
  4984. copyIndicesArray: function ( indices ) {
  4985. var array = this.array, offset = 0;
  4986. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  4987. var index = indices[ i ];
  4988. array[ offset ++ ] = index.a;
  4989. array[ offset ++ ] = index.b;
  4990. array[ offset ++ ] = index.c;
  4991. }
  4992. return this;
  4993. },
  4994. copyVector2sArray: function ( vectors ) {
  4995. var array = this.array, offset = 0;
  4996. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  4997. var vector = vectors[ i ];
  4998. if ( vector === undefined ) {
  4999. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5000. vector = new THREE.Vector2();
  5001. }
  5002. array[ offset ++ ] = vector.x;
  5003. array[ offset ++ ] = vector.y;
  5004. }
  5005. return this;
  5006. },
  5007. copyVector3sArray: function ( vectors ) {
  5008. var array = this.array, offset = 0;
  5009. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5010. var vector = vectors[ i ];
  5011. if ( vector === undefined ) {
  5012. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5013. vector = new THREE.Vector3();
  5014. }
  5015. array[ offset ++ ] = vector.x;
  5016. array[ offset ++ ] = vector.y;
  5017. array[ offset ++ ] = vector.z;
  5018. }
  5019. return this;
  5020. },
  5021. copyVector4sArray: function ( vectors ) {
  5022. var array = this.array, offset = 0;
  5023. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5024. var vector = vectors[ i ];
  5025. if ( vector === undefined ) {
  5026. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5027. vector = new THREE.Vector4();
  5028. }
  5029. array[ offset ++ ] = vector.x;
  5030. array[ offset ++ ] = vector.y;
  5031. array[ offset ++ ] = vector.z;
  5032. array[ offset ++ ] = vector.w;
  5033. }
  5034. return this;
  5035. },
  5036. set: function ( value, offset ) {
  5037. if ( offset === undefined ) offset = 0;
  5038. this.array.set( value, offset );
  5039. return this;
  5040. },
  5041. getX: function ( index ) {
  5042. return this.array[ index * this.itemSize ];
  5043. },
  5044. setX: function ( index, x ) {
  5045. this.array[ index * this.itemSize ] = x;
  5046. return this;
  5047. },
  5048. getY: function ( index ) {
  5049. return this.array[ index * this.itemSize + 1 ];
  5050. },
  5051. setY: function ( index, y ) {
  5052. this.array[ index * this.itemSize + 1 ] = y;
  5053. return this;
  5054. },
  5055. getZ: function ( index ) {
  5056. return this.array[ index * this.itemSize + 2 ];
  5057. },
  5058. setZ: function ( index, z ) {
  5059. this.array[ index * this.itemSize + 2 ] = z;
  5060. return this;
  5061. },
  5062. getW: function ( index ) {
  5063. return this.array[ index * this.itemSize + 3 ];
  5064. },
  5065. setW: function ( index, w ) {
  5066. this.array[ index * this.itemSize + 3 ] = w;
  5067. return this;
  5068. },
  5069. setXY: function ( index, x, y ) {
  5070. index *= this.itemSize;
  5071. this.array[ index + 0 ] = x;
  5072. this.array[ index + 1 ] = y;
  5073. return this;
  5074. },
  5075. setXYZ: function ( index, x, y, z ) {
  5076. index *= this.itemSize;
  5077. this.array[ index + 0 ] = x;
  5078. this.array[ index + 1 ] = y;
  5079. this.array[ index + 2 ] = z;
  5080. return this;
  5081. },
  5082. setXYZW: function ( index, x, y, z, w ) {
  5083. index *= this.itemSize;
  5084. this.array[ index + 0 ] = x;
  5085. this.array[ index + 1 ] = y;
  5086. this.array[ index + 2 ] = z;
  5087. this.array[ index + 3 ] = w;
  5088. return this;
  5089. },
  5090. clone: function () {
  5091. return new THREE.BufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  5092. }
  5093. };
  5094. //
  5095. THREE.Int8Attribute = function ( array, itemSize ) {
  5096. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5097. };
  5098. THREE.Uint8Attribute = function ( array, itemSize ) {
  5099. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5100. };
  5101. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5102. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5103. };
  5104. THREE.Int16Attribute = function ( array, itemSize ) {
  5105. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5106. };
  5107. THREE.Uint16Attribute = function ( array, itemSize ) {
  5108. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5109. };
  5110. THREE.Int32Attribute = function ( array, itemSize ) {
  5111. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5112. };
  5113. THREE.Uint32Attribute = function ( array, itemSize ) {
  5114. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5115. };
  5116. THREE.Float32Attribute = function ( array, itemSize ) {
  5117. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5118. };
  5119. THREE.Float64Attribute = function ( array, itemSize ) {
  5120. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5121. };
  5122. // File:src/core/DynamicBufferAttribute.js
  5123. /**
  5124. * @author benaadams / https://twitter.com/ben_a_adams
  5125. * @author mrdoob / http://mrdoob.com/
  5126. */
  5127. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5128. THREE.BufferAttribute.call( this, array, itemSize );
  5129. this.updateRange = { offset: 0, count: -1 };
  5130. };
  5131. THREE.DynamicBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5132. THREE.DynamicBufferAttribute.prototype.constructor = THREE.DynamicBufferAttribute;
  5133. THREE.DynamicBufferAttribute.prototype.clone = function () {
  5134. return new THREE.DynamicBufferAttribute( new this.array.constructor( this.array ), this.itemSize );
  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, dynamic) {
  5141. THREE.DynamicBufferAttribute.call( this, array, itemSize );
  5142. this.dynamic = dynamic || false;
  5143. this.meshPerAttribute = meshPerAttribute || 1;
  5144. };
  5145. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.DynamicBufferAttribute.prototype );
  5146. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5147. THREE.InstancedBufferAttribute.prototype.clone = function () {
  5148. return new THREE.InstancedBufferAttribute( new this.array.constructor( this.array ), this.itemSize, this.meshPerAttribute, this.dynamic );
  5149. };
  5150. // File:src/core/InterleavedBuffer.js
  5151. /**
  5152. * @author benaadams / https://twitter.com/ben_a_adams
  5153. */
  5154. THREE.InterleavedBuffer = function ( array, stride, dynamic ) {
  5155. this.uuid = THREE.Math.generateUUID();
  5156. this.array = array;
  5157. this.stride = stride;
  5158. this.version = 0;
  5159. this.dynamic = dynamic || false;
  5160. this.updateRange = { offset: 0, count: -1 };
  5161. };
  5162. THREE.InterleavedBuffer.prototype = {
  5163. constructor: THREE.InterleavedBuffer,
  5164. get length () {
  5165. return this.array.length;
  5166. },
  5167. get count () {
  5168. return this.array.length / this.stride;
  5169. },
  5170. set needsUpdate( value ) {
  5171. if ( value === true ) this.version ++;
  5172. },
  5173. copyAt: function ( index1, attribute, index2 ) {
  5174. index1 *= this.stride;
  5175. index2 *= attribute.stride;
  5176. for ( var i = 0, l = this.stride; i < l; i++ ) {
  5177. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5178. }
  5179. return this;
  5180. },
  5181. set: function ( value, offset ) {
  5182. if ( offset === undefined ) offset = 0;
  5183. this.array.set( value, offset );
  5184. return this;
  5185. },
  5186. clone: function () {
  5187. return new THREE.InterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic );
  5188. }
  5189. };
  5190. // File:src/core/InstancedInterleavedBuffer.js
  5191. /**
  5192. * @author benaadams / https://twitter.com/ben_a_adams
  5193. */
  5194. THREE.InstancedInterleavedBuffer = function ( array, stride, dynamic, meshPerAttribute ) {
  5195. THREE.InterleavedBuffer.call( this, array, stride, dynamic );
  5196. this.meshPerAttribute = meshPerAttribute || 1;
  5197. };
  5198. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5199. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5200. THREE.InstancedInterleavedBuffer.prototype.clone = function () {
  5201. return new THREE.InstancedInterleavedBuffer( new this.array.constructor( this.array ), this.stride, this.dynamic, this.meshPerAttribute );
  5202. };
  5203. // File:src/core/InterleavedBufferAttribute.js
  5204. /**
  5205. * @author benaadams / https://twitter.com/ben_a_adams
  5206. */
  5207. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5208. this.uuid = THREE.Math.generateUUID();
  5209. this.data = interleavedBuffer;
  5210. this.itemSize = itemSize;
  5211. this.offset = offset;
  5212. };
  5213. THREE.InterleavedBufferAttribute.prototype = {
  5214. constructor: THREE.InterleavedBufferAttribute,
  5215. get length() {
  5216. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5217. return this.array.length;
  5218. },
  5219. get count() {
  5220. return this.data.array.length / this.data.stride;
  5221. },
  5222. setX: function ( index, x ) {
  5223. this.data.array[ index * this.data.stride + this.offset ] = x;
  5224. return this;
  5225. },
  5226. setY: function ( index, y ) {
  5227. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5228. return this;
  5229. },
  5230. setZ: function ( index, z ) {
  5231. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5232. return this;
  5233. },
  5234. setW: function ( index, w ) {
  5235. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5236. return this;
  5237. },
  5238. getX: function ( index ) {
  5239. return this.data.array[ index * this.data.stride + this.offset ];
  5240. },
  5241. getY: function ( index ) {
  5242. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5243. },
  5244. getZ: function ( index ) {
  5245. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5246. },
  5247. getW: function ( index ) {
  5248. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5249. },
  5250. setXY: function ( index, x, y ) {
  5251. index = index * this.data.stride + this.offset;
  5252. this.data.array[ index + 0 ] = x;
  5253. this.data.array[ index + 1 ] = y;
  5254. return this;
  5255. },
  5256. setXYZ: function ( index, x, y, z ) {
  5257. index = index * this.data.stride + this.offset;
  5258. this.data.array[ index + 0 ] = x;
  5259. this.data.array[ index + 1 ] = y;
  5260. this.data.array[ index + 2 ] = z;
  5261. return this;
  5262. },
  5263. setXYZW: function ( index, x, y, z, w ) {
  5264. index = index * this.data.stride + this.offset;
  5265. this.data.array[ index + 0 ] = x;
  5266. this.data.array[ index + 1 ] = y;
  5267. this.data.array[ index + 2 ] = z;
  5268. this.data.array[ index + 3 ] = w;
  5269. return this;
  5270. }
  5271. };
  5272. // File:src/core/Geometry.js
  5273. /**
  5274. * @author mrdoob / http://mrdoob.com/
  5275. * @author kile / http://kile.stravaganza.org/
  5276. * @author alteredq / http://alteredqualia.com/
  5277. * @author mikael emtinger / http://gomo.se/
  5278. * @author zz85 / http://www.lab4games.net/zz85/blog
  5279. * @author bhouston / http://exocortex.com
  5280. */
  5281. THREE.Geometry = function () {
  5282. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5283. this.uuid = THREE.Math.generateUUID();
  5284. this.name = '';
  5285. this.type = 'Geometry';
  5286. this.vertices = [];
  5287. this.colors = [];
  5288. this.faces = [];
  5289. this.faceVertexUvs = [ [] ];
  5290. this.morphTargets = [];
  5291. this.morphColors = [];
  5292. this.morphNormals = [];
  5293. this.skinWeights = [];
  5294. this.skinIndices = [];
  5295. this.lineDistances = [];
  5296. this.boundingBox = null;
  5297. this.boundingSphere = null;
  5298. this.hasTangents = false;
  5299. // update flags
  5300. this.verticesNeedUpdate = false;
  5301. this.elementsNeedUpdate = false;
  5302. this.uvsNeedUpdate = false;
  5303. this.normalsNeedUpdate = false;
  5304. this.tangentsNeedUpdate = false;
  5305. this.colorsNeedUpdate = false;
  5306. this.lineDistancesNeedUpdate = false;
  5307. };
  5308. THREE.Geometry.prototype = {
  5309. constructor: THREE.Geometry,
  5310. applyMatrix: function ( matrix ) {
  5311. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5312. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5313. var vertex = this.vertices[ i ];
  5314. vertex.applyMatrix4( matrix );
  5315. }
  5316. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5317. var face = this.faces[ i ];
  5318. face.normal.applyMatrix3( normalMatrix ).normalize();
  5319. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5320. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5321. }
  5322. }
  5323. if ( this.boundingBox !== null ) {
  5324. this.computeBoundingBox();
  5325. }
  5326. if ( this.boundingSphere !== null ) {
  5327. this.computeBoundingSphere();
  5328. }
  5329. this.verticesNeedUpdate = true;
  5330. this.normalsNeedUpdate = true;
  5331. },
  5332. fromBufferGeometry: function ( geometry ) {
  5333. var scope = this;
  5334. var attributes = geometry.attributes;
  5335. var vertices = attributes.position.array;
  5336. var indices = attributes.index !== undefined ? attributes.index.array : undefined;
  5337. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5338. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5339. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5340. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5341. var tangents = attributes.tangent !== undefined ? attributes.tangent.array : undefined;
  5342. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5343. if ( tangents !== undefined ) this.hasTangents = true;
  5344. var tempNormals = [];
  5345. var tempUVs = [];
  5346. var tempUVs2 = [];
  5347. var tempTangents = [];
  5348. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5349. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5350. if ( normals !== undefined ) {
  5351. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5352. }
  5353. if ( colors !== undefined ) {
  5354. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5355. }
  5356. if ( uvs !== undefined ) {
  5357. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5358. }
  5359. if ( uvs2 !== undefined ) {
  5360. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5361. }
  5362. if ( tangents !== undefined ) {
  5363. tempTangents.push( new THREE.Vector4( tangents[ k ], tangents[ k + 1 ], tangents[ k + 2 ], tangents[ k + 3 ] ) );
  5364. }
  5365. }
  5366. var addFace = function ( a, b, c ) {
  5367. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5368. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5369. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5370. scope.faces.push( face );
  5371. if ( uvs !== undefined ) {
  5372. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5373. }
  5374. if ( uvs2 !== undefined ) {
  5375. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5376. }
  5377. if ( tangents !== undefined ) {
  5378. face.vertexTangents.push( tempTangents[ a ].clone(), tempTangents[ b ].clone(), tempTangents[ c ].clone() );
  5379. }
  5380. };
  5381. if ( indices !== undefined ) {
  5382. var drawcalls = geometry.drawcalls;
  5383. if ( drawcalls.length > 0 ) {
  5384. for ( var i = 0; i < drawcalls.length; i ++ ) {
  5385. var drawcall = drawcalls[ i ];
  5386. var start = drawcall.start;
  5387. var count = drawcall.count;
  5388. var index = drawcall.index;
  5389. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5390. addFace( index + indices[ j ], index + indices[ j + 1 ], index + indices[ j + 2 ] );
  5391. }
  5392. }
  5393. } else {
  5394. for ( var i = 0; i < indices.length; i += 3 ) {
  5395. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5396. }
  5397. }
  5398. } else {
  5399. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5400. addFace( i, i + 1, i + 2 );
  5401. }
  5402. }
  5403. this.computeFaceNormals();
  5404. if ( geometry.boundingBox !== null ) {
  5405. this.boundingBox = geometry.boundingBox.clone();
  5406. }
  5407. if ( geometry.boundingSphere !== null ) {
  5408. this.boundingSphere = geometry.boundingSphere.clone();
  5409. }
  5410. return this;
  5411. },
  5412. center: function () {
  5413. this.computeBoundingBox();
  5414. var offset = this.boundingBox.center().negate();
  5415. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  5416. return offset;
  5417. },
  5418. normalize: function () {
  5419. this.computeBoundingSphere();
  5420. var center = this.boundingSphere.center;
  5421. var radius = this.boundingSphere.radius;
  5422. var s = radius === 0 ? 1 : 1.0 / radius;
  5423. var matrix = new THREE.Matrix4();
  5424. matrix.set(
  5425. s, 0, 0, -s * center.x,
  5426. 0, s, 0, -s * center.y,
  5427. 0, 0, s, -s * center.z,
  5428. 0, 0, 0, 1
  5429. );
  5430. this.applyMatrix( matrix );
  5431. return this;
  5432. },
  5433. computeFaceNormals: function () {
  5434. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5435. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5436. var face = this.faces[ f ];
  5437. var vA = this.vertices[ face.a ];
  5438. var vB = this.vertices[ face.b ];
  5439. var vC = this.vertices[ face.c ];
  5440. cb.subVectors( vC, vB );
  5441. ab.subVectors( vA, vB );
  5442. cb.cross( ab );
  5443. cb.normalize();
  5444. face.normal.copy( cb );
  5445. }
  5446. },
  5447. computeVertexNormals: function ( areaWeighted ) {
  5448. var v, vl, f, fl, face, vertices;
  5449. vertices = new Array( this.vertices.length );
  5450. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5451. vertices[ v ] = new THREE.Vector3();
  5452. }
  5453. if ( areaWeighted ) {
  5454. // vertex normals weighted by triangle areas
  5455. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5456. var vA, vB, vC;
  5457. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5458. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5459. face = this.faces[ f ];
  5460. vA = this.vertices[ face.a ];
  5461. vB = this.vertices[ face.b ];
  5462. vC = this.vertices[ face.c ];
  5463. cb.subVectors( vC, vB );
  5464. ab.subVectors( vA, vB );
  5465. cb.cross( ab );
  5466. vertices[ face.a ].add( cb );
  5467. vertices[ face.b ].add( cb );
  5468. vertices[ face.c ].add( cb );
  5469. }
  5470. } else {
  5471. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5472. face = this.faces[ f ];
  5473. vertices[ face.a ].add( face.normal );
  5474. vertices[ face.b ].add( face.normal );
  5475. vertices[ face.c ].add( face.normal );
  5476. }
  5477. }
  5478. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5479. vertices[ v ].normalize();
  5480. }
  5481. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5482. face = this.faces[ f ];
  5483. var vertexNormals = face.vertexNormals;
  5484. if ( vertexNormals.length === 3 ) {
  5485. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5486. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5487. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5488. } else {
  5489. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5490. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5491. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5492. }
  5493. }
  5494. },
  5495. computeMorphNormals: function () {
  5496. var i, il, f, fl, face;
  5497. // save original normals
  5498. // - create temp variables on first access
  5499. // otherwise just copy (for faster repeated calls)
  5500. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5501. face = this.faces[ f ];
  5502. if ( ! face.__originalFaceNormal ) {
  5503. face.__originalFaceNormal = face.normal.clone();
  5504. } else {
  5505. face.__originalFaceNormal.copy( face.normal );
  5506. }
  5507. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5508. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5509. if ( ! face.__originalVertexNormals[ i ] ) {
  5510. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5511. } else {
  5512. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5513. }
  5514. }
  5515. }
  5516. // use temp geometry to compute face and vertex normals for each morph
  5517. var tmpGeo = new THREE.Geometry();
  5518. tmpGeo.faces = this.faces;
  5519. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5520. // create on first access
  5521. if ( ! this.morphNormals[ i ] ) {
  5522. this.morphNormals[ i ] = {};
  5523. this.morphNormals[ i ].faceNormals = [];
  5524. this.morphNormals[ i ].vertexNormals = [];
  5525. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5526. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5527. var faceNormal, vertexNormals;
  5528. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5529. faceNormal = new THREE.Vector3();
  5530. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5531. dstNormalsFace.push( faceNormal );
  5532. dstNormalsVertex.push( vertexNormals );
  5533. }
  5534. }
  5535. var morphNormals = this.morphNormals[ i ];
  5536. // set vertices to morph target
  5537. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5538. // compute morph normals
  5539. tmpGeo.computeFaceNormals();
  5540. tmpGeo.computeVertexNormals();
  5541. // store morph normals
  5542. var faceNormal, vertexNormals;
  5543. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5544. face = this.faces[ f ];
  5545. faceNormal = morphNormals.faceNormals[ f ];
  5546. vertexNormals = morphNormals.vertexNormals[ f ];
  5547. faceNormal.copy( face.normal );
  5548. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5549. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5550. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5551. }
  5552. }
  5553. // restore original normals
  5554. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5555. face = this.faces[ f ];
  5556. face.normal = face.__originalFaceNormal;
  5557. face.vertexNormals = face.__originalVertexNormals;
  5558. }
  5559. },
  5560. computeTangents: function () {
  5561. // based on http://www.terathon.com/code/tangent.html
  5562. // tangents go to vertices
  5563. var f, fl, v, vl, i, vertexIndex,
  5564. face, uv, vA, vB, vC, uvA, uvB, uvC,
  5565. x1, x2, y1, y2, z1, z2,
  5566. s1, s2, t1, t2, r, t, test,
  5567. tan1 = [], tan2 = [],
  5568. sdir = new THREE.Vector3(), tdir = new THREE.Vector3(),
  5569. tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3(),
  5570. n = new THREE.Vector3(), w;
  5571. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5572. tan1[ v ] = new THREE.Vector3();
  5573. tan2[ v ] = new THREE.Vector3();
  5574. }
  5575. function handleTriangle( context, a, b, c, ua, ub, uc ) {
  5576. vA = context.vertices[ a ];
  5577. vB = context.vertices[ b ];
  5578. vC = context.vertices[ c ];
  5579. uvA = uv[ ua ];
  5580. uvB = uv[ ub ];
  5581. uvC = uv[ uc ];
  5582. x1 = vB.x - vA.x;
  5583. x2 = vC.x - vA.x;
  5584. y1 = vB.y - vA.y;
  5585. y2 = vC.y - vA.y;
  5586. z1 = vB.z - vA.z;
  5587. z2 = vC.z - vA.z;
  5588. s1 = uvB.x - uvA.x;
  5589. s2 = uvC.x - uvA.x;
  5590. t1 = uvB.y - uvA.y;
  5591. t2 = uvC.y - uvA.y;
  5592. r = 1.0 / ( s1 * t2 - s2 * t1 );
  5593. sdir.set( ( t2 * x1 - t1 * x2 ) * r,
  5594. ( t2 * y1 - t1 * y2 ) * r,
  5595. ( t2 * z1 - t1 * z2 ) * r );
  5596. tdir.set( ( s1 * x2 - s2 * x1 ) * r,
  5597. ( s1 * y2 - s2 * y1 ) * r,
  5598. ( s1 * z2 - s2 * z1 ) * r );
  5599. tan1[ a ].add( sdir );
  5600. tan1[ b ].add( sdir );
  5601. tan1[ c ].add( sdir );
  5602. tan2[ a ].add( tdir );
  5603. tan2[ b ].add( tdir );
  5604. tan2[ c ].add( tdir );
  5605. }
  5606. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5607. face = this.faces[ f ];
  5608. uv = this.faceVertexUvs[ 0 ][ f ]; // use UV layer 0 for tangents
  5609. handleTriangle( this, face.a, face.b, face.c, 0, 1, 2 );
  5610. }
  5611. var faceIndex = [ 'a', 'b', 'c', 'd' ];
  5612. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5613. face = this.faces[ f ];
  5614. for ( i = 0; i < Math.min( face.vertexNormals.length, 3 ); i ++ ) {
  5615. n.copy( face.vertexNormals[ i ] );
  5616. vertexIndex = face[ faceIndex[ i ] ];
  5617. t = tan1[ vertexIndex ];
  5618. // Gram-Schmidt orthogonalize
  5619. tmp.copy( t );
  5620. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  5621. // Calculate handedness
  5622. tmp2.crossVectors( face.vertexNormals[ i ], t );
  5623. test = tmp2.dot( tan2[ vertexIndex ] );
  5624. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  5625. face.vertexTangents[ i ] = new THREE.Vector4( tmp.x, tmp.y, tmp.z, w );
  5626. }
  5627. }
  5628. this.hasTangents = true;
  5629. },
  5630. computeLineDistances: function () {
  5631. var d = 0;
  5632. var vertices = this.vertices;
  5633. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5634. if ( i > 0 ) {
  5635. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5636. }
  5637. this.lineDistances[ i ] = d;
  5638. }
  5639. },
  5640. computeBoundingBox: function () {
  5641. if ( this.boundingBox === null ) {
  5642. this.boundingBox = new THREE.Box3();
  5643. }
  5644. this.boundingBox.setFromPoints( this.vertices );
  5645. },
  5646. computeBoundingSphere: function () {
  5647. if ( this.boundingSphere === null ) {
  5648. this.boundingSphere = new THREE.Sphere();
  5649. }
  5650. this.boundingSphere.setFromPoints( this.vertices );
  5651. },
  5652. merge: function ( geometry, matrix ) {
  5653. if ( geometry instanceof THREE.Geometry === false ) {
  5654. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5655. return;
  5656. }
  5657. var normalMatrix,
  5658. vertexOffset = this.vertices.length,
  5659. vertices1 = this.vertices,
  5660. vertices2 = geometry.vertices,
  5661. faces1 = this.faces,
  5662. faces2 = geometry.faces,
  5663. uvs1 = this.faceVertexUvs[ 0 ],
  5664. uvs2 = geometry.faceVertexUvs[ 0 ];
  5665. if ( matrix !== undefined ) {
  5666. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5667. }
  5668. // vertices
  5669. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5670. var vertex = vertices2[ i ];
  5671. var vertexCopy = vertex.clone();
  5672. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5673. vertices1.push( vertexCopy );
  5674. }
  5675. // faces
  5676. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5677. var face = faces2[ i ], faceCopy, normal, color,
  5678. faceVertexNormals = face.vertexNormals,
  5679. faceVertexColors = face.vertexColors;
  5680. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5681. faceCopy.normal.copy( face.normal );
  5682. if ( normalMatrix !== undefined ) {
  5683. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5684. }
  5685. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5686. normal = faceVertexNormals[ j ].clone();
  5687. if ( normalMatrix !== undefined ) {
  5688. normal.applyMatrix3( normalMatrix ).normalize();
  5689. }
  5690. faceCopy.vertexNormals.push( normal );
  5691. }
  5692. faceCopy.color.copy( face.color );
  5693. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5694. color = faceVertexColors[ j ];
  5695. faceCopy.vertexColors.push( color.clone() );
  5696. }
  5697. faces1.push( faceCopy );
  5698. }
  5699. // uvs
  5700. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5701. var uv = uvs2[ i ], uvCopy = [];
  5702. if ( uv === undefined ) {
  5703. continue;
  5704. }
  5705. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5706. uvCopy.push( uv[ j ].clone() );
  5707. }
  5708. uvs1.push( uvCopy );
  5709. }
  5710. },
  5711. mergeMesh: function ( mesh ) {
  5712. if ( mesh instanceof THREE.Mesh === false ) {
  5713. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5714. return;
  5715. }
  5716. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5717. this.merge( mesh.geometry, mesh.matrix );
  5718. },
  5719. /*
  5720. * Checks for duplicate vertices with hashmap.
  5721. * Duplicated vertices are removed
  5722. * and faces' vertices are updated.
  5723. */
  5724. mergeVertices: function () {
  5725. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5726. var unique = [], changes = [];
  5727. var v, key;
  5728. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5729. var precision = Math.pow( 10, precisionPoints );
  5730. var i, il, face;
  5731. var indices, j, jl;
  5732. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5733. v = this.vertices[ i ];
  5734. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5735. if ( verticesMap[ key ] === undefined ) {
  5736. verticesMap[ key ] = i;
  5737. unique.push( this.vertices[ i ] );
  5738. changes[ i ] = unique.length - 1;
  5739. } else {
  5740. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5741. changes[ i ] = changes[ verticesMap[ key ] ];
  5742. }
  5743. }
  5744. // if faces are completely degenerate after merging vertices, we
  5745. // have to remove them from the geometry.
  5746. var faceIndicesToRemove = [];
  5747. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5748. face = this.faces[ i ];
  5749. face.a = changes[ face.a ];
  5750. face.b = changes[ face.b ];
  5751. face.c = changes[ face.c ];
  5752. indices = [ face.a, face.b, face.c ];
  5753. var dupIndex = - 1;
  5754. // if any duplicate vertices are found in a Face3
  5755. // we have to remove the face as nothing can be saved
  5756. for ( var n = 0; n < 3; n ++ ) {
  5757. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5758. dupIndex = n;
  5759. faceIndicesToRemove.push( i );
  5760. break;
  5761. }
  5762. }
  5763. }
  5764. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5765. var idx = faceIndicesToRemove[ i ];
  5766. this.faces.splice( idx, 1 );
  5767. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5768. this.faceVertexUvs[ j ].splice( idx, 1 );
  5769. }
  5770. }
  5771. // Use unique set of vertices
  5772. var diff = this.vertices.length - unique.length;
  5773. this.vertices = unique;
  5774. return diff;
  5775. },
  5776. toJSON: function () {
  5777. var data = {
  5778. metadata: {
  5779. version: 4.4,
  5780. type: 'Geometry',
  5781. generator: 'Geometry.toJSON'
  5782. }
  5783. };
  5784. // standard Geometry serialization
  5785. data.uuid = this.uuid;
  5786. data.type = this.type;
  5787. if ( this.name !== '' ) data.name = this.name;
  5788. if ( this.parameters !== undefined ) {
  5789. var parameters = this.parameters;
  5790. for ( var key in parameters ) {
  5791. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5792. }
  5793. return data;
  5794. }
  5795. var vertices = [];
  5796. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5797. var vertex = this.vertices[ i ];
  5798. vertices.push( vertex.x, vertex.y, vertex.z );
  5799. }
  5800. var faces = [];
  5801. var normals = [];
  5802. var normalsHash = {};
  5803. var colors = [];
  5804. var colorsHash = {};
  5805. var uvs = [];
  5806. var uvsHash = {};
  5807. for ( var i = 0; i < this.faces.length; i ++ ) {
  5808. var face = this.faces[ i ];
  5809. var hasMaterial = false; // face.materialIndex !== undefined;
  5810. var hasFaceUv = false; // deprecated
  5811. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5812. var hasFaceNormal = face.normal.length() > 0;
  5813. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5814. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5815. var hasFaceVertexColor = face.vertexColors.length > 0;
  5816. var faceType = 0;
  5817. faceType = setBit( faceType, 0, 0 );
  5818. faceType = setBit( faceType, 1, hasMaterial );
  5819. faceType = setBit( faceType, 2, hasFaceUv );
  5820. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5821. faceType = setBit( faceType, 4, hasFaceNormal );
  5822. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5823. faceType = setBit( faceType, 6, hasFaceColor );
  5824. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5825. faces.push( faceType );
  5826. faces.push( face.a, face.b, face.c );
  5827. if ( hasFaceVertexUv ) {
  5828. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5829. faces.push(
  5830. getUvIndex( faceVertexUvs[ 0 ] ),
  5831. getUvIndex( faceVertexUvs[ 1 ] ),
  5832. getUvIndex( faceVertexUvs[ 2 ] )
  5833. );
  5834. }
  5835. if ( hasFaceNormal ) {
  5836. faces.push( getNormalIndex( face.normal ) );
  5837. }
  5838. if ( hasFaceVertexNormal ) {
  5839. var vertexNormals = face.vertexNormals;
  5840. faces.push(
  5841. getNormalIndex( vertexNormals[ 0 ] ),
  5842. getNormalIndex( vertexNormals[ 1 ] ),
  5843. getNormalIndex( vertexNormals[ 2 ] )
  5844. );
  5845. }
  5846. if ( hasFaceColor ) {
  5847. faces.push( getColorIndex( face.color ) );
  5848. }
  5849. if ( hasFaceVertexColor ) {
  5850. var vertexColors = face.vertexColors;
  5851. faces.push(
  5852. getColorIndex( vertexColors[ 0 ] ),
  5853. getColorIndex( vertexColors[ 1 ] ),
  5854. getColorIndex( vertexColors[ 2 ] )
  5855. );
  5856. }
  5857. }
  5858. function setBit( value, position, enabled ) {
  5859. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position) );
  5860. }
  5861. function getNormalIndex( normal ) {
  5862. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5863. if ( normalsHash[ hash ] !== undefined ) {
  5864. return normalsHash[ hash ];
  5865. }
  5866. normalsHash[ hash ] = normals.length / 3;
  5867. normals.push( normal.x, normal.y, normal.z );
  5868. return normalsHash[ hash ];
  5869. }
  5870. function getColorIndex( color ) {
  5871. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5872. if ( colorsHash[ hash ] !== undefined ) {
  5873. return colorsHash[ hash ];
  5874. }
  5875. colorsHash[ hash ] = colors.length;
  5876. colors.push( color.getHex() );
  5877. return colorsHash[ hash ];
  5878. }
  5879. function getUvIndex( uv ) {
  5880. var hash = uv.x.toString() + uv.y.toString();
  5881. if ( uvsHash[ hash ] !== undefined ) {
  5882. return uvsHash[ hash ];
  5883. }
  5884. uvsHash[ hash ] = uvs.length / 2;
  5885. uvs.push( uv.x, uv.y );
  5886. return uvsHash[ hash ];
  5887. }
  5888. data.data = {};
  5889. data.data.vertices = vertices;
  5890. data.data.normals = normals;
  5891. if ( colors.length > 0 ) data.data.colors = colors;
  5892. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  5893. data.data.faces = faces;
  5894. return data;
  5895. },
  5896. clone: function () {
  5897. var geometry = new THREE.Geometry();
  5898. return geometry.copy( this );
  5899. },
  5900. copy: function ( source ) {
  5901. this.vertices = [];
  5902. this.faces = [];
  5903. this.faceVertexUvs = [ [] ];
  5904. var vertices = source.vertices;
  5905. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5906. this.vertices.push( vertices[ i ].clone() );
  5907. }
  5908. var faces = source.faces;
  5909. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  5910. this.faces.push( faces[ i ].clone() );
  5911. }
  5912. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  5913. var faceVertexUvs = source.faceVertexUvs[ i ];
  5914. if ( this.faceVertexUvs[ i ] === undefined ) {
  5915. this.faceVertexUvs[ i ] = [];
  5916. }
  5917. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  5918. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  5919. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  5920. var uv = uvs[ k ];
  5921. uvsCopy.push( uv.clone() );
  5922. }
  5923. this.faceVertexUvs[ i ].push( uvsCopy );
  5924. }
  5925. }
  5926. return this;
  5927. },
  5928. dispose: function () {
  5929. this.dispatchEvent( { type: 'dispose' } );
  5930. },
  5931. // Backwards compatibility
  5932. set groupsNeedUpdate ( value ) {
  5933. if ( value === true ) this.dispose();
  5934. }
  5935. };
  5936. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  5937. THREE.GeometryIdCount = 0;
  5938. // File:src/core/DirectGeometry.js
  5939. /**
  5940. * @author mrdoob / http://mrdoob.com/
  5941. */
  5942. THREE.DirectGeometry = function () {
  5943. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5944. this.uuid = THREE.Math.generateUUID();
  5945. this.name = '';
  5946. this.type = 'DirectGeometry';
  5947. this.indices = [];
  5948. this.vertices = [];
  5949. this.colors = [];
  5950. this.normals = [];
  5951. this.colors = [];
  5952. this.uvs = [];
  5953. this.uvs2 = [];
  5954. this.tangents = [];
  5955. this.morphTargets = [];
  5956. this.morphColors = [];
  5957. this.morphNormals = [];
  5958. this.skinWeights = [];
  5959. this.skinIndices = [];
  5960. // this.lineDistances = [];
  5961. this.boundingBox = null;
  5962. this.boundingSphere = null;
  5963. // update flags
  5964. this.verticesNeedUpdate = false;
  5965. this.normalsNeedUpdate = false;
  5966. this.colorsNeedUpdate = false;
  5967. this.uvsNeedUpdate = false;
  5968. this.tangentsNeedUpdate = false;
  5969. };
  5970. THREE.DirectGeometry.prototype = {
  5971. constructor: THREE.DirectGeometry,
  5972. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  5973. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  5974. computeFaceNormals: function () {
  5975. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  5976. return this;
  5977. },
  5978. computeVertexNormals: function () {
  5979. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  5980. return this;
  5981. },
  5982. computeTangents: function () {
  5983. console.warn( 'THREE.DirectGeometry: computeTangents() is not a method of this type of geometry.' );
  5984. return this;
  5985. },
  5986. fromGeometry: function ( geometry ) {
  5987. var faces = geometry.faces;
  5988. var vertices = geometry.vertices;
  5989. var faceVertexUvs = geometry.faceVertexUvs;
  5990. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  5991. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  5992. var hasTangents = geometry.hasTangents;
  5993. // morphs
  5994. var morphTargets = geometry.morphTargets;
  5995. var morphTargetsLength = morphTargets.length;
  5996. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  5997. this.morphTargets[ i ] = [];
  5998. }
  5999. var morphNormals = geometry.morphNormals;
  6000. var morphNormalsLength = morphNormals.length;
  6001. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6002. this.morphNormals[ i ] = [];
  6003. }
  6004. var morphColors = geometry.morphColors;
  6005. var morphColorsLength = morphColors.length;
  6006. for ( var i = 0; i < morphColorsLength; i ++ ) {
  6007. this.morphColors[ i ] = [];
  6008. }
  6009. // skins
  6010. var skinIndices = geometry.skinIndices;
  6011. var skinWeights = geometry.skinWeights;
  6012. var hasSkinIndices = skinIndices.length === vertices.length;
  6013. var hasSkinWeights = skinWeights.length === vertices.length;
  6014. //
  6015. for ( var i = 0; i < faces.length; i ++ ) {
  6016. var face = faces[ i ];
  6017. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6018. var vertexNormals = face.vertexNormals;
  6019. if ( vertexNormals.length === 3 ) {
  6020. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6021. } else {
  6022. var normal = face.normal;
  6023. this.normals.push( normal, normal, normal );
  6024. }
  6025. var vertexColors = face.vertexColors;
  6026. if ( vertexColors.length === 3 ) {
  6027. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6028. } else {
  6029. var color = face.color;
  6030. this.colors.push( color, color, color );
  6031. }
  6032. if ( hasFaceVertexUv === true ) {
  6033. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6034. if ( vertexUvs !== undefined ) {
  6035. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6036. } else {
  6037. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6038. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6039. }
  6040. }
  6041. if ( hasFaceVertexUv2 === true ) {
  6042. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6043. if ( vertexUvs !== undefined ) {
  6044. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6045. } else {
  6046. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6047. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6048. }
  6049. }
  6050. if ( hasTangents === true ) {
  6051. var vertexTangents = face.vertexTangents;
  6052. if ( vertexTangents.length === 3 ) {
  6053. this.tangents.push( vertexTangents[ 0 ], vertexTangents[ 1 ], vertexTangents[ 2 ] );
  6054. } else {
  6055. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined tangents ', i );
  6056. this.tangents.push( new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4() );
  6057. }
  6058. }
  6059. // morphs
  6060. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6061. var morphTarget = morphTargets[ j ].vertices;
  6062. this.morphTargets[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6063. }
  6064. /*
  6065. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6066. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6067. this.morphNormals[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6068. }
  6069. for ( var j = 0; j < morphColorsLength; j ++ ) {
  6070. var morphColor = morphColors[ j ].colors;
  6071. this.morphColors[ j ].push( morphColor[ face.a ], morphColor[ face.b ], morphColor[ face.c ] );
  6072. }
  6073. */
  6074. // skins
  6075. if ( hasSkinIndices ) {
  6076. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6077. }
  6078. if ( hasSkinWeights ) {
  6079. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6080. }
  6081. }
  6082. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6083. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6084. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6085. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6086. this.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6087. return this;
  6088. },
  6089. dispose: function () {
  6090. this.dispatchEvent( { type: 'dispose' } );
  6091. }
  6092. };
  6093. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6094. // File:src/core/BufferGeometry.js
  6095. /**
  6096. * @author alteredq / http://alteredqualia.com/
  6097. * @author mrdoob / http://mrdoob.com/
  6098. */
  6099. THREE.BufferGeometry = function () {
  6100. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6101. this.uuid = THREE.Math.generateUUID();
  6102. this.name = '';
  6103. this.type = 'BufferGeometry';
  6104. this.attributes = {};
  6105. this.morphAttributes = [];
  6106. this.drawcalls = [];
  6107. this.boundingBox = null;
  6108. this.boundingSphere = null;
  6109. };
  6110. THREE.BufferGeometry.prototype = {
  6111. constructor: THREE.BufferGeometry,
  6112. addAttribute: function ( name, attribute ) {
  6113. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6114. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6115. this.attributes[ name ] = { array: arguments[ 1 ], itemSize: arguments[ 2 ] };
  6116. return;
  6117. }
  6118. this.attributes[ name ] = attribute;
  6119. },
  6120. getAttribute: function ( name ) {
  6121. return this.attributes[ name ];
  6122. },
  6123. get offsets() {
  6124. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .drawcalls.' );
  6125. return this.drawcalls;
  6126. },
  6127. addDrawCall: function ( start, count, indexOffset ) {
  6128. this.drawcalls.push( {
  6129. start: start,
  6130. count: count,
  6131. index: indexOffset !== undefined ? indexOffset : 0
  6132. } );
  6133. },
  6134. clearDrawCalls: function () {
  6135. this.drawcalls = [];
  6136. },
  6137. applyMatrix: function ( matrix ) {
  6138. var position = this.attributes.position;
  6139. if ( position !== undefined ) {
  6140. matrix.applyToVector3Array( position.array );
  6141. position.needsUpdate = true;
  6142. }
  6143. var normal = this.attributes.normal;
  6144. if ( normal !== undefined ) {
  6145. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6146. normalMatrix.applyToVector3Array( normal.array );
  6147. normal.needsUpdate = true;
  6148. }
  6149. if ( this.boundingBox !== null ) {
  6150. this.computeBoundingBox();
  6151. }
  6152. if ( this.boundingSphere !== null ) {
  6153. this.computeBoundingSphere();
  6154. }
  6155. },
  6156. center: function () {
  6157. this.computeBoundingBox();
  6158. var offset = this.boundingBox.center().negate();
  6159. this.applyMatrix( new THREE.Matrix4().setPosition( offset ) );
  6160. return offset;
  6161. },
  6162. setFromObject: function ( object ) {
  6163. console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6164. var geometry = object.geometry;
  6165. if ( object instanceof THREE.PointCloud || object instanceof THREE.Line ) {
  6166. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6167. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6168. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6169. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6170. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6171. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6172. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6173. }
  6174. if ( geometry.boundingSphere !== null ) {
  6175. this.boundingSphere = geometry.boundingSphere.clone();
  6176. }
  6177. if ( geometry.boundingBox !== null ) {
  6178. this.boundingBox = geometry.boundingBox.clone();
  6179. }
  6180. } else if ( object instanceof THREE.Mesh ) {
  6181. if ( geometry instanceof THREE.Geometry ) {
  6182. this.fromGeometry( geometry );
  6183. }
  6184. }
  6185. return this;
  6186. },
  6187. updateFromObject: function ( object ) {
  6188. var geometry = object.geometry;
  6189. if ( object instanceof THREE.Mesh ) {
  6190. var direct = geometry.__directGeometry;
  6191. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6192. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6193. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6194. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6195. direct.tangentsNeedUpdate = geometry.tangentsNeedUpdate;
  6196. geometry.verticesNeedUpdate = false;
  6197. geometry.normalsNeedUpdate = false;
  6198. geometry.colorsNeedUpdate = false;
  6199. geometry.uvsNeedUpdate = false;
  6200. geometry.tangentsNeedUpdate = false;
  6201. geometry = direct;
  6202. }
  6203. if ( geometry.verticesNeedUpdate === true ) {
  6204. var attribute = this.attributes.position;
  6205. if ( attribute !== undefined ) {
  6206. attribute.copyVector3sArray( geometry.vertices );
  6207. attribute.needsUpdate = true;
  6208. }
  6209. geometry.verticesNeedUpdate = false;
  6210. }
  6211. if ( geometry.normalsNeedUpdate === true ) {
  6212. var attribute = this.attributes.normal;
  6213. if ( attribute !== undefined ) {
  6214. attribute.copyVector3sArray( geometry.normals );
  6215. attribute.needsUpdate = true;
  6216. }
  6217. geometry.normalsNeedUpdate = false;
  6218. }
  6219. if ( geometry.colorsNeedUpdate === true ) {
  6220. var attribute = this.attributes.color;
  6221. if ( attribute !== undefined ) {
  6222. attribute.copyColorsArray( geometry.colors );
  6223. attribute.needsUpdate = true;
  6224. }
  6225. geometry.colorsNeedUpdate = false;
  6226. }
  6227. if ( geometry.tangentsNeedUpdate === true ) {
  6228. var attribute = this.attributes.tangent;
  6229. if ( attribute !== undefined ) {
  6230. attribute.copyVector4sArray( geometry.tangents );
  6231. attribute.needsUpdate = true;
  6232. }
  6233. geometry.tangentsNeedUpdate = false;
  6234. }
  6235. if ( geometry.lineDistancesNeedUpdate ) {
  6236. var attribute = this.attributes.lineDistance;
  6237. if ( attribute !== undefined ) {
  6238. attribute.copyArray( geometry.lineDistances );
  6239. attribute.needsUpdate = true;
  6240. }
  6241. geometry.lineDistancesNeedUpdate = false;
  6242. }
  6243. return this;
  6244. },
  6245. fromGeometry: function ( geometry ) {
  6246. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6247. return this.fromDirectGeometry( geometry.__directGeometry );
  6248. },
  6249. fromDirectGeometry: function ( geometry ) {
  6250. var positions = new Float32Array( geometry.vertices.length * 3 );
  6251. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6252. if ( geometry.normals.length > 0 ) {
  6253. var normals = new Float32Array( geometry.normals.length * 3 );
  6254. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6255. }
  6256. if ( geometry.colors.length > 0 ) {
  6257. var colors = new Float32Array( geometry.colors.length * 3 );
  6258. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6259. }
  6260. if ( geometry.uvs.length > 0 ) {
  6261. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6262. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6263. }
  6264. if ( geometry.uvs2.length > 0 ) {
  6265. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6266. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6267. }
  6268. if ( geometry.tangents.length > 0 ) {
  6269. var tangents = new Float32Array( geometry.tangents.length * 4 );
  6270. this.addAttribute( 'tangent', new THREE.BufferAttribute( tangents, 4 ).copyVector4sArray( geometry.tangents ) );
  6271. }
  6272. if ( geometry.indices.length > 0 ) {
  6273. var indices = new Uint16Array( geometry.indices.length * 3 );
  6274. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6275. }
  6276. // morphs
  6277. if ( geometry.morphTargets.length > 0 ) {
  6278. var morphTargets = geometry.morphTargets;
  6279. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6280. var morphTarget = morphTargets[ i ];
  6281. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6282. this.morphAttributes.push( attribute.copyVector3sArray( morphTarget ) );
  6283. }
  6284. // TODO normals, colors
  6285. }
  6286. // skinning
  6287. if ( geometry.skinIndices.length > 0 ) {
  6288. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6289. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6290. }
  6291. if ( geometry.skinWeights.length > 0 ) {
  6292. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6293. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6294. }
  6295. //
  6296. if ( geometry.boundingSphere !== null ) {
  6297. this.boundingSphere = geometry.boundingSphere.clone();
  6298. }
  6299. if ( geometry.boundingBox !== null ) {
  6300. this.boundingBox = geometry.boundingBox.clone();
  6301. }
  6302. return this;
  6303. },
  6304. computeBoundingBox: function () {
  6305. var vector = new THREE.Vector3();
  6306. return function () {
  6307. if ( this.boundingBox === null ) {
  6308. this.boundingBox = new THREE.Box3();
  6309. }
  6310. var positions = this.attributes.position.array;
  6311. if ( positions ) {
  6312. var bb = this.boundingBox;
  6313. bb.makeEmpty();
  6314. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6315. vector.fromArray( positions, i );
  6316. bb.expandByPoint( vector );
  6317. }
  6318. }
  6319. if ( positions === undefined || positions.length === 0 ) {
  6320. this.boundingBox.min.set( 0, 0, 0 );
  6321. this.boundingBox.max.set( 0, 0, 0 );
  6322. }
  6323. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6324. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6325. }
  6326. };
  6327. }(),
  6328. computeBoundingSphere: function () {
  6329. var box = new THREE.Box3();
  6330. var vector = new THREE.Vector3();
  6331. return function () {
  6332. if ( this.boundingSphere === null ) {
  6333. this.boundingSphere = new THREE.Sphere();
  6334. }
  6335. var positions = this.attributes.position.array;
  6336. if ( positions ) {
  6337. box.makeEmpty();
  6338. var center = this.boundingSphere.center;
  6339. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6340. vector.fromArray( positions, i );
  6341. box.expandByPoint( vector );
  6342. }
  6343. box.center( center );
  6344. // hoping to find a boundingSphere with a radius smaller than the
  6345. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6346. var maxRadiusSq = 0;
  6347. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6348. vector.fromArray( positions, i );
  6349. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6350. }
  6351. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6352. if ( isNaN( this.boundingSphere.radius ) ) {
  6353. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6354. }
  6355. }
  6356. };
  6357. }(),
  6358. computeFaceNormals: function () {
  6359. // backwards compatibility
  6360. },
  6361. computeVertexNormals: function () {
  6362. var attributes = this.attributes;
  6363. if ( attributes.position ) {
  6364. var positions = attributes.position.array;
  6365. if ( attributes.normal === undefined ) {
  6366. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6367. } else {
  6368. // reset existing normals to zero
  6369. var normals = attributes.normal.array;
  6370. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6371. normals[ i ] = 0;
  6372. }
  6373. }
  6374. var normals = attributes.normal.array;
  6375. var vA, vB, vC,
  6376. pA = new THREE.Vector3(),
  6377. pB = new THREE.Vector3(),
  6378. pC = new THREE.Vector3(),
  6379. cb = new THREE.Vector3(),
  6380. ab = new THREE.Vector3();
  6381. // indexed elements
  6382. if ( attributes.index ) {
  6383. var indices = attributes.index.array;
  6384. if ( this.drawcalls.length === 0 ) {
  6385. this.addDrawCall( 0, indices.length );
  6386. }
  6387. for ( var j = 0, jl = this.drawcalls.length; j < jl; ++ j ) {
  6388. var start = this.drawcalls[ j ].start;
  6389. var count = this.drawcalls[ j ].count;
  6390. var index = this.drawcalls[ j ].index;
  6391. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6392. vA = ( index + indices[ i ] ) * 3;
  6393. vB = ( index + indices[ i + 1 ] ) * 3;
  6394. vC = ( index + indices[ i + 2 ] ) * 3;
  6395. pA.fromArray( positions, vA );
  6396. pB.fromArray( positions, vB );
  6397. pC.fromArray( positions, vC );
  6398. cb.subVectors( pC, pB );
  6399. ab.subVectors( pA, pB );
  6400. cb.cross( ab );
  6401. normals[ vA ] += cb.x;
  6402. normals[ vA + 1 ] += cb.y;
  6403. normals[ vA + 2 ] += cb.z;
  6404. normals[ vB ] += cb.x;
  6405. normals[ vB + 1 ] += cb.y;
  6406. normals[ vB + 2 ] += cb.z;
  6407. normals[ vC ] += cb.x;
  6408. normals[ vC + 1 ] += cb.y;
  6409. normals[ vC + 2 ] += cb.z;
  6410. }
  6411. }
  6412. } else {
  6413. // non-indexed elements (unconnected triangle soup)
  6414. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6415. pA.fromArray( positions, i );
  6416. pB.fromArray( positions, i + 3 );
  6417. pC.fromArray( positions, i + 6 );
  6418. cb.subVectors( pC, pB );
  6419. ab.subVectors( pA, pB );
  6420. cb.cross( ab );
  6421. normals[ i ] = cb.x;
  6422. normals[ i + 1 ] = cb.y;
  6423. normals[ i + 2 ] = cb.z;
  6424. normals[ i + 3 ] = cb.x;
  6425. normals[ i + 4 ] = cb.y;
  6426. normals[ i + 5 ] = cb.z;
  6427. normals[ i + 6 ] = cb.x;
  6428. normals[ i + 7 ] = cb.y;
  6429. normals[ i + 8 ] = cb.z;
  6430. }
  6431. }
  6432. this.normalizeNormals();
  6433. attributes.normal.needsUpdate = true;
  6434. }
  6435. },
  6436. computeTangents: function () {
  6437. // based on http://www.terathon.com/code/tangent.html
  6438. // (per vertex tangents)
  6439. if ( this.attributes.index === undefined ||
  6440. this.attributes.position === undefined ||
  6441. this.attributes.normal === undefined ||
  6442. this.attributes.uv === undefined ) {
  6443. console.warn( 'THREE.BufferGeometry: Missing required attributes (index, position, normal or uv) in BufferGeometry.computeTangents()' );
  6444. return;
  6445. }
  6446. var indices = this.attributes.index.array;
  6447. var positions = this.attributes.position.array;
  6448. var normals = this.attributes.normal.array;
  6449. var uvs = this.attributes.uv.array;
  6450. var nVertices = positions.length / 3;
  6451. if ( this.attributes.tangent === undefined ) {
  6452. this.addAttribute( 'tangent', new THREE.BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
  6453. }
  6454. var tangents = this.attributes.tangent.array;
  6455. var tan1 = [], tan2 = [];
  6456. for ( var k = 0; k < nVertices; k ++ ) {
  6457. tan1[ k ] = new THREE.Vector3();
  6458. tan2[ k ] = new THREE.Vector3();
  6459. }
  6460. var vA = new THREE.Vector3(),
  6461. vB = new THREE.Vector3(),
  6462. vC = new THREE.Vector3(),
  6463. uvA = new THREE.Vector2(),
  6464. uvB = new THREE.Vector2(),
  6465. uvC = new THREE.Vector2(),
  6466. x1, x2, y1, y2, z1, z2,
  6467. s1, s2, t1, t2, r;
  6468. var sdir = new THREE.Vector3(), tdir = new THREE.Vector3();
  6469. function handleTriangle( a, b, c ) {
  6470. vA.fromArray( positions, a * 3 );
  6471. vB.fromArray( positions, b * 3 );
  6472. vC.fromArray( positions, c * 3 );
  6473. uvA.fromArray( uvs, a * 2 );
  6474. uvB.fromArray( uvs, b * 2 );
  6475. uvC.fromArray( uvs, c * 2 );
  6476. x1 = vB.x - vA.x;
  6477. x2 = vC.x - vA.x;
  6478. y1 = vB.y - vA.y;
  6479. y2 = vC.y - vA.y;
  6480. z1 = vB.z - vA.z;
  6481. z2 = vC.z - vA.z;
  6482. s1 = uvB.x - uvA.x;
  6483. s2 = uvC.x - uvA.x;
  6484. t1 = uvB.y - uvA.y;
  6485. t2 = uvC.y - uvA.y;
  6486. r = 1.0 / ( s1 * t2 - s2 * t1 );
  6487. sdir.set(
  6488. ( t2 * x1 - t1 * x2 ) * r,
  6489. ( t2 * y1 - t1 * y2 ) * r,
  6490. ( t2 * z1 - t1 * z2 ) * r
  6491. );
  6492. tdir.set(
  6493. ( s1 * x2 - s2 * x1 ) * r,
  6494. ( s1 * y2 - s2 * y1 ) * r,
  6495. ( s1 * z2 - s2 * z1 ) * r
  6496. );
  6497. tan1[ a ].add( sdir );
  6498. tan1[ b ].add( sdir );
  6499. tan1[ c ].add( sdir );
  6500. tan2[ a ].add( tdir );
  6501. tan2[ b ].add( tdir );
  6502. tan2[ c ].add( tdir );
  6503. }
  6504. var i, il;
  6505. var j, jl;
  6506. var iA, iB, iC;
  6507. if ( this.drawcalls.length === 0 ) {
  6508. this.addDrawCall( 0, indices.length );
  6509. }
  6510. var drawcalls = this.drawcalls;
  6511. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6512. var start = drawcalls[ j ].start;
  6513. var count = drawcalls[ j ].count;
  6514. var index = drawcalls[ j ].index;
  6515. for ( i = start, il = start + count; i < il; i += 3 ) {
  6516. iA = index + indices[ i ];
  6517. iB = index + indices[ i + 1 ];
  6518. iC = index + indices[ i + 2 ];
  6519. handleTriangle( iA, iB, iC );
  6520. }
  6521. }
  6522. var tmp = new THREE.Vector3(), tmp2 = new THREE.Vector3();
  6523. var n = new THREE.Vector3(), n2 = new THREE.Vector3();
  6524. var w, t, test;
  6525. function handleVertex( v ) {
  6526. n.fromArray( normals, v * 3 );
  6527. n2.copy( n );
  6528. t = tan1[ v ];
  6529. // Gram-Schmidt orthogonalize
  6530. tmp.copy( t );
  6531. tmp.sub( n.multiplyScalar( n.dot( t ) ) ).normalize();
  6532. // Calculate handedness
  6533. tmp2.crossVectors( n2, t );
  6534. test = tmp2.dot( tan2[ v ] );
  6535. w = ( test < 0.0 ) ? - 1.0 : 1.0;
  6536. tangents[ v * 4 ] = tmp.x;
  6537. tangents[ v * 4 + 1 ] = tmp.y;
  6538. tangents[ v * 4 + 2 ] = tmp.z;
  6539. tangents[ v * 4 + 3 ] = w;
  6540. }
  6541. for ( j = 0, jl = drawcalls.length; j < jl; ++ j ) {
  6542. var start = drawcalls[ j ].start;
  6543. var count = drawcalls[ j ].count;
  6544. var index = drawcalls[ j ].index;
  6545. for ( i = start, il = start + count; i < il; i += 3 ) {
  6546. iA = index + indices[ i ];
  6547. iB = index + indices[ i + 1 ];
  6548. iC = index + indices[ i + 2 ];
  6549. handleVertex( iA );
  6550. handleVertex( iB );
  6551. handleVertex( iC );
  6552. }
  6553. }
  6554. },
  6555. /*
  6556. Compute the draw offset for large models by chunking the index buffer into chunks of 65k addressable vertices.
  6557. This method will effectively rewrite the index buffer and remap all attributes to match the new indices.
  6558. WARNING: This method will also expand the vertex count to prevent sprawled triangles across draw offsets.
  6559. size - Defaults to 65535 or 4294967296 if extension OES_element_index_uint supported, but allows for larger or smaller chunks.
  6560. */
  6561. computeOffsets: function ( size ) {
  6562. if ( size === undefined ) size = THREE.BufferGeometry.MaxIndex;
  6563. var indices = this.attributes.index.array;
  6564. var vertices = this.attributes.position.array;
  6565. var facesCount = ( indices.length / 3 );
  6566. var UintArray = ( ( vertices.length / 3 ) > 65535 && THREE.BufferGeometry.MaxIndex > 65535 ) ? Uint32Array : Uint16Array;
  6567. /*
  6568. console.log("Computing buffers in offsets of "+size+" -> indices:"+indices.length+" vertices:"+vertices.length);
  6569. console.log("Faces to process: "+(indices.length/3));
  6570. console.log("Reordering "+verticesCount+" vertices.");
  6571. */
  6572. var sortedIndices = new UintArray( indices.length );
  6573. var indexPtr = 0;
  6574. var vertexPtr = 0;
  6575. var tmpOffsets = [ { start:0, count:0, index:0 } ];
  6576. var offset = tmpOffsets[ 0 ];
  6577. var duplicatedVertices = 0;
  6578. var newVerticeMaps = 0;
  6579. var faceVertices = new Int32Array( 6 );
  6580. var vertexMap = new Int32Array( vertices.length );
  6581. var revVertexMap = new Int32Array( vertices.length );
  6582. for ( var j = 0; j < vertices.length; j ++ ) { vertexMap[ j ] = - 1; revVertexMap[ j ] = - 1; }
  6583. /*
  6584. Traverse every face and reorder vertices in the proper offsets of 65k.
  6585. We can have more than 'size' entries in the index buffer per offset, but only reference 'size' values.
  6586. */
  6587. for ( var findex = 0; findex < facesCount; findex ++ ) {
  6588. newVerticeMaps = 0;
  6589. for ( var vo = 0; vo < 3; vo ++ ) {
  6590. var vid = indices[ findex * 3 + vo ];
  6591. if ( vertexMap[ vid ] === - 1 ) {
  6592. //Unmapped vertex
  6593. faceVertices[ vo * 2 ] = vid;
  6594. faceVertices[ vo * 2 + 1 ] = - 1;
  6595. newVerticeMaps ++;
  6596. } else if ( vertexMap[ vid ] < offset.index ) {
  6597. //Reused vertices from previous block (duplicate)
  6598. faceVertices[ vo * 2 ] = vid;
  6599. faceVertices[ vo * 2 + 1 ] = - 1;
  6600. duplicatedVertices ++;
  6601. } else {
  6602. //Reused vertex in the current block
  6603. faceVertices[ vo * 2 ] = vid;
  6604. faceVertices[ vo * 2 + 1 ] = vertexMap[ vid ];
  6605. }
  6606. }
  6607. var faceMax = vertexPtr + newVerticeMaps;
  6608. if ( faceMax > ( offset.index + size ) ) {
  6609. var new_offset = { start:indexPtr, count:0, index:vertexPtr };
  6610. tmpOffsets.push( new_offset );
  6611. offset = new_offset;
  6612. //Re-evaluate reused vertices in light of new offset.
  6613. for ( var v = 0; v < 6; v += 2 ) {
  6614. var new_vid = faceVertices[ v + 1 ];
  6615. if ( new_vid > - 1 && new_vid < offset.index )
  6616. faceVertices[ v + 1 ] = - 1;
  6617. }
  6618. }
  6619. //Reindex the face.
  6620. for ( var v = 0; v < 6; v += 2 ) {
  6621. var vid = faceVertices[ v ];
  6622. var new_vid = faceVertices[ v + 1 ];
  6623. if ( new_vid === - 1 )
  6624. new_vid = vertexPtr ++;
  6625. vertexMap[ vid ] = new_vid;
  6626. revVertexMap[ new_vid ] = vid;
  6627. sortedIndices[ indexPtr ++ ] = new_vid - offset.index; //XXX overflows at 16bit
  6628. offset.count ++;
  6629. }
  6630. }
  6631. /* Move all attribute values to map to the new computed indices , also expand the vertex stack to match our new vertexPtr. */
  6632. this.reorderBuffers( sortedIndices, revVertexMap, vertexPtr );
  6633. this.clearDrawCalls();
  6634. for ( var i = 0; i < tmpOffsets.length; i ++ ) {
  6635. var tmpOffset = tmpOffsets[ i ];
  6636. this.addDrawCall( tmpOffset.start, tmpOffset.count, tmpOffset.index );
  6637. }
  6638. /*
  6639. var orderTime = Date.now();
  6640. console.log("Reorder time: "+(orderTime-s)+"ms");
  6641. console.log("Duplicated "+duplicatedVertices+" vertices.");
  6642. console.log("Compute Buffers time: "+(Date.now()-s)+"ms");
  6643. console.log("Draw tmpOffsets: "+tmpOffsets.length);
  6644. */
  6645. },
  6646. merge: function ( geometry, offset ) {
  6647. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6648. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6649. return;
  6650. }
  6651. if ( offset === undefined ) offset = 0;
  6652. var attributes = this.attributes;
  6653. for ( var key in attributes ) {
  6654. if ( geometry.attributes[ key ] === undefined ) continue;
  6655. var attribute1 = attributes[ key ];
  6656. var attributeArray1 = attribute1.array;
  6657. var attribute2 = geometry.attributes[ key ];
  6658. var attributeArray2 = attribute2.array;
  6659. var attributeSize = attribute2.itemSize;
  6660. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6661. attributeArray1[ j ] = attributeArray2[ i ];
  6662. }
  6663. }
  6664. return this;
  6665. },
  6666. normalizeNormals: function () {
  6667. var normals = this.attributes.normal.array;
  6668. var x, y, z, n;
  6669. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6670. x = normals[ i ];
  6671. y = normals[ i + 1 ];
  6672. z = normals[ i + 2 ];
  6673. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6674. normals[ i ] *= n;
  6675. normals[ i + 1 ] *= n;
  6676. normals[ i + 2 ] *= n;
  6677. }
  6678. },
  6679. /*
  6680. reoderBuffers:
  6681. Reorder attributes based on a new indexBuffer and indexMap.
  6682. indexBuffer - Uint16Array of the new ordered indices.
  6683. indexMap - Int32Array where the position is the new vertex ID and the value the old vertex ID for each vertex.
  6684. vertexCount - Amount of total vertices considered in this reordering (in case you want to grow the vertex stack).
  6685. */
  6686. reorderBuffers: function ( indexBuffer, indexMap, vertexCount ) {
  6687. /* Create a copy of all attributes for reordering. */
  6688. var sortedAttributes = {};
  6689. for ( var attr in this.attributes ) {
  6690. if ( attr === 'index' )
  6691. continue;
  6692. var sourceArray = this.attributes[ attr ].array;
  6693. sortedAttributes[ attr ] = new sourceArray.constructor( this.attributes[ attr ].itemSize * vertexCount );
  6694. }
  6695. /* Move attribute positions based on the new index map */
  6696. for ( var new_vid = 0; new_vid < vertexCount; new_vid ++ ) {
  6697. var vid = indexMap[ new_vid ];
  6698. for ( var attr in this.attributes ) {
  6699. if ( attr === 'index' )
  6700. continue;
  6701. var attrArray = this.attributes[ attr ].array;
  6702. var attrSize = this.attributes[ attr ].itemSize;
  6703. var sortedAttr = sortedAttributes[ attr ];
  6704. for ( var k = 0; k < attrSize; k ++ )
  6705. sortedAttr[ new_vid * attrSize + k ] = attrArray[ vid * attrSize + k ];
  6706. }
  6707. }
  6708. /* Carry the new sorted buffers locally */
  6709. this.attributes[ 'index' ].array = indexBuffer;
  6710. for ( var attr in this.attributes ) {
  6711. if ( attr === 'index' )
  6712. continue;
  6713. this.attributes[ attr ].array = sortedAttributes[ attr ];
  6714. this.attributes[ attr ].numItems = this.attributes[ attr ].itemSize * vertexCount;
  6715. }
  6716. },
  6717. toJSON: function () {
  6718. var data = {
  6719. metadata: {
  6720. version: 4.4,
  6721. type: 'BufferGeometry',
  6722. generator: 'BufferGeometry.toJSON'
  6723. }
  6724. };
  6725. // standard BufferGeometry serialization
  6726. data.uuid = this.uuid;
  6727. data.type = this.type;
  6728. if ( this.name !== '' ) data.name = this.name;
  6729. if ( this.parameters !== undefined ) {
  6730. var parameters = this.parameters;
  6731. for ( var key in parameters ) {
  6732. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6733. }
  6734. return data;
  6735. }
  6736. data.data = { attributes: {} };
  6737. var attributes = this.attributes;
  6738. var drawcalls = this.drawcalls;
  6739. var boundingSphere = this.boundingSphere;
  6740. for ( var key in attributes ) {
  6741. var attribute = attributes[ key ];
  6742. var array = Array.prototype.slice.call( attribute.array );
  6743. data.data.attributes[ key ] = {
  6744. itemSize: attribute.itemSize,
  6745. type: attribute.array.constructor.name,
  6746. array: array
  6747. };
  6748. }
  6749. if ( drawcalls.length > 0 ) {
  6750. data.data.drawcalls = JSON.parse( JSON.stringify( drawcalls ) );
  6751. }
  6752. if ( boundingSphere !== null ) {
  6753. data.data.boundingSphere = {
  6754. center: boundingSphere.center.toArray(),
  6755. radius: boundingSphere.radius
  6756. };
  6757. }
  6758. return data;
  6759. },
  6760. clone: function () {
  6761. var geometry = new THREE.BufferGeometry();
  6762. return geometry.copy( this );
  6763. },
  6764. copy: function ( source ) {
  6765. for ( var attr in source.attributes ) {
  6766. var sourceAttr = source.attributes[ attr ];
  6767. this.addAttribute( attr, sourceAttr.clone() );
  6768. }
  6769. for ( var i = 0, il = source.drawcalls.length; i < il; i ++ ) {
  6770. var offset = source.drawcalls[ i ];
  6771. this.addDrawCall( offset.start, offset.count, offset.index );
  6772. }
  6773. return this;
  6774. },
  6775. dispose: function () {
  6776. this.dispatchEvent( { type: 'dispose' } );
  6777. }
  6778. };
  6779. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6780. THREE.BufferGeometry.MaxIndex = 65535;
  6781. // File:src/core/InstancedBufferGeometry.js
  6782. /**
  6783. * @author benaadams / https://twitter.com/ben_a_adams
  6784. */
  6785. THREE.InstancedBufferGeometry = function () {
  6786. THREE.BufferGeometry.call( this );
  6787. this.type = 'InstancedBufferGeometry';
  6788. this.maxInstancedCount = undefined;
  6789. };
  6790. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6791. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6792. THREE.InstancedBufferGeometry.prototype.addDrawCall = function ( start, count, indexOffset, instances ) {
  6793. this.drawcalls.push( {
  6794. start: start,
  6795. count: count,
  6796. index: indexOffset !== undefined ? indexOffset : 0,
  6797. instances: instances
  6798. } );
  6799. },
  6800. THREE.InstancedBufferGeometry.prototype.clone = function () {
  6801. var geometry = new THREE.InstancedBufferGeometry();
  6802. for ( var attr in this.attributes ) {
  6803. var sourceAttr = this.attributes[attr];
  6804. geometry.addAttribute( attr, sourceAttr.clone() );
  6805. }
  6806. for ( var i = 0, il = this.drawcalls.length; i < il; i++ ) {
  6807. var offset = this.drawcalls[i];
  6808. geometry.addDrawCall( offset.start, offset.count, offset.index, offset.instances );
  6809. }
  6810. return geometry;
  6811. };
  6812. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6813. // File:src/cameras/Camera.js
  6814. /**
  6815. * @author mrdoob / http://mrdoob.com/
  6816. * @author mikael emtinger / http://gomo.se/
  6817. * @author WestLangley / http://github.com/WestLangley
  6818. */
  6819. THREE.Camera = function () {
  6820. THREE.Object3D.call( this );
  6821. this.type = 'Camera';
  6822. this.matrixWorldInverse = new THREE.Matrix4();
  6823. this.projectionMatrix = new THREE.Matrix4();
  6824. };
  6825. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  6826. THREE.Camera.prototype.constructor = THREE.Camera;
  6827. THREE.Camera.prototype.getWorldDirection = function () {
  6828. var quaternion = new THREE.Quaternion();
  6829. return function ( optionalTarget ) {
  6830. var result = optionalTarget || new THREE.Vector3();
  6831. this.getWorldQuaternion( quaternion );
  6832. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  6833. };
  6834. }();
  6835. THREE.Camera.prototype.lookAt = function () {
  6836. // This routine does not support cameras with rotated and/or translated parent(s)
  6837. var m1 = new THREE.Matrix4();
  6838. return function ( vector ) {
  6839. m1.lookAt( this.position, vector, this.up );
  6840. this.quaternion.setFromRotationMatrix( m1 );
  6841. };
  6842. }();
  6843. THREE.Camera.prototype.clone = function () {
  6844. var camera = new THREE.Camera();
  6845. return camera.copy( this );
  6846. };
  6847. THREE.Camera.prototype.copy = function ( source ) {
  6848. THREE.Object3D.prototype.copy.call( this, source );
  6849. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  6850. this.projectionMatrix.copy( source.projectionMatrix );
  6851. return this;
  6852. };
  6853. // File:src/cameras/CubeCamera.js
  6854. /**
  6855. * Camera for rendering cube maps
  6856. * - renders scene into axis-aligned cube
  6857. *
  6858. * @author alteredq / http://alteredqualia.com/
  6859. */
  6860. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  6861. THREE.Object3D.call( this );
  6862. this.type = 'CubeCamera';
  6863. var fov = 90, aspect = 1;
  6864. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6865. cameraPX.up.set( 0, - 1, 0 );
  6866. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  6867. this.add( cameraPX );
  6868. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6869. cameraNX.up.set( 0, - 1, 0 );
  6870. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  6871. this.add( cameraNX );
  6872. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6873. cameraPY.up.set( 0, 0, 1 );
  6874. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  6875. this.add( cameraPY );
  6876. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6877. cameraNY.up.set( 0, 0, - 1 );
  6878. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  6879. this.add( cameraNY );
  6880. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6881. cameraPZ.up.set( 0, - 1, 0 );
  6882. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  6883. this.add( cameraPZ );
  6884. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  6885. cameraNZ.up.set( 0, - 1, 0 );
  6886. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  6887. this.add( cameraNZ );
  6888. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  6889. this.updateCubeMap = function ( renderer, scene ) {
  6890. if ( this.parent === undefined ) this.updateMatrixWorld();
  6891. var renderTarget = this.renderTarget;
  6892. var generateMipmaps = renderTarget.generateMipmaps;
  6893. renderTarget.generateMipmaps = false;
  6894. renderTarget.activeCubeFace = 0;
  6895. renderer.render( scene, cameraPX, renderTarget );
  6896. renderTarget.activeCubeFace = 1;
  6897. renderer.render( scene, cameraNX, renderTarget );
  6898. renderTarget.activeCubeFace = 2;
  6899. renderer.render( scene, cameraPY, renderTarget );
  6900. renderTarget.activeCubeFace = 3;
  6901. renderer.render( scene, cameraNY, renderTarget );
  6902. renderTarget.activeCubeFace = 4;
  6903. renderer.render( scene, cameraPZ, renderTarget );
  6904. renderTarget.generateMipmaps = generateMipmaps;
  6905. renderTarget.activeCubeFace = 5;
  6906. renderer.render( scene, cameraNZ, renderTarget );
  6907. renderer.setRenderTarget( null );
  6908. };
  6909. };
  6910. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  6911. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  6912. // File:src/cameras/OrthographicCamera.js
  6913. /**
  6914. * @author alteredq / http://alteredqualia.com/
  6915. */
  6916. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  6917. THREE.Camera.call( this );
  6918. this.type = 'OrthographicCamera';
  6919. this.zoom = 1;
  6920. this.left = left;
  6921. this.right = right;
  6922. this.top = top;
  6923. this.bottom = bottom;
  6924. this.near = ( near !== undefined ) ? near : 0.1;
  6925. this.far = ( far !== undefined ) ? far : 2000;
  6926. this.updateProjectionMatrix();
  6927. };
  6928. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  6929. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  6930. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  6931. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  6932. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  6933. var cx = ( this.right + this.left ) / 2;
  6934. var cy = ( this.top + this.bottom ) / 2;
  6935. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  6936. };
  6937. THREE.OrthographicCamera.prototype.clone = function () {
  6938. var camera = new THREE.OrthographicCamera();
  6939. camera.copy( this );
  6940. camera.zoom = this.zoom;
  6941. camera.left = this.left;
  6942. camera.right = this.right;
  6943. camera.top = this.top;
  6944. camera.bottom = this.bottom;
  6945. camera.near = this.near;
  6946. camera.far = this.far;
  6947. return camera;
  6948. };
  6949. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  6950. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  6951. data.object.zoom = this.zoom;
  6952. data.object.left = this.left;
  6953. data.object.right = this.right;
  6954. data.object.top = this.top;
  6955. data.object.bottom = this.bottom;
  6956. data.object.near = this.near;
  6957. data.object.far = this.far;
  6958. return data;
  6959. };
  6960. // File:src/cameras/PerspectiveCamera.js
  6961. /**
  6962. * @author mrdoob / http://mrdoob.com/
  6963. * @author greggman / http://games.greggman.com/
  6964. * @author zz85 / http://www.lab4games.net/zz85/blog
  6965. */
  6966. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  6967. THREE.Camera.call( this );
  6968. this.type = 'PerspectiveCamera';
  6969. this.zoom = 1;
  6970. this.fov = fov !== undefined ? fov : 50;
  6971. this.aspect = aspect !== undefined ? aspect : 1;
  6972. this.near = near !== undefined ? near : 0.1;
  6973. this.far = far !== undefined ? far : 2000;
  6974. this.updateProjectionMatrix();
  6975. };
  6976. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  6977. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  6978. /**
  6979. * Uses Focal Length (in mm) to estimate and set FOV
  6980. * 35mm (full-frame) camera is used if frame size is not specified;
  6981. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  6982. */
  6983. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  6984. if ( frameHeight === undefined ) frameHeight = 24;
  6985. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  6986. this.updateProjectionMatrix();
  6987. };
  6988. /**
  6989. * Sets an offset in a larger frustum. This is useful for multi-window or
  6990. * multi-monitor/multi-machine setups.
  6991. *
  6992. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  6993. * the monitors are in grid like this
  6994. *
  6995. * +---+---+---+
  6996. * | A | B | C |
  6997. * +---+---+---+
  6998. * | D | E | F |
  6999. * +---+---+---+
  7000. *
  7001. * then for each monitor you would call it like this
  7002. *
  7003. * var w = 1920;
  7004. * var h = 1080;
  7005. * var fullWidth = w * 3;
  7006. * var fullHeight = h * 2;
  7007. *
  7008. * --A--
  7009. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  7010. * --B--
  7011. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  7012. * --C--
  7013. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  7014. * --D--
  7015. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  7016. * --E--
  7017. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  7018. * --F--
  7019. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  7020. *
  7021. * Note there is no reason monitors have to be the same size or in a grid.
  7022. */
  7023. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  7024. this.fullWidth = fullWidth;
  7025. this.fullHeight = fullHeight;
  7026. this.x = x;
  7027. this.y = y;
  7028. this.width = width;
  7029. this.height = height;
  7030. this.updateProjectionMatrix();
  7031. };
  7032. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  7033. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  7034. if ( this.fullWidth ) {
  7035. var aspect = this.fullWidth / this.fullHeight;
  7036. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  7037. var bottom = - top;
  7038. var left = aspect * bottom;
  7039. var right = aspect * top;
  7040. var width = Math.abs( right - left );
  7041. var height = Math.abs( top - bottom );
  7042. this.projectionMatrix.makeFrustum(
  7043. left + this.x * width / this.fullWidth,
  7044. left + ( this.x + this.width ) * width / this.fullWidth,
  7045. top - ( this.y + this.height ) * height / this.fullHeight,
  7046. top - this.y * height / this.fullHeight,
  7047. this.near,
  7048. this.far
  7049. );
  7050. } else {
  7051. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  7052. }
  7053. };
  7054. THREE.PerspectiveCamera.prototype.clone = function () {
  7055. var camera = new THREE.PerspectiveCamera();
  7056. camera.copy( this );
  7057. camera.zoom = this.zoom;
  7058. camera.fov = this.fov;
  7059. camera.aspect = this.aspect;
  7060. camera.near = this.near;
  7061. camera.far = this.far;
  7062. return camera;
  7063. };
  7064. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  7065. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7066. data.object.zoom = this.zoom;
  7067. data.object.fov = this.fov;
  7068. data.object.aspect = this.aspect;
  7069. data.object.near = this.near;
  7070. data.object.far = this.far;
  7071. return data;
  7072. };
  7073. // File:src/lights/Light.js
  7074. /**
  7075. * @author mrdoob / http://mrdoob.com/
  7076. * @author alteredq / http://alteredqualia.com/
  7077. */
  7078. THREE.Light = function ( color ) {
  7079. THREE.Object3D.call( this );
  7080. this.type = 'Light';
  7081. this.color = new THREE.Color( color );
  7082. };
  7083. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  7084. THREE.Light.prototype.constructor = THREE.Light;
  7085. THREE.Light.prototype.clone = function () {
  7086. var light = new THREE.Light();
  7087. return light.copy( this );
  7088. };
  7089. THREE.Light.prototype.copy = function ( source ) {
  7090. THREE.Object3D.prototype.copy.call( this, source );
  7091. this.color.copy( source.color );
  7092. return this;
  7093. };
  7094. // File:src/lights/AmbientLight.js
  7095. /**
  7096. * @author mrdoob / http://mrdoob.com/
  7097. */
  7098. THREE.AmbientLight = function ( color ) {
  7099. THREE.Light.call( this, color );
  7100. this.type = 'AmbientLight';
  7101. };
  7102. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  7103. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  7104. THREE.AmbientLight.prototype.clone = function () {
  7105. var light = new THREE.AmbientLight();
  7106. light.copy( this );
  7107. return light;
  7108. };
  7109. THREE.AmbientLight.prototype.toJSON = function ( meta ) {
  7110. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7111. data.object.color = this.color.getHex();
  7112. return data;
  7113. };
  7114. // File:src/lights/AreaLight.js
  7115. /**
  7116. * @author MPanknin / http://www.redplant.de/
  7117. * @author alteredq / http://alteredqualia.com/
  7118. * @author prafullit
  7119. */
  7120. THREE.AreaLight = function ( color, intensity ) {
  7121. THREE.Light.call( this, color );
  7122. this.type = 'AreaLight';
  7123. this.normal = new THREE.Vector3( 0, - 1, 0 );
  7124. this.right = new THREE.Vector3( 1, 0, 0 );
  7125. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7126. this.width = 1.0;
  7127. this.height = 1.0;
  7128. this.constantAttenuation = 1.5;
  7129. this.linearAttenuation = 0.5;
  7130. this.quadraticAttenuation = 0.1;
  7131. };
  7132. THREE.AreaLight.prototype = Object.create( THREE.Light.prototype );
  7133. THREE.AreaLight.prototype.constructor = THREE.AreaLight;
  7134. THREE.AreaLight.prototype.clone = function () {
  7135. var light = new THREE.AreaLight();
  7136. light.copy( this );
  7137. light.normal.copy(this.normal);
  7138. light.right.copy(this.right);
  7139. light.intensity = this.intensity;
  7140. light.width = this.width;
  7141. light.height = this.height;
  7142. light.constantAttenuation = this.constantAttenuation;
  7143. light.linearAttenuation = this.linearAttenuation;
  7144. light.quadraticAttenuation = this.quadraticAttenuation;
  7145. return light;
  7146. };
  7147. THREE.AreaLight.prototype.toJSON = function ( meta ) {
  7148. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7149. data.object.color = this.color.getHex();
  7150. data.object.intensity = this.intensity;
  7151. return data;
  7152. };
  7153. // File:src/lights/DirectionalLight.js
  7154. /**
  7155. * @author mrdoob / http://mrdoob.com/
  7156. * @author alteredq / http://alteredqualia.com/
  7157. */
  7158. THREE.DirectionalLight = function ( color, intensity ) {
  7159. THREE.Light.call( this, color );
  7160. this.type = 'DirectionalLight';
  7161. this.position.set( 0, 1, 0 );
  7162. this.target = new THREE.Object3D();
  7163. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7164. this.castShadow = false;
  7165. this.onlyShadow = false;
  7166. //
  7167. this.shadowCameraNear = 50;
  7168. this.shadowCameraFar = 5000;
  7169. this.shadowCameraLeft = - 500;
  7170. this.shadowCameraRight = 500;
  7171. this.shadowCameraTop = 500;
  7172. this.shadowCameraBottom = - 500;
  7173. this.shadowCameraVisible = false;
  7174. this.shadowBias = 0;
  7175. this.shadowDarkness = 0.5;
  7176. this.shadowMapWidth = 512;
  7177. this.shadowMapHeight = 512;
  7178. //
  7179. this.shadowCascade = false;
  7180. this.shadowCascadeOffset = new THREE.Vector3( 0, 0, - 1000 );
  7181. this.shadowCascadeCount = 2;
  7182. this.shadowCascadeBias = [ 0, 0, 0 ];
  7183. this.shadowCascadeWidth = [ 512, 512, 512 ];
  7184. this.shadowCascadeHeight = [ 512, 512, 512 ];
  7185. this.shadowCascadeNearZ = [ - 1.000, 0.990, 0.998 ];
  7186. this.shadowCascadeFarZ = [ 0.990, 0.998, 1.000 ];
  7187. this.shadowCascadeArray = [];
  7188. //
  7189. this.shadowMap = null;
  7190. this.shadowMapSize = null;
  7191. this.shadowCamera = null;
  7192. this.shadowMatrix = null;
  7193. };
  7194. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  7195. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  7196. THREE.DirectionalLight.prototype.clone = function () {
  7197. var light = new THREE.DirectionalLight();
  7198. light.copy( this );
  7199. light.target = this.target.clone();
  7200. light.intensity = this.intensity;
  7201. light.castShadow = this.castShadow;
  7202. light.onlyShadow = this.onlyShadow;
  7203. //
  7204. light.shadowCameraNear = this.shadowCameraNear;
  7205. light.shadowCameraFar = this.shadowCameraFar;
  7206. light.shadowCameraLeft = this.shadowCameraLeft;
  7207. light.shadowCameraRight = this.shadowCameraRight;
  7208. light.shadowCameraTop = this.shadowCameraTop;
  7209. light.shadowCameraBottom = this.shadowCameraBottom;
  7210. light.shadowCameraVisible = this.shadowCameraVisible;
  7211. light.shadowBias = this.shadowBias;
  7212. light.shadowDarkness = this.shadowDarkness;
  7213. light.shadowMapWidth = this.shadowMapWidth;
  7214. light.shadowMapHeight = this.shadowMapHeight;
  7215. //
  7216. light.shadowCascade = this.shadowCascade;
  7217. light.shadowCascadeOffset.copy( this.shadowCascadeOffset );
  7218. light.shadowCascadeCount = this.shadowCascadeCount;
  7219. light.shadowCascadeBias = this.shadowCascadeBias.slice( 0 );
  7220. light.shadowCascadeWidth = this.shadowCascadeWidth.slice( 0 );
  7221. light.shadowCascadeHeight = this.shadowCascadeHeight.slice( 0 );
  7222. light.shadowCascadeNearZ = this.shadowCascadeNearZ.slice( 0 );
  7223. light.shadowCascadeFarZ = this.shadowCascadeFarZ.slice( 0 );
  7224. return light;
  7225. };
  7226. THREE.DirectionalLight.prototype.toJSON = function ( meta ) {
  7227. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7228. data.object.color = this.color.getHex();
  7229. data.object.intensity = this.intensity;
  7230. return data;
  7231. };
  7232. // File:src/lights/HemisphereLight.js
  7233. /**
  7234. * @author alteredq / http://alteredqualia.com/
  7235. */
  7236. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  7237. THREE.Light.call( this, skyColor );
  7238. this.type = 'HemisphereLight';
  7239. this.position.set( 0, 100, 0 );
  7240. this.groundColor = new THREE.Color( groundColor );
  7241. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7242. };
  7243. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  7244. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  7245. THREE.HemisphereLight.prototype.clone = function () {
  7246. var light = new THREE.HemisphereLight();
  7247. light.copy( this );
  7248. light.groundColor.copy( this.groundColor );
  7249. light.intensity = this.intensity;
  7250. return light;
  7251. };
  7252. THREE.HemisphereLight.prototype.toJSON = function ( meta ) {
  7253. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7254. data.object.color = this.color.getHex();
  7255. data.object.groundColor = this.groundColor.getHex();
  7256. return data;
  7257. };
  7258. // File:src/lights/PointLight.js
  7259. /**
  7260. * @author mrdoob / http://mrdoob.com/
  7261. */
  7262. THREE.PointLight = function ( color, intensity, distance, decay ) {
  7263. THREE.Light.call( this, color );
  7264. this.type = 'PointLight';
  7265. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7266. this.distance = ( distance !== undefined ) ? distance : 0;
  7267. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7268. };
  7269. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  7270. THREE.PointLight.prototype.constructor = THREE.PointLight;
  7271. THREE.PointLight.prototype.clone = function () {
  7272. var light = new THREE.PointLight();
  7273. light.copy( this );
  7274. light.intensity = this.intensity;
  7275. light.distance = this.distance;
  7276. light.decay = this.decay;
  7277. return light;
  7278. };
  7279. THREE.PointLight.prototype.toJSON = function ( meta ) {
  7280. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7281. data.object.color = this.color.getHex();
  7282. data.object.intensity = this.intensity;
  7283. data.object.distance = this.distance;
  7284. data.object.decay = this.decay;
  7285. return data;
  7286. };
  7287. // File:src/lights/SpotLight.js
  7288. /**
  7289. * @author alteredq / http://alteredqualia.com/
  7290. */
  7291. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  7292. THREE.Light.call( this, color );
  7293. this.type = 'SpotLight';
  7294. this.position.set( 0, 1, 0 );
  7295. this.target = new THREE.Object3D();
  7296. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  7297. this.distance = ( distance !== undefined ) ? distance : 0;
  7298. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  7299. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  7300. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  7301. this.castShadow = false;
  7302. this.onlyShadow = false;
  7303. //
  7304. this.shadowCameraNear = 50;
  7305. this.shadowCameraFar = 5000;
  7306. this.shadowCameraFov = 50;
  7307. this.shadowCameraVisible = false;
  7308. this.shadowBias = 0;
  7309. this.shadowDarkness = 0.5;
  7310. this.shadowMapWidth = 512;
  7311. this.shadowMapHeight = 512;
  7312. //
  7313. this.shadowMap = null;
  7314. this.shadowMapSize = null;
  7315. this.shadowCamera = null;
  7316. this.shadowMatrix = null;
  7317. };
  7318. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  7319. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  7320. THREE.SpotLight.prototype.clone = function () {
  7321. var light = new THREE.SpotLight();
  7322. light.copy( this );
  7323. light.target = this.target.clone();
  7324. light.intensity = this.intensity;
  7325. light.distance = this.distance;
  7326. light.angle = this.angle;
  7327. light.exponent = this.exponent;
  7328. light.decay = this.decay;
  7329. light.castShadow = this.castShadow;
  7330. light.onlyShadow = this.onlyShadow;
  7331. //
  7332. light.shadowCameraNear = this.shadowCameraNear;
  7333. light.shadowCameraFar = this.shadowCameraFar;
  7334. light.shadowCameraFov = this.shadowCameraFov;
  7335. light.shadowCameraVisible = this.shadowCameraVisible;
  7336. light.shadowBias = this.shadowBias;
  7337. light.shadowDarkness = this.shadowDarkness;
  7338. light.shadowMapWidth = this.shadowMapWidth;
  7339. light.shadowMapHeight = this.shadowMapHeight;
  7340. return light;
  7341. };
  7342. THREE.SpotLight.prototype.toJSON = function ( meta ) {
  7343. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  7344. data.object.color = this.color.getHex();
  7345. data.object.intensity = this.intensity;
  7346. data.object.distance = this.distance;
  7347. data.object.angle = this.angle;
  7348. data.object.exponent = this.exponent;
  7349. data.object.decay = this.decay;
  7350. return data;
  7351. };
  7352. // File:src/loaders/Cache.js
  7353. /**
  7354. * @author mrdoob / http://mrdoob.com/
  7355. */
  7356. THREE.Cache = {
  7357. enabled: false,
  7358. files: {},
  7359. add: function ( key, file ) {
  7360. if ( this.enabled === false ) return;
  7361. // console.log( 'THREE.Cache', 'Adding key:', key );
  7362. this.files[ key ] = file;
  7363. },
  7364. get: function ( key ) {
  7365. if ( this.enabled === false ) return;
  7366. // console.log( 'THREE.Cache', 'Checking key:', key );
  7367. return this.files[ key ];
  7368. },
  7369. remove: function ( key ) {
  7370. delete this.files[ key ];
  7371. },
  7372. clear: function () {
  7373. this.files = {};
  7374. }
  7375. };
  7376. // File:src/loaders/Loader.js
  7377. /**
  7378. * @author alteredq / http://alteredqualia.com/
  7379. */
  7380. THREE.Loader = function () {
  7381. this.onLoadStart = function () {};
  7382. this.onLoadProgress = function () {};
  7383. this.onLoadComplete = function () {};
  7384. };
  7385. THREE.Loader.prototype = {
  7386. constructor: THREE.Loader,
  7387. crossOrigin: undefined,
  7388. extractUrlBase: function ( url ) {
  7389. var parts = url.split( '/' );
  7390. if ( parts.length === 1 ) return './';
  7391. parts.pop();
  7392. return parts.join( '/' ) + '/';
  7393. },
  7394. initMaterials: function ( materials, texturePath, crossOrigin ) {
  7395. var array = [];
  7396. for ( var i = 0; i < materials.length; ++ i ) {
  7397. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  7398. }
  7399. return array;
  7400. },
  7401. needsTangents: function ( materials ) {
  7402. for ( var i = 0, il = materials.length; i < il; i ++ ) {
  7403. var m = materials[ i ];
  7404. if ( m instanceof THREE.ShaderMaterial ) return true;
  7405. }
  7406. return false;
  7407. },
  7408. createMaterial: ( function () {
  7409. var imageLoader;
  7410. return function createMaterial( m, texturePath, crossOrigin ) {
  7411. var scope = this;
  7412. if ( crossOrigin === undefined && scope.crossOrigin !== undefined ) crossOrigin = scope.crossOrigin;
  7413. if ( imageLoader === undefined ) imageLoader = new THREE.ImageLoader();
  7414. function nearest_pow2( n ) {
  7415. var l = Math.log( n ) / Math.LN2;
  7416. return Math.pow( 2, Math.round( l ) );
  7417. }
  7418. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  7419. var fullPath = texturePath + sourceFile;
  7420. var texture;
  7421. var loader = THREE.Loader.Handlers.get( fullPath );
  7422. if ( loader !== null ) {
  7423. texture = loader.load( fullPath );
  7424. } else {
  7425. texture = new THREE.Texture();
  7426. loader = imageLoader;
  7427. loader.setCrossOrigin( crossOrigin );
  7428. loader.load( fullPath, function ( image ) {
  7429. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  7430. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  7431. var width = nearest_pow2( image.width );
  7432. var height = nearest_pow2( image.height );
  7433. var canvas = document.createElement( 'canvas' );
  7434. canvas.width = width;
  7435. canvas.height = height;
  7436. var context = canvas.getContext( '2d' );
  7437. context.drawImage( image, 0, 0, width, height );
  7438. texture.image = canvas;
  7439. } else {
  7440. texture.image = image;
  7441. }
  7442. texture.needsUpdate = true;
  7443. } );
  7444. }
  7445. texture.sourceFile = sourceFile;
  7446. if ( repeat ) {
  7447. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  7448. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  7449. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  7450. }
  7451. if ( offset ) {
  7452. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  7453. }
  7454. if ( wrap ) {
  7455. var wrapMap = {
  7456. 'repeat': THREE.RepeatWrapping,
  7457. 'mirror': THREE.MirroredRepeatWrapping
  7458. };
  7459. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  7460. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  7461. }
  7462. if ( anisotropy ) {
  7463. texture.anisotropy = anisotropy;
  7464. }
  7465. where[ name ] = texture;
  7466. }
  7467. function rgb2hex( rgb ) {
  7468. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  7469. }
  7470. // defaults
  7471. var mtype = 'MeshLambertMaterial';
  7472. var mpars = { color: 0xeeeeee, opacity: 1.0, map: null, lightMap: null, normalMap: null, bumpMap: null, wireframe: false };
  7473. // parameters from model file
  7474. if ( m.shading ) {
  7475. var shading = m.shading.toLowerCase();
  7476. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  7477. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  7478. }
  7479. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  7480. mpars.blending = THREE[ m.blending ];
  7481. }
  7482. if ( m.transparent !== undefined ) {
  7483. mpars.transparent = m.transparent;
  7484. }
  7485. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  7486. mpars.transparent = true;
  7487. }
  7488. if ( m.depthTest !== undefined ) {
  7489. mpars.depthTest = m.depthTest;
  7490. }
  7491. if ( m.depthWrite !== undefined ) {
  7492. mpars.depthWrite = m.depthWrite;
  7493. }
  7494. if ( m.visible !== undefined ) {
  7495. mpars.visible = m.visible;
  7496. }
  7497. if ( m.flipSided !== undefined ) {
  7498. mpars.side = THREE.BackSide;
  7499. }
  7500. if ( m.doubleSided !== undefined ) {
  7501. mpars.side = THREE.DoubleSide;
  7502. }
  7503. if ( m.wireframe !== undefined ) {
  7504. mpars.wireframe = m.wireframe;
  7505. }
  7506. if ( m.vertexColors !== undefined ) {
  7507. if ( m.vertexColors === 'face' ) {
  7508. mpars.vertexColors = THREE.FaceColors;
  7509. } else if ( m.vertexColors ) {
  7510. mpars.vertexColors = THREE.VertexColors;
  7511. }
  7512. }
  7513. // colors
  7514. if ( m.colorDiffuse ) {
  7515. mpars.color = rgb2hex( m.colorDiffuse );
  7516. } else if ( m.DbgColor ) {
  7517. mpars.color = m.DbgColor;
  7518. }
  7519. if ( m.colorSpecular ) {
  7520. mpars.specular = rgb2hex( m.colorSpecular );
  7521. }
  7522. if ( m.colorEmissive ) {
  7523. mpars.emissive = rgb2hex( m.colorEmissive );
  7524. }
  7525. // modifiers
  7526. if ( m.transparency !== undefined ) {
  7527. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  7528. m.opacity = m.transparency;
  7529. }
  7530. if ( m.opacity !== undefined ) {
  7531. mpars.opacity = m.opacity;
  7532. }
  7533. if ( m.specularCoef ) {
  7534. mpars.shininess = m.specularCoef;
  7535. }
  7536. // textures
  7537. if ( m.mapDiffuse && texturePath ) {
  7538. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  7539. }
  7540. if ( m.mapLight && texturePath ) {
  7541. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  7542. }
  7543. if ( m.mapAO && texturePath ) {
  7544. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  7545. }
  7546. if ( m.mapBump && texturePath ) {
  7547. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  7548. }
  7549. if ( m.mapNormal && texturePath ) {
  7550. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  7551. }
  7552. if ( m.mapSpecular && texturePath ) {
  7553. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  7554. }
  7555. if ( m.mapAlpha && texturePath ) {
  7556. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  7557. }
  7558. //
  7559. if ( m.mapBumpScale ) {
  7560. mpars.bumpScale = m.mapBumpScale;
  7561. }
  7562. if ( m.mapNormalFactor ) {
  7563. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  7564. }
  7565. var material = new THREE[ mtype ]( mpars );
  7566. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  7567. return material;
  7568. };
  7569. } )()
  7570. };
  7571. THREE.Loader.Handlers = {
  7572. handlers: [],
  7573. add: function ( regex, loader ) {
  7574. this.handlers.push( regex, loader );
  7575. },
  7576. get: function ( file ) {
  7577. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  7578. var regex = this.handlers[ i ];
  7579. var loader = this.handlers[ i + 1 ];
  7580. if ( regex.test( file ) ) {
  7581. return loader;
  7582. }
  7583. }
  7584. return null;
  7585. }
  7586. };
  7587. // File:src/loaders/XHRLoader.js
  7588. /**
  7589. * @author mrdoob / http://mrdoob.com/
  7590. */
  7591. THREE.XHRLoader = function ( manager ) {
  7592. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7593. };
  7594. THREE.XHRLoader.prototype = {
  7595. constructor: THREE.XHRLoader,
  7596. load: function ( url, onLoad, onProgress, onError ) {
  7597. var scope = this;
  7598. var cached = THREE.Cache.get( url );
  7599. if ( cached !== undefined ) {
  7600. if ( onLoad ) {
  7601. setTimeout( function () {
  7602. onLoad( cached );
  7603. }, 0 );
  7604. }
  7605. return cached;
  7606. }
  7607. var request = new XMLHttpRequest();
  7608. request.open( 'GET', url, true );
  7609. request.addEventListener( 'load', function ( event ) {
  7610. THREE.Cache.add( url, this.response );
  7611. if ( onLoad ) onLoad( this.response );
  7612. scope.manager.itemEnd( url );
  7613. }, false );
  7614. if ( onProgress !== undefined ) {
  7615. request.addEventListener( 'progress', function ( event ) {
  7616. onProgress( event );
  7617. }, false );
  7618. }
  7619. if ( onError !== undefined ) {
  7620. request.addEventListener( 'error', function ( event ) {
  7621. onError( event );
  7622. }, false );
  7623. }
  7624. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  7625. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  7626. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  7627. request.send( null );
  7628. scope.manager.itemStart( url );
  7629. return request;
  7630. },
  7631. setResponseType: function ( value ) {
  7632. this.responseType = value;
  7633. },
  7634. setCrossOrigin: function ( value ) {
  7635. this.crossOrigin = value;
  7636. },
  7637. setWithCredentials: function ( value ) {
  7638. this.withCredentials = value;
  7639. }
  7640. };
  7641. // File:src/loaders/ImageLoader.js
  7642. /**
  7643. * @author mrdoob / http://mrdoob.com/
  7644. */
  7645. THREE.ImageLoader = function ( manager ) {
  7646. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7647. };
  7648. THREE.ImageLoader.prototype = {
  7649. constructor: THREE.ImageLoader,
  7650. load: function ( url, onLoad, onProgress, onError ) {
  7651. var scope = this;
  7652. var cached = THREE.Cache.get( url );
  7653. if ( cached !== undefined ) {
  7654. if ( onLoad ) {
  7655. setTimeout( function () {
  7656. onLoad( cached );
  7657. }, 0 );
  7658. }
  7659. return cached;
  7660. }
  7661. var image = document.createElement( 'img' );
  7662. image.addEventListener( 'load', function ( event ) {
  7663. THREE.Cache.add( url, this );
  7664. if ( onLoad ) onLoad( this );
  7665. scope.manager.itemEnd( url );
  7666. }, false );
  7667. if ( onProgress !== undefined ) {
  7668. image.addEventListener( 'progress', function ( event ) {
  7669. onProgress( event );
  7670. }, false );
  7671. }
  7672. if ( onError !== undefined ) {
  7673. image.addEventListener( 'error', function ( event ) {
  7674. onError( event );
  7675. }, false );
  7676. }
  7677. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  7678. scope.manager.itemStart( url );
  7679. image.src = url;
  7680. return image;
  7681. },
  7682. setCrossOrigin: function ( value ) {
  7683. this.crossOrigin = value;
  7684. }
  7685. };
  7686. // File:src/loaders/JSONLoader.js
  7687. /**
  7688. * @author mrdoob / http://mrdoob.com/
  7689. * @author alteredq / http://alteredqualia.com/
  7690. */
  7691. THREE.JSONLoader = function ( manager ) {
  7692. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  7693. this.withCredentials = false;
  7694. };
  7695. THREE.JSONLoader.prototype = {
  7696. constructor: THREE.JSONLoader,
  7697. load: function( url, onLoad, onProgress, onError ) {
  7698. var scope = this;
  7699. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  7700. var loader = new THREE.XHRLoader( this.manager );
  7701. loader.setCrossOrigin( this.crossOrigin );
  7702. loader.setWithCredentials( this.withCredentials );
  7703. loader.load( url, function ( text ) {
  7704. var json = JSON.parse( text );
  7705. var metadata = json.metadata;
  7706. if ( metadata !== undefined ) {
  7707. if ( metadata.type === 'object' ) {
  7708. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  7709. return;
  7710. }
  7711. if ( metadata.type === 'scene' ) {
  7712. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  7713. return;
  7714. }
  7715. }
  7716. var object = scope.parse( json, texturePath );
  7717. onLoad( object.geometry, object.materials );
  7718. } );
  7719. },
  7720. setCrossOrigin: function ( value ) {
  7721. this.crossOrigin = value;
  7722. },
  7723. setTexturePath: function ( value ) {
  7724. this.texturePath = value;
  7725. },
  7726. parse: function ( json, texturePath ) {
  7727. var geometry = new THREE.Geometry(),
  7728. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  7729. parseModel( scale );
  7730. parseSkin();
  7731. parseMorphing( scale );
  7732. geometry.computeFaceNormals();
  7733. geometry.computeBoundingSphere();
  7734. function parseModel( scale ) {
  7735. function isBitSet( value, position ) {
  7736. return value & ( 1 << position );
  7737. }
  7738. var i, j, fi,
  7739. offset, zLength,
  7740. colorIndex, normalIndex, uvIndex,
  7741. type,
  7742. isQuad,
  7743. hasMaterial,
  7744. hasFaceVertexUv,
  7745. hasFaceNormal, hasFaceVertexNormal,
  7746. hasFaceColor, hasFaceVertexColor,
  7747. vertex, face, faceA, faceB, hex, normal,
  7748. uvLayer, uv, u, v,
  7749. faces = json.faces,
  7750. vertices = json.vertices,
  7751. normals = json.normals,
  7752. colors = json.colors,
  7753. nUvLayers = 0;
  7754. if ( json.uvs !== undefined ) {
  7755. // disregard empty arrays
  7756. for ( i = 0; i < json.uvs.length; i ++ ) {
  7757. if ( json.uvs[ i ].length ) nUvLayers ++;
  7758. }
  7759. for ( i = 0; i < nUvLayers; i ++ ) {
  7760. geometry.faceVertexUvs[ i ] = [];
  7761. }
  7762. }
  7763. offset = 0;
  7764. zLength = vertices.length;
  7765. while ( offset < zLength ) {
  7766. vertex = new THREE.Vector3();
  7767. vertex.x = vertices[ offset ++ ] * scale;
  7768. vertex.y = vertices[ offset ++ ] * scale;
  7769. vertex.z = vertices[ offset ++ ] * scale;
  7770. geometry.vertices.push( vertex );
  7771. }
  7772. offset = 0;
  7773. zLength = faces.length;
  7774. while ( offset < zLength ) {
  7775. type = faces[ offset ++ ];
  7776. isQuad = isBitSet( type, 0 );
  7777. hasMaterial = isBitSet( type, 1 );
  7778. hasFaceVertexUv = isBitSet( type, 3 );
  7779. hasFaceNormal = isBitSet( type, 4 );
  7780. hasFaceVertexNormal = isBitSet( type, 5 );
  7781. hasFaceColor = isBitSet( type, 6 );
  7782. hasFaceVertexColor = isBitSet( type, 7 );
  7783. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  7784. if ( isQuad ) {
  7785. faceA = new THREE.Face3();
  7786. faceA.a = faces[ offset ];
  7787. faceA.b = faces[ offset + 1 ];
  7788. faceA.c = faces[ offset + 3 ];
  7789. faceB = new THREE.Face3();
  7790. faceB.a = faces[ offset + 1 ];
  7791. faceB.b = faces[ offset + 2 ];
  7792. faceB.c = faces[ offset + 3 ];
  7793. offset += 4;
  7794. if ( hasMaterial ) {
  7795. offset ++;
  7796. }
  7797. // to get face <=> uv index correspondence
  7798. fi = geometry.faces.length;
  7799. if ( hasFaceVertexUv ) {
  7800. for ( i = 0; i < nUvLayers; i ++ ) {
  7801. uvLayer = json.uvs[ i ];
  7802. geometry.faceVertexUvs[ i ][ fi ] = [];
  7803. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  7804. for ( j = 0; j < 4; j ++ ) {
  7805. uvIndex = faces[ offset ++ ];
  7806. u = uvLayer[ uvIndex * 2 ];
  7807. v = uvLayer[ uvIndex * 2 + 1 ];
  7808. uv = new THREE.Vector2( u, v );
  7809. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7810. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  7811. }
  7812. }
  7813. }
  7814. if ( hasFaceNormal ) {
  7815. normalIndex = faces[ offset ++ ] * 3;
  7816. faceA.normal.set(
  7817. normals[ normalIndex ++ ],
  7818. normals[ normalIndex ++ ],
  7819. normals[ normalIndex ]
  7820. );
  7821. faceB.normal.copy( faceA.normal );
  7822. }
  7823. if ( hasFaceVertexNormal ) {
  7824. for ( i = 0; i < 4; i ++ ) {
  7825. normalIndex = faces[ offset ++ ] * 3;
  7826. normal = new THREE.Vector3(
  7827. normals[ normalIndex ++ ],
  7828. normals[ normalIndex ++ ],
  7829. normals[ normalIndex ]
  7830. );
  7831. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  7832. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  7833. }
  7834. }
  7835. if ( hasFaceColor ) {
  7836. colorIndex = faces[ offset ++ ];
  7837. hex = colors[ colorIndex ];
  7838. faceA.color.setHex( hex );
  7839. faceB.color.setHex( hex );
  7840. }
  7841. if ( hasFaceVertexColor ) {
  7842. for ( i = 0; i < 4; i ++ ) {
  7843. colorIndex = faces[ offset ++ ];
  7844. hex = colors[ colorIndex ];
  7845. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  7846. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  7847. }
  7848. }
  7849. geometry.faces.push( faceA );
  7850. geometry.faces.push( faceB );
  7851. } else {
  7852. face = new THREE.Face3();
  7853. face.a = faces[ offset ++ ];
  7854. face.b = faces[ offset ++ ];
  7855. face.c = faces[ offset ++ ];
  7856. if ( hasMaterial ) {
  7857. offset ++;
  7858. }
  7859. // to get face <=> uv index correspondence
  7860. fi = geometry.faces.length;
  7861. if ( hasFaceVertexUv ) {
  7862. for ( i = 0; i < nUvLayers; i ++ ) {
  7863. uvLayer = json.uvs[ i ];
  7864. geometry.faceVertexUvs[ i ][ fi ] = [];
  7865. for ( j = 0; j < 3; j ++ ) {
  7866. uvIndex = faces[ offset ++ ];
  7867. u = uvLayer[ uvIndex * 2 ];
  7868. v = uvLayer[ uvIndex * 2 + 1 ];
  7869. uv = new THREE.Vector2( u, v );
  7870. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  7871. }
  7872. }
  7873. }
  7874. if ( hasFaceNormal ) {
  7875. normalIndex = faces[ offset ++ ] * 3;
  7876. face.normal.set(
  7877. normals[ normalIndex ++ ],
  7878. normals[ normalIndex ++ ],
  7879. normals[ normalIndex ]
  7880. );
  7881. }
  7882. if ( hasFaceVertexNormal ) {
  7883. for ( i = 0; i < 3; i ++ ) {
  7884. normalIndex = faces[ offset ++ ] * 3;
  7885. normal = new THREE.Vector3(
  7886. normals[ normalIndex ++ ],
  7887. normals[ normalIndex ++ ],
  7888. normals[ normalIndex ]
  7889. );
  7890. face.vertexNormals.push( normal );
  7891. }
  7892. }
  7893. if ( hasFaceColor ) {
  7894. colorIndex = faces[ offset ++ ];
  7895. face.color.setHex( colors[ colorIndex ] );
  7896. }
  7897. if ( hasFaceVertexColor ) {
  7898. for ( i = 0; i < 3; i ++ ) {
  7899. colorIndex = faces[ offset ++ ];
  7900. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  7901. }
  7902. }
  7903. geometry.faces.push( face );
  7904. }
  7905. }
  7906. };
  7907. function parseSkin() {
  7908. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  7909. if ( json.skinWeights ) {
  7910. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  7911. var x = json.skinWeights[ i ];
  7912. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  7913. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  7914. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  7915. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  7916. }
  7917. }
  7918. if ( json.skinIndices ) {
  7919. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  7920. var a = json.skinIndices[ i ];
  7921. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  7922. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  7923. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  7924. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  7925. }
  7926. }
  7927. geometry.bones = json.bones;
  7928. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  7929. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  7930. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  7931. }
  7932. // could change this to json.animations[0] or remove completely
  7933. geometry.animation = json.animation;
  7934. geometry.animations = json.animations;
  7935. };
  7936. function parseMorphing( scale ) {
  7937. if ( json.morphTargets !== undefined ) {
  7938. var i, l, v, vl, dstVertices, srcVertices;
  7939. for ( i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  7940. geometry.morphTargets[ i ] = {};
  7941. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  7942. geometry.morphTargets[ i ].vertices = [];
  7943. dstVertices = geometry.morphTargets[ i ].vertices;
  7944. srcVertices = json.morphTargets [ i ].vertices;
  7945. for ( v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  7946. var vertex = new THREE.Vector3();
  7947. vertex.x = srcVertices[ v ] * scale;
  7948. vertex.y = srcVertices[ v + 1 ] * scale;
  7949. vertex.z = srcVertices[ v + 2 ] * scale;
  7950. dstVertices.push( vertex );
  7951. }
  7952. }
  7953. }
  7954. if ( json.morphColors !== undefined ) {
  7955. var i, l, c, cl, dstColors, srcColors, color;
  7956. for ( i = 0, l = json.morphColors.length; i < l; i ++ ) {
  7957. geometry.morphColors[ i ] = {};
  7958. geometry.morphColors[ i ].name = json.morphColors[ i ].name;
  7959. geometry.morphColors[ i ].colors = [];
  7960. dstColors = geometry.morphColors[ i ].colors;
  7961. srcColors = json.morphColors [ i ].colors;
  7962. for ( c = 0, cl = srcColors.length; c < cl; c += 3 ) {
  7963. color = new THREE.Color( 0xffaa00 );
  7964. color.setRGB( srcColors[ c ], srcColors[ c + 1 ], srcColors[ c + 2 ] );
  7965. dstColors.push( color );
  7966. }
  7967. }
  7968. }
  7969. };
  7970. if ( json.materials === undefined || json.materials.length === 0 ) {
  7971. return { geometry: geometry };
  7972. } else {
  7973. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  7974. if ( THREE.Loader.prototype.needsTangents( materials ) ) {
  7975. geometry.computeTangents();
  7976. }
  7977. return { geometry: geometry, materials: materials };
  7978. }
  7979. }
  7980. };
  7981. // File:src/loaders/LoadingManager.js
  7982. /**
  7983. * @author mrdoob / http://mrdoob.com/
  7984. */
  7985. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  7986. var scope = this;
  7987. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  7988. this.onLoad = onLoad;
  7989. this.onProgress = onProgress;
  7990. this.onError = onError;
  7991. this.itemStart = function ( url ) {
  7992. itemsTotal ++;
  7993. if ( isLoading === false ) {
  7994. if ( scope.onStart !== undefined ) {
  7995. scope.onStart( url, itemsLoaded, itemsTotal );
  7996. }
  7997. }
  7998. isLoading = true;
  7999. };
  8000. this.itemEnd = function ( url ) {
  8001. itemsLoaded ++;
  8002. if ( scope.onProgress !== undefined ) {
  8003. scope.onProgress( url, itemsLoaded, itemsTotal );
  8004. }
  8005. if ( itemsLoaded === itemsTotal ) {
  8006. isLoading = false;
  8007. if ( scope.onLoad !== undefined ) {
  8008. scope.onLoad();
  8009. }
  8010. }
  8011. };
  8012. };
  8013. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  8014. // File:src/loaders/BufferGeometryLoader.js
  8015. /**
  8016. * @author mrdoob / http://mrdoob.com/
  8017. */
  8018. THREE.BufferGeometryLoader = function ( manager ) {
  8019. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8020. };
  8021. THREE.BufferGeometryLoader.prototype = {
  8022. constructor: THREE.BufferGeometryLoader,
  8023. load: function ( url, onLoad, onProgress, onError ) {
  8024. var scope = this;
  8025. var loader = new THREE.XHRLoader( scope.manager );
  8026. loader.setCrossOrigin( this.crossOrigin );
  8027. loader.load( url, function ( text ) {
  8028. onLoad( scope.parse( JSON.parse( text ) ) );
  8029. }, onProgress, onError );
  8030. },
  8031. setCrossOrigin: function ( value ) {
  8032. this.crossOrigin = value;
  8033. },
  8034. parse: function ( json ) {
  8035. var geometry = new THREE.BufferGeometry();
  8036. var attributes = json.data.attributes;
  8037. for ( var key in attributes ) {
  8038. var attribute = attributes[ key ];
  8039. var typedArray = new self[ attribute.type ]( attribute.array );
  8040. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  8041. }
  8042. var drawcalls = json.data.drawcalls || json.data.offsets;
  8043. if ( drawcalls !== undefined ) {
  8044. for ( var i = 0, n = drawcalls.length; i !== n; ++ i ) {
  8045. var drawcall = drawcalls[ i ];
  8046. var indexStart = drawcall.start;
  8047. var indexCount = drawcall.count;
  8048. var indexOffset = drawcall.index;
  8049. geometry.addDrawcall( indexStart, indexCount, indexOffset );
  8050. }
  8051. }
  8052. var boundingSphere = json.data.boundingSphere;
  8053. if ( boundingSphere !== undefined ) {
  8054. var center = new THREE.Vector3();
  8055. if ( boundingSphere.center !== undefined ) {
  8056. center.fromArray( boundingSphere.center );
  8057. }
  8058. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  8059. }
  8060. return geometry;
  8061. }
  8062. };
  8063. // File:src/loaders/MaterialLoader.js
  8064. /**
  8065. * @author mrdoob / http://mrdoob.com/
  8066. */
  8067. THREE.MaterialLoader = function ( manager ) {
  8068. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8069. };
  8070. THREE.MaterialLoader.prototype = {
  8071. constructor: THREE.MaterialLoader,
  8072. load: function ( url, onLoad, onProgress, onError ) {
  8073. var scope = this;
  8074. var loader = new THREE.XHRLoader( scope.manager );
  8075. loader.setCrossOrigin( this.crossOrigin );
  8076. loader.load( url, function ( text ) {
  8077. onLoad( scope.parse( JSON.parse( text ) ) );
  8078. }, onProgress, onError );
  8079. },
  8080. setCrossOrigin: function ( value ) {
  8081. this.crossOrigin = value;
  8082. },
  8083. parse: function ( json ) {
  8084. var material = new THREE[ json.type ];
  8085. if ( json.color !== undefined ) material.color.setHex( json.color );
  8086. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  8087. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  8088. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  8089. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  8090. if ( json.attributes !== undefined ) material.attributes = json.attributes;
  8091. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  8092. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  8093. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  8094. if ( json.shading !== undefined ) material.shading = json.shading;
  8095. if ( json.blending !== undefined ) material.blending = json.blending;
  8096. if ( json.side !== undefined ) material.side = json.side;
  8097. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  8098. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  8099. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  8100. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  8101. // for PointCloudMaterial
  8102. if ( json.size !== undefined ) material.size = json.size;
  8103. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  8104. if ( json.materials !== undefined ) {
  8105. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  8106. material.materials.push( this.parse( json.materials[ i ] ) );
  8107. }
  8108. }
  8109. return material;
  8110. }
  8111. };
  8112. // File:src/loaders/ObjectLoader.js
  8113. /**
  8114. * @author mrdoob / http://mrdoob.com/
  8115. */
  8116. THREE.ObjectLoader = function ( manager ) {
  8117. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8118. this.texturePath = '';
  8119. };
  8120. THREE.ObjectLoader.prototype = {
  8121. constructor: THREE.ObjectLoader,
  8122. load: function ( url, onLoad, onProgress, onError ) {
  8123. if ( this.texturePath === '' ) {
  8124. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  8125. }
  8126. var scope = this;
  8127. var loader = new THREE.XHRLoader( scope.manager );
  8128. loader.setCrossOrigin( this.crossOrigin );
  8129. loader.load( url, function ( text ) {
  8130. scope.parse( JSON.parse( text ), onLoad );
  8131. }, onProgress, onError );
  8132. },
  8133. setTexturePath: function ( value ) {
  8134. this.texturePath = value;
  8135. },
  8136. setCrossOrigin: function ( value ) {
  8137. this.crossOrigin = value;
  8138. },
  8139. parse: function ( json, onLoad ) {
  8140. var geometries = this.parseGeometries( json.geometries );
  8141. var images = this.parseImages( json.images, function () {
  8142. if ( onLoad !== undefined ) onLoad( object );
  8143. } );
  8144. var textures = this.parseTextures( json.textures, images );
  8145. var materials = this.parseMaterials( json.materials, textures );
  8146. var object = this.parseObject( json.object, geometries, materials );
  8147. if ( json.images === undefined || json.images.length === 0 ) {
  8148. if ( onLoad !== undefined ) onLoad( object );
  8149. }
  8150. return object;
  8151. },
  8152. parseGeometries: function ( json ) {
  8153. var geometries = {};
  8154. if ( json !== undefined ) {
  8155. var geometryLoader = new THREE.JSONLoader();
  8156. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  8157. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8158. var geometry;
  8159. var data = json[ i ];
  8160. switch ( data.type ) {
  8161. case 'PlaneGeometry':
  8162. case 'PlaneBufferGeometry':
  8163. geometry = new THREE[ data.type ](
  8164. data.width,
  8165. data.height,
  8166. data.widthSegments,
  8167. data.heightSegments
  8168. );
  8169. break;
  8170. case 'BoxGeometry':
  8171. case 'CubeGeometry': // backwards compatible
  8172. geometry = new THREE.BoxGeometry(
  8173. data.width,
  8174. data.height,
  8175. data.depth,
  8176. data.widthSegments,
  8177. data.heightSegments,
  8178. data.depthSegments
  8179. );
  8180. break;
  8181. case 'CircleBufferGeometry':
  8182. geometry = new THREE.CircleBufferGeometry(
  8183. data.radius,
  8184. data.segments,
  8185. data.thetaStart,
  8186. data.thetaLength
  8187. );
  8188. break;
  8189. case 'CircleGeometry':
  8190. geometry = new THREE.CircleGeometry(
  8191. data.radius,
  8192. data.segments,
  8193. data.thetaStart,
  8194. data.thetaLength
  8195. );
  8196. break;
  8197. case 'CylinderGeometry':
  8198. geometry = new THREE.CylinderGeometry(
  8199. data.radiusTop,
  8200. data.radiusBottom,
  8201. data.height,
  8202. data.radialSegments,
  8203. data.heightSegments,
  8204. data.openEnded,
  8205. data.thetaStart,
  8206. data.thetaLength
  8207. );
  8208. break;
  8209. case 'SphereGeometry':
  8210. geometry = new THREE.SphereGeometry(
  8211. data.radius,
  8212. data.widthSegments,
  8213. data.heightSegments,
  8214. data.phiStart,
  8215. data.phiLength,
  8216. data.thetaStart,
  8217. data.thetaLength
  8218. );
  8219. break;
  8220. case 'SphereBufferGeometry':
  8221. geometry = new THREE.SphereBufferGeometry(
  8222. data.radius,
  8223. data.widthSegments,
  8224. data.heightSegments,
  8225. data.phiStart,
  8226. data.phiLength,
  8227. data.thetaStart,
  8228. data.thetaLength
  8229. );
  8230. break;
  8231. case 'DodecahedronGeometry':
  8232. geometry = new THREE.DodecahedronGeometry(
  8233. data.radius,
  8234. data.detail
  8235. );
  8236. break;
  8237. case 'IcosahedronGeometry':
  8238. geometry = new THREE.IcosahedronGeometry(
  8239. data.radius,
  8240. data.detail
  8241. );
  8242. break;
  8243. case 'OctahedronGeometry':
  8244. geometry = new THREE.OctahedronGeometry(
  8245. data.radius,
  8246. data.detail
  8247. );
  8248. break;
  8249. case 'TetrahedronGeometry':
  8250. geometry = new THREE.TetrahedronGeometry(
  8251. data.radius,
  8252. data.detail
  8253. );
  8254. break;
  8255. case 'RingGeometry':
  8256. geometry = new THREE.RingGeometry(
  8257. data.innerRadius,
  8258. data.outerRadius,
  8259. data.thetaSegments,
  8260. data.phiSegments,
  8261. data.thetaStart,
  8262. data.thetaLength
  8263. );
  8264. break;
  8265. case 'TorusGeometry':
  8266. geometry = new THREE.TorusGeometry(
  8267. data.radius,
  8268. data.tube,
  8269. data.radialSegments,
  8270. data.tubularSegments,
  8271. data.arc
  8272. );
  8273. break;
  8274. case 'TorusKnotGeometry':
  8275. geometry = new THREE.TorusKnotGeometry(
  8276. data.radius,
  8277. data.tube,
  8278. data.radialSegments,
  8279. data.tubularSegments,
  8280. data.p,
  8281. data.q,
  8282. data.heightScale
  8283. );
  8284. break;
  8285. case 'BufferGeometry':
  8286. geometry = bufferGeometryLoader.parse( data );
  8287. break;
  8288. case 'Geometry':
  8289. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  8290. break;
  8291. case 'TextGeometry':
  8292. geometry = new THREE.TextGeometry(
  8293. data.text,
  8294. data.data
  8295. );
  8296. break;
  8297. }
  8298. geometry.uuid = data.uuid;
  8299. if ( data.name !== undefined ) geometry.name = data.name;
  8300. geometries[ data.uuid ] = geometry;
  8301. }
  8302. }
  8303. return geometries;
  8304. },
  8305. parseMaterials: function ( json, textures ) {
  8306. var materials = {};
  8307. if ( json !== undefined ) {
  8308. var getTexture = function ( name ) {
  8309. if ( textures[ name ] === undefined ) {
  8310. console.warn( 'THREE.ObjectLoader: Undefined texture', name );
  8311. }
  8312. return textures[ name ];
  8313. };
  8314. var loader = new THREE.MaterialLoader();
  8315. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8316. var data = json[ i ];
  8317. var material = loader.parse( data );
  8318. material.uuid = data.uuid;
  8319. if ( data.depthTest !== undefined ) material.depthTest = data.depthTest;
  8320. if ( data.depthWrite !== undefined ) material.depthWrite = data.depthWrite;
  8321. if ( data.name !== undefined ) material.name = data.name;
  8322. if ( data.map !== undefined ) material.map = getTexture( data.map );
  8323. if ( data.alphaMap !== undefined ) {
  8324. material.alphaMap = getTexture( data.alphaMap );
  8325. material.transparent = true;
  8326. }
  8327. if ( data.bumpMap !== undefined ) material.bumpMap = getTexture( data.bumpMap );
  8328. if ( data.bumpScale !== undefined ) material.bumpScale = data.bumpScale;
  8329. if ( data.normalMap !== undefined ) material.normalMap = getTexture( data.normalMap );
  8330. if ( data.normalScale ) material.normalScale = new THREE.Vector2( data.normalScale, data.normalScale );
  8331. if ( data.specularMap !== undefined ) material.specularMap = getTexture( data.specularMap );
  8332. if ( data.envMap !== undefined ) {
  8333. material.envMap = getTexture( data.envMap );
  8334. material.combine = THREE.MultiplyOperation;
  8335. }
  8336. if ( data.reflectivity ) material.reflectivity = data.reflectivity;
  8337. if ( data.lightMap !== undefined ) material.lightMap = getTexture( data.lightMap );
  8338. if ( data.lightMapIntensity !== undefined ) material.lightMapIntensity = data.lightMapIntensity;
  8339. if ( data.aoMap !== undefined ) material.aoMap = getTexture( data.aoMap );
  8340. if ( data.aoMapIntensity !== undefined ) material.aoMapIntensity = data.aoMapIntensity;
  8341. materials[ data.uuid ] = material;
  8342. }
  8343. }
  8344. return materials;
  8345. },
  8346. parseImages: function ( json, onLoad ) {
  8347. var scope = this;
  8348. var images = {};
  8349. if ( json !== undefined && json.length > 0 ) {
  8350. var manager = new THREE.LoadingManager( onLoad );
  8351. var loader = new THREE.ImageLoader( manager );
  8352. loader.setCrossOrigin( this.crossOrigin );
  8353. var loadImage = function ( url ) {
  8354. url = scope.texturePath + url;
  8355. scope.manager.itemStart( url );
  8356. return loader.load( url, function () {
  8357. scope.manager.itemEnd( url );
  8358. } );
  8359. };
  8360. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8361. var image = json[ i ];
  8362. images[ image.uuid ] = loadImage( image.url );
  8363. }
  8364. }
  8365. return images;
  8366. },
  8367. parseTextures: function ( json, images ) {
  8368. function parseConstant( value ) {
  8369. if ( typeof( value ) === 'number' ) return value;
  8370. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  8371. return THREE[ value ];
  8372. }
  8373. var textures = {};
  8374. if ( json !== undefined ) {
  8375. for ( var i = 0, l = json.length; i < l; i ++ ) {
  8376. var data = json[ i ];
  8377. if ( data.image === undefined ) {
  8378. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  8379. }
  8380. if ( images[ data.image ] === undefined ) {
  8381. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  8382. }
  8383. var texture = new THREE.Texture( images[ data.image ] );
  8384. texture.needsUpdate = true;
  8385. texture.uuid = data.uuid;
  8386. if ( data.name !== undefined ) texture.name = data.name;
  8387. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  8388. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  8389. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  8390. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  8391. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  8392. if ( Array.isArray( data.wrap ) ) {
  8393. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  8394. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  8395. }
  8396. textures[ data.uuid ] = texture;
  8397. }
  8398. }
  8399. return textures;
  8400. },
  8401. parseObject: function () {
  8402. var matrix = new THREE.Matrix4();
  8403. return function ( data, geometries, materials ) {
  8404. var object;
  8405. var getGeometry = function ( name ) {
  8406. if ( geometries[ name ] === undefined ) {
  8407. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  8408. }
  8409. return geometries[ name ];
  8410. };
  8411. var getMaterial = function ( name ) {
  8412. if ( materials[ name ] === undefined ) {
  8413. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  8414. }
  8415. return materials[ name ];
  8416. };
  8417. switch ( data.type ) {
  8418. case 'Scene':
  8419. object = new THREE.Scene();
  8420. break;
  8421. case 'PerspectiveCamera':
  8422. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  8423. break;
  8424. case 'OrthographicCamera':
  8425. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  8426. break;
  8427. case 'AmbientLight':
  8428. object = new THREE.AmbientLight( data.color );
  8429. break;
  8430. case 'DirectionalLight':
  8431. object = new THREE.DirectionalLight( data.color, data.intensity );
  8432. break;
  8433. case 'PointLight':
  8434. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  8435. break;
  8436. case 'SpotLight':
  8437. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  8438. break;
  8439. case 'HemisphereLight':
  8440. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  8441. break;
  8442. case 'Mesh':
  8443. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  8444. break;
  8445. case 'Line':
  8446. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  8447. break;
  8448. case 'PointCloud':
  8449. object = new THREE.PointCloud( getGeometry( data.geometry ), getMaterial( data.material ) );
  8450. break;
  8451. case 'Sprite':
  8452. object = new THREE.Sprite( getMaterial( data.material ) );
  8453. break;
  8454. case 'Group':
  8455. object = new THREE.Group();
  8456. break;
  8457. default:
  8458. object = new THREE.Object3D();
  8459. }
  8460. object.uuid = data.uuid;
  8461. if ( data.name !== undefined ) object.name = data.name;
  8462. if ( data.matrix !== undefined ) {
  8463. matrix.fromArray( data.matrix );
  8464. matrix.decompose( object.position, object.quaternion, object.scale );
  8465. } else {
  8466. if ( data.position !== undefined ) object.position.fromArray( data.position );
  8467. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  8468. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  8469. }
  8470. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  8471. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  8472. if ( data.visible !== undefined ) object.visible = data.visible;
  8473. if ( data.userData !== undefined ) object.userData = data.userData;
  8474. if ( data.children !== undefined ) {
  8475. for ( var child in data.children ) {
  8476. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  8477. }
  8478. }
  8479. return object;
  8480. }
  8481. }()
  8482. };
  8483. // File:src/loaders/TextureLoader.js
  8484. /**
  8485. * @author mrdoob / http://mrdoob.com/
  8486. */
  8487. THREE.TextureLoader = function ( manager ) {
  8488. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8489. };
  8490. THREE.TextureLoader.prototype = {
  8491. constructor: THREE.TextureLoader,
  8492. load: function ( url, onLoad, onProgress, onError ) {
  8493. var scope = this;
  8494. var loader = new THREE.ImageLoader( scope.manager );
  8495. loader.setCrossOrigin( this.crossOrigin );
  8496. loader.load( url, function ( image ) {
  8497. var texture = new THREE.Texture( image );
  8498. texture.needsUpdate = true;
  8499. if ( onLoad !== undefined ) {
  8500. onLoad( texture );
  8501. }
  8502. }, onProgress, onError );
  8503. },
  8504. setCrossOrigin: function ( value ) {
  8505. this.crossOrigin = value;
  8506. }
  8507. };
  8508. // File:src/loaders/BinaryTextureLoader.js
  8509. /**
  8510. * @author Nikos M. / https://github.com/foo123/
  8511. *
  8512. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  8513. */
  8514. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  8515. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8516. // override in sub classes
  8517. this._parser = null;
  8518. };
  8519. THREE.BinaryTextureLoader.prototype = {
  8520. constructor: THREE.BinaryTextureLoader,
  8521. load: function ( url, onLoad, onProgress, onError ) {
  8522. var scope = this;
  8523. var texture = new THREE.DataTexture( );
  8524. var loader = new THREE.XHRLoader( this.manager );
  8525. loader.setCrossOrigin( this.crossOrigin );
  8526. loader.setResponseType( 'arraybuffer' );
  8527. loader.load( url, function ( buffer ) {
  8528. var texData = scope._parser( buffer );
  8529. if ( !texData ) return;
  8530. if ( undefined !== texData.image ) {
  8531. texture.image = texData.image;
  8532. } else if ( undefined !== texData.data ) {
  8533. texture.image.width = texData.width;
  8534. texture.image.height = texData.height;
  8535. texture.image.data = texData.data;
  8536. }
  8537. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  8538. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  8539. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  8540. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  8541. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  8542. if ( undefined !== texData.format ) {
  8543. texture.format = texData.format;
  8544. }
  8545. if ( undefined !== texData.type ) {
  8546. texture.type = texData.type;
  8547. }
  8548. if ( undefined !== texData.mipmaps ) {
  8549. texture.mipmaps = texData.mipmaps;
  8550. }
  8551. if ( 1 === texData.mipmapCount ) {
  8552. texture.minFilter = THREE.LinearFilter;
  8553. }
  8554. texture.needsUpdate = true;
  8555. if ( onLoad ) onLoad( texture, texData );
  8556. }, onProgress, onError );
  8557. return texture;
  8558. },
  8559. setCrossOrigin: function ( value ) {
  8560. this.crossOrigin = value;
  8561. }
  8562. };
  8563. // File:src/loaders/CompressedTextureLoader.js
  8564. /**
  8565. * @author mrdoob / http://mrdoob.com/
  8566. *
  8567. * Abstract Base class to block based textures loader (dds, pvr, ...)
  8568. */
  8569. THREE.CompressedTextureLoader = function ( manager ) {
  8570. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8571. // override in sub classes
  8572. this._parser = null;
  8573. };
  8574. THREE.CompressedTextureLoader.prototype = {
  8575. constructor: THREE.CompressedTextureLoader,
  8576. load: function ( url, onLoad, onProgress, onError ) {
  8577. var scope = this;
  8578. var images = [];
  8579. var texture = new THREE.CompressedTexture();
  8580. texture.image = images;
  8581. var loader = new THREE.XHRLoader( this.manager );
  8582. loader.setCrossOrigin( this.crossOrigin );
  8583. loader.setResponseType( 'arraybuffer' );
  8584. if ( Array.isArray( url ) ) {
  8585. var loaded = 0;
  8586. var loadTexture = function ( i ) {
  8587. loader.load( url[ i ], function ( buffer ) {
  8588. var texDatas = scope._parser( buffer, true );
  8589. images[ i ] = {
  8590. width: texDatas.width,
  8591. height: texDatas.height,
  8592. format: texDatas.format,
  8593. mipmaps: texDatas.mipmaps
  8594. };
  8595. loaded += 1;
  8596. if ( loaded === 6 ) {
  8597. if (texDatas.mipmapCount === 1)
  8598. texture.minFilter = THREE.LinearFilter;
  8599. texture.format = texDatas.format;
  8600. texture.needsUpdate = true;
  8601. if ( onLoad ) onLoad( texture );
  8602. }
  8603. }, onProgress, onError );
  8604. };
  8605. for ( var i = 0, il = url.length; i < il; ++ i ) {
  8606. loadTexture( i );
  8607. }
  8608. } else {
  8609. // compressed cubemap texture stored in a single DDS file
  8610. loader.load( url, function ( buffer ) {
  8611. var texDatas = scope._parser( buffer, true );
  8612. if ( texDatas.isCubemap ) {
  8613. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  8614. for ( var f = 0; f < faces; f ++ ) {
  8615. images[ f ] = { mipmaps : [] };
  8616. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  8617. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  8618. images[ f ].format = texDatas.format;
  8619. images[ f ].width = texDatas.width;
  8620. images[ f ].height = texDatas.height;
  8621. }
  8622. }
  8623. } else {
  8624. texture.image.width = texDatas.width;
  8625. texture.image.height = texDatas.height;
  8626. texture.mipmaps = texDatas.mipmaps;
  8627. }
  8628. if ( texDatas.mipmapCount === 1 ) {
  8629. texture.minFilter = THREE.LinearFilter;
  8630. }
  8631. texture.format = texDatas.format;
  8632. texture.needsUpdate = true;
  8633. if ( onLoad ) onLoad( texture );
  8634. }, onProgress, onError );
  8635. }
  8636. return texture;
  8637. },
  8638. setCrossOrigin: function ( value ) {
  8639. this.crossOrigin = value;
  8640. }
  8641. };
  8642. // File:src/materials/Material.js
  8643. /**
  8644. * @author mrdoob / http://mrdoob.com/
  8645. * @author alteredq / http://alteredqualia.com/
  8646. */
  8647. THREE.Material = function () {
  8648. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  8649. this.uuid = THREE.Math.generateUUID();
  8650. this.name = '';
  8651. this.type = 'Material';
  8652. this.side = THREE.FrontSide;
  8653. this.opacity = 1;
  8654. this.transparent = false;
  8655. this.blending = THREE.NormalBlending;
  8656. this.blendSrc = THREE.SrcAlphaFactor;
  8657. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  8658. this.blendEquation = THREE.AddEquation;
  8659. this.blendSrcAlpha = null;
  8660. this.blendDstAlpha = null;
  8661. this.blendEquationAlpha = null;
  8662. this.depthFunc = THREE.LessEqualDepth;
  8663. this.depthTest = true;
  8664. this.depthWrite = true;
  8665. this.colorWrite = true;
  8666. this.polygonOffset = false;
  8667. this.polygonOffsetFactor = 0;
  8668. this.polygonOffsetUnits = 0;
  8669. this.alphaTest = 0;
  8670. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  8671. this.visible = true;
  8672. this._needsUpdate = true;
  8673. };
  8674. THREE.Material.prototype = {
  8675. constructor: THREE.Material,
  8676. get needsUpdate () {
  8677. return this._needsUpdate;
  8678. },
  8679. set needsUpdate ( value ) {
  8680. if ( value === true ) this.update();
  8681. this._needsUpdate = value;
  8682. },
  8683. setValues: function ( values ) {
  8684. if ( values === undefined ) return;
  8685. for ( var key in values ) {
  8686. var newValue = values[ key ];
  8687. if ( newValue === undefined ) {
  8688. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  8689. continue;
  8690. }
  8691. if ( key in this ) {
  8692. var currentValue = this[ key ];
  8693. if ( currentValue instanceof THREE.Color ) {
  8694. currentValue.set( newValue );
  8695. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  8696. currentValue.copy( newValue );
  8697. } else if ( key === 'overdraw' ) {
  8698. // ensure overdraw is backwards-compatible with legacy boolean type
  8699. this[ key ] = Number( newValue );
  8700. } else {
  8701. this[ key ] = newValue;
  8702. }
  8703. }
  8704. }
  8705. },
  8706. toJSON: function ( meta ) {
  8707. var data = {
  8708. metadata: {
  8709. version: 4.4,
  8710. type: 'Material',
  8711. generator: 'Material.toJSON'
  8712. }
  8713. };
  8714. // standard Material serialization
  8715. data.uuid = this.uuid;
  8716. data.type = this.type;
  8717. if ( this.name !== '' ) data.name = this.name;
  8718. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  8719. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  8720. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  8721. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  8722. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  8723. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  8724. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  8725. if ( this.bumpMap instanceof THREE.Texture ) {
  8726. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  8727. data.bumpScale = this.bumpScale;
  8728. }
  8729. if ( this.normalMap instanceof THREE.Texture ) {
  8730. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  8731. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  8732. }
  8733. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  8734. if ( this.envMap instanceof THREE.Texture ) {
  8735. data.envMap = this.envMap.toJSON( meta ).uuid;
  8736. data.reflectivity = this.reflectivity; // Scale behind envMap
  8737. }
  8738. if ( this.size !== undefined ) data.size = this.size;
  8739. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  8740. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  8741. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  8742. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  8743. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  8744. if ( this.opacity < 1 ) data.opacity = this.opacity;
  8745. if ( this.transparent === true ) data.transparent = this.transparent;
  8746. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  8747. return data;
  8748. },
  8749. clone: function () {
  8750. var material = new THREE.Material();
  8751. return material.copy( this );
  8752. },
  8753. copy: function ( source ) {
  8754. this.name = source.name;
  8755. this.side = source.side;
  8756. this.opacity = source.opacity;
  8757. this.transparent = source.transparent;
  8758. this.blending = source.blending;
  8759. this.blendSrc = source.blendSrc;
  8760. this.blendDst = source.blendDst;
  8761. this.blendEquation = source.blendEquation;
  8762. this.blendSrcAlpha = source.blendSrcAlpha;
  8763. this.blendDstAlpha = source.blendDstAlpha;
  8764. this.blendEquationAlpha = source.blendEquationAlpha;
  8765. this.depthFunc = source.depthFunc;
  8766. this.depthTest = source.depthTest;
  8767. this.depthWrite = source.depthWrite;
  8768. this.polygonOffset = source.polygonOffset;
  8769. this.polygonOffsetFactor = source.polygonOffsetFactor;
  8770. this.polygonOffsetUnits = source.polygonOffsetUnits;
  8771. this.alphaTest = source.alphaTest;
  8772. this.overdraw = source.overdraw;
  8773. this.visible = source.visible;
  8774. return this;
  8775. },
  8776. update: function () {
  8777. this.dispatchEvent( { type: 'update' } );
  8778. },
  8779. dispose: function () {
  8780. this.dispatchEvent( { type: 'dispose' } );
  8781. }
  8782. };
  8783. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  8784. THREE.MaterialIdCount = 0;
  8785. // File:src/materials/LineBasicMaterial.js
  8786. /**
  8787. * @author mrdoob / http://mrdoob.com/
  8788. * @author alteredq / http://alteredqualia.com/
  8789. *
  8790. * parameters = {
  8791. * color: <hex>,
  8792. * opacity: <float>,
  8793. *
  8794. * blending: THREE.NormalBlending,
  8795. * depthTest: <bool>,
  8796. * depthWrite: <bool>,
  8797. *
  8798. * linewidth: <float>,
  8799. * linecap: "round",
  8800. * linejoin: "round",
  8801. *
  8802. * vertexColors: <bool>
  8803. *
  8804. * fog: <bool>
  8805. * }
  8806. */
  8807. THREE.LineBasicMaterial = function ( parameters ) {
  8808. THREE.Material.call( this );
  8809. this.type = 'LineBasicMaterial';
  8810. this.color = new THREE.Color( 0xffffff );
  8811. this.linewidth = 1;
  8812. this.linecap = 'round';
  8813. this.linejoin = 'round';
  8814. this.vertexColors = THREE.NoColors;
  8815. this.fog = true;
  8816. this.setValues( parameters );
  8817. };
  8818. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8819. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  8820. THREE.LineBasicMaterial.prototype.clone = function () {
  8821. var material = new THREE.LineBasicMaterial();
  8822. material.copy( this );
  8823. material.color.copy( this.color );
  8824. material.linewidth = this.linewidth;
  8825. material.linecap = this.linecap;
  8826. material.linejoin = this.linejoin;
  8827. material.vertexColors = this.vertexColors;
  8828. material.fog = this.fog;
  8829. return material;
  8830. };
  8831. // File:src/materials/LineDashedMaterial.js
  8832. /**
  8833. * @author alteredq / http://alteredqualia.com/
  8834. *
  8835. * parameters = {
  8836. * color: <hex>,
  8837. * opacity: <float>,
  8838. *
  8839. * blending: THREE.NormalBlending,
  8840. * depthTest: <bool>,
  8841. * depthWrite: <bool>,
  8842. *
  8843. * linewidth: <float>,
  8844. *
  8845. * scale: <float>,
  8846. * dashSize: <float>,
  8847. * gapSize: <float>,
  8848. *
  8849. * vertexColors: <bool>
  8850. *
  8851. * fog: <bool>
  8852. * }
  8853. */
  8854. THREE.LineDashedMaterial = function ( parameters ) {
  8855. THREE.Material.call( this );
  8856. this.type = 'LineDashedMaterial';
  8857. this.color = new THREE.Color( 0xffffff );
  8858. this.linewidth = 1;
  8859. this.scale = 1;
  8860. this.dashSize = 3;
  8861. this.gapSize = 1;
  8862. this.vertexColors = false;
  8863. this.fog = true;
  8864. this.setValues( parameters );
  8865. };
  8866. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  8867. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  8868. THREE.LineDashedMaterial.prototype.clone = function () {
  8869. var material = new THREE.LineDashedMaterial();
  8870. material.copy( this );
  8871. material.color.copy( this.color );
  8872. material.linewidth = this.linewidth;
  8873. material.scale = this.scale;
  8874. material.dashSize = this.dashSize;
  8875. material.gapSize = this.gapSize;
  8876. material.vertexColors = this.vertexColors;
  8877. material.fog = this.fog;
  8878. return material;
  8879. };
  8880. // File:src/materials/MeshBasicMaterial.js
  8881. /**
  8882. * @author mrdoob / http://mrdoob.com/
  8883. * @author alteredq / http://alteredqualia.com/
  8884. *
  8885. * parameters = {
  8886. * color: <hex>,
  8887. * opacity: <float>,
  8888. * map: new THREE.Texture( <Image> ),
  8889. *
  8890. * aoMap: new THREE.Texture( <Image> ),
  8891. * aoMapIntensity: <float>
  8892. *
  8893. * specularMap: new THREE.Texture( <Image> ),
  8894. *
  8895. * alphaMap: new THREE.Texture( <Image> ),
  8896. *
  8897. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8898. * combine: THREE.Multiply,
  8899. * reflectivity: <float>,
  8900. * refractionRatio: <float>,
  8901. *
  8902. * shading: THREE.SmoothShading,
  8903. * blending: THREE.NormalBlending,
  8904. * depthTest: <bool>,
  8905. * depthWrite: <bool>,
  8906. *
  8907. * wireframe: <boolean>,
  8908. * wireframeLinewidth: <float>,
  8909. *
  8910. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8911. *
  8912. * skinning: <bool>,
  8913. * morphTargets: <bool>,
  8914. *
  8915. * fog: <bool>
  8916. * }
  8917. */
  8918. THREE.MeshBasicMaterial = function ( parameters ) {
  8919. THREE.Material.call( this );
  8920. this.type = 'MeshBasicMaterial';
  8921. this.color = new THREE.Color( 0xffffff ); // emissive
  8922. this.map = null;
  8923. this.aoMap = null;
  8924. this.aoMapIntensity = 1.0;
  8925. this.specularMap = null;
  8926. this.alphaMap = null;
  8927. this.envMap = null;
  8928. this.combine = THREE.MultiplyOperation;
  8929. this.reflectivity = 1;
  8930. this.refractionRatio = 0.98;
  8931. this.fog = true;
  8932. this.shading = THREE.SmoothShading;
  8933. this.wireframe = false;
  8934. this.wireframeLinewidth = 1;
  8935. this.wireframeLinecap = 'round';
  8936. this.wireframeLinejoin = 'round';
  8937. this.vertexColors = THREE.NoColors;
  8938. this.skinning = false;
  8939. this.morphTargets = false;
  8940. this.setValues( parameters );
  8941. };
  8942. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  8943. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  8944. THREE.MeshBasicMaterial.prototype.clone = function () {
  8945. var material = new THREE.MeshBasicMaterial();
  8946. material.copy( this );
  8947. material.color.copy( this.color );
  8948. material.map = this.map;
  8949. material.aoMap = this.aoMap;
  8950. material.aoMapIntensity = this.aoMapIntensity;
  8951. material.specularMap = this.specularMap;
  8952. material.alphaMap = this.alphaMap;
  8953. material.envMap = this.envMap;
  8954. material.combine = this.combine;
  8955. material.reflectivity = this.reflectivity;
  8956. material.refractionRatio = this.refractionRatio;
  8957. material.fog = this.fog;
  8958. material.shading = this.shading;
  8959. material.wireframe = this.wireframe;
  8960. material.wireframeLinewidth = this.wireframeLinewidth;
  8961. material.wireframeLinecap = this.wireframeLinecap;
  8962. material.wireframeLinejoin = this.wireframeLinejoin;
  8963. material.vertexColors = this.vertexColors;
  8964. material.skinning = this.skinning;
  8965. material.morphTargets = this.morphTargets;
  8966. return material;
  8967. };
  8968. // File:src/materials/MeshLambertMaterial.js
  8969. /**
  8970. * @author mrdoob / http://mrdoob.com/
  8971. * @author alteredq / http://alteredqualia.com/
  8972. *
  8973. * parameters = {
  8974. * color: <hex>,
  8975. * emissive: <hex>,
  8976. * opacity: <float>,
  8977. *
  8978. * map: new THREE.Texture( <Image> ),
  8979. *
  8980. * specularMap: new THREE.Texture( <Image> ),
  8981. *
  8982. * alphaMap: new THREE.Texture( <Image> ),
  8983. *
  8984. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  8985. * combine: THREE.Multiply,
  8986. * reflectivity: <float>,
  8987. * refractionRatio: <float>,
  8988. *
  8989. * shading: THREE.SmoothShading,
  8990. * blending: THREE.NormalBlending,
  8991. * depthTest: <bool>,
  8992. * depthWrite: <bool>,
  8993. *
  8994. * wireframe: <boolean>,
  8995. * wireframeLinewidth: <float>,
  8996. *
  8997. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  8998. *
  8999. * skinning: <bool>,
  9000. * morphTargets: <bool>,
  9001. * morphNormals: <bool>,
  9002. *
  9003. * fog: <bool>
  9004. * }
  9005. */
  9006. THREE.MeshLambertMaterial = function ( parameters ) {
  9007. THREE.Material.call( this );
  9008. this.type = 'MeshLambertMaterial';
  9009. this.color = new THREE.Color( 0xffffff ); // diffuse
  9010. this.emissive = new THREE.Color( 0x000000 );
  9011. this.map = null;
  9012. this.specularMap = null;
  9013. this.alphaMap = null;
  9014. this.envMap = null;
  9015. this.combine = THREE.MultiplyOperation;
  9016. this.reflectivity = 1;
  9017. this.refractionRatio = 0.98;
  9018. this.fog = true;
  9019. this.shading = THREE.SmoothShading;
  9020. this.wireframe = false;
  9021. this.wireframeLinewidth = 1;
  9022. this.wireframeLinecap = 'round';
  9023. this.wireframeLinejoin = 'round';
  9024. this.vertexColors = THREE.NoColors;
  9025. this.skinning = false;
  9026. this.morphTargets = false;
  9027. this.morphNormals = false;
  9028. this.setValues( parameters );
  9029. };
  9030. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  9031. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  9032. THREE.MeshLambertMaterial.prototype.clone = function () {
  9033. var material = new THREE.MeshLambertMaterial();
  9034. material.copy( this );
  9035. material.color.copy( this.color );
  9036. material.emissive.copy( this.emissive );
  9037. material.map = this.map;
  9038. material.specularMap = this.specularMap;
  9039. material.alphaMap = this.alphaMap;
  9040. material.envMap = this.envMap;
  9041. material.combine = this.combine;
  9042. material.reflectivity = this.reflectivity;
  9043. material.refractionRatio = this.refractionRatio;
  9044. material.fog = this.fog;
  9045. material.shading = this.shading;
  9046. material.wireframe = this.wireframe;
  9047. material.wireframeLinewidth = this.wireframeLinewidth;
  9048. material.wireframeLinecap = this.wireframeLinecap;
  9049. material.wireframeLinejoin = this.wireframeLinejoin;
  9050. material.vertexColors = this.vertexColors;
  9051. material.skinning = this.skinning;
  9052. material.morphTargets = this.morphTargets;
  9053. material.morphNormals = this.morphNormals;
  9054. return material;
  9055. };
  9056. // File:src/materials/MeshPhongMaterial.js
  9057. /**
  9058. * @author mrdoob / http://mrdoob.com/
  9059. * @author alteredq / http://alteredqualia.com/
  9060. *
  9061. * parameters = {
  9062. * color: <hex>,
  9063. * emissive: <hex>,
  9064. * specular: <hex>,
  9065. * shininess: <float>,
  9066. * opacity: <float>,
  9067. *
  9068. * map: new THREE.Texture( <Image> ),
  9069. *
  9070. * lightMap: new THREE.Texture( <Image> ),
  9071. * lightMapIntensity: <float>
  9072. *
  9073. * aoMap: new THREE.Texture( <Image> ),
  9074. * aoMapIntensity: <float>
  9075. *
  9076. * emissiveMap: new THREE.Texture( <Image> ),
  9077. *
  9078. * bumpMap: new THREE.Texture( <Image> ),
  9079. * bumpScale: <float>,
  9080. *
  9081. * normalMap: new THREE.Texture( <Image> ),
  9082. * normalScale: <Vector2>,
  9083. *
  9084. * specularMap: new THREE.Texture( <Image> ),
  9085. *
  9086. * alphaMap: new THREE.Texture( <Image> ),
  9087. *
  9088. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  9089. * combine: THREE.Multiply,
  9090. * reflectivity: <float>,
  9091. * refractionRatio: <float>,
  9092. *
  9093. * shading: THREE.SmoothShading,
  9094. * blending: THREE.NormalBlending,
  9095. * depthTest: <bool>,
  9096. * depthWrite: <bool>,
  9097. *
  9098. * wireframe: <boolean>,
  9099. * wireframeLinewidth: <float>,
  9100. *
  9101. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9102. *
  9103. * skinning: <bool>,
  9104. * morphTargets: <bool>,
  9105. * morphNormals: <bool>,
  9106. *
  9107. * fog: <bool>
  9108. * }
  9109. */
  9110. THREE.MeshPhongMaterial = function ( parameters ) {
  9111. THREE.Material.call( this );
  9112. this.type = 'MeshPhongMaterial';
  9113. this.color = new THREE.Color( 0xffffff ); // diffuse
  9114. this.emissive = new THREE.Color( 0x000000 );
  9115. this.specular = new THREE.Color( 0x111111 );
  9116. this.shininess = 30;
  9117. this.metal = false;
  9118. this.map = null;
  9119. this.lightMap = null;
  9120. this.lightMapIntensity = 1.0;
  9121. this.aoMap = null;
  9122. this.aoMapIntensity = 1.0;
  9123. this.emissiveMap = null;
  9124. this.bumpMap = null;
  9125. this.bumpScale = 1;
  9126. this.normalMap = null;
  9127. this.normalScale = new THREE.Vector2( 1, 1 );
  9128. this.specularMap = null;
  9129. this.alphaMap = null;
  9130. this.envMap = null;
  9131. this.combine = THREE.MultiplyOperation;
  9132. this.reflectivity = 1;
  9133. this.refractionRatio = 0.98;
  9134. this.fog = true;
  9135. this.shading = THREE.SmoothShading;
  9136. this.wireframe = false;
  9137. this.wireframeLinewidth = 1;
  9138. this.wireframeLinecap = 'round';
  9139. this.wireframeLinejoin = 'round';
  9140. this.vertexColors = THREE.NoColors;
  9141. this.skinning = false;
  9142. this.morphTargets = false;
  9143. this.morphNormals = false;
  9144. this.setValues( parameters );
  9145. };
  9146. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  9147. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  9148. THREE.MeshPhongMaterial.prototype.clone = function () {
  9149. var material = new THREE.MeshPhongMaterial();
  9150. material.copy( this );
  9151. material.color.copy( this.color );
  9152. material.emissive.copy( this.emissive );
  9153. material.specular.copy( this.specular );
  9154. material.shininess = this.shininess;
  9155. material.metal = this.metal;
  9156. material.map = this.map;
  9157. material.lightMap = this.lightMap;
  9158. material.lightMapIntensity = this.lightMapIntensity;
  9159. material.aoMap = this.aoMap;
  9160. material.aoMapIntensity = this.aoMapIntensity;
  9161. material.emissiveMap = this.emissiveMap;
  9162. material.bumpMap = this.bumpMap;
  9163. material.bumpScale = this.bumpScale;
  9164. material.normalMap = this.normalMap;
  9165. material.normalScale.copy( this.normalScale );
  9166. material.specularMap = this.specularMap;
  9167. material.alphaMap = this.alphaMap;
  9168. material.envMap = this.envMap;
  9169. material.combine = this.combine;
  9170. material.reflectivity = this.reflectivity;
  9171. material.refractionRatio = this.refractionRatio;
  9172. material.fog = this.fog;
  9173. material.shading = this.shading;
  9174. material.wireframe = this.wireframe;
  9175. material.wireframeLinewidth = this.wireframeLinewidth;
  9176. material.wireframeLinecap = this.wireframeLinecap;
  9177. material.wireframeLinejoin = this.wireframeLinejoin;
  9178. material.vertexColors = this.vertexColors;
  9179. material.skinning = this.skinning;
  9180. material.morphTargets = this.morphTargets;
  9181. material.morphNormals = this.morphNormals;
  9182. return material;
  9183. };
  9184. // File:src/materials/MeshDepthMaterial.js
  9185. /**
  9186. * @author mrdoob / http://mrdoob.com/
  9187. * @author alteredq / http://alteredqualia.com/
  9188. *
  9189. * parameters = {
  9190. * opacity: <float>,
  9191. *
  9192. * blending: THREE.NormalBlending,
  9193. * depthTest: <bool>,
  9194. * depthWrite: <bool>,
  9195. *
  9196. * wireframe: <boolean>,
  9197. * wireframeLinewidth: <float>
  9198. * }
  9199. */
  9200. THREE.MeshDepthMaterial = function ( parameters ) {
  9201. THREE.Material.call( this );
  9202. this.type = 'MeshDepthMaterial';
  9203. this.morphTargets = false;
  9204. this.wireframe = false;
  9205. this.wireframeLinewidth = 1;
  9206. this.setValues( parameters );
  9207. };
  9208. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  9209. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  9210. THREE.MeshDepthMaterial.prototype.clone = function () {
  9211. var material = new THREE.MeshDepthMaterial();
  9212. material.copy( this );
  9213. material.wireframe = this.wireframe;
  9214. material.wireframeLinewidth = this.wireframeLinewidth;
  9215. return material;
  9216. };
  9217. // File:src/materials/MeshNormalMaterial.js
  9218. /**
  9219. * @author mrdoob / http://mrdoob.com/
  9220. *
  9221. * parameters = {
  9222. * opacity: <float>,
  9223. *
  9224. * shading: THREE.FlatShading,
  9225. * blending: THREE.NormalBlending,
  9226. * depthTest: <bool>,
  9227. * depthWrite: <bool>,
  9228. *
  9229. * wireframe: <boolean>,
  9230. * wireframeLinewidth: <float>
  9231. * }
  9232. */
  9233. THREE.MeshNormalMaterial = function ( parameters ) {
  9234. THREE.Material.call( this, parameters );
  9235. this.type = 'MeshNormalMaterial';
  9236. this.wireframe = false;
  9237. this.wireframeLinewidth = 1;
  9238. this.morphTargets = false;
  9239. this.setValues( parameters );
  9240. };
  9241. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  9242. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  9243. THREE.MeshNormalMaterial.prototype.clone = function () {
  9244. var material = new THREE.MeshNormalMaterial();
  9245. material.copy( this );
  9246. material.wireframe = this.wireframe;
  9247. material.wireframeLinewidth = this.wireframeLinewidth;
  9248. return material;
  9249. };
  9250. // File:src/materials/MeshFaceMaterial.js
  9251. /**
  9252. * @author mrdoob / http://mrdoob.com/
  9253. */
  9254. THREE.MeshFaceMaterial = function ( materials ) {
  9255. this.uuid = THREE.Math.generateUUID();
  9256. this.type = 'MeshFaceMaterial';
  9257. this.materials = materials instanceof Array ? materials : [];
  9258. };
  9259. THREE.MeshFaceMaterial.prototype = {
  9260. constructor: THREE.MeshFaceMaterial,
  9261. toJSON: function () {
  9262. var output = {
  9263. metadata: {
  9264. version: 4.2,
  9265. type: 'material',
  9266. generator: 'MaterialExporter'
  9267. },
  9268. uuid: this.uuid,
  9269. type: this.type,
  9270. materials: []
  9271. };
  9272. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  9273. output.materials.push( this.materials[ i ].toJSON() );
  9274. }
  9275. return output;
  9276. },
  9277. clone: function () {
  9278. var material = new THREE.MeshFaceMaterial();
  9279. for ( var i = 0; i < this.materials.length; i ++ ) {
  9280. material.materials.push( this.materials[ i ].clone() );
  9281. }
  9282. return material;
  9283. }
  9284. };
  9285. // File:src/materials/PointCloudMaterial.js
  9286. /**
  9287. * @author mrdoob / http://mrdoob.com/
  9288. * @author alteredq / http://alteredqualia.com/
  9289. *
  9290. * parameters = {
  9291. * color: <hex>,
  9292. * opacity: <float>,
  9293. * map: new THREE.Texture( <Image> ),
  9294. *
  9295. * size: <float>,
  9296. * sizeAttenuation: <bool>,
  9297. *
  9298. * blending: THREE.NormalBlending,
  9299. * depthTest: <bool>,
  9300. * depthWrite: <bool>,
  9301. *
  9302. * vertexColors: <bool>,
  9303. *
  9304. * fog: <bool>
  9305. * }
  9306. */
  9307. THREE.PointCloudMaterial = function ( parameters ) {
  9308. THREE.Material.call( this );
  9309. this.type = 'PointCloudMaterial';
  9310. this.color = new THREE.Color( 0xffffff );
  9311. this.map = null;
  9312. this.size = 1;
  9313. this.sizeAttenuation = true;
  9314. this.vertexColors = THREE.NoColors;
  9315. this.fog = true;
  9316. this.setValues( parameters );
  9317. };
  9318. THREE.PointCloudMaterial.prototype = Object.create( THREE.Material.prototype );
  9319. THREE.PointCloudMaterial.prototype.constructor = THREE.PointCloudMaterial;
  9320. THREE.PointCloudMaterial.prototype.clone = function () {
  9321. var material = new THREE.PointCloudMaterial();
  9322. material.copy( this );
  9323. material.color.copy( this.color );
  9324. material.map = this.map;
  9325. material.size = this.size;
  9326. material.sizeAttenuation = this.sizeAttenuation;
  9327. material.vertexColors = this.vertexColors;
  9328. material.fog = this.fog;
  9329. return material;
  9330. };
  9331. // backwards compatibility
  9332. THREE.ParticleBasicMaterial = function ( parameters ) {
  9333. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointCloudMaterial.' );
  9334. return new THREE.PointCloudMaterial( parameters );
  9335. };
  9336. THREE.ParticleSystemMaterial = function ( parameters ) {
  9337. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointCloudMaterial.' );
  9338. return new THREE.PointCloudMaterial( parameters );
  9339. };
  9340. // File:src/materials/ShaderMaterial.js
  9341. /**
  9342. * @author alteredq / http://alteredqualia.com/
  9343. *
  9344. * parameters = {
  9345. * defines: { "label" : "value" },
  9346. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  9347. *
  9348. * fragmentShader: <string>,
  9349. * vertexShader: <string>,
  9350. *
  9351. * shading: THREE.SmoothShading,
  9352. * blending: THREE.NormalBlending,
  9353. * depthTest: <bool>,
  9354. * depthWrite: <bool>,
  9355. *
  9356. * wireframe: <boolean>,
  9357. * wireframeLinewidth: <float>,
  9358. *
  9359. * lights: <bool>,
  9360. *
  9361. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  9362. *
  9363. * skinning: <bool>,
  9364. * morphTargets: <bool>,
  9365. * morphNormals: <bool>,
  9366. *
  9367. * fog: <bool>
  9368. * }
  9369. */
  9370. THREE.ShaderMaterial = function ( parameters ) {
  9371. THREE.Material.call( this );
  9372. this.type = 'ShaderMaterial';
  9373. this.defines = {};
  9374. this.uniforms = {};
  9375. this.attributes = [];
  9376. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  9377. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  9378. this.shading = THREE.SmoothShading;
  9379. this.linewidth = 1;
  9380. this.wireframe = false;
  9381. this.wireframeLinewidth = 1;
  9382. this.fog = false; // set to use scene fog
  9383. this.lights = false; // set to use scene lights
  9384. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  9385. this.skinning = false; // set to use skinning attribute streams
  9386. this.morphTargets = false; // set to use morph targets
  9387. this.morphNormals = false; // set to use morph normals
  9388. this.derivatives = false; // set to use derivatives
  9389. // When rendered geometry doesn't include these attributes but the material does,
  9390. // use these default values in WebGL. This avoids errors when buffer data is missing.
  9391. this.defaultAttributeValues = {
  9392. 'color': [ 1, 1, 1 ],
  9393. 'uv': [ 0, 0 ],
  9394. 'uv2': [ 0, 0 ]
  9395. };
  9396. this.index0AttributeName = undefined;
  9397. if ( parameters !== undefined ) {
  9398. if ( parameters.attributes !== undefined && Array.isArray( parameters.attributes ) === false ) {
  9399. console.warn( 'THREE.ShaderMaterial: attributes should now be an array of attribute names.' );
  9400. parameters.attributes = Object.keys( parameters.attributes );
  9401. }
  9402. this.setValues( parameters );
  9403. }
  9404. };
  9405. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  9406. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  9407. THREE.ShaderMaterial.prototype.clone = function () {
  9408. var material = new THREE.ShaderMaterial();
  9409. return material.copy( this );
  9410. };
  9411. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  9412. THREE.Material.prototype.copy.call( this, source );
  9413. this.fragmentShader = source.fragmentShader;
  9414. this.vertexShader = source.vertexShader;
  9415. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  9416. this.attributes = source.attributes;
  9417. this.defines = source.defines;
  9418. this.shading = source.shading;
  9419. this.wireframe = source.wireframe;
  9420. this.wireframeLinewidth = source.wireframeLinewidth;
  9421. this.fog = source.fog;
  9422. this.lights = source.lights;
  9423. this.vertexColors = source.vertexColors;
  9424. this.skinning = source.skinning;
  9425. this.morphTargets = source.morphTargets;
  9426. this.morphNormals = source.morphNormals;
  9427. return this;
  9428. };
  9429. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  9430. var data = THREE.Material.prototype.toJSON.call( this, meta );
  9431. data.uniforms = this.uniforms;
  9432. data.attributes = this.attributes;
  9433. data.vertexShader = this.vertexShader;
  9434. data.fragmentShader = this.fragmentShader;
  9435. return data;
  9436. };
  9437. // File:src/materials/RawShaderMaterial.js
  9438. /**
  9439. * @author mrdoob / http://mrdoob.com/
  9440. */
  9441. THREE.RawShaderMaterial = function ( parameters ) {
  9442. THREE.ShaderMaterial.call( this, parameters );
  9443. this.type = 'RawShaderMaterial';
  9444. };
  9445. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  9446. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  9447. THREE.RawShaderMaterial.prototype.clone = function () {
  9448. var material = new THREE.RawShaderMaterial();
  9449. material.copy( this );
  9450. return material;
  9451. };
  9452. // File:src/materials/SpriteMaterial.js
  9453. /**
  9454. * @author alteredq / http://alteredqualia.com/
  9455. *
  9456. * parameters = {
  9457. * color: <hex>,
  9458. * opacity: <float>,
  9459. * map: new THREE.Texture( <Image> ),
  9460. *
  9461. * blending: THREE.NormalBlending,
  9462. * depthTest: <bool>,
  9463. * depthWrite: <bool>,
  9464. *
  9465. * uvOffset: new THREE.Vector2(),
  9466. * uvScale: new THREE.Vector2(),
  9467. *
  9468. * fog: <bool>
  9469. * }
  9470. */
  9471. THREE.SpriteMaterial = function ( parameters ) {
  9472. THREE.Material.call( this );
  9473. this.type = 'SpriteMaterial';
  9474. this.color = new THREE.Color( 0xffffff );
  9475. this.map = null;
  9476. this.rotation = 0;
  9477. this.fog = false;
  9478. // set parameters
  9479. this.setValues( parameters );
  9480. };
  9481. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  9482. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  9483. THREE.SpriteMaterial.prototype.clone = function () {
  9484. var material = new THREE.SpriteMaterial();
  9485. material.copy( this );
  9486. material.color.copy( this.color );
  9487. material.map = this.map;
  9488. material.rotation = this.rotation;
  9489. material.fog = this.fog;
  9490. return material;
  9491. };
  9492. // File:src/textures/Texture.js
  9493. /**
  9494. * @author mrdoob / http://mrdoob.com/
  9495. * @author alteredq / http://alteredqualia.com/
  9496. * @author szimek / https://github.com/szimek/
  9497. */
  9498. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9499. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  9500. this.uuid = THREE.Math.generateUUID();
  9501. this.name = '';
  9502. this.sourceFile = '';
  9503. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  9504. this.mipmaps = [];
  9505. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  9506. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  9507. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  9508. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  9509. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  9510. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  9511. this.format = format !== undefined ? format : THREE.RGBAFormat;
  9512. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  9513. this.offset = new THREE.Vector2( 0, 0 );
  9514. this.repeat = new THREE.Vector2( 1, 1 );
  9515. this.generateMipmaps = true;
  9516. this.premultiplyAlpha = false;
  9517. this.flipY = true;
  9518. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  9519. this.version = 0;
  9520. this.onUpdate = null;
  9521. };
  9522. THREE.Texture.DEFAULT_IMAGE = undefined;
  9523. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  9524. THREE.Texture.prototype = {
  9525. constructor: THREE.Texture,
  9526. set needsUpdate ( value ) {
  9527. if ( value === true ) this.version ++;
  9528. },
  9529. clone: function () {
  9530. var texture = new THREE.Texture();
  9531. return texture.copy( this );
  9532. },
  9533. copy: function ( source ) {
  9534. this.image = source.image;
  9535. this.mipmaps = source.mipmaps.slice( 0 );
  9536. this.mapping = source.mapping;
  9537. this.wrapS = source.wrapS;
  9538. this.wrapT = source.wrapT;
  9539. this.magFilter = source.magFilter;
  9540. this.minFilter = source.minFilter;
  9541. this.anisotropy = source.anisotropy;
  9542. this.format = source.format;
  9543. this.type = source.type;
  9544. this.offset.copy( source.offset );
  9545. this.repeat.copy( source.repeat );
  9546. this.generateMipmaps = source.generateMipmaps;
  9547. this.premultiplyAlpha = source.premultiplyAlpha;
  9548. this.flipY = source.flipY;
  9549. this.unpackAlignment = source.unpackAlignment;
  9550. return this;
  9551. },
  9552. toJSON: function ( meta ) {
  9553. if ( meta.textures[ this.uuid ] !== undefined ) {
  9554. return meta.textures[ this.uuid ];
  9555. }
  9556. function getDataURL( image ) {
  9557. var canvas;
  9558. if ( image.toDataURL !== undefined ) {
  9559. canvas = image;
  9560. } else {
  9561. canvas = document.createElement( 'canvas' );
  9562. canvas.width = image.width;
  9563. canvas.height = image.height;
  9564. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  9565. }
  9566. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  9567. return canvas.toDataURL( 'image/jpeg', 0.6 );
  9568. } else {
  9569. return canvas.toDataURL( 'image/png' );
  9570. }
  9571. }
  9572. var output = {
  9573. metadata: {
  9574. version: 4.4,
  9575. type: 'Texture',
  9576. generator: 'Texture.toJSON'
  9577. },
  9578. uuid: this.uuid,
  9579. name: this.name,
  9580. mapping: this.mapping,
  9581. repeat: [ this.repeat.x, this.repeat.y ],
  9582. offset: [ this.offset.x, this.offset.y ],
  9583. wrap: [ this.wrapS, this.wrapT ],
  9584. minFilter: this.minFilter,
  9585. magFilter: this.magFilter,
  9586. anisotropy: this.anisotropy
  9587. };
  9588. if ( this.image !== undefined ) {
  9589. // TODO: Move to THREE.Image
  9590. var image = this.image;
  9591. if ( image.uuid === undefined ) {
  9592. image.uuid = THREE.Math.generateUUID(); // UGH
  9593. }
  9594. if ( meta.images[ image.uuid ] === undefined ) {
  9595. meta.images[ image.uuid ] = {
  9596. uuid: image.uuid,
  9597. url: getDataURL( image )
  9598. };
  9599. }
  9600. output.image = image.uuid;
  9601. }
  9602. meta.textures[ this.uuid ] = output;
  9603. return output;
  9604. },
  9605. dispose: function () {
  9606. this.dispatchEvent( { type: 'dispose' } );
  9607. }
  9608. };
  9609. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  9610. THREE.TextureIdCount = 0;
  9611. // File:src/textures/CubeTexture.js
  9612. /**
  9613. * @author mrdoob / http://mrdoob.com/
  9614. */
  9615. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9616. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  9617. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9618. this.images = images;
  9619. this.flipY = false;
  9620. };
  9621. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  9622. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  9623. THREE.CubeTexture.clone = function () {
  9624. var texture = new THREE.CubeTexture();
  9625. texture.copy( this );
  9626. texture.images = this.images;
  9627. return texture;
  9628. };
  9629. // File:src/textures/CompressedTexture.js
  9630. /**
  9631. * @author alteredq / http://alteredqualia.com/
  9632. */
  9633. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9634. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9635. this.image = { width: width, height: height };
  9636. this.mipmaps = mipmaps;
  9637. // no flipping for cube textures
  9638. // (also flipping doesn't work for compressed textures )
  9639. this.flipY = false;
  9640. // can't generate mipmaps for compressed textures
  9641. // mips must be embedded in DDS files
  9642. this.generateMipmaps = false;
  9643. };
  9644. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  9645. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  9646. THREE.CompressedTexture.prototype.clone = function () {
  9647. var texture = new THREE.CompressedTexture();
  9648. texture.copy( this );
  9649. return texture;
  9650. };
  9651. // File:src/textures/DataTexture.js
  9652. /**
  9653. * @author alteredq / http://alteredqualia.com/
  9654. */
  9655. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  9656. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9657. this.image = { data: data, width: width, height: height };
  9658. };
  9659. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  9660. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  9661. THREE.DataTexture.prototype.clone = function () {
  9662. var texture = new THREE.DataTexture();
  9663. texture.copy( this );
  9664. return texture;
  9665. };
  9666. // File:src/textures/VideoTexture.js
  9667. /**
  9668. * @author mrdoob / http://mrdoob.com/
  9669. */
  9670. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  9671. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  9672. this.generateMipmaps = false;
  9673. var scope = this;
  9674. var update = function () {
  9675. requestAnimationFrame( update );
  9676. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  9677. scope.needsUpdate = true;
  9678. }
  9679. };
  9680. update();
  9681. };
  9682. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  9683. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  9684. // File:src/objects/Group.js
  9685. /**
  9686. * @author mrdoob / http://mrdoob.com/
  9687. */
  9688. THREE.Group = function () {
  9689. THREE.Object3D.call( this );
  9690. this.type = 'Group';
  9691. };
  9692. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  9693. THREE.Group.prototype.constructor = THREE.Group;
  9694. THREE.Group.prototype.clone = function () {
  9695. var group = new THREE.Group();
  9696. return group.copy( this );
  9697. };
  9698. THREE.Group.prototype.copy = function ( source ) {
  9699. THREE.Object3D.prototype.copy.call( this, source );
  9700. return this;
  9701. };
  9702. // File:src/objects/PointCloud.js
  9703. /**
  9704. * @author alteredq / http://alteredqualia.com/
  9705. */
  9706. THREE.PointCloud = function ( geometry, material ) {
  9707. THREE.Object3D.call( this );
  9708. this.type = 'PointCloud';
  9709. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9710. this.material = material !== undefined ? material : new THREE.PointCloudMaterial( { color: Math.random() * 0xffffff } );
  9711. };
  9712. THREE.PointCloud.prototype = Object.create( THREE.Object3D.prototype );
  9713. THREE.PointCloud.prototype.constructor = THREE.PointCloud;
  9714. THREE.PointCloud.prototype.raycast = ( function () {
  9715. var inverseMatrix = new THREE.Matrix4();
  9716. var ray = new THREE.Ray();
  9717. return function raycast( raycaster, intersects ) {
  9718. var object = this;
  9719. var geometry = object.geometry;
  9720. var threshold = raycaster.params.PointCloud.threshold;
  9721. inverseMatrix.getInverse( this.matrixWorld );
  9722. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9723. if ( geometry.boundingBox !== null ) {
  9724. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  9725. return;
  9726. }
  9727. }
  9728. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  9729. var localThresholdSq = localThreshold * localThreshold;
  9730. var position = new THREE.Vector3();
  9731. var testPoint = function ( point, index ) {
  9732. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  9733. if ( rayPointDistanceSq < localThresholdSq ) {
  9734. var intersectPoint = ray.closestPointToPoint( point );
  9735. intersectPoint.applyMatrix4( object.matrixWorld );
  9736. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  9737. if ( distance < raycaster.near || distance > raycaster.far ) return;
  9738. intersects.push( {
  9739. distance: distance,
  9740. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  9741. point: intersectPoint.clone(),
  9742. index: index,
  9743. face: null,
  9744. object: object
  9745. } );
  9746. }
  9747. };
  9748. if ( geometry instanceof THREE.BufferGeometry ) {
  9749. var attributes = geometry.attributes;
  9750. var positions = attributes.position.array;
  9751. if ( attributes.index !== undefined ) {
  9752. var indices = attributes.index.array;
  9753. var offsets = geometry.drawcalls;
  9754. if ( offsets.length === 0 ) {
  9755. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9756. }
  9757. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  9758. var offset = offsets[ oi ];
  9759. var start = offset.start;
  9760. var count = offset.count;
  9761. var index = offset.index;
  9762. for ( var i = start, il = start + count; i < il; i ++ ) {
  9763. var a = index + indices[ i ];
  9764. position.fromArray( positions, a * 3 );
  9765. testPoint( position, a );
  9766. }
  9767. }
  9768. } else {
  9769. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  9770. position.fromArray( positions, i * 3 );
  9771. testPoint( position, i );
  9772. }
  9773. }
  9774. } else {
  9775. var vertices = geometry.vertices;
  9776. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  9777. testPoint( vertices[ i ], i );
  9778. }
  9779. }
  9780. };
  9781. }() );
  9782. THREE.PointCloud.prototype.clone = function () {
  9783. var pointCloud = new THREE.PointCloud( this.geometry, this.material );
  9784. return pointCloud.copy( this );
  9785. };
  9786. THREE.PointCloud.prototype.copy = function ( source ) {
  9787. THREE.Object3D.prototype.copy.call( this, source );
  9788. return this;
  9789. };
  9790. THREE.PointCloud.prototype.toJSON = function ( meta ) {
  9791. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9792. // only serialize if not in meta geometries cache
  9793. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9794. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9795. }
  9796. // only serialize if not in meta materials cache
  9797. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9798. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9799. }
  9800. data.object.geometry = this.geometry.uuid;
  9801. data.object.material = this.material.uuid;
  9802. return data;
  9803. };
  9804. // Backwards compatibility
  9805. THREE.ParticleSystem = function ( geometry, material ) {
  9806. console.warn( 'THREE.ParticleSystem has been renamed to THREE.PointCloud.' );
  9807. return new THREE.PointCloud( geometry, material );
  9808. };
  9809. // File:src/objects/Line.js
  9810. /**
  9811. * @author mrdoob / http://mrdoob.com/
  9812. */
  9813. THREE.Line = function ( geometry, material, mode ) {
  9814. if ( mode === 1 ) {
  9815. console.error( 'THREE.Line: THREE.LinePieces mode has been removed. Use THREE.LineSegments instead.' );
  9816. }
  9817. THREE.Object3D.call( this );
  9818. this.type = 'Line';
  9819. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9820. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  9821. };
  9822. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  9823. THREE.Line.prototype.constructor = THREE.Line;
  9824. THREE.Line.prototype.raycast = ( function () {
  9825. var inverseMatrix = new THREE.Matrix4();
  9826. var ray = new THREE.Ray();
  9827. var sphere = new THREE.Sphere();
  9828. return function raycast( raycaster, intersects ) {
  9829. var precision = raycaster.linePrecision;
  9830. var precisionSq = precision * precision;
  9831. var geometry = this.geometry;
  9832. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  9833. // Checking boundingSphere distance to ray
  9834. sphere.copy( geometry.boundingSphere );
  9835. sphere.applyMatrix4( this.matrixWorld );
  9836. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  9837. return;
  9838. }
  9839. inverseMatrix.getInverse( this.matrixWorld );
  9840. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  9841. var vStart = new THREE.Vector3();
  9842. var vEnd = new THREE.Vector3();
  9843. var interSegment = new THREE.Vector3();
  9844. var interRay = new THREE.Vector3();
  9845. var step = this instanceof THREE.LineSegments ? 2 : 1;
  9846. if ( geometry instanceof THREE.BufferGeometry ) {
  9847. var attributes = geometry.attributes;
  9848. if ( attributes.index !== undefined ) {
  9849. var indices = attributes.index.array;
  9850. var positions = attributes.position.array;
  9851. var offsets = geometry.drawcalls;
  9852. if ( offsets.length === 0 ) {
  9853. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  9854. }
  9855. for ( var oi = 0; oi < offsets.length; oi ++) {
  9856. var start = offsets[ oi ].start;
  9857. var count = offsets[ oi ].count;
  9858. var index = offsets[ oi ].index;
  9859. for ( var i = start; i < start + count - 1; i += step ) {
  9860. var a = index + indices[ i ];
  9861. var b = index + indices[ i + 1 ];
  9862. vStart.fromArray( positions, a * 3 );
  9863. vEnd.fromArray( positions, b * 3 );
  9864. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9865. if ( distSq > precisionSq ) continue;
  9866. var distance = ray.origin.distanceTo( interRay );
  9867. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9868. intersects.push( {
  9869. distance: distance,
  9870. // What do we want? intersection point on the ray or on the segment??
  9871. // point: raycaster.ray.at( distance ),
  9872. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9873. index: i,
  9874. offsetIndex: oi,
  9875. face: null,
  9876. faceIndex: null,
  9877. object: this
  9878. } );
  9879. }
  9880. }
  9881. } else {
  9882. var positions = attributes.position.array;
  9883. for ( var i = 0; i < positions.length / 3 - 1; i += step ) {
  9884. vStart.fromArray( positions, 3 * i );
  9885. vEnd.fromArray( positions, 3 * i + 3 );
  9886. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  9887. if ( distSq > precisionSq ) continue;
  9888. var distance = ray.origin.distanceTo( interRay );
  9889. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9890. intersects.push( {
  9891. distance: distance,
  9892. // What do we want? intersection point on the ray or on the segment??
  9893. // point: raycaster.ray.at( distance ),
  9894. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9895. index: i,
  9896. face: null,
  9897. faceIndex: null,
  9898. object: this
  9899. } );
  9900. }
  9901. }
  9902. } else if ( geometry instanceof THREE.Geometry ) {
  9903. var vertices = geometry.vertices;
  9904. var nbVertices = vertices.length;
  9905. for ( var i = 0; i < nbVertices - 1; i += step ) {
  9906. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  9907. if ( distSq > precisionSq ) continue;
  9908. var distance = ray.origin.distanceTo( interRay );
  9909. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  9910. intersects.push( {
  9911. distance: distance,
  9912. // What do we want? intersection point on the ray or on the segment??
  9913. // point: raycaster.ray.at( distance ),
  9914. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  9915. index: i,
  9916. face: null,
  9917. faceIndex: null,
  9918. object: this
  9919. } );
  9920. }
  9921. }
  9922. };
  9923. }() );
  9924. THREE.Line.prototype.clone = function () {
  9925. var line = new THREE.Line( this.geometry, this.material );
  9926. return line.copy( this );
  9927. };
  9928. THREE.Line.prototype.copy = function ( source ) {
  9929. THREE.Object3D.prototype.copy.call( this, source );
  9930. return this;
  9931. };
  9932. THREE.Line.prototype.toJSON = function ( meta ) {
  9933. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9934. // only serialize if not in meta geometries cache
  9935. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  9936. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON();
  9937. }
  9938. // only serialize if not in meta materials cache
  9939. if ( meta.materials[ this.material.uuid ] === undefined ) {
  9940. meta.materials[ this.material.uuid ] = this.material.toJSON();
  9941. }
  9942. data.object.geometry = this.geometry.uuid;
  9943. data.object.material = this.material.uuid;
  9944. return data;
  9945. };
  9946. // DEPRECATED
  9947. THREE.LineStrip = 0;
  9948. THREE.LinePieces = 1;
  9949. // File:src/objects/LineSegments.js
  9950. /**
  9951. * @author mrdoob / http://mrdoob.com/
  9952. */
  9953. THREE.LineSegments = function ( geometry, material ) {
  9954. THREE.Line.call( this, geometry, material );
  9955. this.type = 'LineSegments';
  9956. };
  9957. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  9958. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  9959. THREE.LineSegments.prototype.clone = function () {
  9960. var line = new THREE.LineSegments( this.geometry, this.material );
  9961. line.copy( this );
  9962. return line;
  9963. };
  9964. // File:src/objects/Mesh.js
  9965. /**
  9966. * @author mrdoob / http://mrdoob.com/
  9967. * @author alteredq / http://alteredqualia.com/
  9968. * @author mikael emtinger / http://gomo.se/
  9969. * @author jonobr1 / http://jonobr1.com/
  9970. */
  9971. THREE.Mesh = function ( geometry, material ) {
  9972. THREE.Object3D.call( this );
  9973. this.type = 'Mesh';
  9974. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  9975. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  9976. this.updateMorphTargets();
  9977. };
  9978. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  9979. THREE.Mesh.prototype.constructor = THREE.Mesh;
  9980. THREE.Mesh.prototype.updateMorphTargets = function () {
  9981. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  9982. this.morphTargetBase = - 1;
  9983. this.morphTargetForcedOrder = [];
  9984. this.morphTargetInfluences = [];
  9985. this.morphTargetDictionary = {};
  9986. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  9987. this.morphTargetInfluences.push( 0 );
  9988. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  9989. }
  9990. }
  9991. };
  9992. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  9993. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  9994. return this.morphTargetDictionary[ name ];
  9995. }
  9996. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  9997. return 0;
  9998. };
  9999. THREE.Mesh.prototype.raycast = ( function () {
  10000. var inverseMatrix = new THREE.Matrix4();
  10001. var ray = new THREE.Ray();
  10002. var sphere = new THREE.Sphere();
  10003. var vA = new THREE.Vector3();
  10004. var vB = new THREE.Vector3();
  10005. var vC = new THREE.Vector3();
  10006. var tempA = new THREE.Vector3();
  10007. var tempB = new THREE.Vector3();
  10008. var tempC = new THREE.Vector3();
  10009. return function raycast( raycaster, intersects ) {
  10010. var geometry = this.geometry;
  10011. var material = this.material;
  10012. if ( material === undefined ) return;
  10013. // Checking boundingSphere distance to ray
  10014. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  10015. sphere.copy( geometry.boundingSphere );
  10016. sphere.applyMatrix4( this.matrixWorld );
  10017. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  10018. return;
  10019. }
  10020. // Check boundingBox before continuing
  10021. inverseMatrix.getInverse( this.matrixWorld );
  10022. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  10023. if ( geometry.boundingBox !== null ) {
  10024. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  10025. return;
  10026. }
  10027. }
  10028. var a, b, c;
  10029. if ( geometry instanceof THREE.BufferGeometry ) {
  10030. var attributes = geometry.attributes;
  10031. if ( attributes.index !== undefined ) {
  10032. var indices = attributes.index.array;
  10033. var positions = attributes.position.array;
  10034. var offsets = geometry.drawcalls;
  10035. if ( offsets.length === 0 ) {
  10036. offsets = [ { start: 0, count: indices.length, index: 0 } ];
  10037. }
  10038. for ( var oi = 0, ol = offsets.length; oi < ol; ++ oi ) {
  10039. var start = offsets[ oi ].start;
  10040. var count = offsets[ oi ].count;
  10041. var index = offsets[ oi ].index;
  10042. for ( var i = start, il = start + count; i < il; i += 3 ) {
  10043. a = index + indices[ i ];
  10044. b = index + indices[ i + 1 ];
  10045. c = index + indices[ i + 2 ];
  10046. vA.fromArray( positions, a * 3 );
  10047. vB.fromArray( positions, b * 3 );
  10048. vC.fromArray( positions, c * 3 );
  10049. if ( material.side === THREE.BackSide ) {
  10050. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  10051. } else {
  10052. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  10053. }
  10054. if ( intersectionPoint === null ) continue;
  10055. intersectionPoint.applyMatrix4( this.matrixWorld );
  10056. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10057. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10058. intersects.push( {
  10059. distance: distance,
  10060. point: intersectionPoint,
  10061. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  10062. faceIndex: Math.floor( i / 3 ), // triangle number in indices buffer semantics
  10063. object: this
  10064. } );
  10065. }
  10066. }
  10067. } else {
  10068. var positions = attributes.position.array;
  10069. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  10070. vA.fromArray( positions, i );
  10071. vB.fromArray( positions, i + 3 );
  10072. vC.fromArray( positions, i + 6 );
  10073. if ( material.side === THREE.BackSide ) {
  10074. var intersectionPoint = ray.intersectTriangle( vC, vB, vA, true );
  10075. } else {
  10076. var intersectionPoint = ray.intersectTriangle( vA, vB, vC, material.side !== THREE.DoubleSide );
  10077. }
  10078. if ( intersectionPoint === null ) continue;
  10079. intersectionPoint.applyMatrix4( this.matrixWorld );
  10080. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10081. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10082. a = i / 3;
  10083. b = a + 1;
  10084. c = a + 2;
  10085. intersects.push( {
  10086. distance: distance,
  10087. point: intersectionPoint,
  10088. face: new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) ),
  10089. index: a, // triangle number in positions buffer semantics
  10090. object: this
  10091. } );
  10092. }
  10093. }
  10094. } else if ( geometry instanceof THREE.Geometry ) {
  10095. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  10096. var materials = isFaceMaterial === true ? material.materials : null;
  10097. var vertices = geometry.vertices;
  10098. var faces = geometry.faces;
  10099. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  10100. var face = faces[ f ];
  10101. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  10102. if ( faceMaterial === undefined ) continue;
  10103. a = vertices[ face.a ];
  10104. b = vertices[ face.b ];
  10105. c = vertices[ face.c ];
  10106. if ( faceMaterial.morphTargets === true ) {
  10107. var morphTargets = geometry.morphTargets;
  10108. var morphInfluences = this.morphTargetInfluences;
  10109. vA.set( 0, 0, 0 );
  10110. vB.set( 0, 0, 0 );
  10111. vC.set( 0, 0, 0 );
  10112. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  10113. var influence = morphInfluences[ t ];
  10114. if ( influence === 0 ) continue;
  10115. var targets = morphTargets[ t ].vertices;
  10116. vA.addScaledVector( tempA.subVectors( targets[ face.a ], a ), influence );
  10117. vB.addScaledVector( tempB.subVectors( targets[ face.b ], b ), influence );
  10118. vC.addScaledVector( tempC.subVectors( targets[ face.c ], c ), influence );
  10119. }
  10120. vA.add( a );
  10121. vB.add( b );
  10122. vC.add( c );
  10123. a = vA;
  10124. b = vB;
  10125. c = vC;
  10126. }
  10127. if ( faceMaterial.side === THREE.BackSide ) {
  10128. var intersectionPoint = ray.intersectTriangle( c, b, a, true );
  10129. } else {
  10130. var intersectionPoint = ray.intersectTriangle( a, b, c, faceMaterial.side !== THREE.DoubleSide );
  10131. }
  10132. if ( intersectionPoint === null ) continue;
  10133. intersectionPoint.applyMatrix4( this.matrixWorld );
  10134. var distance = raycaster.ray.origin.distanceTo( intersectionPoint );
  10135. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  10136. intersects.push( {
  10137. distance: distance,
  10138. point: intersectionPoint,
  10139. face: face,
  10140. faceIndex: f,
  10141. object: this
  10142. } );
  10143. }
  10144. }
  10145. };
  10146. }() );
  10147. THREE.Mesh.prototype.clone = function () {
  10148. var mesh = new THREE.Mesh( this.geometry, this.material );
  10149. return mesh.copy( this );
  10150. };
  10151. THREE.Mesh.prototype.copy = function ( source ) {
  10152. THREE.Object3D.prototype.copy.call( this, source );
  10153. return this;
  10154. };
  10155. THREE.Mesh.prototype.toJSON = function ( meta ) {
  10156. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10157. // only serialize if not in meta geometries cache
  10158. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  10159. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  10160. }
  10161. // only serialize if not in meta materials cache
  10162. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10163. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  10164. }
  10165. data.object.geometry = this.geometry.uuid;
  10166. data.object.material = this.material.uuid;
  10167. return data;
  10168. };
  10169. // File:src/objects/Bone.js
  10170. /**
  10171. * @author mikael emtinger / http://gomo.se/
  10172. * @author alteredq / http://alteredqualia.com/
  10173. * @author ikerr / http://verold.com
  10174. */
  10175. THREE.Bone = function ( skin ) {
  10176. THREE.Object3D.call( this );
  10177. this.type = 'Bone';
  10178. this.skin = skin;
  10179. };
  10180. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  10181. THREE.Bone.prototype.constructor = THREE.Bone;
  10182. THREE.Bone.prototype.clone = function () {
  10183. var bone = new THREE.Bone( this.skin );
  10184. return bone.copy( this );
  10185. };
  10186. THREE.Bone.prototype.copy = function ( source ) {
  10187. THREE.Object3D.prototype.copy.call( this, source );
  10188. this.skin = source.skin;
  10189. return this;
  10190. };
  10191. // File:src/objects/Skeleton.js
  10192. /**
  10193. * @author mikael emtinger / http://gomo.se/
  10194. * @author alteredq / http://alteredqualia.com/
  10195. * @author michael guerrero / http://realitymeltdown.com
  10196. * @author ikerr / http://verold.com
  10197. */
  10198. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  10199. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  10200. this.identityMatrix = new THREE.Matrix4();
  10201. // copy the bone array
  10202. bones = bones || [];
  10203. this.bones = bones.slice( 0 );
  10204. // create a bone texture or an array of floats
  10205. if ( this.useVertexTexture ) {
  10206. // layout (1 matrix = 4 pixels)
  10207. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  10208. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  10209. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  10210. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  10211. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  10212. var size = THREE.Math.nextPowerOfTwo( Math.sqrt( this.bones.length * 4 ) ); // 4 pixels needed for 1 matrix
  10213. if ( size === 0 ) size = 2; // Avoid creating empty texture
  10214. this.boneTextureWidth = size;
  10215. this.boneTextureHeight = size;
  10216. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  10217. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  10218. this.boneTexture.minFilter = THREE.NearestFilter;
  10219. this.boneTexture.magFilter = THREE.NearestFilter;
  10220. this.boneTexture.generateMipmaps = false;
  10221. this.boneTexture.flipY = false;
  10222. } else {
  10223. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  10224. }
  10225. // use the supplied bone inverses or calculate the inverses
  10226. if ( boneInverses === undefined ) {
  10227. this.calculateInverses();
  10228. } else {
  10229. if ( this.bones.length === boneInverses.length ) {
  10230. this.boneInverses = boneInverses.slice( 0 );
  10231. } else {
  10232. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  10233. this.boneInverses = [];
  10234. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10235. this.boneInverses.push( new THREE.Matrix4() );
  10236. }
  10237. }
  10238. }
  10239. };
  10240. THREE.Skeleton.prototype.calculateInverses = function () {
  10241. this.boneInverses = [];
  10242. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10243. var inverse = new THREE.Matrix4();
  10244. if ( this.bones[ b ] ) {
  10245. inverse.getInverse( this.bones[ b ].matrixWorld );
  10246. }
  10247. this.boneInverses.push( inverse );
  10248. }
  10249. };
  10250. THREE.Skeleton.prototype.pose = function () {
  10251. var bone;
  10252. // recover the bind-time world matrices
  10253. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10254. bone = this.bones[ b ];
  10255. if ( bone ) {
  10256. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  10257. }
  10258. }
  10259. // compute the local matrices, positions, rotations and scales
  10260. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10261. bone = this.bones[ b ];
  10262. if ( bone ) {
  10263. if ( bone.parent ) {
  10264. bone.matrix.getInverse( bone.parent.matrixWorld );
  10265. bone.matrix.multiply( bone.matrixWorld );
  10266. } else {
  10267. bone.matrix.copy( bone.matrixWorld );
  10268. }
  10269. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  10270. }
  10271. }
  10272. };
  10273. THREE.Skeleton.prototype.update = ( function () {
  10274. var offsetMatrix = new THREE.Matrix4();
  10275. return function update() {
  10276. // flatten bone matrices to array
  10277. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  10278. // compute the offset between the current and the original transform
  10279. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  10280. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  10281. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  10282. }
  10283. if ( this.useVertexTexture ) {
  10284. this.boneTexture.needsUpdate = true;
  10285. }
  10286. };
  10287. } )();
  10288. THREE.Skeleton.prototype.clone = function () {
  10289. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  10290. };
  10291. // File:src/objects/SkinnedMesh.js
  10292. /**
  10293. * @author mikael emtinger / http://gomo.se/
  10294. * @author alteredq / http://alteredqualia.com/
  10295. * @author ikerr / http://verold.com
  10296. */
  10297. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  10298. THREE.Mesh.call( this, geometry, material );
  10299. this.type = 'SkinnedMesh';
  10300. this.bindMode = "attached";
  10301. this.bindMatrix = new THREE.Matrix4();
  10302. this.bindMatrixInverse = new THREE.Matrix4();
  10303. // init bones
  10304. // TODO: remove bone creation as there is no reason (other than
  10305. // convenience) for THREE.SkinnedMesh to do this.
  10306. var bones = [];
  10307. if ( this.geometry && this.geometry.bones !== undefined ) {
  10308. var bone, gbone;
  10309. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10310. gbone = this.geometry.bones[ b ];
  10311. bone = new THREE.Bone( this );
  10312. bones.push( bone );
  10313. bone.name = gbone.name;
  10314. bone.position.fromArray( gbone.pos );
  10315. bone.quaternion.fromArray( gbone.rotq );
  10316. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  10317. }
  10318. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  10319. gbone = this.geometry.bones[ b ];
  10320. if ( gbone.parent !== - 1 ) {
  10321. bones[ gbone.parent ].add( bones[ b ] );
  10322. } else {
  10323. this.add( bones[ b ] );
  10324. }
  10325. }
  10326. }
  10327. this.normalizeSkinWeights();
  10328. this.updateMatrixWorld( true );
  10329. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ) );
  10330. };
  10331. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  10332. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  10333. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  10334. this.skeleton = skeleton;
  10335. if ( bindMatrix === undefined ) {
  10336. this.updateMatrixWorld( true );
  10337. bindMatrix = this.matrixWorld;
  10338. }
  10339. this.bindMatrix.copy( bindMatrix );
  10340. this.bindMatrixInverse.getInverse( bindMatrix );
  10341. };
  10342. THREE.SkinnedMesh.prototype.pose = function () {
  10343. this.skeleton.pose();
  10344. };
  10345. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  10346. if ( this.geometry instanceof THREE.Geometry ) {
  10347. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  10348. var sw = this.geometry.skinWeights[ i ];
  10349. var scale = 1.0 / sw.lengthManhattan();
  10350. if ( scale !== Infinity ) {
  10351. sw.multiplyScalar( scale );
  10352. } else {
  10353. sw.set( 1 ); // this will be normalized by the shader anyway
  10354. }
  10355. }
  10356. } else {
  10357. // skinning weights assumed to be normalized for THREE.BufferGeometry
  10358. }
  10359. };
  10360. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  10361. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  10362. if ( this.bindMode === "attached" ) {
  10363. this.bindMatrixInverse.getInverse( this.matrixWorld );
  10364. } else if ( this.bindMode === "detached" ) {
  10365. this.bindMatrixInverse.getInverse( this.bindMatrix );
  10366. } else {
  10367. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  10368. }
  10369. };
  10370. THREE.SkinnedMesh.prototype.clone = function() {
  10371. var skinMesh = new THREE.SkinnedMesh( this.geometry, this.material, this.useVertexTexture );
  10372. return skinMesh.copy( this );
  10373. };
  10374. THREE.SkinnedMesh.prototype.copy = function( source ) {
  10375. THREE.Mesh.prototype.copy.call( this, source );
  10376. return this;
  10377. };
  10378. // File:src/objects/MorphAnimMesh.js
  10379. /**
  10380. * @author alteredq / http://alteredqualia.com/
  10381. */
  10382. THREE.MorphAnimMesh = function ( geometry, material ) {
  10383. THREE.Mesh.call( this, geometry, material );
  10384. this.type = 'MorphAnimMesh';
  10385. // API
  10386. this.duration = 1000; // milliseconds
  10387. this.mirroredLoop = false;
  10388. this.time = 0;
  10389. // internals
  10390. this.lastKeyframe = 0;
  10391. this.currentKeyframe = 0;
  10392. this.direction = 1;
  10393. this.directionBackwards = false;
  10394. this.setFrameRange( 0, geometry.morphTargets.length - 1 );
  10395. };
  10396. THREE.MorphAnimMesh.prototype = Object.create( THREE.Mesh.prototype );
  10397. THREE.MorphAnimMesh.prototype.constructor = THREE.MorphAnimMesh;
  10398. THREE.MorphAnimMesh.prototype.setFrameRange = function ( start, end ) {
  10399. this.startKeyframe = start;
  10400. this.endKeyframe = end;
  10401. this.length = this.endKeyframe - this.startKeyframe + 1;
  10402. };
  10403. THREE.MorphAnimMesh.prototype.setDirectionForward = function () {
  10404. this.direction = 1;
  10405. this.directionBackwards = false;
  10406. };
  10407. THREE.MorphAnimMesh.prototype.setDirectionBackward = function () {
  10408. this.direction = - 1;
  10409. this.directionBackwards = true;
  10410. };
  10411. THREE.MorphAnimMesh.prototype.parseAnimations = function () {
  10412. var geometry = this.geometry;
  10413. if ( ! geometry.animations ) geometry.animations = {};
  10414. var firstAnimation, animations = geometry.animations;
  10415. var pattern = /([a-z]+)_?(\d+)/;
  10416. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  10417. var morph = geometry.morphTargets[ i ];
  10418. var parts = morph.name.match( pattern );
  10419. if ( parts && parts.length > 1 ) {
  10420. var label = parts[ 1 ];
  10421. if ( ! animations[ label ] ) animations[ label ] = { start: Infinity, end: - Infinity };
  10422. var animation = animations[ label ];
  10423. if ( i < animation.start ) animation.start = i;
  10424. if ( i > animation.end ) animation.end = i;
  10425. if ( ! firstAnimation ) firstAnimation = label;
  10426. }
  10427. }
  10428. geometry.firstAnimation = firstAnimation;
  10429. };
  10430. THREE.MorphAnimMesh.prototype.setAnimationLabel = function ( label, start, end ) {
  10431. if ( ! this.geometry.animations ) this.geometry.animations = {};
  10432. this.geometry.animations[ label ] = { start: start, end: end };
  10433. };
  10434. THREE.MorphAnimMesh.prototype.playAnimation = function ( label, fps ) {
  10435. var animation = this.geometry.animations[ label ];
  10436. if ( animation ) {
  10437. this.setFrameRange( animation.start, animation.end );
  10438. this.duration = 1000 * ( ( animation.end - animation.start ) / fps );
  10439. this.time = 0;
  10440. } else {
  10441. console.warn( 'THREE.MorphAnimMesh: animation[' + label + '] undefined in .playAnimation()' );
  10442. }
  10443. };
  10444. THREE.MorphAnimMesh.prototype.updateAnimation = function ( delta ) {
  10445. var frameTime = this.duration / this.length;
  10446. this.time += this.direction * delta;
  10447. if ( this.mirroredLoop ) {
  10448. if ( this.time > this.duration || this.time < 0 ) {
  10449. this.direction *= - 1;
  10450. if ( this.time > this.duration ) {
  10451. this.time = this.duration;
  10452. this.directionBackwards = true;
  10453. }
  10454. if ( this.time < 0 ) {
  10455. this.time = 0;
  10456. this.directionBackwards = false;
  10457. }
  10458. }
  10459. } else {
  10460. this.time = this.time % this.duration;
  10461. if ( this.time < 0 ) this.time += this.duration;
  10462. }
  10463. var keyframe = this.startKeyframe + THREE.Math.clamp( Math.floor( this.time / frameTime ), 0, this.length - 1 );
  10464. var influences = this.morphTargetInfluences;
  10465. if ( keyframe !== this.currentKeyframe ) {
  10466. influences[ this.lastKeyframe ] = 0;
  10467. influences[ this.currentKeyframe ] = 1;
  10468. influences[ keyframe ] = 0;
  10469. this.lastKeyframe = this.currentKeyframe;
  10470. this.currentKeyframe = keyframe;
  10471. }
  10472. var mix = ( this.time % frameTime ) / frameTime;
  10473. if ( this.directionBackwards ) {
  10474. mix = 1 - mix;
  10475. }
  10476. influences[ this.currentKeyframe ] = mix;
  10477. influences[ this.lastKeyframe ] = 1 - mix;
  10478. };
  10479. THREE.MorphAnimMesh.prototype.interpolateTargets = function ( a, b, t ) {
  10480. var influences = this.morphTargetInfluences;
  10481. for ( var i = 0, l = influences.length; i < l; i ++ ) {
  10482. influences[ i ] = 0;
  10483. }
  10484. if ( a > -1 ) influences[ a ] = 1 - t;
  10485. if ( b > -1 ) influences[ b ] = t;
  10486. };
  10487. THREE.MorphAnimMesh.prototype.clone = function () {
  10488. var morph = new THREE.MorphAnimMesh( this.geometry, this.material );
  10489. return morph.copy( this );
  10490. };
  10491. THREE.MorphAnimMesh.prototype.copy = function ( source ) {
  10492. this.duration = source.duration;
  10493. this.mirroredLoop = source.mirroredLoop;
  10494. this.time = source.time;
  10495. this.lastKeyframe = source.lastKeyframe;
  10496. this.currentKeyframe = source.currentKeyframe;
  10497. this.direction = source.direction;
  10498. this.directionBackwards = source.directionBackwards;
  10499. THREE.Mesh.prototype.copy.call( this, source );
  10500. return this;
  10501. };
  10502. // File:src/objects/LOD.js
  10503. /**
  10504. * @author mikael emtinger / http://gomo.se/
  10505. * @author alteredq / http://alteredqualia.com/
  10506. * @author mrdoob / http://mrdoob.com/
  10507. */
  10508. THREE.LOD = function () {
  10509. THREE.Object3D.call( this );
  10510. Object.defineProperties( this, {
  10511. levels: {
  10512. enumerable: true,
  10513. value: []
  10514. },
  10515. objects: {
  10516. get: function () {
  10517. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  10518. return this.levels;
  10519. }
  10520. }
  10521. } );
  10522. };
  10523. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  10524. THREE.LOD.prototype.constructor = THREE.LOD;
  10525. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  10526. if ( distance === undefined ) distance = 0;
  10527. distance = Math.abs( distance );
  10528. var levels = this.levels;
  10529. for ( var l = 0; l < levels.length; l ++ ) {
  10530. if ( distance < levels[ l ].distance ) {
  10531. break;
  10532. }
  10533. }
  10534. levels.splice( l, 0, { distance: distance, object: object } );
  10535. this.add( object );
  10536. };
  10537. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  10538. var levels = this.levels;
  10539. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10540. if ( distance < levels[ i ].distance ) {
  10541. break;
  10542. }
  10543. }
  10544. return levels[ i - 1 ].object;
  10545. };
  10546. THREE.LOD.prototype.raycast = ( function () {
  10547. var matrixPosition = new THREE.Vector3();
  10548. return function raycast( raycaster, intersects ) {
  10549. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10550. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  10551. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  10552. };
  10553. }() );
  10554. THREE.LOD.prototype.update = function () {
  10555. var v1 = new THREE.Vector3();
  10556. var v2 = new THREE.Vector3();
  10557. return function update( camera ) {
  10558. var levels = this.levels;
  10559. if ( levels.length > 1 ) {
  10560. v1.setFromMatrixPosition( camera.matrixWorld );
  10561. v2.setFromMatrixPosition( this.matrixWorld );
  10562. var distance = v1.distanceTo( v2 );
  10563. levels[ 0 ].object.visible = true;
  10564. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  10565. if ( distance >= levels[ i ].distance ) {
  10566. levels[ i - 1 ].object.visible = false;
  10567. levels[ i ].object.visible = true;
  10568. } else {
  10569. break;
  10570. }
  10571. }
  10572. for ( ; i < l; i ++ ) {
  10573. levels[ i ].object.visible = false;
  10574. }
  10575. }
  10576. };
  10577. }();
  10578. THREE.LOD.prototype.clone = function () {
  10579. var lod = new THREE.LOD();
  10580. return lod.copy( this );
  10581. };
  10582. THREE.LOD.prototype.copy = function ( source ) {
  10583. THREE.Object3D.prototype.copy.call( this, source, false );
  10584. var levels = source.levels;
  10585. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  10586. var level = levels[ i ];
  10587. this.addLevel( level.object.clone(), level.distance );
  10588. }
  10589. return this;
  10590. };
  10591. // File:src/objects/Sprite.js
  10592. /**
  10593. * @author mikael emtinger / http://gomo.se/
  10594. * @author alteredq / http://alteredqualia.com/
  10595. */
  10596. THREE.Sprite = ( function () {
  10597. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  10598. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  10599. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  10600. var geometry = new THREE.BufferGeometry();
  10601. geometry.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  10602. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  10603. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  10604. return function Sprite( material ) {
  10605. THREE.Object3D.call( this );
  10606. this.type = 'Sprite';
  10607. this.geometry = geometry;
  10608. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  10609. };
  10610. } )();
  10611. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  10612. THREE.Sprite.prototype.constructor = THREE.Sprite;
  10613. THREE.Sprite.prototype.raycast = ( function () {
  10614. var matrixPosition = new THREE.Vector3();
  10615. return function raycast( raycaster, intersects ) {
  10616. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  10617. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  10618. var guessSizeSq = this.scale.x * this.scale.y;
  10619. if ( distanceSq > guessSizeSq ) {
  10620. return;
  10621. }
  10622. intersects.push( {
  10623. distance: Math.sqrt( distanceSq ),
  10624. point: this.position,
  10625. face: null,
  10626. object: this
  10627. } );
  10628. };
  10629. }() );
  10630. THREE.Sprite.prototype.clone = function () {
  10631. var sprite = new THREE.Sprite( this.material );
  10632. return sprite.copy( this );
  10633. };
  10634. THREE.Sprite.prototype.copy = function ( source ) {
  10635. THREE.Object3D.prototype.copy.call( this, source );
  10636. return this;
  10637. };
  10638. THREE.Sprite.prototype.toJSON = function ( meta ) {
  10639. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10640. // only serialize if not in meta materials cache
  10641. if ( meta.materials[ this.material.uuid ] === undefined ) {
  10642. meta.materials[ this.material.uuid ] = this.material.toJSON();
  10643. }
  10644. data.object.material = this.material.uuid;
  10645. return data;
  10646. };
  10647. // Backwards compatibility
  10648. THREE.Particle = THREE.Sprite;
  10649. // File:src/objects/LensFlare.js
  10650. /**
  10651. * @author mikael emtinger / http://gomo.se/
  10652. * @author alteredq / http://alteredqualia.com/
  10653. */
  10654. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  10655. THREE.Object3D.call( this );
  10656. this.lensFlares = [];
  10657. this.positionScreen = new THREE.Vector3();
  10658. this.customUpdateCallback = undefined;
  10659. if ( texture !== undefined ) {
  10660. this.add( texture, size, distance, blending, color );
  10661. }
  10662. };
  10663. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  10664. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  10665. /*
  10666. * Add: adds another flare
  10667. */
  10668. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  10669. if ( size === undefined ) size = - 1;
  10670. if ( distance === undefined ) distance = 0;
  10671. if ( opacity === undefined ) opacity = 1;
  10672. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  10673. if ( blending === undefined ) blending = THREE.NormalBlending;
  10674. distance = Math.min( distance, Math.max( 0, distance ) );
  10675. this.lensFlares.push( {
  10676. texture: texture, // THREE.Texture
  10677. size: size, // size in pixels (-1 = use texture.width)
  10678. distance: distance, // distance (0-1) from light source (0=at light source)
  10679. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  10680. scale: 1, // scale
  10681. rotation: 0, // rotation
  10682. opacity: opacity, // opacity
  10683. color: color, // color
  10684. blending: blending // blending
  10685. } );
  10686. };
  10687. /*
  10688. * Update lens flares update positions on all flares based on the screen position
  10689. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  10690. */
  10691. THREE.LensFlare.prototype.updateLensFlares = function () {
  10692. var f, fl = this.lensFlares.length;
  10693. var flare;
  10694. var vecX = - this.positionScreen.x * 2;
  10695. var vecY = - this.positionScreen.y * 2;
  10696. for ( f = 0; f < fl; f ++ ) {
  10697. flare = this.lensFlares[ f ];
  10698. flare.x = this.positionScreen.x + vecX * flare.distance;
  10699. flare.y = this.positionScreen.y + vecY * flare.distance;
  10700. flare.wantedRotation = flare.x * Math.PI * 0.25;
  10701. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  10702. }
  10703. };
  10704. THREE.LensFlare.prototype.clone = function () {
  10705. var flare = new THREE.LensFlare();
  10706. return flare.copy( this );
  10707. };
  10708. THREE.LensFlare.prototype.copy = function ( source ) {
  10709. THREE.Object3D.prototype.copy.call( this, source );
  10710. this.positionScreen.copy( source.positionScreen );
  10711. this.customUpdateCallback = source.customUpdateCallback;
  10712. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  10713. this.lensFlares.push( source.lensFlares[ i ] );
  10714. }
  10715. return this;
  10716. };
  10717. // File:src/scenes/Scene.js
  10718. /**
  10719. * @author mrdoob / http://mrdoob.com/
  10720. */
  10721. THREE.Scene = function () {
  10722. THREE.Object3D.call( this );
  10723. this.type = 'Scene';
  10724. this.fog = null;
  10725. this.overrideMaterial = null;
  10726. this.autoUpdate = true; // checked by the renderer
  10727. };
  10728. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  10729. THREE.Scene.prototype.constructor = THREE.Scene;
  10730. THREE.Scene.prototype.clone = function () {
  10731. var scene = new THREE.Scene();
  10732. return scene.copy( this );
  10733. };
  10734. THREE.Scene.prototype.copy = function ( source ) {
  10735. THREE.Object3D.prototype.copy.call( this, source );
  10736. if ( source.fog !== null ) this.fog = source.fog.clone();
  10737. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  10738. this.autoUpdate = source.autoUpdate;
  10739. this.matrixAutoUpdate = source.matrixAutoUpdate;
  10740. return this;
  10741. };
  10742. // File:src/scenes/Fog.js
  10743. /**
  10744. * @author mrdoob / http://mrdoob.com/
  10745. * @author alteredq / http://alteredqualia.com/
  10746. */
  10747. THREE.Fog = function ( color, near, far ) {
  10748. this.name = '';
  10749. this.color = new THREE.Color( color );
  10750. this.near = ( near !== undefined ) ? near : 1;
  10751. this.far = ( far !== undefined ) ? far : 1000;
  10752. };
  10753. THREE.Fog.prototype.clone = function () {
  10754. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  10755. };
  10756. // File:src/scenes/FogExp2.js
  10757. /**
  10758. * @author mrdoob / http://mrdoob.com/
  10759. * @author alteredq / http://alteredqualia.com/
  10760. */
  10761. THREE.FogExp2 = function ( color, density ) {
  10762. this.name = '';
  10763. this.color = new THREE.Color( color );
  10764. this.density = ( density !== undefined ) ? density : 0.00025;
  10765. };
  10766. THREE.FogExp2.prototype.clone = function () {
  10767. return new THREE.FogExp2( this.color.getHex(), this.density );
  10768. };
  10769. // File:src/renderers/shaders/ShaderChunk.js
  10770. THREE.ShaderChunk = {};
  10771. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  10772. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  10773. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  10774. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  10775. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  10776. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  10777. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  10778. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  10779. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  10780. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  10781. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  10782. THREE.ShaderChunk[ 'bumpmap_pars_fragment'] = "#ifdef USE_BUMPMAP\n\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n\n // Derivative maps - bump mapping unparametrized surfaces by Morten Mikkelsen\n // http://mmikkelsen3d.blogspot.sk/2011/07/derivative-maps.html\n\n // Evaluate the derivative of the height w.r.t. screen-space using forward differencing (listing 2)\n\n vec2 dHdxy_fwd() {\n\n vec2 dSTdx = dFdx( vUv );\n vec2 dSTdy = dFdy( vUv );\n\n float Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\n return vec2( dBx, dBy );\n\n }\n\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\n vec3 vSigmaX = dFdx( surf_pos );\n vec3 vSigmaY = dFdy( surf_pos );\n vec3 vN = surf_norm; // normalized\n\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n\n float fDet = dot( vSigmaX, R1 );\n\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n\n }\n\n#endif\n";
  10783. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  10784. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  10785. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  10786. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  10787. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  10788. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  10789. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  10790. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  10791. // File:src/renderers/shaders/ShaderChunk/common.glsl
  10792. THREE.ShaderChunk[ 'common'] = "#define PI 3.14159\n#define PI2 6.28318\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\n\nvec3 transformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );\n\n}\n\n// http://en.wikibooks.org/wiki/GLSL_Programming/Applying_Matrix_Transformations\nvec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );\n\n}\n\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n float distance = dot( planeNormal, point - pointOnPlane );\n\n return - distance * planeNormal + point;\n\n}\n\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return sign( dot( point - pointOnPlane, planeNormal ) );\n\n}\n\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n\n}\n\nfloat calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {\n\n if ( decayExponent > 0.0 ) {\n\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\n }\n\n return 1.0;\n\n}\n\nvec3 F_Schlick( in vec3 specularColor, in float dotLH ) {\n\n return ( 1.0 - specularColor ) * pow( 1.0 - dotLH, 5.0 ) + specularColor;\n\n}\n\nfloat G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {\n\n // geometry term is (n⋅l)(n⋅v) / 4(n⋅l)(n⋅v)\n\n return 0.25;\n\n}\n\nfloat D_BlinnPhong( in float shininess, in float dotNH ) {\n\n // factor of 1/PI in distribution term omitted\n\n return ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n\n}\n\nvec3 BRDF_BlinnPhong( in vec3 specularColor, in float shininess, in vec3 normal, in vec3 lightDir, in vec3 viewDir ) {\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n //float dotNL = saturate( dot( normal, lightDir ) );\n //float dotNV = saturate( dot( normal, viewDir ) );\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotLH = saturate( dot( lightDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, dotLH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * G * D;\n\n}\n\nvec3 inputToLinear( in vec3 a ) {\n\n #ifdef GAMMA_INPUT\n\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n\nvec3 linearToOutput( in vec3 a ) {\n\n #ifdef GAMMA_OUTPUT\n\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n";
  10793. // File:src/renderers/shaders/ShaderChunk/default_vertex.glsl
  10794. THREE.ShaderChunk[ 'default_vertex'] = "#ifdef USE_SKINNING\n\n vec4 mvPosition = modelViewMatrix * skinned;\n\n#elif defined( USE_MORPHTARGETS )\n\n vec4 mvPosition = modelViewMatrix * vec4( morphed, 1.0 );\n\n#else\n\n vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;\n";
  10795. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  10796. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef USE_SKINNING\n\n vec3 objectNormal = skinnedNormal.xyz;\n\n#elif defined( USE_MORPHNORMALS )\n\n vec3 objectNormal = morphedNormal;\n\n#else\n\n vec3 objectNormal = normal;\n\n#endif\n\n#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  10797. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  10798. 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";
  10799. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  10800. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  10801. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  10802. THREE.ShaderChunk[ 'envmap_fragment'] = "#ifdef USE_ENVMAP\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\n // Transforming Normal Vectors with the Inverse Transformation\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\n #else\n\n vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\n #endif\n\n #else\n\n vec3 reflectVec = vReflect;\n\n #endif\n\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n vec4 envColor = texture2D( envMap, sampleUV );\n\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n #endif\n\n envColor.xyz = inputToLinear( envColor.xyz );\n\n #ifdef ENVMAP_BLENDING_MULTIPLY\n\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_MIX )\n\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_ADD )\n\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n\n #endif\n\n#endif\n";
  10803. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  10804. 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";
  10805. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  10806. 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";
  10807. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  10808. THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n vec3 worldNormal = transformDirection( objectNormal, modelMatrix );\n\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vReflect = reflect( cameraToVertex, worldNormal );\n\n #else\n\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\n #endif\n\n#endif\n";
  10809. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  10810. 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";
  10811. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  10812. 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";
  10813. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  10814. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  10815. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  10816. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  10817. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  10818. THREE.ShaderChunk[ 'lights_lambert_pars_vertex'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n";
  10819. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  10820. THREE.ShaderChunk[ 'lights_lambert_vertex'] = "vLightFront = vec3( 0.0 );\n\n#ifdef DOUBLE_SIDED\n\n vLightBack = vec3( 0.0 );\n\n#endif\n\nvec3 normal = normalize( transformedNormal );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec4 lPosition = viewMatrix * vec4( pointLightPosition[ i ], 1.0 );\n vec3 lVector = lPosition.xyz - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( lightPosition - worldPosition.xyz ) );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = transformDirection( directionalLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = transformDirection( hemisphereLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n #ifdef DOUBLE_SIDED\n\n float hemiDiffuseWeightBack = - 0.5 * dotProduct + 0.5;\n\n vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );\n\n #endif\n\n }\n\n#endif\n\nvLightFront += ambientLightColor;\n\n#ifdef DOUBLE_SIDED\n\n vLightBack += ambientLightColor;\n\n#endif\n";
  10821. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  10822. THREE.ShaderChunk[ 'lights_phong_fragment'] = "#ifndef FLAT_SHADED\n\n vec3 normal = normalize( vNormal );\n\n #ifdef DOUBLE_SIDED\n\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n\n #endif\n\n#else\n\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n\n#endif\n\n#ifdef USE_NORMALMAP\n\n normal = perturbNormal2Arb( -vViewPosition, normal );\n\n#elif defined( USE_BUMPMAP )\n\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n\n#endif\n\nvec3 viewDir = normalize( vViewPosition );\n\nvec3 totalDiffuseLight = vec3( 0.0 );\nvec3 totalSpecularLight = vec3( 0.0 );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec3 lightPosition = pointLightPosition[ i ];\n vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec4 lPosition = viewMatrix * vec4( lightPosition, 1.0 );\n vec3 lVector = lPosition.xyz + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], normalize( lightPosition - vWorldPosition ) );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n // attenuation\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = transformDirection( directionalLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * cosineTerm;\n\n // specular\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * cosineTerm;\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = transformDirection( hemisphereLightDirection[ i ], viewMatrix );\n\n // diffuse\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vec3 lightColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n totalDiffuseLight += lightColor;\n\n // specular (sky term only)\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * max( dotProduct, 0.0 );\n\n }\n\n#endif\n\n#ifdef METAL\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;\n\n#else\n\n outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;\n\n#endif\n";
  10823. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  10824. THREE.ShaderChunk[ 'lights_phong_pars_fragment'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\nvarying vec3 vViewPosition;\n\n#ifndef FLAT_SHADED\n\n varying vec3 vNormal;\n\n#endif\n";
  10825. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  10826. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n";
  10827. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  10828. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_BUMPMAP ) || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif";
  10829. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  10830. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  10831. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  10832. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  10833. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  10834. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n\n uniform float logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n #extension GL_EXT_frag_depth : enable\n varying float vFragDepth;\n\n #endif\n\n#endif";
  10835. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  10836. 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";
  10837. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  10838. 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";
  10839. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  10840. 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";
  10841. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  10842. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  10843. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  10844. 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";
  10845. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  10846. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  10847. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  10848. THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n\n vec3 morphedNormal = vec3( 0.0 );\n\n morphedNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n morphedNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n morphedNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n morphedNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n\n morphedNormal += normal;\n\n#endif";
  10849. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  10850. 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";
  10851. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  10852. THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n\n vec3 morphed = vec3( 0.0 );\n morphed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n morphed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n morphed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n morphed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\n #ifndef USE_MORPHNORMALS\n\n morphed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n morphed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n morphed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n morphed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\n #endif\n\n morphed += position;\n\n#endif";
  10853. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  10854. THREE.ShaderChunk[ 'normalmap_pars_fragment'] = "#ifdef USE_NORMALMAP\n\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n\n // Per-Pixel Tangent Space Normal Mapping\n // http://hacksoflife.blogspot.ch/2009/11/per-pixel-tangent-space-normal-mapping.html\n\n vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\n vec3 q0 = dFdx( eye_pos.xyz );\n vec3 q1 = dFdy( eye_pos.xyz );\n vec2 st0 = dFdx( vUv.st );\n vec2 st1 = dFdy( vUv.st );\n\n vec3 S = normalize( q0 * st1.t - q1 * st0.t );\n vec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n vec3 N = normalize( surf_norm );\n\n vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n mapN.xy = normalScale * mapN.xy;\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n\n }\n\n#endif\n";
  10855. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  10856. THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\n\n #ifdef SHADOWMAP_DEBUG\n\n vec3 frustumColors[3];\n frustumColors[0] = vec3( 1.0, 0.5, 0.0 );\n frustumColors[1] = vec3( 0.0, 1.0, 0.8 );\n frustumColors[2] = vec3( 0.0, 0.5, 1.0 );\n\n #endif\n\n #ifdef SHADOWMAP_CASCADE\n\n int inFrustumCount = 0;\n\n #endif\n\n float fDepth;\n vec3 shadowColor = vec3( 1.0 );\n\n for( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n\n // if ( something && something ) breaks ATI OpenGL shader compiler\n // if ( all( something, something ) ) using this instead\n\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n\n // don't shadow pixels outside of light frustum\n // use just first frustum (for cascades)\n // don't shadow pixels behind far plane of light frustum\n\n #ifdef SHADOWMAP_CASCADE\n\n inFrustumCount += int( inFrustum );\n bvec3 frustumTestVec = bvec3( inFrustum, inFrustumCount == 1, shadowCoord.z <= 1.0 );\n\n #else\n\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\n #endif\n\n bool frustumTest = all( frustumTestVec );\n\n if ( frustumTest ) {\n\n shadowCoord.z += shadowBias[ i ];\n\n #if defined( SHADOWMAP_TYPE_PCF )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n /*\n // nested loops breaks shader compiler / validator on some ATI cards when using OpenGL\n // must enroll loop manually\n\n for ( float y = -1.25; y <= 1.25; y += 1.25 )\n for ( float x = -1.25; x <= 1.25; x += 1.25 ) {\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\n\n // doesn't seem to produce any noticeable visual difference compared to simple texture2D lookup\n //vec4 rgbaDepth = texture2DProj( shadowMap[ i ], vec4( vShadowCoord[ i ].w * ( vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy ), 0.05, vShadowCoord[ i ].w ) );\n\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n shadow += 1.0;\n\n }\n\n shadow /= 9.0;\n\n */\n\n const float shadowDelta = 1.0 / 9.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n float dx0 = -1.25 * xPixelOffset;\n float dy0 = -1.25 * yPixelOffset;\n float dx1 = 1.25 * xPixelOffset;\n float dy1 = 1.25 * yPixelOffset;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += shadowDelta;\n\n shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n // Percentage-close filtering\n // (9 pixel kernel)\n // http://fabiensanglard.net/shadowmappingPCF/\n\n float shadow = 0.0;\n\n float xPixelOffset = 1.0 / shadowMapSize[ i ].x;\n float yPixelOffset = 1.0 / shadowMapSize[ i ].y;\n\n float dx0 = -1.0 * xPixelOffset;\n float dy0 = -1.0 * yPixelOffset;\n float dx1 = 1.0 * xPixelOffset;\n float dy1 = 1.0 * yPixelOffset;\n\n mat3 shadowKernel;\n mat3 depthKernel;\n\n depthKernel[0][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n depthKernel[0][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n depthKernel[0][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n depthKernel[1][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n depthKernel[1][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n depthKernel[1][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n depthKernel[2][0] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n depthKernel[2][1] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n depthKernel[2][2] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[0] = vec3(lessThan(depthKernel[0], shadowZ ));\n shadowKernel[0] *= vec3(0.25);\n\n shadowKernel[1] = vec3(lessThan(depthKernel[1], shadowZ ));\n shadowKernel[1] *= vec3(0.25);\n\n shadowKernel[2] = vec3(lessThan(depthKernel[2], shadowZ ));\n shadowKernel[2] *= vec3(0.25);\n\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[i].xy );\n\n shadowKernel[0] = mix( shadowKernel[1], shadowKernel[0], fractionalCoord.x );\n shadowKernel[1] = mix( shadowKernel[2], shadowKernel[1], fractionalCoord.x );\n\n vec4 shadowValues;\n shadowValues.x = mix( shadowKernel[0][1], shadowKernel[0][0], fractionalCoord.y );\n shadowValues.y = mix( shadowKernel[0][2], shadowKernel[0][1], fractionalCoord.y );\n shadowValues.z = mix( shadowKernel[1][1], shadowKernel[1][0], fractionalCoord.y );\n shadowValues.w = mix( shadowKernel[1][2], shadowKernel[1][1], fractionalCoord.y );\n\n shadow = dot( shadowValues, vec4( 1.0 ) );\n\n shadowColor = shadowColor * vec3( ( 1.0 - shadowDarkness[ i ] * shadow ) );\n\n #else\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n\n // spot with multiple shadows is darker\n\n shadowColor = shadowColor * vec3( 1.0 - shadowDarkness[ i ] );\n\n // spot with multiple shadows has the same color as single shadow spot\n\n // shadowColor = min( shadowColor, vec3( shadowDarkness[ i ] ) );\n\n #endif\n\n }\n\n\n #ifdef SHADOWMAP_DEBUG\n\n #ifdef SHADOWMAP_CASCADE\n\n if ( inFrustum && inFrustumCount == 1 ) outgoingLight *= frustumColors[ i ];\n\n #else\n\n if ( inFrustum ) outgoingLight *= frustumColors[ i ];\n\n #endif\n\n #endif\n\n }\n\n outgoingLight = outgoingLight * shadowColor;\n\n#endif\n";
  10857. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  10858. THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n\n uniform sampler2D shadowMap[ MAX_SHADOWS ];\n uniform vec2 shadowMapSize[ MAX_SHADOWS ];\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform float shadowBias[ MAX_SHADOWS ];\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n float unpackDepth( const in vec4 rgba_depth ) {\n\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n float depth = dot( rgba_depth, bit_shift );\n return depth;\n\n }\n\n#endif";
  10859. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  10860. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n\n#endif";
  10861. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  10862. 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";
  10863. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  10864. 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";
  10865. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  10866. 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";
  10867. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  10868. THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n\n #ifdef USE_MORPHTARGETS\n\n vec4 skinVertex = bindMatrix * vec4( morphed, 1.0 );\n\n #else\n\n vec4 skinVertex = bindMatrix * vec4( position, 1.0 );\n\n #endif\n\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n skinned = bindMatrixInverse * skinned;\n\n#endif\n";
  10869. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  10870. THREE.ShaderChunk[ 'skinnormal_vertex'] = "#ifdef USE_SKINNING\n\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\n #ifdef USE_MORPHNORMALS\n\n vec4 skinnedNormal = skinMatrix * vec4( morphedNormal, 0.0 );\n\n #else\n\n vec4 skinnedNormal = skinMatrix * vec4( normal, 0.0 );\n\n #endif\n\n#endif\n";
  10871. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  10872. 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";
  10873. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  10874. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  10875. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  10876. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  10877. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  10878. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  10879. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  10880. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  10881. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  10882. 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";
  10883. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  10884. 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";
  10885. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  10886. 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";
  10887. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  10888. THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\n #ifdef USE_SKINNING\n\n vec4 worldPosition = modelMatrix * skinned;\n\n #elif defined( USE_MORPHTARGETS )\n\n vec4 worldPosition = modelMatrix * vec4( morphed, 1.0 );\n\n #else\n\n vec4 worldPosition = modelMatrix * vec4( position, 1.0 );\n\n #endif\n\n#endif\n";
  10889. // File:src/renderers/shaders/UniformsUtils.js
  10890. /**
  10891. * Uniform Utilities
  10892. */
  10893. THREE.UniformsUtils = {
  10894. merge: function ( uniforms ) {
  10895. var merged = {};
  10896. for ( var u = 0; u < uniforms.length; u ++ ) {
  10897. var tmp = this.clone( uniforms[ u ] );
  10898. for ( var p in tmp ) {
  10899. merged[ p ] = tmp[ p ];
  10900. }
  10901. }
  10902. return merged;
  10903. },
  10904. clone: function ( uniforms_src ) {
  10905. var uniforms_dst = {};
  10906. for ( var u in uniforms_src ) {
  10907. uniforms_dst[ u ] = {};
  10908. for ( var p in uniforms_src[ u ] ) {
  10909. var parameter_src = uniforms_src[ u ][ p ];
  10910. if ( parameter_src instanceof THREE.Color ||
  10911. parameter_src instanceof THREE.Vector2 ||
  10912. parameter_src instanceof THREE.Vector3 ||
  10913. parameter_src instanceof THREE.Vector4 ||
  10914. parameter_src instanceof THREE.Matrix3 ||
  10915. parameter_src instanceof THREE.Matrix4 ||
  10916. parameter_src instanceof THREE.Texture ) {
  10917. uniforms_dst[ u ][ p ] = parameter_src.clone();
  10918. } else if ( Array.isArray( parameter_src ) ) {
  10919. uniforms_dst[ u ][ p ] = parameter_src.slice();
  10920. } else {
  10921. uniforms_dst[ u ][ p ] = parameter_src;
  10922. }
  10923. }
  10924. }
  10925. return uniforms_dst;
  10926. }
  10927. };
  10928. // File:src/renderers/shaders/UniformsLib.js
  10929. /**
  10930. * Uniforms library for shared webgl shaders
  10931. */
  10932. THREE.UniformsLib = {
  10933. common: {
  10934. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10935. "opacity" : { type: "f", value: 1.0 },
  10936. "map" : { type: "t", value: null },
  10937. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10938. "specularMap" : { type: "t", value: null },
  10939. "alphaMap" : { type: "t", value: null },
  10940. "envMap" : { type: "t", value: null },
  10941. "flipEnvMap" : { type: "f", value: - 1 },
  10942. "reflectivity" : { type: "f", value: 1.0 },
  10943. "refractionRatio" : { type: "f", value: 0.98 }
  10944. },
  10945. aomap: {
  10946. "aoMap" : { type: "t", value: null },
  10947. "aoMapIntensity" : { type: "f", value: 1 },
  10948. },
  10949. lightmap: {
  10950. "lightMap" : { type: "t", value: null },
  10951. "lightMapIntensity" : { type: "f", value: 1 },
  10952. },
  10953. emissivemap: {
  10954. "emissiveMap" : { type: "t", value: null },
  10955. },
  10956. bump: {
  10957. "bumpMap" : { type: "t", value: null },
  10958. "bumpScale" : { type: "f", value: 1 }
  10959. },
  10960. normalmap: {
  10961. "normalMap" : { type: "t", value: null },
  10962. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  10963. },
  10964. fog : {
  10965. "fogDensity" : { type: "f", value: 0.00025 },
  10966. "fogNear" : { type: "f", value: 1 },
  10967. "fogFar" : { type: "f", value: 2000 },
  10968. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  10969. },
  10970. lights: {
  10971. "ambientLightColor" : { type: "fv", value: [] },
  10972. "directionalLightDirection" : { type: "fv", value: [] },
  10973. "directionalLightColor" : { type: "fv", value: [] },
  10974. "hemisphereLightDirection" : { type: "fv", value: [] },
  10975. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  10976. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  10977. "pointLightColor" : { type: "fv", value: [] },
  10978. "pointLightPosition" : { type: "fv", value: [] },
  10979. "pointLightDistance" : { type: "fv1", value: [] },
  10980. "pointLightDecay" : { type: "fv1", value: [] },
  10981. "spotLightColor" : { type: "fv", value: [] },
  10982. "spotLightPosition" : { type: "fv", value: [] },
  10983. "spotLightDirection" : { type: "fv", value: [] },
  10984. "spotLightDistance" : { type: "fv1", value: [] },
  10985. "spotLightAngleCos" : { type: "fv1", value: [] },
  10986. "spotLightExponent" : { type: "fv1", value: [] },
  10987. "spotLightDecay" : { type: "fv1", value: [] }
  10988. },
  10989. particle: {
  10990. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  10991. "opacity" : { type: "f", value: 1.0 },
  10992. "size" : { type: "f", value: 1.0 },
  10993. "scale" : { type: "f", value: 1.0 },
  10994. "map" : { type: "t", value: null },
  10995. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  10996. "fogDensity" : { type: "f", value: 0.00025 },
  10997. "fogNear" : { type: "f", value: 1 },
  10998. "fogFar" : { type: "f", value: 2000 },
  10999. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  11000. },
  11001. shadowmap: {
  11002. "shadowMap": { type: "tv", value: [] },
  11003. "shadowMapSize": { type: "v2v", value: [] },
  11004. "shadowBias" : { type: "fv1", value: [] },
  11005. "shadowDarkness": { type: "fv1", value: [] },
  11006. "shadowMatrix" : { type: "m4v", value: [] }
  11007. }
  11008. };
  11009. // File:src/renderers/shaders/ShaderLib.js
  11010. /**
  11011. * Webgl Shader Library for three.js
  11012. *
  11013. * @author alteredq / http://alteredqualia.com/
  11014. * @author mrdoob / http://mrdoob.com/
  11015. * @author mikael emtinger / http://gomo.se/
  11016. */
  11017. THREE.ShaderLib = {
  11018. 'basic': {
  11019. uniforms: THREE.UniformsUtils.merge( [
  11020. THREE.UniformsLib[ "common" ],
  11021. THREE.UniformsLib[ "aomap" ],
  11022. THREE.UniformsLib[ "fog" ],
  11023. THREE.UniformsLib[ "shadowmap" ]
  11024. ] ),
  11025. vertexShader: [
  11026. THREE.ShaderChunk[ "common" ],
  11027. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11028. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11029. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11030. THREE.ShaderChunk[ "color_pars_vertex" ],
  11031. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11032. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11033. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11034. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11035. "void main() {",
  11036. THREE.ShaderChunk[ "uv_vertex" ],
  11037. THREE.ShaderChunk[ "uv2_vertex" ],
  11038. THREE.ShaderChunk[ "color_vertex" ],
  11039. THREE.ShaderChunk[ "skinbase_vertex" ],
  11040. " #ifdef USE_ENVMAP",
  11041. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11042. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11043. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11044. " #endif",
  11045. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11046. THREE.ShaderChunk[ "skinning_vertex" ],
  11047. THREE.ShaderChunk[ "default_vertex" ],
  11048. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11049. THREE.ShaderChunk[ "worldpos_vertex" ],
  11050. THREE.ShaderChunk[ "envmap_vertex" ],
  11051. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11052. "}"
  11053. ].join("\n"),
  11054. fragmentShader: [
  11055. "uniform vec3 diffuse;",
  11056. "uniform float opacity;",
  11057. THREE.ShaderChunk[ "common" ],
  11058. THREE.ShaderChunk[ "color_pars_fragment" ],
  11059. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11060. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11061. THREE.ShaderChunk[ "map_pars_fragment" ],
  11062. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11063. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11064. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11065. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11066. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11067. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11068. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11069. "void main() {",
  11070. " vec3 outgoingLight = vec3( 0.0 );",
  11071. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11072. " vec3 totalAmbientLight = vec3( 1.0 );", // hardwired
  11073. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11074. THREE.ShaderChunk[ "map_fragment" ],
  11075. THREE.ShaderChunk[ "color_fragment" ],
  11076. THREE.ShaderChunk[ "alphamap_fragment" ],
  11077. THREE.ShaderChunk[ "alphatest_fragment" ],
  11078. THREE.ShaderChunk[ "specularmap_fragment" ],
  11079. THREE.ShaderChunk[ "aomap_fragment" ],
  11080. " outgoingLight = diffuseColor.rgb * totalAmbientLight;", // simple shader
  11081. THREE.ShaderChunk[ "envmap_fragment" ],
  11082. THREE.ShaderChunk[ "shadowmap_fragment" ], // TODO: Shadows on an otherwise unlit surface doesn't make sense.
  11083. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11084. THREE.ShaderChunk[ "fog_fragment" ],
  11085. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11086. "}"
  11087. ].join("\n")
  11088. },
  11089. 'lambert': {
  11090. uniforms: THREE.UniformsUtils.merge( [
  11091. THREE.UniformsLib[ "common" ],
  11092. THREE.UniformsLib[ "fog" ],
  11093. THREE.UniformsLib[ "lights" ],
  11094. THREE.UniformsLib[ "shadowmap" ],
  11095. {
  11096. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  11097. }
  11098. ] ),
  11099. vertexShader: [
  11100. "#define LAMBERT",
  11101. "varying vec3 vLightFront;",
  11102. "#ifdef DOUBLE_SIDED",
  11103. " varying vec3 vLightBack;",
  11104. "#endif",
  11105. THREE.ShaderChunk[ "common" ],
  11106. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11107. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11108. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11109. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  11110. THREE.ShaderChunk[ "color_pars_vertex" ],
  11111. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11112. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11113. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11114. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11115. "void main() {",
  11116. THREE.ShaderChunk[ "uv_vertex" ],
  11117. THREE.ShaderChunk[ "uv2_vertex" ],
  11118. THREE.ShaderChunk[ "color_vertex" ],
  11119. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11120. THREE.ShaderChunk[ "skinbase_vertex" ],
  11121. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11122. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11123. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11124. THREE.ShaderChunk[ "skinning_vertex" ],
  11125. THREE.ShaderChunk[ "default_vertex" ],
  11126. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11127. THREE.ShaderChunk[ "worldpos_vertex" ],
  11128. THREE.ShaderChunk[ "envmap_vertex" ],
  11129. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  11130. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11131. "}"
  11132. ].join("\n"),
  11133. fragmentShader: [
  11134. "uniform vec3 diffuse;",
  11135. "uniform vec3 emissive;",
  11136. "uniform float opacity;",
  11137. "varying vec3 vLightFront;",
  11138. "#ifdef DOUBLE_SIDED",
  11139. " varying vec3 vLightBack;",
  11140. "#endif",
  11141. THREE.ShaderChunk[ "common" ],
  11142. THREE.ShaderChunk[ "color_pars_fragment" ],
  11143. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11144. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11145. THREE.ShaderChunk[ "map_pars_fragment" ],
  11146. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11147. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11148. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11149. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11150. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11151. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11152. "void main() {",
  11153. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  11154. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11155. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11156. THREE.ShaderChunk[ "map_fragment" ],
  11157. THREE.ShaderChunk[ "color_fragment" ],
  11158. THREE.ShaderChunk[ "alphamap_fragment" ],
  11159. THREE.ShaderChunk[ "alphatest_fragment" ],
  11160. THREE.ShaderChunk[ "specularmap_fragment" ],
  11161. " #ifdef DOUBLE_SIDED",
  11162. " if ( gl_FrontFacing )",
  11163. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11164. " else",
  11165. " outgoingLight += diffuseColor.rgb * vLightBack + emissive;",
  11166. " #else",
  11167. " outgoingLight += diffuseColor.rgb * vLightFront + emissive;",
  11168. " #endif",
  11169. THREE.ShaderChunk[ "envmap_fragment" ],
  11170. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11171. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11172. THREE.ShaderChunk[ "fog_fragment" ],
  11173. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11174. "}"
  11175. ].join("\n")
  11176. },
  11177. 'phong': {
  11178. uniforms: THREE.UniformsUtils.merge( [
  11179. THREE.UniformsLib[ "common" ],
  11180. THREE.UniformsLib[ "aomap" ],
  11181. THREE.UniformsLib[ "lightmap" ],
  11182. THREE.UniformsLib[ "emissivemap" ],
  11183. THREE.UniformsLib[ "bump" ],
  11184. THREE.UniformsLib[ "normalmap" ],
  11185. THREE.UniformsLib[ "fog" ],
  11186. THREE.UniformsLib[ "lights" ],
  11187. THREE.UniformsLib[ "shadowmap" ],
  11188. {
  11189. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  11190. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  11191. "shininess": { type: "f", value: 30 }
  11192. }
  11193. ] ),
  11194. vertexShader: [
  11195. "#define PHONG",
  11196. "varying vec3 vViewPosition;",
  11197. "#ifndef FLAT_SHADED",
  11198. " varying vec3 vNormal;",
  11199. "#endif",
  11200. THREE.ShaderChunk[ "common" ],
  11201. THREE.ShaderChunk[ "uv_pars_vertex" ],
  11202. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  11203. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  11204. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  11205. THREE.ShaderChunk[ "color_pars_vertex" ],
  11206. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11207. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11208. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11209. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11210. "void main() {",
  11211. THREE.ShaderChunk[ "uv_vertex" ],
  11212. THREE.ShaderChunk[ "uv2_vertex" ],
  11213. THREE.ShaderChunk[ "color_vertex" ],
  11214. THREE.ShaderChunk[ "morphnormal_vertex" ],
  11215. THREE.ShaderChunk[ "skinbase_vertex" ],
  11216. THREE.ShaderChunk[ "skinnormal_vertex" ],
  11217. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  11218. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  11219. " vNormal = normalize( transformedNormal );",
  11220. "#endif",
  11221. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11222. THREE.ShaderChunk[ "skinning_vertex" ],
  11223. THREE.ShaderChunk[ "default_vertex" ],
  11224. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11225. " vViewPosition = - mvPosition.xyz;",
  11226. THREE.ShaderChunk[ "worldpos_vertex" ],
  11227. THREE.ShaderChunk[ "envmap_vertex" ],
  11228. THREE.ShaderChunk[ "lights_phong_vertex" ],
  11229. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11230. "}"
  11231. ].join("\n"),
  11232. fragmentShader: [
  11233. "#define PHONG",
  11234. "uniform vec3 diffuse;",
  11235. "uniform vec3 emissive;",
  11236. "uniform vec3 specular;",
  11237. "uniform float shininess;",
  11238. "uniform float opacity;",
  11239. THREE.ShaderChunk[ "common" ],
  11240. THREE.ShaderChunk[ "color_pars_fragment" ],
  11241. THREE.ShaderChunk[ "uv_pars_fragment" ],
  11242. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  11243. THREE.ShaderChunk[ "map_pars_fragment" ],
  11244. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  11245. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  11246. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  11247. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  11248. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  11249. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11250. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  11251. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11252. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  11253. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  11254. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  11255. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11256. "void main() {",
  11257. " vec3 outgoingLight = vec3( 0.0 );",
  11258. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11259. " vec3 totalAmbientLight = ambientLightColor;",
  11260. " vec3 totalEmissiveLight = emissive;",
  11261. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11262. THREE.ShaderChunk[ "map_fragment" ],
  11263. THREE.ShaderChunk[ "color_fragment" ],
  11264. THREE.ShaderChunk[ "alphamap_fragment" ],
  11265. THREE.ShaderChunk[ "alphatest_fragment" ],
  11266. THREE.ShaderChunk[ "specularmap_fragment" ],
  11267. THREE.ShaderChunk[ "lightmap_fragment" ],
  11268. THREE.ShaderChunk[ "aomap_fragment" ],
  11269. THREE.ShaderChunk[ "emissivemap_fragment" ],
  11270. THREE.ShaderChunk[ "lights_phong_fragment" ],
  11271. THREE.ShaderChunk[ "envmap_fragment" ],
  11272. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11273. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  11274. THREE.ShaderChunk[ "fog_fragment" ],
  11275. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11276. "}"
  11277. ].join("\n")
  11278. },
  11279. 'particle_basic': {
  11280. uniforms: THREE.UniformsUtils.merge( [
  11281. THREE.UniformsLib[ "particle" ],
  11282. THREE.UniformsLib[ "shadowmap" ]
  11283. ] ),
  11284. vertexShader: [
  11285. "uniform float size;",
  11286. "uniform float scale;",
  11287. THREE.ShaderChunk[ "common" ],
  11288. THREE.ShaderChunk[ "color_pars_vertex" ],
  11289. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  11290. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11291. "void main() {",
  11292. THREE.ShaderChunk[ "color_vertex" ],
  11293. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11294. " #ifdef USE_SIZEATTENUATION",
  11295. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  11296. " #else",
  11297. " gl_PointSize = size;",
  11298. " #endif",
  11299. " gl_Position = projectionMatrix * mvPosition;",
  11300. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11301. THREE.ShaderChunk[ "worldpos_vertex" ],
  11302. THREE.ShaderChunk[ "shadowmap_vertex" ],
  11303. "}"
  11304. ].join("\n"),
  11305. fragmentShader: [
  11306. "uniform vec3 psColor;",
  11307. "uniform float opacity;",
  11308. THREE.ShaderChunk[ "common" ],
  11309. THREE.ShaderChunk[ "color_pars_fragment" ],
  11310. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  11311. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11312. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  11313. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11314. "void main() {",
  11315. " vec3 outgoingLight = vec3( 0.0 );",
  11316. " vec4 diffuseColor = vec4( psColor, opacity );",
  11317. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11318. THREE.ShaderChunk[ "map_particle_fragment" ],
  11319. THREE.ShaderChunk[ "color_fragment" ],
  11320. THREE.ShaderChunk[ "alphatest_fragment" ],
  11321. " outgoingLight = diffuseColor.rgb;", // simple shader
  11322. THREE.ShaderChunk[ "shadowmap_fragment" ],
  11323. THREE.ShaderChunk[ "fog_fragment" ],
  11324. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11325. "}"
  11326. ].join("\n")
  11327. },
  11328. 'dashed': {
  11329. uniforms: THREE.UniformsUtils.merge( [
  11330. THREE.UniformsLib[ "common" ],
  11331. THREE.UniformsLib[ "fog" ],
  11332. {
  11333. "scale" : { type: "f", value: 1 },
  11334. "dashSize" : { type: "f", value: 1 },
  11335. "totalSize": { type: "f", value: 2 }
  11336. }
  11337. ] ),
  11338. vertexShader: [
  11339. "uniform float scale;",
  11340. "attribute float lineDistance;",
  11341. "varying float vLineDistance;",
  11342. THREE.ShaderChunk[ "common" ],
  11343. THREE.ShaderChunk[ "color_pars_vertex" ],
  11344. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11345. "void main() {",
  11346. THREE.ShaderChunk[ "color_vertex" ],
  11347. " vLineDistance = scale * lineDistance;",
  11348. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  11349. " gl_Position = projectionMatrix * mvPosition;",
  11350. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11351. "}"
  11352. ].join("\n"),
  11353. fragmentShader: [
  11354. "uniform vec3 diffuse;",
  11355. "uniform float opacity;",
  11356. "uniform float dashSize;",
  11357. "uniform float totalSize;",
  11358. "varying float vLineDistance;",
  11359. THREE.ShaderChunk[ "common" ],
  11360. THREE.ShaderChunk[ "color_pars_fragment" ],
  11361. THREE.ShaderChunk[ "fog_pars_fragment" ],
  11362. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11363. "void main() {",
  11364. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  11365. " discard;",
  11366. " }",
  11367. " vec3 outgoingLight = vec3( 0.0 );",
  11368. " vec4 diffuseColor = vec4( diffuse, opacity );",
  11369. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11370. THREE.ShaderChunk[ "color_fragment" ],
  11371. " outgoingLight = diffuseColor.rgb;", // simple shader
  11372. THREE.ShaderChunk[ "fog_fragment" ],
  11373. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  11374. "}"
  11375. ].join("\n")
  11376. },
  11377. 'depth': {
  11378. uniforms: {
  11379. "mNear": { type: "f", value: 1.0 },
  11380. "mFar" : { type: "f", value: 2000.0 },
  11381. "opacity" : { type: "f", value: 1.0 }
  11382. },
  11383. vertexShader: [
  11384. THREE.ShaderChunk[ "common" ],
  11385. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11386. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11387. "void main() {",
  11388. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11389. THREE.ShaderChunk[ "default_vertex" ],
  11390. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11391. "}"
  11392. ].join("\n"),
  11393. fragmentShader: [
  11394. "uniform float mNear;",
  11395. "uniform float mFar;",
  11396. "uniform float opacity;",
  11397. THREE.ShaderChunk[ "common" ],
  11398. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11399. "void main() {",
  11400. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11401. " #ifdef USE_LOGDEPTHBUF_EXT",
  11402. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  11403. " #else",
  11404. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  11405. " #endif",
  11406. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  11407. " gl_FragColor = vec4( vec3( color ), opacity );",
  11408. "}"
  11409. ].join("\n")
  11410. },
  11411. 'normal': {
  11412. uniforms: {
  11413. "opacity" : { type: "f", value: 1.0 }
  11414. },
  11415. vertexShader: [
  11416. "varying vec3 vNormal;",
  11417. THREE.ShaderChunk[ "common" ],
  11418. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11419. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11420. "void main() {",
  11421. " vNormal = normalize( normalMatrix * normal );",
  11422. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11423. THREE.ShaderChunk[ "default_vertex" ],
  11424. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11425. "}"
  11426. ].join("\n"),
  11427. fragmentShader: [
  11428. "uniform float opacity;",
  11429. "varying vec3 vNormal;",
  11430. THREE.ShaderChunk[ "common" ],
  11431. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11432. "void main() {",
  11433. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  11434. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11435. "}"
  11436. ].join("\n")
  11437. },
  11438. /* -------------------------------------------------------------------------
  11439. // Cube map shader
  11440. ------------------------------------------------------------------------- */
  11441. 'cube': {
  11442. uniforms: { "tCube": { type: "t", value: null },
  11443. "tFlip": { type: "f", value: - 1 } },
  11444. vertexShader: [
  11445. "varying vec3 vWorldPosition;",
  11446. THREE.ShaderChunk[ "common" ],
  11447. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11448. "void main() {",
  11449. " vWorldPosition = transformDirection( position, modelMatrix );",
  11450. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11451. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11452. "}"
  11453. ].join("\n"),
  11454. fragmentShader: [
  11455. "uniform samplerCube tCube;",
  11456. "uniform float tFlip;",
  11457. "varying vec3 vWorldPosition;",
  11458. THREE.ShaderChunk[ "common" ],
  11459. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11460. "void main() {",
  11461. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11462. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11463. "}"
  11464. ].join("\n")
  11465. },
  11466. /* -------------------------------------------------------------------------
  11467. // Cube map shader
  11468. ------------------------------------------------------------------------- */
  11469. 'equirect': {
  11470. uniforms: { "tEquirect": { type: "t", value: null },
  11471. "tFlip": { type: "f", value: - 1 } },
  11472. vertexShader: [
  11473. "varying vec3 vWorldPosition;",
  11474. THREE.ShaderChunk[ "common" ],
  11475. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11476. "void main() {",
  11477. " vWorldPosition = transformDirection( position, modelMatrix );",
  11478. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  11479. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11480. "}"
  11481. ].join("\n"),
  11482. fragmentShader: [
  11483. "uniform sampler2D tEquirect;",
  11484. "uniform float tFlip;",
  11485. "varying vec3 vWorldPosition;",
  11486. THREE.ShaderChunk[ "common" ],
  11487. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11488. "void main() {",
  11489. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  11490. "vec3 direction = normalize( vWorldPosition );",
  11491. "vec2 sampleUV;",
  11492. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  11493. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  11494. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  11495. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11496. "}"
  11497. ].join("\n")
  11498. },
  11499. /* Depth encoding into RGBA texture
  11500. *
  11501. * based on SpiderGL shadow map example
  11502. * http://spidergl.org/example.php?id=6
  11503. *
  11504. * originally from
  11505. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  11506. *
  11507. * see also
  11508. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  11509. */
  11510. 'depthRGBA': {
  11511. uniforms: {},
  11512. vertexShader: [
  11513. THREE.ShaderChunk[ "common" ],
  11514. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  11515. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  11516. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  11517. "void main() {",
  11518. THREE.ShaderChunk[ "skinbase_vertex" ],
  11519. THREE.ShaderChunk[ "morphtarget_vertex" ],
  11520. THREE.ShaderChunk[ "skinning_vertex" ],
  11521. THREE.ShaderChunk[ "default_vertex" ],
  11522. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  11523. "}"
  11524. ].join("\n"),
  11525. fragmentShader: [
  11526. THREE.ShaderChunk[ "common" ],
  11527. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  11528. "vec4 pack_depth( const in float depth ) {",
  11529. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  11530. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  11531. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  11532. " res -= res.xxyz * bit_mask;",
  11533. " return res;",
  11534. "}",
  11535. "void main() {",
  11536. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  11537. " #ifdef USE_LOGDEPTHBUF_EXT",
  11538. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  11539. " #else",
  11540. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  11541. " #endif",
  11542. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  11543. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  11544. //"gl_FragData[ 0 ] = pack_depth( z );",
  11545. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  11546. "}"
  11547. ].join("\n")
  11548. }
  11549. };
  11550. // File:src/renderers/WebGLRenderer.js
  11551. /**
  11552. * @author supereggbert / http://www.paulbrunt.co.uk/
  11553. * @author mrdoob / http://mrdoob.com/
  11554. * @author alteredq / http://alteredqualia.com/
  11555. * @author szimek / https://github.com/szimek/
  11556. */
  11557. THREE.WebGLRenderer = function ( parameters ) {
  11558. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  11559. parameters = parameters || {};
  11560. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  11561. _context = parameters.context !== undefined ? parameters.context : null,
  11562. _width = _canvas.width,
  11563. _height = _canvas.height,
  11564. pixelRatio = 1,
  11565. _precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  11566. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  11567. _depth = parameters.depth !== undefined ? parameters.depth : true,
  11568. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  11569. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  11570. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  11571. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  11572. _logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false,
  11573. _clearColor = new THREE.Color( 0x000000 ),
  11574. _clearAlpha = 0;
  11575. var lights = [];
  11576. var opaqueObjects = [];
  11577. var transparentObjects = [];
  11578. var opaqueImmediateObjects = [];
  11579. var transparentImmediateObjects = [];
  11580. var morphInfluences = new Float32Array( 8 );
  11581. var sprites = [];
  11582. var lensFlares = [];
  11583. // public properties
  11584. this.domElement = _canvas;
  11585. this.context = null;
  11586. // clearing
  11587. this.autoClear = true;
  11588. this.autoClearColor = true;
  11589. this.autoClearDepth = true;
  11590. this.autoClearStencil = true;
  11591. // scene graph
  11592. this.sortObjects = true;
  11593. // physically based shading
  11594. this.gammaFactor = 2.0; // for backwards compatibility
  11595. this.gammaInput = false;
  11596. this.gammaOutput = false;
  11597. // morphs
  11598. this.maxMorphTargets = 8;
  11599. this.maxMorphNormals = 4;
  11600. // flags
  11601. this.autoScaleCubemaps = true;
  11602. // internal properties
  11603. var _this = this,
  11604. _programs = [],
  11605. // internal state cache
  11606. _currentProgram = null,
  11607. _currentFramebuffer = null,
  11608. _currentMaterialId = - 1,
  11609. _currentGeometryProgram = '',
  11610. _currentCamera = null,
  11611. _usedTextureUnits = 0,
  11612. _viewportX = 0,
  11613. _viewportY = 0,
  11614. _viewportWidth = _canvas.width,
  11615. _viewportHeight = _canvas.height,
  11616. _currentWidth = 0,
  11617. _currentHeight = 0,
  11618. // frustum
  11619. _frustum = new THREE.Frustum(),
  11620. // camera matrices cache
  11621. _projScreenMatrix = new THREE.Matrix4(),
  11622. _vector3 = new THREE.Vector3(),
  11623. // light arrays cache
  11624. _direction = new THREE.Vector3(),
  11625. _lightsNeedUpdate = true,
  11626. _lights = {
  11627. ambient: [ 0, 0, 0 ],
  11628. directional: { length: 0, colors:[], positions: [] },
  11629. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  11630. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  11631. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  11632. },
  11633. // info
  11634. _infoMemory = {
  11635. programs: 0,
  11636. geometries: 0,
  11637. textures: 0
  11638. },
  11639. _infoRender = {
  11640. calls: 0,
  11641. vertices: 0,
  11642. faces: 0,
  11643. points: 0
  11644. };
  11645. this.info = {
  11646. render: _infoRender,
  11647. memory: _infoMemory,
  11648. programs: _programs
  11649. };
  11650. // initialize
  11651. var _gl;
  11652. try {
  11653. var attributes = {
  11654. alpha: _alpha,
  11655. depth: _depth,
  11656. stencil: _stencil,
  11657. antialias: _antialias,
  11658. premultipliedAlpha: _premultipliedAlpha,
  11659. preserveDrawingBuffer: _preserveDrawingBuffer
  11660. };
  11661. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  11662. if ( _gl === null ) {
  11663. if ( _canvas.getContext( 'webgl') !== null ) {
  11664. throw 'Error creating WebGL context with your selected attributes.';
  11665. } else {
  11666. throw 'Error creating WebGL context.';
  11667. }
  11668. }
  11669. _canvas.addEventListener( 'webglcontextlost', function ( event ) {
  11670. event.preventDefault();
  11671. resetGLState();
  11672. setDefaultGLState();
  11673. objects.clear();
  11674. properties.clear();
  11675. }, false );
  11676. } catch ( error ) {
  11677. console.error( 'THREE.WebGLRenderer: ' + error );
  11678. }
  11679. var state = new THREE.WebGLState( _gl, paramThreeToGL );
  11680. if ( _gl.getShaderPrecisionFormat === undefined ) {
  11681. _gl.getShaderPrecisionFormat = function () {
  11682. return {
  11683. 'rangeMin': 1,
  11684. 'rangeMax': 1,
  11685. 'precision': 1
  11686. };
  11687. }
  11688. }
  11689. var properties = new THREE.WebGLProperties();
  11690. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  11691. var extensions = new THREE.WebGLExtensions( _gl );
  11692. extensions.get( 'OES_texture_float' );
  11693. extensions.get( 'OES_texture_float_linear' );
  11694. extensions.get( 'OES_texture_half_float' );
  11695. extensions.get( 'OES_texture_half_float_linear' );
  11696. extensions.get( 'OES_standard_derivatives' );
  11697. extensions.get( 'ANGLE_instanced_arrays' );
  11698. if ( extensions.get( 'OES_element_index_uint' ) ) {
  11699. THREE.BufferGeometry.MaxIndex = 4294967296;
  11700. }
  11701. if ( _logarithmicDepthBuffer ) {
  11702. extensions.get( 'EXT_frag_depth' );
  11703. }
  11704. //
  11705. function glClearColor( r, g, b, a ) {
  11706. if ( _premultipliedAlpha === true ) {
  11707. r *= a; g *= a; b *= a;
  11708. }
  11709. _gl.clearColor( r, g, b, a );
  11710. }
  11711. function setDefaultGLState() {
  11712. state.init();
  11713. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11714. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11715. }
  11716. function resetGLState() {
  11717. _currentProgram = null;
  11718. _currentCamera = null;
  11719. _currentGeometryProgram = '';
  11720. _currentMaterialId = - 1;
  11721. _lightsNeedUpdate = true;
  11722. state.reset();
  11723. }
  11724. setDefaultGLState();
  11725. this.context = _gl;
  11726. this.extensions = extensions;
  11727. this.state = state;
  11728. // shadow map
  11729. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  11730. this.shadowMap = shadowMap;
  11731. // GPU capabilities
  11732. var _maxTextures = _gl.getParameter( _gl.MAX_TEXTURE_IMAGE_UNITS );
  11733. var _maxVertexTextures = _gl.getParameter( _gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  11734. var _maxTextureSize = _gl.getParameter( _gl.MAX_TEXTURE_SIZE );
  11735. var _maxCubemapSize = _gl.getParameter( _gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  11736. var _supportsVertexTextures = _maxVertexTextures > 0;
  11737. var _supportsBoneTextures = _supportsVertexTextures && extensions.get( 'OES_texture_float' );
  11738. var _supportsInstancedArrays = extensions.get( 'ANGLE_instanced_arrays' );
  11739. //
  11740. var _vertexShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.HIGH_FLOAT );
  11741. var _vertexShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.VERTEX_SHADER, _gl.MEDIUM_FLOAT );
  11742. var _fragmentShaderPrecisionHighpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.HIGH_FLOAT );
  11743. var _fragmentShaderPrecisionMediumpFloat = _gl.getShaderPrecisionFormat( _gl.FRAGMENT_SHADER, _gl.MEDIUM_FLOAT );
  11744. var getCompressedTextureFormats = ( function () {
  11745. var array;
  11746. return function getCompressedTextureFormats() {
  11747. if ( array !== undefined ) {
  11748. return array;
  11749. }
  11750. array = [];
  11751. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) || extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  11752. var formats = _gl.getParameter( _gl.COMPRESSED_TEXTURE_FORMATS );
  11753. for ( var i = 0; i < formats.length; i ++ ) {
  11754. array.push( formats[ i ] );
  11755. }
  11756. }
  11757. return array;
  11758. };
  11759. } )();
  11760. // clamp precision to maximum available
  11761. var highpAvailable = _vertexShaderPrecisionHighpFloat.precision > 0 && _fragmentShaderPrecisionHighpFloat.precision > 0;
  11762. var mediumpAvailable = _vertexShaderPrecisionMediumpFloat.precision > 0 && _fragmentShaderPrecisionMediumpFloat.precision > 0;
  11763. if ( _precision === 'highp' && ! highpAvailable ) {
  11764. if ( mediumpAvailable ) {
  11765. _precision = 'mediump';
  11766. console.warn( 'THREE.WebGLRenderer: highp not supported, using mediump.' );
  11767. } else {
  11768. _precision = 'lowp';
  11769. console.warn( 'THREE.WebGLRenderer: highp and mediump not supported, using lowp.' );
  11770. }
  11771. }
  11772. if ( _precision === 'mediump' && ! mediumpAvailable ) {
  11773. _precision = 'lowp';
  11774. console.warn( 'THREE.WebGLRenderer: mediump not supported, using lowp.' );
  11775. }
  11776. // Plugins
  11777. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  11778. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  11779. // API
  11780. this.getContext = function () {
  11781. return _gl;
  11782. };
  11783. this.getContextAttributes = function () {
  11784. return _gl.getContextAttributes();
  11785. };
  11786. this.forceContextLoss = function () {
  11787. extensions.get( 'WEBGL_lose_context' ).loseContext();
  11788. };
  11789. this.supportsVertexTextures = function () {
  11790. return _supportsVertexTextures;
  11791. };
  11792. this.supportsInstancedArrays = function () {
  11793. return _supportsInstancedArrays;
  11794. };
  11795. this.supportsFloatTextures = function () {
  11796. return extensions.get( 'OES_texture_float' );
  11797. };
  11798. this.supportsHalfFloatTextures = function () {
  11799. return extensions.get( 'OES_texture_half_float' );
  11800. };
  11801. this.supportsStandardDerivatives = function () {
  11802. return extensions.get( 'OES_standard_derivatives' );
  11803. };
  11804. this.supportsCompressedTextureS3TC = function () {
  11805. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  11806. };
  11807. this.supportsCompressedTexturePVRTC = function () {
  11808. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  11809. };
  11810. this.supportsBlendMinMax = function () {
  11811. return extensions.get( 'EXT_blend_minmax' );
  11812. };
  11813. this.getMaxAnisotropy = ( function () {
  11814. var value;
  11815. return function getMaxAnisotropy() {
  11816. if ( value !== undefined ) return value;
  11817. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  11818. if ( extension !== null ) {
  11819. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  11820. } else {
  11821. value = 0;
  11822. }
  11823. return value;
  11824. }
  11825. } )();
  11826. this.getPrecision = function () {
  11827. return _precision;
  11828. };
  11829. this.getPixelRatio = function () {
  11830. return pixelRatio;
  11831. };
  11832. this.setPixelRatio = function ( value ) {
  11833. if ( value !== undefined ) pixelRatio = value;
  11834. };
  11835. this.getSize = function () {
  11836. return {
  11837. width: _width,
  11838. height: _height
  11839. };
  11840. };
  11841. this.setSize = function ( width, height, updateStyle ) {
  11842. _width = width;
  11843. _height = height;
  11844. _canvas.width = width * pixelRatio;
  11845. _canvas.height = height * pixelRatio;
  11846. if ( updateStyle !== false ) {
  11847. _canvas.style.width = width + 'px';
  11848. _canvas.style.height = height + 'px';
  11849. }
  11850. this.setViewport( 0, 0, width, height );
  11851. };
  11852. this.setViewport = function ( x, y, width, height ) {
  11853. _viewportX = x * pixelRatio;
  11854. _viewportY = y * pixelRatio;
  11855. _viewportWidth = width * pixelRatio;
  11856. _viewportHeight = height * pixelRatio;
  11857. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  11858. };
  11859. this.setScissor = function ( x, y, width, height ) {
  11860. _gl.scissor(
  11861. x * pixelRatio,
  11862. y * pixelRatio,
  11863. width * pixelRatio,
  11864. height * pixelRatio
  11865. );
  11866. };
  11867. this.enableScissorTest = function ( boolean ) {
  11868. state.setScissorTest( boolean );
  11869. };
  11870. // Clearing
  11871. this.getClearColor = function () {
  11872. return _clearColor;
  11873. };
  11874. this.setClearColor = function ( color, alpha ) {
  11875. _clearColor.set( color );
  11876. _clearAlpha = alpha !== undefined ? alpha : 1;
  11877. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11878. };
  11879. this.getClearAlpha = function () {
  11880. return _clearAlpha;
  11881. };
  11882. this.setClearAlpha = function ( alpha ) {
  11883. _clearAlpha = alpha;
  11884. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  11885. };
  11886. this.clear = function ( color, depth, stencil ) {
  11887. var bits = 0;
  11888. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  11889. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  11890. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  11891. _gl.clear( bits );
  11892. };
  11893. this.clearColor = function () {
  11894. _gl.clear( _gl.COLOR_BUFFER_BIT );
  11895. };
  11896. this.clearDepth = function () {
  11897. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  11898. };
  11899. this.clearStencil = function () {
  11900. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  11901. };
  11902. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  11903. this.setRenderTarget( renderTarget );
  11904. this.clear( color, depth, stencil );
  11905. };
  11906. // Reset
  11907. this.resetGLState = resetGLState;
  11908. // Events
  11909. function onTextureDispose( event ) {
  11910. var texture = event.target;
  11911. texture.removeEventListener( 'dispose', onTextureDispose );
  11912. deallocateTexture( texture );
  11913. _infoMemory.textures --;
  11914. }
  11915. function onRenderTargetDispose( event ) {
  11916. var renderTarget = event.target;
  11917. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  11918. deallocateRenderTarget( renderTarget );
  11919. _infoMemory.textures --;
  11920. }
  11921. function onMaterialDispose( event ) {
  11922. var material = event.target;
  11923. material.removeEventListener( 'dispose', onMaterialDispose );
  11924. deallocateMaterial( material );
  11925. }
  11926. // Buffer deallocation
  11927. function deallocateTexture( texture ) {
  11928. var textureProperties = properties.get( texture );
  11929. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  11930. // cube texture
  11931. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  11932. } else {
  11933. // 2D texture
  11934. if ( textureProperties.__webglInit === undefined ) return;
  11935. _gl.deleteTexture( textureProperties.__webglTexture );
  11936. }
  11937. // remove all webgl properties
  11938. properties.delete( texture );
  11939. }
  11940. function deallocateRenderTarget( renderTarget ) {
  11941. var renderTargetProperties = properties.get( renderTarget );
  11942. if ( ! renderTarget || renderTargetProperties.__webglTexture === undefined ) return;
  11943. _gl.deleteTexture( renderTargetProperties.__webglTexture );
  11944. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  11945. for ( var i = 0; i < 6; i ++ ) {
  11946. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  11947. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  11948. }
  11949. } else {
  11950. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  11951. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  11952. }
  11953. properties.delete( renderTarget );
  11954. }
  11955. function deallocateMaterial( material ) {
  11956. releaseMaterialProgramReference( material );
  11957. properties.delete( material );
  11958. }
  11959. function releaseMaterialProgramReference( material ) {
  11960. var program = properties.get( material ).program.program;
  11961. if ( program === undefined ) return;
  11962. material.program = undefined;
  11963. for ( var i = 0, n = _programs.length; i !== n; ++ i ) {
  11964. var programInfo = _programs[ i ];
  11965. if ( programInfo.program === program ) {
  11966. var newReferenceCount = -- programInfo.usedTimes;
  11967. if ( newReferenceCount === 0 ) {
  11968. // the last meterial that has been using the program let
  11969. // go of it, so remove it from the (unordered) _programs
  11970. // set and deallocate the GL resource
  11971. var newLength = n - 1;
  11972. _programs[ i ] = _programs[ newLength ];
  11973. _programs.pop();
  11974. _gl.deleteProgram( program );
  11975. _infoMemory.programs = newLength;
  11976. }
  11977. break;
  11978. }
  11979. }
  11980. }
  11981. // Buffer rendering
  11982. this.renderBufferImmediate = function ( object, program, material ) {
  11983. state.initAttributes();
  11984. var objectProperties = properties.get( object );
  11985. if ( object.hasPositions && ! objectProperties.__webglVertexBuffer ) objectProperties.__webglVertexBuffer = _gl.createBuffer();
  11986. if ( object.hasNormals && ! objectProperties.__webglNormalBuffer ) objectProperties.__webglNormalBuffer = _gl.createBuffer();
  11987. if ( object.hasUvs && ! objectProperties.__webglUvBuffer ) objectProperties.__webglUvBuffer = _gl.createBuffer();
  11988. if ( object.hasColors && ! objectProperties.__webglColorBuffer ) objectProperties.__webglColorBuffer = _gl.createBuffer();
  11989. var attributes = program.getAttributes();
  11990. if ( object.hasPositions ) {
  11991. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglVertexBuffer );
  11992. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  11993. state.enableAttribute( attributes.position );
  11994. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  11995. }
  11996. if ( object.hasNormals ) {
  11997. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglNormalBuffer );
  11998. if ( material instanceof THREE.MeshPhongMaterial === false && material.shading === THREE.FlatShading ) {
  11999. var nx, ny, nz,
  12000. nax, nbx, ncx, nay, nby, ncy, naz, nbz, ncz,
  12001. normalArray,
  12002. i, il = object.count * 3;
  12003. for ( i = 0; i < il; i += 9 ) {
  12004. normalArray = object.normalArray;
  12005. nax = normalArray[ i ];
  12006. nay = normalArray[ i + 1 ];
  12007. naz = normalArray[ i + 2 ];
  12008. nbx = normalArray[ i + 3 ];
  12009. nby = normalArray[ i + 4 ];
  12010. nbz = normalArray[ i + 5 ];
  12011. ncx = normalArray[ i + 6 ];
  12012. ncy = normalArray[ i + 7 ];
  12013. ncz = normalArray[ i + 8 ];
  12014. nx = ( nax + nbx + ncx ) / 3;
  12015. ny = ( nay + nby + ncy ) / 3;
  12016. nz = ( naz + nbz + ncz ) / 3;
  12017. normalArray[ i ] = nx;
  12018. normalArray[ i + 1 ] = ny;
  12019. normalArray[ i + 2 ] = nz;
  12020. normalArray[ i + 3 ] = nx;
  12021. normalArray[ i + 4 ] = ny;
  12022. normalArray[ i + 5 ] = nz;
  12023. normalArray[ i + 6 ] = nx;
  12024. normalArray[ i + 7 ] = ny;
  12025. normalArray[ i + 8 ] = nz;
  12026. }
  12027. }
  12028. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  12029. state.enableAttribute( attributes.normal );
  12030. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  12031. }
  12032. if ( object.hasUvs && material.map ) {
  12033. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglUvBuffer );
  12034. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  12035. state.enableAttribute( attributes.uv );
  12036. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  12037. }
  12038. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  12039. _gl.bindBuffer( _gl.ARRAY_BUFFER, objectProperties.__webglColorBuffer );
  12040. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  12041. state.enableAttribute( attributes.color );
  12042. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  12043. }
  12044. state.disableUnusedAttributes();
  12045. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  12046. object.count = 0;
  12047. };
  12048. function setupVertexAttributes( material, program, geometry, startIndex ) {
  12049. var extension;
  12050. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12051. extension = extensions.get( 'ANGLE_instanced_arrays' );
  12052. if ( extension === null ) {
  12053. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12054. return;
  12055. }
  12056. }
  12057. var geometryAttributes = geometry.attributes;
  12058. var programAttributes = program.getAttributes();
  12059. var materialDefaultAttributeValues = material.defaultAttributeValues;
  12060. for ( var name in programAttributes ) {
  12061. var programAttribute = programAttributes[ name ];
  12062. if ( programAttribute >= 0 ) {
  12063. var geometryAttribute = geometryAttributes[ name ];
  12064. if ( geometryAttribute !== undefined ) {
  12065. var size = geometryAttribute.itemSize;
  12066. state.enableAttribute( programAttribute );
  12067. var buffer = objects.getAttributeBuffer(geometryAttribute);
  12068. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  12069. var data = geometryAttribute.data;
  12070. var stride = data.stride;
  12071. var offset = geometryAttribute.offset;
  12072. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12073. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  12074. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  12075. if ( extension === null ) {
  12076. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  12077. return;
  12078. }
  12079. extension.vertexAttribDivisorANGLE( programAttribute, data.meshPerAttribute );
  12080. if ( geometry.maxInstancedCount === undefined ) {
  12081. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  12082. }
  12083. }
  12084. } else {
  12085. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  12086. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  12087. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  12088. if ( extension === null ) {
  12089. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferAttribute but hardware does not support extension ANGLE_instanced_arrays.' );
  12090. return;
  12091. }
  12092. extension.vertexAttribDivisorANGLE( programAttribute, geometryAttribute.meshPerAttribute );
  12093. if ( geometry.maxInstancedCount === undefined ) {
  12094. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  12095. }
  12096. }
  12097. }
  12098. } else if ( materialDefaultAttributeValues !== undefined ) {
  12099. var value = materialDefaultAttributeValues[ name ];
  12100. if ( value !== undefined ) {
  12101. switch ( value.length ) {
  12102. case 2:
  12103. _gl.vertexAttrib2fv( programAttribute, value );
  12104. break;
  12105. case 3:
  12106. _gl.vertexAttrib3fv( programAttribute, value );
  12107. break;
  12108. case 4:
  12109. _gl.vertexAttrib4fv( programAttribute, value );
  12110. break;
  12111. default:
  12112. _gl.vertexAttrib1fv( programAttribute, value );
  12113. }
  12114. }
  12115. }
  12116. }
  12117. }
  12118. state.disableUnusedAttributes();
  12119. }
  12120. this.renderBufferDirect = function ( camera, lights, fog, material, object ) {
  12121. if ( material.visible === false ) return;
  12122. setMaterial( material );
  12123. var geometry = objects.geometries.get( object );
  12124. var program = setProgram( camera, lights, fog, material, object );
  12125. var updateBuffers = false,
  12126. wireframeBit = material.wireframe ? 1 : 0,
  12127. geometryProgram = geometry.id + '_' + program.id + '_' + wireframeBit;
  12128. if ( geometryProgram !== _currentGeometryProgram ) {
  12129. _currentGeometryProgram = geometryProgram;
  12130. updateBuffers = true;
  12131. }
  12132. if ( updateBuffers ) {
  12133. state.initAttributes();
  12134. }
  12135. // morph targets
  12136. if ( object.morphTargetInfluences !== undefined ) {
  12137. var activeInfluences = [];
  12138. var morphTargetInfluences = object.morphTargetInfluences;
  12139. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  12140. var influence = morphTargetInfluences[ i ];
  12141. activeInfluences.push( [ influence, i ] );
  12142. }
  12143. activeInfluences.sort( numericalSort );
  12144. if ( activeInfluences.length > 8 ) {
  12145. activeInfluences.length = 8;
  12146. }
  12147. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  12148. var influence = activeInfluences[ i ];
  12149. morphInfluences[ i ] = influence[ 0 ];
  12150. var attribute = geometry.morphAttributes[ influence[ 1 ] ];
  12151. objects.updateAttribute( attribute );
  12152. geometry.addAttribute( 'morphTarget' + i, attribute );
  12153. }
  12154. var uniforms = program.getUniforms();
  12155. if ( uniforms.morphTargetInfluences !== null ) {
  12156. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  12157. }
  12158. }
  12159. if ( object instanceof THREE.Mesh ) {
  12160. renderMesh( material, geometry, object, program, updateBuffers );
  12161. } else if ( object instanceof THREE.Line ) {
  12162. renderLine( material, geometry, object, program, updateBuffers );
  12163. } else if ( object instanceof THREE.PointCloud ) {
  12164. renderPointCloud( material, geometry, object, program, updateBuffers );
  12165. }
  12166. };
  12167. function renderMesh( material, geometry, object, program, updateBuffers ) {
  12168. var mode = _gl.TRIANGLES;
  12169. if ( material.wireframe === true ) {
  12170. mode = _gl.LINES;
  12171. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  12172. }
  12173. var index = geometry.attributes.index;
  12174. if ( index ) {
  12175. // indexed triangles
  12176. var type, size;
  12177. var indexBuffer = objects.getAttributeBuffer(index);
  12178. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12179. type = _gl.UNSIGNED_INT;
  12180. size = 4;
  12181. } else {
  12182. type = _gl.UNSIGNED_SHORT;
  12183. size = 2;
  12184. }
  12185. var offsets = geometry.drawcalls;
  12186. if ( offsets.length === 0 ) {
  12187. if ( updateBuffers ) {
  12188. setupVertexAttributes( material, program, geometry, 0 );
  12189. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12190. }
  12191. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12192. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12193. if ( extension === null ) {
  12194. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12195. return;
  12196. }
  12197. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount ); // Draw the instanced meshes
  12198. } else {
  12199. _gl.drawElements( mode, index.array.length, type, 0 );
  12200. }
  12201. _infoRender.calls ++;
  12202. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12203. _infoRender.faces += index.array.length / 3;
  12204. } else {
  12205. // if there is more than 1 chunk
  12206. // must set attribute pointers to use new offsets for each chunk
  12207. // even if geometry and materials didn't change
  12208. updateBuffers = true;
  12209. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12210. var startIndex = offsets[ i ].index;
  12211. if ( updateBuffers ) {
  12212. setupVertexAttributes( material, program, geometry, startIndex );
  12213. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12214. }
  12215. // render indexed triangles
  12216. if ( geometry instanceof THREE.InstancedBufferGeometry && offsets[i].instances > 0 ) {
  12217. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12218. if ( extension === null ) {
  12219. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12220. return;
  12221. }
  12222. extension.drawElementsInstancedANGLE( mode, offsets[i].count, type, offsets[i].start * size, offsets[i].count, type, offsets[i].instances ); // Draw the instanced meshes
  12223. } else {
  12224. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12225. }
  12226. _infoRender.calls ++;
  12227. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12228. _infoRender.faces += offsets[ i ].count / 3;
  12229. }
  12230. }
  12231. } else {
  12232. // non-indexed triangles
  12233. var offsets = geometry.drawcalls;
  12234. if ( offsets.length === 0 ) {
  12235. if ( updateBuffers ) {
  12236. setupVertexAttributes( material, program, geometry, 0 );
  12237. }
  12238. var position = geometry.attributes.position;
  12239. // render non-indexed triangles
  12240. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  12241. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  12242. if ( extension === null ) {
  12243. console.error( 'THREE.WebGLRenderer.renderMesh: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  12244. return;
  12245. }
  12246. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12247. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12248. } else {
  12249. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount ); // Draw the instanced meshes
  12250. }
  12251. } else {
  12252. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  12253. _gl.drawArrays( mode, 0, position.data.count );
  12254. } else {
  12255. _gl.drawArrays( mode, 0, position.count );
  12256. }
  12257. }
  12258. _infoRender.calls++;
  12259. _infoRender.vertices += position.count;
  12260. _infoRender.faces += position.array.length / 3;
  12261. } else {
  12262. // if there is more than 1 chunk
  12263. // must set attribute pointers to use new offsets for each chunk
  12264. // even if geometry and materials didn't change
  12265. if ( updateBuffers ) {
  12266. setupVertexAttributes( material, program, geometry, 0 );
  12267. }
  12268. for ( var i = 0, il = offsets.length; i < il; i++ ) {
  12269. // render non-indexed triangles
  12270. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  12271. console.error( 'THREE.WebGLRenderer.renderMesh: cannot use drawCalls with THREE.InstancedBufferGeometry.' );
  12272. return;
  12273. } else {
  12274. _gl.drawArrays( mode, offsets[ i ].start, offsets[ i ].count );
  12275. }
  12276. _infoRender.calls++;
  12277. _infoRender.vertices += offsets[ i ].count;
  12278. _infoRender.faces += ( offsets[ i ].count ) / 3;
  12279. }
  12280. }
  12281. }
  12282. }
  12283. function renderLine( material, geometry, object, program, updateBuffers ) {
  12284. var mode = object instanceof THREE.LineSegments ? _gl.LINES : _gl.LINE_STRIP;
  12285. // In case user is not using Line*Material by mistake
  12286. var lineWidth = material.linewidth !== undefined ? material.linewidth : 1;
  12287. state.setLineWidth( lineWidth * pixelRatio );
  12288. var index = geometry.attributes.index;
  12289. if ( index ) {
  12290. // indexed lines
  12291. var type, size;
  12292. var indexBuffer = objects.getAttributeBuffer(index);
  12293. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12294. type = _gl.UNSIGNED_INT;
  12295. size = 4;
  12296. } else {
  12297. type = _gl.UNSIGNED_SHORT;
  12298. size = 2;
  12299. }
  12300. var offsets = geometry.drawcalls;
  12301. if ( offsets.length === 0 ) {
  12302. if ( updateBuffers ) {
  12303. setupVertexAttributes( material, program, geometry, 0 );
  12304. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12305. }
  12306. _gl.drawElements( mode, index.array.length, type, 0 ); // 2 bytes per Uint16Array
  12307. _infoRender.calls ++;
  12308. _infoRender.vertices += index.array.length; // not really true, here vertices can be shared
  12309. } else {
  12310. // if there is more than 1 chunk
  12311. // must set attribute pointers to use new offsets for each chunk
  12312. // even if geometry and materials didn't change
  12313. if ( offsets.length > 1 ) updateBuffers = true;
  12314. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12315. var startIndex = offsets[ i ].index;
  12316. if ( updateBuffers ) {
  12317. setupVertexAttributes( material, program, geometry, startIndex );
  12318. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12319. }
  12320. // render indexed lines
  12321. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size ); // 2 bytes per Uint16Array
  12322. _infoRender.calls ++;
  12323. _infoRender.vertices += offsets[ i ].count; // not really true, here vertices can be shared
  12324. }
  12325. }
  12326. } else {
  12327. // non-indexed lines
  12328. if ( updateBuffers ) {
  12329. setupVertexAttributes( material, program, geometry, 0 );
  12330. }
  12331. var position = geometry.attributes.position;
  12332. var offsets = geometry.drawcalls;
  12333. if ( offsets.length === 0 ) {
  12334. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12335. _infoRender.calls ++;
  12336. _infoRender.vertices += position.array.length / 3;
  12337. } else {
  12338. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12339. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12340. _infoRender.calls ++;
  12341. _infoRender.vertices += offsets[ i ].count;
  12342. }
  12343. }
  12344. }
  12345. }
  12346. function renderPointCloud( material, geometry, object, program, updateBuffers ) {
  12347. var mode = _gl.POINTS;
  12348. var index = geometry.attributes.index;
  12349. if ( index ) {
  12350. // indexed points
  12351. var type, size;
  12352. var indexBuffer = objects.getAttributeBuffer( index );
  12353. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  12354. type = _gl.UNSIGNED_INT;
  12355. size = 4;
  12356. } else {
  12357. type = _gl.UNSIGNED_SHORT;
  12358. size = 2;
  12359. }
  12360. var offsets = geometry.drawcalls;
  12361. if ( offsets.length === 0 ) {
  12362. if ( updateBuffers ) {
  12363. setupVertexAttributes( material, program, geometry, 0 );
  12364. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12365. }
  12366. _gl.drawElements( mode, index.array.length, type, 0);
  12367. _infoRender.calls ++;
  12368. _infoRender.points += index.array.length;
  12369. } else {
  12370. // if there is more than 1 chunk
  12371. // must set attribute pointers to use new offsets for each chunk
  12372. // even if geometry and materials didn't change
  12373. if ( offsets.length > 1 ) updateBuffers = true;
  12374. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12375. var startIndex = offsets[ i ].index;
  12376. if ( updateBuffers ) {
  12377. setupVertexAttributes( material, program, geometry, startIndex );
  12378. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, indexBuffer );
  12379. }
  12380. // render indexed points
  12381. _gl.drawElements( mode, offsets[ i ].count, type, offsets[ i ].start * size );
  12382. _infoRender.calls ++;
  12383. _infoRender.points += offsets[ i ].count;
  12384. }
  12385. }
  12386. } else {
  12387. // non-indexed points
  12388. if ( updateBuffers ) {
  12389. setupVertexAttributes( material, program, geometry, 0 );
  12390. }
  12391. var position = geometry.attributes.position;
  12392. var offsets = geometry.drawcalls;
  12393. if ( offsets.length === 0 ) {
  12394. _gl.drawArrays( mode, 0, position.array.length / 3 );
  12395. _infoRender.calls ++;
  12396. _infoRender.points += position.array.length / 3;
  12397. } else {
  12398. for ( var i = 0, il = offsets.length; i < il; i ++ ) {
  12399. _gl.drawArrays( mode, offsets[ i ].index, offsets[ i ].count );
  12400. _infoRender.calls ++;
  12401. _infoRender.points += offsets[ i ].count;
  12402. }
  12403. }
  12404. }
  12405. }
  12406. // Sorting
  12407. function numericalSort ( a, b ) {
  12408. return b[ 0 ] - a[ 0 ];
  12409. }
  12410. function painterSortStable ( a, b ) {
  12411. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12412. return a.object.renderOrder - b.object.renderOrder;
  12413. } else if ( a.object.material.id !== b.object.material.id ) {
  12414. return a.object.material.id - b.object.material.id;
  12415. } else if ( a.z !== b.z ) {
  12416. return a.z - b.z;
  12417. } else {
  12418. return a.id - b.id;
  12419. }
  12420. }
  12421. function reversePainterSortStable ( a, b ) {
  12422. if ( a.object.renderOrder !== b.object.renderOrder ) {
  12423. return a.object.renderOrder - b.object.renderOrder;
  12424. } if ( a.z !== b.z ) {
  12425. return b.z - a.z;
  12426. } else {
  12427. return a.id - b.id;
  12428. }
  12429. }
  12430. // Rendering
  12431. this.render = function ( scene, camera, renderTarget, forceClear ) {
  12432. if ( camera instanceof THREE.Camera === false ) {
  12433. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  12434. return;
  12435. }
  12436. var fog = scene.fog;
  12437. // reset caching for this frame
  12438. _currentGeometryProgram = '';
  12439. _currentMaterialId = - 1;
  12440. _currentCamera = null;
  12441. _lightsNeedUpdate = true;
  12442. // update scene graph
  12443. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  12444. // update camera matrices and frustum
  12445. if ( camera.parent === undefined ) camera.updateMatrixWorld();
  12446. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  12447. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  12448. _frustum.setFromMatrix( _projScreenMatrix );
  12449. lights.length = 0;
  12450. opaqueObjects.length = 0;
  12451. transparentObjects.length = 0;
  12452. opaqueImmediateObjects.length = 0;
  12453. transparentImmediateObjects.length = 0;
  12454. sprites.length = 0;
  12455. lensFlares.length = 0;
  12456. projectObject( scene );
  12457. if ( _this.sortObjects === true ) {
  12458. opaqueObjects.sort( painterSortStable );
  12459. transparentObjects.sort( reversePainterSortStable );
  12460. }
  12461. objects.update( opaqueObjects );
  12462. objects.update( transparentObjects );
  12463. //
  12464. shadowMap.render( scene, camera );
  12465. //
  12466. _infoRender.calls = 0;
  12467. _infoRender.vertices = 0;
  12468. _infoRender.faces = 0;
  12469. _infoRender.points = 0;
  12470. this.setRenderTarget( renderTarget );
  12471. if ( this.autoClear || forceClear ) {
  12472. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  12473. }
  12474. //
  12475. if ( scene.overrideMaterial ) {
  12476. var overrideMaterial = scene.overrideMaterial;
  12477. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  12478. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  12479. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, overrideMaterial );
  12480. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, overrideMaterial );
  12481. } else {
  12482. // opaque pass (front-to-back order)
  12483. state.setBlending( THREE.NoBlending );
  12484. renderObjects( opaqueObjects, camera, lights, fog, null );
  12485. renderObjectsImmediate( opaqueImmediateObjects, camera, lights, fog, null );
  12486. // transparent pass (back-to-front order)
  12487. renderObjects( transparentObjects, camera, lights, fog, null );
  12488. renderObjectsImmediate( transparentImmediateObjects, camera, lights, fog, null );
  12489. }
  12490. // custom render plugins (post pass)
  12491. spritePlugin.render( scene, camera );
  12492. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  12493. // Generate mipmap if we're using any kind of mipmap filtering
  12494. if ( renderTarget && renderTarget.generateMipmaps && renderTarget.minFilter !== THREE.NearestFilter && renderTarget.minFilter !== THREE.LinearFilter ) {
  12495. updateRenderTargetMipmap( renderTarget );
  12496. }
  12497. // Ensure depth buffer writing is enabled so it can be cleared on next render
  12498. state.setDepthTest( true );
  12499. state.setDepthWrite( true );
  12500. state.setColorWrite( true );
  12501. // _gl.finish();
  12502. };
  12503. function projectObject( object ) {
  12504. if ( object.visible === true ) {
  12505. if ( object instanceof THREE.Scene || object instanceof THREE.Group ) {
  12506. // skip
  12507. } else {
  12508. // update Skeleton objects
  12509. if ( object instanceof THREE.SkinnedMesh ) {
  12510. object.skeleton.update();
  12511. }
  12512. objects.init( object );
  12513. if ( object instanceof THREE.Light ) {
  12514. lights.push( object );
  12515. } else if ( object instanceof THREE.Sprite ) {
  12516. sprites.push( object );
  12517. } else if ( object instanceof THREE.LensFlare ) {
  12518. lensFlares.push( object );
  12519. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  12520. var material = object.material;
  12521. if ( material.transparent ) {
  12522. transparentImmediateObjects.push( object );
  12523. } else {
  12524. opaqueImmediateObjects.push( object );
  12525. }
  12526. } else {
  12527. var webglObject = objects.objects[ object.id ];
  12528. if ( webglObject && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  12529. var material = object.material;
  12530. if ( properties.get( material ) ) {
  12531. material.program = properties.get( material ).program;
  12532. }
  12533. if ( material.transparent ) {
  12534. transparentObjects.push( webglObject );
  12535. } else {
  12536. opaqueObjects.push( webglObject );
  12537. }
  12538. if ( _this.sortObjects === true ) {
  12539. _vector3.setFromMatrixPosition( object.matrixWorld );
  12540. _vector3.applyProjection( _projScreenMatrix );
  12541. webglObject.z = _vector3.z;
  12542. }
  12543. }
  12544. }
  12545. }
  12546. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  12547. projectObject( object.children[ i ] );
  12548. }
  12549. }
  12550. }
  12551. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  12552. var material = overrideMaterial;
  12553. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12554. var webglObject = renderList[ i ];
  12555. var object = webglObject.object;
  12556. setupMatrices( object, camera );
  12557. if ( overrideMaterial === null ) material = object.material;
  12558. if ( material instanceof THREE.MeshFaceMaterial ) {
  12559. var materials = material.materials;
  12560. for ( var j = 0, jl = materials.length; j < jl; j ++ ) {
  12561. _this.renderBufferDirect( camera, lights, fog, materials[ j ], object );
  12562. }
  12563. continue;
  12564. }
  12565. _this.renderBufferDirect( camera, lights, fog, material, object );
  12566. }
  12567. }
  12568. function renderObjectsImmediate( renderList, camera, lights, fog, overrideMaterial ) {
  12569. var material = overrideMaterial;
  12570. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  12571. var object = renderList[ i ];
  12572. setupMatrices( object, camera );
  12573. if ( object.visible === true ) {
  12574. if ( overrideMaterial === null ) material = object.material;
  12575. _this.renderImmediateObject( camera, lights, fog, material, object );
  12576. }
  12577. }
  12578. }
  12579. this.renderImmediateObject = function ( camera, lights, fog, material, object ) {
  12580. setMaterial( material );
  12581. var program = setProgram( camera, lights, fog, material, object );
  12582. _currentGeometryProgram = '';
  12583. object.render( function ( object ) {
  12584. _this.renderBufferImmediate( object, program, material );
  12585. } );
  12586. };
  12587. // Materials
  12588. var shaderIDs = {
  12589. MeshDepthMaterial: 'depth',
  12590. MeshNormalMaterial: 'normal',
  12591. MeshBasicMaterial: 'basic',
  12592. MeshLambertMaterial: 'lambert',
  12593. MeshPhongMaterial: 'phong',
  12594. LineBasicMaterial: 'basic',
  12595. LineDashedMaterial: 'dashed',
  12596. PointCloudMaterial: 'particle_basic'
  12597. };
  12598. function initMaterial( material, lights, fog, object ) {
  12599. var materialProperties = properties.get( material );
  12600. var shaderID = shaderIDs[ material.type ];
  12601. // heuristics to create shader parameters according to lights in the scene
  12602. // (not to blow over maxLights budget)
  12603. var maxLightCount = allocateLights( lights );
  12604. var maxShadows = allocateShadows( lights );
  12605. var maxBones = allocateBones( object );
  12606. var parameters = {
  12607. precision: _precision,
  12608. supportsVertexTextures: _supportsVertexTextures,
  12609. map: !! material.map,
  12610. envMap: !! material.envMap,
  12611. envMapMode: material.envMap && material.envMap.mapping,
  12612. lightMap: !! material.lightMap,
  12613. aoMap: !! material.aoMap,
  12614. emissiveMap: !! material.emissiveMap,
  12615. bumpMap: !! material.bumpMap,
  12616. normalMap: !! material.normalMap,
  12617. specularMap: !! material.specularMap,
  12618. alphaMap: !! material.alphaMap,
  12619. combine: material.combine,
  12620. vertexColors: material.vertexColors,
  12621. fog: fog,
  12622. useFog: material.fog,
  12623. fogExp: fog instanceof THREE.FogExp2,
  12624. flatShading: material.shading === THREE.FlatShading,
  12625. sizeAttenuation: material.sizeAttenuation,
  12626. logarithmicDepthBuffer: _logarithmicDepthBuffer,
  12627. skinning: material.skinning,
  12628. maxBones: maxBones,
  12629. useVertexTexture: _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  12630. morphTargets: material.morphTargets,
  12631. morphNormals: material.morphNormals,
  12632. maxMorphTargets: _this.maxMorphTargets,
  12633. maxMorphNormals: _this.maxMorphNormals,
  12634. maxDirLights: maxLightCount.directional,
  12635. maxPointLights: maxLightCount.point,
  12636. maxSpotLights: maxLightCount.spot,
  12637. maxHemiLights: maxLightCount.hemi,
  12638. maxShadows: maxShadows,
  12639. shadowMapEnabled: shadowMap.enabled && object.receiveShadow && maxShadows > 0,
  12640. shadowMapType: shadowMap.type,
  12641. shadowMapDebug: shadowMap.debug,
  12642. shadowMapCascade: shadowMap.cascade,
  12643. alphaTest: material.alphaTest,
  12644. metal: material.metal,
  12645. doubleSided: material.side === THREE.DoubleSide,
  12646. flipSided: material.side === THREE.BackSide
  12647. };
  12648. // Generate code
  12649. var chunks = [];
  12650. if ( shaderID ) {
  12651. chunks.push( shaderID );
  12652. } else {
  12653. chunks.push( material.fragmentShader );
  12654. chunks.push( material.vertexShader );
  12655. }
  12656. if ( material.defines !== undefined ) {
  12657. for ( var name in material.defines ) {
  12658. chunks.push( name );
  12659. chunks.push( material.defines[ name ] );
  12660. }
  12661. }
  12662. for ( var name in parameters ) {
  12663. chunks.push( name );
  12664. chunks.push( parameters[ name ] );
  12665. }
  12666. var code = chunks.join();
  12667. var programChange = true;
  12668. if ( !materialProperties.program ) {
  12669. // new material
  12670. material.addEventListener( 'dispose', onMaterialDispose );
  12671. } else if ( materialProperties.program.code !== code ) {
  12672. // changed glsl or parameters
  12673. releaseMaterialProgramReference( material );
  12674. } else if ( shaderID !== undefined ) {
  12675. // same glsl and uniform list
  12676. return;
  12677. } else {
  12678. // only rebuild uniform list
  12679. programChange = false;
  12680. }
  12681. if ( shaderID ) {
  12682. var shader = THREE.ShaderLib[ shaderID ];
  12683. materialProperties.__webglShader = {
  12684. name: material.type,
  12685. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  12686. vertexShader: shader.vertexShader,
  12687. fragmentShader: shader.fragmentShader
  12688. };
  12689. } else {
  12690. materialProperties.__webglShader = {
  12691. name: material.type,
  12692. uniforms: material.uniforms,
  12693. vertexShader: material.vertexShader,
  12694. fragmentShader: material.fragmentShader
  12695. };
  12696. }
  12697. var program;
  12698. // Check if code has been already compiled
  12699. for ( var p = 0, pl = _programs.length; p < pl; p ++ ) {
  12700. var programInfo = _programs[ p ];
  12701. if ( programInfo.code === code ) {
  12702. program = programInfo;
  12703. if ( programChange ) {
  12704. program.usedTimes ++;
  12705. }
  12706. break;
  12707. }
  12708. }
  12709. if ( program === undefined ) {
  12710. material.__webglShader = materialProperties.__webglShader;
  12711. program = new THREE.WebGLProgram( _this, code, material, parameters );
  12712. _programs.push( program );
  12713. _infoMemory.programs = _programs.length;
  12714. }
  12715. materialProperties.program = program;
  12716. var attributes = program.getAttributes();
  12717. if ( material.morphTargets ) {
  12718. material.numSupportedMorphTargets = 0;
  12719. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  12720. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  12721. material.numSupportedMorphTargets ++;
  12722. }
  12723. }
  12724. }
  12725. if ( material.morphNormals ) {
  12726. material.numSupportedMorphNormals = 0;
  12727. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  12728. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  12729. material.numSupportedMorphNormals ++;
  12730. }
  12731. }
  12732. }
  12733. materialProperties.uniformsList = [];
  12734. var uniformLocations = materialProperties.program.getUniforms();
  12735. for ( var u in materialProperties.__webglShader.uniforms ) {
  12736. var location = uniformLocations[ u ];
  12737. if ( location ) {
  12738. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  12739. }
  12740. }
  12741. }
  12742. function setMaterial( material ) {
  12743. setMaterialFaces( material );
  12744. if ( material.transparent === true ) {
  12745. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  12746. } else {
  12747. state.setBlending( THREE.NoBlending );
  12748. }
  12749. state.setDepthFunc( material.depthFunc );
  12750. state.setDepthTest( material.depthTest );
  12751. state.setDepthWrite( material.depthWrite );
  12752. state.setColorWrite( material.colorWrite );
  12753. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  12754. }
  12755. function setMaterialFaces( material ) {
  12756. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  12757. state.setFlipSided( material.side === THREE.BackSide );
  12758. }
  12759. function setProgram( camera, lights, fog, material, object ) {
  12760. _usedTextureUnits = 0;
  12761. var materialProperties = properties.get( material );
  12762. if ( material.needsUpdate || ! materialProperties.program ) {
  12763. initMaterial( material, lights, fog, object );
  12764. material.needsUpdate = false;
  12765. }
  12766. var refreshProgram = false;
  12767. var refreshMaterial = false;
  12768. var refreshLights = false;
  12769. var program = materialProperties.program,
  12770. p_uniforms = program.getUniforms(),
  12771. m_uniforms = materialProperties.__webglShader.uniforms;
  12772. if ( program.id !== _currentProgram ) {
  12773. _gl.useProgram( program.program );
  12774. _currentProgram = program.id;
  12775. refreshProgram = true;
  12776. refreshMaterial = true;
  12777. refreshLights = true;
  12778. }
  12779. if ( material.id !== _currentMaterialId ) {
  12780. if ( _currentMaterialId === -1 ) refreshLights = true;
  12781. _currentMaterialId = material.id;
  12782. refreshMaterial = true;
  12783. }
  12784. if ( refreshProgram || camera !== _currentCamera ) {
  12785. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  12786. if ( _logarithmicDepthBuffer ) {
  12787. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  12788. }
  12789. if ( camera !== _currentCamera ) _currentCamera = camera;
  12790. // load material specific uniforms
  12791. // (shader material also gets them for the sake of genericity)
  12792. if ( material instanceof THREE.ShaderMaterial ||
  12793. material instanceof THREE.MeshPhongMaterial ||
  12794. material.envMap ) {
  12795. if ( p_uniforms.cameraPosition !== undefined ) {
  12796. _vector3.setFromMatrixPosition( camera.matrixWorld );
  12797. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  12798. }
  12799. }
  12800. if ( material instanceof THREE.MeshPhongMaterial ||
  12801. material instanceof THREE.MeshLambertMaterial ||
  12802. material instanceof THREE.MeshBasicMaterial ||
  12803. material instanceof THREE.ShaderMaterial ||
  12804. material.skinning ) {
  12805. if ( p_uniforms.viewMatrix !== undefined ) {
  12806. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  12807. }
  12808. }
  12809. }
  12810. // skinning uniforms must be set even if material didn't change
  12811. // auto-setting of texture unit for bone texture must go before other textures
  12812. // not sure why, but otherwise weird things happen
  12813. if ( material.skinning ) {
  12814. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  12815. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  12816. }
  12817. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  12818. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  12819. }
  12820. if ( _supportsBoneTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  12821. if ( p_uniforms.boneTexture !== undefined ) {
  12822. var textureUnit = getTextureUnit();
  12823. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  12824. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  12825. }
  12826. if ( p_uniforms.boneTextureWidth !== undefined ) {
  12827. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  12828. }
  12829. if ( p_uniforms.boneTextureHeight !== undefined ) {
  12830. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  12831. }
  12832. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  12833. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  12834. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  12835. }
  12836. }
  12837. }
  12838. if ( refreshMaterial ) {
  12839. // refresh uniforms common to several materials
  12840. if ( fog && material.fog ) {
  12841. refreshUniformsFog( m_uniforms, fog );
  12842. }
  12843. if ( material instanceof THREE.MeshPhongMaterial ||
  12844. material instanceof THREE.MeshLambertMaterial ||
  12845. material.lights ) {
  12846. if ( _lightsNeedUpdate ) {
  12847. refreshLights = true;
  12848. setupLights( lights );
  12849. _lightsNeedUpdate = false;
  12850. }
  12851. if ( refreshLights ) {
  12852. refreshUniformsLights( m_uniforms, _lights );
  12853. markUniformsLightsNeedsUpdate( m_uniforms, true );
  12854. } else {
  12855. markUniformsLightsNeedsUpdate( m_uniforms, false );
  12856. }
  12857. }
  12858. if ( material instanceof THREE.MeshBasicMaterial ||
  12859. material instanceof THREE.MeshLambertMaterial ||
  12860. material instanceof THREE.MeshPhongMaterial ) {
  12861. refreshUniformsCommon( m_uniforms, material );
  12862. }
  12863. // refresh single material specific uniforms
  12864. if ( material instanceof THREE.LineBasicMaterial ) {
  12865. refreshUniformsLine( m_uniforms, material );
  12866. } else if ( material instanceof THREE.LineDashedMaterial ) {
  12867. refreshUniformsLine( m_uniforms, material );
  12868. refreshUniformsDash( m_uniforms, material );
  12869. } else if ( material instanceof THREE.PointCloudMaterial ) {
  12870. refreshUniformsParticle( m_uniforms, material );
  12871. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  12872. refreshUniformsPhong( m_uniforms, material );
  12873. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  12874. refreshUniformsLambert( m_uniforms, material );
  12875. } else if ( material instanceof THREE.MeshBasicMaterial ) {
  12876. refreshUniformsBasic( m_uniforms, material );
  12877. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  12878. m_uniforms.mNear.value = camera.near;
  12879. m_uniforms.mFar.value = camera.far;
  12880. m_uniforms.opacity.value = material.opacity;
  12881. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  12882. m_uniforms.opacity.value = material.opacity;
  12883. }
  12884. if ( object.receiveShadow && ! material._shadowPass ) {
  12885. refreshUniformsShadow( m_uniforms, lights );
  12886. }
  12887. // load common uniforms
  12888. loadUniformsGeneric( materialProperties.uniformsList );
  12889. }
  12890. loadUniformsMatrices( p_uniforms, object );
  12891. if ( p_uniforms.modelMatrix !== undefined ) {
  12892. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  12893. }
  12894. return program;
  12895. }
  12896. // Uniforms (refresh uniforms objects)
  12897. function refreshUniformsCommon ( uniforms, material ) {
  12898. uniforms.opacity.value = material.opacity;
  12899. uniforms.diffuse.value = material.color;
  12900. uniforms.map.value = material.map;
  12901. uniforms.specularMap.value = material.specularMap;
  12902. uniforms.alphaMap.value = material.alphaMap;
  12903. if ( material.bumpMap ) {
  12904. uniforms.bumpMap.value = material.bumpMap;
  12905. uniforms.bumpScale.value = material.bumpScale;
  12906. }
  12907. if ( material.normalMap ) {
  12908. uniforms.normalMap.value = material.normalMap;
  12909. uniforms.normalScale.value.copy( material.normalScale );
  12910. }
  12911. // uv repeat and offset setting priorities
  12912. // 1. color map
  12913. // 2. specular map
  12914. // 3. normal map
  12915. // 4. bump map
  12916. // 5. alpha map
  12917. // 6. emissive map
  12918. var uvScaleMap;
  12919. if ( material.map ) {
  12920. uvScaleMap = material.map;
  12921. } else if ( material.specularMap ) {
  12922. uvScaleMap = material.specularMap;
  12923. } else if ( material.normalMap ) {
  12924. uvScaleMap = material.normalMap;
  12925. } else if ( material.bumpMap ) {
  12926. uvScaleMap = material.bumpMap;
  12927. } else if ( material.alphaMap ) {
  12928. uvScaleMap = material.alphaMap;
  12929. } else if ( material.emissiveMap ) {
  12930. uvScaleMap = material.emissiveMap;
  12931. }
  12932. if ( uvScaleMap !== undefined ) {
  12933. var offset = uvScaleMap.offset;
  12934. var repeat = uvScaleMap.repeat;
  12935. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  12936. }
  12937. uniforms.envMap.value = material.envMap;
  12938. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  12939. uniforms.reflectivity.value = material.reflectivity;
  12940. uniforms.refractionRatio.value = material.refractionRatio;
  12941. }
  12942. function refreshUniformsLine ( uniforms, material ) {
  12943. uniforms.diffuse.value = material.color;
  12944. uniforms.opacity.value = material.opacity;
  12945. }
  12946. function refreshUniformsDash ( uniforms, material ) {
  12947. uniforms.dashSize.value = material.dashSize;
  12948. uniforms.totalSize.value = material.dashSize + material.gapSize;
  12949. uniforms.scale.value = material.scale;
  12950. }
  12951. function refreshUniformsParticle ( uniforms, material ) {
  12952. uniforms.psColor.value = material.color;
  12953. uniforms.opacity.value = material.opacity;
  12954. uniforms.size.value = material.size;
  12955. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  12956. uniforms.map.value = material.map;
  12957. if ( material.map !== null ) {
  12958. var offset = material.map.offset;
  12959. var repeat = material.map.repeat;
  12960. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  12961. }
  12962. }
  12963. function refreshUniformsFog ( uniforms, fog ) {
  12964. uniforms.fogColor.value = fog.color;
  12965. if ( fog instanceof THREE.Fog ) {
  12966. uniforms.fogNear.value = fog.near;
  12967. uniforms.fogFar.value = fog.far;
  12968. } else if ( fog instanceof THREE.FogExp2 ) {
  12969. uniforms.fogDensity.value = fog.density;
  12970. }
  12971. }
  12972. function refreshUniformsPhong ( uniforms, material ) {
  12973. uniforms.shininess.value = material.shininess;
  12974. uniforms.emissive.value = material.emissive;
  12975. uniforms.specular.value = material.specular;
  12976. uniforms.lightMap.value = material.lightMap;
  12977. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  12978. uniforms.aoMap.value = material.aoMap;
  12979. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  12980. uniforms.emissiveMap.value = material.emissiveMap;
  12981. }
  12982. function refreshUniformsLambert ( uniforms, material ) {
  12983. uniforms.emissive.value = material.emissive;
  12984. }
  12985. function refreshUniformsBasic ( uniforms, material ) {
  12986. uniforms.aoMap.value = material.aoMap;
  12987. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  12988. }
  12989. function refreshUniformsLights ( uniforms, lights ) {
  12990. uniforms.ambientLightColor.value = lights.ambient;
  12991. uniforms.directionalLightColor.value = lights.directional.colors;
  12992. uniforms.directionalLightDirection.value = lights.directional.positions;
  12993. uniforms.pointLightColor.value = lights.point.colors;
  12994. uniforms.pointLightPosition.value = lights.point.positions;
  12995. uniforms.pointLightDistance.value = lights.point.distances;
  12996. uniforms.pointLightDecay.value = lights.point.decays;
  12997. uniforms.spotLightColor.value = lights.spot.colors;
  12998. uniforms.spotLightPosition.value = lights.spot.positions;
  12999. uniforms.spotLightDistance.value = lights.spot.distances;
  13000. uniforms.spotLightDirection.value = lights.spot.directions;
  13001. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  13002. uniforms.spotLightExponent.value = lights.spot.exponents;
  13003. uniforms.spotLightDecay.value = lights.spot.decays;
  13004. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  13005. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  13006. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  13007. }
  13008. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13009. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  13010. uniforms.ambientLightColor.needsUpdate = value;
  13011. uniforms.directionalLightColor.needsUpdate = value;
  13012. uniforms.directionalLightDirection.needsUpdate = value;
  13013. uniforms.pointLightColor.needsUpdate = value;
  13014. uniforms.pointLightPosition.needsUpdate = value;
  13015. uniforms.pointLightDistance.needsUpdate = value;
  13016. uniforms.pointLightDecay.needsUpdate = value;
  13017. uniforms.spotLightColor.needsUpdate = value;
  13018. uniforms.spotLightPosition.needsUpdate = value;
  13019. uniforms.spotLightDistance.needsUpdate = value;
  13020. uniforms.spotLightDirection.needsUpdate = value;
  13021. uniforms.spotLightAngleCos.needsUpdate = value;
  13022. uniforms.spotLightExponent.needsUpdate = value;
  13023. uniforms.spotLightDecay.needsUpdate = value;
  13024. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  13025. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  13026. uniforms.hemisphereLightDirection.needsUpdate = value;
  13027. }
  13028. function refreshUniformsShadow ( uniforms, lights ) {
  13029. if ( uniforms.shadowMatrix ) {
  13030. var j = 0;
  13031. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  13032. var light = lights[ i ];
  13033. if ( ! light.castShadow ) continue;
  13034. if ( light instanceof THREE.SpotLight || ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) ) {
  13035. uniforms.shadowMap.value[ j ] = light.shadowMap;
  13036. uniforms.shadowMapSize.value[ j ] = light.shadowMapSize;
  13037. uniforms.shadowMatrix.value[ j ] = light.shadowMatrix;
  13038. uniforms.shadowDarkness.value[ j ] = light.shadowDarkness;
  13039. uniforms.shadowBias.value[ j ] = light.shadowBias;
  13040. j ++;
  13041. }
  13042. }
  13043. }
  13044. }
  13045. // Uniforms (load to GPU)
  13046. function loadUniformsMatrices ( uniforms, object ) {
  13047. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object._modelViewMatrix.elements );
  13048. if ( uniforms.normalMatrix ) {
  13049. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object._normalMatrix.elements );
  13050. }
  13051. }
  13052. function getTextureUnit() {
  13053. var textureUnit = _usedTextureUnits;
  13054. if ( textureUnit >= _maxTextures ) {
  13055. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + _maxTextures );
  13056. }
  13057. _usedTextureUnits += 1;
  13058. return textureUnit;
  13059. }
  13060. function loadUniformsGeneric ( uniforms ) {
  13061. var texture, textureUnit, offset;
  13062. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  13063. var uniform = uniforms[ j ][ 0 ];
  13064. // needsUpdate property is not added to all uniforms.
  13065. if ( uniform.needsUpdate === false ) continue;
  13066. var type = uniform.type;
  13067. var value = uniform.value;
  13068. var location = uniforms[ j ][ 1 ];
  13069. switch ( type ) {
  13070. case '1i':
  13071. _gl.uniform1i( location, value );
  13072. break;
  13073. case '1f':
  13074. _gl.uniform1f( location, value );
  13075. break;
  13076. case '2f':
  13077. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  13078. break;
  13079. case '3f':
  13080. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  13081. break;
  13082. case '4f':
  13083. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  13084. break;
  13085. case '1iv':
  13086. _gl.uniform1iv( location, value );
  13087. break;
  13088. case '3iv':
  13089. _gl.uniform3iv( location, value );
  13090. break;
  13091. case '1fv':
  13092. _gl.uniform1fv( location, value );
  13093. break;
  13094. case '2fv':
  13095. _gl.uniform2fv( location, value );
  13096. break;
  13097. case '3fv':
  13098. _gl.uniform3fv( location, value );
  13099. break;
  13100. case '4fv':
  13101. _gl.uniform4fv( location, value );
  13102. break;
  13103. case 'Matrix3fv':
  13104. _gl.uniformMatrix3fv( location, false, value );
  13105. break;
  13106. case 'Matrix4fv':
  13107. _gl.uniformMatrix4fv( location, false, value );
  13108. break;
  13109. //
  13110. case 'i':
  13111. // single integer
  13112. _gl.uniform1i( location, value );
  13113. break;
  13114. case 'f':
  13115. // single float
  13116. _gl.uniform1f( location, value );
  13117. break;
  13118. case 'v2':
  13119. // single THREE.Vector2
  13120. _gl.uniform2f( location, value.x, value.y );
  13121. break;
  13122. case 'v3':
  13123. // single THREE.Vector3
  13124. _gl.uniform3f( location, value.x, value.y, value.z );
  13125. break;
  13126. case 'v4':
  13127. // single THREE.Vector4
  13128. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  13129. break;
  13130. case 'c':
  13131. // single THREE.Color
  13132. _gl.uniform3f( location, value.r, value.g, value.b );
  13133. break;
  13134. case 'iv1':
  13135. // flat array of integers (JS or typed array)
  13136. _gl.uniform1iv( location, value );
  13137. break;
  13138. case 'iv':
  13139. // flat array of integers with 3 x N size (JS or typed array)
  13140. _gl.uniform3iv( location, value );
  13141. break;
  13142. case 'fv1':
  13143. // flat array of floats (JS or typed array)
  13144. _gl.uniform1fv( location, value );
  13145. break;
  13146. case 'fv':
  13147. // flat array of floats with 3 x N size (JS or typed array)
  13148. _gl.uniform3fv( location, value );
  13149. break;
  13150. case 'v2v':
  13151. // array of THREE.Vector2
  13152. if ( uniform._array === undefined ) {
  13153. uniform._array = new Float32Array( 2 * value.length );
  13154. }
  13155. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13156. offset = i * 2;
  13157. uniform._array[ offset + 0 ] = value[ i ].x;
  13158. uniform._array[ offset + 1 ] = value[ i ].y;
  13159. }
  13160. _gl.uniform2fv( location, uniform._array );
  13161. break;
  13162. case 'v3v':
  13163. // array of THREE.Vector3
  13164. if ( uniform._array === undefined ) {
  13165. uniform._array = new Float32Array( 3 * value.length );
  13166. }
  13167. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13168. offset = i * 3;
  13169. uniform._array[ offset + 0 ] = value[ i ].x;
  13170. uniform._array[ offset + 1 ] = value[ i ].y;
  13171. uniform._array[ offset + 2 ] = value[ i ].z;
  13172. }
  13173. _gl.uniform3fv( location, uniform._array );
  13174. break;
  13175. case 'v4v':
  13176. // array of THREE.Vector4
  13177. if ( uniform._array === undefined ) {
  13178. uniform._array = new Float32Array( 4 * value.length );
  13179. }
  13180. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13181. offset = i * 4;
  13182. uniform._array[ offset + 0 ] = value[ i ].x;
  13183. uniform._array[ offset + 1 ] = value[ i ].y;
  13184. uniform._array[ offset + 2 ] = value[ i ].z;
  13185. uniform._array[ offset + 3 ] = value[ i ].w;
  13186. }
  13187. _gl.uniform4fv( location, uniform._array );
  13188. break;
  13189. case 'm3':
  13190. // single THREE.Matrix3
  13191. _gl.uniformMatrix3fv( location, false, value.elements );
  13192. break;
  13193. case 'm3v':
  13194. // array of THREE.Matrix3
  13195. if ( uniform._array === undefined ) {
  13196. uniform._array = new Float32Array( 9 * value.length );
  13197. }
  13198. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13199. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  13200. }
  13201. _gl.uniformMatrix3fv( location, false, uniform._array );
  13202. break;
  13203. case 'm4':
  13204. // single THREE.Matrix4
  13205. _gl.uniformMatrix4fv( location, false, value.elements );
  13206. break;
  13207. case 'm4v':
  13208. // array of THREE.Matrix4
  13209. if ( uniform._array === undefined ) {
  13210. uniform._array = new Float32Array( 16 * value.length );
  13211. }
  13212. for ( var i = 0, il = value.length; i < il; i ++ ) {
  13213. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  13214. }
  13215. _gl.uniformMatrix4fv( location, false, uniform._array );
  13216. break;
  13217. case 't':
  13218. // single THREE.Texture (2d or cube)
  13219. texture = value;
  13220. textureUnit = getTextureUnit();
  13221. _gl.uniform1i( location, textureUnit );
  13222. if ( ! texture ) continue;
  13223. if ( texture instanceof THREE.CubeTexture ||
  13224. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) { // CompressedTexture can have Array in image :/
  13225. setCubeTexture( texture, textureUnit );
  13226. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  13227. setCubeTextureDynamic( texture, textureUnit );
  13228. } else {
  13229. _this.setTexture( texture, textureUnit );
  13230. }
  13231. break;
  13232. case 'tv':
  13233. // array of THREE.Texture (2d)
  13234. if ( uniform._array === undefined ) {
  13235. uniform._array = [];
  13236. }
  13237. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13238. uniform._array[ i ] = getTextureUnit();
  13239. }
  13240. _gl.uniform1iv( location, uniform._array );
  13241. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  13242. texture = uniform.value[ i ];
  13243. textureUnit = uniform._array[ i ];
  13244. if ( ! texture ) continue;
  13245. _this.setTexture( texture, textureUnit );
  13246. }
  13247. break;
  13248. default:
  13249. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  13250. }
  13251. }
  13252. }
  13253. function setupMatrices( object, camera ) {
  13254. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13255. object._normalMatrix.getNormalMatrix( object._modelViewMatrix );
  13256. }
  13257. function setColorLinear( array, offset, color, intensity ) {
  13258. array[ offset + 0 ] = color.r * intensity;
  13259. array[ offset + 1 ] = color.g * intensity;
  13260. array[ offset + 2 ] = color.b * intensity;
  13261. }
  13262. function setupLights ( lights ) {
  13263. var l, ll, light,
  13264. r = 0, g = 0, b = 0,
  13265. color, skyColor, groundColor,
  13266. intensity,
  13267. distance,
  13268. zlights = _lights,
  13269. dirColors = zlights.directional.colors,
  13270. dirPositions = zlights.directional.positions,
  13271. pointColors = zlights.point.colors,
  13272. pointPositions = zlights.point.positions,
  13273. pointDistances = zlights.point.distances,
  13274. pointDecays = zlights.point.decays,
  13275. spotColors = zlights.spot.colors,
  13276. spotPositions = zlights.spot.positions,
  13277. spotDistances = zlights.spot.distances,
  13278. spotDirections = zlights.spot.directions,
  13279. spotAnglesCos = zlights.spot.anglesCos,
  13280. spotExponents = zlights.spot.exponents,
  13281. spotDecays = zlights.spot.decays,
  13282. hemiSkyColors = zlights.hemi.skyColors,
  13283. hemiGroundColors = zlights.hemi.groundColors,
  13284. hemiPositions = zlights.hemi.positions,
  13285. dirLength = 0,
  13286. pointLength = 0,
  13287. spotLength = 0,
  13288. hemiLength = 0,
  13289. dirCount = 0,
  13290. pointCount = 0,
  13291. spotCount = 0,
  13292. hemiCount = 0,
  13293. dirOffset = 0,
  13294. pointOffset = 0,
  13295. spotOffset = 0,
  13296. hemiOffset = 0;
  13297. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  13298. light = lights[ l ];
  13299. if ( light.onlyShadow ) continue;
  13300. color = light.color;
  13301. intensity = light.intensity;
  13302. distance = light.distance;
  13303. if ( light instanceof THREE.AmbientLight ) {
  13304. if ( ! light.visible ) continue;
  13305. r += color.r;
  13306. g += color.g;
  13307. b += color.b;
  13308. } else if ( light instanceof THREE.DirectionalLight ) {
  13309. dirCount += 1;
  13310. if ( ! light.visible ) continue;
  13311. _direction.setFromMatrixPosition( light.matrixWorld );
  13312. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13313. _direction.sub( _vector3 );
  13314. _direction.normalize();
  13315. dirOffset = dirLength * 3;
  13316. dirPositions[ dirOffset + 0 ] = _direction.x;
  13317. dirPositions[ dirOffset + 1 ] = _direction.y;
  13318. dirPositions[ dirOffset + 2 ] = _direction.z;
  13319. setColorLinear( dirColors, dirOffset, color, intensity );
  13320. dirLength += 1;
  13321. } else if ( light instanceof THREE.PointLight ) {
  13322. pointCount += 1;
  13323. if ( ! light.visible ) continue;
  13324. pointOffset = pointLength * 3;
  13325. setColorLinear( pointColors, pointOffset, color, intensity );
  13326. _vector3.setFromMatrixPosition( light.matrixWorld );
  13327. pointPositions[ pointOffset + 0 ] = _vector3.x;
  13328. pointPositions[ pointOffset + 1 ] = _vector3.y;
  13329. pointPositions[ pointOffset + 2 ] = _vector3.z;
  13330. // distance is 0 if decay is 0, because there is no attenuation at all.
  13331. pointDistances[ pointLength ] = distance;
  13332. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13333. pointLength += 1;
  13334. } else if ( light instanceof THREE.SpotLight ) {
  13335. spotCount += 1;
  13336. if ( ! light.visible ) continue;
  13337. spotOffset = spotLength * 3;
  13338. setColorLinear( spotColors, spotOffset, color, intensity );
  13339. _direction.setFromMatrixPosition( light.matrixWorld );
  13340. spotPositions[ spotOffset + 0 ] = _direction.x;
  13341. spotPositions[ spotOffset + 1 ] = _direction.y;
  13342. spotPositions[ spotOffset + 2 ] = _direction.z;
  13343. spotDistances[ spotLength ] = distance;
  13344. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  13345. _direction.sub( _vector3 );
  13346. _direction.normalize();
  13347. spotDirections[ spotOffset + 0 ] = _direction.x;
  13348. spotDirections[ spotOffset + 1 ] = _direction.y;
  13349. spotDirections[ spotOffset + 2 ] = _direction.z;
  13350. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  13351. spotExponents[ spotLength ] = light.exponent;
  13352. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  13353. spotLength += 1;
  13354. } else if ( light instanceof THREE.HemisphereLight ) {
  13355. hemiCount += 1;
  13356. if ( ! light.visible ) continue;
  13357. _direction.setFromMatrixPosition( light.matrixWorld );
  13358. _direction.normalize();
  13359. hemiOffset = hemiLength * 3;
  13360. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  13361. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  13362. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  13363. skyColor = light.color;
  13364. groundColor = light.groundColor;
  13365. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  13366. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  13367. hemiLength += 1;
  13368. }
  13369. }
  13370. // null eventual remains from removed lights
  13371. // (this is to avoid if in shader)
  13372. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  13373. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  13374. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  13375. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  13376. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  13377. zlights.directional.length = dirLength;
  13378. zlights.point.length = pointLength;
  13379. zlights.spot.length = spotLength;
  13380. zlights.hemi.length = hemiLength;
  13381. zlights.ambient[ 0 ] = r;
  13382. zlights.ambient[ 1 ] = g;
  13383. zlights.ambient[ 2 ] = b;
  13384. }
  13385. // GL state setting
  13386. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  13387. if ( cullFace === THREE.CullFaceNone ) {
  13388. state.disable( _gl.CULL_FACE );
  13389. } else {
  13390. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  13391. _gl.frontFace( _gl.CW );
  13392. } else {
  13393. _gl.frontFace( _gl.CCW );
  13394. }
  13395. if ( cullFace === THREE.CullFaceBack ) {
  13396. _gl.cullFace( _gl.BACK );
  13397. } else if ( cullFace === THREE.CullFaceFront ) {
  13398. _gl.cullFace( _gl.FRONT );
  13399. } else {
  13400. _gl.cullFace( _gl.FRONT_AND_BACK );
  13401. }
  13402. state.enable( _gl.CULL_FACE );
  13403. }
  13404. };
  13405. this.setMaterialFaces = setMaterialFaces;
  13406. // Textures
  13407. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  13408. var extension;
  13409. if ( isImagePowerOfTwo ) {
  13410. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  13411. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  13412. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  13413. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  13414. } else {
  13415. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  13416. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  13417. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  13418. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  13419. }
  13420. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  13421. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  13422. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13423. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  13424. }
  13425. }
  13426. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  13427. if ( extension && texture.type !== THREE.FloatType && texture.type !== THREE.HalfFloatType ) {
  13428. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  13429. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  13430. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  13431. }
  13432. }
  13433. }
  13434. function uploadTexture( textureProperties, texture, slot ) {
  13435. if ( textureProperties.__webglInit === undefined ) {
  13436. textureProperties.__webglInit = true;
  13437. texture.__webglInit = true;
  13438. texture.addEventListener( 'dispose', onTextureDispose );
  13439. textureProperties.__webglTexture = _gl.createTexture();
  13440. _infoMemory.textures ++;
  13441. }
  13442. state.activeTexture( _gl.TEXTURE0 + slot );
  13443. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13444. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13445. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  13446. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  13447. texture.image = clampToMaxSize( texture.image, _maxTextureSize );
  13448. var image = texture.image,
  13449. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13450. glFormat = paramThreeToGL( texture.format ),
  13451. glType = paramThreeToGL( texture.type );
  13452. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  13453. var mipmap, mipmaps = texture.mipmaps;
  13454. if ( texture instanceof THREE.DataTexture ) {
  13455. // use manually created mipmaps if available
  13456. // if there are no manual mipmaps
  13457. // set 0 level mipmap and then use GL to generate other mipmap levels
  13458. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13459. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13460. mipmap = mipmaps[ i ];
  13461. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13462. }
  13463. texture.generateMipmaps = false;
  13464. } else {
  13465. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  13466. }
  13467. } else if ( texture instanceof THREE.CompressedTexture ) {
  13468. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13469. mipmap = mipmaps[ i ];
  13470. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13471. if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
  13472. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13473. } else {
  13474. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  13475. }
  13476. } else {
  13477. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13478. }
  13479. }
  13480. } else { // regular Texture (image, video, canvas)
  13481. // use manually created mipmaps if available
  13482. // if there are no manual mipmaps
  13483. // set 0 level mipmap and then use GL to generate other mipmap levels
  13484. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  13485. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  13486. mipmap = mipmaps[ i ];
  13487. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  13488. }
  13489. texture.generateMipmaps = false;
  13490. } else {
  13491. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  13492. }
  13493. }
  13494. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13495. textureProperties.__version = texture.version;
  13496. if ( texture.onUpdate ) texture.onUpdate( texture );
  13497. }
  13498. this.setTexture = function ( texture, slot ) {
  13499. var textureProperties = properties.get( texture );
  13500. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13501. var image = texture.image;
  13502. if ( image === undefined ) {
  13503. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  13504. return;
  13505. }
  13506. if ( image.complete === false ) {
  13507. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  13508. return;
  13509. }
  13510. uploadTexture( textureProperties, texture, slot );
  13511. return;
  13512. }
  13513. state.activeTexture( _gl.TEXTURE0 + slot );
  13514. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  13515. };
  13516. function clampToMaxSize ( image, maxSize ) {
  13517. if ( image.width > maxSize || image.height > maxSize ) {
  13518. // Warning: Scaling through the canvas will only work with images that use
  13519. // premultiplied alpha.
  13520. var scale = maxSize / Math.max( image.width, image.height );
  13521. var canvas = document.createElement( 'canvas' );
  13522. canvas.width = Math.floor( image.width * scale );
  13523. canvas.height = Math.floor( image.height * scale );
  13524. var context = canvas.getContext( '2d' );
  13525. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  13526. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  13527. return canvas;
  13528. }
  13529. return image;
  13530. }
  13531. function setCubeTexture ( texture, slot ) {
  13532. var textureProperties = properties.get( texture );
  13533. if ( texture.image.length === 6 ) {
  13534. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  13535. if ( ! textureProperties.__image__webglTextureCube ) {
  13536. texture.addEventListener( 'dispose', onTextureDispose );
  13537. textureProperties.__image__webglTextureCube = _gl.createTexture();
  13538. _infoMemory.textures ++;
  13539. }
  13540. state.activeTexture( _gl.TEXTURE0 + slot );
  13541. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13542. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  13543. var isCompressed = texture instanceof THREE.CompressedTexture;
  13544. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  13545. var cubeImage = [];
  13546. for ( var i = 0; i < 6; i ++ ) {
  13547. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  13548. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], _maxCubemapSize );
  13549. } else {
  13550. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  13551. }
  13552. }
  13553. var image = cubeImage[ 0 ],
  13554. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  13555. glFormat = paramThreeToGL( texture.format ),
  13556. glType = paramThreeToGL( texture.type );
  13557. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  13558. for ( var i = 0; i < 6; i ++ ) {
  13559. if ( ! isCompressed ) {
  13560. if ( isDataTexture ) {
  13561. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  13562. } else {
  13563. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  13564. }
  13565. } else {
  13566. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  13567. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  13568. mipmap = mipmaps[ j ];
  13569. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  13570. if ( getCompressedTextureFormats().indexOf( glFormat ) > -1 ) {
  13571. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  13572. } else {
  13573. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  13574. }
  13575. } else {
  13576. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  13577. }
  13578. }
  13579. }
  13580. }
  13581. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  13582. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13583. }
  13584. textureProperties.__version = texture.version;
  13585. if ( texture.onUpdate ) texture.onUpdate( texture );
  13586. } else {
  13587. state.activeTexture( _gl.TEXTURE0 + slot );
  13588. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  13589. }
  13590. }
  13591. }
  13592. function setCubeTextureDynamic ( texture, slot ) {
  13593. state.activeTexture( _gl.TEXTURE0 + slot );
  13594. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  13595. }
  13596. // Render targets
  13597. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  13598. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13599. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget ).__webglTexture, 0 );
  13600. }
  13601. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  13602. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  13603. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13604. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  13605. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13606. /* For some reason this is not working. Defaulting to RGBA4.
  13607. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13608. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  13609. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13610. */
  13611. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13612. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  13613. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  13614. } else {
  13615. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  13616. }
  13617. }
  13618. this.setRenderTarget = function ( renderTarget ) {
  13619. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  13620. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  13621. var renderTargetProperties = properties.get( renderTarget );
  13622. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  13623. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  13624. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  13625. renderTargetProperties.__webglTexture = _gl.createTexture();
  13626. _infoMemory.textures ++;
  13627. // Setup texture, create render and frame buffers
  13628. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  13629. glFormat = paramThreeToGL( renderTarget.format ),
  13630. glType = paramThreeToGL( renderTarget.type );
  13631. if ( isCube ) {
  13632. renderTargetProperties.__webglFramebuffer = [];
  13633. renderTargetProperties.__webglRenderbuffer = [];
  13634. state.bindTexture( _gl.TEXTURE_CUBE_MAP, renderTargetProperties.__webglTexture );
  13635. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget, isTargetPowerOfTwo );
  13636. for ( var i = 0; i < 6; i ++ ) {
  13637. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  13638. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  13639. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13640. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  13641. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  13642. }
  13643. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13644. } else {
  13645. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  13646. if ( renderTarget.shareDepthFrom ) {
  13647. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  13648. } else {
  13649. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  13650. }
  13651. state.bindTexture( _gl.TEXTURE_2D, renderTargetProperties.__webglTexture );
  13652. setTextureParameters( _gl.TEXTURE_2D, renderTarget, isTargetPowerOfTwo );
  13653. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  13654. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  13655. if ( renderTarget.shareDepthFrom ) {
  13656. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  13657. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13658. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  13659. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  13660. }
  13661. } else {
  13662. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  13663. }
  13664. if ( renderTarget.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  13665. }
  13666. // Release everything
  13667. if ( isCube ) {
  13668. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13669. } else {
  13670. state.bindTexture( _gl.TEXTURE_2D, null );
  13671. }
  13672. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  13673. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  13674. }
  13675. var framebuffer, width, height, vx, vy;
  13676. if ( renderTarget ) {
  13677. var renderTargetProperties = properties.get( renderTarget );
  13678. if ( isCube ) {
  13679. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  13680. } else {
  13681. framebuffer = renderTargetProperties.__webglFramebuffer;
  13682. }
  13683. width = renderTarget.width;
  13684. height = renderTarget.height;
  13685. vx = 0;
  13686. vy = 0;
  13687. } else {
  13688. framebuffer = null;
  13689. width = _viewportWidth;
  13690. height = _viewportHeight;
  13691. vx = _viewportX;
  13692. vy = _viewportY;
  13693. }
  13694. if ( framebuffer !== _currentFramebuffer ) {
  13695. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  13696. _gl.viewport( vx, vy, width, height );
  13697. _currentFramebuffer = framebuffer;
  13698. }
  13699. _currentWidth = width;
  13700. _currentHeight = height;
  13701. };
  13702. this.readRenderTargetPixels = function( renderTarget, x, y, width, height, buffer ) {
  13703. if ( ! ( renderTarget instanceof THREE.WebGLRenderTarget ) ) {
  13704. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  13705. return;
  13706. }
  13707. if ( properties.get( renderTarget ).__webglFramebuffer ) {
  13708. if ( renderTarget.format !== THREE.RGBAFormat ) {
  13709. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA format. readPixels can read only RGBA format.' );
  13710. return;
  13711. }
  13712. var restore = false;
  13713. if ( properties.get( renderTarget ).__webglFramebuffer !== _currentFramebuffer ) {
  13714. _gl.bindFramebuffer( _gl.FRAMEBUFFER, properties.get( renderTarget ).__webglFramebuffer );
  13715. restore = true;
  13716. }
  13717. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  13718. _gl.readPixels( x, y, width, height, _gl.RGBA, _gl.UNSIGNED_BYTE, buffer );
  13719. } else {
  13720. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  13721. }
  13722. if ( restore ) {
  13723. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  13724. }
  13725. }
  13726. };
  13727. function updateRenderTargetMipmap ( renderTarget ) {
  13728. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13729. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( renderTarget ).__webglTexture );
  13730. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  13731. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  13732. } else {
  13733. state.bindTexture( _gl.TEXTURE_2D, properties.get( renderTarget ).__webglTexture );
  13734. _gl.generateMipmap( _gl.TEXTURE_2D );
  13735. state.bindTexture( _gl.TEXTURE_2D, null );
  13736. }
  13737. }
  13738. // Fallback filters for non-power-of-2 textures
  13739. function filterFallback ( f ) {
  13740. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  13741. return _gl.NEAREST;
  13742. }
  13743. return _gl.LINEAR;
  13744. }
  13745. // Map three.js constants to WebGL constants
  13746. function paramThreeToGL ( p ) {
  13747. var extension;
  13748. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  13749. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  13750. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  13751. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  13752. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  13753. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  13754. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  13755. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  13756. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  13757. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  13758. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  13759. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  13760. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  13761. if ( p === THREE.ByteType ) return _gl.BYTE;
  13762. if ( p === THREE.ShortType ) return _gl.SHORT;
  13763. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  13764. if ( p === THREE.IntType ) return _gl.INT;
  13765. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  13766. if ( p === THREE.FloatType ) return _gl.FLOAT;
  13767. extension = extensions.get( 'OES_texture_half_float' );
  13768. if ( extension !== null ) {
  13769. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  13770. }
  13771. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  13772. if ( p === THREE.RGBFormat ) return _gl.RGB;
  13773. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  13774. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  13775. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  13776. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  13777. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  13778. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  13779. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  13780. if ( p === THREE.OneFactor ) return _gl.ONE;
  13781. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  13782. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  13783. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  13784. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  13785. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  13786. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  13787. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  13788. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  13789. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  13790. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  13791. if ( extension !== null ) {
  13792. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  13793. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  13794. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  13795. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  13796. }
  13797. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  13798. if ( extension !== null ) {
  13799. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  13800. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  13801. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  13802. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  13803. }
  13804. extension = extensions.get( 'EXT_blend_minmax' );
  13805. if ( extension !== null ) {
  13806. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  13807. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  13808. }
  13809. return 0;
  13810. }
  13811. // Allocations
  13812. function allocateBones ( object ) {
  13813. if ( _supportsBoneTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  13814. return 1024;
  13815. } else {
  13816. // default for when object is not specified
  13817. // ( for example when prebuilding shader to be used with multiple objects )
  13818. //
  13819. // - leave some extra space for other uniforms
  13820. // - limit here is ANGLE's 254 max uniform vectors
  13821. // (up to 54 should be safe)
  13822. var nVertexUniforms = _gl.getParameter( _gl.MAX_VERTEX_UNIFORM_VECTORS );
  13823. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  13824. var maxBones = nVertexMatrices;
  13825. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  13826. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  13827. if ( maxBones < object.skeleton.bones.length ) {
  13828. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  13829. }
  13830. }
  13831. return maxBones;
  13832. }
  13833. }
  13834. function allocateLights( lights ) {
  13835. var dirLights = 0;
  13836. var pointLights = 0;
  13837. var spotLights = 0;
  13838. var hemiLights = 0;
  13839. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13840. var light = lights[ l ];
  13841. if ( light.onlyShadow || light.visible === false ) continue;
  13842. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  13843. if ( light instanceof THREE.PointLight ) pointLights ++;
  13844. if ( light instanceof THREE.SpotLight ) spotLights ++;
  13845. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  13846. }
  13847. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  13848. }
  13849. function allocateShadows( lights ) {
  13850. var maxShadows = 0;
  13851. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  13852. var light = lights[ l ];
  13853. if ( ! light.castShadow ) continue;
  13854. if ( light instanceof THREE.SpotLight ) maxShadows ++;
  13855. if ( light instanceof THREE.DirectionalLight && ! light.shadowCascade ) maxShadows ++;
  13856. }
  13857. return maxShadows;
  13858. }
  13859. // DEPRECATED
  13860. this.initMaterial = function () {
  13861. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  13862. };
  13863. this.addPrePlugin = function () {
  13864. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  13865. };
  13866. this.addPostPlugin = function () {
  13867. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  13868. };
  13869. this.updateShadowMap = function () {
  13870. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  13871. };
  13872. Object.defineProperties( this, {
  13873. shadowMapEnabled: {
  13874. get: function () {
  13875. return shadowMap.enabled;
  13876. },
  13877. set: function ( value ) {
  13878. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  13879. shadowMap.enabled = value;
  13880. }
  13881. },
  13882. shadowMapType: {
  13883. get: function () {
  13884. return shadowMap.type;
  13885. },
  13886. set: function ( value ) {
  13887. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  13888. shadowMap.type = value;
  13889. }
  13890. },
  13891. shadowMapCullFace: {
  13892. get: function () {
  13893. return shadowMap.cullFace;
  13894. },
  13895. set: function ( value ) {
  13896. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  13897. shadowMap.cullFace = value;
  13898. }
  13899. },
  13900. shadowMapDebug: {
  13901. get: function () {
  13902. return shadowMap.debug;
  13903. },
  13904. set: function ( value ) {
  13905. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  13906. shadowMap.debug = value;
  13907. }
  13908. },
  13909. shadowMapCascade: {
  13910. get: function () {
  13911. return shadowMap.cascade;
  13912. },
  13913. set: function ( value ) {
  13914. console.warn( 'THREE.WebGLRenderer: .shadowMapCascade is now .shadowMap.cascade.' );
  13915. shadowMap.cascade = value;
  13916. }
  13917. }
  13918. } );
  13919. };
  13920. // File:src/renderers/WebGLRenderTarget.js
  13921. /**
  13922. * @author szimek / https://github.com/szimek/
  13923. * @author alteredq / http://alteredqualia.com/
  13924. */
  13925. THREE.WebGLRenderTarget = function ( width, height, options ) {
  13926. this.uuid = THREE.Math.generateUUID();
  13927. this.width = width;
  13928. this.height = height;
  13929. options = options || {};
  13930. this.wrapS = options.wrapS !== undefined ? options.wrapS : THREE.ClampToEdgeWrapping;
  13931. this.wrapT = options.wrapT !== undefined ? options.wrapT : THREE.ClampToEdgeWrapping;
  13932. this.magFilter = options.magFilter !== undefined ? options.magFilter : THREE.LinearFilter;
  13933. this.minFilter = options.minFilter !== undefined ? options.minFilter : THREE.LinearMipMapLinearFilter;
  13934. this.anisotropy = options.anisotropy !== undefined ? options.anisotropy : 1;
  13935. this.offset = new THREE.Vector2( 0, 0 );
  13936. this.repeat = new THREE.Vector2( 1, 1 );
  13937. this.format = options.format !== undefined ? options.format : THREE.RGBAFormat;
  13938. this.type = options.type !== undefined ? options.type : THREE.UnsignedByteType;
  13939. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  13940. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  13941. this.generateMipmaps = true;
  13942. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  13943. };
  13944. THREE.WebGLRenderTarget.prototype = {
  13945. constructor: THREE.WebGLRenderTarget,
  13946. setSize: function ( width, height ) {
  13947. if ( this.width !== width || this.height !== height ) {
  13948. this.width = width;
  13949. this.height = height;
  13950. this.dispose();
  13951. }
  13952. },
  13953. clone: function () {
  13954. var tmp = new THREE.WebGLRenderTarget( this.width, this.height );
  13955. tmp.wrapS = this.wrapS;
  13956. tmp.wrapT = this.wrapT;
  13957. tmp.magFilter = this.magFilter;
  13958. tmp.minFilter = this.minFilter;
  13959. tmp.anisotropy = this.anisotropy;
  13960. tmp.offset.copy( this.offset );
  13961. tmp.repeat.copy( this.repeat );
  13962. tmp.format = this.format;
  13963. tmp.type = this.type;
  13964. tmp.depthBuffer = this.depthBuffer;
  13965. tmp.stencilBuffer = this.stencilBuffer;
  13966. tmp.generateMipmaps = this.generateMipmaps;
  13967. tmp.shareDepthFrom = this.shareDepthFrom;
  13968. return tmp;
  13969. },
  13970. dispose: function () {
  13971. this.dispatchEvent( { type: 'dispose' } );
  13972. }
  13973. };
  13974. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  13975. // File:src/renderers/WebGLRenderTargetCube.js
  13976. /**
  13977. * @author alteredq / http://alteredqualia.com
  13978. */
  13979. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  13980. THREE.WebGLRenderTarget.call( this, width, height, options );
  13981. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  13982. };
  13983. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  13984. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  13985. // File:src/renderers/webgl/WebGLExtensions.js
  13986. /**
  13987. * @author mrdoob / http://mrdoob.com/
  13988. */
  13989. THREE.WebGLExtensions = function ( gl ) {
  13990. var extensions = {};
  13991. this.get = function ( name ) {
  13992. if ( extensions[ name ] !== undefined ) {
  13993. return extensions[ name ];
  13994. }
  13995. var extension;
  13996. switch ( name ) {
  13997. case 'EXT_texture_filter_anisotropic':
  13998. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  13999. break;
  14000. case 'WEBGL_compressed_texture_s3tc':
  14001. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  14002. break;
  14003. case 'WEBGL_compressed_texture_pvrtc':
  14004. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  14005. break;
  14006. default:
  14007. extension = gl.getExtension( name );
  14008. }
  14009. if ( extension === null ) {
  14010. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  14011. }
  14012. extensions[ name ] = extension;
  14013. return extension;
  14014. };
  14015. };
  14016. // File:src/renderers/webgl/WebGLGeometries.js
  14017. /**
  14018. * @author mrdoob / http://mrdoob.com/
  14019. */
  14020. THREE.WebGLGeometries = function ( gl, properties, info ) {
  14021. var geometries = {};
  14022. this.get = function ( object ) {
  14023. var geometry = object.geometry;
  14024. if ( geometries[ geometry.id ] !== undefined ) {
  14025. return geometries[ geometry.id ];
  14026. }
  14027. geometry.addEventListener( 'dispose', onGeometryDispose );
  14028. if ( geometry instanceof THREE.BufferGeometry ) {
  14029. geometries[ geometry.id ] = geometry;
  14030. } else if ( geometry instanceof THREE.Geometry ) {
  14031. if ( object._bufferGeometry === undefined ) {
  14032. object._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  14033. }
  14034. geometries[ geometry.id ] = object._bufferGeometry;
  14035. }
  14036. info.memory.geometries ++;
  14037. return geometries[ geometry.id ];
  14038. };
  14039. function onGeometryDispose( event ) {
  14040. var geometry = event.target;
  14041. var buffergeometry = geometries[ geometry.id ];
  14042. for ( var name in buffergeometry.attributes ) {
  14043. var attribute = buffergeometry.attributes[ name ];
  14044. var buffer = getAttributeBuffer( attribute );
  14045. if ( buffer !== undefined ) {
  14046. gl.deleteBuffer( buffer );
  14047. removeAttributeBuffer( attribute );
  14048. }
  14049. }
  14050. geometry.removeEventListener( 'dispose', onGeometryDispose );
  14051. delete geometries[ geometry.id ];
  14052. info.memory.geometries --;
  14053. }
  14054. function getAttributeBuffer( attribute ) {
  14055. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14056. return properties.get( attribute.data ).__webglBuffer;
  14057. }
  14058. return properties.get( attribute ).__webglBuffer;
  14059. }
  14060. function removeAttributeBuffer( attribute ) {
  14061. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14062. properties.delete( attribute.data );
  14063. } else {
  14064. properties.delete( attribute );
  14065. }
  14066. }
  14067. };
  14068. // File:src/renderers/webgl/WebGLObjects.js
  14069. /**
  14070. * @author mrdoob / http://mrdoob.com/
  14071. */
  14072. THREE.WebGLObjects = function ( gl, properties, info ) {
  14073. var objects = {};
  14074. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  14075. //
  14076. function onObjectRemoved( event ) {
  14077. var object = event.target;
  14078. object.traverse( function ( child ) {
  14079. child.removeEventListener( 'remove', onObjectRemoved );
  14080. removeObject( child );
  14081. } );
  14082. }
  14083. function removeObject( object ) {
  14084. if ( object instanceof THREE.Mesh ||
  14085. object instanceof THREE.PointCloud ||
  14086. object instanceof THREE.Line ) {
  14087. delete objects[ object.id ];
  14088. }
  14089. delete object._modelViewMatrix;
  14090. delete object._normalMatrix;
  14091. properties.delete( object );
  14092. }
  14093. //
  14094. this.objects = objects;
  14095. this.geometries = geometries;
  14096. this.init = function ( object ) {
  14097. var objectProperties = properties.get( object );
  14098. if ( objectProperties.__webglInit === undefined ) {
  14099. objectProperties.__webglInit = true;
  14100. object._modelViewMatrix = new THREE.Matrix4();
  14101. object._normalMatrix = new THREE.Matrix3();
  14102. object.addEventListener( 'removed', onObjectRemoved );
  14103. }
  14104. if ( objectProperties.__webglActive === undefined ) {
  14105. objectProperties.__webglActive = true;
  14106. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.PointCloud ) {
  14107. objects[ object.id ] = {
  14108. id: object.id,
  14109. object: object,
  14110. z: 0
  14111. };
  14112. }
  14113. }
  14114. };
  14115. function updateObject( object ) {
  14116. var geometry = geometries.get( object );
  14117. if ( object.geometry instanceof THREE.Geometry ) {
  14118. geometry.updateFromObject( object );
  14119. }
  14120. //
  14121. var attributes = geometry.attributes;
  14122. for ( var name in attributes ) {
  14123. updateAttribute( attributes[ name ], name );
  14124. }
  14125. }
  14126. function updateAttribute( attribute, name ) {
  14127. var bufferType = ( name === 'index' ) ? gl.ELEMENT_ARRAY_BUFFER : gl.ARRAY_BUFFER;
  14128. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  14129. var attributeProperties = properties.get( data );
  14130. if ( attributeProperties.__webglBuffer === undefined ) {
  14131. createBuffer( attributeProperties, data, bufferType );
  14132. } else if ( attributeProperties.version !== data.version ) {
  14133. updateBuffer( attributeProperties, data, bufferType );
  14134. }
  14135. }
  14136. function createBuffer( attributeProperties, data, bufferType ) {
  14137. attributeProperties.__webglBuffer = gl.createBuffer();
  14138. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14139. var usage = gl.STATIC_DRAW;
  14140. if ( data instanceof THREE.DynamicBufferAttribute
  14141. || ( data instanceof THREE.InstancedBufferAttribute && data.dynamic === true )
  14142. || ( data instanceof THREE.InterleavedBuffer && data.dynamic === true ) ) {
  14143. usage = gl.DYNAMIC_DRAW;
  14144. }
  14145. gl.bufferData( bufferType, data.array, usage );
  14146. attributeProperties.version = data.version;
  14147. }
  14148. function updateBuffer( attributeProperties, data, bufferType ) {
  14149. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  14150. if ( data.updateRange === undefined || data.updateRange.count === -1 ) { // Not using update ranges
  14151. gl.bufferSubData( bufferType, 0, data.array );
  14152. } else if ( data.updateRange.count === 0 ) {
  14153. console.error( 'THREE.WebGLObjects.updateBuffer: using updateRange for THREE.DynamicBufferAttribute and marked as needsUpdate but count is 0, ensure you are using set methods or updating manually.' );
  14154. } else {
  14155. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  14156. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  14157. data.updateRange.count = 0; // reset range
  14158. }
  14159. attributeProperties.version = data.version;
  14160. }
  14161. // returns the webgl buffer for a specified attribute
  14162. this.getAttributeBuffer = function ( attribute ) {
  14163. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  14164. return properties.get( attribute.data ).__webglBuffer;
  14165. }
  14166. return properties.get( attribute ).__webglBuffer;
  14167. };
  14168. this.update = function ( renderList ) {
  14169. for ( var i = 0, ul = renderList.length; i < ul; i ++ ) {
  14170. var object = renderList[ i ].object;
  14171. if ( object.material.visible !== false ) {
  14172. updateObject( object );
  14173. }
  14174. }
  14175. };
  14176. this.updateAttribute = updateAttribute;
  14177. this.clear = function () {
  14178. objects = {};
  14179. };
  14180. };
  14181. // File:src/renderers/webgl/WebGLProgram.js
  14182. THREE.WebGLProgram = ( function () {
  14183. var programIdCount = 0;
  14184. function generateDefines( defines ) {
  14185. var chunks = [];
  14186. for ( var name in defines ) {
  14187. var value = defines[ name ];
  14188. if ( value === false ) continue;
  14189. chunks.push( '#define ' + name + ' ' + value );
  14190. }
  14191. return chunks.join( '\n' );
  14192. }
  14193. function fetchUniformLocations( gl, program, identifiers ) {
  14194. var uniforms = {};
  14195. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  14196. for ( var i = 0; i < n; i ++ ) {
  14197. var info = gl.getActiveUniform( program , i );
  14198. var name = info.name;
  14199. var location = gl.getUniformLocation( program, name );
  14200. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  14201. var suffixPos = name.lastIndexOf( '[0]' );
  14202. if ( suffixPos !== -1 && suffixPos === name.length - 3 ) {
  14203. uniforms[ name.substr( 0, suffixPos ) ] = location;
  14204. }
  14205. uniforms[ name ] = location;
  14206. }
  14207. return uniforms;
  14208. }
  14209. function fetchAttributeLocations( gl, program, identifiers ) {
  14210. var attributes = {};
  14211. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  14212. for ( var i = 0; i < n; i ++ ) {
  14213. var info = gl.getActiveAttrib( program , i );
  14214. var name = info.name;
  14215. //console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name);
  14216. attributes[ name ] = gl.getAttribLocation( program, name );
  14217. }
  14218. return attributes;
  14219. }
  14220. function filterEmptyLine( string ) {
  14221. return string !== '';
  14222. }
  14223. return function WebGLProgram( renderer, code, material, parameters ) {
  14224. var gl = renderer.context;
  14225. var defines = material.defines;
  14226. var vertexShader = material.__webglShader.vertexShader;
  14227. var fragmentShader = material.__webglShader.fragmentShader;
  14228. var index0AttributeName = material.index0AttributeName;
  14229. /*
  14230. if ( index0AttributeName === undefined && parameters.morphTargets === true ) {
  14231. // programs with morphTargets displace position out of attribute 0
  14232. index0AttributeName = 'position';
  14233. }
  14234. */
  14235. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  14236. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  14237. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  14238. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  14239. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  14240. }
  14241. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14242. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  14243. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14244. if ( parameters.envMap ) {
  14245. switch ( material.envMap.mapping ) {
  14246. case THREE.CubeReflectionMapping:
  14247. case THREE.CubeRefractionMapping:
  14248. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  14249. break;
  14250. case THREE.EquirectangularReflectionMapping:
  14251. case THREE.EquirectangularRefractionMapping:
  14252. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  14253. break;
  14254. case THREE.SphericalReflectionMapping:
  14255. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  14256. break;
  14257. }
  14258. switch ( material.envMap.mapping ) {
  14259. case THREE.CubeRefractionMapping:
  14260. case THREE.EquirectangularRefractionMapping:
  14261. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  14262. break;
  14263. }
  14264. switch ( material.combine ) {
  14265. case THREE.MultiplyOperation:
  14266. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  14267. break;
  14268. case THREE.MixOperation:
  14269. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  14270. break;
  14271. case THREE.AddOperation:
  14272. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  14273. break;
  14274. }
  14275. }
  14276. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  14277. // console.log( 'building new program ' );
  14278. //
  14279. var customDefines = generateDefines( defines );
  14280. //
  14281. var program = gl.createProgram();
  14282. var prefixVertex, prefixFragment;
  14283. if ( material instanceof THREE.RawShaderMaterial ) {
  14284. prefixVertex = '';
  14285. prefixFragment = '';
  14286. } else {
  14287. prefixVertex = [
  14288. 'precision ' + parameters.precision + ' float;',
  14289. 'precision ' + parameters.precision + ' int;',
  14290. '#define SHADER_NAME ' + material.__webglShader.name,
  14291. customDefines,
  14292. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  14293. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14294. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14295. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14296. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14297. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14298. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14299. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14300. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14301. '#define MAX_BONES ' + parameters.maxBones,
  14302. parameters.map ? '#define USE_MAP' : '',
  14303. parameters.envMap ? '#define USE_ENVMAP' : '',
  14304. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14305. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14306. parameters.aoMap ? '#define USE_AOMAP' : '',
  14307. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14308. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14309. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14310. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14311. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14312. parameters.vertexColors ? '#define USE_COLOR' : '',
  14313. parameters.flatShading ? '#define FLAT_SHADED': '',
  14314. parameters.skinning ? '#define USE_SKINNING' : '',
  14315. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  14316. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  14317. parameters.morphNormals ? '#define USE_MORPHNORMALS' : '',
  14318. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14319. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14320. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14321. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14322. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14323. parameters.shadowMapCascade ? '#define SHADOWMAP_CASCADE' : '',
  14324. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  14325. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14326. parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14327. 'uniform mat4 modelMatrix;',
  14328. 'uniform mat4 modelViewMatrix;',
  14329. 'uniform mat4 projectionMatrix;',
  14330. 'uniform mat4 viewMatrix;',
  14331. 'uniform mat3 normalMatrix;',
  14332. 'uniform vec3 cameraPosition;',
  14333. 'attribute vec3 position;',
  14334. 'attribute vec3 normal;',
  14335. 'attribute vec2 uv;',
  14336. '#ifdef USE_COLOR',
  14337. ' attribute vec3 color;',
  14338. '#endif',
  14339. '#ifdef USE_MORPHTARGETS',
  14340. ' attribute vec3 morphTarget0;',
  14341. ' attribute vec3 morphTarget1;',
  14342. ' attribute vec3 morphTarget2;',
  14343. ' attribute vec3 morphTarget3;',
  14344. ' #ifdef USE_MORPHNORMALS',
  14345. ' attribute vec3 morphNormal0;',
  14346. ' attribute vec3 morphNormal1;',
  14347. ' attribute vec3 morphNormal2;',
  14348. ' attribute vec3 morphNormal3;',
  14349. ' #else',
  14350. ' attribute vec3 morphTarget4;',
  14351. ' attribute vec3 morphTarget5;',
  14352. ' attribute vec3 morphTarget6;',
  14353. ' attribute vec3 morphTarget7;',
  14354. ' #endif',
  14355. '#endif',
  14356. '#ifdef USE_SKINNING',
  14357. ' attribute vec4 skinIndex;',
  14358. ' attribute vec4 skinWeight;',
  14359. '#endif',
  14360. '\n'
  14361. ].filter( filterEmptyLine ).join( '\n' );
  14362. prefixFragment = [
  14363. ( parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  14364. 'precision ' + parameters.precision + ' float;',
  14365. 'precision ' + parameters.precision + ' int;',
  14366. '#define SHADER_NAME ' + material.__webglShader.name,
  14367. customDefines,
  14368. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  14369. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  14370. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  14371. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  14372. '#define MAX_SHADOWS ' + parameters.maxShadows,
  14373. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  14374. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  14375. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  14376. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  14377. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  14378. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  14379. parameters.map ? '#define USE_MAP' : '',
  14380. parameters.envMap ? '#define USE_ENVMAP' : '',
  14381. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  14382. parameters.envMap ? '#define ' + envMapModeDefine : '',
  14383. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  14384. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  14385. parameters.aoMap ? '#define USE_AOMAP' : '',
  14386. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  14387. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  14388. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  14389. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  14390. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  14391. parameters.vertexColors ? '#define USE_COLOR' : '',
  14392. parameters.flatShading ? '#define FLAT_SHADED': '',
  14393. parameters.metal ? '#define METAL' : '',
  14394. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  14395. parameters.flipSided ? '#define FLIP_SIDED' : '',
  14396. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  14397. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  14398. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  14399. parameters.shadowMapCascade ? '#define SHADOWMAP_CASCADE' : '',
  14400. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  14401. parameters.logarithmicDepthBuffer && renderer.extensions.get('EXT_frag_depth') ? '#define USE_LOGDEPTHBUF_EXT' : '',
  14402. 'uniform mat4 viewMatrix;',
  14403. 'uniform vec3 cameraPosition;',
  14404. '\n'
  14405. ].filter( filterEmptyLine ).join( '\n' );
  14406. }
  14407. var vertexGlsl = prefixVertex + vertexShader;
  14408. var fragmentGlsl = prefixFragment + fragmentShader;
  14409. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  14410. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  14411. gl.attachShader( program, glVertexShader );
  14412. gl.attachShader( program, glFragmentShader );
  14413. if ( index0AttributeName !== undefined ) {
  14414. // Force a particular attribute to index 0.
  14415. // because potentially expensive emulation is done by browser if attribute 0 is disabled.
  14416. // And, color, for example is often automatically bound to index 0 so disabling it
  14417. gl.bindAttribLocation( program, 0, index0AttributeName );
  14418. }
  14419. gl.linkProgram( program );
  14420. var programLog = gl.getProgramInfoLog( program );
  14421. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  14422. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  14423. var runnable = true;
  14424. var haveDiagnostics = true;
  14425. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  14426. runnable = false;
  14427. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  14428. } else if ( programLog !== '' ) {
  14429. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  14430. } else if ( vertexLog === '' || fragmentLog === '' ) {
  14431. haveDiagnostics = false;
  14432. }
  14433. if ( haveDiagnostics ) {
  14434. this.diagnostics = {
  14435. runnable: runnable,
  14436. material: material,
  14437. programLog: programLog,
  14438. vertexShader: {
  14439. log: vertexLog,
  14440. prefix: prefixVertex
  14441. },
  14442. fragmentShader: {
  14443. log: fragmentLog,
  14444. prefix: prefixFragment
  14445. }
  14446. };
  14447. }
  14448. // clean up
  14449. gl.deleteShader( glVertexShader );
  14450. gl.deleteShader( glFragmentShader );
  14451. // set up caching for uniform locations
  14452. var cachedUniforms;
  14453. this.getUniforms = function() {
  14454. if ( cachedUniforms === undefined ) {
  14455. cachedUniforms = fetchUniformLocations( gl, program );
  14456. }
  14457. return cachedUniforms;
  14458. };
  14459. // set up caching for attribute locations
  14460. var cachedAttributes;
  14461. this.getAttributes = function() {
  14462. if ( cachedAttributes === undefined ) {
  14463. cachedAttributes = fetchAttributeLocations( gl, program );
  14464. }
  14465. return cachedAttributes;
  14466. };
  14467. // DEPRECATED
  14468. Object.defineProperties( this, {
  14469. uniforms: {
  14470. get: function() {
  14471. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  14472. return this.getUniforms();
  14473. }
  14474. },
  14475. attributes: {
  14476. get: function() {
  14477. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  14478. return this.getAttributes();
  14479. }
  14480. }
  14481. });
  14482. //
  14483. this.id = programIdCount ++;
  14484. this.code = code;
  14485. this.usedTimes = 1;
  14486. this.program = program;
  14487. this.vertexShader = glVertexShader;
  14488. this.fragmentShader = glFragmentShader;
  14489. return this;
  14490. };
  14491. } )();
  14492. // File:src/renderers/webgl/WebGLProperties.js
  14493. /**
  14494. * @author fordacious / fordacious.github.io
  14495. */
  14496. THREE.WebGLProperties = function () {
  14497. var properties = {};
  14498. this.get = function ( object ) {
  14499. var uuid = object.uuid;
  14500. var map = properties[ uuid ];
  14501. if ( map === undefined ) {
  14502. map = {};
  14503. properties[ uuid ] = map;
  14504. }
  14505. return map;
  14506. };
  14507. this.delete = function ( object ) {
  14508. delete properties[ object.uuid ];
  14509. };
  14510. this.clear = function () {
  14511. properties = {};
  14512. };
  14513. };
  14514. // File:src/renderers/webgl/WebGLShader.js
  14515. THREE.WebGLShader = ( function () {
  14516. var addLineNumbers = function ( string ) {
  14517. var lines = string.split( '\n' );
  14518. for ( var i = 0; i < lines.length; i ++ ) {
  14519. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  14520. }
  14521. return lines.join( '\n' );
  14522. };
  14523. return function WebGLShader( gl, type, string ) {
  14524. var shader = gl.createShader( type );
  14525. gl.shaderSource( shader, string );
  14526. gl.compileShader( shader );
  14527. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  14528. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  14529. }
  14530. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  14531. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  14532. }
  14533. // --enable-privileged-webgl-extension
  14534. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  14535. return shader;
  14536. };
  14537. } )();
  14538. // File:src/renderers/webgl/WebGLShadowMap.js
  14539. /**
  14540. * @author alteredq / http://alteredqualia.com/
  14541. * @author mrdoob / http://mrdoob.com/
  14542. */
  14543. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  14544. var _gl = _renderer.context,
  14545. _state = _renderer.state,
  14546. _frustum = new THREE.Frustum(),
  14547. _projScreenMatrix = new THREE.Matrix4(),
  14548. _min = new THREE.Vector3(),
  14549. _max = new THREE.Vector3(),
  14550. _matrixPosition = new THREE.Vector3(),
  14551. _renderList = [];
  14552. // init
  14553. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  14554. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  14555. var _depthMaterial = new THREE.ShaderMaterial( {
  14556. uniforms: depthUniforms,
  14557. vertexShader: depthShader.vertexShader,
  14558. fragmentShader: depthShader.fragmentShader
  14559. } );
  14560. var _depthMaterialMorph = new THREE.ShaderMaterial( {
  14561. uniforms: depthUniforms,
  14562. vertexShader: depthShader.vertexShader,
  14563. fragmentShader: depthShader.fragmentShader,
  14564. morphTargets: true
  14565. } );
  14566. var _depthMaterialSkin = new THREE.ShaderMaterial( {
  14567. uniforms: depthUniforms,
  14568. vertexShader: depthShader.vertexShader,
  14569. fragmentShader: depthShader.fragmentShader,
  14570. skinning: true
  14571. } );
  14572. var _depthMaterialMorphSkin = new THREE.ShaderMaterial( {
  14573. uniforms: depthUniforms,
  14574. vertexShader: depthShader.vertexShader,
  14575. fragmentShader: depthShader.fragmentShader,
  14576. morphTargets: true,
  14577. skinning: true
  14578. } );
  14579. _depthMaterial._shadowPass = true;
  14580. _depthMaterialMorph._shadowPass = true;
  14581. _depthMaterialSkin._shadowPass = true;
  14582. _depthMaterialMorphSkin._shadowPass = true;
  14583. //
  14584. var scope = this;
  14585. this.enabled = false;
  14586. this.autoUpdate = true;
  14587. this.needsUpdate = false;
  14588. this.type = THREE.PCFShadowMap;
  14589. this.cullFace = THREE.CullFaceFront;
  14590. this.cascade = false;
  14591. this.render = function ( scene, camera ) {
  14592. if ( scope.enabled === false ) return;
  14593. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  14594. var i, il, j, jl, n,
  14595. shadowMap, shadowMatrix, shadowCamera,
  14596. webglObject, object, material, light,
  14597. lights = [],
  14598. k = 0,
  14599. fog = null;
  14600. // set GL state for depth map
  14601. _gl.clearColor( 1, 1, 1, 1 );
  14602. _state.disable( _gl.BLEND );
  14603. _state.enable( _gl.CULL_FACE );
  14604. _gl.frontFace( _gl.CCW );
  14605. if ( scope.cullFace === THREE.CullFaceFront ) {
  14606. _gl.cullFace( _gl.FRONT );
  14607. } else {
  14608. _gl.cullFace( _gl.BACK );
  14609. }
  14610. _state.setDepthTest( true );
  14611. // preprocess lights
  14612. // - skip lights that are not casting shadows
  14613. // - create virtual lights for cascaded shadow maps
  14614. for ( i = 0, il = _lights.length; i < il; i ++ ) {
  14615. light = _lights[ i ];
  14616. if ( ! light.castShadow ) continue;
  14617. if ( ( light instanceof THREE.DirectionalLight ) && light.shadowCascade ) {
  14618. for ( n = 0; n < light.shadowCascadeCount; n ++ ) {
  14619. var virtualLight;
  14620. if ( ! light.shadowCascadeArray[ n ] ) {
  14621. virtualLight = createVirtualLight( light, n );
  14622. virtualLight.originalCamera = camera;
  14623. var gyro = new THREE.Gyroscope();
  14624. gyro.position.copy( light.shadowCascadeOffset );
  14625. gyro.add( virtualLight );
  14626. gyro.add( virtualLight.target );
  14627. camera.add( gyro );
  14628. light.shadowCascadeArray[ n ] = virtualLight;
  14629. //console.log( "Created virtualLight", virtualLight );
  14630. } else {
  14631. virtualLight = light.shadowCascadeArray[ n ];
  14632. }
  14633. updateVirtualLight( light, n );
  14634. lights[ k ] = virtualLight;
  14635. k ++;
  14636. }
  14637. } else {
  14638. lights[ k ] = light;
  14639. k ++;
  14640. }
  14641. }
  14642. // render depth map
  14643. for ( i = 0, il = lights.length; i < il; i ++ ) {
  14644. light = lights[ i ];
  14645. if ( ! light.shadowMap ) {
  14646. var shadowFilter = THREE.LinearFilter;
  14647. if ( scope.type === THREE.PCFSoftShadowMap ) {
  14648. shadowFilter = THREE.NearestFilter;
  14649. }
  14650. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  14651. light.shadowMap = new THREE.WebGLRenderTarget( light.shadowMapWidth, light.shadowMapHeight, pars );
  14652. light.shadowMapSize = new THREE.Vector2( light.shadowMapWidth, light.shadowMapHeight );
  14653. light.shadowMatrix = new THREE.Matrix4();
  14654. }
  14655. if ( ! light.shadowCamera ) {
  14656. if ( light instanceof THREE.SpotLight ) {
  14657. light.shadowCamera = new THREE.PerspectiveCamera( light.shadowCameraFov, light.shadowMapWidth / light.shadowMapHeight, light.shadowCameraNear, light.shadowCameraFar );
  14658. } else if ( light instanceof THREE.DirectionalLight ) {
  14659. light.shadowCamera = new THREE.OrthographicCamera( light.shadowCameraLeft, light.shadowCameraRight, light.shadowCameraTop, light.shadowCameraBottom, light.shadowCameraNear, light.shadowCameraFar );
  14660. } else {
  14661. console.error( "THREE.ShadowMapPlugin: Unsupported light type for shadow", light );
  14662. continue;
  14663. }
  14664. scene.add( light.shadowCamera );
  14665. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  14666. }
  14667. if ( light.shadowCameraVisible && ! light.cameraHelper ) {
  14668. light.cameraHelper = new THREE.CameraHelper( light.shadowCamera );
  14669. scene.add( light.cameraHelper );
  14670. }
  14671. if ( light.isVirtual && virtualLight.originalCamera == camera ) {
  14672. updateShadowCamera( camera, light );
  14673. }
  14674. shadowMap = light.shadowMap;
  14675. shadowMatrix = light.shadowMatrix;
  14676. shadowCamera = light.shadowCamera;
  14677. //
  14678. shadowCamera.position.setFromMatrixPosition( light.matrixWorld );
  14679. _matrixPosition.setFromMatrixPosition( light.target.matrixWorld );
  14680. shadowCamera.lookAt( _matrixPosition );
  14681. shadowCamera.updateMatrixWorld();
  14682. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  14683. //
  14684. if ( light.cameraHelper ) light.cameraHelper.visible = light.shadowCameraVisible;
  14685. if ( light.shadowCameraVisible ) light.cameraHelper.update();
  14686. // compute shadow matrix
  14687. shadowMatrix.set(
  14688. 0.5, 0.0, 0.0, 0.5,
  14689. 0.0, 0.5, 0.0, 0.5,
  14690. 0.0, 0.0, 0.5, 0.5,
  14691. 0.0, 0.0, 0.0, 1.0
  14692. );
  14693. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  14694. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  14695. // update camera matrices and frustum
  14696. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  14697. _frustum.setFromMatrix( _projScreenMatrix );
  14698. // render shadow map
  14699. _renderer.setRenderTarget( shadowMap );
  14700. _renderer.clear();
  14701. // set object matrices & frustum culling
  14702. _renderList.length = 0;
  14703. projectObject( scene, shadowCamera );
  14704. // render regular objects
  14705. var objectMaterial, useMorphing, useSkinning;
  14706. for ( j = 0, jl = _renderList.length; j < jl; j ++ ) {
  14707. webglObject = _renderList[ j ];
  14708. object = webglObject.object;
  14709. // culling is overridden globally for all objects
  14710. // while rendering depth map
  14711. // need to deal with MeshFaceMaterial somehow
  14712. // in that case just use the first of material.materials for now
  14713. // (proper solution would require to break objects by materials
  14714. // similarly to regular rendering and then set corresponding
  14715. // depth materials per each chunk instead of just once per object)
  14716. objectMaterial = getObjectMaterial( object );
  14717. useMorphing = object.geometry.morphTargets !== undefined && object.geometry.morphTargets.length > 0 && objectMaterial.morphTargets;
  14718. useSkinning = object instanceof THREE.SkinnedMesh && objectMaterial.skinning;
  14719. if ( object.customDepthMaterial ) {
  14720. material = object.customDepthMaterial;
  14721. } else if ( useSkinning ) {
  14722. material = useMorphing ? _depthMaterialMorphSkin : _depthMaterialSkin;
  14723. } else if ( useMorphing ) {
  14724. material = _depthMaterialMorph;
  14725. } else {
  14726. material = _depthMaterial;
  14727. }
  14728. _renderer.renderBufferDirect( shadowCamera, _lights, fog, material, object );
  14729. }
  14730. }
  14731. // restore GL state
  14732. var clearColor = _renderer.getClearColor(),
  14733. clearAlpha = _renderer.getClearAlpha();
  14734. _gl.clearColor( clearColor.r, clearColor.g, clearColor.b, clearAlpha );
  14735. _state.enable( _gl.BLEND );
  14736. if ( scope.cullFace === THREE.CullFaceFront ) {
  14737. _gl.cullFace( _gl.BACK );
  14738. }
  14739. _renderer.resetGLState();
  14740. scope.needsUpdate = false;
  14741. };
  14742. function projectObject( object, camera ) {
  14743. if ( object.visible === true ) {
  14744. var webglObject = _objects.objects[ object.id ];
  14745. if ( webglObject && object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  14746. object._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  14747. _renderList.push( webglObject );
  14748. }
  14749. for ( var i = 0, l = object.children.length; i < l; i ++ ) {
  14750. projectObject( object.children[ i ], camera );
  14751. }
  14752. }
  14753. }
  14754. function createVirtualLight( light, cascade ) {
  14755. var virtualLight = new THREE.DirectionalLight();
  14756. virtualLight.isVirtual = true;
  14757. virtualLight.onlyShadow = true;
  14758. virtualLight.castShadow = true;
  14759. virtualLight.shadowCameraNear = light.shadowCameraNear;
  14760. virtualLight.shadowCameraFar = light.shadowCameraFar;
  14761. virtualLight.shadowCameraLeft = light.shadowCameraLeft;
  14762. virtualLight.shadowCameraRight = light.shadowCameraRight;
  14763. virtualLight.shadowCameraBottom = light.shadowCameraBottom;
  14764. virtualLight.shadowCameraTop = light.shadowCameraTop;
  14765. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  14766. virtualLight.shadowDarkness = light.shadowDarkness;
  14767. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  14768. virtualLight.shadowMapWidth = light.shadowCascadeWidth[ cascade ];
  14769. virtualLight.shadowMapHeight = light.shadowCascadeHeight[ cascade ];
  14770. virtualLight.pointsWorld = [];
  14771. virtualLight.pointsFrustum = [];
  14772. var pointsWorld = virtualLight.pointsWorld,
  14773. pointsFrustum = virtualLight.pointsFrustum;
  14774. for ( var i = 0; i < 8; i ++ ) {
  14775. pointsWorld[ i ] = new THREE.Vector3();
  14776. pointsFrustum[ i ] = new THREE.Vector3();
  14777. }
  14778. var nearZ = light.shadowCascadeNearZ[ cascade ];
  14779. var farZ = light.shadowCascadeFarZ[ cascade ];
  14780. pointsFrustum[ 0 ].set( - 1, - 1, nearZ );
  14781. pointsFrustum[ 1 ].set( 1, - 1, nearZ );
  14782. pointsFrustum[ 2 ].set( - 1, 1, nearZ );
  14783. pointsFrustum[ 3 ].set( 1, 1, nearZ );
  14784. pointsFrustum[ 4 ].set( - 1, - 1, farZ );
  14785. pointsFrustum[ 5 ].set( 1, - 1, farZ );
  14786. pointsFrustum[ 6 ].set( - 1, 1, farZ );
  14787. pointsFrustum[ 7 ].set( 1, 1, farZ );
  14788. return virtualLight;
  14789. }
  14790. // Synchronize virtual light with the original light
  14791. function updateVirtualLight( light, cascade ) {
  14792. var virtualLight = light.shadowCascadeArray[ cascade ];
  14793. virtualLight.position.copy( light.position );
  14794. virtualLight.target.position.copy( light.target.position );
  14795. virtualLight.lookAt( virtualLight.target );
  14796. virtualLight.shadowCameraVisible = light.shadowCameraVisible;
  14797. virtualLight.shadowDarkness = light.shadowDarkness;
  14798. virtualLight.shadowBias = light.shadowCascadeBias[ cascade ];
  14799. var nearZ = light.shadowCascadeNearZ[ cascade ];
  14800. var farZ = light.shadowCascadeFarZ[ cascade ];
  14801. var pointsFrustum = virtualLight.pointsFrustum;
  14802. pointsFrustum[ 0 ].z = nearZ;
  14803. pointsFrustum[ 1 ].z = nearZ;
  14804. pointsFrustum[ 2 ].z = nearZ;
  14805. pointsFrustum[ 3 ].z = nearZ;
  14806. pointsFrustum[ 4 ].z = farZ;
  14807. pointsFrustum[ 5 ].z = farZ;
  14808. pointsFrustum[ 6 ].z = farZ;
  14809. pointsFrustum[ 7 ].z = farZ;
  14810. }
  14811. // Fit shadow camera's ortho frustum to camera frustum
  14812. function updateShadowCamera( camera, light ) {
  14813. var shadowCamera = light.shadowCamera,
  14814. pointsFrustum = light.pointsFrustum,
  14815. pointsWorld = light.pointsWorld;
  14816. _min.set( Infinity, Infinity, Infinity );
  14817. _max.set( - Infinity, - Infinity, - Infinity );
  14818. for ( var i = 0; i < 8; i ++ ) {
  14819. var p = pointsWorld[ i ];
  14820. p.copy( pointsFrustum[ i ] );
  14821. p.unproject( camera );
  14822. p.applyMatrix4( shadowCamera.matrixWorldInverse );
  14823. if ( p.x < _min.x ) _min.x = p.x;
  14824. if ( p.x > _max.x ) _max.x = p.x;
  14825. if ( p.y < _min.y ) _min.y = p.y;
  14826. if ( p.y > _max.y ) _max.y = p.y;
  14827. if ( p.z < _min.z ) _min.z = p.z;
  14828. if ( p.z > _max.z ) _max.z = p.z;
  14829. }
  14830. shadowCamera.left = _min.x;
  14831. shadowCamera.right = _max.x;
  14832. shadowCamera.top = _max.y;
  14833. shadowCamera.bottom = _min.y;
  14834. // can't really fit near/far
  14835. //shadowCamera.near = _min.z;
  14836. //shadowCamera.far = _max.z;
  14837. shadowCamera.updateProjectionMatrix();
  14838. }
  14839. // For the moment just ignore objects that have multiple materials with different animation methods
  14840. // Only the first material will be taken into account for deciding which depth material to use for shadow maps
  14841. function getObjectMaterial( object ) {
  14842. return object.material instanceof THREE.MeshFaceMaterial
  14843. ? object.material.materials[ 0 ]
  14844. : object.material;
  14845. }
  14846. };
  14847. // File:src/renderers/webgl/WebGLState.js
  14848. /**
  14849. * @author mrdoob / http://mrdoob.com/
  14850. */
  14851. THREE.WebGLState = function ( gl, paramThreeToGL ) {
  14852. var _this = this;
  14853. var newAttributes = new Uint8Array( 16 );
  14854. var enabledAttributes = new Uint8Array( 16 );
  14855. var capabilities = {};
  14856. var currentBlending = null;
  14857. var currentBlendEquation = null;
  14858. var currentBlendSrc = null;
  14859. var currentBlendDst = null;
  14860. var currentBlendEquationAlpha = null;
  14861. var currentBlendSrcAlpha = null;
  14862. var currentBlendDstAlpha = null;
  14863. var currentDepthFunc = null;
  14864. var currentDepthWrite = null;
  14865. var currentColorWrite = null;
  14866. var currentFlipSided = null;
  14867. var currentLineWidth = null;
  14868. var currentPolygonOffsetFactor = null;
  14869. var currentPolygonOffsetUnits = null;
  14870. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14871. var currentTextureSlot = undefined;
  14872. var currentBoundTextures = {};
  14873. this.init = function () {
  14874. gl.clearColor( 0, 0, 0, 1 );
  14875. gl.clearDepth( 1 );
  14876. gl.clearStencil( 0 );
  14877. this.enable( gl.DEPTH_TEST );
  14878. gl.depthFunc( gl.LEQUAL );
  14879. gl.frontFace( gl.CCW );
  14880. gl.cullFace( gl.BACK );
  14881. this.enable( gl.CULL_FACE );
  14882. this.enable( gl.BLEND );
  14883. gl.blendEquation( gl.FUNC_ADD );
  14884. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  14885. };
  14886. this.initAttributes = function () {
  14887. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  14888. newAttributes[ i ] = 0;
  14889. }
  14890. };
  14891. this.enableAttribute = function ( attribute ) {
  14892. newAttributes[ attribute ] = 1;
  14893. if ( enabledAttributes[ attribute ] === 0 ) {
  14894. gl.enableVertexAttribArray( attribute );
  14895. enabledAttributes[ attribute ] = 1;
  14896. }
  14897. };
  14898. this.disableUnusedAttributes = function () {
  14899. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  14900. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  14901. gl.disableVertexAttribArray( i );
  14902. enabledAttributes[ i ] = 0;
  14903. }
  14904. }
  14905. };
  14906. this.enable = function ( id ) {
  14907. if ( capabilities[ id ] !== true ) {
  14908. gl.enable( id );
  14909. capabilities[ id ] = true;
  14910. }
  14911. };
  14912. this.disable = function ( id ) {
  14913. if ( capabilities[ id ] !== false ) {
  14914. gl.disable( id );
  14915. capabilities[ id ] = false;
  14916. }
  14917. };
  14918. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  14919. if ( blending !== currentBlending ) {
  14920. if ( blending === THREE.NoBlending ) {
  14921. this.disable( gl.BLEND );
  14922. } else if ( blending === THREE.AdditiveBlending ) {
  14923. this.enable( gl.BLEND );
  14924. gl.blendEquation( gl.FUNC_ADD );
  14925. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  14926. } else if ( blending === THREE.SubtractiveBlending ) {
  14927. // TODO: Find blendFuncSeparate() combination
  14928. this.enable( gl.BLEND );
  14929. gl.blendEquation( gl.FUNC_ADD );
  14930. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  14931. } else if ( blending === THREE.MultiplyBlending ) {
  14932. // TODO: Find blendFuncSeparate() combination
  14933. this.enable( gl.BLEND );
  14934. gl.blendEquation( gl.FUNC_ADD );
  14935. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  14936. } else if ( blending === THREE.CustomBlending ) {
  14937. this.enable( gl.BLEND );
  14938. } else {
  14939. this.enable( gl.BLEND );
  14940. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  14941. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  14942. }
  14943. currentBlending = blending;
  14944. }
  14945. if ( blending === THREE.CustomBlending ) {
  14946. blendEquationAlpha = blendEquationAlpha || blendEquation;
  14947. blendSrcAlpha = blendSrcAlpha || blendSrc;
  14948. blendDstAlpha = blendDstAlpha || blendDst;
  14949. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  14950. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  14951. currentBlendEquation = blendEquation;
  14952. currentBlendEquationAlpha = blendEquationAlpha;
  14953. }
  14954. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  14955. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  14956. currentBlendSrc = blendSrc;
  14957. currentBlendDst = blendDst;
  14958. currentBlendSrcAlpha = blendSrcAlpha;
  14959. currentBlendDstAlpha = blendDstAlpha;
  14960. }
  14961. } else {
  14962. currentBlendEquation = null;
  14963. currentBlendSrc = null;
  14964. currentBlendDst = null;
  14965. currentBlendEquationAlpha = null;
  14966. currentBlendSrcAlpha = null;
  14967. currentBlendDstAlpha = null;
  14968. }
  14969. };
  14970. this.setDepthFunc = function ( depthFunc ) {
  14971. if ( currentDepthFunc !== depthFunc ) {
  14972. if ( depthFunc ) {
  14973. switch ( depthFunc ) {
  14974. case THREE.NeverDepth:
  14975. gl.depthFunc( gl.NEVER );
  14976. break;
  14977. case THREE.AlwaysDepth:
  14978. gl.depthFunc( gl.ALWAYS );
  14979. break;
  14980. case THREE.LessDepth:
  14981. gl.depthFunc( gl.LESS );
  14982. break;
  14983. case THREE.LessEqualDepth:
  14984. gl.depthFunc( gl.LEQUAL );
  14985. break;
  14986. case THREE.EqualDepth:
  14987. gl.depthFunc( gl.EQUAL );
  14988. break;
  14989. case THREE.GreaterEqualDepth:
  14990. gl.depthFunc( gl.GEQUAL );
  14991. break;
  14992. case THREE.GreaterDepth:
  14993. gl.depthFunc( gl.GREATER );
  14994. break;
  14995. case THREE.NotEqualDepth:
  14996. gl.depthFunc( gl.NOTEQUAL );
  14997. break;
  14998. default:
  14999. gl.depthFunc( gl.LEQUAL );
  15000. }
  15001. } else {
  15002. gl.depthFunc( gl.LEQUAL );
  15003. }
  15004. currentDepthFunc = depthFunc;
  15005. }
  15006. };
  15007. this.setDepthTest = function ( depthTest ) {
  15008. if ( depthTest ) {
  15009. this.enable( gl.DEPTH_TEST );
  15010. } else {
  15011. this.disable( gl.DEPTH_TEST );
  15012. }
  15013. };
  15014. this.setDepthWrite = function ( depthWrite ) {
  15015. if ( currentDepthWrite !== depthWrite ) {
  15016. gl.depthMask( depthWrite );
  15017. currentDepthWrite = depthWrite;
  15018. }
  15019. };
  15020. this.setColorWrite = function ( colorWrite ) {
  15021. if ( currentColorWrite !== colorWrite ) {
  15022. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  15023. currentColorWrite = colorWrite;
  15024. }
  15025. };
  15026. this.setFlipSided = function ( flipSided ) {
  15027. if ( currentFlipSided !== flipSided ) {
  15028. if ( flipSided ) {
  15029. gl.frontFace( gl.CW );
  15030. } else {
  15031. gl.frontFace( gl.CCW );
  15032. }
  15033. currentFlipSided = flipSided;
  15034. }
  15035. };
  15036. this.setLineWidth = function ( width ) {
  15037. if ( width !== currentLineWidth ) {
  15038. gl.lineWidth( width );
  15039. currentLineWidth = width;
  15040. }
  15041. };
  15042. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  15043. if ( polygonOffset ) {
  15044. this.enable( gl.POLYGON_OFFSET_FILL );
  15045. } else {
  15046. this.disable( gl.POLYGON_OFFSET_FILL );
  15047. }
  15048. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  15049. gl.polygonOffset( factor, units );
  15050. currentPolygonOffsetFactor = factor;
  15051. currentPolygonOffsetUnits = units;
  15052. }
  15053. };
  15054. this.setScissorTest = function ( scissorTest ) {
  15055. if ( scissorTest ) {
  15056. this.enable( gl.SCISSOR_TEST );
  15057. } else {
  15058. this.disable( gl.SCISSOR_TEST );
  15059. }
  15060. };
  15061. // texture
  15062. this.activeTexture = function ( webglSlot ) {
  15063. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  15064. if ( currentTextureSlot !== webglSlot ) {
  15065. gl.activeTexture( webglSlot );
  15066. currentTextureSlot = webglSlot;
  15067. }
  15068. }
  15069. this.bindTexture = function ( webglType, webglTexture ) {
  15070. if ( currentTextureSlot === undefined ) {
  15071. _this.activeTexture();
  15072. }
  15073. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  15074. if ( boundTexture === undefined ) {
  15075. boundTexture = { type: undefined, texture: undefined };
  15076. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  15077. }
  15078. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  15079. gl.bindTexture( webglType, webglTexture );
  15080. boundTexture.type = webglType;
  15081. boundTexture.texture = webglTexture;
  15082. }
  15083. };
  15084. this.compressedTexImage2D = function () {
  15085. try {
  15086. gl.compressedTexImage2D.apply( gl, arguments );
  15087. } catch ( error ) {
  15088. console.error( error );
  15089. }
  15090. };
  15091. this.texImage2D = function () {
  15092. try {
  15093. gl.texImage2D.apply( gl, arguments );
  15094. } catch ( error ) {
  15095. console.error( error );
  15096. }
  15097. };
  15098. //
  15099. this.reset = function () {
  15100. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  15101. if ( enabledAttributes[ i ] === 1 ) {
  15102. gl.disableVertexAttribArray( i );
  15103. enabledAttributes[ i ] = 0;
  15104. }
  15105. }
  15106. capabilities = {};
  15107. currentBlending = null;
  15108. currentDepthWrite = null;
  15109. currentColorWrite = null;
  15110. currentFlipSided = null;
  15111. };
  15112. };
  15113. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  15114. /**
  15115. * @author mikael emtinger / http://gomo.se/
  15116. * @author alteredq / http://alteredqualia.com/
  15117. */
  15118. THREE.LensFlarePlugin = function ( renderer, flares ) {
  15119. var gl = renderer.context;
  15120. var state = renderer.state;
  15121. var vertexBuffer, elementBuffer;
  15122. var program, attributes, uniforms;
  15123. var hasVertexTexture;
  15124. var tempTexture, occlusionTexture;
  15125. var init = function () {
  15126. var vertices = new Float32Array( [
  15127. -1, -1, 0, 0,
  15128. 1, -1, 1, 0,
  15129. 1, 1, 1, 1,
  15130. -1, 1, 0, 1
  15131. ] );
  15132. var faces = new Uint16Array( [
  15133. 0, 1, 2,
  15134. 0, 2, 3
  15135. ] );
  15136. // buffers
  15137. vertexBuffer = gl.createBuffer();
  15138. elementBuffer = gl.createBuffer();
  15139. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15140. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15141. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15142. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15143. // textures
  15144. tempTexture = gl.createTexture();
  15145. occlusionTexture = gl.createTexture();
  15146. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15147. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  15148. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15149. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15150. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15151. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15152. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15153. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  15154. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  15155. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  15156. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  15157. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  15158. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  15159. var shader;
  15160. if ( hasVertexTexture ) {
  15161. shader = {
  15162. vertexShader: [
  15163. "uniform lowp int renderType;",
  15164. "uniform vec3 screenPosition;",
  15165. "uniform vec2 scale;",
  15166. "uniform float rotation;",
  15167. "uniform sampler2D occlusionMap;",
  15168. "attribute vec2 position;",
  15169. "attribute vec2 uv;",
  15170. "varying vec2 vUV;",
  15171. "varying float vVisibility;",
  15172. "void main() {",
  15173. "vUV = uv;",
  15174. "vec2 pos = position;",
  15175. "if( renderType == 2 ) {",
  15176. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  15177. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  15178. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  15179. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  15180. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  15181. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  15182. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  15183. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  15184. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  15185. "vVisibility = visibility.r / 9.0;",
  15186. "vVisibility *= 1.0 - visibility.g / 9.0;",
  15187. "vVisibility *= visibility.b / 9.0;",
  15188. "vVisibility *= 1.0 - visibility.a / 9.0;",
  15189. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15190. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15191. "}",
  15192. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15193. "}"
  15194. ].join( "\n" ),
  15195. fragmentShader: [
  15196. "uniform lowp int renderType;",
  15197. "uniform sampler2D map;",
  15198. "uniform float opacity;",
  15199. "uniform vec3 color;",
  15200. "varying vec2 vUV;",
  15201. "varying float vVisibility;",
  15202. "void main() {",
  15203. // pink square
  15204. "if( renderType == 0 ) {",
  15205. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  15206. // restore
  15207. "} else if( renderType == 1 ) {",
  15208. "gl_FragColor = texture2D( map, vUV );",
  15209. // flare
  15210. "} else {",
  15211. "vec4 texture = texture2D( map, vUV );",
  15212. "texture.a *= opacity * vVisibility;",
  15213. "gl_FragColor = texture;",
  15214. "gl_FragColor.rgb *= color;",
  15215. "}",
  15216. "}"
  15217. ].join( "\n" )
  15218. };
  15219. } else {
  15220. shader = {
  15221. vertexShader: [
  15222. "uniform lowp int renderType;",
  15223. "uniform vec3 screenPosition;",
  15224. "uniform vec2 scale;",
  15225. "uniform float rotation;",
  15226. "attribute vec2 position;",
  15227. "attribute vec2 uv;",
  15228. "varying vec2 vUV;",
  15229. "void main() {",
  15230. "vUV = uv;",
  15231. "vec2 pos = position;",
  15232. "if( renderType == 2 ) {",
  15233. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  15234. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  15235. "}",
  15236. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  15237. "}"
  15238. ].join( "\n" ),
  15239. fragmentShader: [
  15240. "precision mediump float;",
  15241. "uniform lowp int renderType;",
  15242. "uniform sampler2D map;",
  15243. "uniform sampler2D occlusionMap;",
  15244. "uniform float opacity;",
  15245. "uniform vec3 color;",
  15246. "varying vec2 vUV;",
  15247. "void main() {",
  15248. // pink square
  15249. "if( renderType == 0 ) {",
  15250. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  15251. // restore
  15252. "} else if( renderType == 1 ) {",
  15253. "gl_FragColor = texture2D( map, vUV );",
  15254. // flare
  15255. "} else {",
  15256. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  15257. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  15258. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  15259. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  15260. "visibility = ( 1.0 - visibility / 4.0 );",
  15261. "vec4 texture = texture2D( map, vUV );",
  15262. "texture.a *= opacity * visibility;",
  15263. "gl_FragColor = texture;",
  15264. "gl_FragColor.rgb *= color;",
  15265. "}",
  15266. "}"
  15267. ].join( "\n" )
  15268. };
  15269. }
  15270. program = createProgram( shader );
  15271. attributes = {
  15272. vertex: gl.getAttribLocation ( program, "position" ),
  15273. uv: gl.getAttribLocation ( program, "uv" )
  15274. };
  15275. uniforms = {
  15276. renderType: gl.getUniformLocation( program, "renderType" ),
  15277. map: gl.getUniformLocation( program, "map" ),
  15278. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  15279. opacity: gl.getUniformLocation( program, "opacity" ),
  15280. color: gl.getUniformLocation( program, "color" ),
  15281. scale: gl.getUniformLocation( program, "scale" ),
  15282. rotation: gl.getUniformLocation( program, "rotation" ),
  15283. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  15284. };
  15285. };
  15286. /*
  15287. * Render lens flares
  15288. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  15289. * reads these back and calculates occlusion.
  15290. */
  15291. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  15292. if ( flares.length === 0 ) return;
  15293. var tempPosition = new THREE.Vector3();
  15294. var invAspect = viewportHeight / viewportWidth,
  15295. halfViewportWidth = viewportWidth * 0.5,
  15296. halfViewportHeight = viewportHeight * 0.5;
  15297. var size = 16 / viewportHeight,
  15298. scale = new THREE.Vector2( size * invAspect, size );
  15299. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  15300. screenPositionPixels = new THREE.Vector2( 1, 1 );
  15301. if ( program === undefined ) {
  15302. init();
  15303. }
  15304. gl.useProgram( program );
  15305. state.initAttributes();
  15306. state.enableAttribute( attributes.vertex );
  15307. state.enableAttribute( attributes.uv );
  15308. state.disableUnusedAttributes();
  15309. // loop through all lens flares to update their occlusion and positions
  15310. // setup gl and common used attribs/uniforms
  15311. gl.uniform1i( uniforms.occlusionMap, 0 );
  15312. gl.uniform1i( uniforms.map, 1 );
  15313. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15314. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  15315. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15316. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15317. state.disable( gl.CULL_FACE );
  15318. gl.depthMask( false );
  15319. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  15320. size = 16 / viewportHeight;
  15321. scale.set( size * invAspect, size );
  15322. // calc object screen position
  15323. var flare = flares[ i ];
  15324. tempPosition.set( flare.matrixWorld.elements[12], flare.matrixWorld.elements[13], flare.matrixWorld.elements[14] );
  15325. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  15326. tempPosition.applyProjection( camera.projectionMatrix );
  15327. // setup arrays for gl programs
  15328. screenPosition.copy( tempPosition );
  15329. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  15330. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  15331. // screen cull
  15332. if ( hasVertexTexture || (
  15333. screenPositionPixels.x > 0 &&
  15334. screenPositionPixels.x < viewportWidth &&
  15335. screenPositionPixels.y > 0 &&
  15336. screenPositionPixels.y < viewportHeight ) ) {
  15337. // save current RGB to temp texture
  15338. state.activeTexture( gl.TEXTURE0 );
  15339. state.bindTexture( gl.TEXTURE_2D, null );
  15340. state.activeTexture( gl.TEXTURE1 );
  15341. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15342. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15343. // render pink quad
  15344. gl.uniform1i( uniforms.renderType, 0 );
  15345. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15346. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15347. state.disable( gl.BLEND );
  15348. state.enable( gl.DEPTH_TEST );
  15349. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15350. // copy result to occlusionMap
  15351. state.activeTexture( gl.TEXTURE0 );
  15352. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  15353. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  15354. // restore graphics
  15355. gl.uniform1i( uniforms.renderType, 1 );
  15356. state.disable( gl.DEPTH_TEST );
  15357. state.activeTexture( gl.TEXTURE1 );
  15358. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  15359. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15360. // update object positions
  15361. flare.positionScreen.copy( screenPosition );
  15362. if ( flare.customUpdateCallback ) {
  15363. flare.customUpdateCallback( flare );
  15364. } else {
  15365. flare.updateLensFlares();
  15366. }
  15367. // render flares
  15368. gl.uniform1i( uniforms.renderType, 2 );
  15369. state.enable( gl.BLEND );
  15370. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  15371. var sprite = flare.lensFlares[ j ];
  15372. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  15373. screenPosition.x = sprite.x;
  15374. screenPosition.y = sprite.y;
  15375. screenPosition.z = sprite.z;
  15376. size = sprite.size * sprite.scale / viewportHeight;
  15377. scale.x = size * invAspect;
  15378. scale.y = size;
  15379. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  15380. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  15381. gl.uniform1f( uniforms.rotation, sprite.rotation );
  15382. gl.uniform1f( uniforms.opacity, sprite.opacity );
  15383. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  15384. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  15385. renderer.setTexture( sprite.texture, 1 );
  15386. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15387. }
  15388. }
  15389. }
  15390. }
  15391. // restore gl
  15392. state.enable( gl.CULL_FACE );
  15393. state.enable( gl.DEPTH_TEST );
  15394. gl.depthMask( true );
  15395. renderer.resetGLState();
  15396. };
  15397. function createProgram ( shader ) {
  15398. var program = gl.createProgram();
  15399. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15400. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15401. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  15402. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  15403. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  15404. gl.compileShader( fragmentShader );
  15405. gl.compileShader( vertexShader );
  15406. gl.attachShader( program, fragmentShader );
  15407. gl.attachShader( program, vertexShader );
  15408. gl.linkProgram( program );
  15409. return program;
  15410. }
  15411. };
  15412. // File:src/renderers/webgl/plugins/SpritePlugin.js
  15413. /**
  15414. * @author mikael emtinger / http://gomo.se/
  15415. * @author alteredq / http://alteredqualia.com/
  15416. */
  15417. THREE.SpritePlugin = function ( renderer, sprites ) {
  15418. var gl = renderer.context;
  15419. var state = renderer.state;
  15420. var vertexBuffer, elementBuffer;
  15421. var program, attributes, uniforms;
  15422. var texture;
  15423. // decompose matrixWorld
  15424. var spritePosition = new THREE.Vector3();
  15425. var spriteRotation = new THREE.Quaternion();
  15426. var spriteScale = new THREE.Vector3();
  15427. var init = function () {
  15428. var vertices = new Float32Array( [
  15429. - 0.5, - 0.5, 0, 0,
  15430. 0.5, - 0.5, 1, 0,
  15431. 0.5, 0.5, 1, 1,
  15432. - 0.5, 0.5, 0, 1
  15433. ] );
  15434. var faces = new Uint16Array( [
  15435. 0, 1, 2,
  15436. 0, 2, 3
  15437. ] );
  15438. vertexBuffer = gl.createBuffer();
  15439. elementBuffer = gl.createBuffer();
  15440. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15441. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  15442. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15443. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  15444. program = createProgram();
  15445. attributes = {
  15446. position: gl.getAttribLocation ( program, 'position' ),
  15447. uv: gl.getAttribLocation ( program, 'uv' )
  15448. };
  15449. uniforms = {
  15450. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  15451. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  15452. rotation: gl.getUniformLocation( program, 'rotation' ),
  15453. scale: gl.getUniformLocation( program, 'scale' ),
  15454. color: gl.getUniformLocation( program, 'color' ),
  15455. map: gl.getUniformLocation( program, 'map' ),
  15456. opacity: gl.getUniformLocation( program, 'opacity' ),
  15457. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  15458. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  15459. fogType: gl.getUniformLocation( program, 'fogType' ),
  15460. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  15461. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  15462. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  15463. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  15464. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  15465. };
  15466. var canvas = document.createElement( 'canvas' );
  15467. canvas.width = 8;
  15468. canvas.height = 8;
  15469. var context = canvas.getContext( '2d' );
  15470. context.fillStyle = 'white';
  15471. context.fillRect( 0, 0, 8, 8 );
  15472. texture = new THREE.Texture( canvas );
  15473. texture.needsUpdate = true;
  15474. };
  15475. this.render = function ( scene, camera ) {
  15476. if ( sprites.length === 0 ) return;
  15477. // setup gl
  15478. if ( program === undefined ) {
  15479. init();
  15480. }
  15481. gl.useProgram( program );
  15482. state.initAttributes();
  15483. state.enableAttribute( attributes.position );
  15484. state.enableAttribute( attributes.uv );
  15485. state.disableUnusedAttributes();
  15486. state.disable( gl.CULL_FACE );
  15487. state.enable( gl.BLEND );
  15488. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  15489. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  15490. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  15491. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  15492. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15493. state.activeTexture( gl.TEXTURE0 );
  15494. gl.uniform1i( uniforms.map, 0 );
  15495. var oldFogType = 0;
  15496. var sceneFogType = 0;
  15497. var fog = scene.fog;
  15498. if ( fog ) {
  15499. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  15500. if ( fog instanceof THREE.Fog ) {
  15501. gl.uniform1f( uniforms.fogNear, fog.near );
  15502. gl.uniform1f( uniforms.fogFar, fog.far );
  15503. gl.uniform1i( uniforms.fogType, 1 );
  15504. oldFogType = 1;
  15505. sceneFogType = 1;
  15506. } else if ( fog instanceof THREE.FogExp2 ) {
  15507. gl.uniform1f( uniforms.fogDensity, fog.density );
  15508. gl.uniform1i( uniforms.fogType, 2 );
  15509. oldFogType = 2;
  15510. sceneFogType = 2;
  15511. }
  15512. } else {
  15513. gl.uniform1i( uniforms.fogType, 0 );
  15514. oldFogType = 0;
  15515. sceneFogType = 0;
  15516. }
  15517. // update positions and sort
  15518. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15519. var sprite = sprites[ i ];
  15520. sprite._modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  15521. sprite.z = - sprite._modelViewMatrix.elements[ 14 ];
  15522. }
  15523. sprites.sort( painterSortStable );
  15524. // render all sprites
  15525. var scale = [];
  15526. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  15527. var sprite = sprites[ i ];
  15528. var material = sprite.material;
  15529. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  15530. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite._modelViewMatrix.elements );
  15531. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  15532. scale[ 0 ] = spriteScale.x;
  15533. scale[ 1 ] = spriteScale.y;
  15534. var fogType = 0;
  15535. if ( scene.fog && material.fog ) {
  15536. fogType = sceneFogType;
  15537. }
  15538. if ( oldFogType !== fogType ) {
  15539. gl.uniform1i( uniforms.fogType, fogType );
  15540. oldFogType = fogType;
  15541. }
  15542. if ( material.map !== null ) {
  15543. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  15544. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  15545. } else {
  15546. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  15547. gl.uniform2f( uniforms.uvScale, 1, 1 );
  15548. }
  15549. gl.uniform1f( uniforms.opacity, material.opacity );
  15550. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  15551. gl.uniform1f( uniforms.rotation, material.rotation );
  15552. gl.uniform2fv( uniforms.scale, scale );
  15553. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  15554. state.setDepthTest( material.depthTest );
  15555. state.setDepthWrite( material.depthWrite );
  15556. if ( material.map && material.map.image && material.map.image.width ) {
  15557. renderer.setTexture( material.map, 0 );
  15558. } else {
  15559. renderer.setTexture( texture, 0 );
  15560. }
  15561. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  15562. }
  15563. // restore gl
  15564. state.enable( gl.CULL_FACE );
  15565. renderer.resetGLState();
  15566. };
  15567. function createProgram () {
  15568. var program = gl.createProgram();
  15569. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  15570. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  15571. gl.shaderSource( vertexShader, [
  15572. 'precision ' + renderer.getPrecision() + ' float;',
  15573. 'uniform mat4 modelViewMatrix;',
  15574. 'uniform mat4 projectionMatrix;',
  15575. 'uniform float rotation;',
  15576. 'uniform vec2 scale;',
  15577. 'uniform vec2 uvOffset;',
  15578. 'uniform vec2 uvScale;',
  15579. 'attribute vec2 position;',
  15580. 'attribute vec2 uv;',
  15581. 'varying vec2 vUV;',
  15582. 'void main() {',
  15583. 'vUV = uvOffset + uv * uvScale;',
  15584. 'vec2 alignedPosition = position * scale;',
  15585. 'vec2 rotatedPosition;',
  15586. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  15587. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  15588. 'vec4 finalPosition;',
  15589. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  15590. 'finalPosition.xy += rotatedPosition;',
  15591. 'finalPosition = projectionMatrix * finalPosition;',
  15592. 'gl_Position = finalPosition;',
  15593. '}'
  15594. ].join( '\n' ) );
  15595. gl.shaderSource( fragmentShader, [
  15596. 'precision ' + renderer.getPrecision() + ' float;',
  15597. 'uniform vec3 color;',
  15598. 'uniform sampler2D map;',
  15599. 'uniform float opacity;',
  15600. 'uniform int fogType;',
  15601. 'uniform vec3 fogColor;',
  15602. 'uniform float fogDensity;',
  15603. 'uniform float fogNear;',
  15604. 'uniform float fogFar;',
  15605. 'uniform float alphaTest;',
  15606. 'varying vec2 vUV;',
  15607. 'void main() {',
  15608. 'vec4 texture = texture2D( map, vUV );',
  15609. 'if ( texture.a < alphaTest ) discard;',
  15610. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  15611. 'if ( fogType > 0 ) {',
  15612. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  15613. 'float fogFactor = 0.0;',
  15614. 'if ( fogType == 1 ) {',
  15615. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  15616. '} else {',
  15617. 'const float LOG2 = 1.442695;',
  15618. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  15619. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  15620. '}',
  15621. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  15622. '}',
  15623. '}'
  15624. ].join( '\n' ) );
  15625. gl.compileShader( vertexShader );
  15626. gl.compileShader( fragmentShader );
  15627. gl.attachShader( program, vertexShader );
  15628. gl.attachShader( program, fragmentShader );
  15629. gl.linkProgram( program );
  15630. return program;
  15631. }
  15632. function painterSortStable ( a, b ) {
  15633. if ( a.z !== b.z ) {
  15634. return b.z - a.z;
  15635. } else {
  15636. return b.id - a.id;
  15637. }
  15638. }
  15639. };
  15640. // File:src/extras/GeometryUtils.js
  15641. /**
  15642. * @author mrdoob / http://mrdoob.com/
  15643. */
  15644. THREE.GeometryUtils = {
  15645. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  15646. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  15647. var matrix;
  15648. if ( geometry2 instanceof THREE.Mesh ) {
  15649. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  15650. matrix = geometry2.matrix;
  15651. geometry2 = geometry2.geometry;
  15652. }
  15653. geometry1.merge( geometry2, matrix, materialIndexOffset );
  15654. },
  15655. center: function ( geometry ) {
  15656. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  15657. return geometry.center();
  15658. }
  15659. };
  15660. // File:src/extras/ImageUtils.js
  15661. /**
  15662. * @author alteredq / http://alteredqualia.com/
  15663. * @author mrdoob / http://mrdoob.com/
  15664. * @author Daosheng Mu / https://github.com/DaoshengMu/
  15665. */
  15666. THREE.ImageUtils = {
  15667. crossOrigin: undefined,
  15668. loadTexture: function ( url, mapping, onLoad, onError ) {
  15669. var loader = new THREE.ImageLoader();
  15670. loader.crossOrigin = this.crossOrigin;
  15671. var texture = new THREE.Texture( undefined, mapping );
  15672. loader.load( url, function ( image ) {
  15673. texture.image = image;
  15674. texture.needsUpdate = true;
  15675. if ( onLoad ) onLoad( texture );
  15676. }, undefined, function ( event ) {
  15677. if ( onError ) onError( event );
  15678. } );
  15679. texture.sourceFile = url;
  15680. return texture;
  15681. },
  15682. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  15683. var images = [];
  15684. var loader = new THREE.ImageLoader();
  15685. loader.crossOrigin = this.crossOrigin;
  15686. var texture = new THREE.CubeTexture( images, mapping );
  15687. var loaded = 0;
  15688. var loadTexture = function ( i ) {
  15689. loader.load( array[ i ], function ( image ) {
  15690. texture.images[ i ] = image;
  15691. loaded += 1;
  15692. if ( loaded === 6 ) {
  15693. texture.needsUpdate = true;
  15694. if ( onLoad ) onLoad( texture );
  15695. }
  15696. }, undefined, onError );
  15697. };
  15698. for ( var i = 0, il = array.length; i < il; ++ i ) {
  15699. loadTexture( i );
  15700. }
  15701. return texture;
  15702. },
  15703. loadCompressedTexture: function () {
  15704. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  15705. },
  15706. loadCompressedTextureCube: function () {
  15707. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  15708. },
  15709. getNormalMap: function ( image, depth ) {
  15710. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  15711. var cross = function ( a, b ) {
  15712. return [ a[ 1 ] * b[ 2 ] - a[ 2 ] * b[ 1 ], a[ 2 ] * b[ 0 ] - a[ 0 ] * b[ 2 ], a[ 0 ] * b[ 1 ] - a[ 1 ] * b[ 0 ] ];
  15713. };
  15714. var subtract = function ( a, b ) {
  15715. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  15716. };
  15717. var normalize = function ( a ) {
  15718. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  15719. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  15720. };
  15721. depth = depth | 1;
  15722. var width = image.width;
  15723. var height = image.height;
  15724. var canvas = document.createElement( 'canvas' );
  15725. canvas.width = width;
  15726. canvas.height = height;
  15727. var context = canvas.getContext( '2d' );
  15728. context.drawImage( image, 0, 0 );
  15729. var data = context.getImageData( 0, 0, width, height ).data;
  15730. var imageData = context.createImageData( width, height );
  15731. var output = imageData.data;
  15732. for ( var x = 0; x < width; x ++ ) {
  15733. for ( var y = 0; y < height; y ++ ) {
  15734. var ly = y - 1 < 0 ? 0 : y - 1;
  15735. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  15736. var lx = x - 1 < 0 ? 0 : x - 1;
  15737. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  15738. var points = [];
  15739. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  15740. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  15741. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  15742. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  15743. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  15744. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  15745. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  15746. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  15747. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  15748. var normals = [];
  15749. var num_points = points.length;
  15750. for ( var i = 0; i < num_points; i ++ ) {
  15751. var v1 = points[ i ];
  15752. var v2 = points[ ( i + 1 ) % num_points ];
  15753. v1 = subtract( v1, origin );
  15754. v2 = subtract( v2, origin );
  15755. normals.push( normalize( cross( v1, v2 ) ) );
  15756. }
  15757. var normal = [ 0, 0, 0 ];
  15758. for ( var i = 0; i < normals.length; i ++ ) {
  15759. normal[ 0 ] += normals[ i ][ 0 ];
  15760. normal[ 1 ] += normals[ i ][ 1 ];
  15761. normal[ 2 ] += normals[ i ][ 2 ];
  15762. }
  15763. normal[ 0 ] /= normals.length;
  15764. normal[ 1 ] /= normals.length;
  15765. normal[ 2 ] /= normals.length;
  15766. var idx = ( y * width + x ) * 4;
  15767. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15768. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  15769. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  15770. output[ idx + 3 ] = 255;
  15771. }
  15772. }
  15773. context.putImageData( imageData, 0, 0 );
  15774. return canvas;
  15775. },
  15776. generateDataTexture: function ( width, height, color ) {
  15777. var size = width * height;
  15778. var data = new Uint8Array( 3 * size );
  15779. var r = Math.floor( color.r * 255 );
  15780. var g = Math.floor( color.g * 255 );
  15781. var b = Math.floor( color.b * 255 );
  15782. for ( var i = 0; i < size; i ++ ) {
  15783. data[ i * 3 ] = r;
  15784. data[ i * 3 + 1 ] = g;
  15785. data[ i * 3 + 2 ] = b;
  15786. }
  15787. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  15788. texture.needsUpdate = true;
  15789. return texture;
  15790. }
  15791. };
  15792. // File:src/extras/SceneUtils.js
  15793. /**
  15794. * @author alteredq / http://alteredqualia.com/
  15795. */
  15796. THREE.SceneUtils = {
  15797. createMultiMaterialObject: function ( geometry, materials ) {
  15798. var group = new THREE.Object3D();
  15799. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  15800. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  15801. }
  15802. return group;
  15803. },
  15804. detach: function ( child, parent, scene ) {
  15805. child.applyMatrix( parent.matrixWorld );
  15806. parent.remove( child );
  15807. scene.add( child );
  15808. },
  15809. attach: function ( child, scene, parent ) {
  15810. var matrixWorldInverse = new THREE.Matrix4();
  15811. matrixWorldInverse.getInverse( parent.matrixWorld );
  15812. child.applyMatrix( matrixWorldInverse );
  15813. scene.remove( child );
  15814. parent.add( child );
  15815. }
  15816. };
  15817. // File:src/extras/FontUtils.js
  15818. /**
  15819. * @author zz85 / http://www.lab4games.net/zz85/blog
  15820. * @author alteredq / http://alteredqualia.com/
  15821. *
  15822. * For Text operations in three.js (See TextGeometry)
  15823. *
  15824. * It uses techniques used in:
  15825. *
  15826. * Triangulation ported from AS3
  15827. * Simple Polygon Triangulation
  15828. * http://actionsnippet.com/?p=1462
  15829. *
  15830. * A Method to triangulate shapes with holes
  15831. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  15832. *
  15833. */
  15834. THREE.FontUtils = {
  15835. faces: {},
  15836. // Just for now. face[weight][style]
  15837. face: 'helvetiker',
  15838. weight: 'normal',
  15839. style: 'normal',
  15840. size: 150,
  15841. divisions: 10,
  15842. getFace: function () {
  15843. try {
  15844. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  15845. } catch (e) {
  15846. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  15847. }
  15848. },
  15849. loadFace: function ( data ) {
  15850. var family = data.familyName.toLowerCase();
  15851. var ThreeFont = this;
  15852. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  15853. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  15854. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15855. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  15856. return data;
  15857. },
  15858. drawText: function ( text ) {
  15859. // RenderText
  15860. var i,
  15861. face = this.getFace(),
  15862. scale = this.size / face.resolution,
  15863. offset = 0,
  15864. chars = String( text ).split( '' ),
  15865. length = chars.length;
  15866. var fontPaths = [];
  15867. for ( i = 0; i < length; i ++ ) {
  15868. var path = new THREE.Path();
  15869. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  15870. offset += ret.offset;
  15871. fontPaths.push( ret.path );
  15872. }
  15873. // get the width
  15874. var width = offset / 2;
  15875. //
  15876. // for ( p = 0; p < allPts.length; p++ ) {
  15877. //
  15878. // allPts[ p ].x -= width;
  15879. //
  15880. // }
  15881. //var extract = this.extractPoints( allPts, characterPts );
  15882. //extract.contour = allPts;
  15883. //extract.paths = fontPaths;
  15884. //extract.offset = width;
  15885. return { paths: fontPaths, offset: width };
  15886. },
  15887. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  15888. var pts = [];
  15889. var i, i2, divisions,
  15890. outline, action, length,
  15891. scaleX, scaleY,
  15892. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  15893. laste,
  15894. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  15895. if ( ! glyph ) return;
  15896. if ( glyph.o ) {
  15897. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  15898. length = outline.length;
  15899. scaleX = scale;
  15900. scaleY = scale;
  15901. for ( i = 0; i < length; ) {
  15902. action = outline[ i ++ ];
  15903. //console.log( action );
  15904. switch ( action ) {
  15905. case 'm':
  15906. // Move To
  15907. x = outline[ i ++ ] * scaleX + offset;
  15908. y = outline[ i ++ ] * scaleY;
  15909. path.moveTo( x, y );
  15910. break;
  15911. case 'l':
  15912. // Line To
  15913. x = outline[ i ++ ] * scaleX + offset;
  15914. y = outline[ i ++ ] * scaleY;
  15915. path.lineTo( x, y );
  15916. break;
  15917. case 'q':
  15918. // QuadraticCurveTo
  15919. cpx = outline[ i ++ ] * scaleX + offset;
  15920. cpy = outline[ i ++ ] * scaleY;
  15921. cpx1 = outline[ i ++ ] * scaleX + offset;
  15922. cpy1 = outline[ i ++ ] * scaleY;
  15923. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  15924. laste = pts[ pts.length - 1 ];
  15925. if ( laste ) {
  15926. cpx0 = laste.x;
  15927. cpy0 = laste.y;
  15928. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15929. var t = i2 / divisions;
  15930. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  15931. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  15932. }
  15933. }
  15934. break;
  15935. case 'b':
  15936. // Cubic Bezier Curve
  15937. cpx = outline[ i ++ ] * scaleX + offset;
  15938. cpy = outline[ i ++ ] * scaleY;
  15939. cpx1 = outline[ i ++ ] * scaleX + offset;
  15940. cpy1 = outline[ i ++ ] * scaleY;
  15941. cpx2 = outline[ i ++ ] * scaleX + offset;
  15942. cpy2 = outline[ i ++ ] * scaleY;
  15943. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  15944. laste = pts[ pts.length - 1 ];
  15945. if ( laste ) {
  15946. cpx0 = laste.x;
  15947. cpy0 = laste.y;
  15948. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  15949. var t = i2 / divisions;
  15950. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  15951. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  15952. }
  15953. }
  15954. break;
  15955. }
  15956. }
  15957. }
  15958. return { offset: glyph.ha * scale, path:path };
  15959. }
  15960. };
  15961. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  15962. // Parameters
  15963. parameters = parameters || {};
  15964. var size = parameters.size !== undefined ? parameters.size : 100;
  15965. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  15966. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  15967. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  15968. var style = parameters.style !== undefined ? parameters.style : 'normal';
  15969. THREE.FontUtils.size = size;
  15970. THREE.FontUtils.divisions = curveSegments;
  15971. THREE.FontUtils.face = font;
  15972. THREE.FontUtils.weight = weight;
  15973. THREE.FontUtils.style = style;
  15974. // Get a Font data json object
  15975. var data = THREE.FontUtils.drawText( text );
  15976. var paths = data.paths;
  15977. var shapes = [];
  15978. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  15979. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  15980. }
  15981. return shapes;
  15982. };
  15983. /**
  15984. * This code is a quick port of code written in C++ which was submitted to
  15985. * flipcode.com by John W. Ratcliff // July 22, 2000
  15986. * See original code and more information here:
  15987. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  15988. *
  15989. * ported to actionscript by Zevan Rosser
  15990. * www.actionsnippet.com
  15991. *
  15992. * ported to javascript by Joshua Koo
  15993. * http://www.lab4games.net/zz85/blog
  15994. *
  15995. */
  15996. ( function ( namespace ) {
  15997. var EPSILON = 0.0000000001;
  15998. // takes in an contour array and returns
  15999. var process = function ( contour, indices ) {
  16000. var n = contour.length;
  16001. if ( n < 3 ) return null;
  16002. var result = [],
  16003. verts = [],
  16004. vertIndices = [];
  16005. /* we want a counter-clockwise polygon in verts */
  16006. var u, v, w;
  16007. if ( area( contour ) > 0.0 ) {
  16008. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  16009. } else {
  16010. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  16011. }
  16012. var nv = n;
  16013. /* remove nv - 2 vertices, creating 1 triangle every time */
  16014. var count = 2 * nv; /* error detection */
  16015. for ( v = nv - 1; nv > 2; ) {
  16016. /* if we loop, it is probably a non-simple polygon */
  16017. if ( ( count -- ) <= 0 ) {
  16018. //** Triangulate: ERROR - probable bad polygon!
  16019. //throw ( "Warning, unable to triangulate polygon!" );
  16020. //return null;
  16021. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  16022. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  16023. if ( indices ) return vertIndices;
  16024. return result;
  16025. }
  16026. /* three consecutive vertices in current polygon, <u,v,w> */
  16027. u = v; if ( nv <= u ) u = 0; /* previous */
  16028. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  16029. w = v + 1; if ( nv <= w ) w = 0; /* next */
  16030. if ( snip( contour, u, v, w, nv, verts ) ) {
  16031. var a, b, c, s, t;
  16032. /* true names of the vertices */
  16033. a = verts[ u ];
  16034. b = verts[ v ];
  16035. c = verts[ w ];
  16036. /* output Triangle */
  16037. result.push( [ contour[ a ],
  16038. contour[ b ],
  16039. contour[ c ] ] );
  16040. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  16041. /* remove v from the remaining polygon */
  16042. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  16043. verts[ s ] = verts[ t ];
  16044. }
  16045. nv --;
  16046. /* reset error detection counter */
  16047. count = 2 * nv;
  16048. }
  16049. }
  16050. if ( indices ) return vertIndices;
  16051. return result;
  16052. };
  16053. // calculate area of the contour polygon
  16054. var area = function ( contour ) {
  16055. var n = contour.length;
  16056. var a = 0.0;
  16057. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  16058. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  16059. }
  16060. return a * 0.5;
  16061. };
  16062. var snip = function ( contour, u, v, w, n, verts ) {
  16063. var p;
  16064. var ax, ay, bx, by;
  16065. var cx, cy, px, py;
  16066. ax = contour[ verts[ u ] ].x;
  16067. ay = contour[ verts[ u ] ].y;
  16068. bx = contour[ verts[ v ] ].x;
  16069. by = contour[ verts[ v ] ].y;
  16070. cx = contour[ verts[ w ] ].x;
  16071. cy = contour[ verts[ w ] ].y;
  16072. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  16073. var aX, aY, bX, bY, cX, cY;
  16074. var apx, apy, bpx, bpy, cpx, cpy;
  16075. var cCROSSap, bCROSScp, aCROSSbp;
  16076. aX = cx - bx; aY = cy - by;
  16077. bX = ax - cx; bY = ay - cy;
  16078. cX = bx - ax; cY = by - ay;
  16079. for ( p = 0; p < n; p ++ ) {
  16080. px = contour[ verts[ p ] ].x;
  16081. py = contour[ verts[ p ] ].y;
  16082. if ( ( ( px === ax ) && ( py === ay ) ) ||
  16083. ( ( px === bx ) && ( py === by ) ) ||
  16084. ( ( px === cx ) && ( py === cy ) ) ) continue;
  16085. apx = px - ax; apy = py - ay;
  16086. bpx = px - bx; bpy = py - by;
  16087. cpx = px - cx; cpy = py - cy;
  16088. // see if p is inside triangle abc
  16089. aCROSSbp = aX * bpy - aY * bpx;
  16090. cCROSSap = cX * apy - cY * apx;
  16091. bCROSScp = bX * cpy - bY * cpx;
  16092. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  16093. }
  16094. return true;
  16095. };
  16096. namespace.Triangulate = process;
  16097. namespace.Triangulate.area = area;
  16098. return namespace;
  16099. } )( THREE.FontUtils );
  16100. // To use the typeface.js face files, hook up the API
  16101. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  16102. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  16103. // File:src/extras/audio/Audio.js
  16104. /**
  16105. * @author mrdoob / http://mrdoob.com/
  16106. */
  16107. THREE.Audio = function ( listener ) {
  16108. THREE.Object3D.call( this );
  16109. this.type = 'Audio';
  16110. this.context = listener.context;
  16111. this.source = this.context.createBufferSource();
  16112. this.source.onended = this.onEnded.bind(this);
  16113. this.gain = this.context.createGain();
  16114. this.gain.connect( this.context.destination );
  16115. this.panner = this.context.createPanner();
  16116. this.panner.connect( this.gain );
  16117. this.autoplay = false;
  16118. this.startTime = 0;
  16119. this.isPlaying = false;
  16120. };
  16121. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  16122. THREE.Audio.prototype.constructor = THREE.Audio;
  16123. THREE.Audio.prototype.load = function ( file ) {
  16124. var scope = this;
  16125. var request = new XMLHttpRequest();
  16126. request.open( 'GET', file, true );
  16127. request.responseType = 'arraybuffer';
  16128. request.onload = function ( e ) {
  16129. scope.context.decodeAudioData( this.response, function ( buffer ) {
  16130. scope.source.buffer = buffer;
  16131. if( scope.autoplay ) scope.play();
  16132. } );
  16133. };
  16134. request.send();
  16135. return this;
  16136. };
  16137. THREE.Audio.prototype.play = function () {
  16138. if ( this.isPlaying === true ) {
  16139. console.warn( 'THREE.Audio: Audio is already playing.' );
  16140. return;
  16141. }
  16142. var source = this.context.createBufferSource();
  16143. source.buffer = this.source.buffer;
  16144. source.loop = this.source.loop;
  16145. source.onended = this.source.onended;
  16146. source.connect( this.panner );
  16147. source.start( 0, this.startTime );
  16148. this.isPlaying = true;
  16149. this.source = source;
  16150. };
  16151. THREE.Audio.prototype.pause = function () {
  16152. this.source.stop();
  16153. this.startTime = this.context.currentTime;
  16154. };
  16155. THREE.Audio.prototype.stop = function () {
  16156. this.source.stop();
  16157. this.startTime = 0;
  16158. };
  16159. THREE.Audio.prototype.onEnded = function() {
  16160. this.isPlaying = false;
  16161. };
  16162. THREE.Audio.prototype.setLoop = function ( value ) {
  16163. this.source.loop = value;
  16164. };
  16165. THREE.Audio.prototype.setRefDistance = function ( value ) {
  16166. this.panner.refDistance = value;
  16167. };
  16168. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  16169. this.panner.rolloffFactor = value;
  16170. };
  16171. THREE.Audio.prototype.setVolume = function ( value ) {
  16172. this.gain.gain.value = value;
  16173. };
  16174. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  16175. var position = new THREE.Vector3();
  16176. return function updateMatrixWorld( force ) {
  16177. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16178. position.setFromMatrixPosition( this.matrixWorld );
  16179. this.panner.setPosition( position.x, position.y, position.z );
  16180. };
  16181. } )();
  16182. // File:src/extras/audio/AudioListener.js
  16183. /**
  16184. * @author mrdoob / http://mrdoob.com/
  16185. */
  16186. THREE.AudioListener = function () {
  16187. THREE.Object3D.call( this );
  16188. this.type = 'AudioListener';
  16189. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  16190. };
  16191. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  16192. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  16193. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  16194. var position = new THREE.Vector3();
  16195. var quaternion = new THREE.Quaternion();
  16196. var scale = new THREE.Vector3();
  16197. var orientation = new THREE.Vector3();
  16198. return function updateMatrixWorld( force ) {
  16199. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  16200. var listener = this.context.listener;
  16201. var up = this.up;
  16202. this.matrixWorld.decompose( position, quaternion, scale );
  16203. orientation.set( 0, 0, -1 ).applyQuaternion( quaternion );
  16204. listener.setPosition( position.x, position.y, position.z );
  16205. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  16206. };
  16207. } )();
  16208. // File:src/extras/core/Curve.js
  16209. /**
  16210. * @author zz85 / http://www.lab4games.net/zz85/blog
  16211. * Extensible curve object
  16212. *
  16213. * Some common of Curve methods
  16214. * .getPoint(t), getTangent(t)
  16215. * .getPointAt(u), getTagentAt(u)
  16216. * .getPoints(), .getSpacedPoints()
  16217. * .getLength()
  16218. * .updateArcLengths()
  16219. *
  16220. * This following classes subclasses THREE.Curve:
  16221. *
  16222. * -- 2d classes --
  16223. * THREE.LineCurve
  16224. * THREE.QuadraticBezierCurve
  16225. * THREE.CubicBezierCurve
  16226. * THREE.SplineCurve
  16227. * THREE.ArcCurve
  16228. * THREE.EllipseCurve
  16229. *
  16230. * -- 3d classes --
  16231. * THREE.LineCurve3
  16232. * THREE.QuadraticBezierCurve3
  16233. * THREE.CubicBezierCurve3
  16234. * THREE.SplineCurve3
  16235. * THREE.ClosedSplineCurve3
  16236. *
  16237. * A series of curves can be represented as a THREE.CurvePath
  16238. *
  16239. **/
  16240. /**************************************************************
  16241. * Abstract Curve base class
  16242. **************************************************************/
  16243. THREE.Curve = function () {
  16244. };
  16245. // Virtual base class method to overwrite and implement in subclasses
  16246. // - t [0 .. 1]
  16247. THREE.Curve.prototype.getPoint = function ( t ) {
  16248. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  16249. return null;
  16250. };
  16251. // Get point at relative position in curve according to arc length
  16252. // - u [0 .. 1]
  16253. THREE.Curve.prototype.getPointAt = function ( u ) {
  16254. var t = this.getUtoTmapping( u );
  16255. return this.getPoint( t );
  16256. };
  16257. // Get sequence of points using getPoint( t )
  16258. THREE.Curve.prototype.getPoints = function ( divisions ) {
  16259. if ( ! divisions ) divisions = 5;
  16260. var d, pts = [];
  16261. for ( d = 0; d <= divisions; d ++ ) {
  16262. pts.push( this.getPoint( d / divisions ) );
  16263. }
  16264. return pts;
  16265. };
  16266. // Get sequence of points using getPointAt( u )
  16267. THREE.Curve.prototype.getSpacedPoints = function ( divisions ) {
  16268. if ( ! divisions ) divisions = 5;
  16269. var d, pts = [];
  16270. for ( d = 0; d <= divisions; d ++ ) {
  16271. pts.push( this.getPointAt( d / divisions ) );
  16272. }
  16273. return pts;
  16274. };
  16275. // Get total curve arc length
  16276. THREE.Curve.prototype.getLength = function () {
  16277. var lengths = this.getLengths();
  16278. return lengths[ lengths.length - 1 ];
  16279. };
  16280. // Get list of cumulative segment lengths
  16281. THREE.Curve.prototype.getLengths = function ( divisions ) {
  16282. if ( ! divisions ) divisions = (this.__arcLengthDivisions) ? (this.__arcLengthDivisions) : 200;
  16283. if ( this.cacheArcLengths
  16284. && ( this.cacheArcLengths.length === divisions + 1 )
  16285. && ! this.needsUpdate) {
  16286. //console.log( "cached", this.cacheArcLengths );
  16287. return this.cacheArcLengths;
  16288. }
  16289. this.needsUpdate = false;
  16290. var cache = [];
  16291. var current, last = this.getPoint( 0 );
  16292. var p, sum = 0;
  16293. cache.push( 0 );
  16294. for ( p = 1; p <= divisions; p ++ ) {
  16295. current = this.getPoint ( p / divisions );
  16296. sum += current.distanceTo( last );
  16297. cache.push( sum );
  16298. last = current;
  16299. }
  16300. this.cacheArcLengths = cache;
  16301. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  16302. };
  16303. THREE.Curve.prototype.updateArcLengths = function() {
  16304. this.needsUpdate = true;
  16305. this.getLengths();
  16306. };
  16307. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  16308. THREE.Curve.prototype.getUtoTmapping = function ( u, distance ) {
  16309. var arcLengths = this.getLengths();
  16310. var i = 0, il = arcLengths.length;
  16311. var targetArcLength; // The targeted u distance value to get
  16312. if ( distance ) {
  16313. targetArcLength = distance;
  16314. } else {
  16315. targetArcLength = u * arcLengths[ il - 1 ];
  16316. }
  16317. //var time = Date.now();
  16318. // binary search for the index with largest value smaller than target u distance
  16319. var low = 0, high = il - 1, comparison;
  16320. while ( low <= high ) {
  16321. 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
  16322. comparison = arcLengths[ i ] - targetArcLength;
  16323. if ( comparison < 0 ) {
  16324. low = i + 1;
  16325. } else if ( comparison > 0 ) {
  16326. high = i - 1;
  16327. } else {
  16328. high = i;
  16329. break;
  16330. // DONE
  16331. }
  16332. }
  16333. i = high;
  16334. //console.log('b' , i, low, high, Date.now()- time);
  16335. if ( arcLengths[ i ] === targetArcLength ) {
  16336. var t = i / ( il - 1 );
  16337. return t;
  16338. }
  16339. // we could get finer grain at lengths, or use simple interpolation between two points
  16340. var lengthBefore = arcLengths[ i ];
  16341. var lengthAfter = arcLengths[ i + 1 ];
  16342. var segmentLength = lengthAfter - lengthBefore;
  16343. // determine where we are between the 'before' and 'after' points
  16344. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  16345. // add that fractional amount to t
  16346. var t = ( i + segmentFraction ) / ( il - 1 );
  16347. return t;
  16348. };
  16349. // Returns a unit vector tangent at t
  16350. // In case any sub curve does not implement its tangent derivation,
  16351. // 2 points a small delta apart will be used to find its gradient
  16352. // which seems to give a reasonable approximation
  16353. THREE.Curve.prototype.getTangent = function( t ) {
  16354. var delta = 0.0001;
  16355. var t1 = t - delta;
  16356. var t2 = t + delta;
  16357. // Capping in case of danger
  16358. if ( t1 < 0 ) t1 = 0;
  16359. if ( t2 > 1 ) t2 = 1;
  16360. var pt1 = this.getPoint( t1 );
  16361. var pt2 = this.getPoint( t2 );
  16362. var vec = pt2.clone().sub(pt1);
  16363. return vec.normalize();
  16364. };
  16365. THREE.Curve.prototype.getTangentAt = function ( u ) {
  16366. var t = this.getUtoTmapping( u );
  16367. return this.getTangent( t );
  16368. };
  16369. /**************************************************************
  16370. * Utils
  16371. **************************************************************/
  16372. THREE.Curve.Utils = {
  16373. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  16374. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  16375. },
  16376. // Puay Bing, thanks for helping with this derivative!
  16377. tangentCubicBezier: function (t, p0, p1, p2, p3 ) {
  16378. return - 3 * p0 * (1 - t) * (1 - t) +
  16379. 3 * p1 * (1 - t) * (1 - t) - 6 * t * p1 * (1 - t) +
  16380. 6 * t * p2 * (1 - t) - 3 * t * t * p2 +
  16381. 3 * t * t * p3;
  16382. },
  16383. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  16384. // To check if my formulas are correct
  16385. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  16386. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  16387. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  16388. var h11 = 3 * t * t - 2 * t; // t3 − t2
  16389. return h00 + h10 + h01 + h11;
  16390. },
  16391. // Catmull-Rom
  16392. interpolate: function( p0, p1, p2, p3, t ) {
  16393. var v0 = ( p2 - p0 ) * 0.5;
  16394. var v1 = ( p3 - p1 ) * 0.5;
  16395. var t2 = t * t;
  16396. var t3 = t * t2;
  16397. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  16398. }
  16399. };
  16400. // TODO: Transformation for Curves?
  16401. /**************************************************************
  16402. * 3D Curves
  16403. **************************************************************/
  16404. // A Factory method for creating new curve subclasses
  16405. THREE.Curve.create = function ( constructor, getPointFunc ) {
  16406. constructor.prototype = Object.create( THREE.Curve.prototype );
  16407. constructor.prototype.constructor = constructor;
  16408. constructor.prototype.getPoint = getPointFunc;
  16409. return constructor;
  16410. };
  16411. // File:src/extras/core/CurvePath.js
  16412. /**
  16413. * @author zz85 / http://www.lab4games.net/zz85/blog
  16414. *
  16415. **/
  16416. /**************************************************************
  16417. * Curved Path - a curve path is simply a array of connected
  16418. * curves, but retains the api of a curve
  16419. **************************************************************/
  16420. THREE.CurvePath = function () {
  16421. this.curves = [];
  16422. this.bends = [];
  16423. this.autoClose = false; // Automatically closes the path
  16424. };
  16425. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  16426. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  16427. THREE.CurvePath.prototype.add = function ( curve ) {
  16428. this.curves.push( curve );
  16429. };
  16430. THREE.CurvePath.prototype.checkConnection = function() {
  16431. // TODO
  16432. // If the ending of curve is not connected to the starting
  16433. // or the next curve, then, this is not a real path
  16434. };
  16435. THREE.CurvePath.prototype.closePath = function() {
  16436. // TODO Test
  16437. // and verify for vector3 (needs to implement equals)
  16438. // Add a line curve if start and end of lines are not connected
  16439. var startPoint = this.curves[0].getPoint(0);
  16440. var endPoint = this.curves[this.curves.length - 1].getPoint(1);
  16441. if (! startPoint.equals(endPoint)) {
  16442. this.curves.push( new THREE.LineCurve(endPoint, startPoint) );
  16443. }
  16444. };
  16445. // To get accurate point with reference to
  16446. // entire path distance at time t,
  16447. // following has to be done:
  16448. // 1. Length of each sub path have to be known
  16449. // 2. Locate and identify type of curve
  16450. // 3. Get t for the curve
  16451. // 4. Return curve.getPointAt(t')
  16452. THREE.CurvePath.prototype.getPoint = function( t ) {
  16453. var d = t * this.getLength();
  16454. var curveLengths = this.getCurveLengths();
  16455. var i = 0, diff, curve;
  16456. // To think about boundaries points.
  16457. while ( i < curveLengths.length ) {
  16458. if ( curveLengths[ i ] >= d ) {
  16459. diff = curveLengths[ i ] - d;
  16460. curve = this.curves[ i ];
  16461. var u = 1 - diff / curve.getLength();
  16462. return curve.getPointAt( u );
  16463. }
  16464. i ++;
  16465. }
  16466. return null;
  16467. // loop where sum != 0, sum > d , sum+1 <d
  16468. };
  16469. /*
  16470. THREE.CurvePath.prototype.getTangent = function( t ) {
  16471. };*/
  16472. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  16473. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  16474. // getPoint() depends on getLength
  16475. THREE.CurvePath.prototype.getLength = function() {
  16476. var lens = this.getCurveLengths();
  16477. return lens[ lens.length - 1 ];
  16478. };
  16479. // Compute lengths and cache them
  16480. // We cannot overwrite getLengths() because UtoT mapping uses it.
  16481. THREE.CurvePath.prototype.getCurveLengths = function() {
  16482. // We use cache values if curves and cache array are same length
  16483. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  16484. return this.cacheLengths;
  16485. }
  16486. // Get length of sub-curve
  16487. // Push sums into cached array
  16488. var lengths = [], sums = 0;
  16489. var i, il = this.curves.length;
  16490. for ( i = 0; i < il; i ++ ) {
  16491. sums += this.curves[ i ].getLength();
  16492. lengths.push( sums );
  16493. }
  16494. this.cacheLengths = lengths;
  16495. return lengths;
  16496. };
  16497. // Returns min and max coordinates
  16498. THREE.CurvePath.prototype.getBoundingBox = function () {
  16499. var points = this.getPoints();
  16500. var maxX, maxY, maxZ;
  16501. var minX, minY, minZ;
  16502. maxX = maxY = Number.NEGATIVE_INFINITY;
  16503. minX = minY = Number.POSITIVE_INFINITY;
  16504. var p, i, il, sum;
  16505. var v3 = points[0] instanceof THREE.Vector3;
  16506. sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  16507. for ( i = 0, il = points.length; i < il; i ++ ) {
  16508. p = points[ i ];
  16509. if ( p.x > maxX ) maxX = p.x;
  16510. else if ( p.x < minX ) minX = p.x;
  16511. if ( p.y > maxY ) maxY = p.y;
  16512. else if ( p.y < minY ) minY = p.y;
  16513. if ( v3 ) {
  16514. if ( p.z > maxZ ) maxZ = p.z;
  16515. else if ( p.z < minZ ) minZ = p.z;
  16516. }
  16517. sum.add( p );
  16518. }
  16519. var ret = {
  16520. minX: minX,
  16521. minY: minY,
  16522. maxX: maxX,
  16523. maxY: maxY
  16524. };
  16525. if ( v3 ) {
  16526. ret.maxZ = maxZ;
  16527. ret.minZ = minZ;
  16528. }
  16529. return ret;
  16530. };
  16531. /**************************************************************
  16532. * Create Geometries Helpers
  16533. **************************************************************/
  16534. /// Generate geometry from path points (for Line or Points objects)
  16535. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  16536. var pts = this.getPoints( divisions, true );
  16537. return this.createGeometry( pts );
  16538. };
  16539. // Generate geometry from equidistant sampling along the path
  16540. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  16541. var pts = this.getSpacedPoints( divisions, true );
  16542. return this.createGeometry( pts );
  16543. };
  16544. THREE.CurvePath.prototype.createGeometry = function( points ) {
  16545. var geometry = new THREE.Geometry();
  16546. for ( var i = 0; i < points.length; i ++ ) {
  16547. geometry.vertices.push( new THREE.Vector3( points[ i ].x, points[ i ].y, points[ i ].z || 0) );
  16548. }
  16549. return geometry;
  16550. };
  16551. /**************************************************************
  16552. * Bend / Wrap Helper Methods
  16553. **************************************************************/
  16554. // Wrap path / Bend modifiers?
  16555. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  16556. this.bends.push( bendpath );
  16557. };
  16558. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  16559. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  16560. var i, il;
  16561. if ( ! bends ) {
  16562. bends = this.bends;
  16563. }
  16564. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16565. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16566. }
  16567. return oldPts;
  16568. };
  16569. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  16570. var oldPts = this.getSpacedPoints( segments );
  16571. var i, il;
  16572. if ( ! bends ) {
  16573. bends = this.bends;
  16574. }
  16575. for ( i = 0, il = bends.length; i < il; i ++ ) {
  16576. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  16577. }
  16578. return oldPts;
  16579. };
  16580. // This returns getPoints() bend/wrapped around the contour of a path.
  16581. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  16582. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  16583. var bounds = this.getBoundingBox();
  16584. var i, il, p, oldX, oldY, xNorm;
  16585. for ( i = 0, il = oldPts.length; i < il; i ++ ) {
  16586. p = oldPts[ i ];
  16587. oldX = p.x;
  16588. oldY = p.y;
  16589. xNorm = oldX / bounds.maxX;
  16590. // If using actual distance, for length > path, requires line extrusions
  16591. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  16592. xNorm = path.getUtoTmapping( xNorm, oldX );
  16593. // check for out of bounds?
  16594. var pathPt = path.getPoint( xNorm );
  16595. var normal = path.getTangent( xNorm );
  16596. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  16597. p.x = pathPt.x + normal.x;
  16598. p.y = pathPt.y + normal.y;
  16599. }
  16600. return oldPts;
  16601. };
  16602. // File:src/extras/core/Gyroscope.js
  16603. /**
  16604. * @author alteredq / http://alteredqualia.com/
  16605. */
  16606. THREE.Gyroscope = function () {
  16607. THREE.Object3D.call( this );
  16608. };
  16609. THREE.Gyroscope.prototype = Object.create( THREE.Object3D.prototype );
  16610. THREE.Gyroscope.prototype.constructor = THREE.Gyroscope;
  16611. THREE.Gyroscope.prototype.updateMatrixWorld = ( function () {
  16612. var translationObject = new THREE.Vector3();
  16613. var quaternionObject = new THREE.Quaternion();
  16614. var scaleObject = new THREE.Vector3();
  16615. var translationWorld = new THREE.Vector3();
  16616. var quaternionWorld = new THREE.Quaternion();
  16617. var scaleWorld = new THREE.Vector3();
  16618. return function updateMatrixWorld( force ) {
  16619. this.matrixAutoUpdate && this.updateMatrix();
  16620. // update matrixWorld
  16621. if ( this.matrixWorldNeedsUpdate || force ) {
  16622. if ( this.parent ) {
  16623. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  16624. this.matrixWorld.decompose( translationWorld, quaternionWorld, scaleWorld );
  16625. this.matrix.decompose( translationObject, quaternionObject, scaleObject );
  16626. this.matrixWorld.compose( translationWorld, quaternionObject, scaleWorld );
  16627. } else {
  16628. this.matrixWorld.copy( this.matrix );
  16629. }
  16630. this.matrixWorldNeedsUpdate = false;
  16631. force = true;
  16632. }
  16633. // update children
  16634. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  16635. this.children[ i ].updateMatrixWorld( force );
  16636. }
  16637. };
  16638. }() );
  16639. // File:src/extras/core/Path.js
  16640. /**
  16641. * @author zz85 / http://www.lab4games.net/zz85/blog
  16642. * Creates free form 2d path using series of points, lines or curves.
  16643. *
  16644. **/
  16645. THREE.Path = function ( points ) {
  16646. THREE.CurvePath.call(this);
  16647. this.actions = [];
  16648. if ( points ) {
  16649. this.fromPoints( points );
  16650. }
  16651. };
  16652. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  16653. THREE.Path.prototype.constructor = THREE.Path;
  16654. THREE.PathActions = {
  16655. MOVE_TO: 'moveTo',
  16656. LINE_TO: 'lineTo',
  16657. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  16658. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  16659. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  16660. ARC: 'arc', // Circle
  16661. ELLIPSE: 'ellipse'
  16662. };
  16663. // TODO Clean up PATH API
  16664. // Create path using straight lines to connect all points
  16665. // - vectors: array of Vector2
  16666. THREE.Path.prototype.fromPoints = function ( vectors ) {
  16667. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  16668. for ( var v = 1, vlen = vectors.length; v < vlen; v ++ ) {
  16669. this.lineTo( vectors[ v ].x, vectors[ v ].y );
  16670. }
  16671. };
  16672. // startPath() endPath()?
  16673. THREE.Path.prototype.moveTo = function ( x, y ) {
  16674. var args = Array.prototype.slice.call( arguments );
  16675. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  16676. };
  16677. THREE.Path.prototype.lineTo = function ( x, y ) {
  16678. var args = Array.prototype.slice.call( arguments );
  16679. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16680. var x0 = lastargs[ lastargs.length - 2 ];
  16681. var y0 = lastargs[ lastargs.length - 1 ];
  16682. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  16683. this.curves.push( curve );
  16684. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  16685. };
  16686. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  16687. var args = Array.prototype.slice.call( arguments );
  16688. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16689. var x0 = lastargs[ lastargs.length - 2 ];
  16690. var y0 = lastargs[ lastargs.length - 1 ];
  16691. var curve = new THREE.QuadraticBezierCurve( new THREE.Vector2( x0, y0 ),
  16692. new THREE.Vector2( aCPx, aCPy ),
  16693. new THREE.Vector2( aX, aY ) );
  16694. this.curves.push( curve );
  16695. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  16696. };
  16697. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y,
  16698. aCP2x, aCP2y,
  16699. aX, aY ) {
  16700. var args = Array.prototype.slice.call( arguments );
  16701. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16702. var x0 = lastargs[ lastargs.length - 2 ];
  16703. var y0 = lastargs[ lastargs.length - 1 ];
  16704. var curve = new THREE.CubicBezierCurve( new THREE.Vector2( x0, y0 ),
  16705. new THREE.Vector2( aCP1x, aCP1y ),
  16706. new THREE.Vector2( aCP2x, aCP2y ),
  16707. new THREE.Vector2( aX, aY ) );
  16708. this.curves.push( curve );
  16709. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  16710. };
  16711. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  16712. var args = Array.prototype.slice.call( arguments );
  16713. var lastargs = this.actions[ this.actions.length - 1 ].args;
  16714. var x0 = lastargs[ lastargs.length - 2 ];
  16715. var y0 = lastargs[ lastargs.length - 1 ];
  16716. //---
  16717. var npts = [ new THREE.Vector2( x0, y0 ) ];
  16718. Array.prototype.push.apply( npts, pts );
  16719. var curve = new THREE.SplineCurve( npts );
  16720. this.curves.push( curve );
  16721. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  16722. };
  16723. // FUTURE: Change the API or follow canvas API?
  16724. THREE.Path.prototype.arc = function ( aX, aY, aRadius,
  16725. aStartAngle, aEndAngle, aClockwise ) {
  16726. var lastargs = this.actions[ this.actions.length - 1].args;
  16727. var x0 = lastargs[ lastargs.length - 2 ];
  16728. var y0 = lastargs[ lastargs.length - 1 ];
  16729. this.absarc(aX + x0, aY + y0, aRadius,
  16730. aStartAngle, aEndAngle, aClockwise );
  16731. };
  16732. THREE.Path.prototype.absarc = function ( aX, aY, aRadius,
  16733. aStartAngle, aEndAngle, aClockwise ) {
  16734. this.absellipse(aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise);
  16735. };
  16736. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius,
  16737. aStartAngle, aEndAngle, aClockwise ) {
  16738. var lastargs = this.actions[ this.actions.length - 1].args;
  16739. var x0 = lastargs[ lastargs.length - 2 ];
  16740. var y0 = lastargs[ lastargs.length - 1 ];
  16741. this.absellipse(aX + x0, aY + y0, xRadius, yRadius,
  16742. aStartAngle, aEndAngle, aClockwise );
  16743. };
  16744. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius,
  16745. aStartAngle, aEndAngle, aClockwise ) {
  16746. var args = Array.prototype.slice.call( arguments );
  16747. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius,
  16748. aStartAngle, aEndAngle, aClockwise );
  16749. this.curves.push( curve );
  16750. var lastPoint = curve.getPoint(1);
  16751. args.push(lastPoint.x);
  16752. args.push(lastPoint.y);
  16753. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  16754. };
  16755. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  16756. if ( ! divisions ) divisions = 40;
  16757. var points = [];
  16758. for ( var i = 0; i < divisions; i ++ ) {
  16759. points.push( this.getPoint( i / divisions ) );
  16760. //if( !this.getPoint( i / divisions ) ) throw "DIE";
  16761. }
  16762. // if ( closedPath ) {
  16763. //
  16764. // points.push( points[ 0 ] );
  16765. //
  16766. // }
  16767. return points;
  16768. };
  16769. /* Return an array of vectors based on contour of the path */
  16770. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  16771. if (this.useSpacedPoints) {
  16772. return this.getSpacedPoints( divisions, closedPath );
  16773. }
  16774. divisions = divisions || 12;
  16775. var points = [];
  16776. var i, il, item, action, args;
  16777. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  16778. laste, j,
  16779. t, tx, ty;
  16780. for ( i = 0, il = this.actions.length; i < il; i ++ ) {
  16781. item = this.actions[ i ];
  16782. action = item.action;
  16783. args = item.args;
  16784. switch ( action ) {
  16785. case THREE.PathActions.MOVE_TO:
  16786. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16787. break;
  16788. case THREE.PathActions.LINE_TO:
  16789. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  16790. break;
  16791. case THREE.PathActions.QUADRATIC_CURVE_TO:
  16792. cpx = args[ 2 ];
  16793. cpy = args[ 3 ];
  16794. cpx1 = args[ 0 ];
  16795. cpy1 = args[ 1 ];
  16796. if ( points.length > 0 ) {
  16797. laste = points[ points.length - 1 ];
  16798. cpx0 = laste.x;
  16799. cpy0 = laste.y;
  16800. } else {
  16801. laste = this.actions[ i - 1 ].args;
  16802. cpx0 = laste[ laste.length - 2 ];
  16803. cpy0 = laste[ laste.length - 1 ];
  16804. }
  16805. for ( j = 1; j <= divisions; j ++ ) {
  16806. t = j / divisions;
  16807. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  16808. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  16809. points.push( new THREE.Vector2( tx, ty ) );
  16810. }
  16811. break;
  16812. case THREE.PathActions.BEZIER_CURVE_TO:
  16813. cpx = args[ 4 ];
  16814. cpy = args[ 5 ];
  16815. cpx1 = args[ 0 ];
  16816. cpy1 = args[ 1 ];
  16817. cpx2 = args[ 2 ];
  16818. cpy2 = args[ 3 ];
  16819. if ( points.length > 0 ) {
  16820. laste = points[ points.length - 1 ];
  16821. cpx0 = laste.x;
  16822. cpy0 = laste.y;
  16823. } else {
  16824. laste = this.actions[ i - 1 ].args;
  16825. cpx0 = laste[ laste.length - 2 ];
  16826. cpy0 = laste[ laste.length - 1 ];
  16827. }
  16828. for ( j = 1; j <= divisions; j ++ ) {
  16829. t = j / divisions;
  16830. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  16831. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  16832. points.push( new THREE.Vector2( tx, ty ) );
  16833. }
  16834. break;
  16835. case THREE.PathActions.CSPLINE_THRU:
  16836. laste = this.actions[ i - 1 ].args;
  16837. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  16838. var spts = [ last ];
  16839. var n = divisions * args[ 0 ].length;
  16840. spts = spts.concat( args[ 0 ] );
  16841. var spline = new THREE.SplineCurve( spts );
  16842. for ( j = 1; j <= n; j ++ ) {
  16843. points.push( spline.getPointAt( j / n ) ) ;
  16844. }
  16845. break;
  16846. case THREE.PathActions.ARC:
  16847. var aX = args[ 0 ], aY = args[ 1 ],
  16848. aRadius = args[ 2 ],
  16849. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  16850. aClockwise = !! args[ 5 ];
  16851. var deltaAngle = aEndAngle - aStartAngle;
  16852. var angle;
  16853. var tdivisions = divisions * 2;
  16854. for ( j = 1; j <= tdivisions; j ++ ) {
  16855. t = j / tdivisions;
  16856. if ( ! aClockwise ) {
  16857. t = 1 - t;
  16858. }
  16859. angle = aStartAngle + t * deltaAngle;
  16860. tx = aX + aRadius * Math.cos( angle );
  16861. ty = aY + aRadius * Math.sin( angle );
  16862. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16863. points.push( new THREE.Vector2( tx, ty ) );
  16864. }
  16865. //console.log(points);
  16866. break;
  16867. case THREE.PathActions.ELLIPSE:
  16868. var aX = args[ 0 ], aY = args[ 1 ],
  16869. xRadius = args[ 2 ],
  16870. yRadius = args[ 3 ],
  16871. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  16872. aClockwise = !! args[ 6 ];
  16873. var deltaAngle = aEndAngle - aStartAngle;
  16874. var angle;
  16875. var tdivisions = divisions * 2;
  16876. for ( j = 1; j <= tdivisions; j ++ ) {
  16877. t = j / tdivisions;
  16878. if ( ! aClockwise ) {
  16879. t = 1 - t;
  16880. }
  16881. angle = aStartAngle + t * deltaAngle;
  16882. tx = aX + xRadius * Math.cos( angle );
  16883. ty = aY + yRadius * Math.sin( angle );
  16884. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  16885. points.push( new THREE.Vector2( tx, ty ) );
  16886. }
  16887. //console.log(points);
  16888. break;
  16889. } // end switch
  16890. }
  16891. // Normalize to remove the closing point by default.
  16892. var lastPoint = points[ points.length - 1];
  16893. var EPSILON = 0.0000000001;
  16894. if ( Math.abs(lastPoint.x - points[ 0 ].x) < EPSILON &&
  16895. Math.abs(lastPoint.y - points[ 0 ].y) < EPSILON)
  16896. points.splice( points.length - 1, 1);
  16897. if ( closedPath ) {
  16898. points.push( points[ 0 ] );
  16899. }
  16900. return points;
  16901. };
  16902. //
  16903. // Breaks path into shapes
  16904. //
  16905. // Assumptions (if parameter isCCW==true the opposite holds):
  16906. // - solid shapes are defined clockwise (CW)
  16907. // - holes are defined counterclockwise (CCW)
  16908. //
  16909. // If parameter noHoles==true:
  16910. // - all subPaths are regarded as solid shapes
  16911. // - definition order CW/CCW has no relevance
  16912. //
  16913. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  16914. function extractSubpaths( inActions ) {
  16915. var i, il, item, action, args;
  16916. var subPaths = [], lastPath = new THREE.Path();
  16917. for ( i = 0, il = inActions.length; i < il; i ++ ) {
  16918. item = inActions[ i ];
  16919. args = item.args;
  16920. action = item.action;
  16921. if ( action === THREE.PathActions.MOVE_TO ) {
  16922. if ( lastPath.actions.length !== 0 ) {
  16923. subPaths.push( lastPath );
  16924. lastPath = new THREE.Path();
  16925. }
  16926. }
  16927. lastPath[ action ].apply( lastPath, args );
  16928. }
  16929. if ( lastPath.actions.length !== 0 ) {
  16930. subPaths.push( lastPath );
  16931. }
  16932. // console.log(subPaths);
  16933. return subPaths;
  16934. }
  16935. function toShapesNoHoles( inSubpaths ) {
  16936. var shapes = [];
  16937. for ( var i = 0, il = inSubpaths.length; i < il; i ++ ) {
  16938. var tmpPath = inSubpaths[ i ];
  16939. var tmpShape = new THREE.Shape();
  16940. tmpShape.actions = tmpPath.actions;
  16941. tmpShape.curves = tmpPath.curves;
  16942. shapes.push( tmpShape );
  16943. }
  16944. //console.log("shape", shapes);
  16945. return shapes;
  16946. }
  16947. function isPointInsidePolygon( inPt, inPolygon ) {
  16948. var EPSILON = 0.0000000001;
  16949. var polyLen = inPolygon.length;
  16950. // inPt on polygon contour => immediate success or
  16951. // toggling of inside/outside at every single! intersection point of an edge
  16952. // with the horizontal line through inPt, left of inPt
  16953. // not counting lowerY endpoints of edges and whole edges on that line
  16954. var inside = false;
  16955. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  16956. var edgeLowPt = inPolygon[ p ];
  16957. var edgeHighPt = inPolygon[ q ];
  16958. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  16959. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  16960. if ( Math.abs(edgeDy) > EPSILON ) { // not parallel
  16961. if ( edgeDy < 0 ) {
  16962. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  16963. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  16964. }
  16965. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  16966. if ( inPt.y === edgeLowPt.y ) {
  16967. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  16968. // continue; // no intersection or edgeLowPt => doesn't count !!!
  16969. } else {
  16970. var perpEdge = edgeDy * (inPt.x - edgeLowPt.x) - edgeDx * (inPt.y - edgeLowPt.y);
  16971. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  16972. if ( perpEdge < 0 ) continue;
  16973. inside = ! inside; // true intersection left of inPt
  16974. }
  16975. } else { // parallel or collinear
  16976. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  16977. // edge lies on the same horizontal line as inPt
  16978. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  16979. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  16980. // continue;
  16981. }
  16982. }
  16983. return inside;
  16984. }
  16985. var subPaths = extractSubpaths( this.actions );
  16986. if ( subPaths.length === 0 ) return [];
  16987. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  16988. var solid, tmpPath, tmpShape, shapes = [];
  16989. if ( subPaths.length === 1) {
  16990. tmpPath = subPaths[0];
  16991. tmpShape = new THREE.Shape();
  16992. tmpShape.actions = tmpPath.actions;
  16993. tmpShape.curves = tmpPath.curves;
  16994. shapes.push( tmpShape );
  16995. return shapes;
  16996. }
  16997. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  16998. holesFirst = isCCW ? ! holesFirst : holesFirst;
  16999. // console.log("Holes first", holesFirst);
  17000. var betterShapeHoles = [];
  17001. var newShapes = [];
  17002. var newShapeHoles = [];
  17003. var mainIdx = 0;
  17004. var tmpPoints;
  17005. newShapes[mainIdx] = undefined;
  17006. newShapeHoles[mainIdx] = [];
  17007. var i, il;
  17008. for ( i = 0, il = subPaths.length; i < il; i ++ ) {
  17009. tmpPath = subPaths[ i ];
  17010. tmpPoints = tmpPath.getPoints();
  17011. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  17012. solid = isCCW ? ! solid : solid;
  17013. if ( solid ) {
  17014. if ( (! holesFirst ) && ( newShapes[mainIdx] ) ) mainIdx ++;
  17015. newShapes[mainIdx] = { s: new THREE.Shape(), p: tmpPoints };
  17016. newShapes[mainIdx].s.actions = tmpPath.actions;
  17017. newShapes[mainIdx].s.curves = tmpPath.curves;
  17018. if ( holesFirst ) mainIdx ++;
  17019. newShapeHoles[mainIdx] = [];
  17020. //console.log('cw', i);
  17021. } else {
  17022. newShapeHoles[mainIdx].push( { h: tmpPath, p: tmpPoints[0] } );
  17023. //console.log('ccw', i);
  17024. }
  17025. }
  17026. // only Holes? -> probably all Shapes with wrong orientation
  17027. if ( ! newShapes[0] ) return toShapesNoHoles( subPaths );
  17028. if ( newShapes.length > 1 ) {
  17029. var ambiguous = false;
  17030. var toChange = [];
  17031. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  17032. betterShapeHoles[sIdx] = [];
  17033. }
  17034. for (var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  17035. var sho = newShapeHoles[sIdx];
  17036. for (var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  17037. var ho = sho[hIdx];
  17038. var hole_unassigned = true;
  17039. for (var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  17040. if ( isPointInsidePolygon( ho.p, newShapes[s2Idx].p ) ) {
  17041. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  17042. if ( hole_unassigned ) {
  17043. hole_unassigned = false;
  17044. betterShapeHoles[s2Idx].push( ho );
  17045. } else {
  17046. ambiguous = true;
  17047. }
  17048. }
  17049. }
  17050. if ( hole_unassigned ) { betterShapeHoles[sIdx].push( ho ); }
  17051. }
  17052. }
  17053. // console.log("ambiguous: ", ambiguous);
  17054. if ( toChange.length > 0 ) {
  17055. // console.log("to change: ", toChange);
  17056. if (! ambiguous) newShapeHoles = betterShapeHoles;
  17057. }
  17058. }
  17059. var tmpHoles, j, jl;
  17060. for ( i = 0, il = newShapes.length; i < il; i ++ ) {
  17061. tmpShape = newShapes[i].s;
  17062. shapes.push( tmpShape );
  17063. tmpHoles = newShapeHoles[i];
  17064. for ( j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  17065. tmpShape.holes.push( tmpHoles[j].h );
  17066. }
  17067. }
  17068. //console.log("shape", shapes);
  17069. return shapes;
  17070. };
  17071. // File:src/extras/core/Shape.js
  17072. /**
  17073. * @author zz85 / http://www.lab4games.net/zz85/blog
  17074. * Defines a 2d shape plane using paths.
  17075. **/
  17076. // STEP 1 Create a path.
  17077. // STEP 2 Turn path into shape.
  17078. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  17079. // STEP 3a - Extract points from each shape, turn to vertices
  17080. // STEP 3b - Triangulate each shape, add faces.
  17081. THREE.Shape = function () {
  17082. THREE.Path.apply( this, arguments );
  17083. this.holes = [];
  17084. };
  17085. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  17086. THREE.Shape.prototype.constructor = THREE.Shape;
  17087. // Convenience method to return ExtrudeGeometry
  17088. THREE.Shape.prototype.extrude = function ( options ) {
  17089. var extruded = new THREE.ExtrudeGeometry( this, options );
  17090. return extruded;
  17091. };
  17092. // Convenience method to return ShapeGeometry
  17093. THREE.Shape.prototype.makeGeometry = function ( options ) {
  17094. var geometry = new THREE.ShapeGeometry( this, options );
  17095. return geometry;
  17096. };
  17097. // Get points of holes
  17098. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  17099. var i, il = this.holes.length, holesPts = [];
  17100. for ( i = 0; i < il; i ++ ) {
  17101. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  17102. }
  17103. return holesPts;
  17104. };
  17105. // Get points of holes (spaced by regular distance)
  17106. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  17107. var i, il = this.holes.length, holesPts = [];
  17108. for ( i = 0; i < il; i ++ ) {
  17109. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  17110. }
  17111. return holesPts;
  17112. };
  17113. // Get points of shape and holes (keypoints based on segments parameter)
  17114. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  17115. return {
  17116. shape: this.getTransformedPoints( divisions ),
  17117. holes: this.getPointsHoles( divisions )
  17118. };
  17119. };
  17120. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  17121. if (this.useSpacedPoints) {
  17122. return this.extractAllSpacedPoints(divisions);
  17123. }
  17124. return this.extractAllPoints(divisions);
  17125. };
  17126. //
  17127. // THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  17128. //
  17129. // return {
  17130. //
  17131. // shape: this.transform( bend, divisions ),
  17132. // holes: this.getPointsHoles( divisions, bend )
  17133. //
  17134. // };
  17135. //
  17136. // };
  17137. // Get points of shape and holes (spaced by regular distance)
  17138. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  17139. return {
  17140. shape: this.getTransformedSpacedPoints( divisions ),
  17141. holes: this.getSpacedPointsHoles( divisions )
  17142. };
  17143. };
  17144. /**************************************************************
  17145. * Utils
  17146. **************************************************************/
  17147. THREE.Shape.Utils = {
  17148. triangulateShape: function ( contour, holes ) {
  17149. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  17150. // inOtherPt needs to be collinear to the inSegment
  17151. if ( inSegPt1.x !== inSegPt2.x ) {
  17152. if ( inSegPt1.x < inSegPt2.x ) {
  17153. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  17154. } else {
  17155. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  17156. }
  17157. } else {
  17158. if ( inSegPt1.y < inSegPt2.y ) {
  17159. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  17160. } else {
  17161. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  17162. }
  17163. }
  17164. }
  17165. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  17166. var EPSILON = 0.0000000001;
  17167. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  17168. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  17169. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  17170. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  17171. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  17172. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  17173. if ( Math.abs(limit) > EPSILON ) { // not parallel
  17174. var perpSeg2;
  17175. if ( limit > 0 ) {
  17176. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  17177. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17178. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  17179. } else {
  17180. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  17181. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  17182. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  17183. }
  17184. // i.e. to reduce rounding errors
  17185. // intersection at endpoint of segment#1?
  17186. if ( perpSeg2 === 0 ) {
  17187. if ( ( inExcludeAdjacentSegs ) &&
  17188. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17189. return [ inSeg1Pt1 ];
  17190. }
  17191. if ( perpSeg2 === limit ) {
  17192. if ( ( inExcludeAdjacentSegs ) &&
  17193. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  17194. return [ inSeg1Pt2 ];
  17195. }
  17196. // intersection at endpoint of segment#2?
  17197. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  17198. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  17199. // return real intersection point
  17200. var factorSeg1 = perpSeg2 / limit;
  17201. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  17202. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  17203. } else { // parallel or collinear
  17204. if ( ( perpSeg1 !== 0 ) ||
  17205. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  17206. // they are collinear or degenerate
  17207. var seg1Pt = ( (seg1dx === 0) && (seg1dy === 0) ); // segment1 is just a point?
  17208. var seg2Pt = ( (seg2dx === 0) && (seg2dy === 0) ); // segment2 is just a point?
  17209. // both segments are points
  17210. if ( seg1Pt && seg2Pt ) {
  17211. if ( (inSeg1Pt1.x !== inSeg2Pt1.x) ||
  17212. (inSeg1Pt1.y !== inSeg2Pt1.y) ) return []; // they are distinct points
  17213. return [ inSeg1Pt1 ]; // they are the same point
  17214. }
  17215. // segment#1 is a single point
  17216. if ( seg1Pt ) {
  17217. if (! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  17218. return [ inSeg1Pt1 ];
  17219. }
  17220. // segment#2 is a single point
  17221. if ( seg2Pt ) {
  17222. if (! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  17223. return [ inSeg2Pt1 ];
  17224. }
  17225. // they are collinear segments, which might overlap
  17226. var seg1min, seg1max, seg1minVal, seg1maxVal;
  17227. var seg2min, seg2max, seg2minVal, seg2maxVal;
  17228. if (seg1dx !== 0) { // the segments are NOT on a vertical line
  17229. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  17230. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  17231. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  17232. } else {
  17233. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  17234. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  17235. }
  17236. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  17237. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  17238. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  17239. } else {
  17240. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  17241. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  17242. }
  17243. } else { // the segments are on a vertical line
  17244. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  17245. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  17246. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  17247. } else {
  17248. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  17249. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  17250. }
  17251. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  17252. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  17253. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  17254. } else {
  17255. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  17256. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  17257. }
  17258. }
  17259. if ( seg1minVal <= seg2minVal ) {
  17260. if ( seg1maxVal < seg2minVal ) return [];
  17261. if ( seg1maxVal === seg2minVal ) {
  17262. if ( inExcludeAdjacentSegs ) return [];
  17263. return [ seg2min ];
  17264. }
  17265. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  17266. return [ seg2min, seg2max ];
  17267. } else {
  17268. if ( seg1minVal > seg2maxVal ) return [];
  17269. if ( seg1minVal === seg2maxVal ) {
  17270. if ( inExcludeAdjacentSegs ) return [];
  17271. return [ seg1min ];
  17272. }
  17273. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  17274. return [ seg1min, seg2max ];
  17275. }
  17276. }
  17277. }
  17278. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  17279. // The order of legs is important
  17280. var EPSILON = 0.0000000001;
  17281. // translation of all points, so that Vertex is at (0,0)
  17282. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  17283. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  17284. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  17285. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  17286. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  17287. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  17288. if ( Math.abs(from2toAngle) > EPSILON ) { // angle != 180 deg.
  17289. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  17290. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  17291. if ( from2toAngle > 0 ) { // main angle < 180 deg.
  17292. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  17293. } else { // main angle > 180 deg.
  17294. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  17295. }
  17296. } else { // angle == 180 deg.
  17297. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  17298. return ( from2otherAngle > 0 );
  17299. }
  17300. }
  17301. function removeHoles( contour, holes ) {
  17302. var shape = contour.concat(); // work on this shape
  17303. var hole;
  17304. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  17305. // Check if hole point lies within angle around shape point
  17306. var lastShapeIdx = shape.length - 1;
  17307. var prevShapeIdx = inShapeIdx - 1;
  17308. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  17309. var nextShapeIdx = inShapeIdx + 1;
  17310. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  17311. var insideAngle = isPointInsideAngle( shape[inShapeIdx], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[inHoleIdx] );
  17312. if (! insideAngle ) {
  17313. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  17314. return false;
  17315. }
  17316. // Check if shape point lies within angle around hole point
  17317. var lastHoleIdx = hole.length - 1;
  17318. var prevHoleIdx = inHoleIdx - 1;
  17319. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  17320. var nextHoleIdx = inHoleIdx + 1;
  17321. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  17322. insideAngle = isPointInsideAngle( hole[inHoleIdx], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[inShapeIdx] );
  17323. if (! insideAngle ) {
  17324. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  17325. return false;
  17326. }
  17327. return true;
  17328. }
  17329. function intersectsShapeEdge( inShapePt, inHolePt ) {
  17330. // checks for intersections with shape edges
  17331. var sIdx, nextIdx, intersection;
  17332. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  17333. nextIdx = sIdx + 1; nextIdx %= shape.length;
  17334. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[sIdx], shape[nextIdx], true );
  17335. if ( intersection.length > 0 ) return true;
  17336. }
  17337. return false;
  17338. }
  17339. var indepHoles = [];
  17340. function intersectsHoleEdge( inShapePt, inHolePt ) {
  17341. // checks for intersections with hole edges
  17342. var ihIdx, chkHole,
  17343. hIdx, nextIdx, intersection;
  17344. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  17345. chkHole = holes[indepHoles[ihIdx]];
  17346. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  17347. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  17348. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[hIdx], chkHole[nextIdx], true );
  17349. if ( intersection.length > 0 ) return true;
  17350. }
  17351. }
  17352. return false;
  17353. }
  17354. var holeIndex, shapeIndex,
  17355. shapePt, holePt,
  17356. holeIdx, cutKey, failedCuts = [],
  17357. tmpShape1, tmpShape2,
  17358. tmpHole1, tmpHole2;
  17359. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17360. indepHoles.push( h );
  17361. }
  17362. var minShapeIndex = 0;
  17363. var counter = indepHoles.length * 2;
  17364. while ( indepHoles.length > 0 ) {
  17365. counter --;
  17366. if ( counter < 0 ) {
  17367. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  17368. break;
  17369. }
  17370. // search for shape-vertex and hole-vertex,
  17371. // which can be connected without intersections
  17372. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  17373. shapePt = shape[ shapeIndex ];
  17374. holeIndex = - 1;
  17375. // search for hole which can be reached without intersections
  17376. for ( var h = 0; h < indepHoles.length; h ++ ) {
  17377. holeIdx = indepHoles[h];
  17378. // prevent multiple checks
  17379. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  17380. if ( failedCuts[cutKey] !== undefined ) continue;
  17381. hole = holes[holeIdx];
  17382. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  17383. holePt = hole[ h2 ];
  17384. if (! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  17385. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  17386. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  17387. holeIndex = h2;
  17388. indepHoles.splice(h, 1);
  17389. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  17390. tmpShape2 = shape.slice( shapeIndex );
  17391. tmpHole1 = hole.slice( holeIndex );
  17392. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  17393. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  17394. minShapeIndex = shapeIndex;
  17395. // Debug only, to show the selected cuts
  17396. // glob_CutLines.push( [ shapePt, holePt ] );
  17397. break;
  17398. }
  17399. if ( holeIndex >= 0 ) break; // hole-vertex found
  17400. failedCuts[cutKey] = true; // remember failure
  17401. }
  17402. if ( holeIndex >= 0 ) break; // hole-vertex found
  17403. }
  17404. }
  17405. return shape; /* shape with no holes */
  17406. }
  17407. var i, il, f, face,
  17408. key, index,
  17409. allPointsMap = {};
  17410. // 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.
  17411. var allpoints = contour.concat();
  17412. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  17413. Array.prototype.push.apply( allpoints, holes[h] );
  17414. }
  17415. //console.log( "allpoints",allpoints, allpoints.length );
  17416. // prepare all points map
  17417. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  17418. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  17419. if ( allPointsMap[ key ] !== undefined ) {
  17420. console.warn( "THREE.Shape: Duplicate point", key );
  17421. }
  17422. allPointsMap[ key ] = i;
  17423. }
  17424. // remove holes by cutting paths to holes and adding them to the shape
  17425. var shapeWithoutHoles = removeHoles( contour, holes );
  17426. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  17427. //console.log( "triangles",triangles, triangles.length );
  17428. // check all face vertices against all points map
  17429. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  17430. face = triangles[ i ];
  17431. for ( f = 0; f < 3; f ++ ) {
  17432. key = face[ f ].x + ":" + face[ f ].y;
  17433. index = allPointsMap[ key ];
  17434. if ( index !== undefined ) {
  17435. face[ f ] = index;
  17436. }
  17437. }
  17438. }
  17439. return triangles.concat();
  17440. },
  17441. isClockWise: function ( pts ) {
  17442. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  17443. },
  17444. // Bezier Curves formulas obtained from
  17445. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  17446. // Quad Bezier Functions
  17447. b2p0: function ( t, p ) {
  17448. var k = 1 - t;
  17449. return k * k * p;
  17450. },
  17451. b2p1: function ( t, p ) {
  17452. return 2 * ( 1 - t ) * t * p;
  17453. },
  17454. b2p2: function ( t, p ) {
  17455. return t * t * p;
  17456. },
  17457. b2: function ( t, p0, p1, p2 ) {
  17458. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  17459. },
  17460. // Cubic Bezier Functions
  17461. b3p0: function ( t, p ) {
  17462. var k = 1 - t;
  17463. return k * k * k * p;
  17464. },
  17465. b3p1: function ( t, p ) {
  17466. var k = 1 - t;
  17467. return 3 * k * k * t * p;
  17468. },
  17469. b3p2: function ( t, p ) {
  17470. var k = 1 - t;
  17471. return 3 * k * t * t * p;
  17472. },
  17473. b3p3: function ( t, p ) {
  17474. return t * t * t * p;
  17475. },
  17476. b3: function ( t, p0, p1, p2, p3 ) {
  17477. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  17478. }
  17479. };
  17480. // File:src/extras/curves/LineCurve.js
  17481. /**************************************************************
  17482. * Line
  17483. **************************************************************/
  17484. THREE.LineCurve = function ( v1, v2 ) {
  17485. this.v1 = v1;
  17486. this.v2 = v2;
  17487. };
  17488. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  17489. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  17490. THREE.LineCurve.prototype.getPoint = function ( t ) {
  17491. var point = this.v2.clone().sub(this.v1);
  17492. point.multiplyScalar( t ).add( this.v1 );
  17493. return point;
  17494. };
  17495. // Line curve is linear, so we can overwrite default getPointAt
  17496. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  17497. return this.getPoint( u );
  17498. };
  17499. THREE.LineCurve.prototype.getTangent = function( t ) {
  17500. var tangent = this.v2.clone().sub(this.v1);
  17501. return tangent.normalize();
  17502. };
  17503. // File:src/extras/curves/QuadraticBezierCurve.js
  17504. /**************************************************************
  17505. * Quadratic Bezier curve
  17506. **************************************************************/
  17507. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  17508. this.v0 = v0;
  17509. this.v1 = v1;
  17510. this.v2 = v2;
  17511. };
  17512. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17513. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  17514. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  17515. var vector = new THREE.Vector2();
  17516. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17517. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17518. return vector;
  17519. };
  17520. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  17521. var vector = new THREE.Vector2();
  17522. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  17523. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  17524. // returns unit vector
  17525. return vector.normalize();
  17526. };
  17527. // File:src/extras/curves/CubicBezierCurve.js
  17528. /**************************************************************
  17529. * Cubic Bezier curve
  17530. **************************************************************/
  17531. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  17532. this.v0 = v0;
  17533. this.v1 = v1;
  17534. this.v2 = v2;
  17535. this.v3 = v3;
  17536. };
  17537. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  17538. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  17539. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  17540. var tx, ty;
  17541. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17542. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17543. return new THREE.Vector2( tx, ty );
  17544. };
  17545. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  17546. var tx, ty;
  17547. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17548. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17549. var tangent = new THREE.Vector2( tx, ty );
  17550. tangent.normalize();
  17551. return tangent;
  17552. };
  17553. // File:src/extras/curves/SplineCurve.js
  17554. /**************************************************************
  17555. * Spline curve
  17556. **************************************************************/
  17557. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  17558. this.points = ( points == undefined ) ? [] : points;
  17559. };
  17560. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  17561. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  17562. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  17563. var points = this.points;
  17564. var point = ( points.length - 1 ) * t;
  17565. var intPoint = Math.floor( point );
  17566. var weight = point - intPoint;
  17567. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  17568. var point1 = points[ intPoint ];
  17569. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17570. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17571. var vector = new THREE.Vector2();
  17572. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17573. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17574. return vector;
  17575. };
  17576. // File:src/extras/curves/EllipseCurve.js
  17577. /**************************************************************
  17578. * Ellipse curve
  17579. **************************************************************/
  17580. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise ) {
  17581. this.aX = aX;
  17582. this.aY = aY;
  17583. this.xRadius = xRadius;
  17584. this.yRadius = yRadius;
  17585. this.aStartAngle = aStartAngle;
  17586. this.aEndAngle = aEndAngle;
  17587. this.aClockwise = aClockwise;
  17588. };
  17589. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  17590. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  17591. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  17592. var deltaAngle = this.aEndAngle - this.aStartAngle;
  17593. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  17594. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  17595. var angle;
  17596. if ( this.aClockwise === true ) {
  17597. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  17598. } else {
  17599. angle = this.aStartAngle + t * deltaAngle;
  17600. }
  17601. var vector = new THREE.Vector2();
  17602. vector.x = this.aX + this.xRadius * Math.cos( angle );
  17603. vector.y = this.aY + this.yRadius * Math.sin( angle );
  17604. return vector;
  17605. };
  17606. // File:src/extras/curves/ArcCurve.js
  17607. /**************************************************************
  17608. * Arc curve
  17609. **************************************************************/
  17610. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17611. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17612. };
  17613. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  17614. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  17615. // File:src/extras/curves/LineCurve3.js
  17616. /**************************************************************
  17617. * Line3D
  17618. **************************************************************/
  17619. THREE.LineCurve3 = THREE.Curve.create(
  17620. function ( v1, v2 ) {
  17621. this.v1 = v1;
  17622. this.v2 = v2;
  17623. },
  17624. function ( t ) {
  17625. var vector = new THREE.Vector3();
  17626. vector.subVectors( this.v2, this.v1 ); // diff
  17627. vector.multiplyScalar( t );
  17628. vector.add( this.v1 );
  17629. return vector;
  17630. }
  17631. );
  17632. // File:src/extras/curves/QuadraticBezierCurve3.js
  17633. /**************************************************************
  17634. * Quadratic Bezier 3D curve
  17635. **************************************************************/
  17636. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  17637. function ( v0, v1, v2 ) {
  17638. this.v0 = v0;
  17639. this.v1 = v1;
  17640. this.v2 = v2;
  17641. },
  17642. function ( t ) {
  17643. var vector = new THREE.Vector3();
  17644. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  17645. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  17646. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  17647. return vector;
  17648. }
  17649. );
  17650. // File:src/extras/curves/CubicBezierCurve3.js
  17651. /**************************************************************
  17652. * Cubic Bezier 3D curve
  17653. **************************************************************/
  17654. THREE.CubicBezierCurve3 = THREE.Curve.create(
  17655. function ( v0, v1, v2, v3 ) {
  17656. this.v0 = v0;
  17657. this.v1 = v1;
  17658. this.v2 = v2;
  17659. this.v3 = v3;
  17660. },
  17661. function ( t ) {
  17662. var vector = new THREE.Vector3();
  17663. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  17664. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  17665. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  17666. return vector;
  17667. }
  17668. );
  17669. // File:src/extras/curves/SplineCurve3.js
  17670. /**************************************************************
  17671. * Spline 3D curve
  17672. **************************************************************/
  17673. THREE.SplineCurve3 = THREE.Curve.create(
  17674. function ( points /* array of Vector3 */) {
  17675. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  17676. this.points = ( points == undefined ) ? [] : points;
  17677. },
  17678. function ( t ) {
  17679. var points = this.points;
  17680. var point = ( points.length - 1 ) * t;
  17681. var intPoint = Math.floor( point );
  17682. var weight = point - intPoint;
  17683. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  17684. var point1 = points[ intPoint ];
  17685. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  17686. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  17687. var vector = new THREE.Vector3();
  17688. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17689. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17690. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17691. return vector;
  17692. }
  17693. );
  17694. // File:src/extras/curves/CatmullRomCurve3.js
  17695. /**
  17696. * @author zz85 https://github.com/zz85
  17697. *
  17698. * Centripetal CatmullRom Curve - which is useful for avoiding
  17699. * cusps and self-intersections in non-uniform catmull rom curves.
  17700. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  17701. *
  17702. * curve.type accepts centripetal(default), chordal and catmullrom
  17703. * curve.tension is used for catmullrom which defaults to 0.5
  17704. */
  17705. THREE.CatmullRomCurve3 = ( function() {
  17706. var
  17707. tmp = new THREE.Vector3(),
  17708. px = new CubicPoly(),
  17709. py = new CubicPoly(),
  17710. pz = new CubicPoly();
  17711. /*
  17712. Based on an optimized c++ solution in
  17713. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  17714. - http://ideone.com/NoEbVM
  17715. This CubicPoly class could be used for reusing some variables and calculations,
  17716. but for three.js curve use, it could be possible inlined and flatten into a single function call
  17717. which can be placed in CurveUtils.
  17718. */
  17719. function CubicPoly() {
  17720. }
  17721. /*
  17722. * Compute coefficients for a cubic polynomial
  17723. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  17724. * such that
  17725. * p(0) = x0, p(1) = x1
  17726. * and
  17727. * p'(0) = t0, p'(1) = t1.
  17728. */
  17729. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  17730. this.c0 = x0;
  17731. this.c1 = t0;
  17732. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  17733. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  17734. };
  17735. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  17736. // compute tangents when parameterized in [t1,t2]
  17737. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  17738. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  17739. // rescale tangents for parametrization in [0,1]
  17740. t1 *= dt1;
  17741. t2 *= dt1;
  17742. // initCubicPoly
  17743. this.init( x1, x2, t1, t2 );
  17744. };
  17745. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  17746. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  17747. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  17748. };
  17749. CubicPoly.prototype.calc = function( t ) {
  17750. var t2 = t * t;
  17751. var t3 = t2 * t;
  17752. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  17753. };
  17754. // Subclass Three.js curve
  17755. return THREE.Curve.create(
  17756. function ( p /* array of Vector3 */ ) {
  17757. this.points = p || [];
  17758. },
  17759. function ( t ) {
  17760. var points = this.points,
  17761. point, intPoint, weight, l;
  17762. l = points.length;
  17763. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  17764. point = ( l - 1 ) * t;
  17765. intPoint = Math.floor( point );
  17766. weight = point - intPoint;
  17767. if ( weight === 0 && intPoint === l - 1 ) {
  17768. intPoint = l - 2;
  17769. weight = 1;
  17770. }
  17771. var p0, p1, p2, p3;
  17772. if ( intPoint === 0 ) {
  17773. // extrapolate first point
  17774. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  17775. p0 = tmp;
  17776. } else {
  17777. p0 = points[ intPoint - 1 ];
  17778. }
  17779. p1 = points[ intPoint ];
  17780. p2 = points[ intPoint + 1 ];
  17781. if ( intPoint + 2 < l ) {
  17782. p3 = points[ intPoint + 2 ]
  17783. } else {
  17784. // extrapolate last point
  17785. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  17786. p3 = tmp;
  17787. }
  17788. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  17789. // init Centripetal / Chordal Catmull-Rom
  17790. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  17791. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  17792. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  17793. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  17794. // safety check for repeated points
  17795. if ( dt1 < 1e-4 ) dt1 = 1.0;
  17796. if ( dt0 < 1e-4 ) dt0 = dt1;
  17797. if ( dt2 < 1e-4 ) dt2 = dt1;
  17798. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  17799. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  17800. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  17801. } else if ( this.type === 'catmullrom' ) {
  17802. var tension = this.tension !== undefined ? this.tension : 0.5;
  17803. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  17804. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  17805. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  17806. }
  17807. var v = new THREE.Vector3(
  17808. px.calc( weight ),
  17809. py.calc( weight ),
  17810. pz.calc( weight )
  17811. );
  17812. return v;
  17813. }
  17814. );
  17815. } )();
  17816. // File:src/extras/curves/ClosedSplineCurve3.js
  17817. /**************************************************************
  17818. * Closed Spline 3D curve
  17819. **************************************************************/
  17820. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  17821. function ( points /* array of Vector3 */) {
  17822. this.points = ( points == undefined ) ? [] : points;
  17823. },
  17824. function ( t ) {
  17825. var points = this.points;
  17826. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  17827. var intPoint = Math.floor( point );
  17828. var weight = point - intPoint;
  17829. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  17830. var point0 = points[ ( intPoint - 1 ) % points.length ];
  17831. var point1 = points[ ( intPoint ) % points.length ];
  17832. var point2 = points[ ( intPoint + 1 ) % points.length ];
  17833. var point3 = points[ ( intPoint + 2 ) % points.length ];
  17834. var vector = new THREE.Vector3();
  17835. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  17836. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  17837. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  17838. return vector;
  17839. }
  17840. );
  17841. // File:src/extras/animation/AnimationHandler.js
  17842. /**
  17843. * @author mikael emtinger / http://gomo.se/
  17844. */
  17845. THREE.AnimationHandler = {
  17846. LINEAR: 0,
  17847. CATMULLROM: 1,
  17848. CATMULLROM_FORWARD: 2,
  17849. //
  17850. add: function () { console.warn( 'THREE.AnimationHandler.add() has been deprecated.' ); },
  17851. get: function () { console.warn( 'THREE.AnimationHandler.get() has been deprecated.' ); },
  17852. remove: function () { console.warn( 'THREE.AnimationHandler.remove() has been deprecated.' ); },
  17853. //
  17854. animations: [],
  17855. init: function ( data ) {
  17856. if ( data.initialized === true ) return data;
  17857. // loop through all keys
  17858. for ( var h = 0; h < data.hierarchy.length; h ++ ) {
  17859. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17860. // remove minus times
  17861. if ( data.hierarchy[ h ].keys[ k ].time < 0 ) {
  17862. data.hierarchy[ h ].keys[ k ].time = 0;
  17863. }
  17864. // create quaternions
  17865. if ( data.hierarchy[ h ].keys[ k ].rot !== undefined &&
  17866. ! ( data.hierarchy[ h ].keys[ k ].rot instanceof THREE.Quaternion ) ) {
  17867. var quat = data.hierarchy[ h ].keys[ k ].rot;
  17868. data.hierarchy[ h ].keys[ k ].rot = new THREE.Quaternion().fromArray( quat );
  17869. }
  17870. }
  17871. // prepare morph target keys
  17872. if ( data.hierarchy[ h ].keys.length && data.hierarchy[ h ].keys[ 0 ].morphTargets !== undefined ) {
  17873. // get all used
  17874. var usedMorphTargets = {};
  17875. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17876. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17877. var morphTargetName = data.hierarchy[ h ].keys[ k ].morphTargets[ m ];
  17878. usedMorphTargets[ morphTargetName ] = - 1;
  17879. }
  17880. }
  17881. data.hierarchy[ h ].usedMorphTargets = usedMorphTargets;
  17882. // set all used on all frames
  17883. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17884. var influences = {};
  17885. for ( var morphTargetName in usedMorphTargets ) {
  17886. for ( var m = 0; m < data.hierarchy[ h ].keys[ k ].morphTargets.length; m ++ ) {
  17887. if ( data.hierarchy[ h ].keys[ k ].morphTargets[ m ] === morphTargetName ) {
  17888. influences[ morphTargetName ] = data.hierarchy[ h ].keys[ k ].morphTargetsInfluences[ m ];
  17889. break;
  17890. }
  17891. }
  17892. if ( m === data.hierarchy[ h ].keys[ k ].morphTargets.length ) {
  17893. influences[ morphTargetName ] = 0;
  17894. }
  17895. }
  17896. data.hierarchy[ h ].keys[ k ].morphTargetsInfluences = influences;
  17897. }
  17898. }
  17899. // remove all keys that are on the same time
  17900. for ( var k = 1; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17901. if ( data.hierarchy[ h ].keys[ k ].time === data.hierarchy[ h ].keys[ k - 1 ].time ) {
  17902. data.hierarchy[ h ].keys.splice( k, 1 );
  17903. k --;
  17904. }
  17905. }
  17906. // set index
  17907. for ( var k = 0; k < data.hierarchy[ h ].keys.length; k ++ ) {
  17908. data.hierarchy[ h ].keys[ k ].index = k;
  17909. }
  17910. }
  17911. data.initialized = true;
  17912. return data;
  17913. },
  17914. parse: function ( root ) {
  17915. var parseRecurseHierarchy = function ( root, hierarchy ) {
  17916. hierarchy.push( root );
  17917. for ( var c = 0; c < root.children.length; c ++ )
  17918. parseRecurseHierarchy( root.children[ c ], hierarchy );
  17919. };
  17920. // setup hierarchy
  17921. var hierarchy = [];
  17922. if ( root instanceof THREE.SkinnedMesh ) {
  17923. for ( var b = 0; b < root.skeleton.bones.length; b ++ ) {
  17924. hierarchy.push( root.skeleton.bones[ b ] );
  17925. }
  17926. } else {
  17927. parseRecurseHierarchy( root, hierarchy );
  17928. }
  17929. return hierarchy;
  17930. },
  17931. play: function ( animation ) {
  17932. if ( this.animations.indexOf( animation ) === - 1 ) {
  17933. this.animations.push( animation );
  17934. }
  17935. },
  17936. stop: function ( animation ) {
  17937. var index = this.animations.indexOf( animation );
  17938. if ( index !== - 1 ) {
  17939. this.animations.splice( index, 1 );
  17940. }
  17941. },
  17942. update: function ( deltaTimeMS ) {
  17943. for ( var i = 0; i < this.animations.length; i ++ ) {
  17944. this.animations[ i ].resetBlendWeights( );
  17945. }
  17946. for ( var i = 0; i < this.animations.length; i ++ ) {
  17947. this.animations[ i ].update( deltaTimeMS );
  17948. }
  17949. }
  17950. };
  17951. // File:src/extras/animation/Animation.js
  17952. /**
  17953. * @author mikael emtinger / http://gomo.se/
  17954. * @author mrdoob / http://mrdoob.com/
  17955. * @author alteredq / http://alteredqualia.com/
  17956. */
  17957. THREE.Animation = function ( root, data ) {
  17958. this.root = root;
  17959. this.data = THREE.AnimationHandler.init( data );
  17960. this.hierarchy = THREE.AnimationHandler.parse( root );
  17961. this.currentTime = 0;
  17962. this.timeScale = 1;
  17963. this.isPlaying = false;
  17964. this.loop = true;
  17965. this.weight = 0;
  17966. this.interpolationType = THREE.AnimationHandler.LINEAR;
  17967. };
  17968. THREE.Animation.prototype = {
  17969. constructor: THREE.Animation,
  17970. keyTypes: [ "pos", "rot", "scl" ],
  17971. play: function ( startTime, weight ) {
  17972. this.currentTime = startTime !== undefined ? startTime : 0;
  17973. this.weight = weight !== undefined ? weight : 1;
  17974. this.isPlaying = true;
  17975. this.reset();
  17976. THREE.AnimationHandler.play( this );
  17977. },
  17978. stop: function() {
  17979. this.isPlaying = false;
  17980. THREE.AnimationHandler.stop( this );
  17981. },
  17982. reset: function () {
  17983. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  17984. var object = this.hierarchy[ h ];
  17985. if ( object.animationCache === undefined ) {
  17986. object.animationCache = {
  17987. animations: {},
  17988. blending: {
  17989. positionWeight: 0.0,
  17990. quaternionWeight: 0.0,
  17991. scaleWeight: 0.0
  17992. }
  17993. };
  17994. }
  17995. var name = this.data.name;
  17996. var animations = object.animationCache.animations;
  17997. var animationCache = animations[ name ];
  17998. if ( animationCache === undefined ) {
  17999. animationCache = {
  18000. prevKey: { pos: 0, rot: 0, scl: 0 },
  18001. nextKey: { pos: 0, rot: 0, scl: 0 },
  18002. originalMatrix: object.matrix
  18003. };
  18004. animations[ name ] = animationCache;
  18005. }
  18006. // Get keys to match our current time
  18007. for ( var t = 0; t < 3; t ++ ) {
  18008. var type = this.keyTypes[ t ];
  18009. var prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  18010. var nextKey = this.getNextKeyWith( type, h, 1 );
  18011. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18012. prevKey = nextKey;
  18013. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  18014. }
  18015. animationCache.prevKey[ type ] = prevKey;
  18016. animationCache.nextKey[ type ] = nextKey;
  18017. }
  18018. }
  18019. },
  18020. resetBlendWeights: function () {
  18021. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18022. var object = this.hierarchy[ h ];
  18023. var animationCache = object.animationCache;
  18024. if ( animationCache !== undefined ) {
  18025. var blending = animationCache.blending;
  18026. blending.positionWeight = 0.0;
  18027. blending.quaternionWeight = 0.0;
  18028. blending.scaleWeight = 0.0;
  18029. }
  18030. }
  18031. },
  18032. update: ( function() {
  18033. var points = [];
  18034. var target = new THREE.Vector3();
  18035. var newVector = new THREE.Vector3();
  18036. var newQuat = new THREE.Quaternion();
  18037. // Catmull-Rom spline
  18038. var interpolateCatmullRom = function ( points, scale ) {
  18039. var c = [], v3 = [],
  18040. point, intPoint, weight, w2, w3,
  18041. pa, pb, pc, pd;
  18042. point = ( points.length - 1 ) * scale;
  18043. intPoint = Math.floor( point );
  18044. weight = point - intPoint;
  18045. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  18046. c[ 1 ] = intPoint;
  18047. c[ 2 ] = intPoint > points.length - 2 ? intPoint : intPoint + 1;
  18048. c[ 3 ] = intPoint > points.length - 3 ? intPoint : intPoint + 2;
  18049. pa = points[ c[ 0 ] ];
  18050. pb = points[ c[ 1 ] ];
  18051. pc = points[ c[ 2 ] ];
  18052. pd = points[ c[ 3 ] ];
  18053. w2 = weight * weight;
  18054. w3 = weight * w2;
  18055. v3[ 0 ] = interpolate( pa[ 0 ], pb[ 0 ], pc[ 0 ], pd[ 0 ], weight, w2, w3 );
  18056. v3[ 1 ] = interpolate( pa[ 1 ], pb[ 1 ], pc[ 1 ], pd[ 1 ], weight, w2, w3 );
  18057. v3[ 2 ] = interpolate( pa[ 2 ], pb[ 2 ], pc[ 2 ], pd[ 2 ], weight, w2, w3 );
  18058. return v3;
  18059. };
  18060. var interpolate = function ( p0, p1, p2, p3, t, t2, t3 ) {
  18061. var v0 = ( p2 - p0 ) * 0.5,
  18062. v1 = ( p3 - p1 ) * 0.5;
  18063. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  18064. };
  18065. return function ( delta ) {
  18066. if ( this.isPlaying === false ) return;
  18067. this.currentTime += delta * this.timeScale;
  18068. if ( this.weight === 0 )
  18069. return;
  18070. //
  18071. var duration = this.data.length;
  18072. if ( this.currentTime > duration || this.currentTime < 0 ) {
  18073. if ( this.loop ) {
  18074. this.currentTime %= duration;
  18075. if ( this.currentTime < 0 )
  18076. this.currentTime += duration;
  18077. this.reset();
  18078. } else {
  18079. this.stop();
  18080. }
  18081. }
  18082. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18083. var object = this.hierarchy[ h ];
  18084. var animationCache = object.animationCache.animations[this.data.name];
  18085. var blending = object.animationCache.blending;
  18086. // loop through pos/rot/scl
  18087. for ( var t = 0; t < 3; t ++ ) {
  18088. // get keys
  18089. var type = this.keyTypes[ t ];
  18090. var prevKey = animationCache.prevKey[ type ];
  18091. var nextKey = animationCache.nextKey[ type ];
  18092. if ( ( this.timeScale > 0 && nextKey.time <= this.currentTime ) ||
  18093. ( this.timeScale < 0 && prevKey.time >= this.currentTime ) ) {
  18094. prevKey = this.data.hierarchy[ h ].keys[ 0 ];
  18095. nextKey = this.getNextKeyWith( type, h, 1 );
  18096. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18097. prevKey = nextKey;
  18098. nextKey = this.getNextKeyWith( type, h, nextKey.index + 1 );
  18099. }
  18100. animationCache.prevKey[ type ] = prevKey;
  18101. animationCache.nextKey[ type ] = nextKey;
  18102. }
  18103. var scale = ( this.currentTime - prevKey.time ) / ( nextKey.time - prevKey.time );
  18104. var prevXYZ = prevKey[ type ];
  18105. var nextXYZ = nextKey[ type ];
  18106. if ( scale < 0 ) scale = 0;
  18107. if ( scale > 1 ) scale = 1;
  18108. // interpolate
  18109. if ( type === "pos" ) {
  18110. if ( this.interpolationType === THREE.AnimationHandler.LINEAR ) {
  18111. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18112. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18113. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18114. // blend
  18115. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  18116. object.position.lerp( newVector, proportionalWeight );
  18117. blending.positionWeight += this.weight;
  18118. } else if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18119. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18120. points[ 0 ] = this.getPrevKeyWith( "pos", h, prevKey.index - 1 )[ "pos" ];
  18121. points[ 1 ] = prevXYZ;
  18122. points[ 2 ] = nextXYZ;
  18123. points[ 3 ] = this.getNextKeyWith( "pos", h, nextKey.index + 1 )[ "pos" ];
  18124. scale = scale * 0.33 + 0.33;
  18125. var currentPoint = interpolateCatmullRom( points, scale );
  18126. var proportionalWeight = this.weight / ( this.weight + blending.positionWeight );
  18127. blending.positionWeight += this.weight;
  18128. // blend
  18129. var vector = object.position;
  18130. vector.x = vector.x + ( currentPoint[ 0 ] - vector.x ) * proportionalWeight;
  18131. vector.y = vector.y + ( currentPoint[ 1 ] - vector.y ) * proportionalWeight;
  18132. vector.z = vector.z + ( currentPoint[ 2 ] - vector.z ) * proportionalWeight;
  18133. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18134. var forwardPoint = interpolateCatmullRom( points, scale * 1.01 );
  18135. target.set( forwardPoint[ 0 ], forwardPoint[ 1 ], forwardPoint[ 2 ] );
  18136. target.sub( vector );
  18137. target.y = 0;
  18138. target.normalize();
  18139. var angle = Math.atan2( target.x, target.z );
  18140. object.rotation.set( 0, angle, 0 );
  18141. }
  18142. }
  18143. } else if ( type === "rot" ) {
  18144. THREE.Quaternion.slerp( prevXYZ, nextXYZ, newQuat, scale );
  18145. // Avoid paying the cost of an additional slerp if we don't have to
  18146. if ( blending.quaternionWeight === 0 ) {
  18147. object.quaternion.copy(newQuat);
  18148. blending.quaternionWeight = this.weight;
  18149. } else {
  18150. var proportionalWeight = this.weight / ( this.weight + blending.quaternionWeight );
  18151. THREE.Quaternion.slerp( object.quaternion, newQuat, object.quaternion, proportionalWeight );
  18152. blending.quaternionWeight += this.weight;
  18153. }
  18154. } else if ( type === "scl" ) {
  18155. newVector.x = prevXYZ[ 0 ] + ( nextXYZ[ 0 ] - prevXYZ[ 0 ] ) * scale;
  18156. newVector.y = prevXYZ[ 1 ] + ( nextXYZ[ 1 ] - prevXYZ[ 1 ] ) * scale;
  18157. newVector.z = prevXYZ[ 2 ] + ( nextXYZ[ 2 ] - prevXYZ[ 2 ] ) * scale;
  18158. var proportionalWeight = this.weight / ( this.weight + blending.scaleWeight );
  18159. object.scale.lerp( newVector, proportionalWeight );
  18160. blending.scaleWeight += this.weight;
  18161. }
  18162. }
  18163. }
  18164. return true;
  18165. };
  18166. } )(),
  18167. getNextKeyWith: function ( type, h, key ) {
  18168. var keys = this.data.hierarchy[ h ].keys;
  18169. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18170. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18171. key = key < keys.length - 1 ? key : keys.length - 1;
  18172. } else {
  18173. key = key % keys.length;
  18174. }
  18175. for ( ; key < keys.length; key ++ ) {
  18176. if ( keys[ key ][ type ] !== undefined ) {
  18177. return keys[ key ];
  18178. }
  18179. }
  18180. return this.data.hierarchy[ h ].keys[ 0 ];
  18181. },
  18182. getPrevKeyWith: function ( type, h, key ) {
  18183. var keys = this.data.hierarchy[ h ].keys;
  18184. if ( this.interpolationType === THREE.AnimationHandler.CATMULLROM ||
  18185. this.interpolationType === THREE.AnimationHandler.CATMULLROM_FORWARD ) {
  18186. key = key > 0 ? key : 0;
  18187. } else {
  18188. key = key >= 0 ? key : key + keys.length;
  18189. }
  18190. for ( ; key >= 0; key -- ) {
  18191. if ( keys[ key ][ type ] !== undefined ) {
  18192. return keys[ key ];
  18193. }
  18194. }
  18195. return this.data.hierarchy[ h ].keys[ keys.length - 1 ];
  18196. }
  18197. };
  18198. // File:src/extras/animation/KeyFrameAnimation.js
  18199. /**
  18200. * @author mikael emtinger / http://gomo.se/
  18201. * @author mrdoob / http://mrdoob.com/
  18202. * @author alteredq / http://alteredqualia.com/
  18203. * @author khang duong
  18204. * @author erik kitson
  18205. */
  18206. THREE.KeyFrameAnimation = function ( data ) {
  18207. this.root = data.node;
  18208. this.data = THREE.AnimationHandler.init( data );
  18209. this.hierarchy = THREE.AnimationHandler.parse( this.root );
  18210. this.currentTime = 0;
  18211. this.timeScale = 0.001;
  18212. this.isPlaying = false;
  18213. this.isPaused = true;
  18214. this.loop = true;
  18215. // initialize to first keyframes
  18216. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18217. var keys = this.data.hierarchy[h].keys,
  18218. sids = this.data.hierarchy[h].sids,
  18219. obj = this.hierarchy[h];
  18220. if ( keys.length && sids ) {
  18221. for ( var s = 0; s < sids.length; s ++ ) {
  18222. var sid = sids[ s ],
  18223. next = this.getNextKeyWith( sid, h, 0 );
  18224. if ( next ) {
  18225. next.apply( sid );
  18226. }
  18227. }
  18228. obj.matrixAutoUpdate = false;
  18229. this.data.hierarchy[h].node.updateMatrix();
  18230. obj.matrixWorldNeedsUpdate = true;
  18231. }
  18232. }
  18233. };
  18234. THREE.KeyFrameAnimation.prototype = {
  18235. constructor: THREE.KeyFrameAnimation,
  18236. play: function ( startTime ) {
  18237. this.currentTime = startTime !== undefined ? startTime : 0;
  18238. if ( this.isPlaying === false ) {
  18239. this.isPlaying = true;
  18240. // reset key cache
  18241. var h, hl = this.hierarchy.length,
  18242. object,
  18243. node;
  18244. for ( h = 0; h < hl; h ++ ) {
  18245. object = this.hierarchy[ h ];
  18246. node = this.data.hierarchy[ h ];
  18247. if ( node.animationCache === undefined ) {
  18248. node.animationCache = {};
  18249. node.animationCache.prevKey = null;
  18250. node.animationCache.nextKey = null;
  18251. node.animationCache.originalMatrix = object.matrix;
  18252. }
  18253. var keys = this.data.hierarchy[h].keys;
  18254. if (keys.length) {
  18255. node.animationCache.prevKey = keys[ 0 ];
  18256. node.animationCache.nextKey = keys[ 1 ];
  18257. this.startTime = Math.min( keys[0].time, this.startTime );
  18258. this.endTime = Math.max( keys[keys.length - 1].time, this.endTime );
  18259. }
  18260. }
  18261. this.update( 0 );
  18262. }
  18263. this.isPaused = false;
  18264. THREE.AnimationHandler.play( this );
  18265. },
  18266. stop: function () {
  18267. this.isPlaying = false;
  18268. this.isPaused = false;
  18269. THREE.AnimationHandler.stop( this );
  18270. // reset JIT matrix and remove cache
  18271. for ( var h = 0; h < this.data.hierarchy.length; h ++ ) {
  18272. var obj = this.hierarchy[ h ];
  18273. var node = this.data.hierarchy[ h ];
  18274. if ( node.animationCache !== undefined ) {
  18275. var original = node.animationCache.originalMatrix;
  18276. original.copy( obj.matrix );
  18277. obj.matrix = original;
  18278. delete node.animationCache;
  18279. }
  18280. }
  18281. },
  18282. update: function ( delta ) {
  18283. if ( this.isPlaying === false ) return;
  18284. this.currentTime += delta * this.timeScale;
  18285. //
  18286. var duration = this.data.length;
  18287. if ( this.loop === true && this.currentTime > duration ) {
  18288. this.currentTime %= duration;
  18289. }
  18290. this.currentTime = Math.min( this.currentTime, duration );
  18291. for ( var h = 0, hl = this.hierarchy.length; h < hl; h ++ ) {
  18292. var object = this.hierarchy[ h ];
  18293. var node = this.data.hierarchy[ h ];
  18294. var keys = node.keys,
  18295. animationCache = node.animationCache;
  18296. if ( keys.length ) {
  18297. var prevKey = animationCache.prevKey;
  18298. var nextKey = animationCache.nextKey;
  18299. if ( nextKey.time <= this.currentTime ) {
  18300. while ( nextKey.time < this.currentTime && nextKey.index > prevKey.index ) {
  18301. prevKey = nextKey;
  18302. nextKey = keys[ prevKey.index + 1 ];
  18303. }
  18304. animationCache.prevKey = prevKey;
  18305. animationCache.nextKey = nextKey;
  18306. }
  18307. if ( nextKey.time >= this.currentTime ) {
  18308. prevKey.interpolate( nextKey, this.currentTime );
  18309. } else {
  18310. prevKey.interpolate( nextKey, nextKey.time );
  18311. }
  18312. this.data.hierarchy[ h ].node.updateMatrix();
  18313. object.matrixWorldNeedsUpdate = true;
  18314. }
  18315. }
  18316. },
  18317. getNextKeyWith: function ( sid, h, key ) {
  18318. var keys = this.data.hierarchy[ h ].keys;
  18319. key = key % keys.length;
  18320. for ( ; key < keys.length; key ++ ) {
  18321. if ( keys[ key ].hasTarget( sid ) ) {
  18322. return keys[ key ];
  18323. }
  18324. }
  18325. return keys[ 0 ];
  18326. },
  18327. getPrevKeyWith: function ( sid, h, key ) {
  18328. var keys = this.data.hierarchy[ h ].keys;
  18329. key = key >= 0 ? key : key + keys.length;
  18330. for ( ; key >= 0; key -- ) {
  18331. if ( keys[ key ].hasTarget( sid ) ) {
  18332. return keys[ key ];
  18333. }
  18334. }
  18335. return keys[ keys.length - 1 ];
  18336. }
  18337. };
  18338. // File:src/extras/animation/MorphAnimation.js
  18339. /**
  18340. * @author mrdoob / http://mrdoob.com
  18341. * @author willy-vvu / http://willy-vvu.github.io
  18342. */
  18343. THREE.MorphAnimation = function ( mesh ) {
  18344. this.mesh = mesh;
  18345. this.frames = mesh.morphTargetInfluences.length;
  18346. this.currentTime = 0;
  18347. this.duration = 1000;
  18348. this.loop = true;
  18349. this.lastFrame = 0;
  18350. this.currentFrame = 0;
  18351. this.isPlaying = false;
  18352. };
  18353. THREE.MorphAnimation.prototype = {
  18354. constructor: THREE.MorphAnimation,
  18355. play: function () {
  18356. this.isPlaying = true;
  18357. },
  18358. pause: function () {
  18359. this.isPlaying = false;
  18360. },
  18361. update: function ( delta ) {
  18362. if ( this.isPlaying === false ) return;
  18363. this.currentTime += delta;
  18364. if ( this.loop === true && this.currentTime > this.duration ) {
  18365. this.currentTime %= this.duration;
  18366. }
  18367. this.currentTime = Math.min( this.currentTime, this.duration );
  18368. var frameTime = this.duration / this.frames;
  18369. var frame = Math.floor( this.currentTime / frameTime );
  18370. var influences = this.mesh.morphTargetInfluences;
  18371. if ( frame !== this.currentFrame ) {
  18372. influences[ this.lastFrame ] = 0;
  18373. influences[ this.currentFrame ] = 1;
  18374. influences[ frame ] = 0;
  18375. this.lastFrame = this.currentFrame;
  18376. this.currentFrame = frame;
  18377. }
  18378. var mix = ( this.currentTime % frameTime ) / frameTime;
  18379. influences[ frame ] = mix;
  18380. influences[ this.lastFrame ] = 1 - mix;
  18381. }
  18382. };
  18383. // File:src/extras/geometries/BoxGeometry.js
  18384. /**
  18385. * @author mrdoob / http://mrdoob.com/
  18386. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  18387. */
  18388. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  18389. THREE.Geometry.call( this );
  18390. this.type = 'BoxGeometry';
  18391. this.parameters = {
  18392. width: width,
  18393. height: height,
  18394. depth: depth,
  18395. widthSegments: widthSegments,
  18396. heightSegments: heightSegments,
  18397. depthSegments: depthSegments
  18398. };
  18399. this.widthSegments = widthSegments || 1;
  18400. this.heightSegments = heightSegments || 1;
  18401. this.depthSegments = depthSegments || 1;
  18402. var scope = this;
  18403. var width_half = width / 2;
  18404. var height_half = height / 2;
  18405. var depth_half = depth / 2;
  18406. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half ); // px
  18407. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half ); // nx
  18408. buildPlane( 'x', 'z', 1, 1, width, depth, height_half ); // py
  18409. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half ); // ny
  18410. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half ); // pz
  18411. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half ); // nz
  18412. function buildPlane( u, v, udir, vdir, width, height, depth ) {
  18413. var w, ix, iy,
  18414. gridX = scope.widthSegments,
  18415. gridY = scope.heightSegments,
  18416. width_half = width / 2,
  18417. height_half = height / 2,
  18418. offset = scope.vertices.length;
  18419. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  18420. w = 'z';
  18421. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  18422. w = 'y';
  18423. gridY = scope.depthSegments;
  18424. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  18425. w = 'x';
  18426. gridX = scope.depthSegments;
  18427. }
  18428. var gridX1 = gridX + 1,
  18429. gridY1 = gridY + 1,
  18430. segment_width = width / gridX,
  18431. segment_height = height / gridY,
  18432. normal = new THREE.Vector3();
  18433. normal[ w ] = depth > 0 ? 1 : - 1;
  18434. for ( iy = 0; iy < gridY1; iy ++ ) {
  18435. for ( ix = 0; ix < gridX1; ix ++ ) {
  18436. var vector = new THREE.Vector3();
  18437. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  18438. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  18439. vector[ w ] = depth;
  18440. scope.vertices.push( vector );
  18441. }
  18442. }
  18443. for ( iy = 0; iy < gridY; iy ++ ) {
  18444. for ( ix = 0; ix < gridX; ix ++ ) {
  18445. var a = ix + gridX1 * iy;
  18446. var b = ix + gridX1 * ( iy + 1 );
  18447. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  18448. var d = ( ix + 1 ) + gridX1 * iy;
  18449. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  18450. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  18451. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  18452. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  18453. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  18454. face.normal.copy( normal );
  18455. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18456. scope.faces.push( face );
  18457. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  18458. face = new THREE.Face3( b + offset, c + offset, d + offset );
  18459. face.normal.copy( normal );
  18460. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  18461. scope.faces.push( face );
  18462. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  18463. }
  18464. }
  18465. }
  18466. this.mergeVertices();
  18467. };
  18468. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18469. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  18470. THREE.BoxGeometry.prototype.clone = function () {
  18471. var geometry = new THREE.BoxGeometry(
  18472. this.parameters.width,
  18473. this.parameters.height,
  18474. this.parameters.depth,
  18475. this.parameters.widthSegments,
  18476. this.parameters.heightSegments,
  18477. this.parameters.depthSegments
  18478. );
  18479. return geometry;
  18480. };
  18481. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  18482. // File:src/extras/geometries/CircleGeometry.js
  18483. /**
  18484. * @author hughes
  18485. */
  18486. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18487. THREE.Geometry.call( this );
  18488. this.type = 'CircleGeometry';
  18489. this.parameters = {
  18490. radius: radius,
  18491. segments: segments,
  18492. thetaStart: thetaStart,
  18493. thetaLength: thetaLength
  18494. };
  18495. radius = radius || 50;
  18496. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18497. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18498. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18499. var i, uvs = [],
  18500. center = new THREE.Vector3(), centerUV = new THREE.Vector2( 0.5, 0.5 );
  18501. this.vertices.push(center);
  18502. uvs.push( centerUV );
  18503. for ( i = 0; i <= segments; i ++ ) {
  18504. var vertex = new THREE.Vector3();
  18505. var segment = thetaStart + i / segments * thetaLength;
  18506. vertex.x = radius * Math.cos( segment );
  18507. vertex.y = radius * Math.sin( segment );
  18508. this.vertices.push( vertex );
  18509. uvs.push( new THREE.Vector2( ( vertex.x / radius + 1 ) / 2, ( vertex.y / radius + 1 ) / 2 ) );
  18510. }
  18511. var n = new THREE.Vector3( 0, 0, 1 );
  18512. for ( i = 1; i <= segments; i ++ ) {
  18513. this.faces.push( new THREE.Face3( i, i + 1, 0, [ n.clone(), n.clone(), n.clone() ] ) );
  18514. this.faceVertexUvs[ 0 ].push( [ uvs[ i ].clone(), uvs[ i + 1 ].clone(), centerUV.clone() ] );
  18515. }
  18516. this.computeFaceNormals();
  18517. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18518. };
  18519. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18520. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  18521. THREE.CircleGeometry.prototype.clone = function () {
  18522. var geometry = new THREE.CircleGeometry(
  18523. this.parameters.radius,
  18524. this.parameters.segments,
  18525. this.parameters.thetaStart,
  18526. this.parameters.thetaLength
  18527. );
  18528. return geometry;
  18529. };
  18530. // File:src/extras/geometries/CircleBufferGeometry.js
  18531. /**
  18532. * @author benaadams / https://twitter.com/ben_a_adams
  18533. */
  18534. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  18535. THREE.BufferGeometry.call( this );
  18536. this.type = 'CircleBufferGeometry';
  18537. this.parameters = {
  18538. radius: radius,
  18539. segments: segments,
  18540. thetaStart: thetaStart,
  18541. thetaLength: thetaLength
  18542. };
  18543. radius = radius || 50;
  18544. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  18545. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18546. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  18547. var vertices = segments + 2;
  18548. var positions = new Float32Array( vertices * 3 );
  18549. var normals = new Float32Array( vertices * 3 );
  18550. var uvs = new Float32Array( vertices * 2 );
  18551. // center data is already zero, but need to set a few extras
  18552. normals[3] = 1.0;
  18553. uvs[0] = 0.5;
  18554. uvs[1] = 0.5;
  18555. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s++, i += 3, ii += 2 ) {
  18556. var segment = thetaStart + s / segments * thetaLength;
  18557. positions[i] = radius * Math.cos( segment );
  18558. positions[i + 1] = radius * Math.sin( segment );
  18559. normals[i + 2] = 1; // normal z
  18560. uvs[ii] = ( positions[i] / radius + 1 ) / 2;
  18561. uvs[ii + 1] = ( positions[i + 1] / radius + 1 ) / 2;
  18562. }
  18563. var indices = [];
  18564. for ( var i = 1; i <= segments; i ++ ) {
  18565. indices.push( i );
  18566. indices.push( i + 1 );
  18567. indices.push( 0 );
  18568. }
  18569. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  18570. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  18571. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  18572. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  18573. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  18574. };
  18575. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18576. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  18577. THREE.CircleBufferGeometry.prototype.clone = function () {
  18578. var geometry = new THREE.CircleBufferGeometry(
  18579. this.parameters.radius,
  18580. this.parameters.segments,
  18581. this.parameters.thetaStart,
  18582. this.parameters.thetaLength
  18583. );
  18584. geometry.copy( this );
  18585. return geometry;
  18586. };
  18587. // File:src/extras/geometries/CylinderGeometry.js
  18588. /**
  18589. * @author mrdoob / http://mrdoob.com/
  18590. */
  18591. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  18592. THREE.Geometry.call( this );
  18593. this.type = 'CylinderGeometry';
  18594. this.parameters = {
  18595. radiusTop: radiusTop,
  18596. radiusBottom: radiusBottom,
  18597. height: height,
  18598. radialSegments: radialSegments,
  18599. heightSegments: heightSegments,
  18600. openEnded: openEnded,
  18601. thetaStart: thetaStart,
  18602. thetaLength: thetaLength
  18603. };
  18604. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  18605. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  18606. height = height !== undefined ? height : 100;
  18607. radialSegments = radialSegments || 8;
  18608. heightSegments = heightSegments || 1;
  18609. openEnded = openEnded !== undefined ? openEnded : false;
  18610. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  18611. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  18612. var heightHalf = height / 2;
  18613. var x, y, vertices = [], uvs = [];
  18614. for ( y = 0; y <= heightSegments; y ++ ) {
  18615. var verticesRow = [];
  18616. var uvsRow = [];
  18617. var v = y / heightSegments;
  18618. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  18619. for ( x = 0; x <= radialSegments; x ++ ) {
  18620. var u = x / radialSegments;
  18621. var vertex = new THREE.Vector3();
  18622. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  18623. vertex.y = - v * height + heightHalf;
  18624. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  18625. this.vertices.push( vertex );
  18626. verticesRow.push( this.vertices.length - 1 );
  18627. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  18628. }
  18629. vertices.push( verticesRow );
  18630. uvs.push( uvsRow );
  18631. }
  18632. var tanTheta = ( radiusBottom - radiusTop ) / height;
  18633. var na, nb;
  18634. for ( x = 0; x < radialSegments; x ++ ) {
  18635. if ( radiusTop !== 0 ) {
  18636. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  18637. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  18638. } else {
  18639. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  18640. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  18641. }
  18642. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  18643. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  18644. for ( y = 0; y < heightSegments; y ++ ) {
  18645. var v1 = vertices[ y ][ x ];
  18646. var v2 = vertices[ y + 1 ][ x ];
  18647. var v3 = vertices[ y + 1 ][ x + 1 ];
  18648. var v4 = vertices[ y ][ x + 1 ];
  18649. var n1 = na.clone();
  18650. var n2 = na.clone();
  18651. var n3 = nb.clone();
  18652. var n4 = nb.clone();
  18653. var uv1 = uvs[ y ][ x ].clone();
  18654. var uv2 = uvs[ y + 1 ][ x ].clone();
  18655. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  18656. var uv4 = uvs[ y ][ x + 1 ].clone();
  18657. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  18658. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  18659. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  18660. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  18661. }
  18662. }
  18663. // top cap
  18664. if ( openEnded === false && radiusTop > 0 ) {
  18665. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  18666. for ( x = 0; x < radialSegments; x ++ ) {
  18667. var v1 = vertices[ 0 ][ x ];
  18668. var v2 = vertices[ 0 ][ x + 1 ];
  18669. var v3 = this.vertices.length - 1;
  18670. var n1 = new THREE.Vector3( 0, 1, 0 );
  18671. var n2 = new THREE.Vector3( 0, 1, 0 );
  18672. var n3 = new THREE.Vector3( 0, 1, 0 );
  18673. var uv1 = uvs[ 0 ][ x ].clone();
  18674. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  18675. var uv3 = new THREE.Vector2( uv2.x, 0 );
  18676. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18677. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18678. }
  18679. }
  18680. // bottom cap
  18681. if ( openEnded === false && radiusBottom > 0 ) {
  18682. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  18683. for ( x = 0; x < radialSegments; x ++ ) {
  18684. var v1 = vertices[ heightSegments ][ x + 1 ];
  18685. var v2 = vertices[ heightSegments ][ x ];
  18686. var v3 = this.vertices.length - 1;
  18687. var n1 = new THREE.Vector3( 0, - 1, 0 );
  18688. var n2 = new THREE.Vector3( 0, - 1, 0 );
  18689. var n3 = new THREE.Vector3( 0, - 1, 0 );
  18690. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  18691. var uv2 = uvs[ heightSegments ][ x ].clone();
  18692. var uv3 = new THREE.Vector2( uv2.x, 1 );
  18693. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  18694. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  18695. }
  18696. }
  18697. this.computeFaceNormals();
  18698. };
  18699. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18700. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  18701. THREE.CylinderGeometry.prototype.clone = function () {
  18702. var geometry = new THREE.CylinderGeometry(
  18703. this.parameters.radiusTop,
  18704. this.parameters.radiusBottom,
  18705. this.parameters.height,
  18706. this.parameters.radialSegments,
  18707. this.parameters.heightSegments,
  18708. this.parameters.openEnded,
  18709. this.parameters.thetaStart,
  18710. this.parameters.thetaLength
  18711. );
  18712. return geometry;
  18713. };
  18714. // File:src/extras/geometries/EdgesGeometry.js
  18715. /**
  18716. * @author WestLangley / http://github.com/WestLangley
  18717. */
  18718. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  18719. THREE.BufferGeometry.call( this );
  18720. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  18721. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  18722. var edge = [ 0, 0 ], hash = {};
  18723. var sortFunction = function ( a, b ) { return a - b; };
  18724. var keys = [ 'a', 'b', 'c' ];
  18725. var geometry2;
  18726. if ( geometry instanceof THREE.BufferGeometry ) {
  18727. geometry2 = new THREE.Geometry();
  18728. geometry2.fromBufferGeometry( geometry );
  18729. } else {
  18730. geometry2 = geometry.clone();
  18731. }
  18732. geometry2.mergeVertices();
  18733. geometry2.computeFaceNormals();
  18734. var vertices = geometry2.vertices;
  18735. var faces = geometry2.faces;
  18736. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  18737. var face = faces[ i ];
  18738. for ( var j = 0; j < 3; j ++ ) {
  18739. edge[ 0 ] = face[ keys[ j ] ];
  18740. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  18741. edge.sort( sortFunction );
  18742. var key = edge.toString();
  18743. if ( hash[ key ] === undefined ) {
  18744. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  18745. } else {
  18746. hash[ key ].face2 = i;
  18747. }
  18748. }
  18749. }
  18750. var coords = [];
  18751. for ( var key in hash ) {
  18752. var h = hash[ key ];
  18753. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  18754. var vertex = vertices[ h.vert1 ];
  18755. coords.push( vertex.x );
  18756. coords.push( vertex.y );
  18757. coords.push( vertex.z );
  18758. vertex = vertices[ h.vert2 ];
  18759. coords.push( vertex.x );
  18760. coords.push( vertex.y );
  18761. coords.push( vertex.z );
  18762. }
  18763. }
  18764. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  18765. };
  18766. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  18767. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  18768. // File:src/extras/geometries/ExtrudeGeometry.js
  18769. /**
  18770. * @author zz85 / http://www.lab4games.net/zz85/blog
  18771. *
  18772. * Creates extruded geometry from a path shape.
  18773. *
  18774. * parameters = {
  18775. *
  18776. * curveSegments: <int>, // number of points on the curves
  18777. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  18778. * amount: <int>, // Depth to extrude the shape
  18779. *
  18780. * bevelEnabled: <bool>, // turn on bevel
  18781. * bevelThickness: <float>, // how deep into the original shape bevel goes
  18782. * bevelSize: <float>, // how far from shape outline is bevel
  18783. * bevelSegments: <int>, // number of bevel layers
  18784. *
  18785. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  18786. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  18787. *
  18788. * uvGenerator: <Object> // object that provides UV generator functions
  18789. *
  18790. * }
  18791. **/
  18792. THREE.ExtrudeGeometry = function ( shapes, options ) {
  18793. if ( typeof( shapes ) === "undefined" ) {
  18794. shapes = [];
  18795. return;
  18796. }
  18797. THREE.Geometry.call( this );
  18798. this.type = 'ExtrudeGeometry';
  18799. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  18800. this.addShapeList( shapes, options );
  18801. this.computeFaceNormals();
  18802. // can't really use automatic vertex normals
  18803. // as then front and back sides get smoothed too
  18804. // should do separate smoothing just for sides
  18805. //this.computeVertexNormals();
  18806. //console.log( "took", ( Date.now() - startTime ) );
  18807. };
  18808. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  18809. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  18810. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  18811. var sl = shapes.length;
  18812. for ( var s = 0; s < sl; s ++ ) {
  18813. var shape = shapes[ s ];
  18814. this.addShape( shape, options );
  18815. }
  18816. };
  18817. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  18818. var amount = options.amount !== undefined ? options.amount : 100;
  18819. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  18820. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  18821. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  18822. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  18823. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  18824. var steps = options.steps !== undefined ? options.steps : 1;
  18825. var extrudePath = options.extrudePath;
  18826. var extrudePts, extrudeByPath = false;
  18827. // Use default WorldUVGenerator if no UV generators are specified.
  18828. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  18829. var splineTube, binormal, normal, position2;
  18830. if ( extrudePath ) {
  18831. extrudePts = extrudePath.getSpacedPoints( steps );
  18832. extrudeByPath = true;
  18833. bevelEnabled = false; // bevels not supported for path extrusion
  18834. // SETUP TNB variables
  18835. // Reuse TNB from TubeGeomtry for now.
  18836. // TODO1 - have a .isClosed in spline?
  18837. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames(extrudePath, steps, false);
  18838. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  18839. binormal = new THREE.Vector3();
  18840. normal = new THREE.Vector3();
  18841. position2 = new THREE.Vector3();
  18842. }
  18843. // Safeguards if bevels are not enabled
  18844. if ( ! bevelEnabled ) {
  18845. bevelSegments = 0;
  18846. bevelThickness = 0;
  18847. bevelSize = 0;
  18848. }
  18849. // Variables initialization
  18850. var ahole, h, hl; // looping of holes
  18851. var scope = this;
  18852. var shapesOffset = this.vertices.length;
  18853. var shapePoints = shape.extractPoints( curveSegments );
  18854. var vertices = shapePoints.shape;
  18855. var holes = shapePoints.holes;
  18856. var reverse = ! THREE.Shape.Utils.isClockWise( vertices ) ;
  18857. if ( reverse ) {
  18858. vertices = vertices.reverse();
  18859. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  18860. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18861. ahole = holes[ h ];
  18862. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  18863. holes[ h ] = ahole.reverse();
  18864. }
  18865. }
  18866. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  18867. }
  18868. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  18869. /* Vertices */
  18870. var contour = vertices; // vertices has all points but contour has only points of circumference
  18871. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18872. ahole = holes[ h ];
  18873. vertices = vertices.concat( ahole );
  18874. }
  18875. function scalePt2 ( pt, vec, size ) {
  18876. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  18877. return vec.clone().multiplyScalar( size ).add( pt );
  18878. }
  18879. var b, bs, t, z,
  18880. vert, vlen = vertices.length,
  18881. face, flen = faces.length;
  18882. // Find directions for point movement
  18883. function getBevelVec( inPt, inPrev, inNext ) {
  18884. var EPSILON = 0.0000000001;
  18885. // computes for inPt the corresponding point inPt' on a new contour
  18886. // shifted by 1 unit (length of normalized vector) to the left
  18887. // if we walk along contour clockwise, this new contour is outside the old one
  18888. //
  18889. // inPt' is the intersection of the two lines parallel to the two
  18890. // adjacent edges of inPt at a distance of 1 unit on the left side.
  18891. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  18892. // good reading for geometry algorithms (here: line-line intersection)
  18893. // http://geomalgorithms.com/a05-_intersect-1.html
  18894. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  18895. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  18896. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  18897. // check for collinear edges
  18898. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18899. if ( Math.abs( collinear0 ) > EPSILON ) { // not collinear
  18900. // length of vectors for normalizing
  18901. var v_prev_len = Math.sqrt( v_prev_lensq );
  18902. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  18903. // shift adjacent points by unit vectors to the left
  18904. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  18905. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  18906. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  18907. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  18908. // scaling factor for v_prev to intersection point
  18909. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  18910. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  18911. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  18912. // vector from inPt to intersection point
  18913. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  18914. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  18915. // Don't normalize!, otherwise sharp corners become ugly
  18916. // but prevent crazy spikes
  18917. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  18918. if ( v_trans_lensq <= 2 ) {
  18919. return new THREE.Vector2( v_trans_x, v_trans_y );
  18920. } else {
  18921. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  18922. }
  18923. } else { // handle special case of collinear edges
  18924. var direction_eq = false; // assumes: opposite
  18925. if ( v_prev_x > EPSILON ) {
  18926. if ( v_next_x > EPSILON ) { direction_eq = true; }
  18927. } else {
  18928. if ( v_prev_x < - EPSILON ) {
  18929. if ( v_next_x < - EPSILON ) { direction_eq = true; }
  18930. } else {
  18931. if ( Math.sign(v_prev_y) === Math.sign(v_next_y) ) { direction_eq = true; }
  18932. }
  18933. }
  18934. if ( direction_eq ) {
  18935. // console.log("Warning: lines are a straight sequence");
  18936. v_trans_x = - v_prev_y;
  18937. v_trans_y = v_prev_x;
  18938. shrink_by = Math.sqrt( v_prev_lensq );
  18939. } else {
  18940. // console.log("Warning: lines are a straight spike");
  18941. v_trans_x = v_prev_x;
  18942. v_trans_y = v_prev_y;
  18943. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  18944. }
  18945. }
  18946. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  18947. }
  18948. var contourMovements = [];
  18949. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18950. if ( j === il ) j = 0;
  18951. if ( k === il ) k = 0;
  18952. // (j)---(i)---(k)
  18953. // console.log('i,j,k', i, j , k)
  18954. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  18955. }
  18956. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  18957. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18958. ahole = holes[ h ];
  18959. oneHoleMovements = [];
  18960. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  18961. if ( j === il ) j = 0;
  18962. if ( k === il ) k = 0;
  18963. // (j)---(i)---(k)
  18964. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  18965. }
  18966. holesMovements.push( oneHoleMovements );
  18967. verticesMovements = verticesMovements.concat( oneHoleMovements );
  18968. }
  18969. // Loop bevelSegments, 1 for the front, 1 for the back
  18970. for ( b = 0; b < bevelSegments; b ++ ) {
  18971. //for ( b = bevelSegments; b > 0; b -- ) {
  18972. t = b / bevelSegments;
  18973. z = bevelThickness * ( 1 - t );
  18974. //z = bevelThickness * t;
  18975. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ) ; // curved
  18976. //bs = bevelSize * t ; // linear
  18977. // contract shape
  18978. for ( i = 0, il = contour.length; i < il; i ++ ) {
  18979. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  18980. v( vert.x, vert.y, - z );
  18981. }
  18982. // expand holes
  18983. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  18984. ahole = holes[ h ];
  18985. oneHoleMovements = holesMovements[ h ];
  18986. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  18987. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  18988. v( vert.x, vert.y, - z );
  18989. }
  18990. }
  18991. }
  18992. bs = bevelSize;
  18993. // Back facing vertices
  18994. for ( i = 0; i < vlen; i ++ ) {
  18995. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  18996. if ( ! extrudeByPath ) {
  18997. v( vert.x, vert.y, 0 );
  18998. } else {
  18999. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  19000. normal.copy( splineTube.normals[0] ).multiplyScalar(vert.x);
  19001. binormal.copy( splineTube.binormals[0] ).multiplyScalar(vert.y);
  19002. position2.copy( extrudePts[0] ).add(normal).add(binormal);
  19003. v( position2.x, position2.y, position2.z );
  19004. }
  19005. }
  19006. // Add stepped vertices...
  19007. // Including front facing vertices
  19008. var s;
  19009. for ( s = 1; s <= steps; s ++ ) {
  19010. for ( i = 0; i < vlen; i ++ ) {
  19011. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19012. if ( ! extrudeByPath ) {
  19013. v( vert.x, vert.y, amount / steps * s );
  19014. } else {
  19015. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  19016. normal.copy( splineTube.normals[s] ).multiplyScalar( vert.x );
  19017. binormal.copy( splineTube.binormals[s] ).multiplyScalar( vert.y );
  19018. position2.copy( extrudePts[s] ).add( normal ).add( binormal );
  19019. v( position2.x, position2.y, position2.z );
  19020. }
  19021. }
  19022. }
  19023. // Add bevel segments planes
  19024. //for ( b = 1; b <= bevelSegments; b ++ ) {
  19025. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  19026. t = b / bevelSegments;
  19027. z = bevelThickness * ( 1 - t );
  19028. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  19029. bs = bevelSize * Math.sin ( t * Math.PI / 2 ) ;
  19030. // contract shape
  19031. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19032. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19033. v( vert.x, vert.y, amount + z );
  19034. }
  19035. // expand holes
  19036. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19037. ahole = holes[ h ];
  19038. oneHoleMovements = holesMovements[ h ];
  19039. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19040. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19041. if ( ! extrudeByPath ) {
  19042. v( vert.x, vert.y, amount + z );
  19043. } else {
  19044. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19045. }
  19046. }
  19047. }
  19048. }
  19049. /* Faces */
  19050. // Top and bottom faces
  19051. buildLidFaces();
  19052. // Sides faces
  19053. buildSideFaces();
  19054. ///// Internal functions
  19055. function buildLidFaces() {
  19056. if ( bevelEnabled ) {
  19057. var layer = 0 ; // steps + 1
  19058. var offset = vlen * layer;
  19059. // Bottom faces
  19060. for ( i = 0; i < flen; i ++ ) {
  19061. face = faces[ i ];
  19062. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19063. }
  19064. layer = steps + bevelSegments * 2;
  19065. offset = vlen * layer;
  19066. // Top faces
  19067. for ( i = 0; i < flen; i ++ ) {
  19068. face = faces[ i ];
  19069. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19070. }
  19071. } else {
  19072. // Bottom faces
  19073. for ( i = 0; i < flen; i ++ ) {
  19074. face = faces[ i ];
  19075. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19076. }
  19077. // Top faces
  19078. for ( i = 0; i < flen; i ++ ) {
  19079. face = faces[ i ];
  19080. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19081. }
  19082. }
  19083. }
  19084. // Create faces for the z-sides of the shape
  19085. function buildSideFaces() {
  19086. var layeroffset = 0;
  19087. sidewalls( contour, layeroffset );
  19088. layeroffset += contour.length;
  19089. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19090. ahole = holes[ h ];
  19091. sidewalls( ahole, layeroffset );
  19092. //, true
  19093. layeroffset += ahole.length;
  19094. }
  19095. }
  19096. function sidewalls( contour, layeroffset ) {
  19097. var j, k;
  19098. i = contour.length;
  19099. while ( -- i >= 0 ) {
  19100. j = i;
  19101. k = i - 1;
  19102. if ( k < 0 ) k = contour.length - 1;
  19103. //console.log('b', i,j, i-1, k,vertices.length);
  19104. var s = 0, sl = steps + bevelSegments * 2;
  19105. for ( s = 0; s < sl; s ++ ) {
  19106. var slen1 = vlen * s;
  19107. var slen2 = vlen * ( s + 1 );
  19108. var a = layeroffset + j + slen1,
  19109. b = layeroffset + k + slen1,
  19110. c = layeroffset + k + slen2,
  19111. d = layeroffset + j + slen2;
  19112. f4( a, b, c, d, contour, s, sl, j, k );
  19113. }
  19114. }
  19115. }
  19116. function v( x, y, z ) {
  19117. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  19118. }
  19119. function f3( a, b, c ) {
  19120. a += shapesOffset;
  19121. b += shapesOffset;
  19122. c += shapesOffset;
  19123. scope.faces.push( new THREE.Face3( a, b, c ) );
  19124. var uvs = uvgen.generateTopUV( scope, a, b, c );
  19125. scope.faceVertexUvs[ 0 ].push( uvs );
  19126. }
  19127. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  19128. a += shapesOffset;
  19129. b += shapesOffset;
  19130. c += shapesOffset;
  19131. d += shapesOffset;
  19132. scope.faces.push( new THREE.Face3( a, b, d ) );
  19133. scope.faces.push( new THREE.Face3( b, c, d ) );
  19134. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  19135. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  19136. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  19137. }
  19138. };
  19139. THREE.ExtrudeGeometry.WorldUVGenerator = {
  19140. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  19141. var vertices = geometry.vertices;
  19142. var a = vertices[ indexA ];
  19143. var b = vertices[ indexB ];
  19144. var c = vertices[ indexC ];
  19145. return [
  19146. new THREE.Vector2( a.x, a.y ),
  19147. new THREE.Vector2( b.x, b.y ),
  19148. new THREE.Vector2( c.x, c.y )
  19149. ];
  19150. },
  19151. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  19152. var vertices = geometry.vertices;
  19153. var a = vertices[ indexA ];
  19154. var b = vertices[ indexB ];
  19155. var c = vertices[ indexC ];
  19156. var d = vertices[ indexD ];
  19157. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  19158. return [
  19159. new THREE.Vector2( a.x, 1 - a.z ),
  19160. new THREE.Vector2( b.x, 1 - b.z ),
  19161. new THREE.Vector2( c.x, 1 - c.z ),
  19162. new THREE.Vector2( d.x, 1 - d.z )
  19163. ];
  19164. } else {
  19165. return [
  19166. new THREE.Vector2( a.y, 1 - a.z ),
  19167. new THREE.Vector2( b.y, 1 - b.z ),
  19168. new THREE.Vector2( c.y, 1 - c.z ),
  19169. new THREE.Vector2( d.y, 1 - d.z )
  19170. ];
  19171. }
  19172. }
  19173. };
  19174. // File:src/extras/geometries/ShapeGeometry.js
  19175. /**
  19176. * @author jonobr1 / http://jonobr1.com
  19177. *
  19178. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19179. * ExtrudeGeometry.
  19180. *
  19181. * parameters = {
  19182. *
  19183. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19184. *
  19185. * material: <int> // material index for front and back faces
  19186. * uvGenerator: <Object> // object that provides UV generator functions
  19187. *
  19188. * }
  19189. **/
  19190. THREE.ShapeGeometry = function ( shapes, options ) {
  19191. THREE.Geometry.call( this );
  19192. this.type = 'ShapeGeometry';
  19193. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19194. this.addShapeList( shapes, options );
  19195. this.computeFaceNormals();
  19196. };
  19197. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19198. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19199. /**
  19200. * Add an array of shapes to THREE.ShapeGeometry.
  19201. */
  19202. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19203. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19204. this.addShape( shapes[ i ], options );
  19205. }
  19206. return this;
  19207. };
  19208. /**
  19209. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19210. */
  19211. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19212. if ( options === undefined ) options = {};
  19213. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19214. var material = options.material;
  19215. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19216. //
  19217. var i, l, hole;
  19218. var shapesOffset = this.vertices.length;
  19219. var shapePoints = shape.extractPoints( curveSegments );
  19220. var vertices = shapePoints.shape;
  19221. var holes = shapePoints.holes;
  19222. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19223. if ( reverse ) {
  19224. vertices = vertices.reverse();
  19225. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19226. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19227. hole = holes[ i ];
  19228. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19229. holes[ i ] = hole.reverse();
  19230. }
  19231. }
  19232. reverse = false;
  19233. }
  19234. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19235. // Vertices
  19236. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19237. hole = holes[ i ];
  19238. vertices = vertices.concat( hole );
  19239. }
  19240. //
  19241. var vert, vlen = vertices.length;
  19242. var face, flen = faces.length;
  19243. for ( i = 0; i < vlen; i ++ ) {
  19244. vert = vertices[ i ];
  19245. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19246. }
  19247. for ( i = 0; i < flen; i ++ ) {
  19248. face = faces[ i ];
  19249. var a = face[ 0 ] + shapesOffset;
  19250. var b = face[ 1 ] + shapesOffset;
  19251. var c = face[ 2 ] + shapesOffset;
  19252. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19253. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19254. }
  19255. };
  19256. // File:src/extras/geometries/LatheGeometry.js
  19257. /**
  19258. * @author astrodud / http://astrodud.isgreat.org/
  19259. * @author zz85 / https://github.com/zz85
  19260. * @author bhouston / http://exocortex.com
  19261. */
  19262. // points - to create a closed torus, one must use a set of points
  19263. // like so: [ a, b, c, d, a ], see first is the same as last.
  19264. // segments - the number of circumference segments to create
  19265. // phiStart - the starting radian
  19266. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19267. // 2*pi is a closed lathe, less than 2PI is a portion.
  19268. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19269. THREE.Geometry.call( this );
  19270. this.type = 'LatheGeometry';
  19271. this.parameters = {
  19272. points: points,
  19273. segments: segments,
  19274. phiStart: phiStart,
  19275. phiLength: phiLength
  19276. };
  19277. segments = segments || 12;
  19278. phiStart = phiStart || 0;
  19279. phiLength = phiLength || 2 * Math.PI;
  19280. var inversePointLength = 1.0 / ( points.length - 1 );
  19281. var inverseSegments = 1.0 / segments;
  19282. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19283. var phi = phiStart + i * inverseSegments * phiLength;
  19284. var c = Math.cos( phi ),
  19285. s = Math.sin( phi );
  19286. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19287. var pt = points[ j ];
  19288. var vertex = new THREE.Vector3();
  19289. vertex.x = c * pt.x - s * pt.y;
  19290. vertex.y = s * pt.x + c * pt.y;
  19291. vertex.z = pt.z;
  19292. this.vertices.push( vertex );
  19293. }
  19294. }
  19295. var np = points.length;
  19296. for ( var i = 0, il = segments; i < il; i ++ ) {
  19297. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19298. var base = j + np * i;
  19299. var a = base;
  19300. var b = base + np;
  19301. var c = base + 1 + np;
  19302. var d = base + 1;
  19303. var u0 = i * inverseSegments;
  19304. var v0 = j * inversePointLength;
  19305. var u1 = u0 + inverseSegments;
  19306. var v1 = v0 + inversePointLength;
  19307. this.faces.push( new THREE.Face3( a, b, d ) );
  19308. this.faceVertexUvs[ 0 ].push( [
  19309. new THREE.Vector2( u0, v0 ),
  19310. new THREE.Vector2( u1, v0 ),
  19311. new THREE.Vector2( u0, v1 )
  19312. ] );
  19313. this.faces.push( new THREE.Face3( b, c, d ) );
  19314. this.faceVertexUvs[ 0 ].push( [
  19315. new THREE.Vector2( u1, v0 ),
  19316. new THREE.Vector2( u1, v1 ),
  19317. new THREE.Vector2( u0, v1 )
  19318. ] );
  19319. }
  19320. }
  19321. this.mergeVertices();
  19322. this.computeFaceNormals();
  19323. this.computeVertexNormals();
  19324. };
  19325. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19326. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19327. // File:src/extras/geometries/PlaneGeometry.js
  19328. /**
  19329. * @author mrdoob / http://mrdoob.com/
  19330. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19331. */
  19332. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19333. THREE.Geometry.call( this );
  19334. this.type = 'PlaneGeometry';
  19335. this.parameters = {
  19336. width: width,
  19337. height: height,
  19338. widthSegments: widthSegments,
  19339. heightSegments: heightSegments
  19340. };
  19341. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  19342. };
  19343. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19344. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  19345. THREE.PlaneGeometry.prototype.clone = function () {
  19346. var geometry = new THREE.PlaneGeometry(
  19347. this.parameters.width,
  19348. this.parameters.height,
  19349. this.parameters.widthSegments,
  19350. this.parameters.heightSegments
  19351. );
  19352. return geometry;
  19353. };
  19354. // File:src/extras/geometries/PlaneBufferGeometry.js
  19355. /**
  19356. * @author mrdoob / http://mrdoob.com/
  19357. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19358. */
  19359. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  19360. THREE.BufferGeometry.call( this );
  19361. this.type = 'PlaneBufferGeometry';
  19362. this.parameters = {
  19363. width: width,
  19364. height: height,
  19365. widthSegments: widthSegments,
  19366. heightSegments: heightSegments
  19367. };
  19368. var width_half = width / 2;
  19369. var height_half = height / 2;
  19370. var gridX = Math.floor( widthSegments ) || 1;
  19371. var gridY = Math.floor( heightSegments ) || 1;
  19372. var gridX1 = gridX + 1;
  19373. var gridY1 = gridY + 1;
  19374. var segment_width = width / gridX;
  19375. var segment_height = height / gridY;
  19376. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  19377. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  19378. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  19379. var offset = 0;
  19380. var offset2 = 0;
  19381. for ( var iy = 0; iy < gridY1; iy ++ ) {
  19382. var y = iy * segment_height - height_half;
  19383. for ( var ix = 0; ix < gridX1; ix ++ ) {
  19384. var x = ix * segment_width - width_half;
  19385. vertices[ offset ] = x;
  19386. vertices[ offset + 1 ] = - y;
  19387. normals[ offset + 2 ] = 1;
  19388. uvs[ offset2 ] = ix / gridX;
  19389. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  19390. offset += 3;
  19391. offset2 += 2;
  19392. }
  19393. }
  19394. offset = 0;
  19395. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  19396. for ( var iy = 0; iy < gridY; iy ++ ) {
  19397. for ( var ix = 0; ix < gridX; ix ++ ) {
  19398. var a = ix + gridX1 * iy;
  19399. var b = ix + gridX1 * ( iy + 1 );
  19400. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19401. var d = ( ix + 1 ) + gridX1 * iy;
  19402. indices[ offset ] = a;
  19403. indices[ offset + 1 ] = b;
  19404. indices[ offset + 2 ] = d;
  19405. indices[ offset + 3 ] = b;
  19406. indices[ offset + 4 ] = c;
  19407. indices[ offset + 5 ] = d;
  19408. offset += 6;
  19409. }
  19410. }
  19411. this.addAttribute( 'index', new THREE.BufferAttribute( indices, 1 ) );
  19412. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  19413. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19414. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19415. };
  19416. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19417. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  19418. THREE.PlaneBufferGeometry.prototype.clone = function () {
  19419. var geometry = new THREE.PlaneBufferGeometry(
  19420. this.parameters.width,
  19421. this.parameters.height,
  19422. this.parameters.widthSegments,
  19423. this.parameters.heightSegments
  19424. );
  19425. geometry.copy( this );
  19426. return geometry;
  19427. };
  19428. // File:src/extras/geometries/RingGeometry.js
  19429. /**
  19430. * @author Kaleb Murphy
  19431. */
  19432. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  19433. THREE.Geometry.call( this );
  19434. this.type = 'RingGeometry';
  19435. this.parameters = {
  19436. innerRadius: innerRadius,
  19437. outerRadius: outerRadius,
  19438. thetaSegments: thetaSegments,
  19439. phiSegments: phiSegments,
  19440. thetaStart: thetaStart,
  19441. thetaLength: thetaLength
  19442. };
  19443. innerRadius = innerRadius || 0;
  19444. outerRadius = outerRadius || 50;
  19445. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19446. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19447. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  19448. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  19449. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  19450. for ( i = 0; i < phiSegments + 1; i ++ ) { // concentric circles inside ring
  19451. for ( o = 0; o < thetaSegments + 1; o ++ ) { // number of segments per circle
  19452. var vertex = new THREE.Vector3();
  19453. var segment = thetaStart + o / thetaSegments * thetaLength;
  19454. vertex.x = radius * Math.cos( segment );
  19455. vertex.y = radius * Math.sin( segment );
  19456. this.vertices.push( vertex );
  19457. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  19458. }
  19459. radius += radiusStep;
  19460. }
  19461. var n = new THREE.Vector3( 0, 0, 1 );
  19462. for ( i = 0; i < phiSegments; i ++ ) { // concentric circles inside ring
  19463. var thetaSegment = i * (thetaSegments + 1);
  19464. for ( o = 0; o < thetaSegments ; o ++ ) { // number of segments per circle
  19465. var segment = o + thetaSegment;
  19466. var v1 = segment;
  19467. var v2 = segment + thetaSegments + 1;
  19468. var v3 = segment + thetaSegments + 2;
  19469. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19470. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);
  19471. v1 = segment;
  19472. v2 = segment + thetaSegments + 2;
  19473. v3 = segment + 1;
  19474. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  19475. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ]);
  19476. }
  19477. }
  19478. this.computeFaceNormals();
  19479. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19480. };
  19481. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19482. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  19483. THREE.RingGeometry.prototype.clone = function () {
  19484. var geometry = new THREE.RingGeometry(
  19485. this.parameters.innerRadius,
  19486. this.parameters.outerRadius,
  19487. this.parameters.thetaSegments,
  19488. this.parameters.phiSegments,
  19489. this.parameters.thetaStart,
  19490. this.parameters.thetaLength
  19491. );
  19492. return geometry;
  19493. };
  19494. // File:src/extras/geometries/SphereGeometry.js
  19495. /**
  19496. * @author mrdoob / http://mrdoob.com/
  19497. */
  19498. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19499. console.log( 'THREE.SphereGeometry: Consider using THREE.SphereBufferGeometry for lower memory footprint.' );
  19500. THREE.Geometry.call( this );
  19501. this.type = 'SphereGeometry';
  19502. this.parameters = {
  19503. radius: radius,
  19504. widthSegments: widthSegments,
  19505. heightSegments: heightSegments,
  19506. phiStart: phiStart,
  19507. phiLength: phiLength,
  19508. thetaStart: thetaStart,
  19509. thetaLength: thetaLength
  19510. };
  19511. radius = radius || 50;
  19512. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19513. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19514. phiStart = phiStart !== undefined ? phiStart : 0;
  19515. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19516. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19517. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19518. var x, y, vertices = [], uvs = [];
  19519. for ( y = 0; y <= heightSegments; y ++ ) {
  19520. var verticesRow = [];
  19521. var uvsRow = [];
  19522. for ( x = 0; x <= widthSegments; x ++ ) {
  19523. var u = x / widthSegments;
  19524. var v = y / heightSegments;
  19525. var vertex = new THREE.Vector3();
  19526. vertex.x = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19527. vertex.y = radius * Math.cos( thetaStart + v * thetaLength );
  19528. vertex.z = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19529. this.vertices.push( vertex );
  19530. verticesRow.push( this.vertices.length - 1 );
  19531. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19532. }
  19533. vertices.push( verticesRow );
  19534. uvs.push( uvsRow );
  19535. }
  19536. for ( y = 0; y < heightSegments; y ++ ) {
  19537. for ( x = 0; x < widthSegments; x ++ ) {
  19538. var v1 = vertices[ y ][ x + 1 ];
  19539. var v2 = vertices[ y ][ x ];
  19540. var v3 = vertices[ y + 1 ][ x ];
  19541. var v4 = vertices[ y + 1 ][ x + 1 ];
  19542. var n1 = this.vertices[ v1 ].clone().normalize();
  19543. var n2 = this.vertices[ v2 ].clone().normalize();
  19544. var n3 = this.vertices[ v3 ].clone().normalize();
  19545. var n4 = this.vertices[ v4 ].clone().normalize();
  19546. var uv1 = uvs[ y ][ x + 1 ].clone();
  19547. var uv2 = uvs[ y ][ x ].clone();
  19548. var uv3 = uvs[ y + 1 ][ x ].clone();
  19549. var uv4 = uvs[ y + 1 ][ x + 1 ].clone();
  19550. if ( Math.abs( this.vertices[ v1 ].y ) === radius ) {
  19551. uv1.x = ( uv1.x + uv2.x ) / 2;
  19552. this.faces.push( new THREE.Face3( v1, v3, v4, [ n1, n3, n4 ] ) );
  19553. this.faceVertexUvs[ 0 ].push( [ uv1, uv3, uv4 ] );
  19554. } else if ( Math.abs( this.vertices[ v3 ].y ) === radius ) {
  19555. uv3.x = ( uv3.x + uv4.x ) / 2;
  19556. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ] ) );
  19557. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19558. } else {
  19559. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19560. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19561. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19562. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19563. }
  19564. }
  19565. }
  19566. this.computeFaceNormals();
  19567. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19568. };
  19569. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19570. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  19571. THREE.SphereGeometry.prototype.clone = function () {
  19572. var geometry = new THREE.SphereGeometry(
  19573. this.parameters.radius,
  19574. this.parameters.widthSegments,
  19575. this.parameters.heightSegments,
  19576. this.parameters.phiStart,
  19577. this.parameters.phiLength,
  19578. this.parameters.thetaStart,
  19579. this.parameters.thetaLength
  19580. );
  19581. return geometry;
  19582. };
  19583. // File:src/extras/geometries/SphereBufferGeometry.js
  19584. /**
  19585. * @author benaadams / https://twitter.com/ben_a_adams
  19586. * based on THREE.SphereGeometry
  19587. */
  19588. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  19589. THREE.BufferGeometry.call( this );
  19590. this.type = 'SphereBufferGeometry';
  19591. this.parameters = {
  19592. radius: radius,
  19593. widthSegments: widthSegments,
  19594. heightSegments: heightSegments,
  19595. phiStart: phiStart,
  19596. phiLength: phiLength,
  19597. thetaStart: thetaStart,
  19598. thetaLength: thetaLength
  19599. };
  19600. radius = radius || 50;
  19601. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  19602. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  19603. phiStart = phiStart !== undefined ? phiStart : 0;
  19604. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  19605. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19606. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  19607. var thetaEnd = thetaStart + thetaLength;
  19608. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  19609. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19610. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  19611. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  19612. var index = 0, vertices = [], normal = new THREE.Vector3();
  19613. for ( var y = 0; y <= heightSegments; y ++ ) {
  19614. var verticesRow = [];
  19615. var v = y / heightSegments;
  19616. for ( var x = 0; x <= widthSegments; x ++ ) {
  19617. var u = x / widthSegments;
  19618. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19619. var py = radius * Math.cos( thetaStart + v * thetaLength );
  19620. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  19621. normal.set( px, py, pz ).normalize();
  19622. positions.setXYZ( index, px, py, pz );
  19623. normals.setXYZ( index, normal.x, normal.y, normal.z );
  19624. uvs.setXY( index, u, 1 - v );
  19625. verticesRow.push( index );
  19626. index ++;
  19627. }
  19628. vertices.push( verticesRow );
  19629. }
  19630. var indices = [];
  19631. for ( var y = 0; y < heightSegments; y ++ ) {
  19632. for ( var x = 0; x < widthSegments; x ++ ) {
  19633. var v1 = vertices[ y ][ x + 1 ];
  19634. var v2 = vertices[ y ][ x ];
  19635. var v3 = vertices[ y + 1 ][ x ];
  19636. var v4 = vertices[ y + 1 ][ x + 1 ];
  19637. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  19638. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  19639. }
  19640. }
  19641. this.addAttribute( 'index', new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19642. this.addAttribute( 'position', positions );
  19643. this.addAttribute( 'normal', normals );
  19644. this.addAttribute( 'uv', uvs );
  19645. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19646. };
  19647. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19648. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  19649. THREE.SphereBufferGeometry.prototype.clone = function () {
  19650. var geometry = new THREE.SphereBufferGeometry(
  19651. this.parameters.radius,
  19652. this.parameters.widthSegments,
  19653. this.parameters.heightSegments,
  19654. this.parameters.phiStart,
  19655. this.parameters.phiLength,
  19656. this.parameters.thetaStart,
  19657. this.parameters.thetaLength
  19658. );
  19659. geometry.copy( this );
  19660. return geometry;
  19661. };
  19662. // File:src/extras/geometries/TextGeometry.js
  19663. /**
  19664. * @author zz85 / http://www.lab4games.net/zz85/blog
  19665. * @author alteredq / http://alteredqualia.com/
  19666. *
  19667. * For creating 3D text geometry in three.js
  19668. *
  19669. * Text = 3D Text
  19670. *
  19671. * parameters = {
  19672. * size: <float>, // size of the text
  19673. * height: <float>, // thickness to extrude text
  19674. * curveSegments: <int>, // number of points on the curves
  19675. *
  19676. * font: <string>, // font name
  19677. * weight: <string>, // font weight (normal, bold)
  19678. * style: <string>, // font style (normal, italics)
  19679. *
  19680. * bevelEnabled: <bool>, // turn on bevel
  19681. * bevelThickness: <float>, // how deep into text bevel goes
  19682. * bevelSize: <float>, // how far from text outline is bevel
  19683. * }
  19684. *
  19685. */
  19686. /* Usage Examples
  19687. // TextGeometry wrapper
  19688. var text3d = new TextGeometry( text, options );
  19689. // Complete manner
  19690. var textShapes = THREE.FontUtils.generateShapes( text, options );
  19691. var text3d = new ExtrudeGeometry( textShapes, options );
  19692. */
  19693. THREE.TextGeometry = function ( text, parameters ) {
  19694. parameters = parameters || {};
  19695. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  19696. // translate parameters to ExtrudeGeometry API
  19697. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  19698. // defaults
  19699. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  19700. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  19701. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  19702. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  19703. this.type = 'TextGeometry';
  19704. };
  19705. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  19706. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  19707. // File:src/extras/geometries/TorusGeometry.js
  19708. /**
  19709. * @author oosmoxiecode
  19710. * @author mrdoob / http://mrdoob.com/
  19711. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  19712. */
  19713. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  19714. THREE.Geometry.call( this );
  19715. this.type = 'TorusGeometry';
  19716. this.parameters = {
  19717. radius: radius,
  19718. tube: tube,
  19719. radialSegments: radialSegments,
  19720. tubularSegments: tubularSegments,
  19721. arc: arc
  19722. };
  19723. radius = radius || 100;
  19724. tube = tube || 40;
  19725. radialSegments = radialSegments || 8;
  19726. tubularSegments = tubularSegments || 6;
  19727. arc = arc || Math.PI * 2;
  19728. var center = new THREE.Vector3(), uvs = [], normals = [];
  19729. for ( var j = 0; j <= radialSegments; j ++ ) {
  19730. for ( var i = 0; i <= tubularSegments; i ++ ) {
  19731. var u = i / tubularSegments * arc;
  19732. var v = j / radialSegments * Math.PI * 2;
  19733. center.x = radius * Math.cos( u );
  19734. center.y = radius * Math.sin( u );
  19735. var vertex = new THREE.Vector3();
  19736. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  19737. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  19738. vertex.z = tube * Math.sin( v );
  19739. this.vertices.push( vertex );
  19740. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  19741. normals.push( vertex.clone().sub( center ).normalize() );
  19742. }
  19743. }
  19744. for ( var j = 1; j <= radialSegments; j ++ ) {
  19745. for ( var i = 1; i <= tubularSegments; i ++ ) {
  19746. var a = ( tubularSegments + 1 ) * j + i - 1;
  19747. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  19748. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  19749. var d = ( tubularSegments + 1 ) * j + i;
  19750. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  19751. this.faces.push( face );
  19752. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  19753. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  19754. this.faces.push( face );
  19755. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  19756. }
  19757. }
  19758. this.computeFaceNormals();
  19759. };
  19760. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19761. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  19762. THREE.TorusGeometry.prototype.clone = function () {
  19763. var geometry = new THREE.TorusGeometry(
  19764. this.parameters.radius,
  19765. this.parameters.tube,
  19766. this.parameters.radialSegments,
  19767. this.parameters.tubularSegments,
  19768. this.parameters.arc
  19769. );
  19770. return geometry;
  19771. };
  19772. // File:src/extras/geometries/TorusKnotGeometry.js
  19773. /**
  19774. * @author oosmoxiecode
  19775. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  19776. */
  19777. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  19778. THREE.Geometry.call( this );
  19779. this.type = 'TorusKnotGeometry';
  19780. this.parameters = {
  19781. radius: radius,
  19782. tube: tube,
  19783. radialSegments: radialSegments,
  19784. tubularSegments: tubularSegments,
  19785. p: p,
  19786. q: q,
  19787. heightScale: heightScale
  19788. };
  19789. radius = radius || 100;
  19790. tube = tube || 40;
  19791. radialSegments = radialSegments || 64;
  19792. tubularSegments = tubularSegments || 8;
  19793. p = p || 2;
  19794. q = q || 3;
  19795. heightScale = heightScale || 1;
  19796. var grid = new Array( radialSegments );
  19797. var tang = new THREE.Vector3();
  19798. var n = new THREE.Vector3();
  19799. var bitan = new THREE.Vector3();
  19800. for ( var i = 0; i < radialSegments; ++ i ) {
  19801. grid[ i ] = new Array( tubularSegments );
  19802. var u = i / radialSegments * 2 * p * Math.PI;
  19803. var p1 = getPos( u, q, p, radius, heightScale );
  19804. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  19805. tang.subVectors( p2, p1 );
  19806. n.addVectors( p2, p1 );
  19807. bitan.crossVectors( tang, n );
  19808. n.crossVectors( bitan, tang );
  19809. bitan.normalize();
  19810. n.normalize();
  19811. for ( var j = 0; j < tubularSegments; ++ j ) {
  19812. var v = j / tubularSegments * 2 * Math.PI;
  19813. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19814. var cy = tube * Math.sin( v );
  19815. var pos = new THREE.Vector3();
  19816. pos.x = p1.x + cx * n.x + cy * bitan.x;
  19817. pos.y = p1.y + cx * n.y + cy * bitan.y;
  19818. pos.z = p1.z + cx * n.z + cy * bitan.z;
  19819. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  19820. }
  19821. }
  19822. for ( var i = 0; i < radialSegments; ++ i ) {
  19823. for ( var j = 0; j < tubularSegments; ++ j ) {
  19824. var ip = ( i + 1 ) % radialSegments;
  19825. var jp = ( j + 1 ) % tubularSegments;
  19826. var a = grid[ i ][ j ];
  19827. var b = grid[ ip ][ j ];
  19828. var c = grid[ ip ][ jp ];
  19829. var d = grid[ i ][ jp ];
  19830. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  19831. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  19832. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  19833. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  19834. this.faces.push( new THREE.Face3( a, b, d ) );
  19835. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19836. this.faces.push( new THREE.Face3( b, c, d ) );
  19837. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19838. }
  19839. }
  19840. this.computeFaceNormals();
  19841. this.computeVertexNormals();
  19842. function getPos( u, in_q, in_p, radius, heightScale ) {
  19843. var cu = Math.cos( u );
  19844. var su = Math.sin( u );
  19845. var quOverP = in_q / in_p * u;
  19846. var cs = Math.cos( quOverP );
  19847. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  19848. var ty = radius * ( 2 + cs ) * su * 0.5;
  19849. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  19850. return new THREE.Vector3( tx, ty, tz );
  19851. }
  19852. };
  19853. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19854. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  19855. THREE.TorusKnotGeometry.prototype.clone = function () {
  19856. var geometry = new THREE.TorusKnotGeometry(
  19857. this.parameters.radius,
  19858. this.parameters.tube,
  19859. this.parameters.radialSegments,
  19860. this.parameters.tubularSegments,
  19861. this.parameters.p,
  19862. this.parameters.q,
  19863. this.parameters.heightScale
  19864. );
  19865. return geometry;
  19866. };
  19867. // File:src/extras/geometries/TubeGeometry.js
  19868. /**
  19869. * @author WestLangley / https://github.com/WestLangley
  19870. * @author zz85 / https://github.com/zz85
  19871. * @author miningold / https://github.com/miningold
  19872. * @author jonobr1 / https://github.com/jonobr1
  19873. *
  19874. * Modified from the TorusKnotGeometry by @oosmoxiecode
  19875. *
  19876. * Creates a tube which extrudes along a 3d spline
  19877. *
  19878. * Uses parallel transport frames as described in
  19879. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  19880. */
  19881. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  19882. THREE.Geometry.call( this );
  19883. this.type = 'TubeGeometry';
  19884. this.parameters = {
  19885. path: path,
  19886. segments: segments,
  19887. radius: radius,
  19888. radialSegments: radialSegments,
  19889. closed: closed
  19890. };
  19891. segments = segments || 64;
  19892. radius = radius || 1;
  19893. radialSegments = radialSegments || 8;
  19894. closed = closed || false;
  19895. taper = taper || THREE.TubeGeometry.NoTaper;
  19896. var grid = [];
  19897. var scope = this,
  19898. tangent,
  19899. normal,
  19900. binormal,
  19901. numpoints = segments + 1,
  19902. u, v, r,
  19903. cx, cy,
  19904. pos, pos2 = new THREE.Vector3(),
  19905. i, j,
  19906. ip, jp,
  19907. a, b, c, d,
  19908. uva, uvb, uvc, uvd;
  19909. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  19910. tangents = frames.tangents,
  19911. normals = frames.normals,
  19912. binormals = frames.binormals;
  19913. // proxy internals
  19914. this.tangents = tangents;
  19915. this.normals = normals;
  19916. this.binormals = binormals;
  19917. function vert( x, y, z ) {
  19918. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  19919. }
  19920. // construct the grid
  19921. for ( i = 0; i < numpoints; i ++ ) {
  19922. grid[ i ] = [];
  19923. u = i / ( numpoints - 1 );
  19924. pos = path.getPointAt( u );
  19925. tangent = tangents[ i ];
  19926. normal = normals[ i ];
  19927. binormal = binormals[ i ];
  19928. r = radius * taper( u );
  19929. for ( j = 0; j < radialSegments; j ++ ) {
  19930. v = j / radialSegments * 2 * Math.PI;
  19931. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  19932. cy = r * Math.sin( v );
  19933. pos2.copy( pos );
  19934. pos2.x += cx * normal.x + cy * binormal.x;
  19935. pos2.y += cx * normal.y + cy * binormal.y;
  19936. pos2.z += cx * normal.z + cy * binormal.z;
  19937. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  19938. }
  19939. }
  19940. // construct the mesh
  19941. for ( i = 0; i < segments; i ++ ) {
  19942. for ( j = 0; j < radialSegments; j ++ ) {
  19943. ip = ( closed ) ? (i + 1) % segments : i + 1;
  19944. jp = (j + 1) % radialSegments;
  19945. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  19946. b = grid[ ip ][ j ];
  19947. c = grid[ ip ][ jp ];
  19948. d = grid[ i ][ jp ];
  19949. uva = new THREE.Vector2( i / segments, j / radialSegments );
  19950. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  19951. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  19952. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  19953. this.faces.push( new THREE.Face3( a, b, d ) );
  19954. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19955. this.faces.push( new THREE.Face3( b, c, d ) );
  19956. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19957. }
  19958. }
  19959. this.computeFaceNormals();
  19960. this.computeVertexNormals();
  19961. };
  19962. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19963. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  19964. THREE.TubeGeometry.NoTaper = function ( u ) {
  19965. return 1;
  19966. };
  19967. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  19968. return Math.sin( Math.PI * u );
  19969. };
  19970. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  19971. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  19972. var normal = new THREE.Vector3(),
  19973. tangents = [],
  19974. normals = [],
  19975. binormals = [],
  19976. vec = new THREE.Vector3(),
  19977. mat = new THREE.Matrix4(),
  19978. numpoints = segments + 1,
  19979. theta,
  19980. epsilon = 0.0001,
  19981. smallest,
  19982. tx, ty, tz,
  19983. i, u;
  19984. // expose internals
  19985. this.tangents = tangents;
  19986. this.normals = normals;
  19987. this.binormals = binormals;
  19988. // compute the tangent vectors for each segment on the path
  19989. for ( i = 0; i < numpoints; i ++ ) {
  19990. u = i / ( numpoints - 1 );
  19991. tangents[ i ] = path.getTangentAt( u );
  19992. tangents[ i ].normalize();
  19993. }
  19994. initialNormal3();
  19995. /*
  19996. function initialNormal1(lastBinormal) {
  19997. // fixed start binormal. Has dangers of 0 vectors
  19998. normals[ 0 ] = new THREE.Vector3();
  19999. binormals[ 0 ] = new THREE.Vector3();
  20000. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  20001. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  20002. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20003. }
  20004. function initialNormal2() {
  20005. // This uses the Frenet-Serret formula for deriving binormal
  20006. var t2 = path.getTangentAt( epsilon );
  20007. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  20008. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  20009. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  20010. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20011. }
  20012. */
  20013. function initialNormal3() {
  20014. // select an initial normal vector perpendicular to the first tangent vector,
  20015. // and in the direction of the smallest tangent xyz component
  20016. normals[ 0 ] = new THREE.Vector3();
  20017. binormals[ 0 ] = new THREE.Vector3();
  20018. smallest = Number.MAX_VALUE;
  20019. tx = Math.abs( tangents[ 0 ].x );
  20020. ty = Math.abs( tangents[ 0 ].y );
  20021. tz = Math.abs( tangents[ 0 ].z );
  20022. if ( tx <= smallest ) {
  20023. smallest = tx;
  20024. normal.set( 1, 0, 0 );
  20025. }
  20026. if ( ty <= smallest ) {
  20027. smallest = ty;
  20028. normal.set( 0, 1, 0 );
  20029. }
  20030. if ( tz <= smallest ) {
  20031. normal.set( 0, 0, 1 );
  20032. }
  20033. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20034. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20035. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20036. }
  20037. // compute the slowly-varying normal and binormal vectors for each segment on the path
  20038. for ( i = 1; i < numpoints; i ++ ) {
  20039. normals[ i ] = normals[ i - 1 ].clone();
  20040. binormals[ i ] = binormals[ i - 1 ].clone();
  20041. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20042. if ( vec.length() > epsilon ) {
  20043. vec.normalize();
  20044. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20045. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20046. }
  20047. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20048. }
  20049. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20050. if ( closed ) {
  20051. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  20052. theta /= ( numpoints - 1 );
  20053. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  20054. theta = - theta;
  20055. }
  20056. for ( i = 1; i < numpoints; i ++ ) {
  20057. // twist a little...
  20058. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20059. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20060. }
  20061. }
  20062. };
  20063. // File:src/extras/geometries/PolyhedronGeometry.js
  20064. /**
  20065. * @author clockworkgeek / https://github.com/clockworkgeek
  20066. * @author timothypratley / https://github.com/timothypratley
  20067. * @author WestLangley / http://github.com/WestLangley
  20068. */
  20069. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  20070. THREE.Geometry.call( this );
  20071. this.type = 'PolyhedronGeometry';
  20072. this.parameters = {
  20073. vertices: vertices,
  20074. indices: indices,
  20075. radius: radius,
  20076. detail: detail
  20077. };
  20078. radius = radius || 1;
  20079. detail = detail || 0;
  20080. var that = this;
  20081. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  20082. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  20083. }
  20084. var p = this.vertices;
  20085. var faces = [];
  20086. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  20087. var v1 = p[ indices[ i ] ];
  20088. var v2 = p[ indices[ i + 1 ] ];
  20089. var v3 = p[ indices[ i + 2 ] ];
  20090. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  20091. }
  20092. var centroid = new THREE.Vector3();
  20093. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20094. subdivide( faces[ i ], detail );
  20095. }
  20096. // Handle case when face straddles the seam
  20097. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  20098. var uvs = this.faceVertexUvs[ 0 ][ i ];
  20099. var x0 = uvs[ 0 ].x;
  20100. var x1 = uvs[ 1 ].x;
  20101. var x2 = uvs[ 2 ].x;
  20102. var max = Math.max( x0, Math.max( x1, x2 ) );
  20103. var min = Math.min( x0, Math.min( x1, x2 ) );
  20104. if ( max > 0.9 && min < 0.1 ) { // 0.9 is somewhat arbitrary
  20105. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  20106. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  20107. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  20108. }
  20109. }
  20110. // Apply radius
  20111. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  20112. this.vertices[ i ].multiplyScalar( radius );
  20113. }
  20114. // Merge vertices
  20115. this.mergeVertices();
  20116. this.computeFaceNormals();
  20117. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20118. // Project vector onto sphere's surface
  20119. function prepare( vector ) {
  20120. var vertex = vector.normalize().clone();
  20121. vertex.index = that.vertices.push( vertex ) - 1;
  20122. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  20123. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  20124. var v = inclination( vector ) / Math.PI + 0.5;
  20125. vertex.uv = new THREE.Vector2( u, 1 - v );
  20126. return vertex;
  20127. }
  20128. // Approximate a curved face with recursively sub-divided triangles.
  20129. function make( v1, v2, v3 ) {
  20130. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ] );
  20131. that.faces.push( face );
  20132. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  20133. var azi = azimuth( centroid );
  20134. that.faceVertexUvs[ 0 ].push( [
  20135. correctUV( v1.uv, v1, azi ),
  20136. correctUV( v2.uv, v2, azi ),
  20137. correctUV( v3.uv, v3, azi )
  20138. ] );
  20139. }
  20140. // Analytically subdivide a face to the required detail level.
  20141. function subdivide( face, detail ) {
  20142. var cols = Math.pow(2, detail);
  20143. var a = prepare( that.vertices[ face.a ] );
  20144. var b = prepare( that.vertices[ face.b ] );
  20145. var c = prepare( that.vertices[ face.c ] );
  20146. var v = [];
  20147. // Construct all of the vertices for this subdivision.
  20148. for ( var i = 0 ; i <= cols; i ++ ) {
  20149. v[ i ] = [];
  20150. var aj = prepare( a.clone().lerp( c, i / cols ) );
  20151. var bj = prepare( b.clone().lerp( c, i / cols ) );
  20152. var rows = cols - i;
  20153. for ( var j = 0; j <= rows; j ++) {
  20154. if ( j === 0 && i === cols ) {
  20155. v[ i ][ j ] = aj;
  20156. } else {
  20157. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  20158. }
  20159. }
  20160. }
  20161. // Construct all of the faces.
  20162. for ( var i = 0; i < cols ; i ++ ) {
  20163. for ( var j = 0; j < 2 * (cols - i) - 1; j ++ ) {
  20164. var k = Math.floor( j / 2 );
  20165. if ( j % 2 === 0 ) {
  20166. make(
  20167. v[ i ][ k + 1],
  20168. v[ i + 1 ][ k ],
  20169. v[ i ][ k ]
  20170. );
  20171. } else {
  20172. make(
  20173. v[ i ][ k + 1 ],
  20174. v[ i + 1][ k + 1],
  20175. v[ i + 1 ][ k ]
  20176. );
  20177. }
  20178. }
  20179. }
  20180. }
  20181. // Angle around the Y axis, counter-clockwise when looking from above.
  20182. function azimuth( vector ) {
  20183. return Math.atan2( vector.z, - vector.x );
  20184. }
  20185. // Angle above the XZ plane.
  20186. function inclination( vector ) {
  20187. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  20188. }
  20189. // Texture fixing helper. Spheres have some odd behaviours.
  20190. function correctUV( uv, vector, azimuth ) {
  20191. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  20192. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  20193. return uv.clone();
  20194. }
  20195. };
  20196. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20197. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  20198. THREE.PolyhedronGeometry.prototype.clone = function () {
  20199. var geometry = new THREE.PolyhedronGeometry(
  20200. this.parameters.vertices,
  20201. this.parameters.indices,
  20202. this.parameters.radius,
  20203. this.parameters.detail
  20204. );
  20205. return geometry.copy( this );
  20206. };
  20207. THREE.PolyhedronGeometry.prototype.copy = function ( source ) {
  20208. THREE.Geometry.prototype.copy.call( this, source );
  20209. return this;
  20210. };
  20211. // File:src/extras/geometries/DodecahedronGeometry.js
  20212. /**
  20213. * @author Abe Pazos / https://hamoid.com
  20214. */
  20215. THREE.DodecahedronGeometry = function ( radius, detail ) {
  20216. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20217. var r = 1 / t;
  20218. var vertices = [
  20219. // (±1, ±1, ±1)
  20220. -1, -1, -1, -1, -1, 1,
  20221. -1, 1, -1, -1, 1, 1,
  20222. 1, -1, -1, 1, -1, 1,
  20223. 1, 1, -1, 1, 1, 1,
  20224. // (0, ±1/φ, ±φ)
  20225. 0, -r, -t, 0, -r, t,
  20226. 0, r, -t, 0, r, t,
  20227. // (±1/φ, ±φ, 0)
  20228. -r, -t, 0, -r, t, 0,
  20229. r, -t, 0, r, t, 0,
  20230. // (±φ, 0, ±1/φ)
  20231. -t, 0, -r, t, 0, -r,
  20232. -t, 0, r, t, 0, r
  20233. ];
  20234. var indices = [
  20235. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  20236. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  20237. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  20238. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  20239. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  20240. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  20241. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  20242. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  20243. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  20244. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  20245. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  20246. 1, 12, 14, 1, 14, 5, 1, 5, 9
  20247. ];
  20248. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20249. this.type = 'DodecahedronGeometry';
  20250. this.parameters = {
  20251. radius: radius,
  20252. detail: detail
  20253. };
  20254. };
  20255. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20256. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  20257. THREE.DodecahedronGeometry.prototype.clone = function () {
  20258. var geometry = new THREE.DodecahedronGeometry(
  20259. this.parameters.radius,
  20260. this.parameters.detail
  20261. );
  20262. geometry.copy( this );
  20263. return geometry;
  20264. };
  20265. // File:src/extras/geometries/IcosahedronGeometry.js
  20266. /**
  20267. * @author timothypratley / https://github.com/timothypratley
  20268. */
  20269. THREE.IcosahedronGeometry = function ( radius, detail ) {
  20270. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20271. var vertices = [
  20272. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20273. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20274. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20275. ];
  20276. var indices = [
  20277. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20278. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20279. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20280. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20281. ];
  20282. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20283. this.type = 'IcosahedronGeometry';
  20284. this.parameters = {
  20285. radius: radius,
  20286. detail: detail
  20287. };
  20288. };
  20289. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20290. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20291. THREE.IcosahedronGeometry.prototype.clone = function () {
  20292. var geometry = new THREE.IcosahedronGeometry(
  20293. this.parameters.radius,
  20294. this.parameters.detail
  20295. );
  20296. geometry.copy( this );
  20297. return geometry;
  20298. };
  20299. // File:src/extras/geometries/OctahedronGeometry.js
  20300. /**
  20301. * @author timothypratley / https://github.com/timothypratley
  20302. */
  20303. THREE.OctahedronGeometry = function ( radius, detail ) {
  20304. var vertices = [
  20305. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0,- 1, 0, 0, 0, 1, 0, 0,- 1
  20306. ];
  20307. var indices = [
  20308. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20309. ];
  20310. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20311. this.type = 'OctahedronGeometry';
  20312. this.parameters = {
  20313. radius: radius,
  20314. detail: detail
  20315. };
  20316. };
  20317. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20318. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20319. THREE.OctahedronGeometry.prototype.clone = function () {
  20320. var geometry = new THREE.OctahedronGeometry(
  20321. this.parameters.radius,
  20322. this.parameters.detail
  20323. );
  20324. geometry.copy( this );
  20325. return geometry;
  20326. };
  20327. // File:src/extras/geometries/TetrahedronGeometry.js
  20328. /**
  20329. * @author timothypratley / https://github.com/timothypratley
  20330. */
  20331. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20332. var vertices = [
  20333. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20334. ];
  20335. var indices = [
  20336. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20337. ];
  20338. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20339. this.type = 'TetrahedronGeometry';
  20340. this.parameters = {
  20341. radius: radius,
  20342. detail: detail
  20343. };
  20344. };
  20345. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20346. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20347. THREE.TetrahedronGeometry.prototype.clone = function () {
  20348. var geometry = new THREE.TetrahedronGeometry(
  20349. this.parameters.radius,
  20350. this.parameters.detail
  20351. );
  20352. geometry.copy( this );
  20353. return geometry;
  20354. };
  20355. // File:src/extras/geometries/ParametricGeometry.js
  20356. /**
  20357. * @author zz85 / https://github.com/zz85
  20358. * Parametric Surfaces Geometry
  20359. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20360. *
  20361. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20362. *
  20363. */
  20364. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20365. THREE.Geometry.call( this );
  20366. this.type = 'ParametricGeometry';
  20367. this.parameters = {
  20368. func: func,
  20369. slices: slices,
  20370. stacks: stacks
  20371. };
  20372. var verts = this.vertices;
  20373. var faces = this.faces;
  20374. var uvs = this.faceVertexUvs[ 0 ];
  20375. var i, j, p;
  20376. var u, v;
  20377. var sliceCount = slices + 1;
  20378. for ( i = 0; i <= stacks; i ++ ) {
  20379. v = i / stacks;
  20380. for ( j = 0; j <= slices; j ++ ) {
  20381. u = j / slices;
  20382. p = func( u, v );
  20383. verts.push( p );
  20384. }
  20385. }
  20386. var a, b, c, d;
  20387. var uva, uvb, uvc, uvd;
  20388. for ( i = 0; i < stacks; i ++ ) {
  20389. for ( j = 0; j < slices; j ++ ) {
  20390. a = i * sliceCount + j;
  20391. b = i * sliceCount + j + 1;
  20392. c = (i + 1) * sliceCount + j + 1;
  20393. d = (i + 1) * sliceCount + j;
  20394. uva = new THREE.Vector2( j / slices, i / stacks );
  20395. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  20396. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  20397. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  20398. faces.push( new THREE.Face3( a, b, d ) );
  20399. uvs.push( [ uva, uvb, uvd ] );
  20400. faces.push( new THREE.Face3( b, c, d ) );
  20401. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  20402. }
  20403. }
  20404. // console.log(this);
  20405. // magic bullet
  20406. // var diff = this.mergeVertices();
  20407. // console.log('removed ', diff, ' vertices by merging');
  20408. this.computeFaceNormals();
  20409. this.computeVertexNormals();
  20410. };
  20411. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20412. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  20413. // File:src/extras/geometries/WireframeGeometry.js
  20414. /**
  20415. * @author mrdoob / http://mrdoob.com/
  20416. */
  20417. THREE.WireframeGeometry = function ( geometry ) {
  20418. THREE.BufferGeometry.call( this );
  20419. var edge = [ 0, 0 ], hash = {};
  20420. var sortFunction = function ( a, b ) { return a - b; };
  20421. var keys = [ 'a', 'b', 'c' ];
  20422. if ( geometry instanceof THREE.Geometry ) {
  20423. var vertices = geometry.vertices;
  20424. var faces = geometry.faces;
  20425. var numEdges = 0;
  20426. // allocate maximal size
  20427. var edges = new Uint32Array( 6 * faces.length );
  20428. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20429. var face = faces[ i ];
  20430. for ( var j = 0; j < 3; j ++ ) {
  20431. edge[ 0 ] = face[ keys[ j ] ];
  20432. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  20433. edge.sort( sortFunction );
  20434. var key = edge.toString();
  20435. if ( hash[ key ] === undefined ) {
  20436. edges[ 2 * numEdges ] = edge[ 0 ];
  20437. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20438. hash[ key ] = true;
  20439. numEdges ++;
  20440. }
  20441. }
  20442. }
  20443. var coords = new Float32Array( numEdges * 2 * 3 );
  20444. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20445. for ( var j = 0; j < 2; j ++ ) {
  20446. var vertex = vertices[ edges [ 2 * i + j] ];
  20447. var index = 6 * i + 3 * j;
  20448. coords[ index + 0 ] = vertex.x;
  20449. coords[ index + 1 ] = vertex.y;
  20450. coords[ index + 2 ] = vertex.z;
  20451. }
  20452. }
  20453. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20454. } else if ( geometry instanceof THREE.BufferGeometry ) {
  20455. if ( geometry.attributes.index !== undefined ) { // Indexed BufferGeometry
  20456. var vertices = geometry.attributes.position;
  20457. var indices = geometry.attributes.index.array;
  20458. var drawcalls = geometry.drawcalls;
  20459. var numEdges = 0;
  20460. if ( drawcalls.length === 0 ) {
  20461. drawcalls = [ { count : indices.length, index : 0, start : 0 } ];
  20462. }
  20463. // allocate maximal size
  20464. var edges = new Uint32Array( 2 * indices.length );
  20465. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  20466. var start = drawcalls[ o ].start;
  20467. var count = drawcalls[ o ].count;
  20468. var index = drawcalls[ o ].index;
  20469. for ( var i = start, il = start + count; i < il; i += 3 ) {
  20470. for ( var j = 0; j < 3; j ++ ) {
  20471. edge[ 0 ] = index + indices[ i + j ];
  20472. edge[ 1 ] = index + indices[ i + ( j + 1 ) % 3 ];
  20473. edge.sort( sortFunction );
  20474. var key = edge.toString();
  20475. if ( hash[ key ] === undefined ) {
  20476. edges[ 2 * numEdges ] = edge[ 0 ];
  20477. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  20478. hash[ key ] = true;
  20479. numEdges ++;
  20480. }
  20481. }
  20482. }
  20483. }
  20484. var coords = new Float32Array( numEdges * 2 * 3 );
  20485. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  20486. for ( var j = 0; j < 2; j ++ ) {
  20487. var index = 6 * i + 3 * j;
  20488. var index2 = edges[2 * i + j];
  20489. coords[ index + 0 ] = vertices.getX( index2 );
  20490. coords[ index + 1 ] = vertices.getY( index2 );
  20491. coords[ index + 2 ] = vertices.getZ( index2 );
  20492. }
  20493. }
  20494. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20495. } else { // non-indexed BufferGeometry
  20496. var vertices = geometry.attributes.position.array;
  20497. var numEdges = vertices.length / 3;
  20498. var numTris = numEdges / 3;
  20499. var coords = new Float32Array( numEdges * 2 * 3 );
  20500. for ( var i = 0, l = numTris; i < l; i ++ ) {
  20501. for ( var j = 0; j < 3; j ++ ) {
  20502. var index = 18 * i + 6 * j;
  20503. var index1 = 9 * i + 3 * j;
  20504. coords[ index + 0 ] = vertices[ index1 ];
  20505. coords[ index + 1 ] = vertices[ index1 + 1 ];
  20506. coords[ index + 2 ] = vertices[ index1 + 2 ];
  20507. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  20508. coords[ index + 3 ] = vertices[ index2 ];
  20509. coords[ index + 4 ] = vertices[ index2 + 1 ];
  20510. coords[ index + 5 ] = vertices[ index2 + 2 ];
  20511. }
  20512. }
  20513. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  20514. }
  20515. }
  20516. };
  20517. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20518. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  20519. // File:src/extras/helpers/AxisHelper.js
  20520. /**
  20521. * @author sroucheray / http://sroucheray.org/
  20522. * @author mrdoob / http://mrdoob.com/
  20523. */
  20524. THREE.AxisHelper = function ( size ) {
  20525. size = size || 1;
  20526. var vertices = new Float32Array( [
  20527. 0, 0, 0, size, 0, 0,
  20528. 0, 0, 0, 0, size, 0,
  20529. 0, 0, 0, 0, 0, size
  20530. ] );
  20531. var colors = new Float32Array( [
  20532. 1, 0, 0, 1, 0.6, 0,
  20533. 0, 1, 0, 0.6, 1, 0,
  20534. 0, 0, 1, 0, 0.6, 1
  20535. ] );
  20536. var geometry = new THREE.BufferGeometry();
  20537. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20538. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  20539. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20540. THREE.LineSegments.call( this, geometry, material );
  20541. };
  20542. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20543. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  20544. // File:src/extras/helpers/ArrowHelper.js
  20545. /**
  20546. * @author WestLangley / http://github.com/WestLangley
  20547. * @author zz85 / http://github.com/zz85
  20548. * @author bhouston / http://exocortex.com
  20549. *
  20550. * Creates an arrow for visualizing directions
  20551. *
  20552. * Parameters:
  20553. * dir - Vector3
  20554. * origin - Vector3
  20555. * length - Number
  20556. * color - color in hex value
  20557. * headLength - Number
  20558. * headWidth - Number
  20559. */
  20560. THREE.ArrowHelper = ( function () {
  20561. var lineGeometry = new THREE.Geometry();
  20562. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  20563. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  20564. coneGeometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  20565. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  20566. // dir is assumed to be normalized
  20567. THREE.Object3D.call( this );
  20568. if ( color === undefined ) color = 0xffff00;
  20569. if ( length === undefined ) length = 1;
  20570. if ( headLength === undefined ) headLength = 0.2 * length;
  20571. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20572. this.position.copy( origin );
  20573. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  20574. this.line.matrixAutoUpdate = false;
  20575. this.add( this.line );
  20576. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  20577. this.cone.matrixAutoUpdate = false;
  20578. this.add( this.cone );
  20579. this.setDirection( dir );
  20580. this.setLength( length, headLength, headWidth );
  20581. }
  20582. }() );
  20583. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  20584. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  20585. THREE.ArrowHelper.prototype.setDirection = ( function () {
  20586. var axis = new THREE.Vector3();
  20587. var radians;
  20588. return function setDirection( dir ) {
  20589. // dir is assumed to be normalized
  20590. if ( dir.y > 0.99999 ) {
  20591. this.quaternion.set( 0, 0, 0, 1 );
  20592. } else if ( dir.y < - 0.99999 ) {
  20593. this.quaternion.set( 1, 0, 0, 0 );
  20594. } else {
  20595. axis.set( dir.z, 0, - dir.x ).normalize();
  20596. radians = Math.acos( dir.y );
  20597. this.quaternion.setFromAxisAngle( axis, radians );
  20598. }
  20599. };
  20600. }() );
  20601. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  20602. if ( headLength === undefined ) headLength = 0.2 * length;
  20603. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  20604. this.line.scale.set( 1, length - headLength, 1 );
  20605. this.line.updateMatrix();
  20606. this.cone.scale.set( headWidth, headLength, headWidth );
  20607. this.cone.position.y = length;
  20608. this.cone.updateMatrix();
  20609. };
  20610. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  20611. this.line.material.color.set( color );
  20612. this.cone.material.color.set( color );
  20613. };
  20614. // File:src/extras/helpers/BoxHelper.js
  20615. /**
  20616. * @author mrdoob / http://mrdoob.com/
  20617. */
  20618. THREE.BoxHelper = function ( object ) {
  20619. var geometry = new THREE.BufferGeometry();
  20620. geometry.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( 72 ), 3 ) );
  20621. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  20622. if ( object !== undefined ) {
  20623. this.update( object );
  20624. }
  20625. };
  20626. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20627. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  20628. THREE.BoxHelper.prototype.update = ( function () {
  20629. var box = new THREE.Box3();
  20630. return function ( object ) {
  20631. box.setFromObject( object );
  20632. if ( box.empty() ) return;
  20633. var min = box.min;
  20634. var max = box.max;
  20635. /*
  20636. 5____4
  20637. 1/___0/|
  20638. | 6__|_7
  20639. 2/___3/
  20640. 0: max.x, max.y, max.z
  20641. 1: min.x, max.y, max.z
  20642. 2: min.x, min.y, max.z
  20643. 3: max.x, min.y, max.z
  20644. 4: max.x, max.y, min.z
  20645. 5: min.x, max.y, min.z
  20646. 6: min.x, min.y, min.z
  20647. 7: max.x, min.y, min.z
  20648. */
  20649. var vertices = this.geometry.attributes.position.array;
  20650. vertices[ 0 ] = max.x; vertices[ 1 ] = max.y; vertices[ 2 ] = max.z;
  20651. vertices[ 3 ] = min.x; vertices[ 4 ] = max.y; vertices[ 5 ] = max.z;
  20652. vertices[ 6 ] = min.x; vertices[ 7 ] = max.y; vertices[ 8 ] = max.z;
  20653. vertices[ 9 ] = min.x; vertices[ 10 ] = min.y; vertices[ 11 ] = max.z;
  20654. vertices[ 12 ] = min.x; vertices[ 13 ] = min.y; vertices[ 14 ] = max.z;
  20655. vertices[ 15 ] = max.x; vertices[ 16 ] = min.y; vertices[ 17 ] = max.z;
  20656. vertices[ 18 ] = max.x; vertices[ 19 ] = min.y; vertices[ 20 ] = max.z;
  20657. vertices[ 21 ] = max.x; vertices[ 22 ] = max.y; vertices[ 23 ] = max.z;
  20658. //
  20659. vertices[ 24 ] = max.x; vertices[ 25 ] = max.y; vertices[ 26 ] = min.z;
  20660. vertices[ 27 ] = min.x; vertices[ 28 ] = max.y; vertices[ 29 ] = min.z;
  20661. vertices[ 30 ] = min.x; vertices[ 31 ] = max.y; vertices[ 32 ] = min.z;
  20662. vertices[ 33 ] = min.x; vertices[ 34 ] = min.y; vertices[ 35 ] = min.z;
  20663. vertices[ 36 ] = min.x; vertices[ 37 ] = min.y; vertices[ 38 ] = min.z;
  20664. vertices[ 39 ] = max.x; vertices[ 40 ] = min.y; vertices[ 41 ] = min.z;
  20665. vertices[ 42 ] = max.x; vertices[ 43 ] = min.y; vertices[ 44 ] = min.z;
  20666. vertices[ 45 ] = max.x; vertices[ 46 ] = max.y; vertices[ 47 ] = min.z;
  20667. //
  20668. vertices[ 48 ] = max.x; vertices[ 49 ] = max.y; vertices[ 50 ] = max.z;
  20669. vertices[ 51 ] = max.x; vertices[ 52 ] = max.y; vertices[ 53 ] = min.z;
  20670. vertices[ 54 ] = min.x; vertices[ 55 ] = max.y; vertices[ 56 ] = max.z;
  20671. vertices[ 57 ] = min.x; vertices[ 58 ] = max.y; vertices[ 59 ] = min.z;
  20672. vertices[ 60 ] = min.x; vertices[ 61 ] = min.y; vertices[ 62 ] = max.z;
  20673. vertices[ 63 ] = min.x; vertices[ 64 ] = min.y; vertices[ 65 ] = min.z;
  20674. vertices[ 66 ] = max.x; vertices[ 67 ] = min.y; vertices[ 68 ] = max.z;
  20675. vertices[ 69 ] = max.x; vertices[ 70 ] = min.y; vertices[ 71 ] = min.z;
  20676. this.geometry.attributes.position.needsUpdate = true;
  20677. this.geometry.computeBoundingSphere();
  20678. }
  20679. } )();
  20680. // File:src/extras/helpers/BoundingBoxHelper.js
  20681. /**
  20682. * @author WestLangley / http://github.com/WestLangley
  20683. */
  20684. // a helper to show the world-axis-aligned bounding box for an object
  20685. THREE.BoundingBoxHelper = function ( object, hex ) {
  20686. var color = ( hex !== undefined ) ? hex : 0x888888;
  20687. this.object = object;
  20688. this.box = new THREE.Box3();
  20689. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  20690. };
  20691. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  20692. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  20693. THREE.BoundingBoxHelper.prototype.update = function () {
  20694. this.box.setFromObject( this.object );
  20695. this.box.size( this.scale );
  20696. this.box.center( this.position );
  20697. };
  20698. // File:src/extras/helpers/CameraHelper.js
  20699. /**
  20700. * @author alteredq / http://alteredqualia.com/
  20701. *
  20702. * - shows frustum, line of sight and up of the camera
  20703. * - suitable for fast updates
  20704. * - based on frustum visualization in lightgl.js shadowmap example
  20705. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  20706. */
  20707. THREE.CameraHelper = function ( camera ) {
  20708. var geometry = new THREE.Geometry();
  20709. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  20710. var pointMap = {};
  20711. // colors
  20712. var hexFrustum = 0xffaa00;
  20713. var hexCone = 0xff0000;
  20714. var hexUp = 0x00aaff;
  20715. var hexTarget = 0xffffff;
  20716. var hexCross = 0x333333;
  20717. // near
  20718. addLine( "n1", "n2", hexFrustum );
  20719. addLine( "n2", "n4", hexFrustum );
  20720. addLine( "n4", "n3", hexFrustum );
  20721. addLine( "n3", "n1", hexFrustum );
  20722. // far
  20723. addLine( "f1", "f2", hexFrustum );
  20724. addLine( "f2", "f4", hexFrustum );
  20725. addLine( "f4", "f3", hexFrustum );
  20726. addLine( "f3", "f1", hexFrustum );
  20727. // sides
  20728. addLine( "n1", "f1", hexFrustum );
  20729. addLine( "n2", "f2", hexFrustum );
  20730. addLine( "n3", "f3", hexFrustum );
  20731. addLine( "n4", "f4", hexFrustum );
  20732. // cone
  20733. addLine( "p", "n1", hexCone );
  20734. addLine( "p", "n2", hexCone );
  20735. addLine( "p", "n3", hexCone );
  20736. addLine( "p", "n4", hexCone );
  20737. // up
  20738. addLine( "u1", "u2", hexUp );
  20739. addLine( "u2", "u3", hexUp );
  20740. addLine( "u3", "u1", hexUp );
  20741. // target
  20742. addLine( "c", "t", hexTarget );
  20743. addLine( "p", "c", hexCross );
  20744. // cross
  20745. addLine( "cn1", "cn2", hexCross );
  20746. addLine( "cn3", "cn4", hexCross );
  20747. addLine( "cf1", "cf2", hexCross );
  20748. addLine( "cf3", "cf4", hexCross );
  20749. function addLine( a, b, hex ) {
  20750. addPoint( a, hex );
  20751. addPoint( b, hex );
  20752. }
  20753. function addPoint( id, hex ) {
  20754. geometry.vertices.push( new THREE.Vector3() );
  20755. geometry.colors.push( new THREE.Color( hex ) );
  20756. if ( pointMap[ id ] === undefined ) {
  20757. pointMap[ id ] = [];
  20758. }
  20759. pointMap[ id ].push( geometry.vertices.length - 1 );
  20760. }
  20761. THREE.LineSegments.call( this, geometry, material );
  20762. this.camera = camera;
  20763. this.matrix = camera.matrixWorld;
  20764. this.matrixAutoUpdate = false;
  20765. this.pointMap = pointMap;
  20766. this.update();
  20767. };
  20768. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20769. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  20770. THREE.CameraHelper.prototype.update = function () {
  20771. var geometry, pointMap;
  20772. var vector = new THREE.Vector3();
  20773. var camera = new THREE.Camera();
  20774. var setPoint = function ( point, x, y, z ) {
  20775. vector.set( x, y, z ).unproject( camera );
  20776. var points = pointMap[ point ];
  20777. if ( points !== undefined ) {
  20778. for ( var i = 0, il = points.length; i < il; i ++ ) {
  20779. geometry.vertices[ points[ i ] ].copy( vector );
  20780. }
  20781. }
  20782. };
  20783. return function () {
  20784. geometry = this.geometry;
  20785. pointMap = this.pointMap;
  20786. var w = 1, h = 1;
  20787. // we need just camera projection matrix
  20788. // world matrix must be identity
  20789. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  20790. // center / target
  20791. setPoint( "c", 0, 0, - 1 );
  20792. setPoint( "t", 0, 0, 1 );
  20793. // near
  20794. setPoint( "n1", - w, - h, - 1 );
  20795. setPoint( "n2", w, - h, - 1 );
  20796. setPoint( "n3", - w, h, - 1 );
  20797. setPoint( "n4", w, h, - 1 );
  20798. // far
  20799. setPoint( "f1", - w, - h, 1 );
  20800. setPoint( "f2", w, - h, 1 );
  20801. setPoint( "f3", - w, h, 1 );
  20802. setPoint( "f4", w, h, 1 );
  20803. // up
  20804. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  20805. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  20806. setPoint( "u3", 0, h * 2, - 1 );
  20807. // cross
  20808. setPoint( "cf1", - w, 0, 1 );
  20809. setPoint( "cf2", w, 0, 1 );
  20810. setPoint( "cf3", 0, - h, 1 );
  20811. setPoint( "cf4", 0, h, 1 );
  20812. setPoint( "cn1", - w, 0, - 1 );
  20813. setPoint( "cn2", w, 0, - 1 );
  20814. setPoint( "cn3", 0, - h, - 1 );
  20815. setPoint( "cn4", 0, h, - 1 );
  20816. geometry.verticesNeedUpdate = true;
  20817. };
  20818. }();
  20819. // File:src/extras/helpers/DirectionalLightHelper.js
  20820. /**
  20821. * @author alteredq / http://alteredqualia.com/
  20822. * @author mrdoob / http://mrdoob.com/
  20823. * @author WestLangley / http://github.com/WestLangley
  20824. */
  20825. THREE.DirectionalLightHelper = function ( light, size ) {
  20826. THREE.Object3D.call( this );
  20827. this.light = light;
  20828. this.light.updateMatrixWorld();
  20829. this.matrix = light.matrixWorld;
  20830. this.matrixAutoUpdate = false;
  20831. size = size || 1;
  20832. var geometry = new THREE.Geometry();
  20833. geometry.vertices.push(
  20834. new THREE.Vector3( - size, size, 0 ),
  20835. new THREE.Vector3( size, size, 0 ),
  20836. new THREE.Vector3( size, - size, 0 ),
  20837. new THREE.Vector3( - size, - size, 0 ),
  20838. new THREE.Vector3( - size, size, 0 )
  20839. );
  20840. var material = new THREE.LineBasicMaterial( { fog: false } );
  20841. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20842. this.lightPlane = new THREE.Line( geometry, material );
  20843. this.add( this.lightPlane );
  20844. geometry = new THREE.Geometry();
  20845. geometry.vertices.push(
  20846. new THREE.Vector3(),
  20847. new THREE.Vector3()
  20848. );
  20849. material = new THREE.LineBasicMaterial( { fog: false } );
  20850. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20851. this.targetLine = new THREE.Line( geometry, material );
  20852. this.add( this.targetLine );
  20853. this.update();
  20854. };
  20855. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  20856. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  20857. THREE.DirectionalLightHelper.prototype.dispose = function () {
  20858. this.lightPlane.geometry.dispose();
  20859. this.lightPlane.material.dispose();
  20860. this.targetLine.geometry.dispose();
  20861. this.targetLine.material.dispose();
  20862. };
  20863. THREE.DirectionalLightHelper.prototype.update = function () {
  20864. var v1 = new THREE.Vector3();
  20865. var v2 = new THREE.Vector3();
  20866. var v3 = new THREE.Vector3();
  20867. return function () {
  20868. v1.setFromMatrixPosition( this.light.matrixWorld );
  20869. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  20870. v3.subVectors( v2, v1 );
  20871. this.lightPlane.lookAt( v3 );
  20872. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  20873. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  20874. this.targetLine.geometry.verticesNeedUpdate = true;
  20875. this.targetLine.material.color.copy( this.lightPlane.material.color );
  20876. };
  20877. }();
  20878. // File:src/extras/helpers/EdgesHelper.js
  20879. /**
  20880. * @author WestLangley / http://github.com/WestLangley
  20881. * @param object THREE.Mesh whose geometry will be used
  20882. * @param hex line color
  20883. * @param thresholdAngle the minimum angle (in degrees),
  20884. * between the face normals of adjacent faces,
  20885. * that is required to render an edge. A value of 10 means
  20886. * an edge is only rendered if the angle is at least 10 degrees.
  20887. */
  20888. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  20889. var color = ( hex !== undefined ) ? hex : 0xffffff;
  20890. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  20891. this.matrix = object.matrixWorld;
  20892. this.matrixAutoUpdate = false;
  20893. };
  20894. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20895. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  20896. // File:src/extras/helpers/FaceNormalsHelper.js
  20897. /**
  20898. * @author mrdoob / http://mrdoob.com/
  20899. * @author WestLangley / http://github.com/WestLangley
  20900. */
  20901. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  20902. // FaceNormalsHelper only supports THREE.Geometry
  20903. this.object = object;
  20904. this.size = ( size !== undefined ) ? size : 1;
  20905. var color = ( hex !== undefined ) ? hex : 0xffff00;
  20906. var width = ( linewidth !== undefined ) ? linewidth : 1;
  20907. //
  20908. var nNormals = 0;
  20909. var objGeometry = this.object.geometry;
  20910. if ( objGeometry instanceof THREE.Geometry ) {
  20911. nNormals = objGeometry.faces.length;
  20912. } else {
  20913. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  20914. }
  20915. //
  20916. var geometry = new THREE.BufferGeometry();
  20917. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  20918. geometry.addAttribute( 'position', positions );
  20919. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  20920. //
  20921. this.matrixAutoUpdate = false;
  20922. this.normalMatrix = new THREE.Matrix3();
  20923. this.update();
  20924. };
  20925. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20926. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  20927. THREE.FaceNormalsHelper.prototype.update = ( function () {
  20928. var v1 = new THREE.Vector3();
  20929. var v2 = new THREE.Vector3();
  20930. return function update() {
  20931. this.object.updateMatrixWorld( true );
  20932. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  20933. var matrixWorld = this.object.matrixWorld;
  20934. var position = this.geometry.attributes.position;
  20935. //
  20936. var objGeometry = this.object.geometry;
  20937. var vertices = objGeometry.vertices;
  20938. var faces = objGeometry.faces;
  20939. var idx = 0;
  20940. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20941. var face = faces[ i ];
  20942. var normal = face.normal;
  20943. v1.copy( vertices[ face.a ] )
  20944. .add( vertices[ face.b ] )
  20945. .add( vertices[ face.c ] )
  20946. .divideScalar( 3 )
  20947. .applyMatrix4( matrixWorld );
  20948. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  20949. position.setXYZ( idx, v1.x, v1.y, v1.z );
  20950. idx = idx + 1;
  20951. position.setXYZ( idx, v2.x, v2.y, v2.z );
  20952. idx = idx + 1;
  20953. }
  20954. position.needsUpdate = true;
  20955. return this;
  20956. }
  20957. }());
  20958. // File:src/extras/helpers/GridHelper.js
  20959. /**
  20960. * @author mrdoob / http://mrdoob.com/
  20961. */
  20962. THREE.GridHelper = function ( size, step ) {
  20963. var geometry = new THREE.Geometry();
  20964. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  20965. this.color1 = new THREE.Color( 0x444444 );
  20966. this.color2 = new THREE.Color( 0x888888 );
  20967. for ( var i = - size; i <= size; i += step ) {
  20968. geometry.vertices.push(
  20969. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  20970. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  20971. );
  20972. var color = i === 0 ? this.color1 : this.color2;
  20973. geometry.colors.push( color, color, color, color );
  20974. }
  20975. THREE.LineSegments.call( this, geometry, material );
  20976. };
  20977. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  20978. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  20979. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  20980. this.color1.set( colorCenterLine );
  20981. this.color2.set( colorGrid );
  20982. this.geometry.colorsNeedUpdate = true;
  20983. };
  20984. // File:src/extras/helpers/HemisphereLightHelper.js
  20985. /**
  20986. * @author alteredq / http://alteredqualia.com/
  20987. * @author mrdoob / http://mrdoob.com/
  20988. */
  20989. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  20990. THREE.Object3D.call( this );
  20991. this.light = light;
  20992. this.light.updateMatrixWorld();
  20993. this.matrix = light.matrixWorld;
  20994. this.matrixAutoUpdate = false;
  20995. this.colors = [ new THREE.Color(), new THREE.Color() ];
  20996. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  20997. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  20998. for ( var i = 0, il = 8; i < il; i ++ ) {
  20999. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  21000. }
  21001. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  21002. this.lightSphere = new THREE.Mesh( geometry, material );
  21003. this.add( this.lightSphere );
  21004. this.update();
  21005. };
  21006. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21007. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  21008. THREE.HemisphereLightHelper.prototype.dispose = function () {
  21009. this.lightSphere.geometry.dispose();
  21010. this.lightSphere.material.dispose();
  21011. };
  21012. THREE.HemisphereLightHelper.prototype.update = function () {
  21013. var vector = new THREE.Vector3();
  21014. return function () {
  21015. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  21016. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  21017. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  21018. this.lightSphere.geometry.colorsNeedUpdate = true;
  21019. }
  21020. }();
  21021. // File:src/extras/helpers/PointLightHelper.js
  21022. /**
  21023. * @author alteredq / http://alteredqualia.com/
  21024. * @author mrdoob / http://mrdoob.com/
  21025. */
  21026. THREE.PointLightHelper = function ( light, sphereSize ) {
  21027. this.light = light;
  21028. this.light.updateMatrixWorld();
  21029. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21030. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21031. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21032. THREE.Mesh.call( this, geometry, material );
  21033. this.matrix = this.light.matrixWorld;
  21034. this.matrixAutoUpdate = false;
  21035. /*
  21036. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21037. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21038. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21039. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21040. var d = light.distance;
  21041. if ( d === 0.0 ) {
  21042. this.lightDistance.visible = false;
  21043. } else {
  21044. this.lightDistance.scale.set( d, d, d );
  21045. }
  21046. this.add( this.lightDistance );
  21047. */
  21048. };
  21049. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  21050. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  21051. THREE.PointLightHelper.prototype.dispose = function () {
  21052. this.geometry.dispose();
  21053. this.material.dispose();
  21054. };
  21055. THREE.PointLightHelper.prototype.update = function () {
  21056. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21057. /*
  21058. var d = this.light.distance;
  21059. if ( d === 0.0 ) {
  21060. this.lightDistance.visible = false;
  21061. } else {
  21062. this.lightDistance.visible = true;
  21063. this.lightDistance.scale.set( d, d, d );
  21064. }
  21065. */
  21066. };
  21067. // File:src/extras/helpers/SkeletonHelper.js
  21068. /**
  21069. * @author Sean Griffin / http://twitter.com/sgrif
  21070. * @author Michael Guerrero / http://realitymeltdown.com
  21071. * @author mrdoob / http://mrdoob.com/
  21072. * @author ikerr / http://verold.com
  21073. */
  21074. THREE.SkeletonHelper = function ( object ) {
  21075. this.bones = this.getBoneList( object );
  21076. var geometry = new THREE.Geometry();
  21077. for ( var i = 0; i < this.bones.length; i ++ ) {
  21078. var bone = this.bones[ i ];
  21079. if ( bone.parent instanceof THREE.Bone ) {
  21080. geometry.vertices.push( new THREE.Vector3() );
  21081. geometry.vertices.push( new THREE.Vector3() );
  21082. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  21083. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  21084. }
  21085. }
  21086. geometry.dynamic = true;
  21087. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  21088. THREE.LineSegments.call( this, geometry, material );
  21089. this.root = object;
  21090. this.matrix = object.matrixWorld;
  21091. this.matrixAutoUpdate = false;
  21092. this.update();
  21093. };
  21094. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21095. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  21096. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  21097. var boneList = [];
  21098. if ( object instanceof THREE.Bone ) {
  21099. boneList.push( object );
  21100. }
  21101. for ( var i = 0; i < object.children.length; i ++ ) {
  21102. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  21103. }
  21104. return boneList;
  21105. };
  21106. THREE.SkeletonHelper.prototype.update = function () {
  21107. var geometry = this.geometry;
  21108. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  21109. var boneMatrix = new THREE.Matrix4();
  21110. var j = 0;
  21111. for ( var i = 0; i < this.bones.length; i ++ ) {
  21112. var bone = this.bones[ i ];
  21113. if ( bone.parent instanceof THREE.Bone ) {
  21114. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  21115. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  21116. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  21117. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  21118. j += 2;
  21119. }
  21120. }
  21121. geometry.verticesNeedUpdate = true;
  21122. geometry.computeBoundingSphere();
  21123. };
  21124. // File:src/extras/helpers/SpotLightHelper.js
  21125. /**
  21126. * @author alteredq / http://alteredqualia.com/
  21127. * @author mrdoob / http://mrdoob.com/
  21128. * @author WestLangley / http://github.com/WestLangley
  21129. */
  21130. THREE.SpotLightHelper = function ( light ) {
  21131. THREE.Object3D.call( this );
  21132. this.light = light;
  21133. this.light.updateMatrixWorld();
  21134. this.matrix = light.matrixWorld;
  21135. this.matrixAutoUpdate = false;
  21136. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  21137. geometry.applyMatrix( new THREE.Matrix4().makeTranslation( 0, - 0.5, 0 ) );
  21138. geometry.applyMatrix( new THREE.Matrix4().makeRotationX( - Math.PI / 2 ) );
  21139. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21140. this.cone = new THREE.Mesh( geometry, material );
  21141. this.add( this.cone );
  21142. this.update();
  21143. };
  21144. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21145. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  21146. THREE.SpotLightHelper.prototype.dispose = function () {
  21147. this.cone.geometry.dispose();
  21148. this.cone.material.dispose();
  21149. };
  21150. THREE.SpotLightHelper.prototype.update = function () {
  21151. var vector = new THREE.Vector3();
  21152. var vector2 = new THREE.Vector3();
  21153. return function () {
  21154. var coneLength = this.light.distance ? this.light.distance : 10000;
  21155. var coneWidth = coneLength * Math.tan( this.light.angle );
  21156. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21157. vector.setFromMatrixPosition( this.light.matrixWorld );
  21158. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  21159. this.cone.lookAt( vector2.sub( vector ) );
  21160. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21161. };
  21162. }();
  21163. // File:src/extras/helpers/VertexNormalsHelper.js
  21164. /**
  21165. * @author mrdoob / http://mrdoob.com/
  21166. * @author WestLangley / http://github.com/WestLangley
  21167. */
  21168. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  21169. this.object = object;
  21170. this.size = ( size !== undefined ) ? size : 1;
  21171. var color = ( hex !== undefined ) ? hex : 0xff0000;
  21172. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21173. //
  21174. var nNormals = 0;
  21175. var objGeometry = this.object.geometry;
  21176. if ( objGeometry instanceof THREE.Geometry ) {
  21177. nNormals = objGeometry.faces.length * 3;
  21178. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21179. nNormals = objGeometry.attributes.normal.count
  21180. }
  21181. //
  21182. var geometry = new THREE.BufferGeometry();
  21183. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21184. geometry.addAttribute( 'position', positions );
  21185. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21186. //
  21187. this.matrixAutoUpdate = false;
  21188. this.normalMatrix = new THREE.Matrix3();
  21189. this.update();
  21190. };
  21191. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21192. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  21193. THREE.VertexNormalsHelper.prototype.update = ( function () {
  21194. var v1 = new THREE.Vector3();
  21195. var v2 = new THREE.Vector3();
  21196. return function update() {
  21197. var keys = [ 'a', 'b', 'c' ];
  21198. this.object.updateMatrixWorld( true );
  21199. this.normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21200. var matrixWorld = this.object.matrixWorld;
  21201. var position = this.geometry.attributes.position;
  21202. //
  21203. var objGeometry = this.object.geometry;
  21204. if ( objGeometry instanceof THREE.Geometry ) {
  21205. var vertices = objGeometry.vertices;
  21206. var faces = objGeometry.faces;
  21207. var idx = 0;
  21208. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21209. var face = faces[ i ];
  21210. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  21211. var vertex = vertices[ face[ keys[ j ] ] ];
  21212. var normal = face.vertexNormals[ j ];
  21213. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21214. v2.copy( normal ).applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21215. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21216. idx = idx + 1;
  21217. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21218. idx = idx + 1;
  21219. }
  21220. }
  21221. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21222. var objPos = objGeometry.attributes.position;
  21223. var objNorm = objGeometry.attributes.normal;
  21224. var idx = 0;
  21225. // for simplicity, ignore index and drawcalls, and render every normal
  21226. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21227. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21228. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  21229. v2.applyMatrix3( this.normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21230. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21231. idx = idx + 1;
  21232. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21233. idx = idx + 1;
  21234. }
  21235. }
  21236. position.needsUpdate = true;
  21237. return this;
  21238. }
  21239. }());
  21240. // File:src/extras/helpers/VertexTangentsHelper.js
  21241. /**
  21242. * @author mrdoob / http://mrdoob.com/
  21243. * @author WestLangley / http://github.com/WestLangley
  21244. */
  21245. THREE.VertexTangentsHelper = function ( object, size, hex, linewidth ) {
  21246. this.object = object;
  21247. this.size = ( size !== undefined ) ? size : 1;
  21248. var color = ( hex !== undefined ) ? hex : 0x0000ff;
  21249. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21250. //
  21251. var nTangents = 0;
  21252. var objGeometry = this.object.geometry;
  21253. if ( objGeometry instanceof THREE.Geometry ) {
  21254. nTangents = objGeometry.faces.length * 3;
  21255. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21256. nTangents = objGeometry.attributes.tangent.count
  21257. }
  21258. //
  21259. var geometry = new THREE.BufferGeometry();
  21260. var positions = new THREE.Float32Attribute( nTangents * 2 * 3, 3 );
  21261. geometry.addAttribute( 'position', positions );
  21262. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21263. //
  21264. this.matrixAutoUpdate = false;
  21265. this.update();
  21266. };
  21267. THREE.VertexTangentsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21268. THREE.VertexTangentsHelper.prototype.constructor = THREE.VertexTangentsHelper;
  21269. THREE.VertexTangentsHelper.prototype.update = ( function ( object ) {
  21270. var v1 = new THREE.Vector3();
  21271. var v2 = new THREE.Vector3();
  21272. return function() {
  21273. var keys = [ 'a', 'b', 'c' ];
  21274. this.object.updateMatrixWorld( true );
  21275. var matrixWorld = this.object.matrixWorld;
  21276. var position = this.geometry.attributes.position;
  21277. //
  21278. var objGeometry = this.object.geometry;
  21279. if ( objGeometry instanceof THREE.Geometry ) {
  21280. var vertices = objGeometry.vertices;
  21281. var faces = objGeometry.faces;
  21282. var idx = 0;
  21283. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21284. var face = faces[ i ];
  21285. for ( var j = 0, jl = face.vertexTangents.length; j < jl; j ++ ) {
  21286. var vertex = vertices[ face[ keys[ j ] ] ];
  21287. var tangent = face.vertexTangents[ j ];
  21288. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21289. v2.set( tangent.x, tangent.y, tangent.z ); // tangent.w used for bitangents only
  21290. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  21291. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21292. idx = idx + 1;
  21293. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21294. idx = idx + 1;
  21295. }
  21296. }
  21297. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21298. var objPos = objGeometry.attributes.position;
  21299. var objTan = objGeometry.attributes.tangent;
  21300. var idx = 0;
  21301. // for simplicity, ignore index and drawcalls, and render every tangent
  21302. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21303. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21304. v2.set( objTan.getX( j ), objTan.getY( j ), objTan.getZ( j ) ); // tangent.w used for bitangents only
  21305. v2.transformDirection( matrixWorld ).multiplyScalar( this.size ).add( v1 );
  21306. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21307. idx = idx + 1;
  21308. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21309. idx = idx + 1;
  21310. }
  21311. }
  21312. position.needsUpdate = true;
  21313. return this;
  21314. }
  21315. }());
  21316. // File:src/extras/helpers/WireframeHelper.js
  21317. /**
  21318. * @author mrdoob / http://mrdoob.com/
  21319. */
  21320. THREE.WireframeHelper = function ( object, hex ) {
  21321. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21322. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21323. this.matrix = object.matrixWorld;
  21324. this.matrixAutoUpdate = false;
  21325. };
  21326. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21327. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21328. // File:src/extras/objects/ImmediateRenderObject.js
  21329. /**
  21330. * @author alteredq / http://alteredqualia.com/
  21331. */
  21332. THREE.ImmediateRenderObject = function () {
  21333. THREE.Object3D.call( this );
  21334. this.render = function ( renderCallback ) {};
  21335. };
  21336. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21337. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21338. // File:src/extras/objects/MorphBlendMesh.js
  21339. /**
  21340. * @author alteredq / http://alteredqualia.com/
  21341. */
  21342. THREE.MorphBlendMesh = function( geometry, material ) {
  21343. THREE.Mesh.call( this, geometry, material );
  21344. this.animationsMap = {};
  21345. this.animationsList = [];
  21346. // prepare default animation
  21347. // (all frames played together in 1 second)
  21348. var numFrames = this.geometry.morphTargets.length;
  21349. var name = "__default";
  21350. var startFrame = 0;
  21351. var endFrame = numFrames - 1;
  21352. var fps = numFrames / 1;
  21353. this.createAnimation( name, startFrame, endFrame, fps );
  21354. this.setAnimationWeight( name, 1 );
  21355. };
  21356. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21357. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21358. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21359. var animation = {
  21360. startFrame: start,
  21361. endFrame: end,
  21362. length: end - start + 1,
  21363. fps: fps,
  21364. duration: ( end - start ) / fps,
  21365. lastFrame: 0,
  21366. currentFrame: 0,
  21367. active: false,
  21368. time: 0,
  21369. direction: 1,
  21370. weight: 1,
  21371. directionBackwards: false,
  21372. mirroredLoop: false
  21373. };
  21374. this.animationsMap[ name ] = animation;
  21375. this.animationsList.push( animation );
  21376. };
  21377. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21378. var pattern = /([a-z]+)_?(\d+)/;
  21379. var firstAnimation, frameRanges = {};
  21380. var geometry = this.geometry;
  21381. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21382. var morph = geometry.morphTargets[ i ];
  21383. var chunks = morph.name.match( pattern );
  21384. if ( chunks && chunks.length > 1 ) {
  21385. var name = chunks[ 1 ];
  21386. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21387. var range = frameRanges[ name ];
  21388. if ( i < range.start ) range.start = i;
  21389. if ( i > range.end ) range.end = i;
  21390. if ( ! firstAnimation ) firstAnimation = name;
  21391. }
  21392. }
  21393. for ( var name in frameRanges ) {
  21394. var range = frameRanges[ name ];
  21395. this.createAnimation( name, range.start, range.end, fps );
  21396. }
  21397. this.firstAnimation = firstAnimation;
  21398. };
  21399. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21400. var animation = this.animationsMap[ name ];
  21401. if ( animation ) {
  21402. animation.direction = 1;
  21403. animation.directionBackwards = false;
  21404. }
  21405. };
  21406. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21407. var animation = this.animationsMap[ name ];
  21408. if ( animation ) {
  21409. animation.direction = - 1;
  21410. animation.directionBackwards = true;
  21411. }
  21412. };
  21413. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21414. var animation = this.animationsMap[ name ];
  21415. if ( animation ) {
  21416. animation.fps = fps;
  21417. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21418. }
  21419. };
  21420. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21421. var animation = this.animationsMap[ name ];
  21422. if ( animation ) {
  21423. animation.duration = duration;
  21424. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21425. }
  21426. };
  21427. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21428. var animation = this.animationsMap[ name ];
  21429. if ( animation ) {
  21430. animation.weight = weight;
  21431. }
  21432. };
  21433. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21434. var animation = this.animationsMap[ name ];
  21435. if ( animation ) {
  21436. animation.time = time;
  21437. }
  21438. };
  21439. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21440. var time = 0;
  21441. var animation = this.animationsMap[ name ];
  21442. if ( animation ) {
  21443. time = animation.time;
  21444. }
  21445. return time;
  21446. };
  21447. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21448. var duration = - 1;
  21449. var animation = this.animationsMap[ name ];
  21450. if ( animation ) {
  21451. duration = animation.duration;
  21452. }
  21453. return duration;
  21454. };
  21455. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21456. var animation = this.animationsMap[ name ];
  21457. if ( animation ) {
  21458. animation.time = 0;
  21459. animation.active = true;
  21460. } else {
  21461. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21462. }
  21463. };
  21464. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21465. var animation = this.animationsMap[ name ];
  21466. if ( animation ) {
  21467. animation.active = false;
  21468. }
  21469. };
  21470. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  21471. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  21472. var animation = this.animationsList[ i ];
  21473. if ( ! animation.active ) continue;
  21474. var frameTime = animation.duration / animation.length;
  21475. animation.time += animation.direction * delta;
  21476. if ( animation.mirroredLoop ) {
  21477. if ( animation.time > animation.duration || animation.time < 0 ) {
  21478. animation.direction *= - 1;
  21479. if ( animation.time > animation.duration ) {
  21480. animation.time = animation.duration;
  21481. animation.directionBackwards = true;
  21482. }
  21483. if ( animation.time < 0 ) {
  21484. animation.time = 0;
  21485. animation.directionBackwards = false;
  21486. }
  21487. }
  21488. } else {
  21489. animation.time = animation.time % animation.duration;
  21490. if ( animation.time < 0 ) animation.time += animation.duration;
  21491. }
  21492. var keyframe = animation.startFrame + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  21493. var weight = animation.weight;
  21494. if ( keyframe !== animation.currentFrame ) {
  21495. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  21496. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  21497. this.morphTargetInfluences[ keyframe ] = 0;
  21498. animation.lastFrame = animation.currentFrame;
  21499. animation.currentFrame = keyframe;
  21500. }
  21501. var mix = ( animation.time % frameTime ) / frameTime;
  21502. if ( animation.directionBackwards ) mix = 1 - mix;
  21503. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  21504. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  21505. }
  21506. };