three.js 807 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616126171261812619126201262112622126231262412625126261262712628126291263012631126321263312634126351263612637126381263912640126411264212643126441264512646126471264812649126501265112652126531265412655126561265712658126591266012661126621266312664126651266612667126681266912670126711267212673126741267512676126771267812679126801268112682126831268412685126861268712688126891269012691126921269312694126951269612697126981269912700127011270212703127041270512706127071270812709127101271112712127131271412715127161271712718127191272012721127221272312724127251272612727127281272912730127311273212733127341273512736127371273812739127401274112742127431274412745127461274712748127491275012751127521275312754127551275612757127581275912760127611276212763127641276512766127671276812769127701277112772127731277412775127761277712778127791278012781127821278312784127851278612787127881278912790127911279212793127941279512796127971279812799128001280112802128031280412805128061280712808128091281012811128121281312814128151281612817128181281912820128211282212823128241282512826128271282812829128301283112832128331283412835128361283712838128391284012841128421284312844128451284612847128481284912850128511285212853128541285512856128571285812859128601286112862128631286412865128661286712868128691287012871128721287312874128751287612877128781287912880128811288212883128841288512886128871288812889128901289112892128931289412895128961289712898128991290012901129021290312904129051290612907129081290912910129111291212913129141291512916129171291812919129201292112922129231292412925129261292712928129291293012931129321293312934129351293612937129381293912940129411294212943129441294512946129471294812949129501295112952129531295412955129561295712958129591296012961129621296312964129651296612967129681296912970129711297212973129741297512976129771297812979129801298112982129831298412985129861298712988129891299012991129921299312994129951299612997129981299913000130011300213003130041300513006130071300813009130101301113012130131301413015130161301713018130191302013021130221302313024130251302613027130281302913030130311303213033130341303513036130371303813039130401304113042130431304413045130461304713048130491305013051130521305313054130551305613057130581305913060130611306213063130641306513066130671306813069130701307113072130731307413075130761307713078130791308013081130821308313084130851308613087130881308913090130911309213093130941309513096130971309813099131001310113102131031310413105131061310713108131091311013111131121311313114131151311613117131181311913120131211312213123131241312513126131271312813129131301313113132131331313413135131361313713138131391314013141131421314313144131451314613147131481314913150131511315213153131541315513156131571315813159131601316113162131631316413165131661316713168131691317013171131721317313174131751317613177131781317913180131811318213183131841318513186131871318813189131901319113192131931319413195131961319713198131991320013201132021320313204132051320613207132081320913210132111321213213132141321513216132171321813219132201322113222132231322413225132261322713228132291323013231132321323313234132351323613237132381323913240132411324213243132441324513246132471324813249132501325113252132531325413255132561325713258132591326013261132621326313264132651326613267132681326913270132711327213273132741327513276132771327813279132801328113282132831328413285132861328713288132891329013291132921329313294132951329613297132981329913300133011330213303133041330513306133071330813309133101331113312133131331413315133161331713318133191332013321133221332313324133251332613327133281332913330133311333213333133341333513336133371333813339133401334113342133431334413345133461334713348133491335013351133521335313354133551335613357133581335913360133611336213363133641336513366133671336813369133701337113372133731337413375133761337713378133791338013381133821338313384133851338613387133881338913390133911339213393133941339513396133971339813399134001340113402134031340413405134061340713408134091341013411134121341313414134151341613417134181341913420134211342213423134241342513426134271342813429134301343113432134331343413435134361343713438134391344013441134421344313444134451344613447134481344913450134511345213453134541345513456134571345813459134601346113462134631346413465134661346713468134691347013471134721347313474134751347613477134781347913480134811348213483134841348513486134871348813489134901349113492134931349413495134961349713498134991350013501135021350313504135051350613507135081350913510135111351213513135141351513516135171351813519135201352113522135231352413525135261352713528135291353013531135321353313534135351353613537135381353913540135411354213543135441354513546135471354813549135501355113552135531355413555135561355713558135591356013561135621356313564135651356613567135681356913570135711357213573135741357513576135771357813579135801358113582135831358413585135861358713588135891359013591135921359313594135951359613597135981359913600136011360213603136041360513606136071360813609136101361113612136131361413615136161361713618136191362013621136221362313624136251362613627136281362913630136311363213633136341363513636136371363813639136401364113642136431364413645136461364713648136491365013651136521365313654136551365613657136581365913660136611366213663136641366513666136671366813669136701367113672136731367413675136761367713678136791368013681136821368313684136851368613687136881368913690136911369213693136941369513696136971369813699137001370113702137031370413705137061370713708137091371013711137121371313714137151371613717137181371913720137211372213723137241372513726137271372813729137301373113732137331373413735137361373713738137391374013741137421374313744137451374613747137481374913750137511375213753137541375513756137571375813759137601376113762137631376413765137661376713768137691377013771137721377313774137751377613777137781377913780137811378213783137841378513786137871378813789137901379113792137931379413795137961379713798137991380013801138021380313804138051380613807138081380913810138111381213813138141381513816138171381813819138201382113822138231382413825138261382713828138291383013831138321383313834138351383613837138381383913840138411384213843138441384513846138471384813849138501385113852138531385413855138561385713858138591386013861138621386313864138651386613867138681386913870138711387213873138741387513876138771387813879138801388113882138831388413885138861388713888138891389013891138921389313894138951389613897138981389913900139011390213903139041390513906139071390813909139101391113912139131391413915139161391713918139191392013921139221392313924139251392613927139281392913930139311393213933139341393513936139371393813939139401394113942139431394413945139461394713948139491395013951139521395313954139551395613957139581395913960139611396213963139641396513966139671396813969139701397113972139731397413975139761397713978139791398013981139821398313984139851398613987139881398913990139911399213993139941399513996139971399813999140001400114002140031400414005140061400714008140091401014011140121401314014140151401614017140181401914020140211402214023140241402514026140271402814029140301403114032140331403414035140361403714038140391404014041140421404314044140451404614047140481404914050140511405214053140541405514056140571405814059140601406114062140631406414065140661406714068140691407014071140721407314074140751407614077140781407914080140811408214083140841408514086140871408814089140901409114092140931409414095140961409714098140991410014101141021410314104141051410614107141081410914110141111411214113141141411514116141171411814119141201412114122141231412414125141261412714128141291413014131141321413314134141351413614137141381413914140141411414214143141441414514146141471414814149141501415114152141531415414155141561415714158141591416014161141621416314164141651416614167141681416914170141711417214173141741417514176141771417814179141801418114182141831418414185141861418714188141891419014191141921419314194141951419614197141981419914200142011420214203142041420514206142071420814209142101421114212142131421414215142161421714218142191422014221142221422314224142251422614227142281422914230142311423214233142341423514236142371423814239142401424114242142431424414245142461424714248142491425014251142521425314254142551425614257142581425914260142611426214263142641426514266142671426814269142701427114272142731427414275142761427714278142791428014281142821428314284142851428614287142881428914290142911429214293142941429514296142971429814299143001430114302143031430414305143061430714308143091431014311143121431314314143151431614317143181431914320143211432214323143241432514326143271432814329143301433114332143331433414335143361433714338143391434014341143421434314344143451434614347143481434914350143511435214353143541435514356143571435814359143601436114362143631436414365143661436714368143691437014371143721437314374143751437614377143781437914380143811438214383143841438514386143871438814389143901439114392143931439414395143961439714398143991440014401144021440314404144051440614407144081440914410144111441214413144141441514416144171441814419144201442114422144231442414425144261442714428144291443014431144321443314434144351443614437144381443914440144411444214443144441444514446144471444814449144501445114452144531445414455144561445714458144591446014461144621446314464144651446614467144681446914470144711447214473144741447514476144771447814479144801448114482144831448414485144861448714488144891449014491144921449314494144951449614497144981449914500145011450214503145041450514506145071450814509145101451114512145131451414515145161451714518145191452014521145221452314524145251452614527145281452914530145311453214533145341453514536145371453814539145401454114542145431454414545145461454714548145491455014551145521455314554145551455614557145581455914560145611456214563145641456514566145671456814569145701457114572145731457414575145761457714578145791458014581145821458314584145851458614587145881458914590145911459214593145941459514596145971459814599146001460114602146031460414605146061460714608146091461014611146121461314614146151461614617146181461914620146211462214623146241462514626146271462814629146301463114632146331463414635146361463714638146391464014641146421464314644146451464614647146481464914650146511465214653146541465514656146571465814659146601466114662146631466414665146661466714668146691467014671146721467314674146751467614677146781467914680146811468214683146841468514686146871468814689146901469114692146931469414695146961469714698146991470014701147021470314704147051470614707147081470914710147111471214713147141471514716147171471814719147201472114722147231472414725147261472714728147291473014731147321473314734147351473614737147381473914740147411474214743147441474514746147471474814749147501475114752147531475414755147561475714758147591476014761147621476314764147651476614767147681476914770147711477214773147741477514776147771477814779147801478114782147831478414785147861478714788147891479014791147921479314794147951479614797147981479914800148011480214803148041480514806148071480814809148101481114812148131481414815148161481714818148191482014821148221482314824148251482614827148281482914830148311483214833148341483514836148371483814839148401484114842148431484414845148461484714848148491485014851148521485314854148551485614857148581485914860148611486214863148641486514866148671486814869148701487114872148731487414875148761487714878148791488014881148821488314884148851488614887148881488914890148911489214893148941489514896148971489814899149001490114902149031490414905149061490714908149091491014911149121491314914149151491614917149181491914920149211492214923149241492514926149271492814929149301493114932149331493414935149361493714938149391494014941149421494314944149451494614947149481494914950149511495214953149541495514956149571495814959149601496114962149631496414965149661496714968149691497014971149721497314974149751497614977149781497914980149811498214983149841498514986149871498814989149901499114992149931499414995149961499714998149991500015001150021500315004150051500615007150081500915010150111501215013150141501515016150171501815019150201502115022150231502415025150261502715028150291503015031150321503315034150351503615037150381503915040150411504215043150441504515046150471504815049150501505115052150531505415055150561505715058150591506015061150621506315064150651506615067150681506915070150711507215073150741507515076150771507815079150801508115082150831508415085150861508715088150891509015091150921509315094150951509615097150981509915100151011510215103151041510515106151071510815109151101511115112151131511415115151161511715118151191512015121151221512315124151251512615127151281512915130151311513215133151341513515136151371513815139151401514115142151431514415145151461514715148151491515015151151521515315154151551515615157151581515915160151611516215163151641516515166151671516815169151701517115172151731517415175151761517715178151791518015181151821518315184151851518615187151881518915190151911519215193151941519515196151971519815199152001520115202152031520415205152061520715208152091521015211152121521315214152151521615217152181521915220152211522215223152241522515226152271522815229152301523115232152331523415235152361523715238152391524015241152421524315244152451524615247152481524915250152511525215253152541525515256152571525815259152601526115262152631526415265152661526715268152691527015271152721527315274152751527615277152781527915280152811528215283152841528515286152871528815289152901529115292152931529415295152961529715298152991530015301153021530315304153051530615307153081530915310153111531215313153141531515316153171531815319153201532115322153231532415325153261532715328153291533015331153321533315334153351533615337153381533915340153411534215343153441534515346153471534815349153501535115352153531535415355153561535715358153591536015361153621536315364153651536615367153681536915370153711537215373153741537515376153771537815379153801538115382153831538415385153861538715388153891539015391153921539315394153951539615397153981539915400154011540215403154041540515406154071540815409154101541115412154131541415415154161541715418154191542015421154221542315424154251542615427154281542915430154311543215433154341543515436154371543815439154401544115442154431544415445154461544715448154491545015451154521545315454154551545615457154581545915460154611546215463154641546515466154671546815469154701547115472154731547415475154761547715478154791548015481154821548315484154851548615487154881548915490154911549215493154941549515496154971549815499155001550115502155031550415505155061550715508155091551015511155121551315514155151551615517155181551915520155211552215523155241552515526155271552815529155301553115532155331553415535155361553715538155391554015541155421554315544155451554615547155481554915550155511555215553155541555515556155571555815559155601556115562155631556415565155661556715568155691557015571155721557315574155751557615577155781557915580155811558215583155841558515586155871558815589155901559115592155931559415595155961559715598155991560015601156021560315604156051560615607156081560915610156111561215613156141561515616156171561815619156201562115622156231562415625156261562715628156291563015631156321563315634156351563615637156381563915640156411564215643156441564515646156471564815649156501565115652156531565415655156561565715658156591566015661156621566315664156651566615667156681566915670156711567215673156741567515676156771567815679156801568115682156831568415685156861568715688156891569015691156921569315694156951569615697156981569915700157011570215703157041570515706157071570815709157101571115712157131571415715157161571715718157191572015721157221572315724157251572615727157281572915730157311573215733157341573515736157371573815739157401574115742157431574415745157461574715748157491575015751157521575315754157551575615757157581575915760157611576215763157641576515766157671576815769157701577115772157731577415775157761577715778157791578015781157821578315784157851578615787157881578915790157911579215793157941579515796157971579815799158001580115802158031580415805158061580715808158091581015811158121581315814158151581615817158181581915820158211582215823158241582515826158271582815829158301583115832158331583415835158361583715838158391584015841158421584315844158451584615847158481584915850158511585215853158541585515856158571585815859158601586115862158631586415865158661586715868158691587015871158721587315874158751587615877158781587915880158811588215883158841588515886158871588815889158901589115892158931589415895158961589715898158991590015901159021590315904159051590615907159081590915910159111591215913159141591515916159171591815919159201592115922159231592415925159261592715928159291593015931159321593315934159351593615937159381593915940159411594215943159441594515946159471594815949159501595115952159531595415955159561595715958159591596015961159621596315964159651596615967159681596915970159711597215973159741597515976159771597815979159801598115982159831598415985159861598715988159891599015991159921599315994159951599615997159981599916000160011600216003160041600516006160071600816009160101601116012160131601416015160161601716018160191602016021160221602316024160251602616027160281602916030160311603216033160341603516036160371603816039160401604116042160431604416045160461604716048160491605016051160521605316054160551605616057160581605916060160611606216063160641606516066160671606816069160701607116072160731607416075160761607716078160791608016081160821608316084160851608616087160881608916090160911609216093160941609516096160971609816099161001610116102161031610416105161061610716108161091611016111161121611316114161151611616117161181611916120161211612216123161241612516126161271612816129161301613116132161331613416135161361613716138161391614016141161421614316144161451614616147161481614916150161511615216153161541615516156161571615816159161601616116162161631616416165161661616716168161691617016171161721617316174161751617616177161781617916180161811618216183161841618516186161871618816189161901619116192161931619416195161961619716198161991620016201162021620316204162051620616207162081620916210162111621216213162141621516216162171621816219162201622116222162231622416225162261622716228162291623016231162321623316234162351623616237162381623916240162411624216243162441624516246162471624816249162501625116252162531625416255162561625716258162591626016261162621626316264162651626616267162681626916270162711627216273162741627516276162771627816279162801628116282162831628416285162861628716288162891629016291162921629316294162951629616297162981629916300163011630216303163041630516306163071630816309163101631116312163131631416315163161631716318163191632016321163221632316324163251632616327163281632916330163311633216333163341633516336163371633816339163401634116342163431634416345163461634716348163491635016351163521635316354163551635616357163581635916360163611636216363163641636516366163671636816369163701637116372163731637416375163761637716378163791638016381163821638316384163851638616387163881638916390163911639216393163941639516396163971639816399164001640116402164031640416405164061640716408164091641016411164121641316414164151641616417164181641916420164211642216423164241642516426164271642816429164301643116432164331643416435164361643716438164391644016441164421644316444164451644616447164481644916450164511645216453164541645516456164571645816459164601646116462164631646416465164661646716468164691647016471164721647316474164751647616477164781647916480164811648216483164841648516486164871648816489164901649116492164931649416495164961649716498164991650016501165021650316504165051650616507165081650916510165111651216513165141651516516165171651816519165201652116522165231652416525165261652716528165291653016531165321653316534165351653616537165381653916540165411654216543165441654516546165471654816549165501655116552165531655416555165561655716558165591656016561165621656316564165651656616567165681656916570165711657216573165741657516576165771657816579165801658116582165831658416585165861658716588165891659016591165921659316594165951659616597165981659916600166011660216603166041660516606166071660816609166101661116612166131661416615166161661716618166191662016621166221662316624166251662616627166281662916630166311663216633166341663516636166371663816639166401664116642166431664416645166461664716648166491665016651166521665316654166551665616657166581665916660166611666216663166641666516666166671666816669166701667116672166731667416675166761667716678166791668016681166821668316684166851668616687166881668916690166911669216693166941669516696166971669816699167001670116702167031670416705167061670716708167091671016711167121671316714167151671616717167181671916720167211672216723167241672516726167271672816729167301673116732167331673416735167361673716738167391674016741167421674316744167451674616747167481674916750167511675216753167541675516756167571675816759167601676116762167631676416765167661676716768167691677016771167721677316774167751677616777167781677916780167811678216783167841678516786167871678816789167901679116792167931679416795167961679716798167991680016801168021680316804168051680616807168081680916810168111681216813168141681516816168171681816819168201682116822168231682416825168261682716828168291683016831168321683316834168351683616837168381683916840168411684216843168441684516846168471684816849168501685116852168531685416855168561685716858168591686016861168621686316864168651686616867168681686916870168711687216873168741687516876168771687816879168801688116882168831688416885168861688716888168891689016891168921689316894168951689616897168981689916900169011690216903169041690516906169071690816909169101691116912169131691416915169161691716918169191692016921169221692316924169251692616927169281692916930169311693216933169341693516936169371693816939169401694116942169431694416945169461694716948169491695016951169521695316954169551695616957169581695916960169611696216963169641696516966169671696816969169701697116972169731697416975169761697716978169791698016981169821698316984169851698616987169881698916990169911699216993169941699516996169971699816999170001700117002170031700417005170061700717008170091701017011170121701317014170151701617017170181701917020170211702217023170241702517026170271702817029170301703117032170331703417035170361703717038170391704017041170421704317044170451704617047170481704917050170511705217053170541705517056170571705817059170601706117062170631706417065170661706717068170691707017071170721707317074170751707617077170781707917080170811708217083170841708517086170871708817089170901709117092170931709417095170961709717098170991710017101171021710317104171051710617107171081710917110171111711217113171141711517116171171711817119171201712117122171231712417125171261712717128171291713017131171321713317134171351713617137171381713917140171411714217143171441714517146171471714817149171501715117152171531715417155171561715717158171591716017161171621716317164171651716617167171681716917170171711717217173171741717517176171771717817179171801718117182171831718417185171861718717188171891719017191171921719317194171951719617197171981719917200172011720217203172041720517206172071720817209172101721117212172131721417215172161721717218172191722017221172221722317224172251722617227172281722917230172311723217233172341723517236172371723817239172401724117242172431724417245172461724717248172491725017251172521725317254172551725617257172581725917260172611726217263172641726517266172671726817269172701727117272172731727417275172761727717278172791728017281172821728317284172851728617287172881728917290172911729217293172941729517296172971729817299173001730117302173031730417305173061730717308173091731017311173121731317314173151731617317173181731917320173211732217323173241732517326173271732817329173301733117332173331733417335173361733717338173391734017341173421734317344173451734617347173481734917350173511735217353173541735517356173571735817359173601736117362173631736417365173661736717368173691737017371173721737317374173751737617377173781737917380173811738217383173841738517386173871738817389173901739117392173931739417395173961739717398173991740017401174021740317404174051740617407174081740917410174111741217413174141741517416174171741817419174201742117422174231742417425174261742717428174291743017431174321743317434174351743617437174381743917440174411744217443174441744517446174471744817449174501745117452174531745417455174561745717458174591746017461174621746317464174651746617467174681746917470174711747217473174741747517476174771747817479174801748117482174831748417485174861748717488174891749017491174921749317494174951749617497174981749917500175011750217503175041750517506175071750817509175101751117512175131751417515175161751717518175191752017521175221752317524175251752617527175281752917530175311753217533175341753517536175371753817539175401754117542175431754417545175461754717548175491755017551175521755317554175551755617557175581755917560175611756217563175641756517566175671756817569175701757117572175731757417575175761757717578175791758017581175821758317584175851758617587175881758917590175911759217593175941759517596175971759817599176001760117602176031760417605176061760717608176091761017611176121761317614176151761617617176181761917620176211762217623176241762517626176271762817629176301763117632176331763417635176361763717638176391764017641176421764317644176451764617647176481764917650176511765217653176541765517656176571765817659176601766117662176631766417665176661766717668176691767017671176721767317674176751767617677176781767917680176811768217683176841768517686176871768817689176901769117692176931769417695176961769717698176991770017701177021770317704177051770617707177081770917710177111771217713177141771517716177171771817719177201772117722177231772417725177261772717728177291773017731177321773317734177351773617737177381773917740177411774217743177441774517746177471774817749177501775117752177531775417755177561775717758177591776017761177621776317764177651776617767177681776917770177711777217773177741777517776177771777817779177801778117782177831778417785177861778717788177891779017791177921779317794177951779617797177981779917800178011780217803178041780517806178071780817809178101781117812178131781417815178161781717818178191782017821178221782317824178251782617827178281782917830178311783217833178341783517836178371783817839178401784117842178431784417845178461784717848178491785017851178521785317854178551785617857178581785917860178611786217863178641786517866178671786817869178701787117872178731787417875178761787717878178791788017881178821788317884178851788617887178881788917890178911789217893178941789517896178971789817899179001790117902179031790417905179061790717908179091791017911179121791317914179151791617917179181791917920179211792217923179241792517926179271792817929179301793117932179331793417935179361793717938179391794017941179421794317944179451794617947179481794917950179511795217953179541795517956179571795817959179601796117962179631796417965179661796717968179691797017971179721797317974179751797617977179781797917980179811798217983179841798517986179871798817989179901799117992179931799417995179961799717998179991800018001180021800318004180051800618007180081800918010180111801218013180141801518016180171801818019180201802118022180231802418025180261802718028180291803018031180321803318034180351803618037180381803918040180411804218043180441804518046180471804818049180501805118052180531805418055180561805718058180591806018061180621806318064180651806618067180681806918070180711807218073180741807518076180771807818079180801808118082180831808418085180861808718088180891809018091180921809318094180951809618097180981809918100181011810218103181041810518106181071810818109181101811118112181131811418115181161811718118181191812018121181221812318124181251812618127181281812918130181311813218133181341813518136181371813818139181401814118142181431814418145181461814718148181491815018151181521815318154181551815618157181581815918160181611816218163181641816518166181671816818169181701817118172181731817418175181761817718178181791818018181181821818318184181851818618187181881818918190181911819218193181941819518196181971819818199182001820118202182031820418205182061820718208182091821018211182121821318214182151821618217182181821918220182211822218223182241822518226182271822818229182301823118232182331823418235182361823718238182391824018241182421824318244182451824618247182481824918250182511825218253182541825518256182571825818259182601826118262182631826418265182661826718268182691827018271182721827318274182751827618277182781827918280182811828218283182841828518286182871828818289182901829118292182931829418295182961829718298182991830018301183021830318304183051830618307183081830918310183111831218313183141831518316183171831818319183201832118322183231832418325183261832718328183291833018331183321833318334183351833618337183381833918340183411834218343183441834518346183471834818349183501835118352183531835418355183561835718358183591836018361183621836318364183651836618367183681836918370183711837218373183741837518376183771837818379183801838118382183831838418385183861838718388183891839018391183921839318394183951839618397183981839918400184011840218403184041840518406184071840818409184101841118412184131841418415184161841718418184191842018421184221842318424184251842618427184281842918430184311843218433184341843518436184371843818439184401844118442184431844418445184461844718448184491845018451184521845318454184551845618457184581845918460184611846218463184641846518466184671846818469184701847118472184731847418475184761847718478184791848018481184821848318484184851848618487184881848918490184911849218493184941849518496184971849818499185001850118502185031850418505185061850718508185091851018511185121851318514185151851618517185181851918520185211852218523185241852518526185271852818529185301853118532185331853418535185361853718538185391854018541185421854318544185451854618547185481854918550185511855218553185541855518556185571855818559185601856118562185631856418565185661856718568185691857018571185721857318574185751857618577185781857918580185811858218583185841858518586185871858818589185901859118592185931859418595185961859718598185991860018601186021860318604186051860618607186081860918610186111861218613186141861518616186171861818619186201862118622186231862418625186261862718628186291863018631186321863318634186351863618637186381863918640186411864218643186441864518646186471864818649186501865118652186531865418655186561865718658186591866018661186621866318664186651866618667186681866918670186711867218673186741867518676186771867818679186801868118682186831868418685186861868718688186891869018691186921869318694186951869618697186981869918700187011870218703187041870518706187071870818709187101871118712187131871418715187161871718718187191872018721187221872318724187251872618727187281872918730187311873218733187341873518736187371873818739187401874118742187431874418745187461874718748187491875018751187521875318754187551875618757187581875918760187611876218763187641876518766187671876818769187701877118772187731877418775187761877718778187791878018781187821878318784187851878618787187881878918790187911879218793187941879518796187971879818799188001880118802188031880418805188061880718808188091881018811188121881318814188151881618817188181881918820188211882218823188241882518826188271882818829188301883118832188331883418835188361883718838188391884018841188421884318844188451884618847188481884918850188511885218853188541885518856188571885818859188601886118862188631886418865188661886718868188691887018871188721887318874188751887618877188781887918880188811888218883188841888518886188871888818889188901889118892188931889418895188961889718898188991890018901189021890318904189051890618907189081890918910189111891218913189141891518916189171891818919189201892118922189231892418925189261892718928189291893018931189321893318934189351893618937189381893918940189411894218943189441894518946189471894818949189501895118952189531895418955189561895718958189591896018961189621896318964189651896618967189681896918970189711897218973189741897518976189771897818979189801898118982189831898418985189861898718988189891899018991189921899318994189951899618997189981899919000190011900219003190041900519006190071900819009190101901119012190131901419015190161901719018190191902019021190221902319024190251902619027190281902919030190311903219033190341903519036190371903819039190401904119042190431904419045190461904719048190491905019051190521905319054190551905619057190581905919060190611906219063190641906519066190671906819069190701907119072190731907419075190761907719078190791908019081190821908319084190851908619087190881908919090190911909219093190941909519096190971909819099191001910119102191031910419105191061910719108191091911019111191121911319114191151911619117191181911919120191211912219123191241912519126191271912819129191301913119132191331913419135191361913719138191391914019141191421914319144191451914619147191481914919150191511915219153191541915519156191571915819159191601916119162191631916419165191661916719168191691917019171191721917319174191751917619177191781917919180191811918219183191841918519186191871918819189191901919119192191931919419195191961919719198191991920019201192021920319204192051920619207192081920919210192111921219213192141921519216192171921819219192201922119222192231922419225192261922719228192291923019231192321923319234192351923619237192381923919240192411924219243192441924519246192471924819249192501925119252192531925419255192561925719258192591926019261192621926319264192651926619267192681926919270192711927219273192741927519276192771927819279192801928119282192831928419285192861928719288192891929019291192921929319294192951929619297192981929919300193011930219303193041930519306193071930819309193101931119312193131931419315193161931719318193191932019321193221932319324193251932619327193281932919330193311933219333193341933519336193371933819339193401934119342193431934419345193461934719348193491935019351193521935319354193551935619357193581935919360193611936219363193641936519366193671936819369193701937119372193731937419375193761937719378193791938019381193821938319384193851938619387193881938919390193911939219393193941939519396193971939819399194001940119402194031940419405194061940719408194091941019411194121941319414194151941619417194181941919420194211942219423194241942519426194271942819429194301943119432194331943419435194361943719438194391944019441194421944319444194451944619447194481944919450194511945219453194541945519456194571945819459194601946119462194631946419465194661946719468194691947019471194721947319474194751947619477194781947919480194811948219483194841948519486194871948819489194901949119492194931949419495194961949719498194991950019501195021950319504195051950619507195081950919510195111951219513195141951519516195171951819519195201952119522195231952419525195261952719528195291953019531195321953319534195351953619537195381953919540195411954219543195441954519546195471954819549195501955119552195531955419555195561955719558195591956019561195621956319564195651956619567195681956919570195711957219573195741957519576195771957819579195801958119582195831958419585195861958719588195891959019591195921959319594195951959619597195981959919600196011960219603196041960519606196071960819609196101961119612196131961419615196161961719618196191962019621196221962319624196251962619627196281962919630196311963219633196341963519636196371963819639196401964119642196431964419645196461964719648196491965019651196521965319654196551965619657196581965919660196611966219663196641966519666196671966819669196701967119672196731967419675196761967719678196791968019681196821968319684196851968619687196881968919690196911969219693196941969519696196971969819699197001970119702197031970419705197061970719708197091971019711197121971319714197151971619717197181971919720197211972219723197241972519726197271972819729197301973119732197331973419735197361973719738197391974019741197421974319744197451974619747197481974919750197511975219753197541975519756197571975819759197601976119762197631976419765197661976719768197691977019771197721977319774197751977619777197781977919780197811978219783197841978519786197871978819789197901979119792197931979419795197961979719798197991980019801198021980319804198051980619807198081980919810198111981219813198141981519816198171981819819198201982119822198231982419825198261982719828198291983019831198321983319834198351983619837198381983919840198411984219843198441984519846198471984819849198501985119852198531985419855198561985719858198591986019861198621986319864198651986619867198681986919870198711987219873198741987519876198771987819879198801988119882198831988419885198861988719888198891989019891198921989319894198951989619897198981989919900199011990219903199041990519906199071990819909199101991119912199131991419915199161991719918199191992019921199221992319924199251992619927199281992919930199311993219933199341993519936199371993819939199401994119942199431994419945199461994719948199491995019951199521995319954199551995619957199581995919960199611996219963199641996519966199671996819969199701997119972199731997419975199761997719978199791998019981199821998319984199851998619987199881998919990199911999219993199941999519996199971999819999200002000120002200032000420005200062000720008200092001020011200122001320014200152001620017200182001920020200212002220023200242002520026200272002820029200302003120032200332003420035200362003720038200392004020041200422004320044200452004620047200482004920050200512005220053200542005520056200572005820059200602006120062200632006420065200662006720068200692007020071200722007320074200752007620077200782007920080200812008220083200842008520086200872008820089200902009120092200932009420095200962009720098200992010020101201022010320104201052010620107201082010920110201112011220113201142011520116201172011820119201202012120122201232012420125201262012720128201292013020131201322013320134201352013620137201382013920140201412014220143201442014520146201472014820149201502015120152201532015420155201562015720158201592016020161201622016320164201652016620167201682016920170201712017220173201742017520176201772017820179201802018120182201832018420185201862018720188201892019020191201922019320194201952019620197201982019920200202012020220203202042020520206202072020820209202102021120212202132021420215202162021720218202192022020221202222022320224202252022620227202282022920230202312023220233202342023520236202372023820239202402024120242202432024420245202462024720248202492025020251202522025320254202552025620257202582025920260202612026220263202642026520266202672026820269202702027120272202732027420275202762027720278202792028020281202822028320284202852028620287202882028920290202912029220293202942029520296202972029820299203002030120302203032030420305203062030720308203092031020311203122031320314203152031620317203182031920320203212032220323203242032520326203272032820329203302033120332203332033420335203362033720338203392034020341203422034320344203452034620347203482034920350203512035220353203542035520356203572035820359203602036120362203632036420365203662036720368203692037020371203722037320374203752037620377203782037920380203812038220383203842038520386203872038820389203902039120392203932039420395203962039720398203992040020401204022040320404204052040620407204082040920410204112041220413204142041520416204172041820419204202042120422204232042420425204262042720428204292043020431204322043320434204352043620437204382043920440204412044220443204442044520446204472044820449204502045120452204532045420455204562045720458204592046020461204622046320464204652046620467204682046920470204712047220473204742047520476204772047820479204802048120482204832048420485204862048720488204892049020491204922049320494204952049620497204982049920500205012050220503205042050520506205072050820509205102051120512205132051420515205162051720518205192052020521205222052320524205252052620527205282052920530205312053220533205342053520536205372053820539205402054120542205432054420545205462054720548205492055020551205522055320554205552055620557205582055920560205612056220563205642056520566205672056820569205702057120572205732057420575205762057720578205792058020581205822058320584205852058620587205882058920590205912059220593205942059520596205972059820599206002060120602206032060420605206062060720608206092061020611206122061320614206152061620617206182061920620206212062220623206242062520626206272062820629206302063120632206332063420635206362063720638206392064020641206422064320644206452064620647206482064920650206512065220653206542065520656206572065820659206602066120662206632066420665206662066720668206692067020671206722067320674206752067620677206782067920680206812068220683206842068520686206872068820689206902069120692206932069420695206962069720698206992070020701207022070320704207052070620707207082070920710207112071220713207142071520716207172071820719207202072120722207232072420725207262072720728207292073020731207322073320734207352073620737207382073920740207412074220743207442074520746207472074820749207502075120752207532075420755207562075720758207592076020761207622076320764207652076620767207682076920770207712077220773207742077520776207772077820779207802078120782207832078420785207862078720788207892079020791207922079320794207952079620797207982079920800208012080220803208042080520806208072080820809208102081120812208132081420815208162081720818208192082020821208222082320824208252082620827208282082920830208312083220833208342083520836208372083820839208402084120842208432084420845208462084720848208492085020851208522085320854208552085620857208582085920860208612086220863208642086520866208672086820869208702087120872208732087420875208762087720878208792088020881208822088320884208852088620887208882088920890208912089220893208942089520896208972089820899209002090120902209032090420905209062090720908209092091020911209122091320914209152091620917209182091920920209212092220923209242092520926209272092820929209302093120932209332093420935209362093720938209392094020941209422094320944209452094620947209482094920950209512095220953209542095520956209572095820959209602096120962209632096420965209662096720968209692097020971209722097320974209752097620977209782097920980209812098220983209842098520986209872098820989209902099120992209932099420995209962099720998209992100021001210022100321004210052100621007210082100921010210112101221013210142101521016210172101821019210202102121022210232102421025210262102721028210292103021031210322103321034210352103621037210382103921040210412104221043210442104521046210472104821049210502105121052210532105421055210562105721058210592106021061210622106321064210652106621067210682106921070210712107221073210742107521076210772107821079210802108121082210832108421085210862108721088210892109021091210922109321094210952109621097210982109921100211012110221103211042110521106211072110821109211102111121112211132111421115211162111721118211192112021121211222112321124211252112621127211282112921130211312113221133211342113521136211372113821139211402114121142211432114421145211462114721148211492115021151211522115321154211552115621157211582115921160211612116221163211642116521166211672116821169211702117121172211732117421175211762117721178211792118021181211822118321184211852118621187211882118921190211912119221193211942119521196211972119821199212002120121202212032120421205212062120721208212092121021211212122121321214212152121621217212182121921220212212122221223212242122521226212272122821229212302123121232212332123421235212362123721238212392124021241212422124321244212452124621247212482124921250212512125221253212542125521256212572125821259212602126121262212632126421265212662126721268212692127021271212722127321274212752127621277212782127921280212812128221283212842128521286212872128821289212902129121292212932129421295212962129721298212992130021301213022130321304213052130621307213082130921310213112131221313213142131521316213172131821319213202132121322213232132421325213262132721328213292133021331213322133321334213352133621337213382133921340213412134221343213442134521346213472134821349213502135121352213532135421355213562135721358213592136021361213622136321364213652136621367213682136921370213712137221373213742137521376213772137821379213802138121382213832138421385213862138721388213892139021391213922139321394213952139621397213982139921400214012140221403214042140521406214072140821409214102141121412214132141421415214162141721418214192142021421214222142321424214252142621427214282142921430214312143221433214342143521436214372143821439214402144121442214432144421445214462144721448214492145021451214522145321454214552145621457214582145921460214612146221463214642146521466214672146821469214702147121472214732147421475214762147721478214792148021481214822148321484214852148621487214882148921490214912149221493214942149521496214972149821499215002150121502215032150421505215062150721508215092151021511215122151321514215152151621517215182151921520215212152221523215242152521526215272152821529215302153121532215332153421535215362153721538215392154021541215422154321544215452154621547215482154921550215512155221553215542155521556215572155821559215602156121562215632156421565215662156721568215692157021571215722157321574215752157621577215782157921580215812158221583215842158521586215872158821589215902159121592215932159421595215962159721598215992160021601216022160321604216052160621607216082160921610216112161221613216142161521616216172161821619216202162121622216232162421625216262162721628216292163021631216322163321634216352163621637216382163921640216412164221643216442164521646216472164821649216502165121652216532165421655216562165721658216592166021661216622166321664216652166621667216682166921670216712167221673216742167521676216772167821679216802168121682216832168421685216862168721688216892169021691216922169321694216952169621697216982169921700217012170221703217042170521706217072170821709217102171121712217132171421715217162171721718217192172021721217222172321724217252172621727217282172921730217312173221733217342173521736217372173821739217402174121742217432174421745217462174721748217492175021751217522175321754217552175621757217582175921760217612176221763217642176521766217672176821769217702177121772217732177421775217762177721778217792178021781217822178321784217852178621787217882178921790217912179221793217942179521796217972179821799218002180121802218032180421805218062180721808218092181021811218122181321814218152181621817218182181921820218212182221823218242182521826218272182821829218302183121832218332183421835218362183721838218392184021841218422184321844218452184621847218482184921850218512185221853218542185521856218572185821859218602186121862218632186421865218662186721868218692187021871218722187321874218752187621877218782187921880218812188221883218842188521886218872188821889218902189121892218932189421895218962189721898218992190021901219022190321904219052190621907219082190921910219112191221913219142191521916219172191821919219202192121922219232192421925219262192721928219292193021931219322193321934219352193621937219382193921940219412194221943219442194521946219472194821949219502195121952219532195421955219562195721958219592196021961219622196321964219652196621967219682196921970219712197221973219742197521976219772197821979219802198121982219832198421985219862198721988219892199021991219922199321994219952199621997219982199922000220012200222003220042200522006220072200822009220102201122012220132201422015220162201722018220192202022021220222202322024220252202622027220282202922030220312203222033220342203522036220372203822039220402204122042220432204422045220462204722048220492205022051220522205322054220552205622057220582205922060220612206222063220642206522066220672206822069220702207122072220732207422075220762207722078220792208022081220822208322084220852208622087220882208922090220912209222093220942209522096220972209822099221002210122102221032210422105221062210722108221092211022111221122211322114221152211622117221182211922120221212212222123221242212522126221272212822129221302213122132221332213422135221362213722138221392214022141221422214322144221452214622147221482214922150221512215222153221542215522156221572215822159221602216122162221632216422165221662216722168221692217022171221722217322174221752217622177221782217922180221812218222183221842218522186221872218822189221902219122192221932219422195221962219722198221992220022201222022220322204222052220622207222082220922210222112221222213222142221522216222172221822219222202222122222222232222422225222262222722228222292223022231222322223322234222352223622237222382223922240222412224222243222442224522246222472224822249222502225122252222532225422255222562225722258222592226022261222622226322264222652226622267222682226922270222712227222273222742227522276222772227822279222802228122282222832228422285222862228722288222892229022291222922229322294222952229622297222982229922300223012230222303223042230522306223072230822309223102231122312223132231422315223162231722318223192232022321223222232322324223252232622327223282232922330223312233222333223342233522336223372233822339223402234122342223432234422345223462234722348223492235022351223522235322354223552235622357223582235922360223612236222363223642236522366223672236822369223702237122372223732237422375223762237722378223792238022381223822238322384223852238622387223882238922390223912239222393223942239522396223972239822399224002240122402224032240422405224062240722408224092241022411224122241322414224152241622417224182241922420224212242222423224242242522426224272242822429224302243122432224332243422435224362243722438224392244022441224422244322444224452244622447224482244922450224512245222453224542245522456224572245822459224602246122462224632246422465224662246722468224692247022471224722247322474224752247622477224782247922480224812248222483224842248522486224872248822489224902249122492224932249422495224962249722498224992250022501225022250322504225052250622507225082250922510225112251222513225142251522516225172251822519225202252122522225232252422525225262252722528225292253022531225322253322534225352253622537225382253922540225412254222543225442254522546225472254822549225502255122552225532255422555225562255722558225592256022561225622256322564225652256622567225682256922570225712257222573225742257522576225772257822579225802258122582225832258422585225862258722588225892259022591225922259322594225952259622597225982259922600226012260222603226042260522606226072260822609226102261122612226132261422615226162261722618226192262022621226222262322624226252262622627226282262922630226312263222633226342263522636226372263822639226402264122642226432264422645226462264722648226492265022651226522265322654226552265622657226582265922660226612266222663226642266522666226672266822669226702267122672226732267422675226762267722678226792268022681226822268322684226852268622687226882268922690226912269222693226942269522696226972269822699227002270122702227032270422705227062270722708227092271022711227122271322714227152271622717227182271922720227212272222723227242272522726227272272822729227302273122732227332273422735227362273722738227392274022741227422274322744227452274622747227482274922750227512275222753227542275522756227572275822759227602276122762227632276422765227662276722768227692277022771227722277322774227752277622777227782277922780227812278222783227842278522786227872278822789227902279122792227932279422795227962279722798227992280022801228022280322804228052280622807228082280922810228112281222813228142281522816228172281822819228202282122822228232282422825228262282722828228292283022831228322283322834228352283622837228382283922840228412284222843228442284522846228472284822849228502285122852228532285422855228562285722858228592286022861228622286322864228652286622867228682286922870228712287222873228742287522876228772287822879228802288122882228832288422885228862288722888228892289022891228922289322894228952289622897228982289922900229012290222903229042290522906229072290822909229102291122912229132291422915229162291722918229192292022921229222292322924229252292622927229282292922930229312293222933229342293522936229372293822939229402294122942229432294422945229462294722948229492295022951229522295322954229552295622957229582295922960229612296222963229642296522966229672296822969229702297122972229732297422975229762297722978229792298022981229822298322984229852298622987229882298922990229912299222993229942299522996229972299822999230002300123002230032300423005230062300723008230092301023011230122301323014230152301623017230182301923020230212302223023230242302523026230272302823029230302303123032230332303423035230362303723038230392304023041230422304323044230452304623047230482304923050230512305223053230542305523056230572305823059230602306123062230632306423065230662306723068230692307023071230722307323074230752307623077230782307923080230812308223083230842308523086230872308823089230902309123092230932309423095230962309723098230992310023101231022310323104231052310623107231082310923110231112311223113231142311523116231172311823119231202312123122231232312423125231262312723128231292313023131231322313323134231352313623137231382313923140231412314223143231442314523146231472314823149231502315123152231532315423155231562315723158231592316023161231622316323164231652316623167231682316923170231712317223173231742317523176231772317823179231802318123182231832318423185231862318723188231892319023191231922319323194231952319623197231982319923200232012320223203232042320523206232072320823209232102321123212232132321423215232162321723218232192322023221232222322323224232252322623227232282322923230232312323223233232342323523236232372323823239232402324123242232432324423245232462324723248232492325023251232522325323254232552325623257232582325923260232612326223263232642326523266232672326823269232702327123272232732327423275232762327723278232792328023281232822328323284232852328623287232882328923290232912329223293232942329523296232972329823299233002330123302233032330423305233062330723308233092331023311233122331323314233152331623317233182331923320233212332223323233242332523326233272332823329233302333123332233332333423335233362333723338233392334023341233422334323344233452334623347233482334923350233512335223353233542335523356233572335823359233602336123362233632336423365233662336723368233692337023371233722337323374233752337623377233782337923380233812338223383233842338523386233872338823389233902339123392233932339423395233962339723398233992340023401234022340323404234052340623407234082340923410234112341223413234142341523416234172341823419234202342123422234232342423425234262342723428234292343023431234322343323434234352343623437234382343923440234412344223443234442344523446234472344823449234502345123452234532345423455234562345723458234592346023461234622346323464234652346623467234682346923470234712347223473234742347523476234772347823479234802348123482234832348423485234862348723488234892349023491234922349323494234952349623497234982349923500235012350223503235042350523506235072350823509235102351123512235132351423515235162351723518235192352023521235222352323524235252352623527235282352923530235312353223533235342353523536235372353823539235402354123542235432354423545235462354723548235492355023551235522355323554235552355623557235582355923560235612356223563235642356523566235672356823569235702357123572235732357423575235762357723578235792358023581235822358323584235852358623587235882358923590235912359223593235942359523596235972359823599236002360123602236032360423605236062360723608236092361023611236122361323614236152361623617236182361923620236212362223623236242362523626236272362823629236302363123632236332363423635236362363723638236392364023641236422364323644236452364623647236482364923650236512365223653236542365523656236572365823659236602366123662236632366423665236662366723668236692367023671236722367323674236752367623677236782367923680236812368223683236842368523686236872368823689236902369123692236932369423695236962369723698236992370023701237022370323704237052370623707237082370923710237112371223713237142371523716237172371823719237202372123722237232372423725237262372723728237292373023731237322373323734237352373623737237382373923740237412374223743237442374523746237472374823749237502375123752237532375423755237562375723758237592376023761237622376323764237652376623767237682376923770237712377223773237742377523776237772377823779237802378123782237832378423785237862378723788237892379023791237922379323794237952379623797237982379923800238012380223803238042380523806238072380823809238102381123812238132381423815238162381723818238192382023821238222382323824238252382623827238282382923830238312383223833238342383523836238372383823839238402384123842238432384423845238462384723848238492385023851238522385323854238552385623857238582385923860238612386223863238642386523866238672386823869238702387123872238732387423875238762387723878238792388023881238822388323884238852388623887238882388923890238912389223893238942389523896238972389823899239002390123902239032390423905239062390723908239092391023911239122391323914239152391623917239182391923920239212392223923239242392523926239272392823929239302393123932239332393423935239362393723938239392394023941239422394323944239452394623947239482394923950239512395223953239542395523956239572395823959239602396123962239632396423965239662396723968239692397023971239722397323974239752397623977239782397923980239812398223983239842398523986239872398823989239902399123992239932399423995239962399723998239992400024001240022400324004240052400624007240082400924010240112401224013240142401524016240172401824019240202402124022240232402424025240262402724028240292403024031240322403324034240352403624037240382403924040240412404224043240442404524046240472404824049240502405124052240532405424055240562405724058240592406024061240622406324064240652406624067240682406924070240712407224073240742407524076240772407824079240802408124082240832408424085240862408724088240892409024091240922409324094240952409624097240982409924100241012410224103241042410524106241072410824109241102411124112241132411424115241162411724118241192412024121241222412324124241252412624127241282412924130241312413224133241342413524136241372413824139241402414124142241432414424145241462414724148241492415024151241522415324154241552415624157241582415924160241612416224163241642416524166241672416824169241702417124172241732417424175241762417724178241792418024181241822418324184241852418624187241882418924190241912419224193241942419524196241972419824199242002420124202242032420424205242062420724208242092421024211242122421324214242152421624217242182421924220242212422224223242242422524226242272422824229242302423124232242332423424235242362423724238242392424024241242422424324244242452424624247242482424924250242512425224253242542425524256242572425824259242602426124262242632426424265242662426724268242692427024271242722427324274242752427624277242782427924280242812428224283242842428524286242872428824289242902429124292242932429424295242962429724298242992430024301243022430324304243052430624307243082430924310243112431224313243142431524316243172431824319243202432124322243232432424325243262432724328243292433024331243322433324334243352433624337243382433924340243412434224343243442434524346243472434824349243502435124352243532435424355243562435724358243592436024361243622436324364243652436624367243682436924370243712437224373243742437524376243772437824379243802438124382243832438424385243862438724388243892439024391243922439324394243952439624397243982439924400244012440224403244042440524406244072440824409244102441124412244132441424415244162441724418244192442024421244222442324424244252442624427244282442924430244312443224433244342443524436244372443824439244402444124442244432444424445244462444724448244492445024451244522445324454244552445624457244582445924460244612446224463244642446524466244672446824469244702447124472244732447424475244762447724478244792448024481244822448324484244852448624487244882448924490244912449224493244942449524496244972449824499245002450124502245032450424505245062450724508245092451024511245122451324514245152451624517245182451924520245212452224523245242452524526245272452824529245302453124532245332453424535245362453724538245392454024541245422454324544245452454624547245482454924550245512455224553245542455524556245572455824559245602456124562245632456424565245662456724568245692457024571245722457324574245752457624577245782457924580245812458224583245842458524586245872458824589245902459124592245932459424595245962459724598245992460024601246022460324604246052460624607246082460924610246112461224613246142461524616246172461824619246202462124622246232462424625246262462724628246292463024631246322463324634246352463624637246382463924640246412464224643246442464524646246472464824649246502465124652246532465424655246562465724658246592466024661246622466324664246652466624667246682466924670246712467224673246742467524676246772467824679246802468124682246832468424685246862468724688246892469024691246922469324694246952469624697246982469924700247012470224703247042470524706247072470824709247102471124712247132471424715247162471724718247192472024721247222472324724247252472624727247282472924730247312473224733247342473524736247372473824739247402474124742247432474424745247462474724748247492475024751247522475324754247552475624757247582475924760247612476224763247642476524766247672476824769247702477124772247732477424775247762477724778247792478024781247822478324784247852478624787247882478924790247912479224793247942479524796247972479824799248002480124802248032480424805248062480724808248092481024811248122481324814248152481624817248182481924820248212482224823248242482524826248272482824829248302483124832248332483424835248362483724838248392484024841248422484324844248452484624847248482484924850248512485224853248542485524856248572485824859248602486124862248632486424865248662486724868248692487024871248722487324874248752487624877248782487924880248812488224883248842488524886248872488824889248902489124892248932489424895248962489724898248992490024901249022490324904249052490624907249082490924910249112491224913249142491524916249172491824919249202492124922249232492424925249262492724928249292493024931249322493324934249352493624937249382493924940249412494224943249442494524946249472494824949249502495124952249532495424955249562495724958249592496024961249622496324964249652496624967249682496924970249712497224973249742497524976249772497824979249802498124982249832498424985249862498724988249892499024991249922499324994249952499624997249982499925000250012500225003250042500525006250072500825009250102501125012250132501425015250162501725018250192502025021250222502325024250252502625027250282502925030250312503225033250342503525036250372503825039250402504125042250432504425045250462504725048250492505025051250522505325054250552505625057250582505925060250612506225063250642506525066250672506825069250702507125072250732507425075250762507725078250792508025081250822508325084250852508625087250882508925090250912509225093250942509525096250972509825099251002510125102251032510425105251062510725108251092511025111251122511325114251152511625117251182511925120251212512225123251242512525126251272512825129251302513125132251332513425135251362513725138251392514025141251422514325144251452514625147251482514925150251512515225153251542515525156251572515825159251602516125162251632516425165251662516725168251692517025171251722517325174251752517625177251782517925180251812518225183251842518525186251872518825189251902519125192251932519425195251962519725198251992520025201252022520325204252052520625207252082520925210252112521225213252142521525216252172521825219252202522125222252232522425225252262522725228252292523025231252322523325234252352523625237252382523925240252412524225243252442524525246252472524825249252502525125252252532525425255252562525725258252592526025261252622526325264252652526625267252682526925270252712527225273252742527525276252772527825279252802528125282252832528425285252862528725288252892529025291252922529325294252952529625297252982529925300253012530225303253042530525306253072530825309253102531125312253132531425315253162531725318253192532025321253222532325324253252532625327253282532925330253312533225333253342533525336253372533825339253402534125342253432534425345253462534725348253492535025351253522535325354253552535625357253582535925360253612536225363253642536525366253672536825369253702537125372253732537425375253762537725378253792538025381253822538325384253852538625387253882538925390253912539225393253942539525396253972539825399254002540125402254032540425405254062540725408254092541025411254122541325414254152541625417254182541925420254212542225423254242542525426254272542825429254302543125432254332543425435254362543725438254392544025441254422544325444254452544625447254482544925450254512545225453254542545525456254572545825459254602546125462254632546425465254662546725468254692547025471254722547325474254752547625477254782547925480254812548225483254842548525486254872548825489254902549125492254932549425495254962549725498254992550025501255022550325504255052550625507255082550925510255112551225513255142551525516255172551825519255202552125522255232552425525255262552725528255292553025531255322553325534255352553625537255382553925540255412554225543255442554525546255472554825549255502555125552255532555425555255562555725558255592556025561255622556325564255652556625567255682556925570255712557225573255742557525576255772557825579255802558125582255832558425585255862558725588255892559025591255922559325594255952559625597255982559925600256012560225603256042560525606256072560825609256102561125612256132561425615256162561725618256192562025621256222562325624256252562625627256282562925630256312563225633256342563525636256372563825639256402564125642256432564425645256462564725648256492565025651256522565325654256552565625657256582565925660256612566225663256642566525666256672566825669256702567125672256732567425675256762567725678256792568025681256822568325684256852568625687256882568925690256912569225693256942569525696256972569825699257002570125702257032570425705257062570725708257092571025711257122571325714257152571625717257182571925720257212572225723257242572525726257272572825729257302573125732257332573425735257362573725738257392574025741257422574325744257452574625747257482574925750257512575225753257542575525756257572575825759257602576125762257632576425765257662576725768257692577025771257722577325774257752577625777257782577925780257812578225783257842578525786257872578825789257902579125792257932579425795257962579725798257992580025801258022580325804258052580625807258082580925810258112581225813258142581525816258172581825819258202582125822258232582425825258262582725828258292583025831258322583325834258352583625837258382583925840258412584225843258442584525846258472584825849258502585125852258532585425855258562585725858258592586025861258622586325864258652586625867258682586925870258712587225873258742587525876258772587825879258802588125882258832588425885258862588725888258892589025891258922589325894258952589625897258982589925900259012590225903259042590525906259072590825909259102591125912259132591425915259162591725918259192592025921259222592325924259252592625927259282592925930259312593225933259342593525936259372593825939259402594125942259432594425945259462594725948259492595025951259522595325954259552595625957259582595925960259612596225963259642596525966259672596825969259702597125972259732597425975259762597725978259792598025981259822598325984259852598625987259882598925990259912599225993259942599525996259972599825999260002600126002260032600426005260062600726008260092601026011260122601326014260152601626017260182601926020260212602226023260242602526026260272602826029260302603126032260332603426035260362603726038260392604026041260422604326044260452604626047260482604926050260512605226053260542605526056260572605826059260602606126062260632606426065260662606726068260692607026071260722607326074260752607626077260782607926080260812608226083260842608526086260872608826089260902609126092260932609426095260962609726098260992610026101261022610326104261052610626107261082610926110261112611226113261142611526116261172611826119261202612126122261232612426125261262612726128261292613026131261322613326134261352613626137261382613926140261412614226143261442614526146261472614826149261502615126152261532615426155261562615726158261592616026161261622616326164261652616626167261682616926170261712617226173261742617526176261772617826179261802618126182261832618426185261862618726188261892619026191261922619326194261952619626197261982619926200262012620226203262042620526206262072620826209262102621126212262132621426215262162621726218262192622026221262222622326224262252622626227262282622926230262312623226233262342623526236262372623826239262402624126242262432624426245262462624726248262492625026251262522625326254262552625626257262582625926260262612626226263262642626526266262672626826269262702627126272262732627426275262762627726278262792628026281262822628326284262852628626287262882628926290262912629226293262942629526296262972629826299263002630126302263032630426305263062630726308263092631026311263122631326314263152631626317263182631926320263212632226323263242632526326263272632826329263302633126332263332633426335263362633726338263392634026341263422634326344263452634626347263482634926350263512635226353263542635526356263572635826359263602636126362263632636426365263662636726368263692637026371263722637326374263752637626377263782637926380263812638226383263842638526386263872638826389263902639126392263932639426395263962639726398263992640026401264022640326404264052640626407264082640926410264112641226413264142641526416264172641826419264202642126422264232642426425264262642726428264292643026431264322643326434264352643626437264382643926440264412644226443264442644526446264472644826449264502645126452264532645426455264562645726458264592646026461264622646326464264652646626467264682646926470264712647226473264742647526476264772647826479264802648126482264832648426485264862648726488264892649026491264922649326494264952649626497264982649926500265012650226503265042650526506265072650826509265102651126512265132651426515265162651726518265192652026521265222652326524265252652626527265282652926530265312653226533265342653526536265372653826539265402654126542265432654426545265462654726548265492655026551265522655326554265552655626557265582655926560265612656226563265642656526566265672656826569265702657126572265732657426575265762657726578265792658026581265822658326584265852658626587265882658926590265912659226593265942659526596265972659826599266002660126602266032660426605266062660726608266092661026611266122661326614266152661626617266182661926620266212662226623266242662526626266272662826629266302663126632266332663426635266362663726638266392664026641266422664326644266452664626647266482664926650266512665226653266542665526656266572665826659266602666126662266632666426665266662666726668266692667026671266722667326674266752667626677266782667926680266812668226683266842668526686266872668826689266902669126692266932669426695266962669726698266992670026701267022670326704267052670626707267082670926710267112671226713267142671526716267172671826719267202672126722267232672426725267262672726728267292673026731267322673326734267352673626737267382673926740267412674226743267442674526746267472674826749267502675126752267532675426755267562675726758267592676026761267622676326764267652676626767267682676926770267712677226773267742677526776267772677826779267802678126782267832678426785267862678726788267892679026791267922679326794267952679626797267982679926800268012680226803268042680526806268072680826809268102681126812268132681426815268162681726818268192682026821268222682326824268252682626827268282682926830268312683226833268342683526836268372683826839268402684126842268432684426845268462684726848268492685026851268522685326854268552685626857268582685926860268612686226863268642686526866268672686826869268702687126872268732687426875268762687726878268792688026881268822688326884268852688626887268882688926890268912689226893268942689526896268972689826899269002690126902269032690426905269062690726908269092691026911269122691326914269152691626917269182691926920269212692226923269242692526926269272692826929269302693126932269332693426935269362693726938269392694026941269422694326944269452694626947269482694926950269512695226953269542695526956269572695826959269602696126962269632696426965269662696726968269692697026971269722697326974269752697626977269782697926980269812698226983269842698526986269872698826989269902699126992269932699426995269962699726998269992700027001270022700327004270052700627007270082700927010270112701227013270142701527016270172701827019270202702127022270232702427025270262702727028270292703027031270322703327034270352703627037270382703927040270412704227043270442704527046270472704827049270502705127052270532705427055270562705727058270592706027061270622706327064270652706627067270682706927070270712707227073270742707527076270772707827079270802708127082270832708427085270862708727088270892709027091270922709327094270952709627097270982709927100271012710227103271042710527106271072710827109271102711127112271132711427115271162711727118271192712027121271222712327124271252712627127271282712927130271312713227133271342713527136271372713827139271402714127142271432714427145271462714727148271492715027151271522715327154271552715627157271582715927160271612716227163271642716527166271672716827169271702717127172271732717427175271762717727178271792718027181271822718327184271852718627187271882718927190271912719227193271942719527196271972719827199272002720127202272032720427205272062720727208272092721027211272122721327214272152721627217272182721927220272212722227223272242722527226272272722827229272302723127232272332723427235272362723727238272392724027241272422724327244272452724627247272482724927250272512725227253272542725527256272572725827259272602726127262272632726427265272662726727268272692727027271272722727327274272752727627277272782727927280272812728227283272842728527286272872728827289272902729127292272932729427295272962729727298272992730027301273022730327304273052730627307273082730927310273112731227313273142731527316273172731827319273202732127322273232732427325273262732727328273292733027331273322733327334273352733627337273382733927340273412734227343273442734527346273472734827349273502735127352273532735427355273562735727358273592736027361273622736327364273652736627367273682736927370273712737227373273742737527376273772737827379273802738127382273832738427385273862738727388273892739027391273922739327394273952739627397273982739927400274012740227403274042740527406274072740827409274102741127412274132741427415274162741727418274192742027421274222742327424274252742627427274282742927430274312743227433274342743527436274372743827439274402744127442274432744427445274462744727448274492745027451274522745327454274552745627457274582745927460274612746227463274642746527466274672746827469274702747127472274732747427475274762747727478274792748027481274822748327484274852748627487274882748927490274912749227493274942749527496274972749827499275002750127502275032750427505275062750727508275092751027511275122751327514275152751627517275182751927520275212752227523275242752527526275272752827529275302753127532275332753427535275362753727538275392754027541275422754327544275452754627547275482754927550275512755227553275542755527556275572755827559275602756127562275632756427565275662756727568275692757027571275722757327574275752757627577275782757927580275812758227583275842758527586275872758827589275902759127592275932759427595275962759727598275992760027601276022760327604276052760627607276082760927610276112761227613276142761527616276172761827619276202762127622276232762427625276262762727628276292763027631276322763327634276352763627637276382763927640276412764227643276442764527646276472764827649276502765127652276532765427655276562765727658276592766027661276622766327664276652766627667276682766927670276712767227673276742767527676276772767827679276802768127682276832768427685276862768727688276892769027691276922769327694276952769627697276982769927700277012770227703277042770527706277072770827709277102771127712277132771427715277162771727718277192772027721277222772327724277252772627727277282772927730277312773227733277342773527736277372773827739277402774127742277432774427745277462774727748277492775027751277522775327754277552775627757277582775927760277612776227763277642776527766277672776827769277702777127772277732777427775277762777727778277792778027781277822778327784277852778627787277882778927790277912779227793277942779527796277972779827799278002780127802278032780427805278062780727808278092781027811278122781327814278152781627817278182781927820278212782227823278242782527826278272782827829278302783127832278332783427835278362783727838278392784027841278422784327844278452784627847278482784927850278512785227853278542785527856278572785827859278602786127862278632786427865278662786727868278692787027871278722787327874278752787627877278782787927880278812788227883278842788527886278872788827889278902789127892278932789427895278962789727898278992790027901279022790327904279052790627907279082790927910279112791227913279142791527916279172791827919279202792127922279232792427925279262792727928279292793027931279322793327934279352793627937279382793927940279412794227943279442794527946279472794827949279502795127952279532795427955279562795727958279592796027961279622796327964279652796627967279682796927970279712797227973279742797527976279772797827979279802798127982279832798427985279862798727988279892799027991279922799327994279952799627997279982799928000280012800228003280042800528006280072800828009280102801128012280132801428015280162801728018280192802028021280222802328024280252802628027280282802928030280312803228033280342803528036280372803828039280402804128042280432804428045280462804728048280492805028051280522805328054280552805628057280582805928060280612806228063280642806528066280672806828069280702807128072280732807428075280762807728078280792808028081280822808328084280852808628087280882808928090280912809228093280942809528096280972809828099281002810128102281032810428105281062810728108281092811028111281122811328114281152811628117281182811928120281212812228123281242812528126281272812828129281302813128132281332813428135281362813728138281392814028141281422814328144281452814628147281482814928150281512815228153281542815528156281572815828159281602816128162281632816428165281662816728168281692817028171281722817328174281752817628177281782817928180281812818228183281842818528186281872818828189281902819128192281932819428195281962819728198281992820028201282022820328204282052820628207282082820928210282112821228213282142821528216282172821828219282202822128222282232822428225282262822728228282292823028231282322823328234282352823628237282382823928240282412824228243282442824528246282472824828249282502825128252282532825428255282562825728258282592826028261282622826328264282652826628267282682826928270282712827228273282742827528276282772827828279282802828128282282832828428285282862828728288282892829028291282922829328294282952829628297282982829928300283012830228303283042830528306283072830828309283102831128312283132831428315283162831728318283192832028321283222832328324283252832628327283282832928330283312833228333283342833528336283372833828339283402834128342283432834428345283462834728348283492835028351283522835328354283552835628357283582835928360283612836228363283642836528366283672836828369283702837128372283732837428375283762837728378283792838028381283822838328384283852838628387283882838928390283912839228393283942839528396283972839828399284002840128402284032840428405284062840728408284092841028411284122841328414284152841628417284182841928420284212842228423284242842528426284272842828429284302843128432284332843428435284362843728438284392844028441284422844328444284452844628447284482844928450284512845228453284542845528456284572845828459284602846128462284632846428465284662846728468284692847028471284722847328474284752847628477284782847928480284812848228483284842848528486284872848828489284902849128492284932849428495284962849728498284992850028501285022850328504285052850628507285082850928510285112851228513285142851528516285172851828519285202852128522285232852428525285262852728528285292853028531285322853328534285352853628537285382853928540285412854228543285442854528546285472854828549285502855128552285532855428555285562855728558285592856028561285622856328564285652856628567285682856928570285712857228573285742857528576285772857828579285802858128582285832858428585285862858728588285892859028591285922859328594285952859628597285982859928600286012860228603286042860528606286072860828609286102861128612286132861428615286162861728618286192862028621286222862328624286252862628627286282862928630286312863228633286342863528636286372863828639286402864128642286432864428645286462864728648286492865028651286522865328654286552865628657286582865928660286612866228663286642866528666286672866828669286702867128672286732867428675286762867728678286792868028681286822868328684286852868628687286882868928690286912869228693286942869528696286972869828699287002870128702287032870428705287062870728708287092871028711287122871328714287152871628717287182871928720287212872228723287242872528726287272872828729287302873128732287332873428735287362873728738287392874028741287422874328744287452874628747287482874928750287512875228753287542875528756287572875828759287602876128762287632876428765287662876728768287692877028771287722877328774287752877628777287782877928780287812878228783287842878528786287872878828789287902879128792287932879428795287962879728798287992880028801288022880328804288052880628807288082880928810288112881228813288142881528816288172881828819288202882128822288232882428825288262882728828288292883028831288322883328834288352883628837288382883928840288412884228843288442884528846288472884828849288502885128852288532885428855288562885728858288592886028861288622886328864288652886628867288682886928870288712887228873288742887528876288772887828879288802888128882288832888428885288862888728888288892889028891288922889328894288952889628897288982889928900289012890228903289042890528906289072890828909289102891128912289132891428915289162891728918289192892028921289222892328924289252892628927289282892928930289312893228933289342893528936289372893828939289402894128942289432894428945289462894728948289492895028951289522895328954289552895628957289582895928960289612896228963289642896528966289672896828969289702897128972289732897428975289762897728978289792898028981289822898328984289852898628987289882898928990289912899228993289942899528996289972899828999290002900129002290032900429005290062900729008290092901029011290122901329014290152901629017290182901929020290212902229023290242902529026290272902829029290302903129032290332903429035290362903729038290392904029041290422904329044290452904629047290482904929050290512905229053290542905529056290572905829059290602906129062290632906429065290662906729068290692907029071290722907329074290752907629077290782907929080290812908229083290842908529086290872908829089290902909129092290932909429095290962909729098290992910029101291022910329104291052910629107291082910929110291112911229113291142911529116291172911829119291202912129122291232912429125291262912729128291292913029131291322913329134291352913629137291382913929140291412914229143291442914529146291472914829149291502915129152291532915429155291562915729158291592916029161291622916329164291652916629167291682916929170291712917229173291742917529176291772917829179291802918129182291832918429185291862918729188291892919029191291922919329194291952919629197291982919929200292012920229203292042920529206292072920829209292102921129212292132921429215292162921729218292192922029221292222922329224292252922629227292282922929230292312923229233292342923529236292372923829239292402924129242292432924429245292462924729248292492925029251292522925329254292552925629257292582925929260292612926229263292642926529266292672926829269292702927129272292732927429275292762927729278292792928029281292822928329284292852928629287292882928929290292912929229293292942929529296292972929829299293002930129302293032930429305293062930729308293092931029311293122931329314293152931629317293182931929320293212932229323293242932529326293272932829329293302933129332293332933429335293362933729338293392934029341293422934329344293452934629347293482934929350293512935229353293542935529356293572935829359293602936129362293632936429365293662936729368293692937029371293722937329374293752937629377293782937929380293812938229383293842938529386293872938829389293902939129392293932939429395293962939729398293992940029401294022940329404294052940629407294082940929410294112941229413294142941529416294172941829419294202942129422294232942429425294262942729428294292943029431294322943329434294352943629437294382943929440294412944229443294442944529446294472944829449294502945129452294532945429455294562945729458294592946029461294622946329464294652946629467294682946929470294712947229473294742947529476294772947829479294802948129482294832948429485294862948729488294892949029491294922949329494294952949629497294982949929500295012950229503295042950529506295072950829509295102951129512295132951429515295162951729518295192952029521295222952329524295252952629527295282952929530295312953229533295342953529536295372953829539295402954129542295432954429545295462954729548295492955029551295522955329554295552955629557295582955929560295612956229563295642956529566295672956829569295702957129572295732957429575295762957729578295792958029581295822958329584295852958629587295882958929590295912959229593295942959529596295972959829599296002960129602296032960429605296062960729608296092961029611296122961329614296152961629617296182961929620296212962229623296242962529626296272962829629296302963129632296332963429635296362963729638296392964029641296422964329644296452964629647296482964929650296512965229653296542965529656296572965829659296602966129662296632966429665296662966729668296692967029671296722967329674296752967629677296782967929680296812968229683296842968529686296872968829689296902969129692296932969429695296962969729698296992970029701297022970329704297052970629707297082970929710297112971229713297142971529716297172971829719297202972129722297232972429725297262972729728297292973029731297322973329734297352973629737297382973929740297412974229743297442974529746297472974829749297502975129752297532975429755297562975729758297592976029761297622976329764297652976629767297682976929770297712977229773297742977529776297772977829779297802978129782297832978429785297862978729788297892979029791297922979329794297952979629797297982979929800298012980229803298042980529806298072980829809298102981129812298132981429815298162981729818298192982029821298222982329824298252982629827298282982929830298312983229833298342983529836298372983829839298402984129842298432984429845298462984729848298492985029851298522985329854298552985629857298582985929860298612986229863298642986529866298672986829869298702987129872298732987429875298762987729878298792988029881298822988329884298852988629887298882988929890298912989229893298942989529896298972989829899299002990129902299032990429905299062990729908299092991029911299122991329914299152991629917299182991929920299212992229923299242992529926299272992829929299302993129932299332993429935299362993729938299392994029941299422994329944299452994629947299482994929950299512995229953299542995529956299572995829959299602996129962299632996429965299662996729968299692997029971299722997329974299752997629977299782997929980299812998229983299842998529986299872998829989299902999129992299932999429995299962999729998299993000030001300023000330004300053000630007300083000930010300113001230013300143001530016300173001830019300203002130022300233002430025300263002730028300293003030031300323003330034300353003630037300383003930040300413004230043300443004530046300473004830049300503005130052300533005430055300563005730058300593006030061300623006330064300653006630067300683006930070300713007230073300743007530076300773007830079300803008130082300833008430085300863008730088300893009030091300923009330094300953009630097300983009930100301013010230103301043010530106301073010830109301103011130112301133011430115301163011730118301193012030121301223012330124301253012630127301283012930130301313013230133301343013530136301373013830139301403014130142301433014430145301463014730148301493015030151301523015330154301553015630157301583015930160301613016230163301643016530166301673016830169301703017130172301733017430175301763017730178301793018030181301823018330184301853018630187301883018930190301913019230193301943019530196301973019830199302003020130202302033020430205302063020730208302093021030211302123021330214302153021630217302183021930220302213022230223302243022530226302273022830229302303023130232302333023430235302363023730238302393024030241302423024330244302453024630247302483024930250302513025230253302543025530256302573025830259302603026130262302633026430265302663026730268302693027030271302723027330274302753027630277302783027930280302813028230283302843028530286302873028830289302903029130292302933029430295302963029730298302993030030301303023030330304303053030630307303083030930310303113031230313303143031530316303173031830319303203032130322303233032430325303263032730328303293033030331303323033330334303353033630337303383033930340303413034230343303443034530346303473034830349303503035130352303533035430355303563035730358303593036030361303623036330364303653036630367303683036930370303713037230373303743037530376303773037830379303803038130382303833038430385303863038730388303893039030391303923039330394303953039630397303983039930400304013040230403304043040530406304073040830409304103041130412304133041430415304163041730418304193042030421304223042330424304253042630427304283042930430304313043230433304343043530436304373043830439304403044130442304433044430445304463044730448304493045030451304523045330454304553045630457304583045930460304613046230463304643046530466304673046830469304703047130472304733047430475304763047730478304793048030481304823048330484304853048630487304883048930490304913049230493304943049530496304973049830499305003050130502305033050430505305063050730508305093051030511305123051330514305153051630517305183051930520305213052230523305243052530526305273052830529305303053130532305333053430535305363053730538305393054030541305423054330544305453054630547305483054930550305513055230553305543055530556305573055830559305603056130562305633056430565305663056730568305693057030571305723057330574305753057630577305783057930580305813058230583305843058530586305873058830589305903059130592305933059430595305963059730598305993060030601306023060330604306053060630607306083060930610306113061230613306143061530616306173061830619306203062130622306233062430625306263062730628306293063030631306323063330634306353063630637306383063930640306413064230643306443064530646306473064830649306503065130652306533065430655306563065730658306593066030661306623066330664306653066630667306683066930670306713067230673306743067530676306773067830679306803068130682306833068430685306863068730688306893069030691306923069330694306953069630697306983069930700307013070230703307043070530706307073070830709307103071130712307133071430715307163071730718307193072030721307223072330724307253072630727307283072930730307313073230733307343073530736307373073830739307403074130742307433074430745307463074730748307493075030751307523075330754307553075630757307583075930760307613076230763307643076530766307673076830769307703077130772307733077430775307763077730778307793078030781307823078330784307853078630787307883078930790307913079230793307943079530796307973079830799308003080130802308033080430805308063080730808308093081030811308123081330814308153081630817308183081930820308213082230823308243082530826308273082830829308303083130832308333083430835308363083730838308393084030841308423084330844308453084630847308483084930850308513085230853308543085530856308573085830859308603086130862308633086430865308663086730868308693087030871308723087330874308753087630877308783087930880308813088230883308843088530886308873088830889308903089130892308933089430895308963089730898308993090030901309023090330904309053090630907309083090930910309113091230913309143091530916309173091830919309203092130922309233092430925309263092730928309293093030931309323093330934309353093630937309383093930940309413094230943309443094530946309473094830949309503095130952309533095430955309563095730958309593096030961309623096330964309653096630967309683096930970309713097230973309743097530976309773097830979309803098130982309833098430985309863098730988309893099030991309923099330994309953099630997309983099931000310013100231003310043100531006310073100831009310103101131012310133101431015310163101731018310193102031021310223102331024310253102631027310283102931030310313103231033310343103531036310373103831039310403104131042310433104431045310463104731048310493105031051310523105331054310553105631057310583105931060310613106231063310643106531066310673106831069310703107131072310733107431075310763107731078310793108031081310823108331084310853108631087310883108931090310913109231093310943109531096310973109831099311003110131102311033110431105311063110731108311093111031111311123111331114311153111631117311183111931120311213112231123311243112531126311273112831129311303113131132311333113431135311363113731138311393114031141311423114331144311453114631147311483114931150311513115231153311543115531156311573115831159311603116131162311633116431165311663116731168311693117031171311723117331174311753117631177311783117931180311813118231183311843118531186311873118831189311903119131192311933119431195311963119731198311993120031201312023120331204312053120631207312083120931210312113121231213312143121531216312173121831219312203122131222312233122431225312263122731228312293123031231312323123331234312353123631237312383123931240312413124231243312443124531246312473124831249312503125131252312533125431255312563125731258312593126031261312623126331264312653126631267312683126931270312713127231273312743127531276312773127831279312803128131282312833128431285312863128731288312893129031291312923129331294312953129631297312983129931300313013130231303313043130531306313073130831309313103131131312313133131431315313163131731318313193132031321313223132331324313253132631327313283132931330313313133231333313343133531336313373133831339313403134131342313433134431345313463134731348313493135031351313523135331354313553135631357313583135931360313613136231363313643136531366313673136831369313703137131372313733137431375313763137731378313793138031381313823138331384313853138631387313883138931390313913139231393313943139531396313973139831399314003140131402314033140431405314063140731408314093141031411314123141331414314153141631417314183141931420314213142231423314243142531426314273142831429314303143131432314333143431435314363143731438314393144031441314423144331444314453144631447314483144931450314513145231453314543145531456314573145831459314603146131462314633146431465314663146731468314693147031471314723147331474314753147631477314783147931480314813148231483314843148531486314873148831489314903149131492314933149431495314963149731498314993150031501315023150331504315053150631507315083150931510315113151231513315143151531516315173151831519315203152131522315233152431525315263152731528315293153031531315323153331534315353153631537315383153931540315413154231543315443154531546315473154831549315503155131552315533155431555315563155731558315593156031561315623156331564315653156631567315683156931570315713157231573315743157531576315773157831579315803158131582315833158431585315863158731588315893159031591315923159331594315953159631597315983159931600316013160231603316043160531606316073160831609316103161131612316133161431615316163161731618316193162031621316223162331624316253162631627316283162931630316313163231633316343163531636316373163831639316403164131642316433164431645316463164731648316493165031651316523165331654316553165631657316583165931660316613166231663316643166531666316673166831669316703167131672316733167431675316763167731678316793168031681316823168331684316853168631687316883168931690316913169231693316943169531696316973169831699317003170131702317033170431705317063170731708317093171031711317123171331714317153171631717317183171931720317213172231723317243172531726317273172831729317303173131732317333173431735317363173731738317393174031741317423174331744317453174631747317483174931750317513175231753317543175531756317573175831759317603176131762317633176431765317663176731768317693177031771317723177331774317753177631777317783177931780317813178231783317843178531786317873178831789317903179131792317933179431795317963179731798317993180031801318023180331804318053180631807318083180931810318113181231813318143181531816318173181831819318203182131822318233182431825318263182731828318293183031831318323183331834318353183631837318383183931840318413184231843318443184531846318473184831849318503185131852318533185431855318563185731858318593186031861318623186331864318653186631867318683186931870318713187231873318743187531876318773187831879318803188131882318833188431885318863188731888318893189031891318923189331894318953189631897318983189931900319013190231903319043190531906319073190831909319103191131912319133191431915319163191731918319193192031921319223192331924319253192631927319283192931930319313193231933319343193531936319373193831939319403194131942319433194431945319463194731948319493195031951319523195331954319553195631957319583195931960319613196231963319643196531966319673196831969319703197131972319733197431975319763197731978319793198031981319823198331984319853198631987319883198931990319913199231993319943199531996319973199831999320003200132002320033200432005320063200732008320093201032011320123201332014320153201632017320183201932020320213202232023320243202532026320273202832029320303203132032320333203432035320363203732038320393204032041320423204332044320453204632047320483204932050320513205232053320543205532056320573205832059320603206132062320633206432065320663206732068320693207032071320723207332074320753207632077320783207932080320813208232083320843208532086320873208832089320903209132092320933209432095320963209732098320993210032101321023210332104321053210632107321083210932110321113211232113321143211532116321173211832119321203212132122321233212432125321263212732128321293213032131321323213332134321353213632137321383213932140321413214232143321443214532146321473214832149321503215132152321533215432155321563215732158321593216032161321623216332164321653216632167321683216932170321713217232173321743217532176321773217832179321803218132182321833218432185321863218732188321893219032191321923219332194321953219632197321983219932200322013220232203322043220532206322073220832209322103221132212322133221432215322163221732218322193222032221322223222332224322253222632227322283222932230322313223232233322343223532236322373223832239322403224132242322433224432245322463224732248322493225032251322523225332254322553225632257322583225932260322613226232263322643226532266322673226832269322703227132272322733227432275322763227732278322793228032281322823228332284322853228632287322883228932290322913229232293322943229532296322973229832299323003230132302323033230432305323063230732308323093231032311323123231332314323153231632317323183231932320323213232232323323243232532326323273232832329323303233132332323333233432335323363233732338323393234032341323423234332344323453234632347323483234932350323513235232353323543235532356323573235832359323603236132362323633236432365323663236732368323693237032371323723237332374323753237632377323783237932380323813238232383323843238532386323873238832389323903239132392323933239432395323963239732398323993240032401324023240332404324053240632407324083240932410324113241232413324143241532416324173241832419324203242132422324233242432425324263242732428324293243032431324323243332434324353243632437324383243932440324413244232443324443244532446324473244832449324503245132452324533245432455324563245732458324593246032461324623246332464324653246632467324683246932470324713247232473324743247532476324773247832479324803248132482324833248432485324863248732488324893249032491324923249332494324953249632497324983249932500325013250232503325043250532506325073250832509325103251132512325133251432515325163251732518325193252032521325223252332524325253252632527325283252932530325313253232533325343253532536325373253832539325403254132542325433254432545325463254732548325493255032551325523255332554325553255632557325583255932560325613256232563325643256532566325673256832569325703257132572325733257432575325763257732578325793258032581325823258332584325853258632587325883258932590325913259232593325943259532596325973259832599326003260132602326033260432605326063260732608326093261032611326123261332614326153261632617326183261932620326213262232623326243262532626326273262832629326303263132632326333263432635326363263732638326393264032641326423264332644326453264632647326483264932650326513265232653326543265532656326573265832659326603266132662326633266432665326663266732668326693267032671326723267332674326753267632677326783267932680326813268232683326843268532686326873268832689326903269132692326933269432695326963269732698326993270032701327023270332704327053270632707327083270932710327113271232713327143271532716327173271832719327203272132722327233272432725327263272732728327293273032731327323273332734327353273632737327383273932740327413274232743327443274532746327473274832749327503275132752327533275432755327563275732758327593276032761327623276332764327653276632767327683276932770327713277232773327743277532776327773277832779327803278132782327833278432785327863278732788327893279032791327923279332794327953279632797327983279932800328013280232803328043280532806328073280832809328103281132812328133281432815328163281732818328193282032821328223282332824328253282632827328283282932830328313283232833328343283532836328373283832839328403284132842328433284432845328463284732848328493285032851328523285332854328553285632857328583285932860328613286232863328643286532866328673286832869328703287132872328733287432875328763287732878328793288032881328823288332884328853288632887328883288932890328913289232893328943289532896328973289832899329003290132902329033290432905329063290732908329093291032911329123291332914329153291632917329183291932920329213292232923329243292532926329273292832929329303293132932329333293432935329363293732938329393294032941329423294332944329453294632947329483294932950329513295232953329543295532956329573295832959329603296132962329633296432965329663296732968329693297032971329723297332974329753297632977329783297932980329813298232983329843298532986329873298832989329903299132992329933299432995329963299732998329993300033001330023300333004330053300633007330083300933010330113301233013330143301533016330173301833019330203302133022330233302433025330263302733028330293303033031330323303333034330353303633037330383303933040330413304233043330443304533046330473304833049330503305133052330533305433055330563305733058330593306033061330623306333064330653306633067330683306933070330713307233073330743307533076330773307833079330803308133082330833308433085330863308733088330893309033091330923309333094330953309633097330983309933100331013310233103331043310533106331073310833109331103311133112331133311433115331163311733118331193312033121331223312333124331253312633127331283312933130331313313233133331343313533136331373313833139331403314133142331433314433145331463314733148331493315033151331523315333154331553315633157331583315933160331613316233163331643316533166331673316833169331703317133172331733317433175331763317733178331793318033181331823318333184331853318633187331883318933190331913319233193331943319533196331973319833199332003320133202332033320433205332063320733208332093321033211332123321333214332153321633217332183321933220332213322233223332243322533226332273322833229332303323133232332333323433235332363323733238332393324033241332423324333244332453324633247332483324933250332513325233253332543325533256332573325833259332603326133262332633326433265332663326733268332693327033271332723327333274332753327633277332783327933280332813328233283332843328533286332873328833289332903329133292332933329433295332963329733298332993330033301333023330333304333053330633307333083330933310333113331233313333143331533316333173331833319333203332133322333233332433325333263332733328333293333033331333323333333334333353333633337333383333933340333413334233343333443334533346333473334833349333503335133352333533335433355333563335733358333593336033361333623336333364333653336633367333683336933370333713337233373333743337533376333773337833379333803338133382333833338433385333863338733388333893339033391333923339333394333953339633397333983339933400334013340233403334043340533406334073340833409334103341133412334133341433415334163341733418334193342033421334223342333424334253342633427334283342933430334313343233433334343343533436334373343833439334403344133442334433344433445334463344733448334493345033451334523345333454334553345633457334583345933460334613346233463334643346533466334673346833469334703347133472334733347433475334763347733478334793348033481334823348333484334853348633487334883348933490334913349233493334943349533496334973349833499335003350133502335033350433505335063350733508335093351033511335123351333514335153351633517335183351933520335213352233523335243352533526335273352833529335303353133532335333353433535335363353733538335393354033541335423354333544335453354633547335483354933550335513355233553335543355533556335573355833559335603356133562335633356433565335663356733568335693357033571335723357333574335753357633577335783357933580335813358233583335843358533586335873358833589335903359133592335933359433595335963359733598335993360033601336023360333604336053360633607336083360933610336113361233613336143361533616336173361833619336203362133622336233362433625336263362733628336293363033631336323363333634336353363633637336383363933640336413364233643336443364533646336473364833649336503365133652336533365433655336563365733658336593366033661336623366333664336653366633667336683366933670336713367233673336743367533676336773367833679336803368133682336833368433685336863368733688336893369033691336923369333694336953369633697336983369933700337013370233703337043370533706337073370833709337103371133712337133371433715337163371733718337193372033721337223372333724337253372633727337283372933730337313373233733337343373533736337373373833739337403374133742337433374433745337463374733748337493375033751337523375333754337553375633757337583375933760337613376233763337643376533766337673376833769337703377133772337733377433775337763377733778337793378033781337823378333784337853378633787337883378933790337913379233793337943379533796337973379833799338003380133802338033380433805338063380733808338093381033811338123381333814338153381633817338183381933820338213382233823338243382533826338273382833829338303383133832338333383433835338363383733838338393384033841338423384333844338453384633847338483384933850338513385233853338543385533856338573385833859338603386133862338633386433865338663386733868338693387033871338723387333874338753387633877338783387933880338813388233883338843388533886338873388833889338903389133892338933389433895338963389733898338993390033901339023390333904339053390633907339083390933910339113391233913339143391533916339173391833919339203392133922339233392433925339263392733928339293393033931339323393333934339353393633937339383393933940339413394233943339443394533946339473394833949339503395133952339533395433955339563395733958339593396033961339623396333964339653396633967339683396933970339713397233973339743397533976339773397833979339803398133982339833398433985339863398733988339893399033991339923399333994339953399633997339983399934000340013400234003340043400534006340073400834009340103401134012340133401434015340163401734018340193402034021340223402334024340253402634027340283402934030340313403234033340343403534036340373403834039340403404134042340433404434045340463404734048340493405034051340523405334054340553405634057340583405934060340613406234063340643406534066340673406834069340703407134072340733407434075340763407734078340793408034081340823408334084340853408634087340883408934090340913409234093340943409534096340973409834099341003410134102341033410434105341063410734108341093411034111341123411334114341153411634117341183411934120341213412234123341243412534126341273412834129341303413134132341333413434135341363413734138341393414034141341423414334144341453414634147341483414934150341513415234153341543415534156341573415834159341603416134162341633416434165341663416734168341693417034171341723417334174341753417634177341783417934180341813418234183341843418534186341873418834189341903419134192341933419434195341963419734198341993420034201342023420334204342053420634207342083420934210342113421234213342143421534216342173421834219342203422134222342233422434225342263422734228342293423034231342323423334234342353423634237342383423934240342413424234243342443424534246342473424834249342503425134252342533425434255342563425734258342593426034261342623426334264342653426634267342683426934270342713427234273342743427534276342773427834279342803428134282342833428434285342863428734288342893429034291342923429334294342953429634297342983429934300343013430234303343043430534306343073430834309343103431134312343133431434315343163431734318343193432034321343223432334324343253432634327343283432934330343313433234333343343433534336343373433834339343403434134342343433434434345343463434734348343493435034351343523435334354343553435634357343583435934360343613436234363343643436534366343673436834369343703437134372343733437434375343763437734378343793438034381343823438334384343853438634387343883438934390343913439234393343943439534396343973439834399344003440134402344033440434405344063440734408344093441034411344123441334414344153441634417344183441934420344213442234423344243442534426344273442834429344303443134432344333443434435344363443734438344393444034441344423444334444344453444634447344483444934450344513445234453344543445534456344573445834459344603446134462344633446434465344663446734468344693447034471344723447334474344753447634477344783447934480344813448234483344843448534486344873448834489344903449134492344933449434495344963449734498344993450034501345023450334504345053450634507345083450934510345113451234513345143451534516345173451834519345203452134522345233452434525345263452734528345293453034531345323453334534345353453634537345383453934540345413454234543345443454534546345473454834549345503455134552345533455434555345563455734558345593456034561345623456334564345653456634567345683456934570345713457234573345743457534576345773457834579345803458134582345833458434585345863458734588345893459034591345923459334594345953459634597345983459934600346013460234603346043460534606346073460834609346103461134612346133461434615346163461734618346193462034621346223462334624346253462634627346283462934630346313463234633346343463534636346373463834639346403464134642346433464434645346463464734648346493465034651346523465334654346553465634657346583465934660346613466234663346643466534666346673466834669346703467134672346733467434675346763467734678346793468034681346823468334684346853468634687346883468934690346913469234693346943469534696346973469834699347003470134702347033470434705347063470734708347093471034711347123471334714347153471634717347183471934720347213472234723347243472534726347273472834729347303473134732347333473434735347363473734738347393474034741347423474334744347453474634747347483474934750347513475234753347543475534756347573475834759347603476134762347633476434765347663476734768347693477034771347723477334774347753477634777347783477934780347813478234783347843478534786347873478834789347903479134792347933479434795347963479734798347993480034801348023480334804348053480634807348083480934810348113481234813348143481534816348173481834819348203482134822348233482434825348263482734828348293483034831348323483334834348353483634837348383483934840348413484234843348443484534846348473484834849348503485134852348533485434855348563485734858348593486034861348623486334864348653486634867348683486934870348713487234873348743487534876348773487834879348803488134882348833488434885348863488734888348893489034891348923489334894348953489634897348983489934900349013490234903349043490534906349073490834909349103491134912349133491434915349163491734918349193492034921349223492334924349253492634927349283492934930349313493234933349343493534936349373493834939349403494134942349433494434945349463494734948349493495034951349523495334954349553495634957349583495934960349613496234963349643496534966349673496834969349703497134972349733497434975349763497734978349793498034981349823498334984349853498634987349883498934990349913499234993349943499534996349973499834999350003500135002350033500435005350063500735008350093501035011350123501335014350153501635017350183501935020350213502235023350243502535026350273502835029350303503135032350333503435035350363503735038350393504035041350423504335044350453504635047350483504935050350513505235053350543505535056350573505835059350603506135062350633506435065350663506735068350693507035071350723507335074350753507635077350783507935080350813508235083350843508535086350873508835089350903509135092350933509435095350963509735098350993510035101351023510335104351053510635107351083510935110351113511235113351143511535116351173511835119351203512135122351233512435125351263512735128351293513035131351323513335134351353513635137351383513935140351413514235143351443514535146351473514835149351503515135152351533515435155351563515735158351593516035161351623516335164351653516635167351683516935170351713517235173351743517535176351773517835179351803518135182351833518435185351863518735188351893519035191351923519335194351953519635197351983519935200352013520235203352043520535206352073520835209352103521135212352133521435215352163521735218352193522035221352223522335224352253522635227352283522935230352313523235233352343523535236352373523835239352403524135242352433524435245352463524735248352493525035251352523525335254352553525635257352583525935260352613526235263352643526535266352673526835269352703527135272352733527435275352763527735278352793528035281352823528335284352853528635287352883528935290352913529235293352943529535296352973529835299353003530135302353033530435305353063530735308353093531035311353123531335314353153531635317353183531935320353213532235323353243532535326353273532835329353303533135332353333533435335353363533735338353393534035341353423534335344353453534635347353483534935350353513535235353353543535535356353573535835359353603536135362353633536435365353663536735368353693537035371353723537335374353753537635377353783537935380353813538235383353843538535386353873538835389353903539135392353933539435395353963539735398353993540035401354023540335404354053540635407354083540935410354113541235413354143541535416354173541835419354203542135422354233542435425354263542735428354293543035431354323543335434354353543635437354383543935440354413544235443354443544535446354473544835449354503545135452354533545435455354563545735458354593546035461354623546335464354653546635467354683546935470354713547235473354743547535476354773547835479354803548135482354833548435485354863548735488354893549035491354923549335494354953549635497354983549935500355013550235503355043550535506355073550835509355103551135512355133551435515355163551735518355193552035521355223552335524355253552635527355283552935530355313553235533355343553535536355373553835539355403554135542355433554435545355463554735548355493555035551355523555335554355553555635557355583555935560355613556235563355643556535566355673556835569355703557135572355733557435575355763557735578355793558035581355823558335584355853558635587355883558935590355913559235593355943559535596355973559835599356003560135602356033560435605356063560735608356093561035611356123561335614356153561635617356183561935620356213562235623356243562535626356273562835629356303563135632356333563435635356363563735638356393564035641356423564335644356453564635647356483564935650356513565235653356543565535656356573565835659356603566135662356633566435665356663566735668356693567035671356723567335674356753567635677356783567935680356813568235683356843568535686356873568835689356903569135692356933569435695356963569735698356993570035701357023570335704357053570635707357083570935710357113571235713357143571535716357173571835719357203572135722357233572435725357263572735728357293573035731357323573335734357353573635737357383573935740357413574235743357443574535746357473574835749357503575135752357533575435755357563575735758357593576035761357623576335764357653576635767357683576935770357713577235773357743577535776357773577835779357803578135782357833578435785357863578735788357893579035791357923579335794357953579635797357983579935800358013580235803358043580535806358073580835809358103581135812358133581435815358163581735818358193582035821358223582335824358253582635827358283582935830358313583235833358343583535836358373583835839358403584135842358433584435845358463584735848358493585035851358523585335854358553585635857358583585935860358613586235863358643586535866358673586835869358703587135872358733587435875358763587735878358793588035881358823588335884358853588635887358883588935890358913589235893358943589535896358973589835899359003590135902359033590435905359063590735908359093591035911359123591335914359153591635917359183591935920359213592235923359243592535926359273592835929359303593135932359333593435935359363593735938359393594035941359423594335944359453594635947359483594935950359513595235953359543595535956359573595835959359603596135962359633596435965359663596735968359693597035971359723597335974359753597635977359783597935980359813598235983359843598535986359873598835989359903599135992359933599435995359963599735998359993600036001360023600336004360053600636007360083600936010360113601236013360143601536016360173601836019360203602136022360233602436025360263602736028360293603036031360323603336034360353603636037360383603936040360413604236043360443604536046360473604836049360503605136052360533605436055360563605736058360593606036061360623606336064360653606636067360683606936070360713607236073360743607536076360773607836079360803608136082360833608436085360863608736088360893609036091360923609336094360953609636097360983609936100361013610236103361043610536106361073610836109361103611136112361133611436115361163611736118361193612036121361223612336124361253612636127361283612936130361313613236133361343613536136361373613836139361403614136142361433614436145361463614736148361493615036151361523615336154361553615636157361583615936160361613616236163361643616536166361673616836169361703617136172361733617436175361763617736178361793618036181361823618336184361853618636187361883618936190361913619236193361943619536196361973619836199362003620136202362033620436205362063620736208362093621036211362123621336214362153621636217362183621936220362213622236223362243622536226362273622836229362303623136232362333623436235362363623736238362393624036241362423624336244362453624636247362483624936250362513625236253362543625536256362573625836259362603626136262362633626436265362663626736268362693627036271362723627336274362753627636277362783627936280362813628236283362843628536286362873628836289362903629136292362933629436295362963629736298362993630036301363023630336304363053630636307363083630936310363113631236313363143631536316363173631836319363203632136322363233632436325363263632736328363293633036331363323633336334363353633636337363383633936340363413634236343363443634536346363473634836349363503635136352363533635436355363563635736358363593636036361363623636336364363653636636367363683636936370363713637236373363743637536376363773637836379363803638136382363833638436385363863638736388363893639036391363923639336394363953639636397363983639936400364013640236403364043640536406364073640836409364103641136412364133641436415364163641736418364193642036421364223642336424364253642636427364283642936430364313643236433364343643536436364373643836439364403644136442364433644436445364463644736448364493645036451364523645336454364553645636457364583645936460364613646236463364643646536466364673646836469364703647136472364733647436475364763647736478364793648036481364823648336484364853648636487364883648936490364913649236493364943649536496364973649836499365003650136502365033650436505365063650736508365093651036511365123651336514365153651636517365183651936520365213652236523365243652536526365273652836529365303653136532365333653436535365363653736538365393654036541365423654336544365453654636547365483654936550365513655236553365543655536556365573655836559365603656136562365633656436565365663656736568365693657036571365723657336574365753657636577365783657936580365813658236583365843658536586365873658836589365903659136592365933659436595365963659736598365993660036601366023660336604366053660636607366083660936610366113661236613366143661536616366173661836619366203662136622366233662436625366263662736628366293663036631366323663336634366353663636637366383663936640366413664236643366443664536646366473664836649366503665136652366533665436655366563665736658366593666036661366623666336664366653666636667366683666936670366713667236673366743667536676366773667836679366803668136682366833668436685366863668736688366893669036691366923669336694366953669636697366983669936700367013670236703367043670536706367073670836709367103671136712367133671436715367163671736718367193672036721367223672336724367253672636727367283672936730367313673236733367343673536736367373673836739367403674136742367433674436745367463674736748367493675036751367523675336754367553675636757367583675936760367613676236763367643676536766367673676836769367703677136772367733677436775367763677736778367793678036781367823678336784367853678636787367883678936790367913679236793367943679536796367973679836799368003680136802368033680436805368063680736808368093681036811368123681336814368153681636817368183681936820368213682236823368243682536826368273682836829368303683136832368333683436835368363683736838368393684036841368423684336844368453684636847368483684936850368513685236853368543685536856368573685836859368603686136862368633686436865368663686736868368693687036871368723687336874368753687636877368783687936880368813688236883368843688536886368873688836889368903689136892368933689436895368963689736898368993690036901369023690336904369053690636907369083690936910369113691236913369143691536916369173691836919369203692136922369233692436925369263692736928369293693036931369323693336934369353693636937369383693936940369413694236943369443694536946369473694836949369503695136952369533695436955369563695736958369593696036961369623696336964369653696636967369683696936970369713697236973369743697536976369773697836979369803698136982369833698436985369863698736988369893699036991369923699336994369953699636997369983699937000370013700237003370043700537006370073700837009370103701137012370133701437015370163701737018370193702037021370223702337024370253702637027370283702937030370313703237033370343703537036370373703837039370403704137042370433704437045370463704737048370493705037051370523705337054370553705637057370583705937060
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '73dev' };
  6. //
  7. if ( typeof define === 'function' && define.amd ) {
  8. define( 'three', THREE );
  9. } else if ( 'undefined' !== typeof exports && 'undefined' !== typeof module ) {
  10. module.exports = THREE;
  11. }
  12. // polyfills
  13. if ( self.requestAnimationFrame === undefined || self.cancelAnimationFrame === undefined ) {
  14. // Missing in Android stock browser.
  15. ( function () {
  16. var lastTime = 0;
  17. var vendors = [ 'ms', 'moz', 'webkit', 'o' ];
  18. for ( var x = 0; x < vendors.length && ! self.requestAnimationFrame; ++ x ) {
  19. self.requestAnimationFrame = self[ vendors[ x ] + 'RequestAnimationFrame' ];
  20. self.cancelAnimationFrame = self[ vendors[ x ] + 'CancelAnimationFrame' ] || self[ vendors[ x ] + 'CancelRequestAnimationFrame' ];
  21. }
  22. if ( self.requestAnimationFrame === undefined && self.setTimeout !== undefined ) {
  23. self.requestAnimationFrame = function ( callback ) {
  24. var currTime = Date.now(), timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
  25. var id = self.setTimeout( function () {
  26. callback( currTime + timeToCall );
  27. }, timeToCall );
  28. lastTime = currTime + timeToCall;
  29. return id;
  30. };
  31. }
  32. if ( self.cancelAnimationFrame === undefined && self.clearTimeout !== undefined ) {
  33. self.cancelAnimationFrame = function ( id ) {
  34. self.clearTimeout( id );
  35. };
  36. }
  37. } )();
  38. }
  39. //
  40. if ( self.performance === undefined ) {
  41. self.performance = {};
  42. }
  43. if ( self.performance.now === undefined ) {
  44. ( function () {
  45. var start = Date.now();
  46. self.performance.now = function () {
  47. return Date.now() - start;
  48. }
  49. } )();
  50. }
  51. if ( Math.sign === undefined ) {
  52. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  53. Math.sign = function ( x ) {
  54. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  55. };
  56. }
  57. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  58. // Missing in IE9-11.
  59. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  60. Object.defineProperty( Function.prototype, 'name', {
  61. get: function () {
  62. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  63. }
  64. } );
  65. }
  66. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  67. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  68. // GL STATE CONSTANTS
  69. THREE.CullFaceNone = 0;
  70. THREE.CullFaceBack = 1;
  71. THREE.CullFaceFront = 2;
  72. THREE.CullFaceFrontBack = 3;
  73. THREE.FrontFaceDirectionCW = 0;
  74. THREE.FrontFaceDirectionCCW = 1;
  75. // SHADOWING TYPES
  76. THREE.BasicShadowMap = 0;
  77. THREE.PCFShadowMap = 1;
  78. THREE.PCFSoftShadowMap = 2;
  79. // MATERIAL CONSTANTS
  80. // side
  81. THREE.FrontSide = 0;
  82. THREE.BackSide = 1;
  83. THREE.DoubleSide = 2;
  84. // shading
  85. THREE.FlatShading = 1;
  86. THREE.SmoothShading = 2;
  87. // colors
  88. THREE.NoColors = 0;
  89. THREE.FaceColors = 1;
  90. THREE.VertexColors = 2;
  91. // blending modes
  92. THREE.NoBlending = 0;
  93. THREE.NormalBlending = 1;
  94. THREE.AdditiveBlending = 2;
  95. THREE.SubtractiveBlending = 3;
  96. THREE.MultiplyBlending = 4;
  97. THREE.CustomBlending = 5;
  98. // custom blending equations
  99. // (numbers start from 100 not to clash with other
  100. // mappings to OpenGL constants defined in Texture.js)
  101. THREE.AddEquation = 100;
  102. THREE.SubtractEquation = 101;
  103. THREE.ReverseSubtractEquation = 102;
  104. THREE.MinEquation = 103;
  105. THREE.MaxEquation = 104;
  106. // custom blending destination factors
  107. THREE.ZeroFactor = 200;
  108. THREE.OneFactor = 201;
  109. THREE.SrcColorFactor = 202;
  110. THREE.OneMinusSrcColorFactor = 203;
  111. THREE.SrcAlphaFactor = 204;
  112. THREE.OneMinusSrcAlphaFactor = 205;
  113. THREE.DstAlphaFactor = 206;
  114. THREE.OneMinusDstAlphaFactor = 207;
  115. // custom blending source factors
  116. //THREE.ZeroFactor = 200;
  117. //THREE.OneFactor = 201;
  118. //THREE.SrcAlphaFactor = 204;
  119. //THREE.OneMinusSrcAlphaFactor = 205;
  120. //THREE.DstAlphaFactor = 206;
  121. //THREE.OneMinusDstAlphaFactor = 207;
  122. THREE.DstColorFactor = 208;
  123. THREE.OneMinusDstColorFactor = 209;
  124. THREE.SrcAlphaSaturateFactor = 210;
  125. // depth modes
  126. THREE.NeverDepth = 0;
  127. THREE.AlwaysDepth = 1;
  128. THREE.LessDepth = 2;
  129. THREE.LessEqualDepth = 3;
  130. THREE.EqualDepth = 4;
  131. THREE.GreaterEqualDepth = 5;
  132. THREE.GreaterDepth = 6;
  133. THREE.NotEqualDepth = 7;
  134. // TEXTURE CONSTANTS
  135. THREE.MultiplyOperation = 0;
  136. THREE.MixOperation = 1;
  137. THREE.AddOperation = 2;
  138. // Mapping modes
  139. THREE.UVMapping = 300;
  140. THREE.CubeReflectionMapping = 301;
  141. THREE.CubeRefractionMapping = 302;
  142. THREE.EquirectangularReflectionMapping = 303;
  143. THREE.EquirectangularRefractionMapping = 304;
  144. THREE.SphericalReflectionMapping = 305;
  145. // Wrapping modes
  146. THREE.RepeatWrapping = 1000;
  147. THREE.ClampToEdgeWrapping = 1001;
  148. THREE.MirroredRepeatWrapping = 1002;
  149. // Filters
  150. THREE.NearestFilter = 1003;
  151. THREE.NearestMipMapNearestFilter = 1004;
  152. THREE.NearestMipMapLinearFilter = 1005;
  153. THREE.LinearFilter = 1006;
  154. THREE.LinearMipMapNearestFilter = 1007;
  155. THREE.LinearMipMapLinearFilter = 1008;
  156. // Data types
  157. THREE.UnsignedByteType = 1009;
  158. THREE.ByteType = 1010;
  159. THREE.ShortType = 1011;
  160. THREE.UnsignedShortType = 1012;
  161. THREE.IntType = 1013;
  162. THREE.UnsignedIntType = 1014;
  163. THREE.FloatType = 1015;
  164. THREE.HalfFloatType = 1025;
  165. // Pixel types
  166. //THREE.UnsignedByteType = 1009;
  167. THREE.UnsignedShort4444Type = 1016;
  168. THREE.UnsignedShort5551Type = 1017;
  169. THREE.UnsignedShort565Type = 1018;
  170. // Pixel formats
  171. THREE.AlphaFormat = 1019;
  172. THREE.RGBFormat = 1020;
  173. THREE.RGBAFormat = 1021;
  174. THREE.LuminanceFormat = 1022;
  175. THREE.LuminanceAlphaFormat = 1023;
  176. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  177. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  178. // DDS / ST3C Compressed texture formats
  179. THREE.RGB_S3TC_DXT1_Format = 2001;
  180. THREE.RGBA_S3TC_DXT1_Format = 2002;
  181. THREE.RGBA_S3TC_DXT3_Format = 2003;
  182. THREE.RGBA_S3TC_DXT5_Format = 2004;
  183. // PVRTC compressed texture formats
  184. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  185. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  186. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  187. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  188. // Loop styles for AnimationAction
  189. THREE.LoopOnce = 2200;
  190. THREE.LoopRepeat = 2201;
  191. THREE.LoopPingPong = 2202;
  192. // DEPRECATED
  193. THREE.Projector = function () {
  194. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  195. this.projectVector = function ( vector, camera ) {
  196. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  197. vector.project( camera );
  198. };
  199. this.unprojectVector = function ( vector, camera ) {
  200. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  201. vector.unproject( camera );
  202. };
  203. this.pickingRay = function ( vector, camera ) {
  204. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  205. };
  206. };
  207. THREE.CanvasRenderer = function () {
  208. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  209. this.domElement = document.createElement( 'canvas' );
  210. this.clear = function () {};
  211. this.render = function () {};
  212. this.setClearColor = function () {};
  213. this.setSize = function () {};
  214. };
  215. // File:src/math/Color.js
  216. /**
  217. * @author mrdoob / http://mrdoob.com/
  218. */
  219. THREE.Color = function ( color ) {
  220. if ( arguments.length === 3 ) {
  221. return this.fromArray( arguments );
  222. }
  223. return this.set( color );
  224. };
  225. THREE.Color.prototype = {
  226. constructor: THREE.Color,
  227. r: 1, g: 1, b: 1,
  228. set: function ( value ) {
  229. if ( value instanceof THREE.Color ) {
  230. this.copy( value );
  231. } else if ( typeof value === 'number' ) {
  232. this.setHex( value );
  233. } else if ( typeof value === 'string' ) {
  234. this.setStyle( value );
  235. }
  236. return this;
  237. },
  238. setHex: function ( hex ) {
  239. hex = Math.floor( hex );
  240. this.r = ( hex >> 16 & 255 ) / 255;
  241. this.g = ( hex >> 8 & 255 ) / 255;
  242. this.b = ( hex & 255 ) / 255;
  243. return this;
  244. },
  245. setRGB: function ( r, g, b ) {
  246. this.r = r;
  247. this.g = g;
  248. this.b = b;
  249. return this;
  250. },
  251. setHSL: function () {
  252. function hue2rgb( p, q, t ) {
  253. if ( t < 0 ) t += 1;
  254. if ( t > 1 ) t -= 1;
  255. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  256. if ( t < 1 / 2 ) return q;
  257. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  258. return p;
  259. }
  260. return function ( h, s, l ) {
  261. // h,s,l ranges are in 0.0 - 1.0
  262. h = THREE.Math.euclideanModulo( h, 1 );
  263. s = THREE.Math.clamp( s, 0, 1 );
  264. l = THREE.Math.clamp( l, 0, 1 );
  265. if ( s === 0 ) {
  266. this.r = this.g = this.b = l;
  267. } else {
  268. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  269. var q = ( 2 * l ) - p;
  270. this.r = hue2rgb( q, p, h + 1 / 3 );
  271. this.g = hue2rgb( q, p, h );
  272. this.b = hue2rgb( q, p, h - 1 / 3 );
  273. }
  274. return this;
  275. };
  276. }(),
  277. setStyle: function ( style ) {
  278. function parseAlpha( strAlpha ) {
  279. var alpha = parseFloat( strAlpha );
  280. if ( alpha < 1 ) {
  281. console.warn( 'THREE.Color: Alpha component of color ' + style + ' will be ignored.' );
  282. }
  283. return alpha;
  284. }
  285. var m;
  286. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  287. // rgb / hsl
  288. var color;
  289. var name = m[ 1 ];
  290. var components = m[ 2 ];
  291. switch ( name ) {
  292. case 'rgb':
  293. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*$/.exec( components ) ) {
  294. // rgb(255,0,0)
  295. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  296. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  297. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  298. return this;
  299. }
  300. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  301. // rgb(100%,0%,0%)
  302. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  303. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  304. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  305. return this;
  306. }
  307. break;
  308. case 'rgba':
  309. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  310. // rgba(255,0,0,0.5)
  311. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  312. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  313. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  314. parseAlpha( color[ 4 ] );
  315. return this;
  316. }
  317. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  318. // rgba(100%,0%,0%,0.5)
  319. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  320. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  321. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  322. parseAlpha( color[ 4 ] );
  323. return this;
  324. }
  325. break;
  326. case 'hsl':
  327. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*$/.exec( components ) ) {
  328. // hsl(120,50%,50%)
  329. var h = parseFloat( color[ 1 ] );
  330. var s = parseInt( color[ 2 ], 10 ) / 100;
  331. var l = parseInt( color[ 3 ], 10 ) / 100;
  332. return this.setHSL( h, s, l );
  333. }
  334. break;
  335. case 'hsla':
  336. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*,\s*([0-9]*\.?[0-9]+)\s*$/.exec( components ) ) {
  337. // hsla(120,50%,50%,0.5)
  338. var h = parseFloat( color[ 1 ] );
  339. var s = parseInt( color[ 2 ], 10 ) / 100;
  340. var l = parseInt( color[ 3 ], 10 ) / 100;
  341. parseAlpha( color[ 4 ] );
  342. return this.setHSL( h, s, l );
  343. }
  344. break;
  345. }
  346. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  347. // hex color
  348. var hex = m[ 1 ];
  349. var size = hex.length;
  350. if ( size === 3 ) {
  351. // #ff0
  352. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  353. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  354. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  355. return this;
  356. } else if ( size === 6 ) {
  357. // #ff0000
  358. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  359. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  360. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  361. return this;
  362. }
  363. }
  364. if ( style && style.length > 0 ) {
  365. // color keywords
  366. var hex = THREE.ColorKeywords[ style ];
  367. if ( hex !== undefined ) {
  368. // red
  369. this.setHex( hex );
  370. } else {
  371. // unknown color
  372. console.warn( 'THREE.Color: Unknown color ' + style );
  373. }
  374. }
  375. return this;
  376. },
  377. clone: function () {
  378. return new this.constructor( this.r, this.g, this.b );
  379. },
  380. copy: function ( color ) {
  381. this.r = color.r;
  382. this.g = color.g;
  383. this.b = color.b;
  384. return this;
  385. },
  386. copyGammaToLinear: function ( color, gammaFactor ) {
  387. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  388. this.r = Math.pow( color.r, gammaFactor );
  389. this.g = Math.pow( color.g, gammaFactor );
  390. this.b = Math.pow( color.b, gammaFactor );
  391. return this;
  392. },
  393. copyLinearToGamma: function ( color, gammaFactor ) {
  394. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  395. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  396. this.r = Math.pow( color.r, safeInverse );
  397. this.g = Math.pow( color.g, safeInverse );
  398. this.b = Math.pow( color.b, safeInverse );
  399. return this;
  400. },
  401. convertGammaToLinear: function () {
  402. var r = this.r, g = this.g, b = this.b;
  403. this.r = r * r;
  404. this.g = g * g;
  405. this.b = b * b;
  406. return this;
  407. },
  408. convertLinearToGamma: function () {
  409. this.r = Math.sqrt( this.r );
  410. this.g = Math.sqrt( this.g );
  411. this.b = Math.sqrt( this.b );
  412. return this;
  413. },
  414. getHex: function () {
  415. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  416. },
  417. getHexString: function () {
  418. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  419. },
  420. getHSL: function ( optionalTarget ) {
  421. // h,s,l ranges are in 0.0 - 1.0
  422. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  423. var r = this.r, g = this.g, b = this.b;
  424. var max = Math.max( r, g, b );
  425. var min = Math.min( r, g, b );
  426. var hue, saturation;
  427. var lightness = ( min + max ) / 2.0;
  428. if ( min === max ) {
  429. hue = 0;
  430. saturation = 0;
  431. } else {
  432. var delta = max - min;
  433. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  434. switch ( max ) {
  435. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  436. case g: hue = ( b - r ) / delta + 2; break;
  437. case b: hue = ( r - g ) / delta + 4; break;
  438. }
  439. hue /= 6;
  440. }
  441. hsl.h = hue;
  442. hsl.s = saturation;
  443. hsl.l = lightness;
  444. return hsl;
  445. },
  446. getStyle: function () {
  447. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  448. },
  449. offsetHSL: function ( h, s, l ) {
  450. var hsl = this.getHSL();
  451. hsl.h += h; hsl.s += s; hsl.l += l;
  452. this.setHSL( hsl.h, hsl.s, hsl.l );
  453. return this;
  454. },
  455. add: function ( color ) {
  456. this.r += color.r;
  457. this.g += color.g;
  458. this.b += color.b;
  459. return this;
  460. },
  461. addColors: function ( color1, color2 ) {
  462. this.r = color1.r + color2.r;
  463. this.g = color1.g + color2.g;
  464. this.b = color1.b + color2.b;
  465. return this;
  466. },
  467. addScalar: function ( s ) {
  468. this.r += s;
  469. this.g += s;
  470. this.b += s;
  471. return this;
  472. },
  473. multiply: function ( color ) {
  474. this.r *= color.r;
  475. this.g *= color.g;
  476. this.b *= color.b;
  477. return this;
  478. },
  479. multiplyScalar: function ( s ) {
  480. this.r *= s;
  481. this.g *= s;
  482. this.b *= s;
  483. return this;
  484. },
  485. lerp: function ( color, alpha ) {
  486. this.r += ( color.r - this.r ) * alpha;
  487. this.g += ( color.g - this.g ) * alpha;
  488. this.b += ( color.b - this.b ) * alpha;
  489. return this;
  490. },
  491. equals: function ( c ) {
  492. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  493. },
  494. fromArray: function ( array, offset ) {
  495. if ( offset === undefined ) offset = 0;
  496. this.r = array[ offset ];
  497. this.g = array[ offset + 1 ];
  498. this.b = array[ offset + 2 ];
  499. return this;
  500. },
  501. toArray: function ( array, offset ) {
  502. if ( array === undefined ) array = [];
  503. if ( offset === undefined ) offset = 0;
  504. array[ offset ] = this.r;
  505. array[ offset + 1 ] = this.g;
  506. array[ offset + 2 ] = this.b;
  507. return array;
  508. }
  509. };
  510. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  511. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  512. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  513. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  514. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  515. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  516. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  517. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  518. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  519. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  520. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  521. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  522. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  523. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  524. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  525. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  526. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  527. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  528. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  529. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  530. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  531. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  532. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  533. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  534. // File:src/math/Quaternion.js
  535. /**
  536. * @author mikael emtinger / http://gomo.se/
  537. * @author alteredq / http://alteredqualia.com/
  538. * @author WestLangley / http://github.com/WestLangley
  539. * @author bhouston / http://clara.io
  540. */
  541. THREE.Quaternion = function ( x, y, z, w ) {
  542. this._x = x || 0;
  543. this._y = y || 0;
  544. this._z = z || 0;
  545. this._w = ( w !== undefined ) ? w : 1;
  546. };
  547. THREE.Quaternion.prototype = {
  548. constructor: THREE.Quaternion,
  549. get x () {
  550. return this._x;
  551. },
  552. set x ( value ) {
  553. this._x = value;
  554. this.onChangeCallback();
  555. },
  556. get y () {
  557. return this._y;
  558. },
  559. set y ( value ) {
  560. this._y = value;
  561. this.onChangeCallback();
  562. },
  563. get z () {
  564. return this._z;
  565. },
  566. set z ( value ) {
  567. this._z = value;
  568. this.onChangeCallback();
  569. },
  570. get w () {
  571. return this._w;
  572. },
  573. set w ( value ) {
  574. this._w = value;
  575. this.onChangeCallback();
  576. },
  577. set: function ( x, y, z, w ) {
  578. this._x = x;
  579. this._y = y;
  580. this._z = z;
  581. this._w = w;
  582. this.onChangeCallback();
  583. return this;
  584. },
  585. clone: function () {
  586. return new this.constructor( this._x, this._y, this._z, this._w );
  587. },
  588. copy: function ( quaternion ) {
  589. this._x = quaternion.x;
  590. this._y = quaternion.y;
  591. this._z = quaternion.z;
  592. this._w = quaternion.w;
  593. this.onChangeCallback();
  594. return this;
  595. },
  596. setFromEuler: function ( euler, update ) {
  597. if ( euler instanceof THREE.Euler === false ) {
  598. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  599. }
  600. // http://www.mathworks.com/matlabcentral/fileexchange/
  601. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  602. // content/SpinCalc.m
  603. var c1 = Math.cos( euler._x / 2 );
  604. var c2 = Math.cos( euler._y / 2 );
  605. var c3 = Math.cos( euler._z / 2 );
  606. var s1 = Math.sin( euler._x / 2 );
  607. var s2 = Math.sin( euler._y / 2 );
  608. var s3 = Math.sin( euler._z / 2 );
  609. var order = euler.order;
  610. if ( order === 'XYZ' ) {
  611. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  612. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  613. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  614. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  615. } else if ( order === 'YXZ' ) {
  616. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  617. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  618. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  619. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  620. } else if ( order === 'ZXY' ) {
  621. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  622. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  623. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  624. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  625. } else if ( order === 'ZYX' ) {
  626. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  627. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  628. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  629. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  630. } else if ( order === 'YZX' ) {
  631. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  632. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  633. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  634. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  635. } else if ( order === 'XZY' ) {
  636. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  637. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  638. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  639. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  640. }
  641. if ( update !== false ) this.onChangeCallback();
  642. return this;
  643. },
  644. setFromAxisAngle: function ( axis, angle ) {
  645. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  646. // assumes axis is normalized
  647. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  648. this._x = axis.x * s;
  649. this._y = axis.y * s;
  650. this._z = axis.z * s;
  651. this._w = Math.cos( halfAngle );
  652. this.onChangeCallback();
  653. return this;
  654. },
  655. setFromRotationMatrix: function ( m ) {
  656. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  657. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  658. var te = m.elements,
  659. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  660. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  661. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  662. trace = m11 + m22 + m33,
  663. s;
  664. if ( trace > 0 ) {
  665. s = 0.5 / Math.sqrt( trace + 1.0 );
  666. this._w = 0.25 / s;
  667. this._x = ( m32 - m23 ) * s;
  668. this._y = ( m13 - m31 ) * s;
  669. this._z = ( m21 - m12 ) * s;
  670. } else if ( m11 > m22 && m11 > m33 ) {
  671. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  672. this._w = ( m32 - m23 ) / s;
  673. this._x = 0.25 * s;
  674. this._y = ( m12 + m21 ) / s;
  675. this._z = ( m13 + m31 ) / s;
  676. } else if ( m22 > m33 ) {
  677. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  678. this._w = ( m13 - m31 ) / s;
  679. this._x = ( m12 + m21 ) / s;
  680. this._y = 0.25 * s;
  681. this._z = ( m23 + m32 ) / s;
  682. } else {
  683. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  684. this._w = ( m21 - m12 ) / s;
  685. this._x = ( m13 + m31 ) / s;
  686. this._y = ( m23 + m32 ) / s;
  687. this._z = 0.25 * s;
  688. }
  689. this.onChangeCallback();
  690. return this;
  691. },
  692. setFromUnitVectors: function () {
  693. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  694. // assumes direction vectors vFrom and vTo are normalized
  695. var v1, r;
  696. var EPS = 0.000001;
  697. return function ( vFrom, vTo ) {
  698. if ( v1 === undefined ) v1 = new THREE.Vector3();
  699. r = vFrom.dot( vTo ) + 1;
  700. if ( r < EPS ) {
  701. r = 0;
  702. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  703. v1.set( - vFrom.y, vFrom.x, 0 );
  704. } else {
  705. v1.set( 0, - vFrom.z, vFrom.y );
  706. }
  707. } else {
  708. v1.crossVectors( vFrom, vTo );
  709. }
  710. this._x = v1.x;
  711. this._y = v1.y;
  712. this._z = v1.z;
  713. this._w = r;
  714. this.normalize();
  715. return this;
  716. }
  717. }(),
  718. inverse: function () {
  719. this.conjugate().normalize();
  720. return this;
  721. },
  722. conjugate: function () {
  723. this._x *= - 1;
  724. this._y *= - 1;
  725. this._z *= - 1;
  726. this.onChangeCallback();
  727. return this;
  728. },
  729. dot: function ( v ) {
  730. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  731. },
  732. lengthSq: function () {
  733. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  734. },
  735. length: function () {
  736. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  737. },
  738. normalize: function () {
  739. var l = this.length();
  740. if ( l === 0 ) {
  741. this._x = 0;
  742. this._y = 0;
  743. this._z = 0;
  744. this._w = 1;
  745. } else {
  746. l = 1 / l;
  747. this._x = this._x * l;
  748. this._y = this._y * l;
  749. this._z = this._z * l;
  750. this._w = this._w * l;
  751. }
  752. this.onChangeCallback();
  753. return this;
  754. },
  755. multiply: function ( q, p ) {
  756. if ( p !== undefined ) {
  757. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  758. return this.multiplyQuaternions( q, p );
  759. }
  760. return this.multiplyQuaternions( this, q );
  761. },
  762. multiplyQuaternions: function ( a, b ) {
  763. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  764. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  765. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  766. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  767. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  768. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  769. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  770. this.onChangeCallback();
  771. return this;
  772. },
  773. multiplyVector3: function ( vector ) {
  774. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  775. return vector.applyQuaternion( this );
  776. },
  777. slerp: function ( qb, t ) {
  778. if ( t === 0 ) return this;
  779. if ( t === 1 ) return this.copy( qb );
  780. var x = this._x, y = this._y, z = this._z, w = this._w;
  781. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  782. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  783. if ( cosHalfTheta < 0 ) {
  784. this._w = - qb._w;
  785. this._x = - qb._x;
  786. this._y = - qb._y;
  787. this._z = - qb._z;
  788. cosHalfTheta = - cosHalfTheta;
  789. } else {
  790. this.copy( qb );
  791. }
  792. if ( cosHalfTheta >= 1.0 ) {
  793. this._w = w;
  794. this._x = x;
  795. this._y = y;
  796. this._z = z;
  797. return this;
  798. }
  799. var halfTheta = Math.acos( cosHalfTheta );
  800. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  801. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  802. this._w = 0.5 * ( w + this._w );
  803. this._x = 0.5 * ( x + this._x );
  804. this._y = 0.5 * ( y + this._y );
  805. this._z = 0.5 * ( z + this._z );
  806. return this;
  807. }
  808. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  809. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  810. this._w = ( w * ratioA + this._w * ratioB );
  811. this._x = ( x * ratioA + this._x * ratioB );
  812. this._y = ( y * ratioA + this._y * ratioB );
  813. this._z = ( z * ratioA + this._z * ratioB );
  814. this.onChangeCallback();
  815. return this;
  816. },
  817. equals: function ( quaternion ) {
  818. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  819. },
  820. fromArray: function ( array, offset ) {
  821. if ( offset === undefined ) offset = 0;
  822. this._x = array[ offset ];
  823. this._y = array[ offset + 1 ];
  824. this._z = array[ offset + 2 ];
  825. this._w = array[ offset + 3 ];
  826. this.onChangeCallback();
  827. return this;
  828. },
  829. toArray: function ( array, offset ) {
  830. if ( array === undefined ) array = [];
  831. if ( offset === undefined ) offset = 0;
  832. array[ offset ] = this._x;
  833. array[ offset + 1 ] = this._y;
  834. array[ offset + 2 ] = this._z;
  835. array[ offset + 3 ] = this._w;
  836. return array;
  837. },
  838. onChange: function ( callback ) {
  839. this.onChangeCallback = callback;
  840. return this;
  841. },
  842. onChangeCallback: function () {}
  843. };
  844. THREE.Quaternion.slerp = function ( qa, qb, qm, t ) {
  845. return qm.copy( qa ).slerp( qb, t );
  846. };
  847. // File:src/math/Vector2.js
  848. /**
  849. * @author mrdoob / http://mrdoob.com/
  850. * @author philogb / http://blog.thejit.org/
  851. * @author egraether / http://egraether.com/
  852. * @author zz85 / http://www.lab4games.net/zz85/blog
  853. */
  854. THREE.Vector2 = function ( x, y ) {
  855. this.x = x || 0;
  856. this.y = y || 0;
  857. };
  858. THREE.Vector2.prototype = {
  859. constructor: THREE.Vector2,
  860. get width() { return this.x },
  861. set width( value ) { this.x = value },
  862. get height() { return this.y },
  863. set height( value ) { this.y = value },
  864. //
  865. set: function ( x, y ) {
  866. this.x = x;
  867. this.y = y;
  868. return this;
  869. },
  870. setX: function ( x ) {
  871. this.x = x;
  872. return this;
  873. },
  874. setY: function ( y ) {
  875. this.y = y;
  876. return this;
  877. },
  878. setComponent: function ( index, value ) {
  879. switch ( index ) {
  880. case 0: this.x = value; break;
  881. case 1: this.y = value; break;
  882. default: throw new Error( 'index is out of range: ' + index );
  883. }
  884. },
  885. getComponent: function ( index ) {
  886. switch ( index ) {
  887. case 0: return this.x;
  888. case 1: return this.y;
  889. default: throw new Error( 'index is out of range: ' + index );
  890. }
  891. },
  892. clone: function () {
  893. return new this.constructor( this.x, this.y );
  894. },
  895. copy: function ( v ) {
  896. this.x = v.x;
  897. this.y = v.y;
  898. return this;
  899. },
  900. add: function ( v, w ) {
  901. if ( w !== undefined ) {
  902. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  903. return this.addVectors( v, w );
  904. }
  905. this.x += v.x;
  906. this.y += v.y;
  907. return this;
  908. },
  909. addScalar: function ( s ) {
  910. this.x += s;
  911. this.y += s;
  912. return this;
  913. },
  914. addVectors: function ( a, b ) {
  915. this.x = a.x + b.x;
  916. this.y = a.y + b.y;
  917. return this;
  918. },
  919. addScaledVector: function ( v, s ) {
  920. this.x += v.x * s;
  921. this.y += v.y * s;
  922. return this;
  923. },
  924. sub: function ( v, w ) {
  925. if ( w !== undefined ) {
  926. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  927. return this.subVectors( v, w );
  928. }
  929. this.x -= v.x;
  930. this.y -= v.y;
  931. return this;
  932. },
  933. subScalar: function ( s ) {
  934. this.x -= s;
  935. this.y -= s;
  936. return this;
  937. },
  938. subVectors: function ( a, b ) {
  939. this.x = a.x - b.x;
  940. this.y = a.y - b.y;
  941. return this;
  942. },
  943. multiply: function ( v ) {
  944. this.x *= v.x;
  945. this.y *= v.y;
  946. return this;
  947. },
  948. multiplyScalar: function ( s ) {
  949. this.x *= s;
  950. this.y *= s;
  951. return this;
  952. },
  953. divide: function ( v ) {
  954. this.x /= v.x;
  955. this.y /= v.y;
  956. return this;
  957. },
  958. divideScalar: function ( scalar ) {
  959. if ( scalar !== 0 ) {
  960. var invScalar = 1 / scalar;
  961. this.x *= invScalar;
  962. this.y *= invScalar;
  963. } else {
  964. this.x = 0;
  965. this.y = 0;
  966. }
  967. return this;
  968. },
  969. min: function ( v ) {
  970. if ( this.x > v.x ) {
  971. this.x = v.x;
  972. }
  973. if ( this.y > v.y ) {
  974. this.y = v.y;
  975. }
  976. return this;
  977. },
  978. max: function ( v ) {
  979. if ( this.x < v.x ) {
  980. this.x = v.x;
  981. }
  982. if ( this.y < v.y ) {
  983. this.y = v.y;
  984. }
  985. return this;
  986. },
  987. clamp: function ( min, max ) {
  988. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  989. if ( this.x < min.x ) {
  990. this.x = min.x;
  991. } else if ( this.x > max.x ) {
  992. this.x = max.x;
  993. }
  994. if ( this.y < min.y ) {
  995. this.y = min.y;
  996. } else if ( this.y > max.y ) {
  997. this.y = max.y;
  998. }
  999. return this;
  1000. },
  1001. clampScalar: function () {
  1002. var min, max;
  1003. return function clampScalar( minVal, maxVal ) {
  1004. if ( min === undefined ) {
  1005. min = new THREE.Vector2();
  1006. max = new THREE.Vector2();
  1007. }
  1008. min.set( minVal, minVal );
  1009. max.set( maxVal, maxVal );
  1010. return this.clamp( min, max );
  1011. };
  1012. }(),
  1013. floor: function () {
  1014. this.x = Math.floor( this.x );
  1015. this.y = Math.floor( this.y );
  1016. return this;
  1017. },
  1018. ceil: function () {
  1019. this.x = Math.ceil( this.x );
  1020. this.y = Math.ceil( this.y );
  1021. return this;
  1022. },
  1023. round: function () {
  1024. this.x = Math.round( this.x );
  1025. this.y = Math.round( this.y );
  1026. return this;
  1027. },
  1028. roundToZero: function () {
  1029. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1030. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1031. return this;
  1032. },
  1033. negate: function () {
  1034. this.x = - this.x;
  1035. this.y = - this.y;
  1036. return this;
  1037. },
  1038. dot: function ( v ) {
  1039. return this.x * v.x + this.y * v.y;
  1040. },
  1041. lengthSq: function () {
  1042. return this.x * this.x + this.y * this.y;
  1043. },
  1044. length: function () {
  1045. return Math.sqrt( this.x * this.x + this.y * this.y );
  1046. },
  1047. lengthManhattan: function() {
  1048. return Math.abs( this.x ) + Math.abs( this.y );
  1049. },
  1050. normalize: function () {
  1051. return this.divideScalar( this.length() );
  1052. },
  1053. distanceTo: function ( v ) {
  1054. return Math.sqrt( this.distanceToSquared( v ) );
  1055. },
  1056. distanceToSquared: function ( v ) {
  1057. var dx = this.x - v.x, dy = this.y - v.y;
  1058. return dx * dx + dy * dy;
  1059. },
  1060. setLength: function ( l ) {
  1061. var oldLength = this.length();
  1062. if ( oldLength !== 0 && l !== oldLength ) {
  1063. this.multiplyScalar( l / oldLength );
  1064. }
  1065. return this;
  1066. },
  1067. lerp: function ( v, alpha ) {
  1068. this.x += ( v.x - this.x ) * alpha;
  1069. this.y += ( v.y - this.y ) * alpha;
  1070. return this;
  1071. },
  1072. lerpVectors: function ( v1, v2, alpha ) {
  1073. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1074. return this;
  1075. },
  1076. equals: function ( v ) {
  1077. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1078. },
  1079. fromArray: function ( array, offset ) {
  1080. if ( offset === undefined ) offset = 0;
  1081. this.x = array[ offset ];
  1082. this.y = array[ offset + 1 ];
  1083. return this;
  1084. },
  1085. toArray: function ( array, offset ) {
  1086. if ( array === undefined ) array = [];
  1087. if ( offset === undefined ) offset = 0;
  1088. array[ offset ] = this.x;
  1089. array[ offset + 1 ] = this.y;
  1090. return array;
  1091. },
  1092. fromAttribute: function ( attribute, index, offset ) {
  1093. if ( offset === undefined ) offset = 0;
  1094. index = index * attribute.itemSize + offset;
  1095. this.x = attribute.array[ index ];
  1096. this.y = attribute.array[ index + 1 ];
  1097. return this;
  1098. }
  1099. };
  1100. // File:src/math/Vector3.js
  1101. /**
  1102. * @author mrdoob / http://mrdoob.com/
  1103. * @author *kile / http://kile.stravaganza.org/
  1104. * @author philogb / http://blog.thejit.org/
  1105. * @author mikael emtinger / http://gomo.se/
  1106. * @author egraether / http://egraether.com/
  1107. * @author WestLangley / http://github.com/WestLangley
  1108. */
  1109. THREE.Vector3 = function ( x, y, z ) {
  1110. this.x = x || 0;
  1111. this.y = y || 0;
  1112. this.z = z || 0;
  1113. };
  1114. THREE.Vector3.prototype = {
  1115. constructor: THREE.Vector3,
  1116. set: function ( x, y, z ) {
  1117. this.x = x;
  1118. this.y = y;
  1119. this.z = z;
  1120. return this;
  1121. },
  1122. setX: function ( x ) {
  1123. this.x = x;
  1124. return this;
  1125. },
  1126. setY: function ( y ) {
  1127. this.y = y;
  1128. return this;
  1129. },
  1130. setZ: function ( z ) {
  1131. this.z = z;
  1132. return this;
  1133. },
  1134. setComponent: function ( index, value ) {
  1135. switch ( index ) {
  1136. case 0: this.x = value; break;
  1137. case 1: this.y = value; break;
  1138. case 2: this.z = value; break;
  1139. default: throw new Error( 'index is out of range: ' + index );
  1140. }
  1141. },
  1142. getComponent: function ( index ) {
  1143. switch ( index ) {
  1144. case 0: return this.x;
  1145. case 1: return this.y;
  1146. case 2: return this.z;
  1147. default: throw new Error( 'index is out of range: ' + index );
  1148. }
  1149. },
  1150. clone: function () {
  1151. return new this.constructor( this.x, this.y, this.z );
  1152. },
  1153. copy: function ( v ) {
  1154. this.x = v.x;
  1155. this.y = v.y;
  1156. this.z = v.z;
  1157. return this;
  1158. },
  1159. add: function ( v, w ) {
  1160. if ( w !== undefined ) {
  1161. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1162. return this.addVectors( v, w );
  1163. }
  1164. this.x += v.x;
  1165. this.y += v.y;
  1166. this.z += v.z;
  1167. return this;
  1168. },
  1169. addScalar: function ( s ) {
  1170. this.x += s;
  1171. this.y += s;
  1172. this.z += s;
  1173. return this;
  1174. },
  1175. addVectors: function ( a, b ) {
  1176. this.x = a.x + b.x;
  1177. this.y = a.y + b.y;
  1178. this.z = a.z + b.z;
  1179. return this;
  1180. },
  1181. addScaledVector: function ( v, s ) {
  1182. this.x += v.x * s;
  1183. this.y += v.y * s;
  1184. this.z += v.z * s;
  1185. return this;
  1186. },
  1187. sub: function ( v, w ) {
  1188. if ( w !== undefined ) {
  1189. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1190. return this.subVectors( v, w );
  1191. }
  1192. this.x -= v.x;
  1193. this.y -= v.y;
  1194. this.z -= v.z;
  1195. return this;
  1196. },
  1197. subScalar: function ( s ) {
  1198. this.x -= s;
  1199. this.y -= s;
  1200. this.z -= s;
  1201. return this;
  1202. },
  1203. subVectors: function ( a, b ) {
  1204. this.x = a.x - b.x;
  1205. this.y = a.y - b.y;
  1206. this.z = a.z - b.z;
  1207. return this;
  1208. },
  1209. multiply: function ( v, w ) {
  1210. if ( w !== undefined ) {
  1211. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1212. return this.multiplyVectors( v, w );
  1213. }
  1214. this.x *= v.x;
  1215. this.y *= v.y;
  1216. this.z *= v.z;
  1217. return this;
  1218. },
  1219. multiplyScalar: function ( scalar ) {
  1220. this.x *= scalar;
  1221. this.y *= scalar;
  1222. this.z *= scalar;
  1223. return this;
  1224. },
  1225. multiplyVectors: function ( a, b ) {
  1226. this.x = a.x * b.x;
  1227. this.y = a.y * b.y;
  1228. this.z = a.z * b.z;
  1229. return this;
  1230. },
  1231. applyEuler: function () {
  1232. var quaternion;
  1233. return function applyEuler( euler ) {
  1234. if ( euler instanceof THREE.Euler === false ) {
  1235. console.error( 'THREE.Vector3: .applyEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  1236. }
  1237. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1238. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1239. return this;
  1240. };
  1241. }(),
  1242. applyAxisAngle: function () {
  1243. var quaternion;
  1244. return function applyAxisAngle( axis, angle ) {
  1245. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1246. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1247. return this;
  1248. };
  1249. }(),
  1250. applyMatrix3: function ( m ) {
  1251. var x = this.x;
  1252. var y = this.y;
  1253. var z = this.z;
  1254. var e = m.elements;
  1255. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1256. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1257. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1258. return this;
  1259. },
  1260. applyMatrix4: function ( m ) {
  1261. // input: THREE.Matrix4 affine matrix
  1262. var x = this.x, y = this.y, z = this.z;
  1263. var e = m.elements;
  1264. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1265. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1266. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1267. return this;
  1268. },
  1269. applyProjection: function ( m ) {
  1270. // input: THREE.Matrix4 projection matrix
  1271. var x = this.x, y = this.y, z = this.z;
  1272. var e = m.elements;
  1273. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1274. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1275. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1276. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1277. return this;
  1278. },
  1279. applyQuaternion: function ( q ) {
  1280. var x = this.x;
  1281. var y = this.y;
  1282. var z = this.z;
  1283. var qx = q.x;
  1284. var qy = q.y;
  1285. var qz = q.z;
  1286. var qw = q.w;
  1287. // calculate quat * vector
  1288. var ix = qw * x + qy * z - qz * y;
  1289. var iy = qw * y + qz * x - qx * z;
  1290. var iz = qw * z + qx * y - qy * x;
  1291. var iw = - qx * x - qy * y - qz * z;
  1292. // calculate result * inverse quat
  1293. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1294. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1295. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1296. return this;
  1297. },
  1298. project: function () {
  1299. var matrix;
  1300. return function project( camera ) {
  1301. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1302. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1303. return this.applyProjection( matrix );
  1304. };
  1305. }(),
  1306. unproject: function () {
  1307. var matrix;
  1308. return function unproject( camera ) {
  1309. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1310. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1311. return this.applyProjection( matrix );
  1312. };
  1313. }(),
  1314. transformDirection: function ( m ) {
  1315. // input: THREE.Matrix4 affine matrix
  1316. // vector interpreted as a direction
  1317. var x = this.x, y = this.y, z = this.z;
  1318. var e = m.elements;
  1319. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1320. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1321. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1322. this.normalize();
  1323. return this;
  1324. },
  1325. divide: function ( v ) {
  1326. this.x /= v.x;
  1327. this.y /= v.y;
  1328. this.z /= v.z;
  1329. return this;
  1330. },
  1331. divideScalar: function ( scalar ) {
  1332. if ( scalar !== 0 ) {
  1333. var invScalar = 1 / scalar;
  1334. this.x *= invScalar;
  1335. this.y *= invScalar;
  1336. this.z *= invScalar;
  1337. } else {
  1338. this.x = 0;
  1339. this.y = 0;
  1340. this.z = 0;
  1341. }
  1342. return this;
  1343. },
  1344. min: function ( v ) {
  1345. if ( this.x > v.x ) {
  1346. this.x = v.x;
  1347. }
  1348. if ( this.y > v.y ) {
  1349. this.y = v.y;
  1350. }
  1351. if ( this.z > v.z ) {
  1352. this.z = v.z;
  1353. }
  1354. return this;
  1355. },
  1356. max: function ( v ) {
  1357. if ( this.x < v.x ) {
  1358. this.x = v.x;
  1359. }
  1360. if ( this.y < v.y ) {
  1361. this.y = v.y;
  1362. }
  1363. if ( this.z < v.z ) {
  1364. this.z = v.z;
  1365. }
  1366. return this;
  1367. },
  1368. clamp: function ( min, max ) {
  1369. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1370. if ( this.x < min.x ) {
  1371. this.x = min.x;
  1372. } else if ( this.x > max.x ) {
  1373. this.x = max.x;
  1374. }
  1375. if ( this.y < min.y ) {
  1376. this.y = min.y;
  1377. } else if ( this.y > max.y ) {
  1378. this.y = max.y;
  1379. }
  1380. if ( this.z < min.z ) {
  1381. this.z = min.z;
  1382. } else if ( this.z > max.z ) {
  1383. this.z = max.z;
  1384. }
  1385. return this;
  1386. },
  1387. clampScalar: function () {
  1388. var min, max;
  1389. return function clampScalar( minVal, maxVal ) {
  1390. if ( min === undefined ) {
  1391. min = new THREE.Vector3();
  1392. max = new THREE.Vector3();
  1393. }
  1394. min.set( minVal, minVal, minVal );
  1395. max.set( maxVal, maxVal, maxVal );
  1396. return this.clamp( min, max );
  1397. };
  1398. }(),
  1399. floor: function () {
  1400. this.x = Math.floor( this.x );
  1401. this.y = Math.floor( this.y );
  1402. this.z = Math.floor( this.z );
  1403. return this;
  1404. },
  1405. ceil: function () {
  1406. this.x = Math.ceil( this.x );
  1407. this.y = Math.ceil( this.y );
  1408. this.z = Math.ceil( this.z );
  1409. return this;
  1410. },
  1411. round: function () {
  1412. this.x = Math.round( this.x );
  1413. this.y = Math.round( this.y );
  1414. this.z = Math.round( this.z );
  1415. return this;
  1416. },
  1417. roundToZero: function () {
  1418. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1419. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1420. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1421. return this;
  1422. },
  1423. negate: function () {
  1424. this.x = - this.x;
  1425. this.y = - this.y;
  1426. this.z = - this.z;
  1427. return this;
  1428. },
  1429. dot: function ( v ) {
  1430. return this.x * v.x + this.y * v.y + this.z * v.z;
  1431. },
  1432. lengthSq: function () {
  1433. return this.x * this.x + this.y * this.y + this.z * this.z;
  1434. },
  1435. length: function () {
  1436. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1437. },
  1438. lengthManhattan: function () {
  1439. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1440. },
  1441. normalize: function () {
  1442. return this.divideScalar( this.length() );
  1443. },
  1444. setLength: function ( l ) {
  1445. var oldLength = this.length();
  1446. if ( oldLength !== 0 && l !== oldLength ) {
  1447. this.multiplyScalar( l / oldLength );
  1448. }
  1449. return this;
  1450. },
  1451. lerp: function ( v, alpha ) {
  1452. this.x += ( v.x - this.x ) * alpha;
  1453. this.y += ( v.y - this.y ) * alpha;
  1454. this.z += ( v.z - this.z ) * alpha;
  1455. return this;
  1456. },
  1457. lerpVectors: function ( v1, v2, alpha ) {
  1458. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1459. return this;
  1460. },
  1461. cross: function ( v, w ) {
  1462. if ( w !== undefined ) {
  1463. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1464. return this.crossVectors( v, w );
  1465. }
  1466. var x = this.x, y = this.y, z = this.z;
  1467. this.x = y * v.z - z * v.y;
  1468. this.y = z * v.x - x * v.z;
  1469. this.z = x * v.y - y * v.x;
  1470. return this;
  1471. },
  1472. crossVectors: function ( a, b ) {
  1473. var ax = a.x, ay = a.y, az = a.z;
  1474. var bx = b.x, by = b.y, bz = b.z;
  1475. this.x = ay * bz - az * by;
  1476. this.y = az * bx - ax * bz;
  1477. this.z = ax * by - ay * bx;
  1478. return this;
  1479. },
  1480. projectOnVector: function () {
  1481. var v1, dot;
  1482. return function projectOnVector( vector ) {
  1483. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1484. v1.copy( vector ).normalize();
  1485. dot = this.dot( v1 );
  1486. return this.copy( v1 ).multiplyScalar( dot );
  1487. };
  1488. }(),
  1489. projectOnPlane: function () {
  1490. var v1;
  1491. return function projectOnPlane( planeNormal ) {
  1492. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1493. v1.copy( this ).projectOnVector( planeNormal );
  1494. return this.sub( v1 );
  1495. }
  1496. }(),
  1497. reflect: function () {
  1498. // reflect incident vector off plane orthogonal to normal
  1499. // normal is assumed to have unit length
  1500. var v1;
  1501. return function reflect( normal ) {
  1502. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1503. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1504. }
  1505. }(),
  1506. angleTo: function ( v ) {
  1507. var theta = this.dot( v ) / ( this.length() * v.length() );
  1508. // clamp, to handle numerical problems
  1509. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1510. },
  1511. distanceTo: function ( v ) {
  1512. return Math.sqrt( this.distanceToSquared( v ) );
  1513. },
  1514. distanceToSquared: function ( v ) {
  1515. var dx = this.x - v.x;
  1516. var dy = this.y - v.y;
  1517. var dz = this.z - v.z;
  1518. return dx * dx + dy * dy + dz * dz;
  1519. },
  1520. setEulerFromRotationMatrix: function ( m, order ) {
  1521. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  1522. },
  1523. setEulerFromQuaternion: function ( q, order ) {
  1524. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  1525. },
  1526. getPositionFromMatrix: function ( m ) {
  1527. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  1528. return this.setFromMatrixPosition( m );
  1529. },
  1530. getScaleFromMatrix: function ( m ) {
  1531. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  1532. return this.setFromMatrixScale( m );
  1533. },
  1534. getColumnFromMatrix: function ( index, matrix ) {
  1535. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  1536. return this.setFromMatrixColumn( index, matrix );
  1537. },
  1538. setFromMatrixPosition: function ( m ) {
  1539. this.x = m.elements[ 12 ];
  1540. this.y = m.elements[ 13 ];
  1541. this.z = m.elements[ 14 ];
  1542. return this;
  1543. },
  1544. setFromMatrixScale: function ( m ) {
  1545. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1546. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1547. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1548. this.x = sx;
  1549. this.y = sy;
  1550. this.z = sz;
  1551. return this;
  1552. },
  1553. setFromMatrixColumn: function ( index, matrix ) {
  1554. var offset = index * 4;
  1555. var me = matrix.elements;
  1556. this.x = me[ offset ];
  1557. this.y = me[ offset + 1 ];
  1558. this.z = me[ offset + 2 ];
  1559. return this;
  1560. },
  1561. equals: function ( v ) {
  1562. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1563. },
  1564. fromArray: function ( array, offset ) {
  1565. if ( offset === undefined ) offset = 0;
  1566. this.x = array[ offset ];
  1567. this.y = array[ offset + 1 ];
  1568. this.z = array[ offset + 2 ];
  1569. return this;
  1570. },
  1571. toArray: function ( array, offset ) {
  1572. if ( array === undefined ) array = [];
  1573. if ( offset === undefined ) offset = 0;
  1574. array[ offset ] = this.x;
  1575. array[ offset + 1 ] = this.y;
  1576. array[ offset + 2 ] = this.z;
  1577. return array;
  1578. },
  1579. fromAttribute: function ( attribute, index, offset ) {
  1580. if ( offset === undefined ) offset = 0;
  1581. index = index * attribute.itemSize + offset;
  1582. this.x = attribute.array[ index ];
  1583. this.y = attribute.array[ index + 1 ];
  1584. this.z = attribute.array[ index + 2 ];
  1585. return this;
  1586. }
  1587. };
  1588. // File:src/math/Vector4.js
  1589. /**
  1590. * @author supereggbert / http://www.paulbrunt.co.uk/
  1591. * @author philogb / http://blog.thejit.org/
  1592. * @author mikael emtinger / http://gomo.se/
  1593. * @author egraether / http://egraether.com/
  1594. * @author WestLangley / http://github.com/WestLangley
  1595. */
  1596. THREE.Vector4 = function ( x, y, z, w ) {
  1597. this.x = x || 0;
  1598. this.y = y || 0;
  1599. this.z = z || 0;
  1600. this.w = ( w !== undefined ) ? w : 1;
  1601. };
  1602. THREE.Vector4.prototype = {
  1603. constructor: THREE.Vector4,
  1604. set: function ( x, y, z, w ) {
  1605. this.x = x;
  1606. this.y = y;
  1607. this.z = z;
  1608. this.w = w;
  1609. return this;
  1610. },
  1611. setX: function ( x ) {
  1612. this.x = x;
  1613. return this;
  1614. },
  1615. setY: function ( y ) {
  1616. this.y = y;
  1617. return this;
  1618. },
  1619. setZ: function ( z ) {
  1620. this.z = z;
  1621. return this;
  1622. },
  1623. setW: function ( w ) {
  1624. this.w = w;
  1625. return this;
  1626. },
  1627. setComponent: function ( index, value ) {
  1628. switch ( index ) {
  1629. case 0: this.x = value; break;
  1630. case 1: this.y = value; break;
  1631. case 2: this.z = value; break;
  1632. case 3: this.w = value; break;
  1633. default: throw new Error( 'index is out of range: ' + index );
  1634. }
  1635. },
  1636. getComponent: function ( index ) {
  1637. switch ( index ) {
  1638. case 0: return this.x;
  1639. case 1: return this.y;
  1640. case 2: return this.z;
  1641. case 3: return this.w;
  1642. default: throw new Error( 'index is out of range: ' + index );
  1643. }
  1644. },
  1645. clone: function () {
  1646. return new this.constructor( this.x, this.y, this.z, this.w );
  1647. },
  1648. copy: function ( v ) {
  1649. this.x = v.x;
  1650. this.y = v.y;
  1651. this.z = v.z;
  1652. this.w = ( v.w !== undefined ) ? v.w : 1;
  1653. return this;
  1654. },
  1655. add: function ( v, w ) {
  1656. if ( w !== undefined ) {
  1657. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1658. return this.addVectors( v, w );
  1659. }
  1660. this.x += v.x;
  1661. this.y += v.y;
  1662. this.z += v.z;
  1663. this.w += v.w;
  1664. return this;
  1665. },
  1666. addScalar: function ( s ) {
  1667. this.x += s;
  1668. this.y += s;
  1669. this.z += s;
  1670. this.w += s;
  1671. return this;
  1672. },
  1673. addVectors: function ( a, b ) {
  1674. this.x = a.x + b.x;
  1675. this.y = a.y + b.y;
  1676. this.z = a.z + b.z;
  1677. this.w = a.w + b.w;
  1678. return this;
  1679. },
  1680. addScaledVector: function ( v, s ) {
  1681. this.x += v.x * s;
  1682. this.y += v.y * s;
  1683. this.z += v.z * s;
  1684. this.w += v.w * s;
  1685. return this;
  1686. },
  1687. sub: function ( v, w ) {
  1688. if ( w !== undefined ) {
  1689. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1690. return this.subVectors( v, w );
  1691. }
  1692. this.x -= v.x;
  1693. this.y -= v.y;
  1694. this.z -= v.z;
  1695. this.w -= v.w;
  1696. return this;
  1697. },
  1698. subScalar: function ( s ) {
  1699. this.x -= s;
  1700. this.y -= s;
  1701. this.z -= s;
  1702. this.w -= s;
  1703. return this;
  1704. },
  1705. subVectors: function ( a, b ) {
  1706. this.x = a.x - b.x;
  1707. this.y = a.y - b.y;
  1708. this.z = a.z - b.z;
  1709. this.w = a.w - b.w;
  1710. return this;
  1711. },
  1712. multiplyScalar: function ( scalar ) {
  1713. this.x *= scalar;
  1714. this.y *= scalar;
  1715. this.z *= scalar;
  1716. this.w *= scalar;
  1717. return this;
  1718. },
  1719. applyMatrix4: function ( m ) {
  1720. var x = this.x;
  1721. var y = this.y;
  1722. var z = this.z;
  1723. var w = this.w;
  1724. var e = m.elements;
  1725. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1726. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1727. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1728. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1729. return this;
  1730. },
  1731. divideScalar: function ( scalar ) {
  1732. if ( scalar !== 0 ) {
  1733. var invScalar = 1 / scalar;
  1734. this.x *= invScalar;
  1735. this.y *= invScalar;
  1736. this.z *= invScalar;
  1737. this.w *= invScalar;
  1738. } else {
  1739. this.x = 0;
  1740. this.y = 0;
  1741. this.z = 0;
  1742. this.w = 1;
  1743. }
  1744. return this;
  1745. },
  1746. setAxisAngleFromQuaternion: function ( q ) {
  1747. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1748. // q is assumed to be normalized
  1749. this.w = 2 * Math.acos( q.w );
  1750. var s = Math.sqrt( 1 - q.w * q.w );
  1751. if ( s < 0.0001 ) {
  1752. this.x = 1;
  1753. this.y = 0;
  1754. this.z = 0;
  1755. } else {
  1756. this.x = q.x / s;
  1757. this.y = q.y / s;
  1758. this.z = q.z / s;
  1759. }
  1760. return this;
  1761. },
  1762. setAxisAngleFromRotationMatrix: function ( m ) {
  1763. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1764. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1765. var angle, x, y, z, // variables for result
  1766. epsilon = 0.01, // margin to allow for rounding errors
  1767. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1768. te = m.elements,
  1769. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1770. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1771. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1772. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1773. && ( Math.abs( m13 - m31 ) < epsilon )
  1774. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1775. // singularity found
  1776. // first check for identity matrix which must have +1 for all terms
  1777. // in leading diagonal and zero in other terms
  1778. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1779. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1780. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1781. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1782. // this singularity is identity matrix so angle = 0
  1783. this.set( 1, 0, 0, 0 );
  1784. return this; // zero angle, arbitrary axis
  1785. }
  1786. // otherwise this singularity is angle = 180
  1787. angle = Math.PI;
  1788. var xx = ( m11 + 1 ) / 2;
  1789. var yy = ( m22 + 1 ) / 2;
  1790. var zz = ( m33 + 1 ) / 2;
  1791. var xy = ( m12 + m21 ) / 4;
  1792. var xz = ( m13 + m31 ) / 4;
  1793. var yz = ( m23 + m32 ) / 4;
  1794. if ( ( xx > yy ) && ( xx > zz ) ) {
  1795. // m11 is the largest diagonal term
  1796. if ( xx < epsilon ) {
  1797. x = 0;
  1798. y = 0.707106781;
  1799. z = 0.707106781;
  1800. } else {
  1801. x = Math.sqrt( xx );
  1802. y = xy / x;
  1803. z = xz / x;
  1804. }
  1805. } else if ( yy > zz ) {
  1806. // m22 is the largest diagonal term
  1807. if ( yy < epsilon ) {
  1808. x = 0.707106781;
  1809. y = 0;
  1810. z = 0.707106781;
  1811. } else {
  1812. y = Math.sqrt( yy );
  1813. x = xy / y;
  1814. z = yz / y;
  1815. }
  1816. } else {
  1817. // m33 is the largest diagonal term so base result on this
  1818. if ( zz < epsilon ) {
  1819. x = 0.707106781;
  1820. y = 0.707106781;
  1821. z = 0;
  1822. } else {
  1823. z = Math.sqrt( zz );
  1824. x = xz / z;
  1825. y = yz / z;
  1826. }
  1827. }
  1828. this.set( x, y, z, angle );
  1829. return this; // return 180 deg rotation
  1830. }
  1831. // as we have reached here there are no singularities so we can handle normally
  1832. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1833. + ( m13 - m31 ) * ( m13 - m31 )
  1834. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1835. if ( Math.abs( s ) < 0.001 ) s = 1;
  1836. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1837. // caught by singularity test above, but I've left it in just in case
  1838. this.x = ( m32 - m23 ) / s;
  1839. this.y = ( m13 - m31 ) / s;
  1840. this.z = ( m21 - m12 ) / s;
  1841. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1842. return this;
  1843. },
  1844. min: function ( v ) {
  1845. if ( this.x > v.x ) {
  1846. this.x = v.x;
  1847. }
  1848. if ( this.y > v.y ) {
  1849. this.y = v.y;
  1850. }
  1851. if ( this.z > v.z ) {
  1852. this.z = v.z;
  1853. }
  1854. if ( this.w > v.w ) {
  1855. this.w = v.w;
  1856. }
  1857. return this;
  1858. },
  1859. max: function ( v ) {
  1860. if ( this.x < v.x ) {
  1861. this.x = v.x;
  1862. }
  1863. if ( this.y < v.y ) {
  1864. this.y = v.y;
  1865. }
  1866. if ( this.z < v.z ) {
  1867. this.z = v.z;
  1868. }
  1869. if ( this.w < v.w ) {
  1870. this.w = v.w;
  1871. }
  1872. return this;
  1873. },
  1874. clamp: function ( min, max ) {
  1875. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1876. if ( this.x < min.x ) {
  1877. this.x = min.x;
  1878. } else if ( this.x > max.x ) {
  1879. this.x = max.x;
  1880. }
  1881. if ( this.y < min.y ) {
  1882. this.y = min.y;
  1883. } else if ( this.y > max.y ) {
  1884. this.y = max.y;
  1885. }
  1886. if ( this.z < min.z ) {
  1887. this.z = min.z;
  1888. } else if ( this.z > max.z ) {
  1889. this.z = max.z;
  1890. }
  1891. if ( this.w < min.w ) {
  1892. this.w = min.w;
  1893. } else if ( this.w > max.w ) {
  1894. this.w = max.w;
  1895. }
  1896. return this;
  1897. },
  1898. clampScalar: function () {
  1899. var min, max;
  1900. return function clampScalar( minVal, maxVal ) {
  1901. if ( min === undefined ) {
  1902. min = new THREE.Vector4();
  1903. max = new THREE.Vector4();
  1904. }
  1905. min.set( minVal, minVal, minVal, minVal );
  1906. max.set( maxVal, maxVal, maxVal, maxVal );
  1907. return this.clamp( min, max );
  1908. };
  1909. }(),
  1910. floor: function () {
  1911. this.x = Math.floor( this.x );
  1912. this.y = Math.floor( this.y );
  1913. this.z = Math.floor( this.z );
  1914. this.w = Math.floor( this.w );
  1915. return this;
  1916. },
  1917. ceil: function () {
  1918. this.x = Math.ceil( this.x );
  1919. this.y = Math.ceil( this.y );
  1920. this.z = Math.ceil( this.z );
  1921. this.w = Math.ceil( this.w );
  1922. return this;
  1923. },
  1924. round: function () {
  1925. this.x = Math.round( this.x );
  1926. this.y = Math.round( this.y );
  1927. this.z = Math.round( this.z );
  1928. this.w = Math.round( this.w );
  1929. return this;
  1930. },
  1931. roundToZero: function () {
  1932. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1933. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1934. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1935. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1936. return this;
  1937. },
  1938. negate: function () {
  1939. this.x = - this.x;
  1940. this.y = - this.y;
  1941. this.z = - this.z;
  1942. this.w = - this.w;
  1943. return this;
  1944. },
  1945. dot: function ( v ) {
  1946. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1947. },
  1948. lengthSq: function () {
  1949. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1950. },
  1951. length: function () {
  1952. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1953. },
  1954. lengthManhattan: function () {
  1955. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1956. },
  1957. normalize: function () {
  1958. return this.divideScalar( this.length() );
  1959. },
  1960. setLength: function ( l ) {
  1961. var oldLength = this.length();
  1962. if ( oldLength !== 0 && l !== oldLength ) {
  1963. this.multiplyScalar( l / oldLength );
  1964. }
  1965. return this;
  1966. },
  1967. lerp: function ( v, alpha ) {
  1968. this.x += ( v.x - this.x ) * alpha;
  1969. this.y += ( v.y - this.y ) * alpha;
  1970. this.z += ( v.z - this.z ) * alpha;
  1971. this.w += ( v.w - this.w ) * alpha;
  1972. return this;
  1973. },
  1974. lerpVectors: function ( v1, v2, alpha ) {
  1975. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1976. return this;
  1977. },
  1978. equals: function ( v ) {
  1979. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1980. },
  1981. fromArray: function ( array, offset ) {
  1982. if ( offset === undefined ) offset = 0;
  1983. this.x = array[ offset ];
  1984. this.y = array[ offset + 1 ];
  1985. this.z = array[ offset + 2 ];
  1986. this.w = array[ offset + 3 ];
  1987. return this;
  1988. },
  1989. toArray: function ( array, offset ) {
  1990. if ( array === undefined ) array = [];
  1991. if ( offset === undefined ) offset = 0;
  1992. array[ offset ] = this.x;
  1993. array[ offset + 1 ] = this.y;
  1994. array[ offset + 2 ] = this.z;
  1995. array[ offset + 3 ] = this.w;
  1996. return array;
  1997. },
  1998. fromAttribute: function ( attribute, index, offset ) {
  1999. if ( offset === undefined ) offset = 0;
  2000. index = index * attribute.itemSize + offset;
  2001. this.x = attribute.array[ index ];
  2002. this.y = attribute.array[ index + 1 ];
  2003. this.z = attribute.array[ index + 2 ];
  2004. this.w = attribute.array[ index + 3 ];
  2005. return this;
  2006. }
  2007. };
  2008. // File:src/math/Euler.js
  2009. /**
  2010. * @author mrdoob / http://mrdoob.com/
  2011. * @author WestLangley / http://github.com/WestLangley
  2012. * @author bhouston / http://clara.io
  2013. */
  2014. THREE.Euler = function ( x, y, z, order ) {
  2015. this._x = x || 0;
  2016. this._y = y || 0;
  2017. this._z = z || 0;
  2018. this._order = order || THREE.Euler.DefaultOrder;
  2019. };
  2020. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  2021. THREE.Euler.DefaultOrder = 'XYZ';
  2022. THREE.Euler.prototype = {
  2023. constructor: THREE.Euler,
  2024. get x () {
  2025. return this._x;
  2026. },
  2027. set x ( value ) {
  2028. this._x = value;
  2029. this.onChangeCallback();
  2030. },
  2031. get y () {
  2032. return this._y;
  2033. },
  2034. set y ( value ) {
  2035. this._y = value;
  2036. this.onChangeCallback();
  2037. },
  2038. get z () {
  2039. return this._z;
  2040. },
  2041. set z ( value ) {
  2042. this._z = value;
  2043. this.onChangeCallback();
  2044. },
  2045. get order () {
  2046. return this._order;
  2047. },
  2048. set order ( value ) {
  2049. this._order = value;
  2050. this.onChangeCallback();
  2051. },
  2052. set: function ( x, y, z, order ) {
  2053. this._x = x;
  2054. this._y = y;
  2055. this._z = z;
  2056. this._order = order || this._order;
  2057. this.onChangeCallback();
  2058. return this;
  2059. },
  2060. clone: function () {
  2061. return new this.constructor( this._x, this._y, this._z, this._order);
  2062. },
  2063. copy: function ( euler ) {
  2064. this._x = euler._x;
  2065. this._y = euler._y;
  2066. this._z = euler._z;
  2067. this._order = euler._order;
  2068. this.onChangeCallback();
  2069. return this;
  2070. },
  2071. setFromRotationMatrix: function ( m, order, update ) {
  2072. var clamp = THREE.Math.clamp;
  2073. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2074. var te = m.elements;
  2075. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2076. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2077. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2078. order = order || this._order;
  2079. if ( order === 'XYZ' ) {
  2080. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2081. if ( Math.abs( m13 ) < 0.99999 ) {
  2082. this._x = Math.atan2( - m23, m33 );
  2083. this._z = Math.atan2( - m12, m11 );
  2084. } else {
  2085. this._x = Math.atan2( m32, m22 );
  2086. this._z = 0;
  2087. }
  2088. } else if ( order === 'YXZ' ) {
  2089. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2090. if ( Math.abs( m23 ) < 0.99999 ) {
  2091. this._y = Math.atan2( m13, m33 );
  2092. this._z = Math.atan2( m21, m22 );
  2093. } else {
  2094. this._y = Math.atan2( - m31, m11 );
  2095. this._z = 0;
  2096. }
  2097. } else if ( order === 'ZXY' ) {
  2098. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2099. if ( Math.abs( m32 ) < 0.99999 ) {
  2100. this._y = Math.atan2( - m31, m33 );
  2101. this._z = Math.atan2( - m12, m22 );
  2102. } else {
  2103. this._y = 0;
  2104. this._z = Math.atan2( m21, m11 );
  2105. }
  2106. } else if ( order === 'ZYX' ) {
  2107. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2108. if ( Math.abs( m31 ) < 0.99999 ) {
  2109. this._x = Math.atan2( m32, m33 );
  2110. this._z = Math.atan2( m21, m11 );
  2111. } else {
  2112. this._x = 0;
  2113. this._z = Math.atan2( - m12, m22 );
  2114. }
  2115. } else if ( order === 'YZX' ) {
  2116. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2117. if ( Math.abs( m21 ) < 0.99999 ) {
  2118. this._x = Math.atan2( - m23, m22 );
  2119. this._y = Math.atan2( - m31, m11 );
  2120. } else {
  2121. this._x = 0;
  2122. this._y = Math.atan2( m13, m33 );
  2123. }
  2124. } else if ( order === 'XZY' ) {
  2125. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2126. if ( Math.abs( m12 ) < 0.99999 ) {
  2127. this._x = Math.atan2( m32, m22 );
  2128. this._y = Math.atan2( m13, m11 );
  2129. } else {
  2130. this._x = Math.atan2( - m23, m33 );
  2131. this._y = 0;
  2132. }
  2133. } else {
  2134. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2135. }
  2136. this._order = order;
  2137. if ( update !== false ) this.onChangeCallback();
  2138. return this;
  2139. },
  2140. setFromQuaternion: function () {
  2141. var matrix;
  2142. return function ( q, order, update ) {
  2143. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2144. matrix.makeRotationFromQuaternion( q );
  2145. this.setFromRotationMatrix( matrix, order, update );
  2146. return this;
  2147. };
  2148. }(),
  2149. setFromVector3: function ( v, order ) {
  2150. return this.set( v.x, v.y, v.z, order || this._order );
  2151. },
  2152. reorder: function () {
  2153. // WARNING: this discards revolution information -bhouston
  2154. var q = new THREE.Quaternion();
  2155. return function ( newOrder ) {
  2156. q.setFromEuler( this );
  2157. this.setFromQuaternion( q, newOrder );
  2158. };
  2159. }(),
  2160. equals: function ( euler ) {
  2161. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2162. },
  2163. fromArray: function ( array ) {
  2164. this._x = array[ 0 ];
  2165. this._y = array[ 1 ];
  2166. this._z = array[ 2 ];
  2167. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2168. this.onChangeCallback();
  2169. return this;
  2170. },
  2171. toArray: function ( array, offset ) {
  2172. if ( array === undefined ) array = [];
  2173. if ( offset === undefined ) offset = 0;
  2174. array[ offset ] = this._x;
  2175. array[ offset + 1 ] = this._y;
  2176. array[ offset + 2 ] = this._z;
  2177. array[ offset + 3 ] = this._order;
  2178. return array;
  2179. },
  2180. toVector3: function ( optionalResult ) {
  2181. if ( optionalResult ) {
  2182. return optionalResult.set( this._x, this._y, this._z );
  2183. } else {
  2184. return new THREE.Vector3( this._x, this._y, this._z );
  2185. }
  2186. },
  2187. onChange: function ( callback ) {
  2188. this.onChangeCallback = callback;
  2189. return this;
  2190. },
  2191. onChangeCallback: function () {}
  2192. };
  2193. // File:src/math/Line3.js
  2194. /**
  2195. * @author bhouston / http://clara.io
  2196. */
  2197. THREE.Line3 = function ( start, end ) {
  2198. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2199. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2200. };
  2201. THREE.Line3.prototype = {
  2202. constructor: THREE.Line3,
  2203. set: function ( start, end ) {
  2204. this.start.copy( start );
  2205. this.end.copy( end );
  2206. return this;
  2207. },
  2208. clone: function () {
  2209. return new this.constructor().copy( this );
  2210. },
  2211. copy: function ( line ) {
  2212. this.start.copy( line.start );
  2213. this.end.copy( line.end );
  2214. return this;
  2215. },
  2216. center: function ( optionalTarget ) {
  2217. var result = optionalTarget || new THREE.Vector3();
  2218. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2219. },
  2220. delta: function ( optionalTarget ) {
  2221. var result = optionalTarget || new THREE.Vector3();
  2222. return result.subVectors( this.end, this.start );
  2223. },
  2224. distanceSq: function () {
  2225. return this.start.distanceToSquared( this.end );
  2226. },
  2227. distance: function () {
  2228. return this.start.distanceTo( this.end );
  2229. },
  2230. at: function ( t, optionalTarget ) {
  2231. var result = optionalTarget || new THREE.Vector3();
  2232. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2233. },
  2234. closestPointToPointParameter: function () {
  2235. var startP = new THREE.Vector3();
  2236. var startEnd = new THREE.Vector3();
  2237. return function ( point, clampToLine ) {
  2238. startP.subVectors( point, this.start );
  2239. startEnd.subVectors( this.end, this.start );
  2240. var startEnd2 = startEnd.dot( startEnd );
  2241. var startEnd_startP = startEnd.dot( startP );
  2242. var t = startEnd_startP / startEnd2;
  2243. if ( clampToLine ) {
  2244. t = THREE.Math.clamp( t, 0, 1 );
  2245. }
  2246. return t;
  2247. };
  2248. }(),
  2249. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2250. var t = this.closestPointToPointParameter( point, clampToLine );
  2251. var result = optionalTarget || new THREE.Vector3();
  2252. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2253. },
  2254. applyMatrix4: function ( matrix ) {
  2255. this.start.applyMatrix4( matrix );
  2256. this.end.applyMatrix4( matrix );
  2257. return this;
  2258. },
  2259. equals: function ( line ) {
  2260. return line.start.equals( this.start ) && line.end.equals( this.end );
  2261. }
  2262. };
  2263. // File:src/math/Box2.js
  2264. /**
  2265. * @author bhouston / http://clara.io
  2266. */
  2267. THREE.Box2 = function ( min, max ) {
  2268. this.min = ( min !== undefined ) ? min : new THREE.Vector2( Infinity, Infinity );
  2269. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2270. };
  2271. THREE.Box2.prototype = {
  2272. constructor: THREE.Box2,
  2273. set: function ( min, max ) {
  2274. this.min.copy( min );
  2275. this.max.copy( max );
  2276. return this;
  2277. },
  2278. setFromPoints: function ( points ) {
  2279. this.makeEmpty();
  2280. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2281. this.expandByPoint( points[ i ] )
  2282. }
  2283. return this;
  2284. },
  2285. setFromCenterAndSize: function () {
  2286. var v1 = new THREE.Vector2();
  2287. return function ( center, size ) {
  2288. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2289. this.min.copy( center ).sub( halfSize );
  2290. this.max.copy( center ).add( halfSize );
  2291. return this;
  2292. };
  2293. }(),
  2294. clone: function () {
  2295. return new this.constructor().copy( this );
  2296. },
  2297. copy: function ( box ) {
  2298. this.min.copy( box.min );
  2299. this.max.copy( box.max );
  2300. return this;
  2301. },
  2302. makeEmpty: function () {
  2303. this.min.x = this.min.y = Infinity;
  2304. this.max.x = this.max.y = - Infinity;
  2305. return this;
  2306. },
  2307. empty: function () {
  2308. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2309. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2310. },
  2311. center: function ( optionalTarget ) {
  2312. var result = optionalTarget || new THREE.Vector2();
  2313. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2314. },
  2315. size: function ( optionalTarget ) {
  2316. var result = optionalTarget || new THREE.Vector2();
  2317. return result.subVectors( this.max, this.min );
  2318. },
  2319. expandByPoint: function ( point ) {
  2320. this.min.min( point );
  2321. this.max.max( point );
  2322. return this;
  2323. },
  2324. expandByVector: function ( vector ) {
  2325. this.min.sub( vector );
  2326. this.max.add( vector );
  2327. return this;
  2328. },
  2329. expandByScalar: function ( scalar ) {
  2330. this.min.addScalar( - scalar );
  2331. this.max.addScalar( scalar );
  2332. return this;
  2333. },
  2334. containsPoint: function ( point ) {
  2335. if ( point.x < this.min.x || point.x > this.max.x ||
  2336. point.y < this.min.y || point.y > this.max.y ) {
  2337. return false;
  2338. }
  2339. return true;
  2340. },
  2341. containsBox: function ( box ) {
  2342. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2343. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2344. return true;
  2345. }
  2346. return false;
  2347. },
  2348. getParameter: function ( point, optionalTarget ) {
  2349. // This can potentially have a divide by zero if the box
  2350. // has a size dimension of 0.
  2351. var result = optionalTarget || new THREE.Vector2();
  2352. return result.set(
  2353. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2354. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2355. );
  2356. },
  2357. isIntersectionBox: function ( box ) {
  2358. // using 6 splitting planes to rule out intersections.
  2359. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2360. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2361. return false;
  2362. }
  2363. return true;
  2364. },
  2365. clampPoint: function ( point, optionalTarget ) {
  2366. var result = optionalTarget || new THREE.Vector2();
  2367. return result.copy( point ).clamp( this.min, this.max );
  2368. },
  2369. distanceToPoint: function () {
  2370. var v1 = new THREE.Vector2();
  2371. return function ( point ) {
  2372. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2373. return clampedPoint.sub( point ).length();
  2374. };
  2375. }(),
  2376. intersect: function ( box ) {
  2377. this.min.max( box.min );
  2378. this.max.min( box.max );
  2379. return this;
  2380. },
  2381. union: function ( box ) {
  2382. this.min.min( box.min );
  2383. this.max.max( box.max );
  2384. return this;
  2385. },
  2386. translate: function ( offset ) {
  2387. this.min.add( offset );
  2388. this.max.add( offset );
  2389. return this;
  2390. },
  2391. equals: function ( box ) {
  2392. return box.min.equals( this.min ) && box.max.equals( this.max );
  2393. }
  2394. };
  2395. // File:src/math/Box3.js
  2396. /**
  2397. * @author bhouston / http://clara.io
  2398. * @author WestLangley / http://github.com/WestLangley
  2399. */
  2400. THREE.Box3 = function ( min, max ) {
  2401. this.min = ( min !== undefined ) ? min : new THREE.Vector3( Infinity, Infinity, Infinity );
  2402. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2403. };
  2404. THREE.Box3.prototype = {
  2405. constructor: THREE.Box3,
  2406. set: function ( min, max ) {
  2407. this.min.copy( min );
  2408. this.max.copy( max );
  2409. return this;
  2410. },
  2411. setFromPoints: function ( points ) {
  2412. this.makeEmpty();
  2413. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2414. this.expandByPoint( points[ i ] );
  2415. }
  2416. return this;
  2417. },
  2418. setFromCenterAndSize: function () {
  2419. var v1 = new THREE.Vector3();
  2420. return function ( center, size ) {
  2421. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2422. this.min.copy( center ).sub( halfSize );
  2423. this.max.copy( center ).add( halfSize );
  2424. return this;
  2425. };
  2426. }(),
  2427. setFromObject: function () {
  2428. // Computes the world-axis-aligned bounding box of an object (including its children),
  2429. // accounting for both the object's, and children's, world transforms
  2430. var v1 = new THREE.Vector3();
  2431. return function ( object ) {
  2432. var scope = this;
  2433. object.updateMatrixWorld( true );
  2434. this.makeEmpty();
  2435. object.traverse( function ( node ) {
  2436. var geometry = node.geometry;
  2437. if ( geometry !== undefined ) {
  2438. if ( geometry instanceof THREE.Geometry ) {
  2439. var vertices = geometry.vertices;
  2440. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  2441. v1.copy( vertices[ i ] );
  2442. v1.applyMatrix4( node.matrixWorld );
  2443. scope.expandByPoint( v1 );
  2444. }
  2445. } else if ( geometry instanceof THREE.BufferGeometry && geometry.attributes[ 'position' ] !== undefined ) {
  2446. var positions = geometry.attributes[ 'position' ].array;
  2447. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  2448. v1.set( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] );
  2449. v1.applyMatrix4( node.matrixWorld );
  2450. scope.expandByPoint( v1 );
  2451. }
  2452. }
  2453. }
  2454. } );
  2455. return this;
  2456. };
  2457. }(),
  2458. clone: function () {
  2459. return new this.constructor().copy( this );
  2460. },
  2461. copy: function ( box ) {
  2462. this.min.copy( box.min );
  2463. this.max.copy( box.max );
  2464. return this;
  2465. },
  2466. makeEmpty: function () {
  2467. this.min.x = this.min.y = this.min.z = Infinity;
  2468. this.max.x = this.max.y = this.max.z = - Infinity;
  2469. return this;
  2470. },
  2471. empty: function () {
  2472. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2473. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2474. },
  2475. center: function ( optionalTarget ) {
  2476. var result = optionalTarget || new THREE.Vector3();
  2477. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2478. },
  2479. size: function ( optionalTarget ) {
  2480. var result = optionalTarget || new THREE.Vector3();
  2481. return result.subVectors( this.max, this.min );
  2482. },
  2483. expandByPoint: function ( point ) {
  2484. this.min.min( point );
  2485. this.max.max( point );
  2486. return this;
  2487. },
  2488. expandByVector: function ( vector ) {
  2489. this.min.sub( vector );
  2490. this.max.add( vector );
  2491. return this;
  2492. },
  2493. expandByScalar: function ( scalar ) {
  2494. this.min.addScalar( - scalar );
  2495. this.max.addScalar( scalar );
  2496. return this;
  2497. },
  2498. containsPoint: function ( point ) {
  2499. if ( point.x < this.min.x || point.x > this.max.x ||
  2500. point.y < this.min.y || point.y > this.max.y ||
  2501. point.z < this.min.z || point.z > this.max.z ) {
  2502. return false;
  2503. }
  2504. return true;
  2505. },
  2506. containsBox: function ( box ) {
  2507. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2508. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2509. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2510. return true;
  2511. }
  2512. return false;
  2513. },
  2514. getParameter: function ( point, optionalTarget ) {
  2515. // This can potentially have a divide by zero if the box
  2516. // has a size dimension of 0.
  2517. var result = optionalTarget || new THREE.Vector3();
  2518. return result.set(
  2519. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2520. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2521. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2522. );
  2523. },
  2524. isIntersectionBox: function ( box ) {
  2525. // using 6 splitting planes to rule out intersections.
  2526. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2527. box.max.y < this.min.y || box.min.y > this.max.y ||
  2528. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2529. return false;
  2530. }
  2531. return true;
  2532. },
  2533. clampPoint: function ( point, optionalTarget ) {
  2534. var result = optionalTarget || new THREE.Vector3();
  2535. return result.copy( point ).clamp( this.min, this.max );
  2536. },
  2537. distanceToPoint: function () {
  2538. var v1 = new THREE.Vector3();
  2539. return function ( point ) {
  2540. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2541. return clampedPoint.sub( point ).length();
  2542. };
  2543. }(),
  2544. getBoundingSphere: function () {
  2545. var v1 = new THREE.Vector3();
  2546. return function ( optionalTarget ) {
  2547. var result = optionalTarget || new THREE.Sphere();
  2548. result.center = this.center();
  2549. result.radius = this.size( v1 ).length() * 0.5;
  2550. return result;
  2551. };
  2552. }(),
  2553. intersect: function ( box ) {
  2554. this.min.max( box.min );
  2555. this.max.min( box.max );
  2556. return this;
  2557. },
  2558. union: function ( box ) {
  2559. this.min.min( box.min );
  2560. this.max.max( box.max );
  2561. return this;
  2562. },
  2563. applyMatrix4: function () {
  2564. var points = [
  2565. new THREE.Vector3(),
  2566. new THREE.Vector3(),
  2567. new THREE.Vector3(),
  2568. new THREE.Vector3(),
  2569. new THREE.Vector3(),
  2570. new THREE.Vector3(),
  2571. new THREE.Vector3(),
  2572. new THREE.Vector3()
  2573. ];
  2574. return function ( matrix ) {
  2575. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2576. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2577. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2578. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2579. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2580. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2581. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2582. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2583. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2584. this.makeEmpty();
  2585. this.setFromPoints( points );
  2586. return this;
  2587. };
  2588. }(),
  2589. translate: function ( offset ) {
  2590. this.min.add( offset );
  2591. this.max.add( offset );
  2592. return this;
  2593. },
  2594. equals: function ( box ) {
  2595. return box.min.equals( this.min ) && box.max.equals( this.max );
  2596. }
  2597. };
  2598. // File:src/math/Matrix3.js
  2599. /**
  2600. * @author alteredq / http://alteredqualia.com/
  2601. * @author WestLangley / http://github.com/WestLangley
  2602. * @author bhouston / http://clara.io
  2603. */
  2604. THREE.Matrix3 = function () {
  2605. this.elements = new Float32Array( [
  2606. 1, 0, 0,
  2607. 0, 1, 0,
  2608. 0, 0, 1
  2609. ] );
  2610. if ( arguments.length > 0 ) {
  2611. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2612. }
  2613. };
  2614. THREE.Matrix3.prototype = {
  2615. constructor: THREE.Matrix3,
  2616. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2617. var te = this.elements;
  2618. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2619. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2620. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2621. return this;
  2622. },
  2623. identity: function () {
  2624. this.set(
  2625. 1, 0, 0,
  2626. 0, 1, 0,
  2627. 0, 0, 1
  2628. );
  2629. return this;
  2630. },
  2631. clone: function () {
  2632. return new this.constructor().fromArray( this.elements );
  2633. },
  2634. copy: function ( m ) {
  2635. var me = m.elements;
  2636. this.set(
  2637. me[ 0 ], me[ 3 ], me[ 6 ],
  2638. me[ 1 ], me[ 4 ], me[ 7 ],
  2639. me[ 2 ], me[ 5 ], me[ 8 ]
  2640. );
  2641. return this;
  2642. },
  2643. multiplyVector3: function ( vector ) {
  2644. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  2645. return vector.applyMatrix3( this );
  2646. },
  2647. multiplyVector3Array: function ( a ) {
  2648. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  2649. return this.applyToVector3Array( a );
  2650. },
  2651. applyToVector3Array: function () {
  2652. var v1;
  2653. return function ( array, offset, length ) {
  2654. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2655. if ( offset === undefined ) offset = 0;
  2656. if ( length === undefined ) length = array.length;
  2657. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2658. v1.fromArray( array, j );
  2659. v1.applyMatrix3( this );
  2660. v1.toArray( array, j );
  2661. }
  2662. return array;
  2663. };
  2664. }(),
  2665. applyToBuffer: function () {
  2666. var v1;
  2667. return function applyToBuffer( buffer, offset, length ) {
  2668. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2669. if ( offset === undefined ) offset = 0;
  2670. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2671. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2672. v1.x = buffer.getX( j );
  2673. v1.y = buffer.getY( j );
  2674. v1.z = buffer.getZ( j );
  2675. v1.applyMatrix3( this );
  2676. buffer.setXYZ( v1.x, v1.y, v1.z );
  2677. }
  2678. return buffer;
  2679. };
  2680. }(),
  2681. multiplyScalar: function ( s ) {
  2682. var te = this.elements;
  2683. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2684. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2685. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2686. return this;
  2687. },
  2688. determinant: function () {
  2689. var te = this.elements;
  2690. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2691. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2692. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2693. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2694. },
  2695. getInverse: function ( matrix, throwOnInvertible ) {
  2696. // input: THREE.Matrix4
  2697. // ( based on http://code.google.com/p/webgl-mjs/ )
  2698. var me = matrix.elements;
  2699. var te = this.elements;
  2700. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2701. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2702. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2703. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2704. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2705. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2706. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2707. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2708. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2709. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2710. // no inverse
  2711. if ( det === 0 ) {
  2712. var msg = "Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2713. if ( throwOnInvertible || false ) {
  2714. throw new Error( msg );
  2715. } else {
  2716. console.warn( msg );
  2717. }
  2718. this.identity();
  2719. return this;
  2720. }
  2721. this.multiplyScalar( 1.0 / det );
  2722. return this;
  2723. },
  2724. transpose: function () {
  2725. var tmp, m = this.elements;
  2726. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2727. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2728. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2729. return this;
  2730. },
  2731. flattenToArrayOffset: function ( array, offset ) {
  2732. var te = this.elements;
  2733. array[ offset ] = te[ 0 ];
  2734. array[ offset + 1 ] = te[ 1 ];
  2735. array[ offset + 2 ] = te[ 2 ];
  2736. array[ offset + 3 ] = te[ 3 ];
  2737. array[ offset + 4 ] = te[ 4 ];
  2738. array[ offset + 5 ] = te[ 5 ];
  2739. array[ offset + 6 ] = te[ 6 ];
  2740. array[ offset + 7 ] = te[ 7 ];
  2741. array[ offset + 8 ] = te[ 8 ];
  2742. return array;
  2743. },
  2744. getNormalMatrix: function ( m ) {
  2745. // input: THREE.Matrix4
  2746. this.getInverse( m ).transpose();
  2747. return this;
  2748. },
  2749. transposeIntoArray: function ( r ) {
  2750. var m = this.elements;
  2751. r[ 0 ] = m[ 0 ];
  2752. r[ 1 ] = m[ 3 ];
  2753. r[ 2 ] = m[ 6 ];
  2754. r[ 3 ] = m[ 1 ];
  2755. r[ 4 ] = m[ 4 ];
  2756. r[ 5 ] = m[ 7 ];
  2757. r[ 6 ] = m[ 2 ];
  2758. r[ 7 ] = m[ 5 ];
  2759. r[ 8 ] = m[ 8 ];
  2760. return this;
  2761. },
  2762. fromArray: function ( array ) {
  2763. this.elements.set( array );
  2764. return this;
  2765. },
  2766. toArray: function () {
  2767. var te = this.elements;
  2768. return [
  2769. te[ 0 ], te[ 1 ], te[ 2 ],
  2770. te[ 3 ], te[ 4 ], te[ 5 ],
  2771. te[ 6 ], te[ 7 ], te[ 8 ]
  2772. ];
  2773. }
  2774. };
  2775. // File:src/math/Matrix4.js
  2776. /**
  2777. * @author mrdoob / http://mrdoob.com/
  2778. * @author supereggbert / http://www.paulbrunt.co.uk/
  2779. * @author philogb / http://blog.thejit.org/
  2780. * @author jordi_ros / http://plattsoft.com
  2781. * @author D1plo1d / http://github.com/D1plo1d
  2782. * @author alteredq / http://alteredqualia.com/
  2783. * @author mikael emtinger / http://gomo.se/
  2784. * @author timknip / http://www.floorplanner.com/
  2785. * @author bhouston / http://clara.io
  2786. * @author WestLangley / http://github.com/WestLangley
  2787. */
  2788. THREE.Matrix4 = function () {
  2789. this.elements = new Float32Array( [
  2790. 1, 0, 0, 0,
  2791. 0, 1, 0, 0,
  2792. 0, 0, 1, 0,
  2793. 0, 0, 0, 1
  2794. ] );
  2795. if ( arguments.length > 0 ) {
  2796. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2797. }
  2798. };
  2799. THREE.Matrix4.prototype = {
  2800. constructor: THREE.Matrix4,
  2801. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2802. var te = this.elements;
  2803. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2804. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2805. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2806. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2807. return this;
  2808. },
  2809. identity: function () {
  2810. this.set(
  2811. 1, 0, 0, 0,
  2812. 0, 1, 0, 0,
  2813. 0, 0, 1, 0,
  2814. 0, 0, 0, 1
  2815. );
  2816. return this;
  2817. },
  2818. clone: function () {
  2819. return new THREE.Matrix4().fromArray( this.elements );
  2820. },
  2821. copy: function ( m ) {
  2822. this.elements.set( m.elements );
  2823. return this;
  2824. },
  2825. extractPosition: function ( m ) {
  2826. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  2827. return this.copyPosition( m );
  2828. },
  2829. copyPosition: function ( m ) {
  2830. var te = this.elements;
  2831. var me = m.elements;
  2832. te[ 12 ] = me[ 12 ];
  2833. te[ 13 ] = me[ 13 ];
  2834. te[ 14 ] = me[ 14 ];
  2835. return this;
  2836. },
  2837. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2838. var te = this.elements;
  2839. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2840. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2841. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2842. return this;
  2843. },
  2844. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2845. this.set(
  2846. xAxis.x, yAxis.x, zAxis.x, 0,
  2847. xAxis.y, yAxis.y, zAxis.y, 0,
  2848. xAxis.z, yAxis.z, zAxis.z, 0,
  2849. 0, 0, 0, 1
  2850. );
  2851. return this;
  2852. },
  2853. extractRotation: function () {
  2854. var v1;
  2855. return function ( m ) {
  2856. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2857. var te = this.elements;
  2858. var me = m.elements;
  2859. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2860. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2861. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2862. te[ 0 ] = me[ 0 ] * scaleX;
  2863. te[ 1 ] = me[ 1 ] * scaleX;
  2864. te[ 2 ] = me[ 2 ] * scaleX;
  2865. te[ 4 ] = me[ 4 ] * scaleY;
  2866. te[ 5 ] = me[ 5 ] * scaleY;
  2867. te[ 6 ] = me[ 6 ] * scaleY;
  2868. te[ 8 ] = me[ 8 ] * scaleZ;
  2869. te[ 9 ] = me[ 9 ] * scaleZ;
  2870. te[ 10 ] = me[ 10 ] * scaleZ;
  2871. return this;
  2872. };
  2873. }(),
  2874. makeRotationFromEuler: function ( euler ) {
  2875. if ( euler instanceof THREE.Euler === false ) {
  2876. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2877. }
  2878. var te = this.elements;
  2879. var x = euler.x, y = euler.y, z = euler.z;
  2880. var a = Math.cos( x ), b = Math.sin( x );
  2881. var c = Math.cos( y ), d = Math.sin( y );
  2882. var e = Math.cos( z ), f = Math.sin( z );
  2883. if ( euler.order === 'XYZ' ) {
  2884. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2885. te[ 0 ] = c * e;
  2886. te[ 4 ] = - c * f;
  2887. te[ 8 ] = d;
  2888. te[ 1 ] = af + be * d;
  2889. te[ 5 ] = ae - bf * d;
  2890. te[ 9 ] = - b * c;
  2891. te[ 2 ] = bf - ae * d;
  2892. te[ 6 ] = be + af * d;
  2893. te[ 10 ] = a * c;
  2894. } else if ( euler.order === 'YXZ' ) {
  2895. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2896. te[ 0 ] = ce + df * b;
  2897. te[ 4 ] = de * b - cf;
  2898. te[ 8 ] = a * d;
  2899. te[ 1 ] = a * f;
  2900. te[ 5 ] = a * e;
  2901. te[ 9 ] = - b;
  2902. te[ 2 ] = cf * b - de;
  2903. te[ 6 ] = df + ce * b;
  2904. te[ 10 ] = a * c;
  2905. } else if ( euler.order === 'ZXY' ) {
  2906. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2907. te[ 0 ] = ce - df * b;
  2908. te[ 4 ] = - a * f;
  2909. te[ 8 ] = de + cf * b;
  2910. te[ 1 ] = cf + de * b;
  2911. te[ 5 ] = a * e;
  2912. te[ 9 ] = df - ce * b;
  2913. te[ 2 ] = - a * d;
  2914. te[ 6 ] = b;
  2915. te[ 10 ] = a * c;
  2916. } else if ( euler.order === 'ZYX' ) {
  2917. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2918. te[ 0 ] = c * e;
  2919. te[ 4 ] = be * d - af;
  2920. te[ 8 ] = ae * d + bf;
  2921. te[ 1 ] = c * f;
  2922. te[ 5 ] = bf * d + ae;
  2923. te[ 9 ] = af * d - be;
  2924. te[ 2 ] = - d;
  2925. te[ 6 ] = b * c;
  2926. te[ 10 ] = a * c;
  2927. } else if ( euler.order === 'YZX' ) {
  2928. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2929. te[ 0 ] = c * e;
  2930. te[ 4 ] = bd - ac * f;
  2931. te[ 8 ] = bc * f + ad;
  2932. te[ 1 ] = f;
  2933. te[ 5 ] = a * e;
  2934. te[ 9 ] = - b * e;
  2935. te[ 2 ] = - d * e;
  2936. te[ 6 ] = ad * f + bc;
  2937. te[ 10 ] = ac - bd * f;
  2938. } else if ( euler.order === 'XZY' ) {
  2939. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2940. te[ 0 ] = c * e;
  2941. te[ 4 ] = - f;
  2942. te[ 8 ] = d * e;
  2943. te[ 1 ] = ac * f + bd;
  2944. te[ 5 ] = a * e;
  2945. te[ 9 ] = ad * f - bc;
  2946. te[ 2 ] = bc * f - ad;
  2947. te[ 6 ] = b * e;
  2948. te[ 10 ] = bd * f + ac;
  2949. }
  2950. // last column
  2951. te[ 3 ] = 0;
  2952. te[ 7 ] = 0;
  2953. te[ 11 ] = 0;
  2954. // bottom row
  2955. te[ 12 ] = 0;
  2956. te[ 13 ] = 0;
  2957. te[ 14 ] = 0;
  2958. te[ 15 ] = 1;
  2959. return this;
  2960. },
  2961. setRotationFromQuaternion: function ( q ) {
  2962. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  2963. return this.makeRotationFromQuaternion( q );
  2964. },
  2965. makeRotationFromQuaternion: function ( q ) {
  2966. var te = this.elements;
  2967. var x = q.x, y = q.y, z = q.z, w = q.w;
  2968. var x2 = x + x, y2 = y + y, z2 = z + z;
  2969. var xx = x * x2, xy = x * y2, xz = x * z2;
  2970. var yy = y * y2, yz = y * z2, zz = z * z2;
  2971. var wx = w * x2, wy = w * y2, wz = w * z2;
  2972. te[ 0 ] = 1 - ( yy + zz );
  2973. te[ 4 ] = xy - wz;
  2974. te[ 8 ] = xz + wy;
  2975. te[ 1 ] = xy + wz;
  2976. te[ 5 ] = 1 - ( xx + zz );
  2977. te[ 9 ] = yz - wx;
  2978. te[ 2 ] = xz - wy;
  2979. te[ 6 ] = yz + wx;
  2980. te[ 10 ] = 1 - ( xx + yy );
  2981. // last column
  2982. te[ 3 ] = 0;
  2983. te[ 7 ] = 0;
  2984. te[ 11 ] = 0;
  2985. // bottom row
  2986. te[ 12 ] = 0;
  2987. te[ 13 ] = 0;
  2988. te[ 14 ] = 0;
  2989. te[ 15 ] = 1;
  2990. return this;
  2991. },
  2992. lookAt: function () {
  2993. var x, y, z;
  2994. return function ( eye, target, up ) {
  2995. if ( x === undefined ) x = new THREE.Vector3();
  2996. if ( y === undefined ) y = new THREE.Vector3();
  2997. if ( z === undefined ) z = new THREE.Vector3();
  2998. var te = this.elements;
  2999. z.subVectors( eye, target ).normalize();
  3000. if ( z.length() === 0 ) {
  3001. z.z = 1;
  3002. }
  3003. x.crossVectors( up, z ).normalize();
  3004. if ( x.length() === 0 ) {
  3005. z.x += 0.0001;
  3006. x.crossVectors( up, z ).normalize();
  3007. }
  3008. y.crossVectors( z, x );
  3009. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  3010. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  3011. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  3012. return this;
  3013. };
  3014. }(),
  3015. multiply: function ( m, n ) {
  3016. if ( n !== undefined ) {
  3017. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  3018. return this.multiplyMatrices( m, n );
  3019. }
  3020. return this.multiplyMatrices( this, m );
  3021. },
  3022. multiplyMatrices: function ( a, b ) {
  3023. var ae = a.elements;
  3024. var be = b.elements;
  3025. var te = this.elements;
  3026. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3027. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3028. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3029. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3030. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3031. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3032. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3033. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3034. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3035. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3036. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3037. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3038. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3039. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3040. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3041. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3042. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3043. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3044. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3045. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3046. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3047. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3048. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3049. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3050. return this;
  3051. },
  3052. multiplyToArray: function ( a, b, r ) {
  3053. var te = this.elements;
  3054. this.multiplyMatrices( a, b );
  3055. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3056. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3057. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3058. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3059. return this;
  3060. },
  3061. multiplyScalar: function ( s ) {
  3062. var te = this.elements;
  3063. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3064. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3065. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3066. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3067. return this;
  3068. },
  3069. multiplyVector3: function ( vector ) {
  3070. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  3071. return vector.applyProjection( this );
  3072. },
  3073. multiplyVector4: function ( vector ) {
  3074. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3075. return vector.applyMatrix4( this );
  3076. },
  3077. multiplyVector3Array: function ( a ) {
  3078. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  3079. return this.applyToVector3Array( a );
  3080. },
  3081. applyToVector3Array: function () {
  3082. var v1;
  3083. return function ( array, offset, length ) {
  3084. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3085. if ( offset === undefined ) offset = 0;
  3086. if ( length === undefined ) length = array.length;
  3087. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3088. v1.fromArray( array, j );
  3089. v1.applyMatrix4( this );
  3090. v1.toArray( array, j );
  3091. }
  3092. return array;
  3093. };
  3094. }(),
  3095. applyToBuffer: function () {
  3096. var v1;
  3097. return function applyToBuffer( buffer, offset, length ) {
  3098. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3099. if ( offset === undefined ) offset = 0;
  3100. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3101. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3102. v1.x = buffer.getX( j );
  3103. v1.y = buffer.getY( j );
  3104. v1.z = buffer.getZ( j );
  3105. v1.applyMatrix4( this );
  3106. buffer.setXYZ( v1.x, v1.y, v1.z );
  3107. }
  3108. return buffer;
  3109. };
  3110. }(),
  3111. rotateAxis: function ( v ) {
  3112. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  3113. v.transformDirection( this );
  3114. },
  3115. crossVector: function ( vector ) {
  3116. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  3117. return vector.applyMatrix4( this );
  3118. },
  3119. determinant: function () {
  3120. var te = this.elements;
  3121. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3122. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3123. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3124. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3125. //TODO: make this more efficient
  3126. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3127. return (
  3128. n41 * (
  3129. + n14 * n23 * n32
  3130. - n13 * n24 * n32
  3131. - n14 * n22 * n33
  3132. + n12 * n24 * n33
  3133. + n13 * n22 * n34
  3134. - n12 * n23 * n34
  3135. ) +
  3136. n42 * (
  3137. + n11 * n23 * n34
  3138. - n11 * n24 * n33
  3139. + n14 * n21 * n33
  3140. - n13 * n21 * n34
  3141. + n13 * n24 * n31
  3142. - n14 * n23 * n31
  3143. ) +
  3144. n43 * (
  3145. + n11 * n24 * n32
  3146. - n11 * n22 * n34
  3147. - n14 * n21 * n32
  3148. + n12 * n21 * n34
  3149. + n14 * n22 * n31
  3150. - n12 * n24 * n31
  3151. ) +
  3152. n44 * (
  3153. - n13 * n22 * n31
  3154. - n11 * n23 * n32
  3155. + n11 * n22 * n33
  3156. + n13 * n21 * n32
  3157. - n12 * n21 * n33
  3158. + n12 * n23 * n31
  3159. )
  3160. );
  3161. },
  3162. transpose: function () {
  3163. var te = this.elements;
  3164. var tmp;
  3165. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3166. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3167. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3168. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3169. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3170. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3171. return this;
  3172. },
  3173. flattenToArrayOffset: function ( array, offset ) {
  3174. var te = this.elements;
  3175. array[ offset ] = te[ 0 ];
  3176. array[ offset + 1 ] = te[ 1 ];
  3177. array[ offset + 2 ] = te[ 2 ];
  3178. array[ offset + 3 ] = te[ 3 ];
  3179. array[ offset + 4 ] = te[ 4 ];
  3180. array[ offset + 5 ] = te[ 5 ];
  3181. array[ offset + 6 ] = te[ 6 ];
  3182. array[ offset + 7 ] = te[ 7 ];
  3183. array[ offset + 8 ] = te[ 8 ];
  3184. array[ offset + 9 ] = te[ 9 ];
  3185. array[ offset + 10 ] = te[ 10 ];
  3186. array[ offset + 11 ] = te[ 11 ];
  3187. array[ offset + 12 ] = te[ 12 ];
  3188. array[ offset + 13 ] = te[ 13 ];
  3189. array[ offset + 14 ] = te[ 14 ];
  3190. array[ offset + 15 ] = te[ 15 ];
  3191. return array;
  3192. },
  3193. getPosition: function () {
  3194. var v1;
  3195. return function () {
  3196. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3197. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3198. var te = this.elements;
  3199. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3200. };
  3201. }(),
  3202. setPosition: function ( v ) {
  3203. var te = this.elements;
  3204. te[ 12 ] = v.x;
  3205. te[ 13 ] = v.y;
  3206. te[ 14 ] = v.z;
  3207. return this;
  3208. },
  3209. getInverse: function ( m, throwOnInvertible ) {
  3210. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3211. var te = this.elements;
  3212. var me = m.elements;
  3213. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3214. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3215. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3216. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3217. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3218. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3219. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3220. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3221. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3222. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3223. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3224. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3225. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3226. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3227. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3228. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3229. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3230. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3231. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3232. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3233. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3234. if ( det === 0 ) {
  3235. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3236. if ( throwOnInvertible || false ) {
  3237. throw new Error( msg );
  3238. } else {
  3239. console.warn( msg );
  3240. }
  3241. this.identity();
  3242. return this;
  3243. }
  3244. this.multiplyScalar( 1 / det );
  3245. return this;
  3246. },
  3247. translate: function ( v ) {
  3248. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  3249. },
  3250. rotateX: function ( angle ) {
  3251. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  3252. },
  3253. rotateY: function ( angle ) {
  3254. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  3255. },
  3256. rotateZ: function ( angle ) {
  3257. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  3258. },
  3259. rotateByAxis: function ( axis, angle ) {
  3260. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  3261. },
  3262. scale: function ( v ) {
  3263. var te = this.elements;
  3264. var x = v.x, y = v.y, z = v.z;
  3265. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3266. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3267. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3268. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3269. return this;
  3270. },
  3271. getMaxScaleOnAxis: function () {
  3272. var te = this.elements;
  3273. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3274. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3275. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3276. return Math.sqrt( Math.max( scaleXSq, Math.max( scaleYSq, scaleZSq ) ) );
  3277. },
  3278. makeTranslation: function ( x, y, z ) {
  3279. this.set(
  3280. 1, 0, 0, x,
  3281. 0, 1, 0, y,
  3282. 0, 0, 1, z,
  3283. 0, 0, 0, 1
  3284. );
  3285. return this;
  3286. },
  3287. makeRotationX: function ( theta ) {
  3288. var c = Math.cos( theta ), s = Math.sin( theta );
  3289. this.set(
  3290. 1, 0, 0, 0,
  3291. 0, c, - s, 0,
  3292. 0, s, c, 0,
  3293. 0, 0, 0, 1
  3294. );
  3295. return this;
  3296. },
  3297. makeRotationY: function ( theta ) {
  3298. var c = Math.cos( theta ), s = Math.sin( theta );
  3299. this.set(
  3300. c, 0, s, 0,
  3301. 0, 1, 0, 0,
  3302. - s, 0, c, 0,
  3303. 0, 0, 0, 1
  3304. );
  3305. return this;
  3306. },
  3307. makeRotationZ: function ( theta ) {
  3308. var c = Math.cos( theta ), s = Math.sin( theta );
  3309. this.set(
  3310. c, - s, 0, 0,
  3311. s, c, 0, 0,
  3312. 0, 0, 1, 0,
  3313. 0, 0, 0, 1
  3314. );
  3315. return this;
  3316. },
  3317. makeRotationAxis: function ( axis, angle ) {
  3318. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3319. var c = Math.cos( angle );
  3320. var s = Math.sin( angle );
  3321. var t = 1 - c;
  3322. var x = axis.x, y = axis.y, z = axis.z;
  3323. var tx = t * x, ty = t * y;
  3324. this.set(
  3325. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3326. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3327. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3328. 0, 0, 0, 1
  3329. );
  3330. return this;
  3331. },
  3332. makeScale: function ( x, y, z ) {
  3333. this.set(
  3334. x, 0, 0, 0,
  3335. 0, y, 0, 0,
  3336. 0, 0, z, 0,
  3337. 0, 0, 0, 1
  3338. );
  3339. return this;
  3340. },
  3341. compose: function ( position, quaternion, scale ) {
  3342. this.makeRotationFromQuaternion( quaternion );
  3343. this.scale( scale );
  3344. this.setPosition( position );
  3345. return this;
  3346. },
  3347. decompose: function () {
  3348. var vector, matrix;
  3349. return function ( position, quaternion, scale ) {
  3350. if ( vector === undefined ) vector = new THREE.Vector3();
  3351. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3352. var te = this.elements;
  3353. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3354. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3355. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3356. // if determine is negative, we need to invert one scale
  3357. var det = this.determinant();
  3358. if ( det < 0 ) {
  3359. sx = - sx;
  3360. }
  3361. position.x = te[ 12 ];
  3362. position.y = te[ 13 ];
  3363. position.z = te[ 14 ];
  3364. // scale the rotation part
  3365. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3366. var invSX = 1 / sx;
  3367. var invSY = 1 / sy;
  3368. var invSZ = 1 / sz;
  3369. matrix.elements[ 0 ] *= invSX;
  3370. matrix.elements[ 1 ] *= invSX;
  3371. matrix.elements[ 2 ] *= invSX;
  3372. matrix.elements[ 4 ] *= invSY;
  3373. matrix.elements[ 5 ] *= invSY;
  3374. matrix.elements[ 6 ] *= invSY;
  3375. matrix.elements[ 8 ] *= invSZ;
  3376. matrix.elements[ 9 ] *= invSZ;
  3377. matrix.elements[ 10 ] *= invSZ;
  3378. quaternion.setFromRotationMatrix( matrix );
  3379. scale.x = sx;
  3380. scale.y = sy;
  3381. scale.z = sz;
  3382. return this;
  3383. };
  3384. }(),
  3385. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3386. var te = this.elements;
  3387. var x = 2 * near / ( right - left );
  3388. var y = 2 * near / ( top - bottom );
  3389. var a = ( right + left ) / ( right - left );
  3390. var b = ( top + bottom ) / ( top - bottom );
  3391. var c = - ( far + near ) / ( far - near );
  3392. var d = - 2 * far * near / ( far - near );
  3393. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3394. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3395. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3396. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3397. return this;
  3398. },
  3399. makePerspective: function ( fov, aspect, near, far ) {
  3400. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3401. var ymin = - ymax;
  3402. var xmin = ymin * aspect;
  3403. var xmax = ymax * aspect;
  3404. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3405. },
  3406. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3407. var te = this.elements;
  3408. var w = right - left;
  3409. var h = top - bottom;
  3410. var p = far - near;
  3411. var x = ( right + left ) / w;
  3412. var y = ( top + bottom ) / h;
  3413. var z = ( far + near ) / p;
  3414. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3415. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3416. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3417. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3418. return this;
  3419. },
  3420. equals: function ( matrix ) {
  3421. var te = this.elements;
  3422. var me = matrix.elements;
  3423. for ( var i = 0; i < 16; i ++ ) {
  3424. if ( te[ i ] !== me[ i ] ) return false;
  3425. }
  3426. return true;
  3427. },
  3428. fromArray: function ( array ) {
  3429. this.elements.set( array );
  3430. return this;
  3431. },
  3432. toArray: function () {
  3433. var te = this.elements;
  3434. return [
  3435. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3436. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3437. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3438. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3439. ];
  3440. }
  3441. };
  3442. // File:src/math/Ray.js
  3443. /**
  3444. * @author bhouston / http://clara.io
  3445. */
  3446. THREE.Ray = function ( origin, direction ) {
  3447. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3448. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3449. };
  3450. THREE.Ray.prototype = {
  3451. constructor: THREE.Ray,
  3452. set: function ( origin, direction ) {
  3453. this.origin.copy( origin );
  3454. this.direction.copy( direction );
  3455. return this;
  3456. },
  3457. clone: function () {
  3458. return new this.constructor().copy( this );
  3459. },
  3460. copy: function ( ray ) {
  3461. this.origin.copy( ray.origin );
  3462. this.direction.copy( ray.direction );
  3463. return this;
  3464. },
  3465. at: function ( t, optionalTarget ) {
  3466. var result = optionalTarget || new THREE.Vector3();
  3467. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3468. },
  3469. recast: function () {
  3470. var v1 = new THREE.Vector3();
  3471. return function ( t ) {
  3472. this.origin.copy( this.at( t, v1 ) );
  3473. return this;
  3474. };
  3475. }(),
  3476. closestPointToPoint: function ( point, optionalTarget ) {
  3477. var result = optionalTarget || new THREE.Vector3();
  3478. result.subVectors( point, this.origin );
  3479. var directionDistance = result.dot( this.direction );
  3480. if ( directionDistance < 0 ) {
  3481. return result.copy( this.origin );
  3482. }
  3483. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3484. },
  3485. distanceToPoint: function ( point ) {
  3486. return Math.sqrt( this.distanceSqToPoint( point ) );
  3487. },
  3488. distanceSqToPoint: function () {
  3489. var v1 = new THREE.Vector3();
  3490. return function ( point ) {
  3491. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3492. // point behind the ray
  3493. if ( directionDistance < 0 ) {
  3494. return this.origin.distanceToSquared( point );
  3495. }
  3496. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3497. return v1.distanceToSquared( point );
  3498. };
  3499. }(),
  3500. distanceSqToSegment: function () {
  3501. var segCenter = new THREE.Vector3();
  3502. var segDir = new THREE.Vector3();
  3503. var diff = new THREE.Vector3();
  3504. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3505. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3506. // It returns the min distance between the ray and the segment
  3507. // defined by v0 and v1
  3508. // It can also set two optional targets :
  3509. // - The closest point on the ray
  3510. // - The closest point on the segment
  3511. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3512. segDir.copy( v1 ).sub( v0 ).normalize();
  3513. diff.copy( this.origin ).sub( segCenter );
  3514. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3515. var a01 = - this.direction.dot( segDir );
  3516. var b0 = diff.dot( this.direction );
  3517. var b1 = - diff.dot( segDir );
  3518. var c = diff.lengthSq();
  3519. var det = Math.abs( 1 - a01 * a01 );
  3520. var s0, s1, sqrDist, extDet;
  3521. if ( det > 0 ) {
  3522. // The ray and segment are not parallel.
  3523. s0 = a01 * b1 - b0;
  3524. s1 = a01 * b0 - b1;
  3525. extDet = segExtent * det;
  3526. if ( s0 >= 0 ) {
  3527. if ( s1 >= - extDet ) {
  3528. if ( s1 <= extDet ) {
  3529. // region 0
  3530. // Minimum at interior points of ray and segment.
  3531. var invDet = 1 / det;
  3532. s0 *= invDet;
  3533. s1 *= invDet;
  3534. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3535. } else {
  3536. // region 1
  3537. s1 = segExtent;
  3538. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3539. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3540. }
  3541. } else {
  3542. // region 5
  3543. s1 = - segExtent;
  3544. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3545. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3546. }
  3547. } else {
  3548. if ( s1 <= - extDet ) {
  3549. // region 4
  3550. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3551. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3552. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3553. } else if ( s1 <= extDet ) {
  3554. // region 3
  3555. s0 = 0;
  3556. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3557. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3558. } else {
  3559. // region 2
  3560. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3561. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3562. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3563. }
  3564. }
  3565. } else {
  3566. // Ray and segment are parallel.
  3567. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3568. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3569. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3570. }
  3571. if ( optionalPointOnRay ) {
  3572. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3573. }
  3574. if ( optionalPointOnSegment ) {
  3575. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3576. }
  3577. return sqrDist;
  3578. };
  3579. }(),
  3580. isIntersectionSphere: function ( sphere ) {
  3581. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3582. },
  3583. intersectSphere: function () {
  3584. // from http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-sphere-intersection/
  3585. var v1 = new THREE.Vector3();
  3586. return function ( sphere, optionalTarget ) {
  3587. v1.subVectors( sphere.center, this.origin );
  3588. var tca = v1.dot( this.direction );
  3589. var d2 = v1.dot( v1 ) - tca * tca;
  3590. var radius2 = sphere.radius * sphere.radius;
  3591. if ( d2 > radius2 ) return null;
  3592. var thc = Math.sqrt( radius2 - d2 );
  3593. // t0 = first intersect point - entrance on front of sphere
  3594. var t0 = tca - thc;
  3595. // t1 = second intersect point - exit point on back of sphere
  3596. var t1 = tca + thc;
  3597. // test to see if both t0 and t1 are behind the ray - if so, return null
  3598. if ( t0 < 0 && t1 < 0 ) return null;
  3599. // test to see if t0 is behind the ray:
  3600. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3601. // in order to always return an intersect point that is in front of the ray.
  3602. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3603. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3604. return this.at( t0, optionalTarget );
  3605. }
  3606. }(),
  3607. isIntersectionPlane: function ( plane ) {
  3608. // check if the ray lies on the plane first
  3609. var distToPoint = plane.distanceToPoint( this.origin );
  3610. if ( distToPoint === 0 ) {
  3611. return true;
  3612. }
  3613. var denominator = plane.normal.dot( this.direction );
  3614. if ( denominator * distToPoint < 0 ) {
  3615. return true;
  3616. }
  3617. // ray origin is behind the plane (and is pointing behind it)
  3618. return false;
  3619. },
  3620. distanceToPlane: function ( plane ) {
  3621. var denominator = plane.normal.dot( this.direction );
  3622. if ( denominator === 0 ) {
  3623. // line is coplanar, return origin
  3624. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3625. return 0;
  3626. }
  3627. // Null is preferable to undefined since undefined means.... it is undefined
  3628. return null;
  3629. }
  3630. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3631. // Return if the ray never intersects the plane
  3632. return t >= 0 ? t : null;
  3633. },
  3634. intersectPlane: function ( plane, optionalTarget ) {
  3635. var t = this.distanceToPlane( plane );
  3636. if ( t === null ) {
  3637. return null;
  3638. }
  3639. return this.at( t, optionalTarget );
  3640. },
  3641. isIntersectionBox: function () {
  3642. var v = new THREE.Vector3();
  3643. return function ( box ) {
  3644. return this.intersectBox( box, v ) !== null;
  3645. };
  3646. }(),
  3647. intersectBox: function ( box, optionalTarget ) {
  3648. // http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-7-intersecting-simple-shapes/ray-box-intersection/
  3649. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3650. var invdirx = 1 / this.direction.x,
  3651. invdiry = 1 / this.direction.y,
  3652. invdirz = 1 / this.direction.z;
  3653. var origin = this.origin;
  3654. if ( invdirx >= 0 ) {
  3655. tmin = ( box.min.x - origin.x ) * invdirx;
  3656. tmax = ( box.max.x - origin.x ) * invdirx;
  3657. } else {
  3658. tmin = ( box.max.x - origin.x ) * invdirx;
  3659. tmax = ( box.min.x - origin.x ) * invdirx;
  3660. }
  3661. if ( invdiry >= 0 ) {
  3662. tymin = ( box.min.y - origin.y ) * invdiry;
  3663. tymax = ( box.max.y - origin.y ) * invdiry;
  3664. } else {
  3665. tymin = ( box.max.y - origin.y ) * invdiry;
  3666. tymax = ( box.min.y - origin.y ) * invdiry;
  3667. }
  3668. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3669. // These lines also handle the case where tmin or tmax is NaN
  3670. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3671. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3672. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3673. if ( invdirz >= 0 ) {
  3674. tzmin = ( box.min.z - origin.z ) * invdirz;
  3675. tzmax = ( box.max.z - origin.z ) * invdirz;
  3676. } else {
  3677. tzmin = ( box.max.z - origin.z ) * invdirz;
  3678. tzmax = ( box.min.z - origin.z ) * invdirz;
  3679. }
  3680. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3681. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3682. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3683. //return point closest to the ray (positive side)
  3684. if ( tmax < 0 ) return null;
  3685. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3686. },
  3687. intersectTriangle: function () {
  3688. // Compute the offset origin, edges, and normal.
  3689. var diff = new THREE.Vector3();
  3690. var edge1 = new THREE.Vector3();
  3691. var edge2 = new THREE.Vector3();
  3692. var normal = new THREE.Vector3();
  3693. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3694. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3695. edge1.subVectors( b, a );
  3696. edge2.subVectors( c, a );
  3697. normal.crossVectors( edge1, edge2 );
  3698. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3699. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3700. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3701. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3702. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3703. var DdN = this.direction.dot( normal );
  3704. var sign;
  3705. if ( DdN > 0 ) {
  3706. if ( backfaceCulling ) return null;
  3707. sign = 1;
  3708. } else if ( DdN < 0 ) {
  3709. sign = - 1;
  3710. DdN = - DdN;
  3711. } else {
  3712. return null;
  3713. }
  3714. diff.subVectors( this.origin, a );
  3715. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3716. // b1 < 0, no intersection
  3717. if ( DdQxE2 < 0 ) {
  3718. return null;
  3719. }
  3720. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3721. // b2 < 0, no intersection
  3722. if ( DdE1xQ < 0 ) {
  3723. return null;
  3724. }
  3725. // b1+b2 > 1, no intersection
  3726. if ( DdQxE2 + DdE1xQ > DdN ) {
  3727. return null;
  3728. }
  3729. // Line intersects triangle, check if ray does.
  3730. var QdN = - sign * diff.dot( normal );
  3731. // t < 0, no intersection
  3732. if ( QdN < 0 ) {
  3733. return null;
  3734. }
  3735. // Ray intersects triangle.
  3736. return this.at( QdN / DdN, optionalTarget );
  3737. };
  3738. }(),
  3739. applyMatrix4: function ( matrix4 ) {
  3740. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3741. this.origin.applyMatrix4( matrix4 );
  3742. this.direction.sub( this.origin );
  3743. this.direction.normalize();
  3744. return this;
  3745. },
  3746. equals: function ( ray ) {
  3747. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3748. }
  3749. };
  3750. // File:src/math/Sphere.js
  3751. /**
  3752. * @author bhouston / http://clara.io
  3753. * @author mrdoob / http://mrdoob.com/
  3754. */
  3755. THREE.Sphere = function ( center, radius ) {
  3756. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3757. this.radius = ( radius !== undefined ) ? radius : 0;
  3758. };
  3759. THREE.Sphere.prototype = {
  3760. constructor: THREE.Sphere,
  3761. set: function ( center, radius ) {
  3762. this.center.copy( center );
  3763. this.radius = radius;
  3764. return this;
  3765. },
  3766. setFromPoints: function () {
  3767. var box = new THREE.Box3();
  3768. return function ( points, optionalCenter ) {
  3769. var center = this.center;
  3770. if ( optionalCenter !== undefined ) {
  3771. center.copy( optionalCenter );
  3772. } else {
  3773. box.setFromPoints( points ).center( center );
  3774. }
  3775. var maxRadiusSq = 0;
  3776. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3777. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3778. }
  3779. this.radius = Math.sqrt( maxRadiusSq );
  3780. return this;
  3781. };
  3782. }(),
  3783. clone: function () {
  3784. return new this.constructor().copy( this );
  3785. },
  3786. copy: function ( sphere ) {
  3787. this.center.copy( sphere.center );
  3788. this.radius = sphere.radius;
  3789. return this;
  3790. },
  3791. empty: function () {
  3792. return ( this.radius <= 0 );
  3793. },
  3794. containsPoint: function ( point ) {
  3795. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3796. },
  3797. distanceToPoint: function ( point ) {
  3798. return ( point.distanceTo( this.center ) - this.radius );
  3799. },
  3800. intersectsSphere: function ( sphere ) {
  3801. var radiusSum = this.radius + sphere.radius;
  3802. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3803. },
  3804. clampPoint: function ( point, optionalTarget ) {
  3805. var deltaLengthSq = this.center.distanceToSquared( point );
  3806. var result = optionalTarget || new THREE.Vector3();
  3807. result.copy( point );
  3808. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3809. result.sub( this.center ).normalize();
  3810. result.multiplyScalar( this.radius ).add( this.center );
  3811. }
  3812. return result;
  3813. },
  3814. getBoundingBox: function ( optionalTarget ) {
  3815. var box = optionalTarget || new THREE.Box3();
  3816. box.set( this.center, this.center );
  3817. box.expandByScalar( this.radius );
  3818. return box;
  3819. },
  3820. applyMatrix4: function ( matrix ) {
  3821. this.center.applyMatrix4( matrix );
  3822. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3823. return this;
  3824. },
  3825. translate: function ( offset ) {
  3826. this.center.add( offset );
  3827. return this;
  3828. },
  3829. equals: function ( sphere ) {
  3830. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3831. }
  3832. };
  3833. // File:src/math/Frustum.js
  3834. /**
  3835. * @author mrdoob / http://mrdoob.com/
  3836. * @author alteredq / http://alteredqualia.com/
  3837. * @author bhouston / http://clara.io
  3838. */
  3839. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3840. this.planes = [
  3841. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3842. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3843. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3844. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3845. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3846. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3847. ];
  3848. };
  3849. THREE.Frustum.prototype = {
  3850. constructor: THREE.Frustum,
  3851. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3852. var planes = this.planes;
  3853. planes[ 0 ].copy( p0 );
  3854. planes[ 1 ].copy( p1 );
  3855. planes[ 2 ].copy( p2 );
  3856. planes[ 3 ].copy( p3 );
  3857. planes[ 4 ].copy( p4 );
  3858. planes[ 5 ].copy( p5 );
  3859. return this;
  3860. },
  3861. clone: function () {
  3862. return new this.constructor().copy( this );
  3863. },
  3864. copy: function ( frustum ) {
  3865. var planes = this.planes;
  3866. for ( var i = 0; i < 6; i ++ ) {
  3867. planes[ i ].copy( frustum.planes[ i ] );
  3868. }
  3869. return this;
  3870. },
  3871. setFromMatrix: function ( m ) {
  3872. var planes = this.planes;
  3873. var me = m.elements;
  3874. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3875. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3876. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3877. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3878. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3879. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3880. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3881. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3882. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3883. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3884. return this;
  3885. },
  3886. intersectsObject: function () {
  3887. var sphere = new THREE.Sphere();
  3888. return function ( object ) {
  3889. var geometry = object.geometry;
  3890. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3891. sphere.copy( geometry.boundingSphere );
  3892. sphere.applyMatrix4( object.matrixWorld );
  3893. return this.intersectsSphere( sphere );
  3894. };
  3895. }(),
  3896. intersectsSphere: function ( sphere ) {
  3897. var planes = this.planes;
  3898. var center = sphere.center;
  3899. var negRadius = - sphere.radius;
  3900. for ( var i = 0; i < 6; i ++ ) {
  3901. var distance = planes[ i ].distanceToPoint( center );
  3902. if ( distance < negRadius ) {
  3903. return false;
  3904. }
  3905. }
  3906. return true;
  3907. },
  3908. intersectsBox: function () {
  3909. var p1 = new THREE.Vector3(),
  3910. p2 = new THREE.Vector3();
  3911. return function ( box ) {
  3912. var planes = this.planes;
  3913. for ( var i = 0; i < 6 ; i ++ ) {
  3914. var plane = planes[ i ];
  3915. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3916. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3917. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3918. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3919. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3920. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3921. var d1 = plane.distanceToPoint( p1 );
  3922. var d2 = plane.distanceToPoint( p2 );
  3923. // if both outside plane, no intersection
  3924. if ( d1 < 0 && d2 < 0 ) {
  3925. return false;
  3926. }
  3927. }
  3928. return true;
  3929. };
  3930. }(),
  3931. containsPoint: function ( point ) {
  3932. var planes = this.planes;
  3933. for ( var i = 0; i < 6; i ++ ) {
  3934. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3935. return false;
  3936. }
  3937. }
  3938. return true;
  3939. }
  3940. };
  3941. // File:src/math/Plane.js
  3942. /**
  3943. * @author bhouston / http://clara.io
  3944. */
  3945. THREE.Plane = function ( normal, constant ) {
  3946. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3947. this.constant = ( constant !== undefined ) ? constant : 0;
  3948. };
  3949. THREE.Plane.prototype = {
  3950. constructor: THREE.Plane,
  3951. set: function ( normal, constant ) {
  3952. this.normal.copy( normal );
  3953. this.constant = constant;
  3954. return this;
  3955. },
  3956. setComponents: function ( x, y, z, w ) {
  3957. this.normal.set( x, y, z );
  3958. this.constant = w;
  3959. return this;
  3960. },
  3961. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3962. this.normal.copy( normal );
  3963. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3964. return this;
  3965. },
  3966. setFromCoplanarPoints: function () {
  3967. var v1 = new THREE.Vector3();
  3968. var v2 = new THREE.Vector3();
  3969. return function ( a, b, c ) {
  3970. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3971. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3972. this.setFromNormalAndCoplanarPoint( normal, a );
  3973. return this;
  3974. };
  3975. }(),
  3976. clone: function () {
  3977. return new this.constructor().copy( this );
  3978. },
  3979. copy: function ( plane ) {
  3980. this.normal.copy( plane.normal );
  3981. this.constant = plane.constant;
  3982. return this;
  3983. },
  3984. normalize: function () {
  3985. // Note: will lead to a divide by zero if the plane is invalid.
  3986. var inverseNormalLength = 1.0 / this.normal.length();
  3987. this.normal.multiplyScalar( inverseNormalLength );
  3988. this.constant *= inverseNormalLength;
  3989. return this;
  3990. },
  3991. negate: function () {
  3992. this.constant *= - 1;
  3993. this.normal.negate();
  3994. return this;
  3995. },
  3996. distanceToPoint: function ( point ) {
  3997. return this.normal.dot( point ) + this.constant;
  3998. },
  3999. distanceToSphere: function ( sphere ) {
  4000. return this.distanceToPoint( sphere.center ) - sphere.radius;
  4001. },
  4002. projectPoint: function ( point, optionalTarget ) {
  4003. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  4004. },
  4005. orthoPoint: function ( point, optionalTarget ) {
  4006. var perpendicularMagnitude = this.distanceToPoint( point );
  4007. var result = optionalTarget || new THREE.Vector3();
  4008. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  4009. },
  4010. isIntersectionLine: function ( line ) {
  4011. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  4012. var startSign = this.distanceToPoint( line.start );
  4013. var endSign = this.distanceToPoint( line.end );
  4014. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  4015. },
  4016. intersectLine: function () {
  4017. var v1 = new THREE.Vector3();
  4018. return function ( line, optionalTarget ) {
  4019. var result = optionalTarget || new THREE.Vector3();
  4020. var direction = line.delta( v1 );
  4021. var denominator = this.normal.dot( direction );
  4022. if ( denominator === 0 ) {
  4023. // line is coplanar, return origin
  4024. if ( this.distanceToPoint( line.start ) === 0 ) {
  4025. return result.copy( line.start );
  4026. }
  4027. // Unsure if this is the correct method to handle this case.
  4028. return undefined;
  4029. }
  4030. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  4031. if ( t < 0 || t > 1 ) {
  4032. return undefined;
  4033. }
  4034. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  4035. };
  4036. }(),
  4037. coplanarPoint: function ( optionalTarget ) {
  4038. var result = optionalTarget || new THREE.Vector3();
  4039. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4040. },
  4041. applyMatrix4: function () {
  4042. var v1 = new THREE.Vector3();
  4043. var v2 = new THREE.Vector3();
  4044. var m1 = new THREE.Matrix3();
  4045. return function ( matrix, optionalNormalMatrix ) {
  4046. // compute new normal based on theory here:
  4047. // http://www.songho.ca/opengl/gl_normaltransform.html
  4048. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4049. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4050. var newCoplanarPoint = this.coplanarPoint( v2 );
  4051. newCoplanarPoint.applyMatrix4( matrix );
  4052. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4053. return this;
  4054. };
  4055. }(),
  4056. translate: function ( offset ) {
  4057. this.constant = this.constant - offset.dot( this.normal );
  4058. return this;
  4059. },
  4060. equals: function ( plane ) {
  4061. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4062. }
  4063. };
  4064. // File:src/math/Math.js
  4065. /**
  4066. * @author alteredq / http://alteredqualia.com/
  4067. * @author mrdoob / http://mrdoob.com/
  4068. */
  4069. THREE.Math = {
  4070. generateUUID: function () {
  4071. // http://www.broofa.com/Tools/Math.uuid.htm
  4072. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4073. var uuid = new Array( 36 );
  4074. var rnd = 0, r;
  4075. return function () {
  4076. for ( var i = 0; i < 36; i ++ ) {
  4077. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4078. uuid[ i ] = '-';
  4079. } else if ( i === 14 ) {
  4080. uuid[ i ] = '4';
  4081. } else {
  4082. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4083. r = rnd & 0xf;
  4084. rnd = rnd >> 4;
  4085. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4086. }
  4087. }
  4088. return uuid.join( '' );
  4089. };
  4090. }(),
  4091. // Clamp value to range <a, b>
  4092. clamp: function ( x, a, b ) {
  4093. return ( x < a ) ? a : ( ( x > b ) ? b : x );
  4094. },
  4095. // Clamp value to range <a, inf)
  4096. clampBottom: function ( x, a ) {
  4097. return x < a ? a : x;
  4098. },
  4099. // compute euclidian modulo of m % n
  4100. // https://en.wikipedia.org/wiki/Modulo_operation
  4101. euclideanModulo: function ( n, m ) {
  4102. return ( ( n % m ) + m ) % m;
  4103. },
  4104. // Linear mapping from range <a1, a2> to range <b1, b2>
  4105. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4106. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4107. },
  4108. // http://en.wikipedia.org/wiki/Smoothstep
  4109. smoothstep: function ( x, min, max ) {
  4110. if ( x <= min ) return 0;
  4111. if ( x >= max ) return 1;
  4112. x = ( x - min ) / ( max - min );
  4113. return x * x * ( 3 - 2 * x );
  4114. },
  4115. smootherstep: function ( x, min, max ) {
  4116. if ( x <= min ) return 0;
  4117. if ( x >= max ) return 1;
  4118. x = ( x - min ) / ( max - min );
  4119. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4120. },
  4121. // Random float from <0, 1> with 16 bits of randomness
  4122. // (standard Math.random() creates repetitive patterns when applied over larger space)
  4123. random16: function () {
  4124. return ( 65280 * Math.random() + 255 * Math.random() ) / 65535;
  4125. },
  4126. // Random integer from <low, high> interval
  4127. randInt: function ( low, high ) {
  4128. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4129. },
  4130. // Random float from <low, high> interval
  4131. randFloat: function ( low, high ) {
  4132. return low + Math.random() * ( high - low );
  4133. },
  4134. // Random float from <-range/2, range/2> interval
  4135. randFloatSpread: function ( range ) {
  4136. return range * ( 0.5 - Math.random() );
  4137. },
  4138. degToRad: function () {
  4139. var degreeToRadiansFactor = Math.PI / 180;
  4140. return function ( degrees ) {
  4141. return degrees * degreeToRadiansFactor;
  4142. };
  4143. }(),
  4144. radToDeg: function () {
  4145. var radianToDegreesFactor = 180 / Math.PI;
  4146. return function ( radians ) {
  4147. return radians * radianToDegreesFactor;
  4148. };
  4149. }(),
  4150. isPowerOfTwo: function ( value ) {
  4151. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4152. },
  4153. nextPowerOfTwo: function ( value ) {
  4154. value --;
  4155. value |= value >> 1;
  4156. value |= value >> 2;
  4157. value |= value >> 4;
  4158. value |= value >> 8;
  4159. value |= value >> 16;
  4160. value ++;
  4161. return value;
  4162. }
  4163. };
  4164. // File:src/math/Spline.js
  4165. /**
  4166. * Spline from Tween.js, slightly optimized (and trashed)
  4167. * http://sole.github.com/tween.js/examples/05_spline.html
  4168. *
  4169. * @author mrdoob / http://mrdoob.com/
  4170. * @author alteredq / http://alteredqualia.com/
  4171. */
  4172. THREE.Spline = function ( points ) {
  4173. this.points = points;
  4174. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4175. point, intPoint, weight, w2, w3,
  4176. pa, pb, pc, pd;
  4177. this.initFromArray = function ( a ) {
  4178. this.points = [];
  4179. for ( var i = 0; i < a.length; i ++ ) {
  4180. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4181. }
  4182. };
  4183. this.getPoint = function ( k ) {
  4184. point = ( this.points.length - 1 ) * k;
  4185. intPoint = Math.floor( point );
  4186. weight = point - intPoint;
  4187. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4188. c[ 1 ] = intPoint;
  4189. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4190. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4191. pa = this.points[ c[ 0 ] ];
  4192. pb = this.points[ c[ 1 ] ];
  4193. pc = this.points[ c[ 2 ] ];
  4194. pd = this.points[ c[ 3 ] ];
  4195. w2 = weight * weight;
  4196. w3 = weight * w2;
  4197. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4198. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4199. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4200. return v3;
  4201. };
  4202. this.getControlPointsArray = function () {
  4203. var i, p, l = this.points.length,
  4204. coords = [];
  4205. for ( i = 0; i < l; i ++ ) {
  4206. p = this.points[ i ];
  4207. coords[ i ] = [ p.x, p.y, p.z ];
  4208. }
  4209. return coords;
  4210. };
  4211. // approximate length by summing linear segments
  4212. this.getLength = function ( nSubDivisions ) {
  4213. var i, index, nSamples, position,
  4214. point = 0, intPoint = 0, oldIntPoint = 0,
  4215. oldPosition = new THREE.Vector3(),
  4216. tmpVec = new THREE.Vector3(),
  4217. chunkLengths = [],
  4218. totalLength = 0;
  4219. // first point has 0 length
  4220. chunkLengths[ 0 ] = 0;
  4221. if ( ! nSubDivisions ) nSubDivisions = 100;
  4222. nSamples = this.points.length * nSubDivisions;
  4223. oldPosition.copy( this.points[ 0 ] );
  4224. for ( i = 1; i < nSamples; i ++ ) {
  4225. index = i / nSamples;
  4226. position = this.getPoint( index );
  4227. tmpVec.copy( position );
  4228. totalLength += tmpVec.distanceTo( oldPosition );
  4229. oldPosition.copy( position );
  4230. point = ( this.points.length - 1 ) * index;
  4231. intPoint = Math.floor( point );
  4232. if ( intPoint !== oldIntPoint ) {
  4233. chunkLengths[ intPoint ] = totalLength;
  4234. oldIntPoint = intPoint;
  4235. }
  4236. }
  4237. // last point ends with total length
  4238. chunkLengths[ chunkLengths.length ] = totalLength;
  4239. return { chunks: chunkLengths, total: totalLength };
  4240. };
  4241. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4242. var i, j,
  4243. index, indexCurrent, indexNext,
  4244. realDistance,
  4245. sampling, position,
  4246. newpoints = [],
  4247. tmpVec = new THREE.Vector3(),
  4248. sl = this.getLength();
  4249. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4250. for ( i = 1; i < this.points.length; i ++ ) {
  4251. //tmpVec.copy( this.points[ i - 1 ] );
  4252. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4253. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4254. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4255. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4256. indexNext = i / ( this.points.length - 1 );
  4257. for ( j = 1; j < sampling - 1; j ++ ) {
  4258. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4259. position = this.getPoint( index );
  4260. newpoints.push( tmpVec.copy( position ).clone() );
  4261. }
  4262. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4263. }
  4264. this.points = newpoints;
  4265. };
  4266. // Catmull-Rom
  4267. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4268. var v0 = ( p2 - p0 ) * 0.5,
  4269. v1 = ( p3 - p1 ) * 0.5;
  4270. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4271. }
  4272. };
  4273. // File:src/math/Triangle.js
  4274. /**
  4275. * @author bhouston / http://clara.io
  4276. * @author mrdoob / http://mrdoob.com/
  4277. */
  4278. THREE.Triangle = function ( a, b, c ) {
  4279. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4280. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4281. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4282. };
  4283. THREE.Triangle.normal = function () {
  4284. var v0 = new THREE.Vector3();
  4285. return function ( a, b, c, optionalTarget ) {
  4286. var result = optionalTarget || new THREE.Vector3();
  4287. result.subVectors( c, b );
  4288. v0.subVectors( a, b );
  4289. result.cross( v0 );
  4290. var resultLengthSq = result.lengthSq();
  4291. if ( resultLengthSq > 0 ) {
  4292. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4293. }
  4294. return result.set( 0, 0, 0 );
  4295. };
  4296. }();
  4297. // static/instance method to calculate barycentric coordinates
  4298. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4299. THREE.Triangle.barycoordFromPoint = function () {
  4300. var v0 = new THREE.Vector3();
  4301. var v1 = new THREE.Vector3();
  4302. var v2 = new THREE.Vector3();
  4303. return function ( point, a, b, c, optionalTarget ) {
  4304. v0.subVectors( c, a );
  4305. v1.subVectors( b, a );
  4306. v2.subVectors( point, a );
  4307. var dot00 = v0.dot( v0 );
  4308. var dot01 = v0.dot( v1 );
  4309. var dot02 = v0.dot( v2 );
  4310. var dot11 = v1.dot( v1 );
  4311. var dot12 = v1.dot( v2 );
  4312. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4313. var result = optionalTarget || new THREE.Vector3();
  4314. // collinear or singular triangle
  4315. if ( denom === 0 ) {
  4316. // arbitrary location outside of triangle?
  4317. // not sure if this is the best idea, maybe should be returning undefined
  4318. return result.set( - 2, - 1, - 1 );
  4319. }
  4320. var invDenom = 1 / denom;
  4321. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4322. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4323. // barycentric coordinates must always sum to 1
  4324. return result.set( 1 - u - v, v, u );
  4325. };
  4326. }();
  4327. THREE.Triangle.containsPoint = function () {
  4328. var v1 = new THREE.Vector3();
  4329. return function ( point, a, b, c ) {
  4330. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4331. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4332. };
  4333. }();
  4334. THREE.Triangle.prototype = {
  4335. constructor: THREE.Triangle,
  4336. set: function ( a, b, c ) {
  4337. this.a.copy( a );
  4338. this.b.copy( b );
  4339. this.c.copy( c );
  4340. return this;
  4341. },
  4342. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4343. this.a.copy( points[ i0 ] );
  4344. this.b.copy( points[ i1 ] );
  4345. this.c.copy( points[ i2 ] );
  4346. return this;
  4347. },
  4348. clone: function () {
  4349. return new this.constructor().copy( this );
  4350. },
  4351. copy: function ( triangle ) {
  4352. this.a.copy( triangle.a );
  4353. this.b.copy( triangle.b );
  4354. this.c.copy( triangle.c );
  4355. return this;
  4356. },
  4357. area: function () {
  4358. var v0 = new THREE.Vector3();
  4359. var v1 = new THREE.Vector3();
  4360. return function () {
  4361. v0.subVectors( this.c, this.b );
  4362. v1.subVectors( this.a, this.b );
  4363. return v0.cross( v1 ).length() * 0.5;
  4364. };
  4365. }(),
  4366. midpoint: function ( optionalTarget ) {
  4367. var result = optionalTarget || new THREE.Vector3();
  4368. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4369. },
  4370. normal: function ( optionalTarget ) {
  4371. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4372. },
  4373. plane: function ( optionalTarget ) {
  4374. var result = optionalTarget || new THREE.Plane();
  4375. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4376. },
  4377. barycoordFromPoint: function ( point, optionalTarget ) {
  4378. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4379. },
  4380. containsPoint: function ( point ) {
  4381. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4382. },
  4383. equals: function ( triangle ) {
  4384. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4385. }
  4386. };
  4387. // File:src/core/Clock.js
  4388. /**
  4389. * @author alteredq / http://alteredqualia.com/
  4390. */
  4391. THREE.Clock = function ( autoStart ) {
  4392. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4393. this.startTime = 0;
  4394. this.oldTime = 0;
  4395. this.elapsedTime = 0;
  4396. this.running = false;
  4397. };
  4398. THREE.Clock.prototype = {
  4399. constructor: THREE.Clock,
  4400. start: function () {
  4401. this.startTime = self.performance.now();
  4402. this.oldTime = this.startTime;
  4403. this.running = true;
  4404. },
  4405. stop: function () {
  4406. this.getElapsedTime();
  4407. this.running = false;
  4408. },
  4409. getElapsedTime: function () {
  4410. this.getDelta();
  4411. return this.elapsedTime;
  4412. },
  4413. getDelta: function () {
  4414. var diff = 0;
  4415. if ( this.autoStart && ! this.running ) {
  4416. this.start();
  4417. }
  4418. if ( this.running ) {
  4419. var newTime = self.performance.now();
  4420. diff = 0.001 * ( newTime - this.oldTime );
  4421. this.oldTime = newTime;
  4422. this.elapsedTime += diff;
  4423. }
  4424. return diff;
  4425. }
  4426. };
  4427. // File:src/core/EventDispatcher.js
  4428. /**
  4429. * https://github.com/mrdoob/eventdispatcher.js/
  4430. */
  4431. THREE.EventDispatcher = function () {};
  4432. THREE.EventDispatcher.prototype = {
  4433. constructor: THREE.EventDispatcher,
  4434. apply: function ( object ) {
  4435. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4436. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4437. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4438. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4439. },
  4440. addEventListener: function ( type, listener ) {
  4441. if ( this._listeners === undefined ) this._listeners = {};
  4442. var listeners = this._listeners;
  4443. if ( listeners[ type ] === undefined ) {
  4444. listeners[ type ] = [];
  4445. }
  4446. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4447. listeners[ type ].push( listener );
  4448. }
  4449. },
  4450. hasEventListener: function ( type, listener ) {
  4451. if ( this._listeners === undefined ) return false;
  4452. var listeners = this._listeners;
  4453. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4454. return true;
  4455. }
  4456. return false;
  4457. },
  4458. removeEventListener: function ( type, listener ) {
  4459. if ( this._listeners === undefined ) return;
  4460. var listeners = this._listeners;
  4461. var listenerArray = listeners[ type ];
  4462. if ( listenerArray !== undefined ) {
  4463. var index = listenerArray.indexOf( listener );
  4464. if ( index !== - 1 ) {
  4465. listenerArray.splice( index, 1 );
  4466. }
  4467. }
  4468. },
  4469. dispatchEvent: function ( event ) {
  4470. if ( this._listeners === undefined ) return;
  4471. var listeners = this._listeners;
  4472. var listenerArray = listeners[ event.type ];
  4473. if ( listenerArray !== undefined ) {
  4474. event.target = this;
  4475. var array = [];
  4476. var length = listenerArray.length;
  4477. for ( var i = 0; i < length; i ++ ) {
  4478. array[ i ] = listenerArray[ i ];
  4479. }
  4480. for ( var i = 0; i < length; i ++ ) {
  4481. array[ i ].call( this, event );
  4482. }
  4483. }
  4484. }
  4485. };
  4486. // File:src/core/Raycaster.js
  4487. /**
  4488. * @author mrdoob / http://mrdoob.com/
  4489. * @author bhouston / http://clara.io/
  4490. * @author stephomi / http://stephaneginier.com/
  4491. */
  4492. ( function ( THREE ) {
  4493. THREE.Raycaster = function ( origin, direction, near, far ) {
  4494. this.ray = new THREE.Ray( origin, direction );
  4495. // direction is assumed to be normalized (for accurate distance calculations)
  4496. this.near = near || 0;
  4497. this.far = far || Infinity;
  4498. this.params = {
  4499. Mesh: {},
  4500. Line: {},
  4501. LOD: {},
  4502. Points: { threshold: 1 },
  4503. Sprite: {}
  4504. };
  4505. Object.defineProperties( this.params, {
  4506. PointCloud: {
  4507. get: function () {
  4508. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4509. return this.Points;
  4510. }
  4511. }
  4512. } );
  4513. };
  4514. function descSort( a, b ) {
  4515. return a.distance - b.distance;
  4516. }
  4517. function intersectObject( object, raycaster, intersects, recursive ) {
  4518. if ( object.visible === false ) return;
  4519. object.raycast( raycaster, intersects );
  4520. if ( recursive === true ) {
  4521. var children = object.children;
  4522. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4523. intersectObject( children[ i ], raycaster, intersects, true );
  4524. }
  4525. }
  4526. }
  4527. //
  4528. THREE.Raycaster.prototype = {
  4529. constructor: THREE.Raycaster,
  4530. linePrecision: 1,
  4531. set: function ( origin, direction ) {
  4532. // direction is assumed to be normalized (for accurate distance calculations)
  4533. this.ray.set( origin, direction );
  4534. },
  4535. setFromCamera: function ( coords, camera ) {
  4536. if ( camera instanceof THREE.PerspectiveCamera ) {
  4537. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4538. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4539. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4540. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4541. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4542. } else {
  4543. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4544. }
  4545. },
  4546. intersectObject: function ( object, recursive ) {
  4547. var intersects = [];
  4548. intersectObject( object, this, intersects, recursive );
  4549. intersects.sort( descSort );
  4550. return intersects;
  4551. },
  4552. intersectObjects: function ( objects, recursive ) {
  4553. var intersects = [];
  4554. if ( Array.isArray( objects ) === false ) {
  4555. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4556. return intersects;
  4557. }
  4558. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4559. intersectObject( objects[ i ], this, intersects, recursive );
  4560. }
  4561. intersects.sort( descSort );
  4562. return intersects;
  4563. }
  4564. };
  4565. }( THREE ) );
  4566. // File:src/core/Object3D.js
  4567. /**
  4568. * @author mrdoob / http://mrdoob.com/
  4569. * @author mikael emtinger / http://gomo.se/
  4570. * @author alteredq / http://alteredqualia.com/
  4571. * @author WestLangley / http://github.com/WestLangley
  4572. * @author elephantatwork / www.elephantatwork.ch
  4573. */
  4574. THREE.Object3D = function () {
  4575. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4576. this.uuid = THREE.Math.generateUUID();
  4577. this.name = '';
  4578. this.type = 'Object3D';
  4579. this.parent = null;
  4580. this.children = [];
  4581. this.up = THREE.Object3D.DefaultUp.clone();
  4582. var position = new THREE.Vector3();
  4583. var rotation = new THREE.Euler();
  4584. var quaternion = new THREE.Quaternion();
  4585. var scale = new THREE.Vector3( 1, 1, 1 );
  4586. function onRotationChange() {
  4587. quaternion.setFromEuler( rotation, false );
  4588. }
  4589. function onQuaternionChange() {
  4590. rotation.setFromQuaternion( quaternion, undefined, false );
  4591. }
  4592. rotation.onChange( onRotationChange );
  4593. quaternion.onChange( onQuaternionChange );
  4594. Object.defineProperties( this, {
  4595. position: {
  4596. enumerable: true,
  4597. value: position
  4598. },
  4599. rotation: {
  4600. enumerable: true,
  4601. value: rotation
  4602. },
  4603. quaternion: {
  4604. enumerable: true,
  4605. value: quaternion
  4606. },
  4607. scale: {
  4608. enumerable: true,
  4609. value: scale
  4610. },
  4611. modelViewMatrix: {
  4612. value: new THREE.Matrix4()
  4613. },
  4614. normalMatrix: {
  4615. value: new THREE.Matrix3()
  4616. }
  4617. } );
  4618. this.rotationAutoUpdate = true;
  4619. this.matrix = new THREE.Matrix4();
  4620. this.matrixWorld = new THREE.Matrix4();
  4621. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4622. this.matrixWorldNeedsUpdate = false;
  4623. this.visible = true;
  4624. this.castShadow = false;
  4625. this.receiveShadow = false;
  4626. this.frustumCulled = true;
  4627. this.renderOrder = 0;
  4628. this.userData = {};
  4629. };
  4630. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4631. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4632. THREE.Object3D.prototype = {
  4633. constructor: THREE.Object3D,
  4634. get eulerOrder () {
  4635. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  4636. return this.rotation.order;
  4637. },
  4638. set eulerOrder ( value ) {
  4639. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  4640. this.rotation.order = value;
  4641. },
  4642. get useQuaternion () {
  4643. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4644. },
  4645. set useQuaternion ( value ) {
  4646. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  4647. },
  4648. set renderDepth ( value ) {
  4649. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  4650. },
  4651. //
  4652. applyMatrix: function ( matrix ) {
  4653. this.matrix.multiplyMatrices( matrix, this.matrix );
  4654. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4655. },
  4656. setRotationFromAxisAngle: function ( axis, angle ) {
  4657. // assumes axis is normalized
  4658. this.quaternion.setFromAxisAngle( axis, angle );
  4659. },
  4660. setRotationFromEuler: function ( euler ) {
  4661. this.quaternion.setFromEuler( euler, true );
  4662. },
  4663. setRotationFromMatrix: function ( m ) {
  4664. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4665. this.quaternion.setFromRotationMatrix( m );
  4666. },
  4667. setRotationFromQuaternion: function ( q ) {
  4668. // assumes q is normalized
  4669. this.quaternion.copy( q );
  4670. },
  4671. rotateOnAxis: function () {
  4672. // rotate object on axis in object space
  4673. // axis is assumed to be normalized
  4674. var q1 = new THREE.Quaternion();
  4675. return function ( axis, angle ) {
  4676. q1.setFromAxisAngle( axis, angle );
  4677. this.quaternion.multiply( q1 );
  4678. return this;
  4679. };
  4680. }(),
  4681. rotateX: function () {
  4682. var v1 = new THREE.Vector3( 1, 0, 0 );
  4683. return function ( angle ) {
  4684. return this.rotateOnAxis( v1, angle );
  4685. };
  4686. }(),
  4687. rotateY: function () {
  4688. var v1 = new THREE.Vector3( 0, 1, 0 );
  4689. return function ( angle ) {
  4690. return this.rotateOnAxis( v1, angle );
  4691. };
  4692. }(),
  4693. rotateZ: function () {
  4694. var v1 = new THREE.Vector3( 0, 0, 1 );
  4695. return function ( angle ) {
  4696. return this.rotateOnAxis( v1, angle );
  4697. };
  4698. }(),
  4699. translateOnAxis: function () {
  4700. // translate object by distance along axis in object space
  4701. // axis is assumed to be normalized
  4702. var v1 = new THREE.Vector3();
  4703. return function ( axis, distance ) {
  4704. v1.copy( axis ).applyQuaternion( this.quaternion );
  4705. this.position.add( v1.multiplyScalar( distance ) );
  4706. return this;
  4707. };
  4708. }(),
  4709. translate: function ( distance, axis ) {
  4710. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  4711. return this.translateOnAxis( axis, distance );
  4712. },
  4713. translateX: function () {
  4714. var v1 = new THREE.Vector3( 1, 0, 0 );
  4715. return function ( distance ) {
  4716. return this.translateOnAxis( v1, distance );
  4717. };
  4718. }(),
  4719. translateY: function () {
  4720. var v1 = new THREE.Vector3( 0, 1, 0 );
  4721. return function ( distance ) {
  4722. return this.translateOnAxis( v1, distance );
  4723. };
  4724. }(),
  4725. translateZ: function () {
  4726. var v1 = new THREE.Vector3( 0, 0, 1 );
  4727. return function ( distance ) {
  4728. return this.translateOnAxis( v1, distance );
  4729. };
  4730. }(),
  4731. localToWorld: function ( vector ) {
  4732. return vector.applyMatrix4( this.matrixWorld );
  4733. },
  4734. worldToLocal: function () {
  4735. var m1 = new THREE.Matrix4();
  4736. return function ( vector ) {
  4737. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  4738. };
  4739. }(),
  4740. lookAt: function () {
  4741. // This routine does not support objects with rotated and/or translated parent(s)
  4742. var m1 = new THREE.Matrix4();
  4743. return function ( vector ) {
  4744. m1.lookAt( vector, this.position, this.up );
  4745. this.quaternion.setFromRotationMatrix( m1 );
  4746. };
  4747. }(),
  4748. add: function ( object ) {
  4749. if ( arguments.length > 1 ) {
  4750. for ( var i = 0; i < arguments.length; i ++ ) {
  4751. this.add( arguments[ i ] );
  4752. }
  4753. return this;
  4754. }
  4755. if ( object === this ) {
  4756. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  4757. return this;
  4758. }
  4759. if ( object instanceof THREE.Object3D ) {
  4760. if ( object.parent !== null ) {
  4761. object.parent.remove( object );
  4762. }
  4763. object.parent = this;
  4764. object.dispatchEvent( { type: 'added' } );
  4765. this.children.push( object );
  4766. } else {
  4767. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  4768. }
  4769. return this;
  4770. },
  4771. remove: function ( object ) {
  4772. if ( arguments.length > 1 ) {
  4773. for ( var i = 0; i < arguments.length; i ++ ) {
  4774. this.remove( arguments[ i ] );
  4775. }
  4776. }
  4777. var index = this.children.indexOf( object );
  4778. if ( index !== - 1 ) {
  4779. object.parent = null;
  4780. object.dispatchEvent( { type: 'removed' } );
  4781. this.children.splice( index, 1 );
  4782. }
  4783. },
  4784. getChildByName: function ( name ) {
  4785. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  4786. return this.getObjectByName( name );
  4787. },
  4788. getObjectById: function ( id ) {
  4789. return this.getObjectByProperty( 'id', id );
  4790. },
  4791. getObjectByName: function ( name ) {
  4792. return this.getObjectByProperty( 'name', name );
  4793. },
  4794. getObjectByProperty: function ( name, value ) {
  4795. if ( this[ name ] === value ) return this;
  4796. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4797. var child = this.children[ i ];
  4798. var object = child.getObjectByProperty( name, value );
  4799. if ( object !== undefined ) {
  4800. return object;
  4801. }
  4802. }
  4803. return undefined;
  4804. },
  4805. getWorldPosition: function ( optionalTarget ) {
  4806. var result = optionalTarget || new THREE.Vector3();
  4807. this.updateMatrixWorld( true );
  4808. return result.setFromMatrixPosition( this.matrixWorld );
  4809. },
  4810. getWorldQuaternion: function () {
  4811. var position = new THREE.Vector3();
  4812. var scale = new THREE.Vector3();
  4813. return function ( optionalTarget ) {
  4814. var result = optionalTarget || new THREE.Quaternion();
  4815. this.updateMatrixWorld( true );
  4816. this.matrixWorld.decompose( position, result, scale );
  4817. return result;
  4818. };
  4819. }(),
  4820. getWorldRotation: function () {
  4821. var quaternion = new THREE.Quaternion();
  4822. return function ( optionalTarget ) {
  4823. var result = optionalTarget || new THREE.Euler();
  4824. this.getWorldQuaternion( quaternion );
  4825. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  4826. };
  4827. }(),
  4828. getWorldScale: function () {
  4829. var position = new THREE.Vector3();
  4830. var quaternion = new THREE.Quaternion();
  4831. return function ( optionalTarget ) {
  4832. var result = optionalTarget || new THREE.Vector3();
  4833. this.updateMatrixWorld( true );
  4834. this.matrixWorld.decompose( position, quaternion, result );
  4835. return result;
  4836. };
  4837. }(),
  4838. getWorldDirection: function () {
  4839. var quaternion = new THREE.Quaternion();
  4840. return function ( optionalTarget ) {
  4841. var result = optionalTarget || new THREE.Vector3();
  4842. this.getWorldQuaternion( quaternion );
  4843. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  4844. };
  4845. }(),
  4846. raycast: function () {},
  4847. traverse: function ( callback ) {
  4848. callback( this );
  4849. var children = this.children;
  4850. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4851. children[ i ].traverse( callback );
  4852. }
  4853. },
  4854. traverseVisible: function ( callback ) {
  4855. if ( this.visible === false ) return;
  4856. callback( this );
  4857. var children = this.children;
  4858. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4859. children[ i ].traverseVisible( callback );
  4860. }
  4861. },
  4862. traverseAncestors: function ( callback ) {
  4863. var parent = this.parent;
  4864. if ( parent !== null ) {
  4865. callback( parent );
  4866. parent.traverseAncestors( callback );
  4867. }
  4868. },
  4869. updateMatrix: function () {
  4870. this.matrix.compose( this.position, this.quaternion, this.scale );
  4871. this.matrixWorldNeedsUpdate = true;
  4872. },
  4873. updateMatrixWorld: function ( force ) {
  4874. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  4875. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  4876. if ( this.parent === null ) {
  4877. this.matrixWorld.copy( this.matrix );
  4878. } else {
  4879. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  4880. }
  4881. this.matrixWorldNeedsUpdate = false;
  4882. force = true;
  4883. }
  4884. // update children
  4885. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  4886. this.children[ i ].updateMatrixWorld( force );
  4887. }
  4888. },
  4889. toJSON: function ( meta ) {
  4890. var isRootObject = ( meta === undefined );
  4891. var output = {};
  4892. // meta is a hash used to collect geometries, materials.
  4893. // not providing it implies that this is the root object
  4894. // being serialized.
  4895. if ( isRootObject ) {
  4896. // initialize meta obj
  4897. meta = {
  4898. geometries: {},
  4899. materials: {},
  4900. textures: {},
  4901. images: {}
  4902. };
  4903. output.metadata = {
  4904. version: 4.4,
  4905. type: 'Object',
  4906. generator: 'Object3D.toJSON'
  4907. };
  4908. }
  4909. // standard Object3D serialization
  4910. var object = {};
  4911. object.uuid = this.uuid;
  4912. object.type = this.type;
  4913. if ( this.name !== '' ) object.name = this.name;
  4914. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  4915. if ( this.castShadow === true ) object.castShadow = true;
  4916. if ( this.receiveShadow === true ) object.receiveShadow = true;
  4917. if ( this.visible === false ) object.visible = false;
  4918. object.matrix = this.matrix.toArray();
  4919. //
  4920. if ( this.geometry !== undefined ) {
  4921. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  4922. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  4923. }
  4924. object.geometry = this.geometry.uuid;
  4925. }
  4926. if ( this.material !== undefined ) {
  4927. if ( meta.materials[ this.material.uuid ] === undefined ) {
  4928. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  4929. }
  4930. object.material = this.material.uuid;
  4931. }
  4932. //
  4933. if ( this.children.length > 0 ) {
  4934. object.children = [];
  4935. for ( var i = 0; i < this.children.length; i ++ ) {
  4936. object.children.push( this.children[ i ].toJSON( meta ).object );
  4937. }
  4938. }
  4939. if ( isRootObject ) {
  4940. var geometries = extractFromCache( meta.geometries );
  4941. var materials = extractFromCache( meta.materials );
  4942. var textures = extractFromCache( meta.textures );
  4943. var images = extractFromCache( meta.images );
  4944. if ( geometries.length > 0 ) output.geometries = geometries;
  4945. if ( materials.length > 0 ) output.materials = materials;
  4946. if ( textures.length > 0 ) output.textures = textures;
  4947. if ( images.length > 0 ) output.images = images;
  4948. }
  4949. output.object = object;
  4950. return output;
  4951. // extract data from the cache hash
  4952. // remove metadata on each item
  4953. // and return as array
  4954. function extractFromCache ( cache ) {
  4955. var values = [];
  4956. for ( var key in cache ) {
  4957. var data = cache[ key ];
  4958. delete data.metadata;
  4959. values.push( data );
  4960. }
  4961. return values;
  4962. }
  4963. },
  4964. clone: function ( recursive ) {
  4965. return new this.constructor().copy( this, recursive );
  4966. },
  4967. copy: function ( source, recursive ) {
  4968. if ( recursive === undefined ) recursive = true;
  4969. this.name = source.name;
  4970. this.up.copy( source.up );
  4971. this.position.copy( source.position );
  4972. this.quaternion.copy( source.quaternion );
  4973. this.scale.copy( source.scale );
  4974. this.rotationAutoUpdate = source.rotationAutoUpdate;
  4975. this.matrix.copy( source.matrix );
  4976. this.matrixWorld.copy( source.matrixWorld );
  4977. this.matrixAutoUpdate = source.matrixAutoUpdate;
  4978. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  4979. this.visible = source.visible;
  4980. this.castShadow = source.castShadow;
  4981. this.receiveShadow = source.receiveShadow;
  4982. this.frustumCulled = source.frustumCulled;
  4983. this.renderOrder = source.renderOrder;
  4984. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  4985. if ( recursive === true ) {
  4986. for ( var i = 0; i < source.children.length; i ++ ) {
  4987. var child = source.children[ i ];
  4988. this.add( child.clone() );
  4989. }
  4990. }
  4991. return this;
  4992. }
  4993. };
  4994. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  4995. THREE.Object3DIdCount = 0;
  4996. // File:src/core/Face3.js
  4997. /**
  4998. * @author mrdoob / http://mrdoob.com/
  4999. * @author alteredq / http://alteredqualia.com/
  5000. */
  5001. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5002. this.a = a;
  5003. this.b = b;
  5004. this.c = c;
  5005. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5006. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5007. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5008. this.vertexColors = Array.isArray( color ) ? color : [];
  5009. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5010. };
  5011. THREE.Face3.prototype = {
  5012. constructor: THREE.Face3,
  5013. clone: function () {
  5014. return new this.constructor().copy( this );
  5015. },
  5016. copy: function ( source ) {
  5017. this.a = source.a;
  5018. this.b = source.b;
  5019. this.c = source.c;
  5020. this.normal.copy( source.normal );
  5021. this.color.copy( source.color );
  5022. this.materialIndex = source.materialIndex;
  5023. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5024. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5025. }
  5026. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5027. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5028. }
  5029. return this;
  5030. }
  5031. };
  5032. // File:src/core/Face4.js
  5033. /**
  5034. * @author mrdoob / http://mrdoob.com/
  5035. */
  5036. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  5037. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  5038. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  5039. };
  5040. // File:src/core/BufferAttribute.js
  5041. /**
  5042. * @author mrdoob / http://mrdoob.com/
  5043. */
  5044. THREE.BufferAttribute = function ( array, itemSize ) {
  5045. this.uuid = THREE.Math.generateUUID();
  5046. this.array = array;
  5047. this.itemSize = itemSize;
  5048. this.dynamic = false;
  5049. this.updateRange = { offset: 0, count: - 1 };
  5050. this.version = 0;
  5051. };
  5052. THREE.BufferAttribute.prototype = {
  5053. constructor: THREE.BufferAttribute,
  5054. get length() {
  5055. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5056. return this.array.length;
  5057. },
  5058. get count() {
  5059. return this.array.length / this.itemSize;
  5060. },
  5061. set needsUpdate( value ) {
  5062. if ( value === true ) this.version ++;
  5063. },
  5064. setDynamic: function ( value ) {
  5065. this.dynamic = value;
  5066. return this;
  5067. },
  5068. copy: function ( source ) {
  5069. this.array = new source.array.constructor( source.array );
  5070. this.itemSize = source.itemSize;
  5071. this.dynamic = source.dynamic;
  5072. return this;
  5073. },
  5074. copyAt: function ( index1, attribute, index2 ) {
  5075. index1 *= this.itemSize;
  5076. index2 *= attribute.itemSize;
  5077. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5078. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5079. }
  5080. return this;
  5081. },
  5082. copyArray: function ( array ) {
  5083. this.array.set( array );
  5084. return this;
  5085. },
  5086. copyColorsArray: function ( colors ) {
  5087. var array = this.array, offset = 0;
  5088. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5089. var color = colors[ i ];
  5090. if ( color === undefined ) {
  5091. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5092. color = new THREE.Color();
  5093. }
  5094. array[ offset ++ ] = color.r;
  5095. array[ offset ++ ] = color.g;
  5096. array[ offset ++ ] = color.b;
  5097. }
  5098. return this;
  5099. },
  5100. copyIndicesArray: function ( indices ) {
  5101. var array = this.array, offset = 0;
  5102. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5103. var index = indices[ i ];
  5104. array[ offset ++ ] = index.a;
  5105. array[ offset ++ ] = index.b;
  5106. array[ offset ++ ] = index.c;
  5107. }
  5108. return this;
  5109. },
  5110. copyVector2sArray: function ( vectors ) {
  5111. var array = this.array, offset = 0;
  5112. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5113. var vector = vectors[ i ];
  5114. if ( vector === undefined ) {
  5115. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5116. vector = new THREE.Vector2();
  5117. }
  5118. array[ offset ++ ] = vector.x;
  5119. array[ offset ++ ] = vector.y;
  5120. }
  5121. return this;
  5122. },
  5123. copyVector3sArray: function ( vectors ) {
  5124. var array = this.array, offset = 0;
  5125. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5126. var vector = vectors[ i ];
  5127. if ( vector === undefined ) {
  5128. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5129. vector = new THREE.Vector3();
  5130. }
  5131. array[ offset ++ ] = vector.x;
  5132. array[ offset ++ ] = vector.y;
  5133. array[ offset ++ ] = vector.z;
  5134. }
  5135. return this;
  5136. },
  5137. copyVector4sArray: function ( vectors ) {
  5138. var array = this.array, offset = 0;
  5139. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5140. var vector = vectors[ i ];
  5141. if ( vector === undefined ) {
  5142. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5143. vector = new THREE.Vector4();
  5144. }
  5145. array[ offset ++ ] = vector.x;
  5146. array[ offset ++ ] = vector.y;
  5147. array[ offset ++ ] = vector.z;
  5148. array[ offset ++ ] = vector.w;
  5149. }
  5150. return this;
  5151. },
  5152. set: function ( value, offset ) {
  5153. if ( offset === undefined ) offset = 0;
  5154. this.array.set( value, offset );
  5155. return this;
  5156. },
  5157. getX: function ( index ) {
  5158. return this.array[ index * this.itemSize ];
  5159. },
  5160. setX: function ( index, x ) {
  5161. this.array[ index * this.itemSize ] = x;
  5162. return this;
  5163. },
  5164. getY: function ( index ) {
  5165. return this.array[ index * this.itemSize + 1 ];
  5166. },
  5167. setY: function ( index, y ) {
  5168. this.array[ index * this.itemSize + 1 ] = y;
  5169. return this;
  5170. },
  5171. getZ: function ( index ) {
  5172. return this.array[ index * this.itemSize + 2 ];
  5173. },
  5174. setZ: function ( index, z ) {
  5175. this.array[ index * this.itemSize + 2 ] = z;
  5176. return this;
  5177. },
  5178. getW: function ( index ) {
  5179. return this.array[ index * this.itemSize + 3 ];
  5180. },
  5181. setW: function ( index, w ) {
  5182. this.array[ index * this.itemSize + 3 ] = w;
  5183. return this;
  5184. },
  5185. setXY: function ( index, x, y ) {
  5186. index *= this.itemSize;
  5187. this.array[ index + 0 ] = x;
  5188. this.array[ index + 1 ] = y;
  5189. return this;
  5190. },
  5191. setXYZ: function ( index, x, y, z ) {
  5192. index *= this.itemSize;
  5193. this.array[ index + 0 ] = x;
  5194. this.array[ index + 1 ] = y;
  5195. this.array[ index + 2 ] = z;
  5196. return this;
  5197. },
  5198. setXYZW: function ( index, x, y, z, w ) {
  5199. index *= this.itemSize;
  5200. this.array[ index + 0 ] = x;
  5201. this.array[ index + 1 ] = y;
  5202. this.array[ index + 2 ] = z;
  5203. this.array[ index + 3 ] = w;
  5204. return this;
  5205. },
  5206. clone: function () {
  5207. return new this.constructor().copy( this );
  5208. }
  5209. };
  5210. //
  5211. THREE.Int8Attribute = function ( array, itemSize ) {
  5212. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5213. };
  5214. THREE.Uint8Attribute = function ( array, itemSize ) {
  5215. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5216. };
  5217. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5218. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5219. };
  5220. THREE.Int16Attribute = function ( array, itemSize ) {
  5221. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5222. };
  5223. THREE.Uint16Attribute = function ( array, itemSize ) {
  5224. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5225. };
  5226. THREE.Int32Attribute = function ( array, itemSize ) {
  5227. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5228. };
  5229. THREE.Uint32Attribute = function ( array, itemSize ) {
  5230. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5231. };
  5232. THREE.Float32Attribute = function ( array, itemSize ) {
  5233. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5234. };
  5235. THREE.Float64Attribute = function ( array, itemSize ) {
  5236. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5237. };
  5238. // Deprecated
  5239. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5240. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5241. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5242. };
  5243. // File:src/core/InstancedBufferAttribute.js
  5244. /**
  5245. * @author benaadams / https://twitter.com/ben_a_adams
  5246. */
  5247. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5248. THREE.BufferAttribute.call( this, array, itemSize );
  5249. this.meshPerAttribute = meshPerAttribute || 1;
  5250. };
  5251. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5252. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5253. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5254. THREE.BufferAttribute.prototype.copy.call( this, source );
  5255. this.meshPerAttribute = source.meshPerAttribute;
  5256. return this;
  5257. };
  5258. // File:src/core/InterleavedBuffer.js
  5259. /**
  5260. * @author benaadams / https://twitter.com/ben_a_adams
  5261. */
  5262. THREE.InterleavedBuffer = function ( array, stride ) {
  5263. this.uuid = THREE.Math.generateUUID();
  5264. this.array = array;
  5265. this.stride = stride;
  5266. this.dynamic = false;
  5267. this.updateRange = { offset: 0, count: - 1 };
  5268. this.version = 0;
  5269. };
  5270. THREE.InterleavedBuffer.prototype = {
  5271. constructor: THREE.InterleavedBuffer,
  5272. get length () {
  5273. return this.array.length;
  5274. },
  5275. get count () {
  5276. return this.array.length / this.stride;
  5277. },
  5278. set needsUpdate( value ) {
  5279. if ( value === true ) this.version ++;
  5280. },
  5281. setDynamic: function ( value ) {
  5282. this.dynamic = value;
  5283. return this;
  5284. },
  5285. copy: function ( source ) {
  5286. this.array = new source.array.constructor( source.array );
  5287. this.stride = source.stride;
  5288. this.dynamic = source.dynamic;
  5289. },
  5290. copyAt: function ( index1, attribute, index2 ) {
  5291. index1 *= this.stride;
  5292. index2 *= attribute.stride;
  5293. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5294. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5295. }
  5296. return this;
  5297. },
  5298. set: function ( value, offset ) {
  5299. if ( offset === undefined ) offset = 0;
  5300. this.array.set( value, offset );
  5301. return this;
  5302. },
  5303. clone: function () {
  5304. return new this.constructor().copy( this );
  5305. }
  5306. };
  5307. // File:src/core/InstancedInterleavedBuffer.js
  5308. /**
  5309. * @author benaadams / https://twitter.com/ben_a_adams
  5310. */
  5311. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5312. THREE.InterleavedBuffer.call( this, array, stride );
  5313. this.meshPerAttribute = meshPerAttribute || 1;
  5314. };
  5315. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5316. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5317. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5318. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5319. this.meshPerAttribute = source.meshPerAttribute;
  5320. return this;
  5321. };
  5322. // File:src/core/InterleavedBufferAttribute.js
  5323. /**
  5324. * @author benaadams / https://twitter.com/ben_a_adams
  5325. */
  5326. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5327. this.uuid = THREE.Math.generateUUID();
  5328. this.data = interleavedBuffer;
  5329. this.itemSize = itemSize;
  5330. this.offset = offset;
  5331. };
  5332. THREE.InterleavedBufferAttribute.prototype = {
  5333. constructor: THREE.InterleavedBufferAttribute,
  5334. get length() {
  5335. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5336. return this.array.length;
  5337. },
  5338. get count() {
  5339. return this.data.array.length / this.data.stride;
  5340. },
  5341. setX: function ( index, x ) {
  5342. this.data.array[ index * this.data.stride + this.offset ] = x;
  5343. return this;
  5344. },
  5345. setY: function ( index, y ) {
  5346. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5347. return this;
  5348. },
  5349. setZ: function ( index, z ) {
  5350. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5351. return this;
  5352. },
  5353. setW: function ( index, w ) {
  5354. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5355. return this;
  5356. },
  5357. getX: function ( index ) {
  5358. return this.data.array[ index * this.data.stride + this.offset ];
  5359. },
  5360. getY: function ( index ) {
  5361. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5362. },
  5363. getZ: function ( index ) {
  5364. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5365. },
  5366. getW: function ( index ) {
  5367. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5368. },
  5369. setXY: function ( index, x, y ) {
  5370. index = index * this.data.stride + this.offset;
  5371. this.data.array[ index + 0 ] = x;
  5372. this.data.array[ index + 1 ] = y;
  5373. return this;
  5374. },
  5375. setXYZ: function ( index, x, y, z ) {
  5376. index = index * this.data.stride + this.offset;
  5377. this.data.array[ index + 0 ] = x;
  5378. this.data.array[ index + 1 ] = y;
  5379. this.data.array[ index + 2 ] = z;
  5380. return this;
  5381. },
  5382. setXYZW: function ( index, x, y, z, w ) {
  5383. index = index * this.data.stride + this.offset;
  5384. this.data.array[ index + 0 ] = x;
  5385. this.data.array[ index + 1 ] = y;
  5386. this.data.array[ index + 2 ] = z;
  5387. this.data.array[ index + 3 ] = w;
  5388. return this;
  5389. }
  5390. };
  5391. // File:src/core/Geometry.js
  5392. /**
  5393. * @author mrdoob / http://mrdoob.com/
  5394. * @author kile / http://kile.stravaganza.org/
  5395. * @author alteredq / http://alteredqualia.com/
  5396. * @author mikael emtinger / http://gomo.se/
  5397. * @author zz85 / http://www.lab4games.net/zz85/blog
  5398. * @author bhouston / http://clara.io
  5399. */
  5400. THREE.Geometry = function () {
  5401. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5402. this.uuid = THREE.Math.generateUUID();
  5403. this.name = '';
  5404. this.type = 'Geometry';
  5405. this.vertices = [];
  5406. this.colors = [];
  5407. this.faces = [];
  5408. this.faceVertexUvs = [ [] ];
  5409. this.morphTargets = [];
  5410. this.morphNormals = [];
  5411. this.skinWeights = [];
  5412. this.skinIndices = [];
  5413. this.lineDistances = [];
  5414. this.boundingBox = null;
  5415. this.boundingSphere = null;
  5416. // update flags
  5417. this.verticesNeedUpdate = false;
  5418. this.elementsNeedUpdate = false;
  5419. this.uvsNeedUpdate = false;
  5420. this.normalsNeedUpdate = false;
  5421. this.colorsNeedUpdate = false;
  5422. this.lineDistancesNeedUpdate = false;
  5423. this.groupsNeedUpdate = false;
  5424. };
  5425. THREE.Geometry.prototype = {
  5426. constructor: THREE.Geometry,
  5427. applyMatrix: function ( matrix ) {
  5428. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5429. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5430. var vertex = this.vertices[ i ];
  5431. vertex.applyMatrix4( matrix );
  5432. }
  5433. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5434. var face = this.faces[ i ];
  5435. face.normal.applyMatrix3( normalMatrix ).normalize();
  5436. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5437. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5438. }
  5439. }
  5440. if ( this.boundingBox !== null ) {
  5441. this.computeBoundingBox();
  5442. }
  5443. if ( this.boundingSphere !== null ) {
  5444. this.computeBoundingSphere();
  5445. }
  5446. this.verticesNeedUpdate = true;
  5447. this.normalsNeedUpdate = true;
  5448. },
  5449. rotateX: function () {
  5450. // rotate geometry around world x-axis
  5451. var m1;
  5452. return function rotateX( angle ) {
  5453. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5454. m1.makeRotationX( angle );
  5455. this.applyMatrix( m1 );
  5456. return this;
  5457. };
  5458. }(),
  5459. rotateY: function () {
  5460. // rotate geometry around world y-axis
  5461. var m1;
  5462. return function rotateY( angle ) {
  5463. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5464. m1.makeRotationY( angle );
  5465. this.applyMatrix( m1 );
  5466. return this;
  5467. };
  5468. }(),
  5469. rotateZ: function () {
  5470. // rotate geometry around world z-axis
  5471. var m1;
  5472. return function rotateZ( angle ) {
  5473. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5474. m1.makeRotationZ( angle );
  5475. this.applyMatrix( m1 );
  5476. return this;
  5477. };
  5478. }(),
  5479. translate: function () {
  5480. // translate geometry
  5481. var m1;
  5482. return function translate( x, y, z ) {
  5483. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5484. m1.makeTranslation( x, y, z );
  5485. this.applyMatrix( m1 );
  5486. return this;
  5487. };
  5488. }(),
  5489. scale: function () {
  5490. // scale geometry
  5491. var m1;
  5492. return function scale( x, y, z ) {
  5493. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5494. m1.makeScale( x, y, z );
  5495. this.applyMatrix( m1 );
  5496. return this;
  5497. };
  5498. }(),
  5499. lookAt: function () {
  5500. var obj;
  5501. return function lookAt( vector ) {
  5502. if ( obj === undefined ) obj = new THREE.Object3D();
  5503. obj.lookAt( vector );
  5504. obj.updateMatrix();
  5505. this.applyMatrix( obj.matrix );
  5506. };
  5507. }(),
  5508. fromBufferGeometry: function ( geometry ) {
  5509. var scope = this;
  5510. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5511. var attributes = geometry.attributes;
  5512. var vertices = attributes.position.array;
  5513. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5514. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5515. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5516. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5517. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5518. var tempNormals = [];
  5519. var tempUVs = [];
  5520. var tempUVs2 = [];
  5521. for ( var i = 0, j = 0, k = 0; i < vertices.length; i += 3, j += 2, k += 4 ) {
  5522. scope.vertices.push( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  5523. if ( normals !== undefined ) {
  5524. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5525. }
  5526. if ( colors !== undefined ) {
  5527. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5528. }
  5529. if ( uvs !== undefined ) {
  5530. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5531. }
  5532. if ( uvs2 !== undefined ) {
  5533. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5534. }
  5535. }
  5536. function addFace( a, b, c ) {
  5537. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5538. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5539. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5540. scope.faces.push( face );
  5541. if ( uvs !== undefined ) {
  5542. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5543. }
  5544. if ( uvs2 !== undefined ) {
  5545. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5546. }
  5547. };
  5548. if ( indices !== undefined ) {
  5549. var groups = geometry.groups;
  5550. if ( groups.length > 0 ) {
  5551. for ( var i = 0; i < groups.length; i ++ ) {
  5552. var group = groups[ i ];
  5553. var start = group.start;
  5554. var count = group.count;
  5555. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5556. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5557. }
  5558. }
  5559. } else {
  5560. for ( var i = 0; i < indices.length; i += 3 ) {
  5561. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5562. }
  5563. }
  5564. } else {
  5565. for ( var i = 0; i < vertices.length / 3; i += 3 ) {
  5566. addFace( i, i + 1, i + 2 );
  5567. }
  5568. }
  5569. this.computeFaceNormals();
  5570. if ( geometry.boundingBox !== null ) {
  5571. this.boundingBox = geometry.boundingBox.clone();
  5572. }
  5573. if ( geometry.boundingSphere !== null ) {
  5574. this.boundingSphere = geometry.boundingSphere.clone();
  5575. }
  5576. return this;
  5577. },
  5578. center: function () {
  5579. this.computeBoundingBox();
  5580. var offset = this.boundingBox.center().negate();
  5581. this.translate( offset.x, offset.y, offset.z );
  5582. return offset;
  5583. },
  5584. normalize: function () {
  5585. this.computeBoundingSphere();
  5586. var center = this.boundingSphere.center;
  5587. var radius = this.boundingSphere.radius;
  5588. var s = radius === 0 ? 1 : 1.0 / radius;
  5589. var matrix = new THREE.Matrix4();
  5590. matrix.set(
  5591. s, 0, 0, - s * center.x,
  5592. 0, s, 0, - s * center.y,
  5593. 0, 0, s, - s * center.z,
  5594. 0, 0, 0, 1
  5595. );
  5596. this.applyMatrix( matrix );
  5597. return this;
  5598. },
  5599. computeFaceNormals: function () {
  5600. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5601. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5602. var face = this.faces[ f ];
  5603. var vA = this.vertices[ face.a ];
  5604. var vB = this.vertices[ face.b ];
  5605. var vC = this.vertices[ face.c ];
  5606. cb.subVectors( vC, vB );
  5607. ab.subVectors( vA, vB );
  5608. cb.cross( ab );
  5609. cb.normalize();
  5610. face.normal.copy( cb );
  5611. }
  5612. },
  5613. computeVertexNormals: function ( areaWeighted ) {
  5614. var v, vl, f, fl, face, vertices;
  5615. vertices = new Array( this.vertices.length );
  5616. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5617. vertices[ v ] = new THREE.Vector3();
  5618. }
  5619. if ( areaWeighted ) {
  5620. // vertex normals weighted by triangle areas
  5621. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5622. var vA, vB, vC;
  5623. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5624. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5625. face = this.faces[ f ];
  5626. vA = this.vertices[ face.a ];
  5627. vB = this.vertices[ face.b ];
  5628. vC = this.vertices[ face.c ];
  5629. cb.subVectors( vC, vB );
  5630. ab.subVectors( vA, vB );
  5631. cb.cross( ab );
  5632. vertices[ face.a ].add( cb );
  5633. vertices[ face.b ].add( cb );
  5634. vertices[ face.c ].add( cb );
  5635. }
  5636. } else {
  5637. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5638. face = this.faces[ f ];
  5639. vertices[ face.a ].add( face.normal );
  5640. vertices[ face.b ].add( face.normal );
  5641. vertices[ face.c ].add( face.normal );
  5642. }
  5643. }
  5644. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5645. vertices[ v ].normalize();
  5646. }
  5647. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5648. face = this.faces[ f ];
  5649. var vertexNormals = face.vertexNormals;
  5650. if ( vertexNormals.length === 3 ) {
  5651. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5652. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5653. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5654. } else {
  5655. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5656. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5657. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5658. }
  5659. }
  5660. },
  5661. computeMorphNormals: function () {
  5662. var i, il, f, fl, face;
  5663. // save original normals
  5664. // - create temp variables on first access
  5665. // otherwise just copy (for faster repeated calls)
  5666. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5667. face = this.faces[ f ];
  5668. if ( ! face.__originalFaceNormal ) {
  5669. face.__originalFaceNormal = face.normal.clone();
  5670. } else {
  5671. face.__originalFaceNormal.copy( face.normal );
  5672. }
  5673. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5674. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5675. if ( ! face.__originalVertexNormals[ i ] ) {
  5676. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5677. } else {
  5678. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5679. }
  5680. }
  5681. }
  5682. // use temp geometry to compute face and vertex normals for each morph
  5683. var tmpGeo = new THREE.Geometry();
  5684. tmpGeo.faces = this.faces;
  5685. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5686. // create on first access
  5687. if ( ! this.morphNormals[ i ] ) {
  5688. this.morphNormals[ i ] = {};
  5689. this.morphNormals[ i ].faceNormals = [];
  5690. this.morphNormals[ i ].vertexNormals = [];
  5691. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5692. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5693. var faceNormal, vertexNormals;
  5694. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5695. faceNormal = new THREE.Vector3();
  5696. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5697. dstNormalsFace.push( faceNormal );
  5698. dstNormalsVertex.push( vertexNormals );
  5699. }
  5700. }
  5701. var morphNormals = this.morphNormals[ i ];
  5702. // set vertices to morph target
  5703. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5704. // compute morph normals
  5705. tmpGeo.computeFaceNormals();
  5706. tmpGeo.computeVertexNormals();
  5707. // store morph normals
  5708. var faceNormal, vertexNormals;
  5709. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5710. face = this.faces[ f ];
  5711. faceNormal = morphNormals.faceNormals[ f ];
  5712. vertexNormals = morphNormals.vertexNormals[ f ];
  5713. faceNormal.copy( face.normal );
  5714. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  5715. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  5716. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  5717. }
  5718. }
  5719. // restore original normals
  5720. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5721. face = this.faces[ f ];
  5722. face.normal = face.__originalFaceNormal;
  5723. face.vertexNormals = face.__originalVertexNormals;
  5724. }
  5725. },
  5726. computeTangents: function () {
  5727. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  5728. },
  5729. computeLineDistances: function () {
  5730. var d = 0;
  5731. var vertices = this.vertices;
  5732. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  5733. if ( i > 0 ) {
  5734. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  5735. }
  5736. this.lineDistances[ i ] = d;
  5737. }
  5738. },
  5739. computeBoundingBox: function () {
  5740. if ( this.boundingBox === null ) {
  5741. this.boundingBox = new THREE.Box3();
  5742. }
  5743. this.boundingBox.setFromPoints( this.vertices );
  5744. },
  5745. computeBoundingSphere: function () {
  5746. if ( this.boundingSphere === null ) {
  5747. this.boundingSphere = new THREE.Sphere();
  5748. }
  5749. this.boundingSphere.setFromPoints( this.vertices );
  5750. },
  5751. merge: function ( geometry, matrix, materialIndexOffset ) {
  5752. if ( geometry instanceof THREE.Geometry === false ) {
  5753. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  5754. return;
  5755. }
  5756. var normalMatrix,
  5757. vertexOffset = this.vertices.length,
  5758. vertices1 = this.vertices,
  5759. vertices2 = geometry.vertices,
  5760. faces1 = this.faces,
  5761. faces2 = geometry.faces,
  5762. uvs1 = this.faceVertexUvs[ 0 ],
  5763. uvs2 = geometry.faceVertexUvs[ 0 ];
  5764. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  5765. if ( matrix !== undefined ) {
  5766. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5767. }
  5768. // vertices
  5769. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  5770. var vertex = vertices2[ i ];
  5771. var vertexCopy = vertex.clone();
  5772. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  5773. vertices1.push( vertexCopy );
  5774. }
  5775. // faces
  5776. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  5777. var face = faces2[ i ], faceCopy, normal, color,
  5778. faceVertexNormals = face.vertexNormals,
  5779. faceVertexColors = face.vertexColors;
  5780. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  5781. faceCopy.normal.copy( face.normal );
  5782. if ( normalMatrix !== undefined ) {
  5783. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  5784. }
  5785. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  5786. normal = faceVertexNormals[ j ].clone();
  5787. if ( normalMatrix !== undefined ) {
  5788. normal.applyMatrix3( normalMatrix ).normalize();
  5789. }
  5790. faceCopy.vertexNormals.push( normal );
  5791. }
  5792. faceCopy.color.copy( face.color );
  5793. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  5794. color = faceVertexColors[ j ];
  5795. faceCopy.vertexColors.push( color.clone() );
  5796. }
  5797. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  5798. faces1.push( faceCopy );
  5799. }
  5800. // uvs
  5801. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  5802. var uv = uvs2[ i ], uvCopy = [];
  5803. if ( uv === undefined ) {
  5804. continue;
  5805. }
  5806. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  5807. uvCopy.push( uv[ j ].clone() );
  5808. }
  5809. uvs1.push( uvCopy );
  5810. }
  5811. },
  5812. mergeMesh: function ( mesh ) {
  5813. if ( mesh instanceof THREE.Mesh === false ) {
  5814. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  5815. return;
  5816. }
  5817. mesh.matrixAutoUpdate && mesh.updateMatrix();
  5818. this.merge( mesh.geometry, mesh.matrix );
  5819. },
  5820. /*
  5821. * Checks for duplicate vertices with hashmap.
  5822. * Duplicated vertices are removed
  5823. * and faces' vertices are updated.
  5824. */
  5825. mergeVertices: function () {
  5826. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  5827. var unique = [], changes = [];
  5828. var v, key;
  5829. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  5830. var precision = Math.pow( 10, precisionPoints );
  5831. var i, il, face;
  5832. var indices, j, jl;
  5833. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  5834. v = this.vertices[ i ];
  5835. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  5836. if ( verticesMap[ key ] === undefined ) {
  5837. verticesMap[ key ] = i;
  5838. unique.push( this.vertices[ i ] );
  5839. changes[ i ] = unique.length - 1;
  5840. } else {
  5841. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  5842. changes[ i ] = changes[ verticesMap[ key ] ];
  5843. }
  5844. }
  5845. // if faces are completely degenerate after merging vertices, we
  5846. // have to remove them from the geometry.
  5847. var faceIndicesToRemove = [];
  5848. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  5849. face = this.faces[ i ];
  5850. face.a = changes[ face.a ];
  5851. face.b = changes[ face.b ];
  5852. face.c = changes[ face.c ];
  5853. indices = [ face.a, face.b, face.c ];
  5854. var dupIndex = - 1;
  5855. // if any duplicate vertices are found in a Face3
  5856. // we have to remove the face as nothing can be saved
  5857. for ( var n = 0; n < 3; n ++ ) {
  5858. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  5859. dupIndex = n;
  5860. faceIndicesToRemove.push( i );
  5861. break;
  5862. }
  5863. }
  5864. }
  5865. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  5866. var idx = faceIndicesToRemove[ i ];
  5867. this.faces.splice( idx, 1 );
  5868. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  5869. this.faceVertexUvs[ j ].splice( idx, 1 );
  5870. }
  5871. }
  5872. // Use unique set of vertices
  5873. var diff = this.vertices.length - unique.length;
  5874. this.vertices = unique;
  5875. return diff;
  5876. },
  5877. sortFacesByMaterialIndex: function () {
  5878. var faces = this.faces;
  5879. var length = faces.length;
  5880. // tag faces
  5881. for ( var i = 0; i < length; i ++ ) {
  5882. faces[ i ]._id = i;
  5883. }
  5884. // sort faces
  5885. function materialIndexSort( a, b ) {
  5886. return a.materialIndex - b.materialIndex;
  5887. }
  5888. faces.sort( materialIndexSort );
  5889. // sort uvs
  5890. var uvs1 = this.faceVertexUvs[ 0 ];
  5891. var uvs2 = this.faceVertexUvs[ 1 ];
  5892. var newUvs1, newUvs2;
  5893. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  5894. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  5895. for ( var i = 0; i < length; i ++ ) {
  5896. var id = faces[ i ]._id;
  5897. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  5898. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  5899. }
  5900. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  5901. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  5902. },
  5903. toJSON: function () {
  5904. var data = {
  5905. metadata: {
  5906. version: 4.4,
  5907. type: 'Geometry',
  5908. generator: 'Geometry.toJSON'
  5909. }
  5910. };
  5911. // standard Geometry serialization
  5912. data.uuid = this.uuid;
  5913. data.type = this.type;
  5914. if ( this.name !== '' ) data.name = this.name;
  5915. if ( this.parameters !== undefined ) {
  5916. var parameters = this.parameters;
  5917. for ( var key in parameters ) {
  5918. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  5919. }
  5920. return data;
  5921. }
  5922. var vertices = [];
  5923. for ( var i = 0; i < this.vertices.length; i ++ ) {
  5924. var vertex = this.vertices[ i ];
  5925. vertices.push( vertex.x, vertex.y, vertex.z );
  5926. }
  5927. var faces = [];
  5928. var normals = [];
  5929. var normalsHash = {};
  5930. var colors = [];
  5931. var colorsHash = {};
  5932. var uvs = [];
  5933. var uvsHash = {};
  5934. for ( var i = 0; i < this.faces.length; i ++ ) {
  5935. var face = this.faces[ i ];
  5936. var hasMaterial = false; // face.materialIndex !== undefined;
  5937. var hasFaceUv = false; // deprecated
  5938. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  5939. var hasFaceNormal = face.normal.length() > 0;
  5940. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  5941. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  5942. var hasFaceVertexColor = face.vertexColors.length > 0;
  5943. var faceType = 0;
  5944. faceType = setBit( faceType, 0, 0 );
  5945. faceType = setBit( faceType, 1, hasMaterial );
  5946. faceType = setBit( faceType, 2, hasFaceUv );
  5947. faceType = setBit( faceType, 3, hasFaceVertexUv );
  5948. faceType = setBit( faceType, 4, hasFaceNormal );
  5949. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  5950. faceType = setBit( faceType, 6, hasFaceColor );
  5951. faceType = setBit( faceType, 7, hasFaceVertexColor );
  5952. faces.push( faceType );
  5953. faces.push( face.a, face.b, face.c );
  5954. if ( hasFaceVertexUv ) {
  5955. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  5956. faces.push(
  5957. getUvIndex( faceVertexUvs[ 0 ] ),
  5958. getUvIndex( faceVertexUvs[ 1 ] ),
  5959. getUvIndex( faceVertexUvs[ 2 ] )
  5960. );
  5961. }
  5962. if ( hasFaceNormal ) {
  5963. faces.push( getNormalIndex( face.normal ) );
  5964. }
  5965. if ( hasFaceVertexNormal ) {
  5966. var vertexNormals = face.vertexNormals;
  5967. faces.push(
  5968. getNormalIndex( vertexNormals[ 0 ] ),
  5969. getNormalIndex( vertexNormals[ 1 ] ),
  5970. getNormalIndex( vertexNormals[ 2 ] )
  5971. );
  5972. }
  5973. if ( hasFaceColor ) {
  5974. faces.push( getColorIndex( face.color ) );
  5975. }
  5976. if ( hasFaceVertexColor ) {
  5977. var vertexColors = face.vertexColors;
  5978. faces.push(
  5979. getColorIndex( vertexColors[ 0 ] ),
  5980. getColorIndex( vertexColors[ 1 ] ),
  5981. getColorIndex( vertexColors[ 2 ] )
  5982. );
  5983. }
  5984. }
  5985. function setBit( value, position, enabled ) {
  5986. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  5987. }
  5988. function getNormalIndex( normal ) {
  5989. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  5990. if ( normalsHash[ hash ] !== undefined ) {
  5991. return normalsHash[ hash ];
  5992. }
  5993. normalsHash[ hash ] = normals.length / 3;
  5994. normals.push( normal.x, normal.y, normal.z );
  5995. return normalsHash[ hash ];
  5996. }
  5997. function getColorIndex( color ) {
  5998. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  5999. if ( colorsHash[ hash ] !== undefined ) {
  6000. return colorsHash[ hash ];
  6001. }
  6002. colorsHash[ hash ] = colors.length;
  6003. colors.push( color.getHex() );
  6004. return colorsHash[ hash ];
  6005. }
  6006. function getUvIndex( uv ) {
  6007. var hash = uv.x.toString() + uv.y.toString();
  6008. if ( uvsHash[ hash ] !== undefined ) {
  6009. return uvsHash[ hash ];
  6010. }
  6011. uvsHash[ hash ] = uvs.length / 2;
  6012. uvs.push( uv.x, uv.y );
  6013. return uvsHash[ hash ];
  6014. }
  6015. data.data = {};
  6016. data.data.vertices = vertices;
  6017. data.data.normals = normals;
  6018. if ( colors.length > 0 ) data.data.colors = colors;
  6019. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6020. data.data.faces = faces;
  6021. return data;
  6022. },
  6023. clone: function () {
  6024. return new this.constructor().copy( this );
  6025. },
  6026. copy: function ( source ) {
  6027. this.vertices = [];
  6028. this.faces = [];
  6029. this.faceVertexUvs = [ [] ];
  6030. var vertices = source.vertices;
  6031. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6032. this.vertices.push( vertices[ i ].clone() );
  6033. }
  6034. var faces = source.faces;
  6035. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6036. this.faces.push( faces[ i ].clone() );
  6037. }
  6038. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6039. var faceVertexUvs = source.faceVertexUvs[ i ];
  6040. if ( this.faceVertexUvs[ i ] === undefined ) {
  6041. this.faceVertexUvs[ i ] = [];
  6042. }
  6043. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6044. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6045. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6046. var uv = uvs[ k ];
  6047. uvsCopy.push( uv.clone() );
  6048. }
  6049. this.faceVertexUvs[ i ].push( uvsCopy );
  6050. }
  6051. }
  6052. return this;
  6053. },
  6054. dispose: function () {
  6055. this.dispatchEvent( { type: 'dispose' } );
  6056. }
  6057. };
  6058. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6059. THREE.GeometryIdCount = 0;
  6060. // File:src/core/DirectGeometry.js
  6061. /**
  6062. * @author mrdoob / http://mrdoob.com/
  6063. */
  6064. THREE.DirectGeometry = function () {
  6065. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6066. this.uuid = THREE.Math.generateUUID();
  6067. this.name = '';
  6068. this.type = 'DirectGeometry';
  6069. this.indices = [];
  6070. this.vertices = [];
  6071. this.normals = [];
  6072. this.colors = [];
  6073. this.uvs = [];
  6074. this.uvs2 = [];
  6075. this.groups = [];
  6076. this.morphTargets = {};
  6077. this.skinWeights = [];
  6078. this.skinIndices = [];
  6079. // this.lineDistances = [];
  6080. this.boundingBox = null;
  6081. this.boundingSphere = null;
  6082. // update flags
  6083. this.verticesNeedUpdate = false;
  6084. this.normalsNeedUpdate = false;
  6085. this.colorsNeedUpdate = false;
  6086. this.uvsNeedUpdate = false;
  6087. this.groupsNeedUpdate = false;
  6088. };
  6089. THREE.DirectGeometry.prototype = {
  6090. constructor: THREE.DirectGeometry,
  6091. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6092. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6093. computeFaceNormals: function () {
  6094. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6095. },
  6096. computeVertexNormals: function () {
  6097. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6098. },
  6099. computeGroups: function ( geometry ) {
  6100. var group;
  6101. var groups = [];
  6102. var materialIndex;
  6103. var faces = geometry.faces;
  6104. for ( var i = 0; i < faces.length; i ++ ) {
  6105. var face = faces[ i ];
  6106. // materials
  6107. if ( face.materialIndex !== materialIndex ) {
  6108. materialIndex = face.materialIndex;
  6109. if ( group !== undefined ) {
  6110. group.count = ( i * 3 ) - group.start;
  6111. groups.push( group );
  6112. }
  6113. group = {
  6114. start: i * 3,
  6115. materialIndex: materialIndex
  6116. };
  6117. }
  6118. }
  6119. if ( group !== undefined ) {
  6120. group.count = ( i * 3 ) - group.start;
  6121. groups.push( group );
  6122. }
  6123. this.groups = groups;
  6124. },
  6125. fromGeometry: function ( geometry ) {
  6126. var faces = geometry.faces;
  6127. var vertices = geometry.vertices;
  6128. var faceVertexUvs = geometry.faceVertexUvs;
  6129. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6130. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6131. // morphs
  6132. var morphTargets = geometry.morphTargets;
  6133. var morphTargetsLength = morphTargets.length;
  6134. if ( morphTargetsLength > 0 ) {
  6135. var morphTargetsPosition = [];
  6136. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6137. morphTargetsPosition[ i ] = [];
  6138. }
  6139. this.morphTargets.position = morphTargetsPosition;
  6140. }
  6141. var morphNormals = geometry.morphNormals;
  6142. var morphNormalsLength = morphNormals.length;
  6143. if ( morphNormalsLength > 0 ) {
  6144. var morphTargetsNormal = [];
  6145. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6146. morphTargetsNormal[ i ] = [];
  6147. }
  6148. this.morphTargets.normal = morphTargetsNormal;
  6149. }
  6150. // skins
  6151. var skinIndices = geometry.skinIndices;
  6152. var skinWeights = geometry.skinWeights;
  6153. var hasSkinIndices = skinIndices.length === vertices.length;
  6154. var hasSkinWeights = skinWeights.length === vertices.length;
  6155. //
  6156. for ( var i = 0; i < faces.length; i ++ ) {
  6157. var face = faces[ i ];
  6158. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6159. var vertexNormals = face.vertexNormals;
  6160. if ( vertexNormals.length === 3 ) {
  6161. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6162. } else {
  6163. var normal = face.normal;
  6164. this.normals.push( normal, normal, normal );
  6165. }
  6166. var vertexColors = face.vertexColors;
  6167. if ( vertexColors.length === 3 ) {
  6168. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6169. } else {
  6170. var color = face.color;
  6171. this.colors.push( color, color, color );
  6172. }
  6173. if ( hasFaceVertexUv === true ) {
  6174. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6175. if ( vertexUvs !== undefined ) {
  6176. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6177. } else {
  6178. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6179. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6180. }
  6181. }
  6182. if ( hasFaceVertexUv2 === true ) {
  6183. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6184. if ( vertexUvs !== undefined ) {
  6185. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6186. } else {
  6187. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6188. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6189. }
  6190. }
  6191. // morphs
  6192. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6193. var morphTarget = morphTargets[ j ].vertices;
  6194. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6195. }
  6196. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6197. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6198. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6199. }
  6200. // skins
  6201. if ( hasSkinIndices ) {
  6202. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6203. }
  6204. if ( hasSkinWeights ) {
  6205. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6206. }
  6207. }
  6208. this.computeGroups( geometry );
  6209. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6210. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6211. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6212. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6213. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6214. return this;
  6215. },
  6216. dispose: function () {
  6217. this.dispatchEvent( { type: 'dispose' } );
  6218. }
  6219. };
  6220. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6221. // File:src/core/BufferGeometry.js
  6222. /**
  6223. * @author alteredq / http://alteredqualia.com/
  6224. * @author mrdoob / http://mrdoob.com/
  6225. */
  6226. THREE.BufferGeometry = function () {
  6227. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6228. this.uuid = THREE.Math.generateUUID();
  6229. this.name = '';
  6230. this.type = 'BufferGeometry';
  6231. this.index = null;
  6232. this.attributes = {};
  6233. this.morphAttributes = {};
  6234. this.groups = [];
  6235. this.boundingBox = null;
  6236. this.boundingSphere = null;
  6237. this.drawRange = { start: 0, count: Infinity };
  6238. };
  6239. THREE.BufferGeometry.prototype = {
  6240. constructor: THREE.BufferGeometry,
  6241. addIndex: function ( index ) {
  6242. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  6243. this.setIndex( index );
  6244. },
  6245. getIndex: function () {
  6246. return this.index;
  6247. },
  6248. setIndex: function ( index ) {
  6249. this.index = index;
  6250. },
  6251. addAttribute: function ( name, attribute ) {
  6252. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6253. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6254. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6255. return;
  6256. }
  6257. if ( name === 'index' ) {
  6258. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6259. this.setIndex( attribute );
  6260. return;
  6261. }
  6262. this.attributes[ name ] = attribute;
  6263. },
  6264. getAttribute: function ( name ) {
  6265. return this.attributes[ name ];
  6266. },
  6267. removeAttribute: function ( name ) {
  6268. delete this.attributes[ name ];
  6269. },
  6270. get drawcalls() {
  6271. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  6272. return this.groups;
  6273. },
  6274. get offsets() {
  6275. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  6276. return this.groups;
  6277. },
  6278. addDrawCall: function ( start, count, indexOffset ) {
  6279. if ( indexOffset !== undefined ) {
  6280. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  6281. }
  6282. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  6283. this.addGroup( start, count );
  6284. },
  6285. clearDrawCalls: function () {
  6286. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  6287. this.clearGroups();
  6288. },
  6289. addGroup: function ( start, count, materialIndex ) {
  6290. this.groups.push( {
  6291. start: start,
  6292. count: count,
  6293. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6294. } );
  6295. },
  6296. clearGroups: function () {
  6297. this.groups = [];
  6298. },
  6299. setDrawRange: function ( start, count ) {
  6300. this.drawRange.start = start;
  6301. this.drawRange.count = count;
  6302. },
  6303. applyMatrix: function ( matrix ) {
  6304. var position = this.attributes.position;
  6305. if ( position !== undefined ) {
  6306. matrix.applyToVector3Array( position.array );
  6307. position.needsUpdate = true;
  6308. }
  6309. var normal = this.attributes.normal;
  6310. if ( normal !== undefined ) {
  6311. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6312. normalMatrix.applyToVector3Array( normal.array );
  6313. normal.needsUpdate = true;
  6314. }
  6315. if ( this.boundingBox !== null ) {
  6316. this.computeBoundingBox();
  6317. }
  6318. if ( this.boundingSphere !== null ) {
  6319. this.computeBoundingSphere();
  6320. }
  6321. },
  6322. rotateX: function () {
  6323. // rotate geometry around world x-axis
  6324. var m1;
  6325. return function rotateX( angle ) {
  6326. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6327. m1.makeRotationX( angle );
  6328. this.applyMatrix( m1 );
  6329. return this;
  6330. };
  6331. }(),
  6332. rotateY: function () {
  6333. // rotate geometry around world y-axis
  6334. var m1;
  6335. return function rotateY( angle ) {
  6336. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6337. m1.makeRotationY( angle );
  6338. this.applyMatrix( m1 );
  6339. return this;
  6340. };
  6341. }(),
  6342. rotateZ: function () {
  6343. // rotate geometry around world z-axis
  6344. var m1;
  6345. return function rotateZ( angle ) {
  6346. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6347. m1.makeRotationZ( angle );
  6348. this.applyMatrix( m1 );
  6349. return this;
  6350. };
  6351. }(),
  6352. translate: function () {
  6353. // translate geometry
  6354. var m1;
  6355. return function translate( x, y, z ) {
  6356. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6357. m1.makeTranslation( x, y, z );
  6358. this.applyMatrix( m1 );
  6359. return this;
  6360. };
  6361. }(),
  6362. scale: function () {
  6363. // scale geometry
  6364. var m1;
  6365. return function scale( x, y, z ) {
  6366. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6367. m1.makeScale( x, y, z );
  6368. this.applyMatrix( m1 );
  6369. return this;
  6370. };
  6371. }(),
  6372. lookAt: function () {
  6373. var obj;
  6374. return function lookAt( vector ) {
  6375. if ( obj === undefined ) obj = new THREE.Object3D();
  6376. obj.lookAt( vector );
  6377. obj.updateMatrix();
  6378. this.applyMatrix( obj.matrix );
  6379. };
  6380. }(),
  6381. center: function () {
  6382. this.computeBoundingBox();
  6383. var offset = this.boundingBox.center().negate();
  6384. this.translate( offset.x, offset.y, offset.z );
  6385. return offset;
  6386. },
  6387. setFromObject: function ( object ) {
  6388. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6389. var geometry = object.geometry;
  6390. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6391. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6392. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6393. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6394. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6395. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6396. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6397. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6398. }
  6399. if ( geometry.boundingSphere !== null ) {
  6400. this.boundingSphere = geometry.boundingSphere.clone();
  6401. }
  6402. if ( geometry.boundingBox !== null ) {
  6403. this.boundingBox = geometry.boundingBox.clone();
  6404. }
  6405. } else if ( object instanceof THREE.Mesh ) {
  6406. if ( geometry instanceof THREE.Geometry ) {
  6407. this.fromGeometry( geometry );
  6408. }
  6409. }
  6410. return this;
  6411. },
  6412. updateFromObject: function ( object ) {
  6413. var geometry = object.geometry;
  6414. if ( object instanceof THREE.Mesh ) {
  6415. var direct = geometry.__directGeometry;
  6416. if ( direct === undefined ) {
  6417. return this.fromGeometry( geometry );
  6418. }
  6419. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6420. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6421. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6422. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6423. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6424. geometry.verticesNeedUpdate = false;
  6425. geometry.normalsNeedUpdate = false;
  6426. geometry.colorsNeedUpdate = false;
  6427. geometry.uvsNeedUpdate = false;
  6428. geometry.groupsNeedUpdate = false;
  6429. geometry = direct;
  6430. }
  6431. if ( geometry.verticesNeedUpdate === true ) {
  6432. var attribute = this.attributes.position;
  6433. if ( attribute !== undefined ) {
  6434. attribute.copyVector3sArray( geometry.vertices );
  6435. attribute.needsUpdate = true;
  6436. }
  6437. geometry.verticesNeedUpdate = false;
  6438. }
  6439. if ( geometry.normalsNeedUpdate === true ) {
  6440. var attribute = this.attributes.normal;
  6441. if ( attribute !== undefined ) {
  6442. attribute.copyVector3sArray( geometry.normals );
  6443. attribute.needsUpdate = true;
  6444. }
  6445. geometry.normalsNeedUpdate = false;
  6446. }
  6447. if ( geometry.colorsNeedUpdate === true ) {
  6448. var attribute = this.attributes.color;
  6449. if ( attribute !== undefined ) {
  6450. attribute.copyColorsArray( geometry.colors );
  6451. attribute.needsUpdate = true;
  6452. }
  6453. geometry.colorsNeedUpdate = false;
  6454. }
  6455. if ( geometry.uvsNeedUpdate ) {
  6456. var attribute = this.attributes.uv;
  6457. if ( attribute !== undefined ) {
  6458. attribute.copyVector2sArray( geometry.uvs );
  6459. attribute.needsUpdate = true;
  6460. }
  6461. geometry.uvsNeedUpdate = false;
  6462. }
  6463. if ( geometry.lineDistancesNeedUpdate ) {
  6464. var attribute = this.attributes.lineDistance;
  6465. if ( attribute !== undefined ) {
  6466. attribute.copyArray( geometry.lineDistances );
  6467. attribute.needsUpdate = true;
  6468. }
  6469. geometry.lineDistancesNeedUpdate = false;
  6470. }
  6471. if ( geometry.groupsNeedUpdate ) {
  6472. geometry.computeGroups( object.geometry );
  6473. this.groups = geometry.groups;
  6474. geometry.groupsNeedUpdate = false;
  6475. }
  6476. return this;
  6477. },
  6478. fromGeometry: function ( geometry ) {
  6479. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6480. return this.fromDirectGeometry( geometry.__directGeometry );
  6481. },
  6482. fromDirectGeometry: function ( geometry ) {
  6483. var positions = new Float32Array( geometry.vertices.length * 3 );
  6484. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6485. if ( geometry.normals.length > 0 ) {
  6486. var normals = new Float32Array( geometry.normals.length * 3 );
  6487. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6488. }
  6489. if ( geometry.colors.length > 0 ) {
  6490. var colors = new Float32Array( geometry.colors.length * 3 );
  6491. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6492. }
  6493. if ( geometry.uvs.length > 0 ) {
  6494. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6495. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6496. }
  6497. if ( geometry.uvs2.length > 0 ) {
  6498. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6499. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6500. }
  6501. if ( geometry.indices.length > 0 ) {
  6502. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6503. var indices = new TypeArray( geometry.indices.length * 3 );
  6504. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6505. }
  6506. // groups
  6507. this.groups = geometry.groups;
  6508. // morphs
  6509. for ( var name in geometry.morphTargets ) {
  6510. var array = [];
  6511. var morphTargets = geometry.morphTargets[ name ];
  6512. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6513. var morphTarget = morphTargets[ i ];
  6514. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6515. array.push( attribute.copyVector3sArray( morphTarget ) );
  6516. }
  6517. this.morphAttributes[ name ] = array;
  6518. }
  6519. // skinning
  6520. if ( geometry.skinIndices.length > 0 ) {
  6521. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6522. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6523. }
  6524. if ( geometry.skinWeights.length > 0 ) {
  6525. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6526. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6527. }
  6528. //
  6529. if ( geometry.boundingSphere !== null ) {
  6530. this.boundingSphere = geometry.boundingSphere.clone();
  6531. }
  6532. if ( geometry.boundingBox !== null ) {
  6533. this.boundingBox = geometry.boundingBox.clone();
  6534. }
  6535. return this;
  6536. },
  6537. computeBoundingBox: function () {
  6538. var vector = new THREE.Vector3();
  6539. return function () {
  6540. if ( this.boundingBox === null ) {
  6541. this.boundingBox = new THREE.Box3();
  6542. }
  6543. var positions = this.attributes.position.array;
  6544. if ( positions ) {
  6545. var bb = this.boundingBox;
  6546. bb.makeEmpty();
  6547. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6548. vector.fromArray( positions, i );
  6549. bb.expandByPoint( vector );
  6550. }
  6551. }
  6552. if ( positions === undefined || positions.length === 0 ) {
  6553. this.boundingBox.min.set( 0, 0, 0 );
  6554. this.boundingBox.max.set( 0, 0, 0 );
  6555. }
  6556. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6557. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6558. }
  6559. };
  6560. }(),
  6561. computeBoundingSphere: function () {
  6562. var box = new THREE.Box3();
  6563. var vector = new THREE.Vector3();
  6564. return function () {
  6565. if ( this.boundingSphere === null ) {
  6566. this.boundingSphere = new THREE.Sphere();
  6567. }
  6568. var positions = this.attributes.position.array;
  6569. if ( positions ) {
  6570. box.makeEmpty();
  6571. var center = this.boundingSphere.center;
  6572. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6573. vector.fromArray( positions, i );
  6574. box.expandByPoint( vector );
  6575. }
  6576. box.center( center );
  6577. // hoping to find a boundingSphere with a radius smaller than the
  6578. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6579. var maxRadiusSq = 0;
  6580. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6581. vector.fromArray( positions, i );
  6582. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6583. }
  6584. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6585. if ( isNaN( this.boundingSphere.radius ) ) {
  6586. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6587. }
  6588. }
  6589. };
  6590. }(),
  6591. computeFaceNormals: function () {
  6592. // backwards compatibility
  6593. },
  6594. computeVertexNormals: function () {
  6595. var index = this.index;
  6596. var attributes = this.attributes;
  6597. var groups = this.groups;
  6598. if ( attributes.position ) {
  6599. var positions = attributes.position.array;
  6600. if ( attributes.normal === undefined ) {
  6601. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6602. } else {
  6603. // reset existing normals to zero
  6604. var normals = attributes.normal.array;
  6605. for ( var i = 0, il = normals.length; i < il; i ++ ) {
  6606. normals[ i ] = 0;
  6607. }
  6608. }
  6609. var normals = attributes.normal.array;
  6610. var vA, vB, vC,
  6611. pA = new THREE.Vector3(),
  6612. pB = new THREE.Vector3(),
  6613. pC = new THREE.Vector3(),
  6614. cb = new THREE.Vector3(),
  6615. ab = new THREE.Vector3();
  6616. // indexed elements
  6617. if ( index ) {
  6618. var indices = index.array;
  6619. if ( groups.length === 0 ) {
  6620. this.addGroup( 0, indices.length );
  6621. }
  6622. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6623. var group = groups[ j ];
  6624. var start = group.start;
  6625. var count = group.count;
  6626. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6627. vA = indices[ i + 0 ] * 3;
  6628. vB = indices[ i + 1 ] * 3;
  6629. vC = indices[ i + 2 ] * 3;
  6630. pA.fromArray( positions, vA );
  6631. pB.fromArray( positions, vB );
  6632. pC.fromArray( positions, vC );
  6633. cb.subVectors( pC, pB );
  6634. ab.subVectors( pA, pB );
  6635. cb.cross( ab );
  6636. normals[ vA ] += cb.x;
  6637. normals[ vA + 1 ] += cb.y;
  6638. normals[ vA + 2 ] += cb.z;
  6639. normals[ vB ] += cb.x;
  6640. normals[ vB + 1 ] += cb.y;
  6641. normals[ vB + 2 ] += cb.z;
  6642. normals[ vC ] += cb.x;
  6643. normals[ vC + 1 ] += cb.y;
  6644. normals[ vC + 2 ] += cb.z;
  6645. }
  6646. }
  6647. } else {
  6648. // non-indexed elements (unconnected triangle soup)
  6649. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6650. pA.fromArray( positions, i );
  6651. pB.fromArray( positions, i + 3 );
  6652. pC.fromArray( positions, i + 6 );
  6653. cb.subVectors( pC, pB );
  6654. ab.subVectors( pA, pB );
  6655. cb.cross( ab );
  6656. normals[ i ] = cb.x;
  6657. normals[ i + 1 ] = cb.y;
  6658. normals[ i + 2 ] = cb.z;
  6659. normals[ i + 3 ] = cb.x;
  6660. normals[ i + 4 ] = cb.y;
  6661. normals[ i + 5 ] = cb.z;
  6662. normals[ i + 6 ] = cb.x;
  6663. normals[ i + 7 ] = cb.y;
  6664. normals[ i + 8 ] = cb.z;
  6665. }
  6666. }
  6667. this.normalizeNormals();
  6668. attributes.normal.needsUpdate = true;
  6669. }
  6670. },
  6671. computeTangents: function () {
  6672. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  6673. },
  6674. computeOffsets: function ( size ) {
  6675. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.')
  6676. },
  6677. merge: function ( geometry, offset ) {
  6678. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6679. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6680. return;
  6681. }
  6682. if ( offset === undefined ) offset = 0;
  6683. var attributes = this.attributes;
  6684. for ( var key in attributes ) {
  6685. if ( geometry.attributes[ key ] === undefined ) continue;
  6686. var attribute1 = attributes[ key ];
  6687. var attributeArray1 = attribute1.array;
  6688. var attribute2 = geometry.attributes[ key ];
  6689. var attributeArray2 = attribute2.array;
  6690. var attributeSize = attribute2.itemSize;
  6691. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6692. attributeArray1[ j ] = attributeArray2[ i ];
  6693. }
  6694. }
  6695. return this;
  6696. },
  6697. normalizeNormals: function () {
  6698. var normals = this.attributes.normal.array;
  6699. var x, y, z, n;
  6700. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6701. x = normals[ i ];
  6702. y = normals[ i + 1 ];
  6703. z = normals[ i + 2 ];
  6704. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6705. normals[ i ] *= n;
  6706. normals[ i + 1 ] *= n;
  6707. normals[ i + 2 ] *= n;
  6708. }
  6709. },
  6710. toJSON: function () {
  6711. var data = {
  6712. metadata: {
  6713. version: 4.4,
  6714. type: 'BufferGeometry',
  6715. generator: 'BufferGeometry.toJSON'
  6716. }
  6717. };
  6718. // standard BufferGeometry serialization
  6719. data.uuid = this.uuid;
  6720. data.type = this.type;
  6721. if ( this.name !== '' ) data.name = this.name;
  6722. if ( this.parameters !== undefined ) {
  6723. var parameters = this.parameters;
  6724. for ( var key in parameters ) {
  6725. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6726. }
  6727. return data;
  6728. }
  6729. data.data = { attributes: {} };
  6730. var index = this.index;
  6731. if ( index !== null ) {
  6732. var array = Array.prototype.slice.call( index.array );
  6733. data.data.index = {
  6734. type: index.array.constructor.name,
  6735. array: array
  6736. };
  6737. }
  6738. var attributes = this.attributes;
  6739. for ( var key in attributes ) {
  6740. var attribute = attributes[ key ];
  6741. var array = Array.prototype.slice.call( attribute.array );
  6742. data.data.attributes[ key ] = {
  6743. itemSize: attribute.itemSize,
  6744. type: attribute.array.constructor.name,
  6745. array: array
  6746. };
  6747. }
  6748. var groups = this.groups;
  6749. if ( groups.length > 0 ) {
  6750. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  6751. }
  6752. var boundingSphere = this.boundingSphere;
  6753. if ( boundingSphere !== null ) {
  6754. data.data.boundingSphere = {
  6755. center: boundingSphere.center.toArray(),
  6756. radius: boundingSphere.radius
  6757. };
  6758. }
  6759. return data;
  6760. },
  6761. clone: function () {
  6762. return new this.constructor().copy( this );
  6763. },
  6764. copy: function ( source ) {
  6765. var index = source.index;
  6766. if ( index !== null ) {
  6767. this.setIndex( index.clone() );
  6768. }
  6769. var attributes = source.attributes;
  6770. for ( var name in attributes ) {
  6771. var attribute = attributes[ name ];
  6772. this.addAttribute( name, attribute.clone() );
  6773. }
  6774. var groups = source.groups;
  6775. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6776. var group = groups[ i ];
  6777. this.addGroup( group.start, group.count );
  6778. }
  6779. return this;
  6780. },
  6781. dispose: function () {
  6782. this.dispatchEvent( { type: 'dispose' } );
  6783. }
  6784. };
  6785. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  6786. THREE.BufferGeometry.MaxIndex = 65535;
  6787. // File:src/core/InstancedBufferGeometry.js
  6788. /**
  6789. * @author benaadams / https://twitter.com/ben_a_adams
  6790. */
  6791. THREE.InstancedBufferGeometry = function () {
  6792. THREE.BufferGeometry.call( this );
  6793. this.type = 'InstancedBufferGeometry';
  6794. this.maxInstancedCount = undefined;
  6795. };
  6796. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  6797. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  6798. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  6799. this.groups.push( {
  6800. start: start,
  6801. count: count,
  6802. instances: instances
  6803. } );
  6804. };
  6805. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  6806. var index = source.index;
  6807. if ( index !== null ) {
  6808. this.setIndex( index.clone() );
  6809. }
  6810. var attributes = source.attributes;
  6811. for ( var name in attributes ) {
  6812. var attribute = attributes[ name ];
  6813. this.addAttribute( name, attribute.clone() );
  6814. }
  6815. var groups = source.groups;
  6816. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  6817. var group = groups[ i ];
  6818. this.addGroup( group.start, group.count, group.instances );
  6819. }
  6820. return this;
  6821. };
  6822. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  6823. // File:src/animation/AnimationAction.js
  6824. /**
  6825. *
  6826. * A clip that has been explicitly scheduled.
  6827. *
  6828. * @author Ben Houston / http://clara.io/
  6829. * @author David Sarno / http://lighthaus.us/
  6830. */
  6831. THREE.AnimationAction = function ( clip, startTime, timeScale, weight, loop ) {
  6832. if ( clip === undefined ) throw new Error( 'clip is null' );
  6833. this.clip = clip;
  6834. this.localRoot = null;
  6835. this.startTime = startTime || 0;
  6836. this.timeScale = timeScale || 1;
  6837. this.weight = weight || 1;
  6838. this.loop = loop || THREE.LoopRepeat;
  6839. this.loopCount = 0;
  6840. this.enabled = true; // allow for easy disabling of the action.
  6841. this.actionTime = - this.startTime;
  6842. this.clipTime = 0;
  6843. this.propertyBindings = [];
  6844. };
  6845. /*
  6846. THREE.LoopOnce = 2200;
  6847. THREE.LoopRepeat = 2201;
  6848. THREE.LoopPingPing = 2202;
  6849. */
  6850. THREE.AnimationAction.prototype = {
  6851. constructor: THREE.AnimationAction,
  6852. setLocalRoot: function( localRoot ) {
  6853. this.localRoot = localRoot;
  6854. return this;
  6855. },
  6856. updateTime: function( clipDeltaTime ) {
  6857. var previousClipTime = this.clipTime;
  6858. var previousLoopCount = this.loopCount;
  6859. var previousActionTime = this.actionTime;
  6860. var duration = this.clip.duration;
  6861. this.actionTime = this.actionTime + clipDeltaTime;
  6862. if ( this.loop === THREE.LoopOnce ) {
  6863. this.loopCount = 0;
  6864. this.clipTime = Math.min( Math.max( this.actionTime, 0 ), duration );
  6865. // if time is changed since last time, see if we have hit a start/end limit
  6866. if ( this.clipTime !== previousClipTime ) {
  6867. if ( this.clipTime === duration ) {
  6868. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: 1 } );
  6869. } else if ( this.clipTime === 0 ) {
  6870. this.mixer.dispatchEvent( { type: 'finished', action: this, direction: -1 } );
  6871. }
  6872. }
  6873. return this.clipTime;
  6874. }
  6875. this.loopCount = Math.floor( this.actionTime / duration );
  6876. var newClipTime = this.actionTime - this.loopCount * duration;
  6877. newClipTime = newClipTime % duration;
  6878. // if we are ping pong looping, ensure that we go backwards when appropriate
  6879. if ( this.loop == THREE.LoopPingPong ) {
  6880. if ( Math.abs( this.loopCount % 2 ) === 1 ) {
  6881. newClipTime = duration - newClipTime;
  6882. }
  6883. }
  6884. this.clipTime = newClipTime;
  6885. if ( this.loopCount !== previousLoopCount ) {
  6886. this.mixer.dispatchEvent( { type: 'loop', action: this, loopDelta: ( this.loopCount - this.loopCount ) } );
  6887. }
  6888. return this.clipTime;
  6889. },
  6890. syncWith: function( action ) {
  6891. this.actionTime = action.actionTime;
  6892. this.timeScale = action.timeScale;
  6893. return this;
  6894. },
  6895. warpToDuration: function( duration ) {
  6896. this.timeScale = this.clip.duration / duration;
  6897. return this;
  6898. },
  6899. init: function( time ) {
  6900. this.clipTime = time - this.startTime;
  6901. return this;
  6902. },
  6903. update: function( clipDeltaTime ) {
  6904. this.updateTime( clipDeltaTime );
  6905. var clipResults = this.clip.getAt( this.clipTime );
  6906. return clipResults;
  6907. },
  6908. getTimeScaleAt: function( time ) {
  6909. if ( this.timeScale.getAt ) {
  6910. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6911. return this.timeScale.getAt( time );
  6912. }
  6913. return this.timeScale;
  6914. },
  6915. getWeightAt: function( time ) {
  6916. if ( this.weight.getAt ) {
  6917. // pass in time, not clip time, allows for fadein/fadeout across multiple loops of the clip
  6918. return this.weight.getAt( time );
  6919. }
  6920. return this.weight;
  6921. }
  6922. };
  6923. // File:src/animation/AnimationClip.js
  6924. /**
  6925. *
  6926. * Reusable set of Tracks that represent an animation.
  6927. *
  6928. * @author Ben Houston / http://clara.io/
  6929. * @author David Sarno / http://lighthaus.us/
  6930. */
  6931. THREE.AnimationClip = function ( name, duration, tracks ) {
  6932. this.name = name;
  6933. this.tracks = tracks;
  6934. this.duration = ( duration !== undefined ) ? duration : -1;
  6935. // this means it should figure out its duration by scanning the tracks
  6936. if ( this.duration < 0 ) {
  6937. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6938. var track = this.tracks[i];
  6939. this.duration = Math.max( track.keys[ track.keys.length - 1 ].time );
  6940. }
  6941. }
  6942. // maybe only do these on demand, as doing them here could potentially slow down loading
  6943. // but leaving these here during development as this ensures a lot of testing of these functions
  6944. this.trim();
  6945. this.optimize();
  6946. this.results = [];
  6947. };
  6948. THREE.AnimationClip.prototype = {
  6949. constructor: THREE.AnimationClip,
  6950. getAt: function( clipTime ) {
  6951. clipTime = Math.max( 0, Math.min( clipTime, this.duration ) );
  6952. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6953. var track = this.tracks[ i ];
  6954. this.results[ i ] = track.getAt( clipTime );
  6955. }
  6956. return this.results;
  6957. },
  6958. trim: function() {
  6959. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6960. this.tracks[ i ].trim( 0, this.duration );
  6961. }
  6962. return this;
  6963. },
  6964. optimize: function() {
  6965. for ( var i = 0; i < this.tracks.length; i ++ ) {
  6966. this.tracks[ i ].optimize();
  6967. }
  6968. return this;
  6969. }
  6970. };
  6971. THREE.AnimationClip.CreateFromMorphTargetSequence = function( name, morphTargetSequence, fps ) {
  6972. var numMorphTargets = morphTargetSequence.length;
  6973. var tracks = [];
  6974. for ( var i = 0; i < numMorphTargets; i ++ ) {
  6975. var keys = [];
  6976. keys.push( { time: ( i + numMorphTargets - 1 ) % numMorphTargets, value: 0 } );
  6977. keys.push( { time: i, value: 1 } );
  6978. keys.push( { time: ( i + 1 ) % numMorphTargets, value: 0 } );
  6979. keys.sort( THREE.KeyframeTrack.keyComparer );
  6980. // if there is a key at the first frame, duplicate it as the last frame as well for perfect loop.
  6981. if ( keys[0].time === 0 ) {
  6982. keys.push( {
  6983. time: numMorphTargets,
  6984. value: keys[0].value
  6985. });
  6986. }
  6987. tracks.push( new THREE.NumberKeyframeTrack( '.morphTargetInfluences[' + morphTargetSequence[i].name + ']', keys ).scale( 1.0 / fps ) );
  6988. }
  6989. return new THREE.AnimationClip( name, -1, tracks );
  6990. };
  6991. THREE.AnimationClip.findByName = function( clipArray, name ) {
  6992. for ( var i = 0; i < clipArray.length; i ++ ) {
  6993. if ( clipArray[i].name === name ) {
  6994. return clipArray[i];
  6995. }
  6996. }
  6997. return null;
  6998. };
  6999. THREE.AnimationClip.CreateClipsFromMorphTargetSequences = function( morphTargets, fps ) {
  7000. var animationToMorphTargets = {};
  7001. // tested with https://regex101.com/ on trick sequences such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7002. var pattern = /^([\w-]*?)([\d]+)$/;
  7003. // sort morph target names into animation groups based patterns like Walk_001, Walk_002, Run_001, Run_002
  7004. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7005. var morphTarget = morphTargets[ i ];
  7006. var parts = morphTarget.name.match( pattern );
  7007. if ( parts && parts.length > 1 ) {
  7008. var name = parts[ 1 ];
  7009. var animationMorphTargets = animationToMorphTargets[ name ];
  7010. if ( ! animationMorphTargets ) {
  7011. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7012. }
  7013. animationMorphTargets.push( morphTarget );
  7014. }
  7015. }
  7016. var clips = [];
  7017. for ( var name in animationToMorphTargets ) {
  7018. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7019. }
  7020. return clips;
  7021. };
  7022. // parse the standard JSON format for clips
  7023. THREE.AnimationClip.parse = function( json ) {
  7024. var tracks = [];
  7025. for ( var i = 0; i < json.tracks.length; i ++ ) {
  7026. tracks.push( THREE.KeyframeTrack.parse( json.tracks[i] ).scale( 1.0 / json.fps ) );
  7027. }
  7028. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7029. };
  7030. // parse the animation.hierarchy format
  7031. THREE.AnimationClip.parseAnimation = function( animation, bones, nodeName ) {
  7032. if ( ! animation ) {
  7033. console.error( " no animation in JSONLoader data" );
  7034. return null;
  7035. }
  7036. var convertTrack = function( trackName, animationKeys, propertyName, trackType, animationKeyToValueFunc ) {
  7037. var keys = [];
  7038. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7039. var animationKey = animationKeys[k];
  7040. if ( animationKey[propertyName] !== undefined ) {
  7041. keys.push( { time: animationKey.time, value: animationKeyToValueFunc( animationKey ) } );
  7042. }
  7043. }
  7044. // only return track if there are actually keys.
  7045. if ( keys.length > 0 ) {
  7046. return new trackType( trackName, keys );
  7047. }
  7048. return null;
  7049. };
  7050. var tracks = [];
  7051. var clipName = animation.name || 'default';
  7052. var duration = animation.length || -1; // automatic length determination in AnimationClip.
  7053. var fps = animation.fps || 30;
  7054. var hierarchyTracks = animation.hierarchy || [];
  7055. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7056. var animationKeys = hierarchyTracks[ h ].keys;
  7057. // skip empty tracks
  7058. if ( ! animationKeys || animationKeys.length == 0 ) {
  7059. continue;
  7060. }
  7061. // process morph targets in a way exactly compatible with AnimationHandler.init( animation )
  7062. if ( animationKeys[0].morphTargets ) {
  7063. // figure out all morph targets used in this track
  7064. var morphTargetNames = {};
  7065. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7066. if ( animationKeys[k].morphTargets ) {
  7067. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7068. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7069. }
  7070. }
  7071. }
  7072. // create a track for each morph target with all zero morphTargetInfluences except for the keys in which the morphTarget is named.
  7073. for ( var morphTargetName in morphTargetNames ) {
  7074. var keys = [];
  7075. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7076. var animationKey = animationKeys[k];
  7077. keys.push( {
  7078. time: animationKey.time,
  7079. value: (( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7080. });
  7081. }
  7082. tracks.push( new THREE.NumberKeyframeTrack( nodeName + '.morphTargetInfluence[' + morphTargetName + ']', keys ) );
  7083. }
  7084. duration = morphTargetNames.length * ( fps || 1.0 );
  7085. } else {
  7086. var boneName = nodeName + '.bones[' + bones[ h ].name + ']';
  7087. // track contains positions...
  7088. var positionTrack = convertTrack( boneName + '.position', animationKeys, 'pos', THREE.VectorKeyframeTrack, function( animationKey ) {
  7089. return new THREE.Vector3().fromArray( animationKey.pos )
  7090. } );
  7091. if ( positionTrack ) tracks.push( positionTrack );
  7092. // track contains quaternions...
  7093. var quaternionTrack = convertTrack( boneName + '.quaternion', animationKeys, 'rot', THREE.QuaternionKeyframeTrack, function( animationKey ) {
  7094. if ( animationKey.rot.slerp ) {
  7095. return animationKey.rot.clone();
  7096. } else {
  7097. return new THREE.Quaternion().fromArray( animationKey.rot );
  7098. }
  7099. } );
  7100. if ( quaternionTrack ) tracks.push( quaternionTrack );
  7101. // track contains quaternions...
  7102. var scaleTrack = convertTrack( boneName + '.scale', animationKeys, 'scl', THREE.VectorKeyframeTrack, function( animationKey ) {
  7103. return new THREE.Vector3().fromArray( animationKey.scl )
  7104. } );
  7105. if ( scaleTrack ) tracks.push( scaleTrack );
  7106. }
  7107. }
  7108. if ( tracks.length === 0 ) {
  7109. return null;
  7110. }
  7111. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7112. return clip;
  7113. };
  7114. // File:src/animation/AnimationMixer.js
  7115. /**
  7116. *
  7117. * Mixes together the AnimationClips scheduled by AnimationActions and applies them to the root and subtree
  7118. *
  7119. *
  7120. * @author Ben Houston / http://clara.io/
  7121. * @author David Sarno / http://lighthaus.us/
  7122. */
  7123. THREE.AnimationMixer = function( root ) {
  7124. this.root = root;
  7125. this.time = 0;
  7126. this.timeScale = 1.0;
  7127. this.actions = [];
  7128. this.propertyBindingMap = {};
  7129. };
  7130. THREE.AnimationMixer.prototype = {
  7131. constructor: THREE.AnimationMixer,
  7132. addAction: function( action ) {
  7133. // TODO: check for duplicate action names? Or provide each action with a UUID?
  7134. this.actions.push( action );
  7135. action.init( this.time );
  7136. action.mixer = this;
  7137. var tracks = action.clip.tracks;
  7138. var root = action.localRoot || this.root;
  7139. for ( var i = 0; i < tracks.length; i ++ ) {
  7140. var track = tracks[ i ];
  7141. var propertyBindingKey = root.uuid + '-' + track.name;
  7142. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7143. if ( propertyBinding === undefined ) {
  7144. propertyBinding = new THREE.PropertyBinding( root, track.name );
  7145. this.propertyBindingMap[ propertyBindingKey ] = propertyBinding;
  7146. }
  7147. // push in the same order as the tracks.
  7148. action.propertyBindings.push( propertyBinding );
  7149. // track usages of shared property bindings, because if we leave too many around, the mixer can get slow
  7150. propertyBinding.referenceCount += 1;
  7151. }
  7152. },
  7153. removeAllActions: function() {
  7154. for ( var i = 0; i < this.actions.length; i ++ ) {
  7155. this.actions[i].mixer = null;
  7156. }
  7157. // unbind all property bindings
  7158. for ( var properyBindingKey in this.propertyBindingMap ) {
  7159. this.propertyBindingMap[ properyBindingKey ].unbind();
  7160. }
  7161. this.actions = [];
  7162. this.propertyBindingMap = {};
  7163. return this;
  7164. },
  7165. removeAction: function( action ) {
  7166. var index = this.actions.indexOf( action );
  7167. if ( index !== - 1 ) {
  7168. this.actions.splice( index, 1 );
  7169. action.mixer = null;
  7170. }
  7171. // remove unused property bindings because if we leave them around the mixer can get slow
  7172. var root = action.localRoot || this.root;
  7173. var tracks = action.clip.tracks;
  7174. for ( var i = 0; i < tracks.length; i ++ ) {
  7175. var track = tracks[ i ];
  7176. var propertyBindingKey = root.uuid + '-' + track.name;
  7177. var propertyBinding = this.propertyBindingMap[ propertyBindingKey ];
  7178. propertyBinding.referenceCount -= 1;
  7179. if ( propertyBinding.referenceCount <= 0 ) {
  7180. propertyBinding.unbind();
  7181. delete this.propertyBindingMap[ propertyBindingKey ];
  7182. }
  7183. }
  7184. return this;
  7185. },
  7186. // can be optimized if needed
  7187. findActionByName: function( name ) {
  7188. for ( var i = 0; i < this.actions.length; i ++ ) {
  7189. if ( this.actions[i].name === name ) return this.actions[i];
  7190. }
  7191. return null;
  7192. },
  7193. play: function( action, optionalFadeInDuration ) {
  7194. action.startTime = this.time;
  7195. this.addAction( action );
  7196. return this;
  7197. },
  7198. fadeOut: function( action, duration ) {
  7199. var keys = [];
  7200. keys.push( { time: this.time, value: 1 } );
  7201. keys.push( { time: this.time + duration, value: 0 } );
  7202. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7203. return this;
  7204. },
  7205. fadeIn: function( action, duration ) {
  7206. var keys = [];
  7207. keys.push( { time: this.time, value: 0 } );
  7208. keys.push( { time: this.time + duration, value: 1 } );
  7209. action.weight = new THREE.NumberKeyframeTrack( "weight", keys );
  7210. return this;
  7211. },
  7212. warp: function( action, startTimeScale, endTimeScale, duration ) {
  7213. var keys = [];
  7214. keys.push( { time: this.time, value: startTimeScale } );
  7215. keys.push( { time: this.time + duration, value: endTimeScale } );
  7216. action.timeScale = new THREE.NumberKeyframeTrack( "timeScale", keys );
  7217. return this;
  7218. },
  7219. crossFade: function( fadeOutAction, fadeInAction, duration, warp ) {
  7220. this.fadeOut( fadeOutAction, duration );
  7221. this.fadeIn( fadeInAction, duration );
  7222. if ( warp ) {
  7223. var startEndRatio = fadeOutAction.clip.duration / fadeInAction.clip.duration;
  7224. var endStartRatio = 1.0 / startEndRatio;
  7225. this.warp( fadeOutAction, 1.0, startEndRatio, duration );
  7226. this.warp( fadeInAction, endStartRatio, 1.0, duration );
  7227. }
  7228. return this;
  7229. },
  7230. update: function( deltaTime ) {
  7231. var mixerDeltaTime = deltaTime * this.timeScale;
  7232. this.time += mixerDeltaTime;
  7233. for ( var i = 0; i < this.actions.length; i ++ ) {
  7234. var action = this.actions[i];
  7235. var weight = action.getWeightAt( this.time );
  7236. var actionTimeScale = action.getTimeScaleAt( this.time );
  7237. var actionDeltaTime = mixerDeltaTime * actionTimeScale;
  7238. var actionResults = action.update( actionDeltaTime );
  7239. if ( action.weight <= 0 || ! action.enabled ) continue;
  7240. for ( var j = 0; j < actionResults.length; j ++ ) {
  7241. var name = action.clip.tracks[j].name;
  7242. action.propertyBindings[ j ].accumulate( actionResults[j], weight );
  7243. }
  7244. }
  7245. // apply to nodes
  7246. for ( var propertyBindingKey in this.propertyBindingMap ) {
  7247. this.propertyBindingMap[ propertyBindingKey ].apply();
  7248. }
  7249. return this;
  7250. }
  7251. };
  7252. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7253. // File:src/animation/AnimationUtils.js
  7254. /**
  7255. * @author Ben Houston / http://clara.io/
  7256. * @author David Sarno / http://lighthaus.us/
  7257. */
  7258. THREE.AnimationUtils = {
  7259. getEqualsFunc: function( exemplarValue ) {
  7260. if ( exemplarValue.equals ) {
  7261. return function equals_object( a, b ) {
  7262. return a.equals( b );
  7263. }
  7264. }
  7265. return function equals_primitive( a, b ) {
  7266. return ( a === b );
  7267. };
  7268. },
  7269. clone: function( exemplarValue ) {
  7270. var typeName = typeof exemplarValue;
  7271. if ( typeName === "object" ) {
  7272. if ( exemplarValue.clone ) {
  7273. return exemplarValue.clone();
  7274. }
  7275. console.error( "can not figure out how to copy exemplarValue", exemplarValue );
  7276. }
  7277. return exemplarValue;
  7278. },
  7279. lerp: function( a, b, alpha, interTrack ) {
  7280. var lerpFunc = THREE.AnimationUtils.getLerpFunc( a, interTrack );
  7281. return lerpFunc( a, b, alpha );
  7282. },
  7283. lerp_object: function( a, b, alpha ) {
  7284. return a.lerp( b, alpha );
  7285. },
  7286. slerp_object: function( a, b, alpha ) {
  7287. return a.slerp( b, alpha );
  7288. },
  7289. lerp_number: function( a, b, alpha ) {
  7290. return a * ( 1 - alpha ) + b * alpha;
  7291. },
  7292. lerp_boolean: function( a, b, alpha ) {
  7293. return ( alpha < 0.5 ) ? a : b;
  7294. },
  7295. lerp_boolean_immediate: function( a, b, alpha ) {
  7296. return a;
  7297. },
  7298. lerp_string: function( a, b, alpha ) {
  7299. return ( alpha < 0.5 ) ? a : b;
  7300. },
  7301. lerp_string_immediate: function( a, b, alpha ) {
  7302. return a;
  7303. },
  7304. // NOTE: this is an accumulator function that modifies the first argument (e.g. a). This is to minimize memory alocations.
  7305. getLerpFunc: function( exemplarValue, interTrack ) {
  7306. if ( exemplarValue === undefined || exemplarValue === null ) throw new Error( "examplarValue is null" );
  7307. var typeName = typeof exemplarValue;
  7308. switch( typeName ) {
  7309. case "object":
  7310. if ( exemplarValue.lerp ) {
  7311. return THREE.AnimationUtils.lerp_object;
  7312. }
  7313. if ( exemplarValue.slerp ) {
  7314. return THREE.AnimationUtils.slerp_object;
  7315. }
  7316. break;
  7317. case "number":
  7318. return THREE.AnimationUtils.lerp_number;
  7319. case "boolean":
  7320. if ( interTrack ) {
  7321. return THREE.AnimationUtils.lerp_boolean;
  7322. } else {
  7323. return THREE.AnimationUtils.lerp_boolean_immediate;
  7324. }
  7325. case "string":
  7326. if ( interTrack ) {
  7327. return THREE.AnimationUtils.lerp_string;
  7328. } else {
  7329. return THREE.AnimationUtils.lerp_string_immediate;
  7330. }
  7331. }
  7332. }
  7333. };
  7334. // File:src/animation/KeyframeTrack.js
  7335. /**
  7336. *
  7337. * A Track that returns a keyframe interpolated value, currently linearly interpolated
  7338. *
  7339. * @author Ben Houston / http://clara.io/
  7340. * @author David Sarno / http://lighthaus.us/
  7341. */
  7342. THREE.KeyframeTrack = function ( name, keys ) {
  7343. if ( name === undefined ) throw new Error( "track name is undefined" );
  7344. if ( keys === undefined || keys.length === 0 ) throw new Error( "no keys in track named " + name );
  7345. this.name = name;
  7346. this.keys = keys; // time in seconds, value as value
  7347. // the index of the last result, used as a starting point for local search.
  7348. this.lastIndex = 0;
  7349. this.validate();
  7350. this.optimize();
  7351. };
  7352. THREE.KeyframeTrack.prototype = {
  7353. constructor: THREE.KeyframeTrack,
  7354. getAt: function( time ) {
  7355. // this can not go higher than this.keys.length.
  7356. while( ( this.lastIndex < this.keys.length ) && ( time >= this.keys[this.lastIndex].time ) ) {
  7357. this.lastIndex ++;
  7358. };
  7359. // this can not go lower than 0.
  7360. while( ( this.lastIndex > 0 ) && ( time < this.keys[this.lastIndex - 1].time ) ) {
  7361. this.lastIndex --;
  7362. }
  7363. if ( this.lastIndex >= this.keys.length ) {
  7364. this.setResult( this.keys[ this.keys.length - 1 ].value );
  7365. return this.result;
  7366. }
  7367. if ( this.lastIndex === 0 ) {
  7368. this.setResult( this.keys[ 0 ].value );
  7369. return this.result;
  7370. }
  7371. var prevKey = this.keys[ this.lastIndex - 1 ];
  7372. this.setResult( prevKey.value );
  7373. // if true, means that prev/current keys are identical, thus no interpolation required.
  7374. if ( prevKey.constantToNext ) {
  7375. return this.result;
  7376. }
  7377. // linear interpolation to start with
  7378. var currentKey = this.keys[ this.lastIndex ];
  7379. var alpha = ( time - prevKey.time ) / ( currentKey.time - prevKey.time );
  7380. this.result = this.lerpValues( this.result, currentKey.value, alpha );
  7381. return this.result;
  7382. },
  7383. // move all keyframes either forwards or backwards in time
  7384. shift: function( timeOffset ) {
  7385. if ( timeOffset !== 0.0 ) {
  7386. for ( var i = 0; i < this.keys.length; i ++ ) {
  7387. this.keys[i].time += timeOffset;
  7388. }
  7389. }
  7390. return this;
  7391. },
  7392. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  7393. scale: function( timeScale ) {
  7394. if ( timeScale !== 1.0 ) {
  7395. for ( var i = 0; i < this.keys.length; i ++ ) {
  7396. this.keys[i].time *= timeScale;
  7397. }
  7398. }
  7399. return this;
  7400. },
  7401. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  7402. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  7403. trim: function( startTime, endTime ) {
  7404. var firstKeysToRemove = 0;
  7405. for ( var i = 1; i < this.keys.length; i ++ ) {
  7406. if ( this.keys[i] <= startTime ) {
  7407. firstKeysToRemove ++;
  7408. }
  7409. }
  7410. var lastKeysToRemove = 0;
  7411. for ( var i = this.keys.length - 2; i > 0; i ++ ) {
  7412. if ( this.keys[i] >= endTime ) {
  7413. lastKeysToRemove ++;
  7414. } else {
  7415. break;
  7416. }
  7417. }
  7418. // remove last keys first because it doesn't affect the position of the first keys (the otherway around doesn't work as easily)
  7419. if ( ( firstKeysToRemove + lastKeysToRemove ) > 0 ) {
  7420. this.keys = this.keys.splice( firstKeysToRemove, this.keys.length - lastKeysToRemove - firstKeysToRemove );;
  7421. }
  7422. return this;
  7423. },
  7424. /* NOTE: This is commented out because we really shouldn't have to handle unsorted key lists
  7425. Tracks with out of order keys should be considered to be invalid. - bhouston
  7426. sort: function() {
  7427. this.keys.sort( THREE.KeyframeTrack.keyComparer );
  7428. return this;
  7429. },*/
  7430. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  7431. // One could eventually ensure that all key.values in a track are all of the same type (otherwise interpolation makes no sense.)
  7432. validate: function() {
  7433. var prevKey = null;
  7434. if ( this.keys.length === 0 ) {
  7435. console.error( " track is empty, no keys", this );
  7436. return;
  7437. }
  7438. for ( var i = 0; i < this.keys.length; i ++ ) {
  7439. var currKey = this.keys[i];
  7440. if ( ! currKey ) {
  7441. console.error( " key is null in track", this, i );
  7442. return;
  7443. }
  7444. if ( ( typeof currKey.time ) !== 'number' || Number.isNaN( currKey.time ) ) {
  7445. console.error( " key.time is not a valid number", this, i, currKey );
  7446. return;
  7447. }
  7448. if ( currKey.value === undefined || currKey.value === null) {
  7449. console.error( " key.value is null in track", this, i, currKey );
  7450. return;
  7451. }
  7452. if ( prevKey && prevKey.time > currKey.time ) {
  7453. console.error( " key.time is less than previous key time, out of order keys", this, i, currKey, prevKey );
  7454. return;
  7455. }
  7456. prevKey = currKey;
  7457. }
  7458. return this;
  7459. },
  7460. // currently only removes equivalent sequential keys (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0), which are common in morph target animations
  7461. optimize: function() {
  7462. var newKeys = [];
  7463. var prevKey = this.keys[0];
  7464. newKeys.push( prevKey );
  7465. var equalsFunc = THREE.AnimationUtils.getEqualsFunc( prevKey.value );
  7466. for ( var i = 1; i < this.keys.length - 1; i ++ ) {
  7467. var currKey = this.keys[i];
  7468. var nextKey = this.keys[i+1];
  7469. // if prevKey & currKey are the same time, remove currKey. If you want immediate adjacent keys, use an epsilon offset
  7470. // it is not possible to have two keys at the same time as we sort them. The sort is not stable on keys with the same time.
  7471. if ( ( prevKey.time === currKey.time ) ) {
  7472. continue;
  7473. }
  7474. // remove completely unnecessary keyframes that are the same as their prev and next keys
  7475. if ( this.compareValues( prevKey.value, currKey.value ) && this.compareValues( currKey.value, nextKey.value ) ) {
  7476. continue;
  7477. }
  7478. // determine if interpolation is required
  7479. prevKey.constantToNext = this.compareValues( prevKey.value, currKey.value );
  7480. newKeys.push( currKey );
  7481. prevKey = currKey;
  7482. }
  7483. newKeys.push( this.keys[ this.keys.length - 1 ] );
  7484. this.keys = newKeys;
  7485. return this;
  7486. }
  7487. };
  7488. THREE.KeyframeTrack.keyComparer = function keyComparator(key0, key1) {
  7489. return key0.time - key1.time;
  7490. };
  7491. THREE.KeyframeTrack.parse = function( json ) {
  7492. if ( json.type === undefined ) throw new Error( "track type undefined, can not parse" );
  7493. var trackType = THREE.KeyframeTrack.GetTrackTypeForTypeName( json.type );
  7494. return trackType.parse( json );
  7495. };
  7496. THREE.KeyframeTrack.GetTrackTypeForTypeName = function( typeName ) {
  7497. switch( typeName.toLowerCase() ) {
  7498. case "vector":
  7499. case "vector2":
  7500. case "vector3":
  7501. case "vector4":
  7502. return THREE.VectorKeyframeTrack;
  7503. case "quaternion":
  7504. return THREE.QuaternionKeyframeTrack;
  7505. case "integer":
  7506. case "scalar":
  7507. case "double":
  7508. case "float":
  7509. case "number":
  7510. return THREE.NumberKeyframeTrack;
  7511. case "bool":
  7512. case "boolean":
  7513. return THREE.BooleanKeyframeTrack;
  7514. case "string":
  7515. return THREE.StringKeyframeTrack;
  7516. };
  7517. throw new Error( "Unsupported typeName: " + typeName );
  7518. };
  7519. // File:src/animation/PropertyBinding.js
  7520. /**
  7521. *
  7522. * A track bound to a real value in the scene graph.
  7523. *
  7524. * @author Ben Houston / http://clara.io/
  7525. * @author David Sarno / http://lighthaus.us/
  7526. */
  7527. THREE.PropertyBinding = function ( rootNode, trackName ) {
  7528. this.rootNode = rootNode;
  7529. this.trackName = trackName;
  7530. this.referenceCount = 0;
  7531. this.originalValue = null; // the value of the property before it was controlled by this binding
  7532. var parseResults = THREE.PropertyBinding.parseTrackName( trackName );
  7533. this.directoryName = parseResults.directoryName;
  7534. this.nodeName = parseResults.nodeName;
  7535. this.objectName = parseResults.objectName;
  7536. this.objectIndex = parseResults.objectIndex;
  7537. this.propertyName = parseResults.propertyName;
  7538. this.propertyIndex = parseResults.propertyIndex;
  7539. this.node = THREE.PropertyBinding.findNode( rootNode, this.nodeName ) || rootNode;
  7540. this.cumulativeValue = null;
  7541. this.cumulativeWeight = 0;
  7542. };
  7543. THREE.PropertyBinding.prototype = {
  7544. constructor: THREE.PropertyBinding,
  7545. reset: function() {
  7546. this.cumulativeValue = null;
  7547. this.cumulativeWeight = 0;
  7548. },
  7549. accumulate: function( value, weight ) {
  7550. if ( ! this.isBound ) this.bind();
  7551. if ( this.cumulativeWeight === 0 ) {
  7552. if ( weight > 0 ) {
  7553. if ( this.cumulativeValue === null ) {
  7554. this.cumulativeValue = THREE.AnimationUtils.clone( value );
  7555. }
  7556. this.cumulativeWeight = weight;
  7557. }
  7558. } else {
  7559. var lerpAlpha = weight / ( this.cumulativeWeight + weight );
  7560. this.cumulativeValue = this.lerpValue( this.cumulativeValue, value, lerpAlpha );
  7561. this.cumulativeWeight += weight;
  7562. }
  7563. },
  7564. unbind: function() {
  7565. if ( ! this.isBound ) return;
  7566. this.setValue( this.originalValue );
  7567. this.setValue = null;
  7568. this.getValue = null;
  7569. this.lerpValue = null;
  7570. this.equalsValue = null;
  7571. this.triggerDirty = null;
  7572. this.isBound = false;
  7573. },
  7574. // bind to the real property in the scene graph, remember original value, memorize various accessors for speed/inefficiency
  7575. bind: function() {
  7576. if ( this.isBound ) return;
  7577. var targetObject = this.node;
  7578. // ensure there is a value node
  7579. if ( ! targetObject ) {
  7580. console.error( " trying to update node for track: " + this.trackName + " but it wasn't found." );
  7581. return;
  7582. }
  7583. if ( this.objectName ) {
  7584. // special case were we need to reach deeper into the hierarchy to get the face materials....
  7585. if ( this.objectName === "materials" ) {
  7586. if ( ! targetObject.material ) {
  7587. console.error( ' can not bind to material as node does not have a material', this );
  7588. return;
  7589. }
  7590. if ( ! targetObject.material.materials ) {
  7591. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  7592. return;
  7593. }
  7594. targetObject = targetObject.material.materials;
  7595. } else if ( this.objectName === "bones" ) {
  7596. if ( ! targetObject.skeleton ) {
  7597. console.error( ' can not bind to bones as node does not have a skeleton', this );
  7598. return;
  7599. }
  7600. // potential future optimization: skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7601. targetObject = targetObject.skeleton.bones;
  7602. // support resolving morphTarget names into indices.
  7603. for ( var i = 0; i < targetObject.length; i ++ ) {
  7604. if ( targetObject[i].name === this.objectIndex ) {
  7605. this.objectIndex = i;
  7606. break;
  7607. }
  7608. }
  7609. } else {
  7610. if ( targetObject[ this.objectName ] === undefined ) {
  7611. console.error( ' can not bind to objectName of node, undefined', this );
  7612. return;
  7613. }
  7614. targetObject = targetObject[ this.objectName ];
  7615. }
  7616. if ( this.objectIndex !== undefined ) {
  7617. if ( targetObject[ this.objectIndex ] === undefined ) {
  7618. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  7619. return;
  7620. }
  7621. targetObject = targetObject[ this.objectIndex ];
  7622. }
  7623. }
  7624. // special case mappings
  7625. var nodeProperty = targetObject[ this.propertyName ];
  7626. if ( ! nodeProperty ) {
  7627. console.error( " trying to update property for track: " + this.nodeName + '.' + this.propertyName + " but it wasn't found.", targetObject );
  7628. return;
  7629. }
  7630. // access a sub element of the property array (only primitives are supported right now)
  7631. if ( this.propertyIndex !== undefined ) {
  7632. if ( this.propertyName === "morphTargetInfluences" ) {
  7633. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  7634. // support resolving morphTarget names into indices.
  7635. if ( ! targetObject.geometry ) {
  7636. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  7637. }
  7638. if ( ! targetObject.geometry.morphTargets ) {
  7639. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  7640. }
  7641. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  7642. if ( targetObject.geometry.morphTargets[i].name === this.propertyIndex ) {
  7643. this.propertyIndex = i;
  7644. break;
  7645. }
  7646. }
  7647. }
  7648. this.setValue = function setValue_propertyIndexed( value ) {
  7649. if ( ! this.equalsValue( nodeProperty[ this.propertyIndex ], value ) ) {
  7650. nodeProperty[ this.propertyIndex ] = value;
  7651. return true;
  7652. }
  7653. return false;
  7654. };
  7655. this.getValue = function getValue_propertyIndexed() {
  7656. return nodeProperty[ this.propertyIndex ];
  7657. };
  7658. }
  7659. // must use copy for Object3D.Euler/Quaternion
  7660. else if ( nodeProperty.copy ) {
  7661. this.setValue = function setValue_propertyObject( value ) {
  7662. if ( ! this.equalsValue( nodeProperty, value ) ) {
  7663. nodeProperty.copy( value );
  7664. return true;
  7665. }
  7666. return false;
  7667. }
  7668. this.getValue = function getValue_propertyObject() {
  7669. return nodeProperty;
  7670. };
  7671. }
  7672. // otherwise just set the property directly on the node (do not use nodeProperty as it may not be a reference object)
  7673. else {
  7674. this.setValue = function setValue_property( value ) {
  7675. if ( ! this.equalsValue( targetObject[ this.propertyName ], value ) ) {
  7676. targetObject[ this.propertyName ] = value;
  7677. return true;
  7678. }
  7679. return false;
  7680. }
  7681. this.getValue = function getValue_property() {
  7682. return targetObject[ this.propertyName ];
  7683. };
  7684. }
  7685. // trigger node dirty
  7686. if ( targetObject.needsUpdate !== undefined ) { // material
  7687. this.triggerDirty = function triggerDirty_needsUpdate() {
  7688. this.node.needsUpdate = true;
  7689. }
  7690. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  7691. this.triggerDirty = function triggerDirty_matrixWorldNeedsUpdate() {
  7692. targetObject.matrixWorldNeedsUpdate = true;
  7693. }
  7694. }
  7695. this.originalValue = this.getValue();
  7696. this.equalsValue = THREE.AnimationUtils.getEqualsFunc( this.originalValue );
  7697. this.lerpValue = THREE.AnimationUtils.getLerpFunc( this.originalValue, true );
  7698. this.isBound = true;
  7699. },
  7700. apply: function() {
  7701. // for speed capture the setter pattern as a closure (sort of a memoization pattern: https://en.wikipedia.org/wiki/Memoization)
  7702. if ( ! this.isBound ) this.bind();
  7703. // early exit if there is nothing to apply.
  7704. if ( this.cumulativeWeight > 0 ) {
  7705. // blend with original value
  7706. if ( this.cumulativeWeight < 1 ) {
  7707. var remainingWeight = 1 - this.cumulativeWeight;
  7708. var lerpAlpha = remainingWeight / ( this.cumulativeWeight + remainingWeight );
  7709. this.cumulativeValue = this.lerpValue( this.cumulativeValue, this.originalValue, lerpAlpha );
  7710. }
  7711. var valueChanged = this.setValue( this.cumulativeValue );
  7712. if ( valueChanged && this.triggerDirty ) {
  7713. this.triggerDirty();
  7714. }
  7715. // reset accumulator
  7716. this.cumulativeValue = null;
  7717. this.cumulativeWeight = 0;
  7718. }
  7719. }
  7720. };
  7721. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  7722. // matches strings in the form of:
  7723. // nodeName.property
  7724. // nodeName.property[accessor]
  7725. // nodeName.material.property[accessor]
  7726. // uuid.property[accessor]
  7727. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  7728. // parentName/nodeName.property
  7729. // parentName/parentName/nodeName.property[index]
  7730. // .bone[Armature.DEF_cog].position
  7731. // created and tested via https://regex101.com/#javascript
  7732. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  7733. var matches = re.exec(trackName);
  7734. if ( ! matches ) {
  7735. throw new Error( "cannot parse trackName at all: " + trackName );
  7736. }
  7737. if (matches.index === re.lastIndex) {
  7738. re.lastIndex++;
  7739. }
  7740. var results = {
  7741. directoryName: matches[1],
  7742. nodeName: matches[3], // allowed to be null, specified root node.
  7743. objectName: matches[5],
  7744. objectIndex: matches[7],
  7745. propertyName: matches[9],
  7746. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  7747. };
  7748. if ( results.propertyName === null || results.propertyName.length === 0 ) {
  7749. throw new Error( "can not parse propertyName from trackName: " + trackName );
  7750. }
  7751. return results;
  7752. };
  7753. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  7754. function searchSkeleton( skeleton ) {
  7755. for ( var i = 0; i < skeleton.bones.length; i ++ ) {
  7756. var bone = skeleton.bones[i];
  7757. if ( bone.name === nodeName ) {
  7758. return bone;
  7759. }
  7760. }
  7761. return null;
  7762. }
  7763. function searchNodeSubtree( children ) {
  7764. for ( var i = 0; i < children.length; i ++ ) {
  7765. var childNode = children[i];
  7766. if ( childNode.name === nodeName || childNode.uuid === nodeName ) {
  7767. return childNode;
  7768. }
  7769. var result = searchNodeSubtree( childNode.children );
  7770. if ( result ) return result;
  7771. }
  7772. return null;
  7773. }
  7774. //
  7775. if ( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  7776. return root;
  7777. }
  7778. // search into skeleton bones.
  7779. if ( root.skeleton ) {
  7780. var bone = searchSkeleton( root.skeleton );
  7781. if ( bone ) {
  7782. return bone;
  7783. }
  7784. }
  7785. // search into node subtree.
  7786. if ( root.children ) {
  7787. var subTreeNode = searchNodeSubtree( root.children );
  7788. if ( subTreeNode ) {
  7789. return subTreeNode;
  7790. }
  7791. }
  7792. return null;
  7793. }
  7794. // File:src/animation/tracks/VectorKeyframeTrack.js
  7795. /**
  7796. *
  7797. * A Track that interpolates Vectors
  7798. *
  7799. * @author Ben Houston / http://clara.io/
  7800. * @author David Sarno / http://lighthaus.us/
  7801. */
  7802. THREE.VectorKeyframeTrack = function ( name, keys ) {
  7803. THREE.KeyframeTrack.call( this, name, keys );
  7804. // local cache of value type to avoid allocations during runtime.
  7805. this.result = this.keys[0].value.clone();
  7806. };
  7807. THREE.VectorKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7808. THREE.VectorKeyframeTrack.prototype.constructor = THREE.VectorKeyframeTrack;
  7809. THREE.VectorKeyframeTrack.prototype.setResult = function( value ) {
  7810. this.result.copy( value );
  7811. };
  7812. // memoization of the lerp function for speed.
  7813. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7814. THREE.VectorKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7815. return value0.lerp( value1, alpha );
  7816. };
  7817. THREE.VectorKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7818. return value0.equals( value1 );
  7819. };
  7820. THREE.VectorKeyframeTrack.prototype.clone = function() {
  7821. var clonedKeys = [];
  7822. for ( var i = 0; i < this.keys.length; i ++ ) {
  7823. var key = this.keys[i];
  7824. clonedKeys.push( {
  7825. time: key.time,
  7826. value: key.value.clone()
  7827. } );
  7828. }
  7829. return new THREE.VectorKeyframeTrack( this.name, clonedKeys );
  7830. };
  7831. THREE.VectorKeyframeTrack.parse = function( json ) {
  7832. var elementCount = json.keys[0].value.length;
  7833. var valueType = THREE[ 'Vector' + elementCount ];
  7834. var keys = [];
  7835. for ( var i = 0; i < json.keys.length; i ++ ) {
  7836. var jsonKey = json.keys[i];
  7837. keys.push( {
  7838. value: new valueType().fromArray( jsonKey.value ),
  7839. time: jsonKey.time
  7840. } );
  7841. }
  7842. return new THREE.VectorKeyframeTrack( json.name, keys );
  7843. };
  7844. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  7845. /**
  7846. *
  7847. * A Track that interpolates Quaternion
  7848. *
  7849. * @author Ben Houston / http://clara.io/
  7850. * @author David Sarno / http://lighthaus.us/
  7851. */
  7852. THREE.QuaternionKeyframeTrack = function ( name, keys ) {
  7853. THREE.KeyframeTrack.call( this, name, keys );
  7854. // local cache of value type to avoid allocations during runtime.
  7855. this.result = this.keys[0].value.clone();
  7856. };
  7857. THREE.QuaternionKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7858. THREE.QuaternionKeyframeTrack.prototype.constructor = THREE.QuaternionKeyframeTrack;
  7859. THREE.QuaternionKeyframeTrack.prototype.setResult = function( value ) {
  7860. this.result.copy( value );
  7861. };
  7862. // memoization of the lerp function for speed.
  7863. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7864. THREE.QuaternionKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7865. return value0.slerp( value1, alpha );
  7866. };
  7867. THREE.QuaternionKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7868. return value0.equals( value1 );
  7869. };
  7870. THREE.QuaternionKeyframeTrack.prototype.multiply = function( quat ) {
  7871. for ( var i = 0; i < this.keys.length; i ++ ) {
  7872. this.keys[i].value.multiply( quat );
  7873. }
  7874. return this;
  7875. };
  7876. THREE.QuaternionKeyframeTrack.prototype.clone = function() {
  7877. var clonedKeys = [];
  7878. for ( var i = 0; i < this.keys.length; i ++ ) {
  7879. var key = this.keys[i];
  7880. clonedKeys.push( {
  7881. time: key.time,
  7882. value: key.value.clone()
  7883. } );
  7884. }
  7885. return new THREE.QuaternionKeyframeTrack( this.name, clonedKeys );
  7886. };
  7887. THREE.QuaternionKeyframeTrack.parse = function( json ) {
  7888. var keys = [];
  7889. for ( var i = 0; i < json.keys.length; i ++ ) {
  7890. var jsonKey = json.keys[i];
  7891. keys.push( {
  7892. value: new THREE.Quaternion().fromArray( jsonKey.value ),
  7893. time: jsonKey.time
  7894. } );
  7895. }
  7896. return new THREE.QuaternionKeyframeTrack( json.name, keys );
  7897. };
  7898. // File:src/animation/tracks/StringKeyframeTrack.js
  7899. /**
  7900. *
  7901. * A Track that interpolates Strings
  7902. *
  7903. * @author Ben Houston / http://clara.io/
  7904. * @author David Sarno / http://lighthaus.us/
  7905. */
  7906. THREE.StringKeyframeTrack = function ( name, keys ) {
  7907. THREE.KeyframeTrack.call( this, name, keys );
  7908. // local cache of value type to avoid allocations during runtime.
  7909. this.result = this.keys[0].value;
  7910. };
  7911. THREE.StringKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7912. THREE.StringKeyframeTrack.prototype.constructor = THREE.StringKeyframeTrack;
  7913. THREE.StringKeyframeTrack.prototype.setResult = function( value ) {
  7914. this.result = value;
  7915. };
  7916. // memoization of the lerp function for speed.
  7917. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7918. THREE.StringKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7919. return ( alpha < 1.0 ) ? value0 : value1;
  7920. };
  7921. THREE.StringKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7922. return ( value0 === value1 );
  7923. };
  7924. THREE.StringKeyframeTrack.prototype.clone = function() {
  7925. var clonedKeys = [];
  7926. for ( var i = 0; i < this.keys.length; i ++ ) {
  7927. var key = this.keys[i];
  7928. clonedKeys.push( {
  7929. time: key.time,
  7930. value: key.value
  7931. } );
  7932. }
  7933. return new THREE.StringKeyframeTrack( this.name, clonedKeys );
  7934. };
  7935. THREE.StringKeyframeTrack.parse = function( json ) {
  7936. return new THREE.StringKeyframeTrack( json.name, json.keys );
  7937. };
  7938. // File:src/animation/tracks/BooleanKeyframeTrack.js
  7939. /**
  7940. *
  7941. * A Track that interpolates Boolean
  7942. *
  7943. * @author Ben Houston / http://clara.io/
  7944. * @author David Sarno / http://lighthaus.us/
  7945. */
  7946. THREE.BooleanKeyframeTrack = function ( name, keys ) {
  7947. THREE.KeyframeTrack.call( this, name, keys );
  7948. // local cache of value type to avoid allocations during runtime.
  7949. this.result = this.keys[0].value;
  7950. };
  7951. THREE.BooleanKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7952. THREE.BooleanKeyframeTrack.prototype.constructor = THREE.BooleanKeyframeTrack;
  7953. THREE.BooleanKeyframeTrack.prototype.setResult = function( value ) {
  7954. this.result = value;
  7955. };
  7956. // memoization of the lerp function for speed.
  7957. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7958. THREE.BooleanKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7959. return ( alpha < 1.0 ) ? value0 : value1;
  7960. };
  7961. THREE.BooleanKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  7962. return ( value0 === value1 );
  7963. };
  7964. THREE.BooleanKeyframeTrack.prototype.clone = function() {
  7965. var clonedKeys = [];
  7966. for ( var i = 0; i < this.keys.length; i ++ ) {
  7967. var key = this.keys[i];
  7968. clonedKeys.push( {
  7969. time: key.time,
  7970. value: key.value
  7971. } );
  7972. }
  7973. return new THREE.BooleanKeyframeTrack( this.name, clonedKeys );
  7974. };
  7975. THREE.BooleanKeyframeTrack.parse = function( json ) {
  7976. return new THREE.BooleanKeyframeTrack( json.name, json.keys );
  7977. };
  7978. // File:src/animation/tracks/NumberKeyframeTrack.js
  7979. /**
  7980. *
  7981. * A Track that interpolates Numbers
  7982. *
  7983. * @author Ben Houston / http://clara.io/
  7984. * @author David Sarno / http://lighthaus.us/
  7985. */
  7986. THREE.NumberKeyframeTrack = function ( name, keys ) {
  7987. THREE.KeyframeTrack.call( this, name, keys );
  7988. // local cache of value type to avoid allocations during runtime.
  7989. this.result = this.keys[0].value;
  7990. };
  7991. THREE.NumberKeyframeTrack.prototype = Object.create( THREE.KeyframeTrack.prototype );
  7992. THREE.NumberKeyframeTrack.prototype.constructor = THREE.NumberKeyframeTrack;
  7993. THREE.NumberKeyframeTrack.prototype.setResult = function( value ) {
  7994. this.result = value;
  7995. };
  7996. // memoization of the lerp function for speed.
  7997. // NOTE: Do not optimize as a prototype initialization closure, as value0 will be different on a per class basis.
  7998. THREE.NumberKeyframeTrack.prototype.lerpValues = function( value0, value1, alpha ) {
  7999. return value0 * ( 1 - alpha ) + value1 * alpha;
  8000. };
  8001. THREE.NumberKeyframeTrack.prototype.compareValues = function( value0, value1 ) {
  8002. return ( value0 === value1 );
  8003. };
  8004. THREE.NumberKeyframeTrack.prototype.clone = function() {
  8005. var clonedKeys = [];
  8006. for ( var i = 0; i < this.keys.length; i ++ ) {
  8007. var key = this.keys[i];
  8008. clonedKeys.push( {
  8009. time: key.time,
  8010. value: key.value
  8011. } );
  8012. }
  8013. return new THREE.NumberKeyframeTrack( this.name, clonedKeys );
  8014. };
  8015. THREE.NumberKeyframeTrack.parse = function( json ) {
  8016. return new THREE.NumberKeyframeTrack( json.name, json.keys );
  8017. };
  8018. // File:src/cameras/Camera.js
  8019. /**
  8020. * @author mrdoob / http://mrdoob.com/
  8021. * @author mikael emtinger / http://gomo.se/
  8022. * @author WestLangley / http://github.com/WestLangley
  8023. */
  8024. THREE.Camera = function () {
  8025. THREE.Object3D.call( this );
  8026. this.type = 'Camera';
  8027. this.matrixWorldInverse = new THREE.Matrix4();
  8028. this.projectionMatrix = new THREE.Matrix4();
  8029. };
  8030. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  8031. THREE.Camera.prototype.constructor = THREE.Camera;
  8032. THREE.Camera.prototype.getWorldDirection = function () {
  8033. var quaternion = new THREE.Quaternion();
  8034. return function ( optionalTarget ) {
  8035. var result = optionalTarget || new THREE.Vector3();
  8036. this.getWorldQuaternion( quaternion );
  8037. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  8038. };
  8039. }();
  8040. THREE.Camera.prototype.lookAt = function () {
  8041. // This routine does not support cameras with rotated and/or translated parent(s)
  8042. var m1 = new THREE.Matrix4();
  8043. return function ( vector ) {
  8044. m1.lookAt( this.position, vector, this.up );
  8045. this.quaternion.setFromRotationMatrix( m1 );
  8046. };
  8047. }();
  8048. THREE.Camera.prototype.clone = function () {
  8049. return new this.constructor().copy( this );
  8050. };
  8051. THREE.Camera.prototype.copy = function ( source ) {
  8052. THREE.Object3D.prototype.copy.call( this, source );
  8053. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  8054. this.projectionMatrix.copy( source.projectionMatrix );
  8055. return this;
  8056. };
  8057. // File:src/cameras/CubeCamera.js
  8058. /**
  8059. * Camera for rendering cube maps
  8060. * - renders scene into axis-aligned cube
  8061. *
  8062. * @author alteredq / http://alteredqualia.com/
  8063. */
  8064. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  8065. THREE.Object3D.call( this );
  8066. this.type = 'CubeCamera';
  8067. var fov = 90, aspect = 1;
  8068. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8069. cameraPX.up.set( 0, - 1, 0 );
  8070. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  8071. this.add( cameraPX );
  8072. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8073. cameraNX.up.set( 0, - 1, 0 );
  8074. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  8075. this.add( cameraNX );
  8076. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8077. cameraPY.up.set( 0, 0, 1 );
  8078. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  8079. this.add( cameraPY );
  8080. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8081. cameraNY.up.set( 0, 0, - 1 );
  8082. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  8083. this.add( cameraNY );
  8084. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8085. cameraPZ.up.set( 0, - 1, 0 );
  8086. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  8087. this.add( cameraPZ );
  8088. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  8089. cameraNZ.up.set( 0, - 1, 0 );
  8090. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  8091. this.add( cameraNZ );
  8092. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter } );
  8093. this.updateCubeMap = function ( renderer, scene ) {
  8094. if ( this.parent === null ) this.updateMatrixWorld();
  8095. var renderTarget = this.renderTarget;
  8096. var generateMipmaps = renderTarget.texture.generateMipmaps;
  8097. renderTarget.texture.generateMipmaps = false;
  8098. renderTarget.activeCubeFace = 0;
  8099. renderer.render( scene, cameraPX, renderTarget );
  8100. renderTarget.activeCubeFace = 1;
  8101. renderer.render( scene, cameraNX, renderTarget );
  8102. renderTarget.activeCubeFace = 2;
  8103. renderer.render( scene, cameraPY, renderTarget );
  8104. renderTarget.activeCubeFace = 3;
  8105. renderer.render( scene, cameraNY, renderTarget );
  8106. renderTarget.activeCubeFace = 4;
  8107. renderer.render( scene, cameraPZ, renderTarget );
  8108. renderTarget.texture.generateMipmaps = generateMipmaps;
  8109. renderTarget.activeCubeFace = 5;
  8110. renderer.render( scene, cameraNZ, renderTarget );
  8111. renderer.setRenderTarget( null );
  8112. };
  8113. };
  8114. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  8115. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  8116. // File:src/cameras/OrthographicCamera.js
  8117. /**
  8118. * @author alteredq / http://alteredqualia.com/
  8119. */
  8120. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  8121. THREE.Camera.call( this );
  8122. this.type = 'OrthographicCamera';
  8123. this.zoom = 1;
  8124. this.left = left;
  8125. this.right = right;
  8126. this.top = top;
  8127. this.bottom = bottom;
  8128. this.near = ( near !== undefined ) ? near : 0.1;
  8129. this.far = ( far !== undefined ) ? far : 2000;
  8130. this.updateProjectionMatrix();
  8131. };
  8132. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  8133. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  8134. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  8135. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  8136. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  8137. var cx = ( this.right + this.left ) / 2;
  8138. var cy = ( this.top + this.bottom ) / 2;
  8139. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  8140. };
  8141. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  8142. THREE.Camera.prototype.copy.call( this, source );
  8143. this.left = source.left;
  8144. this.right = source.right;
  8145. this.top = source.top;
  8146. this.bottom = source.bottom;
  8147. this.near = source.near;
  8148. this.far = source.far;
  8149. this.zoom = source.zoom;
  8150. return this;
  8151. };
  8152. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  8153. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8154. data.object.zoom = this.zoom;
  8155. data.object.left = this.left;
  8156. data.object.right = this.right;
  8157. data.object.top = this.top;
  8158. data.object.bottom = this.bottom;
  8159. data.object.near = this.near;
  8160. data.object.far = this.far;
  8161. return data;
  8162. };
  8163. // File:src/cameras/PerspectiveCamera.js
  8164. /**
  8165. * @author mrdoob / http://mrdoob.com/
  8166. * @author greggman / http://games.greggman.com/
  8167. * @author zz85 / http://www.lab4games.net/zz85/blog
  8168. */
  8169. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  8170. THREE.Camera.call( this );
  8171. this.type = 'PerspectiveCamera';
  8172. this.zoom = 1;
  8173. this.fov = fov !== undefined ? fov : 50;
  8174. this.aspect = aspect !== undefined ? aspect : 1;
  8175. this.near = near !== undefined ? near : 0.1;
  8176. this.far = far !== undefined ? far : 2000;
  8177. this.updateProjectionMatrix();
  8178. };
  8179. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  8180. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  8181. /**
  8182. * Uses Focal Length (in mm) to estimate and set FOV
  8183. * 35mm (full-frame) camera is used if frame size is not specified;
  8184. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  8185. */
  8186. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  8187. if ( frameHeight === undefined ) frameHeight = 24;
  8188. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  8189. this.updateProjectionMatrix();
  8190. };
  8191. /**
  8192. * Sets an offset in a larger frustum. This is useful for multi-window or
  8193. * multi-monitor/multi-machine setups.
  8194. *
  8195. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  8196. * the monitors are in grid like this
  8197. *
  8198. * +---+---+---+
  8199. * | A | B | C |
  8200. * +---+---+---+
  8201. * | D | E | F |
  8202. * +---+---+---+
  8203. *
  8204. * then for each monitor you would call it like this
  8205. *
  8206. * var w = 1920;
  8207. * var h = 1080;
  8208. * var fullWidth = w * 3;
  8209. * var fullHeight = h * 2;
  8210. *
  8211. * --A--
  8212. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  8213. * --B--
  8214. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  8215. * --C--
  8216. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  8217. * --D--
  8218. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  8219. * --E--
  8220. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  8221. * --F--
  8222. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  8223. *
  8224. * Note there is no reason monitors have to be the same size or in a grid.
  8225. */
  8226. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  8227. this.fullWidth = fullWidth;
  8228. this.fullHeight = fullHeight;
  8229. this.x = x;
  8230. this.y = y;
  8231. this.width = width;
  8232. this.height = height;
  8233. this.updateProjectionMatrix();
  8234. };
  8235. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  8236. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  8237. if ( this.fullWidth ) {
  8238. var aspect = this.fullWidth / this.fullHeight;
  8239. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  8240. var bottom = - top;
  8241. var left = aspect * bottom;
  8242. var right = aspect * top;
  8243. var width = Math.abs( right - left );
  8244. var height = Math.abs( top - bottom );
  8245. this.projectionMatrix.makeFrustum(
  8246. left + this.x * width / this.fullWidth,
  8247. left + ( this.x + this.width ) * width / this.fullWidth,
  8248. top - ( this.y + this.height ) * height / this.fullHeight,
  8249. top - this.y * height / this.fullHeight,
  8250. this.near,
  8251. this.far
  8252. );
  8253. } else {
  8254. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  8255. }
  8256. };
  8257. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  8258. THREE.Camera.prototype.copy.call( this, source );
  8259. this.fov = source.fov;
  8260. this.aspect = source.aspect;
  8261. this.near = source.near;
  8262. this.far = source.far;
  8263. this.zoom = source.zoom;
  8264. return this;
  8265. };
  8266. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  8267. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8268. data.object.zoom = this.zoom;
  8269. data.object.fov = this.fov;
  8270. data.object.aspect = this.aspect;
  8271. data.object.near = this.near;
  8272. data.object.far = this.far;
  8273. return data;
  8274. };
  8275. // File:src/lights/Light.js
  8276. /**
  8277. * @author mrdoob / http://mrdoob.com/
  8278. * @author alteredq / http://alteredqualia.com/
  8279. */
  8280. THREE.Light = function ( color ) {
  8281. THREE.Object3D.call( this );
  8282. this.type = 'Light';
  8283. this.color = new THREE.Color( color );
  8284. this.receiveShadow = undefined;
  8285. };
  8286. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  8287. THREE.Light.prototype.constructor = THREE.Light;
  8288. Object.defineProperties( THREE.Light.prototype, {
  8289. onlyShadow: {
  8290. set: function ( value ) {
  8291. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  8292. }
  8293. },
  8294. shadowCameraFov: {
  8295. set: function ( value ) {
  8296. this.shadow.camera.fov = value;
  8297. }
  8298. },
  8299. shadowCameraLeft: {
  8300. set: function ( value ) {
  8301. this.shadow.camera.left = value;
  8302. }
  8303. },
  8304. shadowCameraRight: {
  8305. set: function ( value ) {
  8306. this.shadow.camera.right = value;
  8307. }
  8308. },
  8309. shadowCameraTop: {
  8310. set: function ( value ) {
  8311. this.shadow.camera.top = value;
  8312. }
  8313. },
  8314. shadowCameraBottom: {
  8315. set: function ( value ) {
  8316. this.shadow.camera.bottom = value;
  8317. }
  8318. },
  8319. shadowCameraNear: {
  8320. set: function ( value ) {
  8321. this.shadow.camera.near = value;
  8322. }
  8323. },
  8324. shadowCameraFar: {
  8325. set: function ( value ) {
  8326. this.shadow.camera.far = value;
  8327. }
  8328. },
  8329. shadowCameraVisible: {
  8330. set: function ( value ) {
  8331. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow ) instead.' );
  8332. }
  8333. },
  8334. shadowBias: {
  8335. set: function ( value ) {
  8336. this.shadow.bias = value;
  8337. }
  8338. },
  8339. shadowDarkness: {
  8340. set: function ( value ) {
  8341. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  8342. }
  8343. },
  8344. shadowMapWidth: {
  8345. set: function ( value ) {
  8346. this.shadow.mapSize.width = value;
  8347. }
  8348. },
  8349. shadowMapHeight: {
  8350. set: function ( value ) {
  8351. this.shadow.mapSize.height = value;
  8352. }
  8353. }
  8354. } );
  8355. THREE.Light.prototype.copy = function ( source ) {
  8356. THREE.Object3D.prototype.copy.call( this, source );
  8357. this.color.copy( source.color );
  8358. return this;
  8359. };
  8360. THREE.Light.prototype.toJSON = function ( meta ) {
  8361. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  8362. data.object.color = this.color.getHex();
  8363. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  8364. if ( this.intensity !== undefined ) data.object.intensity = this.intensity;
  8365. if ( this.distance !== undefined ) data.object.distance = this.distance;
  8366. if ( this.angle !== undefined ) data.object.angle = this.angle;
  8367. if ( this.decay !== undefined ) data.object.decay = this.decay;
  8368. if ( this.exponent !== undefined ) data.object.exponent = this.exponent;
  8369. return data;
  8370. };
  8371. // File:src/lights/LightShadow.js
  8372. /**
  8373. * @author mrdoob / http://mrdoob.com/
  8374. */
  8375. THREE.LightShadow = function ( camera ) {
  8376. this.camera = camera;
  8377. this.bias = 0;
  8378. this.mapSize = new THREE.Vector2( 512, 512 );
  8379. this.map = null;
  8380. this.matrix = null;
  8381. };
  8382. THREE.LightShadow.prototype = {
  8383. constructor: THREE.LightShadow,
  8384. copy: function ( source ) {
  8385. this.camera = source.camera.clone();
  8386. this.bias = source.bias;
  8387. this.darkness = source.darkness;
  8388. this.mapSize.copy( source.mapSize );
  8389. },
  8390. clone: function () {
  8391. return new this.constructor().copy( this );
  8392. }
  8393. };
  8394. // File:src/lights/AmbientLight.js
  8395. /**
  8396. * @author mrdoob / http://mrdoob.com/
  8397. */
  8398. THREE.AmbientLight = function ( color ) {
  8399. THREE.Light.call( this, color );
  8400. this.type = 'AmbientLight';
  8401. };
  8402. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  8403. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  8404. // File:src/lights/DirectionalLight.js
  8405. /**
  8406. * @author mrdoob / http://mrdoob.com/
  8407. * @author alteredq / http://alteredqualia.com/
  8408. */
  8409. THREE.DirectionalLight = function ( color, intensity ) {
  8410. THREE.Light.call( this, color );
  8411. this.type = 'DirectionalLight';
  8412. this.position.set( 0, 1, 0 );
  8413. this.updateMatrix();
  8414. this.target = new THREE.Object3D();
  8415. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8416. this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 500, 500, 500, - 500, 50, 5000 ) );
  8417. };
  8418. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  8419. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  8420. THREE.DirectionalLight.prototype.copy = function ( source ) {
  8421. THREE.Light.prototype.copy.call( this, source );
  8422. this.intensity = source.intensity;
  8423. this.target = source.target.clone();
  8424. this.shadow = source.shadow.clone();
  8425. return this;
  8426. };
  8427. // File:src/lights/HemisphereLight.js
  8428. /**
  8429. * @author alteredq / http://alteredqualia.com/
  8430. */
  8431. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  8432. THREE.Light.call( this, skyColor );
  8433. this.type = 'HemisphereLight';
  8434. this.position.set( 0, 1, 0 );
  8435. this.updateMatrix();
  8436. this.groundColor = new THREE.Color( groundColor );
  8437. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8438. };
  8439. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  8440. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  8441. THREE.HemisphereLight.prototype.copy = function ( source ) {
  8442. THREE.Light.prototype.copy.call( this, source );
  8443. this.groundColor.copy( source.groundColor );
  8444. this.intensity = source.intensity;
  8445. return this;
  8446. };
  8447. // File:src/lights/PointLight.js
  8448. /**
  8449. * @author mrdoob / http://mrdoob.com/
  8450. */
  8451. THREE.PointLight = function ( color, intensity, distance, decay ) {
  8452. THREE.Light.call( this, color );
  8453. this.type = 'PointLight';
  8454. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8455. this.distance = ( distance !== undefined ) ? distance : 0;
  8456. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8457. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 1, 500 ) );
  8458. };
  8459. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  8460. THREE.PointLight.prototype.constructor = THREE.PointLight;
  8461. THREE.PointLight.prototype.copy = function ( source ) {
  8462. THREE.Light.prototype.copy.call( this, source );
  8463. this.intensity = source.intensity;
  8464. this.distance = source.distance;
  8465. this.decay = source.decay;
  8466. this.shadow = source.shadow.clone();
  8467. return this;
  8468. };
  8469. // File:src/lights/SpotLight.js
  8470. /**
  8471. * @author alteredq / http://alteredqualia.com/
  8472. */
  8473. THREE.SpotLight = function ( color, intensity, distance, angle, exponent, decay ) {
  8474. THREE.Light.call( this, color );
  8475. this.type = 'SpotLight';
  8476. this.position.set( 0, 1, 0 );
  8477. this.updateMatrix();
  8478. this.target = new THREE.Object3D();
  8479. this.intensity = ( intensity !== undefined ) ? intensity : 1;
  8480. this.distance = ( distance !== undefined ) ? distance : 0;
  8481. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  8482. this.exponent = ( exponent !== undefined ) ? exponent : 10;
  8483. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  8484. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 50, 5000 ) );
  8485. };
  8486. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  8487. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  8488. THREE.SpotLight.prototype.copy = function ( source ) {
  8489. THREE.Light.prototype.copy.call( this, source );
  8490. this.intensity = source.intensity;
  8491. this.distance = source.distance;
  8492. this.angle = source.angle;
  8493. this.exponent = source.exponent;
  8494. this.decay = source.decay;
  8495. this.target = source.target.clone();
  8496. this.shadow = source.shadow.clone();
  8497. return this;
  8498. };
  8499. // File:src/loaders/Cache.js
  8500. /**
  8501. * @author mrdoob / http://mrdoob.com/
  8502. */
  8503. THREE.Cache = {
  8504. enabled: false,
  8505. files: {},
  8506. add: function ( key, file ) {
  8507. if ( this.enabled === false ) return;
  8508. // console.log( 'THREE.Cache', 'Adding key:', key );
  8509. this.files[ key ] = file;
  8510. },
  8511. get: function ( key ) {
  8512. if ( this.enabled === false ) return;
  8513. // console.log( 'THREE.Cache', 'Checking key:', key );
  8514. return this.files[ key ];
  8515. },
  8516. remove: function ( key ) {
  8517. delete this.files[ key ];
  8518. },
  8519. clear: function () {
  8520. this.files = {};
  8521. }
  8522. };
  8523. // File:src/loaders/Loader.js
  8524. /**
  8525. * @author alteredq / http://alteredqualia.com/
  8526. */
  8527. THREE.Loader = function () {
  8528. this.onLoadStart = function () {};
  8529. this.onLoadProgress = function () {};
  8530. this.onLoadComplete = function () {};
  8531. };
  8532. THREE.Loader.prototype = {
  8533. constructor: THREE.Loader,
  8534. crossOrigin: undefined,
  8535. extractUrlBase: function ( url ) {
  8536. var parts = url.split( '/' );
  8537. if ( parts.length === 1 ) return './';
  8538. parts.pop();
  8539. return parts.join( '/' ) + '/';
  8540. },
  8541. initMaterials: function ( materials, texturePath, crossOrigin ) {
  8542. var array = [];
  8543. for ( var i = 0; i < materials.length; ++ i ) {
  8544. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  8545. }
  8546. return array;
  8547. },
  8548. createMaterial: ( function () {
  8549. var imageLoader;
  8550. return function createMaterial( m, texturePath, crossOrigin ) {
  8551. var scope = this;
  8552. if ( crossOrigin === undefined && scope.crossOrigin !== undefined ) crossOrigin = scope.crossOrigin;
  8553. if ( imageLoader === undefined ) imageLoader = new THREE.ImageLoader();
  8554. function nearest_pow2( n ) {
  8555. var l = Math.log( n ) / Math.LN2;
  8556. return Math.pow( 2, Math.round( l ) );
  8557. }
  8558. function create_texture( where, name, sourceFile, repeat, offset, wrap, anisotropy ) {
  8559. var fullPath = texturePath + sourceFile;
  8560. var texture;
  8561. var loader = THREE.Loader.Handlers.get( fullPath );
  8562. if ( loader !== null ) {
  8563. texture = loader.load( fullPath );
  8564. } else {
  8565. texture = new THREE.Texture();
  8566. loader = imageLoader;
  8567. loader.setCrossOrigin( crossOrigin );
  8568. loader.load( fullPath, function ( image ) {
  8569. if ( THREE.Math.isPowerOfTwo( image.width ) === false ||
  8570. THREE.Math.isPowerOfTwo( image.height ) === false ) {
  8571. var width = nearest_pow2( image.width );
  8572. var height = nearest_pow2( image.height );
  8573. var canvas = document.createElement( 'canvas' );
  8574. canvas.width = width;
  8575. canvas.height = height;
  8576. var context = canvas.getContext( '2d' );
  8577. context.drawImage( image, 0, 0, width, height );
  8578. texture.image = canvas;
  8579. } else {
  8580. texture.image = image;
  8581. }
  8582. texture.needsUpdate = true;
  8583. } );
  8584. }
  8585. texture.sourceFile = sourceFile;
  8586. if ( repeat ) {
  8587. texture.repeat.set( repeat[ 0 ], repeat[ 1 ] );
  8588. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  8589. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  8590. }
  8591. if ( offset ) {
  8592. texture.offset.set( offset[ 0 ], offset[ 1 ] );
  8593. }
  8594. if ( wrap ) {
  8595. var wrapMap = {
  8596. 'repeat': THREE.RepeatWrapping,
  8597. 'mirror': THREE.MirroredRepeatWrapping
  8598. };
  8599. if ( wrapMap[ wrap[ 0 ] ] !== undefined ) texture.wrapS = wrapMap[ wrap[ 0 ] ];
  8600. if ( wrapMap[ wrap[ 1 ] ] !== undefined ) texture.wrapT = wrapMap[ wrap[ 1 ] ];
  8601. }
  8602. if ( anisotropy ) {
  8603. texture.anisotropy = anisotropy;
  8604. }
  8605. where[ name ] = texture;
  8606. }
  8607. function rgb2hex( rgb ) {
  8608. return ( rgb[ 0 ] * 255 << 16 ) + ( rgb[ 1 ] * 255 << 8 ) + rgb[ 2 ] * 255;
  8609. }
  8610. // defaults
  8611. var mtype = 'MeshLambertMaterial';
  8612. var mpars = {};
  8613. // parameters from model file
  8614. if ( m.shading ) {
  8615. var shading = m.shading.toLowerCase();
  8616. if ( shading === 'phong' ) mtype = 'MeshPhongMaterial';
  8617. else if ( shading === 'basic' ) mtype = 'MeshBasicMaterial';
  8618. }
  8619. if ( m.blending !== undefined && THREE[ m.blending ] !== undefined ) {
  8620. mpars.blending = THREE[ m.blending ];
  8621. }
  8622. if ( m.transparent !== undefined ) {
  8623. mpars.transparent = m.transparent;
  8624. }
  8625. if ( m.opacity !== undefined && m.opacity < 1.0 ) {
  8626. mpars.transparent = true;
  8627. }
  8628. if ( m.depthTest !== undefined ) {
  8629. mpars.depthTest = m.depthTest;
  8630. }
  8631. if ( m.depthWrite !== undefined ) {
  8632. mpars.depthWrite = m.depthWrite;
  8633. }
  8634. if ( m.visible !== undefined ) {
  8635. mpars.visible = m.visible;
  8636. }
  8637. if ( m.flipSided !== undefined ) {
  8638. mpars.side = THREE.BackSide;
  8639. }
  8640. if ( m.doubleSided !== undefined ) {
  8641. mpars.side = THREE.DoubleSide;
  8642. }
  8643. if ( m.wireframe !== undefined ) {
  8644. mpars.wireframe = m.wireframe;
  8645. }
  8646. if ( m.vertexColors !== undefined ) {
  8647. if ( m.vertexColors === 'face' ) {
  8648. mpars.vertexColors = THREE.FaceColors;
  8649. } else if ( m.vertexColors ) {
  8650. mpars.vertexColors = THREE.VertexColors;
  8651. }
  8652. }
  8653. // colors
  8654. if ( m.colorDiffuse ) {
  8655. mpars.color = rgb2hex( m.colorDiffuse );
  8656. } else if ( m.DbgColor ) {
  8657. mpars.color = m.DbgColor;
  8658. }
  8659. if ( m.colorEmissive ) {
  8660. mpars.emissive = rgb2hex( m.colorEmissive );
  8661. }
  8662. if ( mtype === 'MeshPhongMaterial' ) {
  8663. if ( m.colorSpecular ) {
  8664. mpars.specular = rgb2hex( m.colorSpecular );
  8665. }
  8666. if ( m.specularCoef ) {
  8667. mpars.shininess = m.specularCoef;
  8668. }
  8669. }
  8670. // modifiers
  8671. if ( m.transparency !== undefined ) {
  8672. console.warn( 'THREE.Loader: transparency has been renamed to opacity' );
  8673. m.opacity = m.transparency;
  8674. }
  8675. if ( m.opacity !== undefined ) {
  8676. mpars.opacity = m.opacity;
  8677. }
  8678. // textures
  8679. if ( texturePath ) {
  8680. if ( m.mapDiffuse ) {
  8681. create_texture( mpars, 'map', m.mapDiffuse, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  8682. }
  8683. if ( m.mapLight ) {
  8684. create_texture( mpars, 'lightMap', m.mapLight, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  8685. }
  8686. if ( m.mapAO ) {
  8687. create_texture( mpars, 'aoMap', m.mapAO, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  8688. }
  8689. if ( m.mapBump ) {
  8690. create_texture( mpars, 'bumpMap', m.mapBump, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  8691. }
  8692. if ( m.mapNormal ) {
  8693. create_texture( mpars, 'normalMap', m.mapNormal, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  8694. }
  8695. if ( m.mapSpecular ) {
  8696. create_texture( mpars, 'specularMap', m.mapSpecular, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  8697. }
  8698. if ( m.mapAlpha ) {
  8699. create_texture( mpars, 'alphaMap', m.mapAlpha, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  8700. }
  8701. }
  8702. //
  8703. if ( m.mapBumpScale ) {
  8704. mpars.bumpScale = m.mapBumpScale;
  8705. }
  8706. if ( m.mapNormalFactor ) {
  8707. mpars.normalScale = new THREE.Vector2( m.mapNormalFactor, m.mapNormalFactor );
  8708. }
  8709. var material = new THREE[ mtype ]( mpars );
  8710. if ( m.DbgName !== undefined ) material.name = m.DbgName;
  8711. return material;
  8712. };
  8713. } )()
  8714. };
  8715. THREE.Loader.Handlers = {
  8716. handlers: [],
  8717. add: function ( regex, loader ) {
  8718. this.handlers.push( regex, loader );
  8719. },
  8720. get: function ( file ) {
  8721. for ( var i = 0, l = this.handlers.length; i < l; i += 2 ) {
  8722. var regex = this.handlers[ i ];
  8723. var loader = this.handlers[ i + 1 ];
  8724. if ( regex.test( file ) ) {
  8725. return loader;
  8726. }
  8727. }
  8728. return null;
  8729. }
  8730. };
  8731. // File:src/loaders/XHRLoader.js
  8732. /**
  8733. * @author mrdoob / http://mrdoob.com/
  8734. */
  8735. THREE.XHRLoader = function ( manager ) {
  8736. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8737. };
  8738. THREE.XHRLoader.prototype = {
  8739. constructor: THREE.XHRLoader,
  8740. load: function ( url, onLoad, onProgress, onError ) {
  8741. var scope = this;
  8742. var cached = THREE.Cache.get( url );
  8743. if ( cached !== undefined ) {
  8744. if ( onLoad ) {
  8745. setTimeout( function () {
  8746. onLoad( cached );
  8747. }, 0 );
  8748. }
  8749. return cached;
  8750. }
  8751. var request = new XMLHttpRequest();
  8752. request.open( 'GET', url, true );
  8753. request.addEventListener( 'load', function ( event ) {
  8754. var response = event.target.response;
  8755. THREE.Cache.add( url, response );
  8756. if ( onLoad ) onLoad( response );
  8757. scope.manager.itemEnd( url );
  8758. }, false );
  8759. if ( onProgress !== undefined ) {
  8760. request.addEventListener( 'progress', function ( event ) {
  8761. onProgress( event );
  8762. }, false );
  8763. }
  8764. request.addEventListener( 'error', function ( event ) {
  8765. if ( onError ) onError( event );
  8766. scope.manager.itemError( url );
  8767. }, false );
  8768. if ( this.crossOrigin !== undefined ) request.crossOrigin = this.crossOrigin;
  8769. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  8770. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  8771. request.send( null );
  8772. scope.manager.itemStart( url );
  8773. return request;
  8774. },
  8775. setResponseType: function ( value ) {
  8776. this.responseType = value;
  8777. },
  8778. setCrossOrigin: function ( value ) {
  8779. this.crossOrigin = value;
  8780. },
  8781. setWithCredentials: function ( value ) {
  8782. this.withCredentials = value;
  8783. }
  8784. };
  8785. // File:src/loaders/ImageLoader.js
  8786. /**
  8787. * @author mrdoob / http://mrdoob.com/
  8788. */
  8789. THREE.ImageLoader = function ( manager ) {
  8790. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8791. };
  8792. THREE.ImageLoader.prototype = {
  8793. constructor: THREE.ImageLoader,
  8794. load: function ( url, onLoad, onProgress, onError ) {
  8795. var scope = this;
  8796. var cached = THREE.Cache.get( url );
  8797. if ( cached !== undefined ) {
  8798. scope.manager.itemStart( url );
  8799. if ( onLoad ) {
  8800. setTimeout( function () {
  8801. onLoad( cached );
  8802. scope.manager.itemEnd( url );
  8803. }, 0 );
  8804. } else {
  8805. scope.manager.itemEnd( url );
  8806. }
  8807. return cached;
  8808. }
  8809. var image = document.createElement( 'img' );
  8810. image.addEventListener( 'load', function ( event ) {
  8811. THREE.Cache.add( url, this );
  8812. if ( onLoad ) onLoad( this );
  8813. scope.manager.itemEnd( url );
  8814. }, false );
  8815. if ( onProgress !== undefined ) {
  8816. image.addEventListener( 'progress', function ( event ) {
  8817. onProgress( event );
  8818. }, false );
  8819. }
  8820. image.addEventListener( 'error', function ( event ) {
  8821. if ( onError ) onError( event );
  8822. scope.manager.itemError( url );
  8823. }, false );
  8824. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  8825. scope.manager.itemStart( url );
  8826. image.src = url;
  8827. return image;
  8828. },
  8829. setCrossOrigin: function ( value ) {
  8830. this.crossOrigin = value;
  8831. }
  8832. };
  8833. // File:src/loaders/JSONLoader.js
  8834. /**
  8835. * @author mrdoob / http://mrdoob.com/
  8836. * @author alteredq / http://alteredqualia.com/
  8837. */
  8838. THREE.JSONLoader = function ( manager ) {
  8839. if ( typeof manager === 'boolean' ) {
  8840. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  8841. manager = undefined;
  8842. }
  8843. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  8844. this.withCredentials = false;
  8845. };
  8846. THREE.JSONLoader.prototype = {
  8847. constructor: THREE.JSONLoader,
  8848. // Deprecated
  8849. get statusDomElement () {
  8850. if ( this._statusDomElement === undefined ) {
  8851. this._statusDomElement = document.createElement( 'div' );
  8852. }
  8853. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  8854. return this._statusDomElement;
  8855. },
  8856. load: function( url, onLoad, onProgress, onError ) {
  8857. var scope = this;
  8858. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  8859. var loader = new THREE.XHRLoader( this.manager );
  8860. loader.setCrossOrigin( this.crossOrigin );
  8861. loader.setWithCredentials( this.withCredentials );
  8862. loader.load( url, function ( text ) {
  8863. var json = JSON.parse( text );
  8864. var metadata = json.metadata;
  8865. if ( metadata !== undefined ) {
  8866. if ( metadata.type === 'object' ) {
  8867. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  8868. return;
  8869. }
  8870. if ( metadata.type === 'scene' ) {
  8871. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  8872. return;
  8873. }
  8874. }
  8875. var object = scope.parse( json, texturePath );
  8876. onLoad( object.geometry, object.materials );
  8877. } );
  8878. },
  8879. setCrossOrigin: function ( value ) {
  8880. this.crossOrigin = value;
  8881. },
  8882. setTexturePath: function ( value ) {
  8883. this.texturePath = value;
  8884. },
  8885. parse: function ( json, texturePath ) {
  8886. var geometry = new THREE.Geometry(),
  8887. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  8888. parseModel( scale );
  8889. parseSkin();
  8890. parseMorphing( scale );
  8891. parseAnimations();
  8892. geometry.computeFaceNormals();
  8893. geometry.computeBoundingSphere();
  8894. function parseModel( scale ) {
  8895. function isBitSet( value, position ) {
  8896. return value & ( 1 << position );
  8897. }
  8898. var i, j, fi,
  8899. offset, zLength,
  8900. colorIndex, normalIndex, uvIndex, materialIndex,
  8901. type,
  8902. isQuad,
  8903. hasMaterial,
  8904. hasFaceVertexUv,
  8905. hasFaceNormal, hasFaceVertexNormal,
  8906. hasFaceColor, hasFaceVertexColor,
  8907. vertex, face, faceA, faceB, hex, normal,
  8908. uvLayer, uv, u, v,
  8909. faces = json.faces,
  8910. vertices = json.vertices,
  8911. normals = json.normals,
  8912. colors = json.colors,
  8913. nUvLayers = 0;
  8914. if ( json.uvs !== undefined ) {
  8915. // disregard empty arrays
  8916. for ( i = 0; i < json.uvs.length; i ++ ) {
  8917. if ( json.uvs[ i ].length ) nUvLayers ++;
  8918. }
  8919. for ( i = 0; i < nUvLayers; i ++ ) {
  8920. geometry.faceVertexUvs[ i ] = [];
  8921. }
  8922. }
  8923. offset = 0;
  8924. zLength = vertices.length;
  8925. while ( offset < zLength ) {
  8926. vertex = new THREE.Vector3();
  8927. vertex.x = vertices[ offset ++ ] * scale;
  8928. vertex.y = vertices[ offset ++ ] * scale;
  8929. vertex.z = vertices[ offset ++ ] * scale;
  8930. geometry.vertices.push( vertex );
  8931. }
  8932. offset = 0;
  8933. zLength = faces.length;
  8934. while ( offset < zLength ) {
  8935. type = faces[ offset ++ ];
  8936. isQuad = isBitSet( type, 0 );
  8937. hasMaterial = isBitSet( type, 1 );
  8938. hasFaceVertexUv = isBitSet( type, 3 );
  8939. hasFaceNormal = isBitSet( type, 4 );
  8940. hasFaceVertexNormal = isBitSet( type, 5 );
  8941. hasFaceColor = isBitSet( type, 6 );
  8942. hasFaceVertexColor = isBitSet( type, 7 );
  8943. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  8944. if ( isQuad ) {
  8945. faceA = new THREE.Face3();
  8946. faceA.a = faces[ offset ];
  8947. faceA.b = faces[ offset + 1 ];
  8948. faceA.c = faces[ offset + 3 ];
  8949. faceB = new THREE.Face3();
  8950. faceB.a = faces[ offset + 1 ];
  8951. faceB.b = faces[ offset + 2 ];
  8952. faceB.c = faces[ offset + 3 ];
  8953. offset += 4;
  8954. if ( hasMaterial ) {
  8955. materialIndex = faces[ offset ++ ];
  8956. faceA.materialIndex = materialIndex;
  8957. faceB.materialIndex = materialIndex;
  8958. }
  8959. // to get face <=> uv index correspondence
  8960. fi = geometry.faces.length;
  8961. if ( hasFaceVertexUv ) {
  8962. for ( i = 0; i < nUvLayers; i ++ ) {
  8963. uvLayer = json.uvs[ i ];
  8964. geometry.faceVertexUvs[ i ][ fi ] = [];
  8965. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  8966. for ( j = 0; j < 4; j ++ ) {
  8967. uvIndex = faces[ offset ++ ];
  8968. u = uvLayer[ uvIndex * 2 ];
  8969. v = uvLayer[ uvIndex * 2 + 1 ];
  8970. uv = new THREE.Vector2( u, v );
  8971. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  8972. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  8973. }
  8974. }
  8975. }
  8976. if ( hasFaceNormal ) {
  8977. normalIndex = faces[ offset ++ ] * 3;
  8978. faceA.normal.set(
  8979. normals[ normalIndex ++ ],
  8980. normals[ normalIndex ++ ],
  8981. normals[ normalIndex ]
  8982. );
  8983. faceB.normal.copy( faceA.normal );
  8984. }
  8985. if ( hasFaceVertexNormal ) {
  8986. for ( i = 0; i < 4; i ++ ) {
  8987. normalIndex = faces[ offset ++ ] * 3;
  8988. normal = new THREE.Vector3(
  8989. normals[ normalIndex ++ ],
  8990. normals[ normalIndex ++ ],
  8991. normals[ normalIndex ]
  8992. );
  8993. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  8994. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  8995. }
  8996. }
  8997. if ( hasFaceColor ) {
  8998. colorIndex = faces[ offset ++ ];
  8999. hex = colors[ colorIndex ];
  9000. faceA.color.setHex( hex );
  9001. faceB.color.setHex( hex );
  9002. }
  9003. if ( hasFaceVertexColor ) {
  9004. for ( i = 0; i < 4; i ++ ) {
  9005. colorIndex = faces[ offset ++ ];
  9006. hex = colors[ colorIndex ];
  9007. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  9008. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  9009. }
  9010. }
  9011. geometry.faces.push( faceA );
  9012. geometry.faces.push( faceB );
  9013. } else {
  9014. face = new THREE.Face3();
  9015. face.a = faces[ offset ++ ];
  9016. face.b = faces[ offset ++ ];
  9017. face.c = faces[ offset ++ ];
  9018. if ( hasMaterial ) {
  9019. materialIndex = faces[ offset ++ ];
  9020. face.materialIndex = materialIndex;
  9021. }
  9022. // to get face <=> uv index correspondence
  9023. fi = geometry.faces.length;
  9024. if ( hasFaceVertexUv ) {
  9025. for ( i = 0; i < nUvLayers; i ++ ) {
  9026. uvLayer = json.uvs[ i ];
  9027. geometry.faceVertexUvs[ i ][ fi ] = [];
  9028. for ( j = 0; j < 3; j ++ ) {
  9029. uvIndex = faces[ offset ++ ];
  9030. u = uvLayer[ uvIndex * 2 ];
  9031. v = uvLayer[ uvIndex * 2 + 1 ];
  9032. uv = new THREE.Vector2( u, v );
  9033. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  9034. }
  9035. }
  9036. }
  9037. if ( hasFaceNormal ) {
  9038. normalIndex = faces[ offset ++ ] * 3;
  9039. face.normal.set(
  9040. normals[ normalIndex ++ ],
  9041. normals[ normalIndex ++ ],
  9042. normals[ normalIndex ]
  9043. );
  9044. }
  9045. if ( hasFaceVertexNormal ) {
  9046. for ( i = 0; i < 3; i ++ ) {
  9047. normalIndex = faces[ offset ++ ] * 3;
  9048. normal = new THREE.Vector3(
  9049. normals[ normalIndex ++ ],
  9050. normals[ normalIndex ++ ],
  9051. normals[ normalIndex ]
  9052. );
  9053. face.vertexNormals.push( normal );
  9054. }
  9055. }
  9056. if ( hasFaceColor ) {
  9057. colorIndex = faces[ offset ++ ];
  9058. face.color.setHex( colors[ colorIndex ] );
  9059. }
  9060. if ( hasFaceVertexColor ) {
  9061. for ( i = 0; i < 3; i ++ ) {
  9062. colorIndex = faces[ offset ++ ];
  9063. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  9064. }
  9065. }
  9066. geometry.faces.push( face );
  9067. }
  9068. }
  9069. };
  9070. function parseSkin() {
  9071. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  9072. if ( json.skinWeights ) {
  9073. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  9074. var x = json.skinWeights[ i ];
  9075. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  9076. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  9077. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  9078. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  9079. }
  9080. }
  9081. if ( json.skinIndices ) {
  9082. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  9083. var a = json.skinIndices[ i ];
  9084. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  9085. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  9086. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  9087. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  9088. }
  9089. }
  9090. geometry.bones = json.bones;
  9091. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  9092. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  9093. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  9094. }
  9095. };
  9096. function parseMorphing( scale ) {
  9097. if ( json.morphTargets !== undefined ) {
  9098. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  9099. geometry.morphTargets[ i ] = {};
  9100. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  9101. geometry.morphTargets[ i ].vertices = [];
  9102. var dstVertices = geometry.morphTargets[ i ].vertices;
  9103. var srcVertices = json.morphTargets[ i ].vertices;
  9104. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  9105. var vertex = new THREE.Vector3();
  9106. vertex.x = srcVertices[ v ] * scale;
  9107. vertex.y = srcVertices[ v + 1 ] * scale;
  9108. vertex.z = srcVertices[ v + 2 ] * scale;
  9109. dstVertices.push( vertex );
  9110. }
  9111. }
  9112. }
  9113. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  9114. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  9115. var faces = geometry.faces;
  9116. var morphColors = json.morphColors[ 0 ].colors;
  9117. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  9118. faces[ i ].color.fromArray( morphColors, i * 3 );
  9119. }
  9120. }
  9121. }
  9122. function parseAnimations() {
  9123. var outputAnimations = [];
  9124. // parse old style Bone/Hierarchy animations
  9125. var animations = [];
  9126. if ( json.animation !== undefined ) {
  9127. animations.push( json.animation );
  9128. }
  9129. if ( json.animations !== undefined ) {
  9130. if ( json.animations.length ) {
  9131. animations = animations.concat( json.animations );
  9132. } else {
  9133. animations.push( json.animations );
  9134. }
  9135. }
  9136. for ( var i = 0; i < animations.length; i ++ ) {
  9137. var clip = THREE.AnimationClip.parseAnimation( animations[i], geometry.bones );
  9138. if ( clip ) outputAnimations.push( clip );
  9139. }
  9140. // parse implicit morph animations
  9141. if ( geometry.morphTargets ) {
  9142. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  9143. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  9144. outputAnimations = outputAnimations.concat( morphAnimationClips );
  9145. }
  9146. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  9147. };
  9148. if ( json.materials === undefined || json.materials.length === 0 ) {
  9149. return { geometry: geometry };
  9150. } else {
  9151. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  9152. return { geometry: geometry, materials: materials };
  9153. }
  9154. }
  9155. };
  9156. // File:src/loaders/LoadingManager.js
  9157. /**
  9158. * @author mrdoob / http://mrdoob.com/
  9159. */
  9160. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  9161. var scope = this;
  9162. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  9163. this.onStart = undefined;
  9164. this.onLoad = onLoad;
  9165. this.onProgress = onProgress;
  9166. this.onError = onError;
  9167. this.itemStart = function ( url ) {
  9168. itemsTotal ++;
  9169. if ( isLoading === false ) {
  9170. if ( scope.onStart !== undefined ) {
  9171. scope.onStart( url, itemsLoaded, itemsTotal );
  9172. }
  9173. }
  9174. isLoading = true;
  9175. };
  9176. this.itemEnd = function ( url ) {
  9177. itemsLoaded ++;
  9178. if ( scope.onProgress !== undefined ) {
  9179. scope.onProgress( url, itemsLoaded, itemsTotal );
  9180. }
  9181. if ( itemsLoaded === itemsTotal ) {
  9182. isLoading = false;
  9183. if ( scope.onLoad !== undefined ) {
  9184. scope.onLoad();
  9185. }
  9186. }
  9187. };
  9188. this.itemError = function ( url ) {
  9189. if ( scope.onError !== undefined ) {
  9190. scope.onError( url );
  9191. }
  9192. };
  9193. };
  9194. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  9195. // File:src/loaders/BufferGeometryLoader.js
  9196. /**
  9197. * @author mrdoob / http://mrdoob.com/
  9198. */
  9199. THREE.BufferGeometryLoader = function ( manager ) {
  9200. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9201. };
  9202. THREE.BufferGeometryLoader.prototype = {
  9203. constructor: THREE.BufferGeometryLoader,
  9204. load: function ( url, onLoad, onProgress, onError ) {
  9205. var scope = this;
  9206. var loader = new THREE.XHRLoader( scope.manager );
  9207. loader.setCrossOrigin( this.crossOrigin );
  9208. loader.load( url, function ( text ) {
  9209. onLoad( scope.parse( JSON.parse( text ) ) );
  9210. }, onProgress, onError );
  9211. },
  9212. setCrossOrigin: function ( value ) {
  9213. this.crossOrigin = value;
  9214. },
  9215. parse: function ( json ) {
  9216. var geometry = new THREE.BufferGeometry();
  9217. var index = json.data.index;
  9218. if ( index !== undefined ) {
  9219. var typedArray = new self[ index.type ]( index.array );
  9220. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  9221. }
  9222. var attributes = json.data.attributes;
  9223. for ( var key in attributes ) {
  9224. var attribute = attributes[ key ];
  9225. var typedArray = new self[ attribute.type ]( attribute.array );
  9226. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  9227. }
  9228. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  9229. if ( groups !== undefined ) {
  9230. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  9231. var group = groups[ i ];
  9232. geometry.addGroup( group.start, group.count );
  9233. }
  9234. }
  9235. var boundingSphere = json.data.boundingSphere;
  9236. if ( boundingSphere !== undefined ) {
  9237. var center = new THREE.Vector3();
  9238. if ( boundingSphere.center !== undefined ) {
  9239. center.fromArray( boundingSphere.center );
  9240. }
  9241. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  9242. }
  9243. return geometry;
  9244. }
  9245. };
  9246. // File:src/loaders/MaterialLoader.js
  9247. /**
  9248. * @author mrdoob / http://mrdoob.com/
  9249. */
  9250. THREE.MaterialLoader = function ( manager ) {
  9251. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9252. this.textures = {};
  9253. };
  9254. THREE.MaterialLoader.prototype = {
  9255. constructor: THREE.MaterialLoader,
  9256. load: function ( url, onLoad, onProgress, onError ) {
  9257. var scope = this;
  9258. var loader = new THREE.XHRLoader( scope.manager );
  9259. loader.setCrossOrigin( this.crossOrigin );
  9260. loader.load( url, function ( text ) {
  9261. onLoad( scope.parse( JSON.parse( text ) ) );
  9262. }, onProgress, onError );
  9263. },
  9264. setCrossOrigin: function ( value ) {
  9265. this.crossOrigin = value;
  9266. },
  9267. setTextures: function ( value ) {
  9268. this.textures = value;
  9269. },
  9270. getTexture: function ( name ) {
  9271. var textures = this.textures;
  9272. if ( textures[ name ] === undefined ) {
  9273. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  9274. }
  9275. return textures[ name ];
  9276. },
  9277. parse: function ( json ) {
  9278. var material = new THREE[ json.type ];
  9279. material.uuid = json.uuid;
  9280. if ( json.name !== undefined ) material.name = json.name;
  9281. if ( json.color !== undefined ) material.color.setHex( json.color );
  9282. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  9283. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  9284. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  9285. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  9286. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  9287. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  9288. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  9289. if ( json.shading !== undefined ) material.shading = json.shading;
  9290. if ( json.blending !== undefined ) material.blending = json.blending;
  9291. if ( json.side !== undefined ) material.side = json.side;
  9292. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  9293. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  9294. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  9295. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  9296. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  9297. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  9298. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  9299. // for PointsMaterial
  9300. if ( json.size !== undefined ) material.size = json.size;
  9301. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  9302. // maps
  9303. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  9304. if ( json.alphaMap !== undefined ) {
  9305. material.alphaMap = this.getTexture( json.alphaMap );
  9306. material.transparent = true;
  9307. }
  9308. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  9309. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  9310. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  9311. if ( json.normalScale ) material.normalScale = new THREE.Vector2( json.normalScale, json.normalScale );
  9312. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  9313. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  9314. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  9315. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  9316. if ( json.envMap !== undefined ) {
  9317. material.envMap = this.getTexture( json.envMap );
  9318. material.combine = THREE.MultiplyOperation;
  9319. }
  9320. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  9321. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  9322. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  9323. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  9324. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  9325. // MeshFaceMaterial
  9326. if ( json.materials !== undefined ) {
  9327. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  9328. material.materials.push( this.parse( json.materials[ i ] ) );
  9329. }
  9330. }
  9331. return material;
  9332. }
  9333. };
  9334. // File:src/loaders/ObjectLoader.js
  9335. /**
  9336. * @author mrdoob / http://mrdoob.com/
  9337. */
  9338. THREE.ObjectLoader = function ( manager ) {
  9339. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9340. this.texturePath = '';
  9341. };
  9342. THREE.ObjectLoader.prototype = {
  9343. constructor: THREE.ObjectLoader,
  9344. load: function ( url, onLoad, onProgress, onError ) {
  9345. if ( this.texturePath === '' ) {
  9346. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  9347. }
  9348. var scope = this;
  9349. var loader = new THREE.XHRLoader( scope.manager );
  9350. loader.setCrossOrigin( this.crossOrigin );
  9351. loader.load( url, function ( text ) {
  9352. scope.parse( JSON.parse( text ), onLoad );
  9353. }, onProgress, onError );
  9354. },
  9355. setTexturePath: function ( value ) {
  9356. this.texturePath = value;
  9357. },
  9358. setCrossOrigin: function ( value ) {
  9359. this.crossOrigin = value;
  9360. },
  9361. parse: function ( json, onLoad ) {
  9362. var geometries = this.parseGeometries( json.geometries );
  9363. var images = this.parseImages( json.images, function () {
  9364. if ( onLoad !== undefined ) onLoad( object );
  9365. } );
  9366. var textures = this.parseTextures( json.textures, images );
  9367. var materials = this.parseMaterials( json.materials, textures );
  9368. var object = this.parseObject( json.object, geometries, materials );
  9369. if ( json.animations ) {
  9370. object.animations = this.parseAnimations( json.animations );
  9371. }
  9372. if ( json.images === undefined || json.images.length === 0 ) {
  9373. if ( onLoad !== undefined ) onLoad( object );
  9374. }
  9375. return object;
  9376. },
  9377. parseGeometries: function ( json ) {
  9378. var geometries = {};
  9379. if ( json !== undefined ) {
  9380. var geometryLoader = new THREE.JSONLoader();
  9381. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  9382. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9383. var geometry;
  9384. var data = json[ i ];
  9385. switch ( data.type ) {
  9386. case 'PlaneGeometry':
  9387. case 'PlaneBufferGeometry':
  9388. geometry = new THREE[ data.type ](
  9389. data.width,
  9390. data.height,
  9391. data.widthSegments,
  9392. data.heightSegments
  9393. );
  9394. break;
  9395. case 'BoxGeometry':
  9396. case 'CubeGeometry': // backwards compatible
  9397. geometry = new THREE.BoxGeometry(
  9398. data.width,
  9399. data.height,
  9400. data.depth,
  9401. data.widthSegments,
  9402. data.heightSegments,
  9403. data.depthSegments
  9404. );
  9405. break;
  9406. case 'CircleBufferGeometry':
  9407. geometry = new THREE.CircleBufferGeometry(
  9408. data.radius,
  9409. data.segments,
  9410. data.thetaStart,
  9411. data.thetaLength
  9412. );
  9413. break;
  9414. case 'CircleGeometry':
  9415. geometry = new THREE.CircleGeometry(
  9416. data.radius,
  9417. data.segments,
  9418. data.thetaStart,
  9419. data.thetaLength
  9420. );
  9421. break;
  9422. case 'CylinderGeometry':
  9423. geometry = new THREE.CylinderGeometry(
  9424. data.radiusTop,
  9425. data.radiusBottom,
  9426. data.height,
  9427. data.radialSegments,
  9428. data.heightSegments,
  9429. data.openEnded,
  9430. data.thetaStart,
  9431. data.thetaLength
  9432. );
  9433. break;
  9434. case 'SphereGeometry':
  9435. geometry = new THREE.SphereGeometry(
  9436. data.radius,
  9437. data.widthSegments,
  9438. data.heightSegments,
  9439. data.phiStart,
  9440. data.phiLength,
  9441. data.thetaStart,
  9442. data.thetaLength
  9443. );
  9444. break;
  9445. case 'SphereBufferGeometry':
  9446. geometry = new THREE.SphereBufferGeometry(
  9447. data.radius,
  9448. data.widthSegments,
  9449. data.heightSegments,
  9450. data.phiStart,
  9451. data.phiLength,
  9452. data.thetaStart,
  9453. data.thetaLength
  9454. );
  9455. break;
  9456. case 'DodecahedronGeometry':
  9457. geometry = new THREE.DodecahedronGeometry(
  9458. data.radius,
  9459. data.detail
  9460. );
  9461. break;
  9462. case 'IcosahedronGeometry':
  9463. geometry = new THREE.IcosahedronGeometry(
  9464. data.radius,
  9465. data.detail
  9466. );
  9467. break;
  9468. case 'OctahedronGeometry':
  9469. geometry = new THREE.OctahedronGeometry(
  9470. data.radius,
  9471. data.detail
  9472. );
  9473. break;
  9474. case 'TetrahedronGeometry':
  9475. geometry = new THREE.TetrahedronGeometry(
  9476. data.radius,
  9477. data.detail
  9478. );
  9479. break;
  9480. case 'RingGeometry':
  9481. geometry = new THREE.RingGeometry(
  9482. data.innerRadius,
  9483. data.outerRadius,
  9484. data.thetaSegments,
  9485. data.phiSegments,
  9486. data.thetaStart,
  9487. data.thetaLength
  9488. );
  9489. break;
  9490. case 'TorusGeometry':
  9491. geometry = new THREE.TorusGeometry(
  9492. data.radius,
  9493. data.tube,
  9494. data.radialSegments,
  9495. data.tubularSegments,
  9496. data.arc
  9497. );
  9498. break;
  9499. case 'TorusKnotGeometry':
  9500. geometry = new THREE.TorusKnotGeometry(
  9501. data.radius,
  9502. data.tube,
  9503. data.radialSegments,
  9504. data.tubularSegments,
  9505. data.p,
  9506. data.q,
  9507. data.heightScale
  9508. );
  9509. break;
  9510. case 'TextGeometry':
  9511. geometry = new THREE.TextGeometry(
  9512. data.text,
  9513. data.data
  9514. );
  9515. break;
  9516. case 'BufferGeometry':
  9517. geometry = bufferGeometryLoader.parse( data );
  9518. break;
  9519. case 'Geometry':
  9520. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  9521. break;
  9522. default:
  9523. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  9524. continue;
  9525. }
  9526. geometry.uuid = data.uuid;
  9527. if ( data.name !== undefined ) geometry.name = data.name;
  9528. geometries[ data.uuid ] = geometry;
  9529. }
  9530. }
  9531. return geometries;
  9532. },
  9533. parseMaterials: function ( json, textures ) {
  9534. var materials = {};
  9535. if ( json !== undefined ) {
  9536. var loader = new THREE.MaterialLoader();
  9537. loader.setTextures( textures );
  9538. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9539. var material = loader.parse( json[ i ] );
  9540. materials[ material.uuid ] = material;
  9541. }
  9542. }
  9543. return materials;
  9544. },
  9545. parseAnimations: function ( json ) {
  9546. var animations = [];
  9547. for ( var i = 0; i < json.length; i ++ ) {
  9548. var clip = THREE.AnimationClip.parse( json[i] );
  9549. animations.push( clip );
  9550. }
  9551. return animations;
  9552. },
  9553. parseImages: function ( json, onLoad ) {
  9554. var scope = this;
  9555. var images = {};
  9556. function loadImage( url ) {
  9557. scope.manager.itemStart( url );
  9558. return loader.load( url, function () {
  9559. scope.manager.itemEnd( url );
  9560. } );
  9561. }
  9562. if ( json !== undefined && json.length > 0 ) {
  9563. var manager = new THREE.LoadingManager( onLoad );
  9564. var loader = new THREE.ImageLoader( manager );
  9565. loader.setCrossOrigin( this.crossOrigin );
  9566. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9567. var image = json[ i ];
  9568. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  9569. images[ image.uuid ] = loadImage( path );
  9570. }
  9571. }
  9572. return images;
  9573. },
  9574. parseTextures: function ( json, images ) {
  9575. function parseConstant( value ) {
  9576. if ( typeof( value ) === 'number' ) return value;
  9577. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  9578. return THREE[ value ];
  9579. }
  9580. var textures = {};
  9581. if ( json !== undefined ) {
  9582. for ( var i = 0, l = json.length; i < l; i ++ ) {
  9583. var data = json[ i ];
  9584. if ( data.image === undefined ) {
  9585. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  9586. }
  9587. if ( images[ data.image ] === undefined ) {
  9588. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  9589. }
  9590. var texture = new THREE.Texture( images[ data.image ] );
  9591. texture.needsUpdate = true;
  9592. texture.uuid = data.uuid;
  9593. if ( data.name !== undefined ) texture.name = data.name;
  9594. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  9595. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  9596. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  9597. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  9598. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  9599. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  9600. if ( Array.isArray( data.wrap ) ) {
  9601. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  9602. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  9603. }
  9604. textures[ data.uuid ] = texture;
  9605. }
  9606. }
  9607. return textures;
  9608. },
  9609. parseObject: function () {
  9610. var matrix = new THREE.Matrix4();
  9611. return function ( data, geometries, materials ) {
  9612. var object;
  9613. function getGeometry( name ) {
  9614. if ( geometries[ name ] === undefined ) {
  9615. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  9616. }
  9617. return geometries[ name ];
  9618. }
  9619. function getMaterial( name ) {
  9620. if ( name === undefined ) return undefined;
  9621. if ( materials[ name ] === undefined ) {
  9622. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  9623. }
  9624. return materials[ name ];
  9625. }
  9626. switch ( data.type ) {
  9627. case 'Scene':
  9628. object = new THREE.Scene();
  9629. break;
  9630. case 'PerspectiveCamera':
  9631. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  9632. break;
  9633. case 'OrthographicCamera':
  9634. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  9635. break;
  9636. case 'AmbientLight':
  9637. object = new THREE.AmbientLight( data.color );
  9638. break;
  9639. case 'DirectionalLight':
  9640. object = new THREE.DirectionalLight( data.color, data.intensity );
  9641. break;
  9642. case 'PointLight':
  9643. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  9644. break;
  9645. case 'SpotLight':
  9646. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.exponent, data.decay );
  9647. break;
  9648. case 'HemisphereLight':
  9649. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  9650. break;
  9651. case 'Mesh':
  9652. object = new THREE.Mesh( getGeometry( data.geometry ), getMaterial( data.material ) );
  9653. break;
  9654. case 'LOD':
  9655. object = new THREE.LOD();
  9656. break;
  9657. case 'Line':
  9658. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  9659. break;
  9660. case 'PointCloud':
  9661. case 'Points':
  9662. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  9663. break;
  9664. case 'Sprite':
  9665. object = new THREE.Sprite( getMaterial( data.material ) );
  9666. break;
  9667. case 'Group':
  9668. object = new THREE.Group();
  9669. break;
  9670. default:
  9671. object = new THREE.Object3D();
  9672. }
  9673. object.uuid = data.uuid;
  9674. if ( data.name !== undefined ) object.name = data.name;
  9675. if ( data.matrix !== undefined ) {
  9676. matrix.fromArray( data.matrix );
  9677. matrix.decompose( object.position, object.quaternion, object.scale );
  9678. } else {
  9679. if ( data.position !== undefined ) object.position.fromArray( data.position );
  9680. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  9681. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  9682. }
  9683. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  9684. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  9685. if ( data.visible !== undefined ) object.visible = data.visible;
  9686. if ( data.userData !== undefined ) object.userData = data.userData;
  9687. if ( data.children !== undefined ) {
  9688. for ( var child in data.children ) {
  9689. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  9690. }
  9691. }
  9692. if ( data.type === 'LOD' ) {
  9693. var levels = data.levels;
  9694. for ( var l = 0; l < levels.length; l ++ ) {
  9695. var level = levels[ l ];
  9696. var child = object.getObjectByProperty( 'uuid', level.object );
  9697. if ( child !== undefined ) {
  9698. object.addLevel( child, level.distance );
  9699. }
  9700. }
  9701. }
  9702. return object;
  9703. }
  9704. }()
  9705. };
  9706. // File:src/loaders/TextureLoader.js
  9707. /**
  9708. * @author mrdoob / http://mrdoob.com/
  9709. */
  9710. THREE.TextureLoader = function ( manager ) {
  9711. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9712. };
  9713. THREE.TextureLoader.prototype = {
  9714. constructor: THREE.TextureLoader,
  9715. load: function ( url, onLoad, onProgress, onError ) {
  9716. var scope = this;
  9717. var loader = new THREE.ImageLoader( scope.manager );
  9718. loader.setCrossOrigin( this.crossOrigin );
  9719. loader.load( url, function ( image ) {
  9720. var texture = new THREE.Texture( image );
  9721. texture.needsUpdate = true;
  9722. if ( onLoad !== undefined ) {
  9723. onLoad( texture );
  9724. }
  9725. }, onProgress, onError );
  9726. },
  9727. setCrossOrigin: function ( value ) {
  9728. this.crossOrigin = value;
  9729. }
  9730. };
  9731. // File:src/loaders/BinaryTextureLoader.js
  9732. /**
  9733. * @author Nikos M. / https://github.com/foo123/
  9734. *
  9735. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  9736. */
  9737. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  9738. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9739. // override in sub classes
  9740. this._parser = null;
  9741. };
  9742. THREE.BinaryTextureLoader.prototype = {
  9743. constructor: THREE.BinaryTextureLoader,
  9744. load: function ( url, onLoad, onProgress, onError ) {
  9745. var scope = this;
  9746. var texture = new THREE.DataTexture();
  9747. var loader = new THREE.XHRLoader( this.manager );
  9748. loader.setCrossOrigin( this.crossOrigin );
  9749. loader.setResponseType( 'arraybuffer' );
  9750. loader.load( url, function ( buffer ) {
  9751. var texData = scope._parser( buffer );
  9752. if ( ! texData ) return;
  9753. if ( undefined !== texData.image ) {
  9754. texture.image = texData.image;
  9755. } else if ( undefined !== texData.data ) {
  9756. texture.image.width = texData.width;
  9757. texture.image.height = texData.height;
  9758. texture.image.data = texData.data;
  9759. }
  9760. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  9761. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  9762. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  9763. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  9764. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  9765. if ( undefined !== texData.format ) {
  9766. texture.format = texData.format;
  9767. }
  9768. if ( undefined !== texData.type ) {
  9769. texture.type = texData.type;
  9770. }
  9771. if ( undefined !== texData.mipmaps ) {
  9772. texture.mipmaps = texData.mipmaps;
  9773. }
  9774. if ( 1 === texData.mipmapCount ) {
  9775. texture.minFilter = THREE.LinearFilter;
  9776. }
  9777. texture.needsUpdate = true;
  9778. if ( onLoad ) onLoad( texture, texData );
  9779. }, onProgress, onError );
  9780. return texture;
  9781. },
  9782. setCrossOrigin: function ( value ) {
  9783. this.crossOrigin = value;
  9784. }
  9785. };
  9786. // File:src/loaders/CompressedTextureLoader.js
  9787. /**
  9788. * @author mrdoob / http://mrdoob.com/
  9789. *
  9790. * Abstract Base class to block based textures loader (dds, pvr, ...)
  9791. */
  9792. THREE.CompressedTextureLoader = function ( manager ) {
  9793. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  9794. // override in sub classes
  9795. this._parser = null;
  9796. };
  9797. THREE.CompressedTextureLoader.prototype = {
  9798. constructor: THREE.CompressedTextureLoader,
  9799. load: function ( url, onLoad, onProgress, onError ) {
  9800. var scope = this;
  9801. var images = [];
  9802. var texture = new THREE.CompressedTexture();
  9803. texture.image = images;
  9804. var loader = new THREE.XHRLoader( this.manager );
  9805. loader.setCrossOrigin( this.crossOrigin );
  9806. loader.setResponseType( 'arraybuffer' );
  9807. if ( Array.isArray( url ) ) {
  9808. var loaded = 0;
  9809. var loadTexture = function ( i ) {
  9810. loader.load( url[ i ], function ( buffer ) {
  9811. var texDatas = scope._parser( buffer, true );
  9812. images[ i ] = {
  9813. width: texDatas.width,
  9814. height: texDatas.height,
  9815. format: texDatas.format,
  9816. mipmaps: texDatas.mipmaps
  9817. };
  9818. loaded += 1;
  9819. if ( loaded === 6 ) {
  9820. if ( texDatas.mipmapCount === 1 )
  9821. texture.minFilter = THREE.LinearFilter;
  9822. texture.format = texDatas.format;
  9823. texture.needsUpdate = true;
  9824. if ( onLoad ) onLoad( texture );
  9825. }
  9826. }, onProgress, onError );
  9827. };
  9828. for ( var i = 0, il = url.length; i < il; ++ i ) {
  9829. loadTexture( i );
  9830. }
  9831. } else {
  9832. // compressed cubemap texture stored in a single DDS file
  9833. loader.load( url, function ( buffer ) {
  9834. var texDatas = scope._parser( buffer, true );
  9835. if ( texDatas.isCubemap ) {
  9836. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  9837. for ( var f = 0; f < faces; f ++ ) {
  9838. images[ f ] = { mipmaps : [] };
  9839. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  9840. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  9841. images[ f ].format = texDatas.format;
  9842. images[ f ].width = texDatas.width;
  9843. images[ f ].height = texDatas.height;
  9844. }
  9845. }
  9846. } else {
  9847. texture.image.width = texDatas.width;
  9848. texture.image.height = texDatas.height;
  9849. texture.mipmaps = texDatas.mipmaps;
  9850. }
  9851. if ( texDatas.mipmapCount === 1 ) {
  9852. texture.minFilter = THREE.LinearFilter;
  9853. }
  9854. texture.format = texDatas.format;
  9855. texture.needsUpdate = true;
  9856. if ( onLoad ) onLoad( texture );
  9857. }, onProgress, onError );
  9858. }
  9859. return texture;
  9860. },
  9861. setCrossOrigin: function ( value ) {
  9862. this.crossOrigin = value;
  9863. }
  9864. };
  9865. // File:src/materials/Material.js
  9866. /**
  9867. * @author mrdoob / http://mrdoob.com/
  9868. * @author alteredq / http://alteredqualia.com/
  9869. */
  9870. THREE.Material = function () {
  9871. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  9872. this.uuid = THREE.Math.generateUUID();
  9873. this.name = '';
  9874. this.type = 'Material';
  9875. this.side = THREE.FrontSide;
  9876. this.opacity = 1;
  9877. this.transparent = false;
  9878. this.blending = THREE.NormalBlending;
  9879. this.blendSrc = THREE.SrcAlphaFactor;
  9880. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  9881. this.blendEquation = THREE.AddEquation;
  9882. this.blendSrcAlpha = null;
  9883. this.blendDstAlpha = null;
  9884. this.blendEquationAlpha = null;
  9885. this.depthFunc = THREE.LessEqualDepth;
  9886. this.depthTest = true;
  9887. this.depthWrite = true;
  9888. this.colorWrite = true;
  9889. this.precision = null; // override the renderer's default precision for this material
  9890. this.polygonOffset = false;
  9891. this.polygonOffsetFactor = 0;
  9892. this.polygonOffsetUnits = 0;
  9893. this.alphaTest = 0;
  9894. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  9895. this.visible = true;
  9896. this._needsUpdate = true;
  9897. };
  9898. THREE.Material.prototype = {
  9899. constructor: THREE.Material,
  9900. get needsUpdate () {
  9901. return this._needsUpdate;
  9902. },
  9903. set needsUpdate ( value ) {
  9904. if ( value === true ) this.update();
  9905. this._needsUpdate = value;
  9906. },
  9907. setValues: function ( values ) {
  9908. if ( values === undefined ) return;
  9909. for ( var key in values ) {
  9910. var newValue = values[ key ];
  9911. if ( newValue === undefined ) {
  9912. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  9913. continue;
  9914. }
  9915. var currentValue = this[ key ];
  9916. if ( currentValue === undefined ) {
  9917. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  9918. continue;
  9919. }
  9920. if ( currentValue instanceof THREE.Color ) {
  9921. currentValue.set( newValue );
  9922. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  9923. currentValue.copy( newValue );
  9924. } else if ( key === 'overdraw' ) {
  9925. // ensure overdraw is backwards-compatible with legacy boolean type
  9926. this[ key ] = Number( newValue );
  9927. } else {
  9928. this[ key ] = newValue;
  9929. }
  9930. }
  9931. },
  9932. toJSON: function ( meta ) {
  9933. var data = {
  9934. metadata: {
  9935. version: 4.4,
  9936. type: 'Material',
  9937. generator: 'Material.toJSON'
  9938. }
  9939. };
  9940. // standard Material serialization
  9941. data.uuid = this.uuid;
  9942. data.type = this.type;
  9943. if ( this.name !== '' ) data.name = this.name;
  9944. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  9945. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  9946. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  9947. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  9948. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  9949. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  9950. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  9951. if ( this.bumpMap instanceof THREE.Texture ) {
  9952. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  9953. data.bumpScale = this.bumpScale;
  9954. }
  9955. if ( this.normalMap instanceof THREE.Texture ) {
  9956. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  9957. data.normalScale = this.normalScale; // Removed for now, causes issue in editor ui.js
  9958. }
  9959. if ( this.displacementMap instanceof THREE.Texture ) {
  9960. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  9961. data.displacementScale = this.displacementScale;
  9962. data.displacementBias = this.displacementBias;
  9963. }
  9964. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  9965. if ( this.envMap instanceof THREE.Texture ) {
  9966. data.envMap = this.envMap.toJSON( meta ).uuid;
  9967. data.reflectivity = this.reflectivity; // Scale behind envMap
  9968. }
  9969. if ( this.size !== undefined ) data.size = this.size;
  9970. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  9971. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  9972. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  9973. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  9974. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  9975. if ( this.opacity < 1 ) data.opacity = this.opacity;
  9976. if ( this.transparent === true ) data.transparent = this.transparent;
  9977. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  9978. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  9979. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  9980. return data;
  9981. },
  9982. clone: function () {
  9983. return new this.constructor().copy( this );
  9984. },
  9985. copy: function ( source ) {
  9986. this.name = source.name;
  9987. this.side = source.side;
  9988. this.opacity = source.opacity;
  9989. this.transparent = source.transparent;
  9990. this.blending = source.blending;
  9991. this.blendSrc = source.blendSrc;
  9992. this.blendDst = source.blendDst;
  9993. this.blendEquation = source.blendEquation;
  9994. this.blendSrcAlpha = source.blendSrcAlpha;
  9995. this.blendDstAlpha = source.blendDstAlpha;
  9996. this.blendEquationAlpha = source.blendEquationAlpha;
  9997. this.depthFunc = source.depthFunc;
  9998. this.depthTest = source.depthTest;
  9999. this.depthWrite = source.depthWrite;
  10000. this.precision = source.precision;
  10001. this.polygonOffset = source.polygonOffset;
  10002. this.polygonOffsetFactor = source.polygonOffsetFactor;
  10003. this.polygonOffsetUnits = source.polygonOffsetUnits;
  10004. this.alphaTest = source.alphaTest;
  10005. this.overdraw = source.overdraw;
  10006. this.visible = source.visible;
  10007. return this;
  10008. },
  10009. update: function () {
  10010. this.dispatchEvent( { type: 'update' } );
  10011. },
  10012. dispose: function () {
  10013. this.dispatchEvent( { type: 'dispose' } );
  10014. },
  10015. // Deprecated
  10016. get wrapAround () {
  10017. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  10018. },
  10019. set wrapAround ( boolean ) {
  10020. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  10021. },
  10022. get wrapRGB () {
  10023. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  10024. return new THREE.Color();
  10025. }
  10026. };
  10027. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  10028. THREE.MaterialIdCount = 0;
  10029. // File:src/materials/LineBasicMaterial.js
  10030. /**
  10031. * @author mrdoob / http://mrdoob.com/
  10032. * @author alteredq / http://alteredqualia.com/
  10033. *
  10034. * parameters = {
  10035. * color: <hex>,
  10036. * opacity: <float>,
  10037. *
  10038. * blending: THREE.NormalBlending,
  10039. * depthTest: <bool>,
  10040. * depthWrite: <bool>,
  10041. *
  10042. * linewidth: <float>,
  10043. * linecap: "round",
  10044. * linejoin: "round",
  10045. *
  10046. * vertexColors: <bool>
  10047. *
  10048. * fog: <bool>
  10049. * }
  10050. */
  10051. THREE.LineBasicMaterial = function ( parameters ) {
  10052. THREE.Material.call( this );
  10053. this.type = 'LineBasicMaterial';
  10054. this.color = new THREE.Color( 0xffffff );
  10055. this.linewidth = 1;
  10056. this.linecap = 'round';
  10057. this.linejoin = 'round';
  10058. this.vertexColors = THREE.NoColors;
  10059. this.fog = true;
  10060. this.setValues( parameters );
  10061. };
  10062. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  10063. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  10064. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  10065. THREE.Material.prototype.copy.call( this, source );
  10066. this.color.copy( source.color );
  10067. this.linewidth = source.linewidth;
  10068. this.linecap = source.linecap;
  10069. this.linejoin = source.linejoin;
  10070. this.vertexColors = source.vertexColors;
  10071. this.fog = source.fog;
  10072. return this;
  10073. };
  10074. // File:src/materials/LineDashedMaterial.js
  10075. /**
  10076. * @author alteredq / http://alteredqualia.com/
  10077. *
  10078. * parameters = {
  10079. * color: <hex>,
  10080. * opacity: <float>,
  10081. *
  10082. * blending: THREE.NormalBlending,
  10083. * depthTest: <bool>,
  10084. * depthWrite: <bool>,
  10085. *
  10086. * linewidth: <float>,
  10087. *
  10088. * scale: <float>,
  10089. * dashSize: <float>,
  10090. * gapSize: <float>,
  10091. *
  10092. * vertexColors: <bool>
  10093. *
  10094. * fog: <bool>
  10095. * }
  10096. */
  10097. THREE.LineDashedMaterial = function ( parameters ) {
  10098. THREE.Material.call( this );
  10099. this.type = 'LineDashedMaterial';
  10100. this.color = new THREE.Color( 0xffffff );
  10101. this.linewidth = 1;
  10102. this.scale = 1;
  10103. this.dashSize = 3;
  10104. this.gapSize = 1;
  10105. this.vertexColors = false;
  10106. this.fog = true;
  10107. this.setValues( parameters );
  10108. };
  10109. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  10110. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  10111. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  10112. THREE.Material.prototype.copy.call( this, source );
  10113. this.color.copy( source.color );
  10114. this.linewidth = source.linewidth;
  10115. this.scale = source.scale;
  10116. this.dashSize = source.dashSize;
  10117. this.gapSize = source.gapSize;
  10118. this.vertexColors = source.vertexColors;
  10119. this.fog = source.fog;
  10120. return this;
  10121. };
  10122. // File:src/materials/MeshBasicMaterial.js
  10123. /**
  10124. * @author mrdoob / http://mrdoob.com/
  10125. * @author alteredq / http://alteredqualia.com/
  10126. *
  10127. * parameters = {
  10128. * color: <hex>,
  10129. * opacity: <float>,
  10130. * map: new THREE.Texture( <Image> ),
  10131. *
  10132. * aoMap: new THREE.Texture( <Image> ),
  10133. * aoMapIntensity: <float>
  10134. *
  10135. * specularMap: new THREE.Texture( <Image> ),
  10136. *
  10137. * alphaMap: new THREE.Texture( <Image> ),
  10138. *
  10139. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10140. * combine: THREE.Multiply,
  10141. * reflectivity: <float>,
  10142. * refractionRatio: <float>,
  10143. *
  10144. * shading: THREE.SmoothShading,
  10145. * blending: THREE.NormalBlending,
  10146. * depthTest: <bool>,
  10147. * depthWrite: <bool>,
  10148. *
  10149. * wireframe: <boolean>,
  10150. * wireframeLinewidth: <float>,
  10151. *
  10152. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10153. *
  10154. * skinning: <bool>,
  10155. * morphTargets: <bool>,
  10156. *
  10157. * fog: <bool>
  10158. * }
  10159. */
  10160. THREE.MeshBasicMaterial = function ( parameters ) {
  10161. THREE.Material.call( this );
  10162. this.type = 'MeshBasicMaterial';
  10163. this.color = new THREE.Color( 0xffffff ); // emissive
  10164. this.map = null;
  10165. this.aoMap = null;
  10166. this.aoMapIntensity = 1.0;
  10167. this.specularMap = null;
  10168. this.alphaMap = null;
  10169. this.envMap = null;
  10170. this.combine = THREE.MultiplyOperation;
  10171. this.reflectivity = 1;
  10172. this.refractionRatio = 0.98;
  10173. this.fog = true;
  10174. this.shading = THREE.SmoothShading;
  10175. this.wireframe = false;
  10176. this.wireframeLinewidth = 1;
  10177. this.wireframeLinecap = 'round';
  10178. this.wireframeLinejoin = 'round';
  10179. this.vertexColors = THREE.NoColors;
  10180. this.skinning = false;
  10181. this.morphTargets = false;
  10182. this.setValues( parameters );
  10183. };
  10184. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  10185. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  10186. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  10187. THREE.Material.prototype.copy.call( this, source );
  10188. this.color.copy( source.color );
  10189. this.map = source.map;
  10190. this.aoMap = source.aoMap;
  10191. this.aoMapIntensity = source.aoMapIntensity;
  10192. this.specularMap = source.specularMap;
  10193. this.alphaMap = source.alphaMap;
  10194. this.envMap = source.envMap;
  10195. this.combine = source.combine;
  10196. this.reflectivity = source.reflectivity;
  10197. this.refractionRatio = source.refractionRatio;
  10198. this.fog = source.fog;
  10199. this.shading = source.shading;
  10200. this.wireframe = source.wireframe;
  10201. this.wireframeLinewidth = source.wireframeLinewidth;
  10202. this.wireframeLinecap = source.wireframeLinecap;
  10203. this.wireframeLinejoin = source.wireframeLinejoin;
  10204. this.vertexColors = source.vertexColors;
  10205. this.skinning = source.skinning;
  10206. this.morphTargets = source.morphTargets;
  10207. return this;
  10208. };
  10209. // File:src/materials/MeshLambertMaterial.js
  10210. /**
  10211. * @author mrdoob / http://mrdoob.com/
  10212. * @author alteredq / http://alteredqualia.com/
  10213. *
  10214. * parameters = {
  10215. * color: <hex>,
  10216. * emissive: <hex>,
  10217. * opacity: <float>,
  10218. *
  10219. * map: new THREE.Texture( <Image> ),
  10220. *
  10221. * specularMap: new THREE.Texture( <Image> ),
  10222. *
  10223. * alphaMap: new THREE.Texture( <Image> ),
  10224. *
  10225. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10226. * combine: THREE.Multiply,
  10227. * reflectivity: <float>,
  10228. * refractionRatio: <float>,
  10229. *
  10230. * blending: THREE.NormalBlending,
  10231. * depthTest: <bool>,
  10232. * depthWrite: <bool>,
  10233. *
  10234. * wireframe: <boolean>,
  10235. * wireframeLinewidth: <float>,
  10236. *
  10237. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10238. *
  10239. * skinning: <bool>,
  10240. * morphTargets: <bool>,
  10241. * morphNormals: <bool>,
  10242. *
  10243. * fog: <bool>
  10244. * }
  10245. */
  10246. THREE.MeshLambertMaterial = function ( parameters ) {
  10247. THREE.Material.call( this );
  10248. this.type = 'MeshLambertMaterial';
  10249. this.color = new THREE.Color( 0xffffff ); // diffuse
  10250. this.emissive = new THREE.Color( 0x000000 );
  10251. this.map = null;
  10252. this.specularMap = null;
  10253. this.alphaMap = null;
  10254. this.envMap = null;
  10255. this.combine = THREE.MultiplyOperation;
  10256. this.reflectivity = 1;
  10257. this.refractionRatio = 0.98;
  10258. this.fog = true;
  10259. this.wireframe = false;
  10260. this.wireframeLinewidth = 1;
  10261. this.wireframeLinecap = 'round';
  10262. this.wireframeLinejoin = 'round';
  10263. this.vertexColors = THREE.NoColors;
  10264. this.skinning = false;
  10265. this.morphTargets = false;
  10266. this.morphNormals = false;
  10267. this.setValues( parameters );
  10268. };
  10269. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  10270. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  10271. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  10272. THREE.Material.prototype.copy.call( this, source );
  10273. this.color.copy( source.color );
  10274. this.emissive.copy( source.emissive );
  10275. this.map = source.map;
  10276. this.specularMap = source.specularMap;
  10277. this.alphaMap = source.alphaMap;
  10278. this.envMap = source.envMap;
  10279. this.combine = source.combine;
  10280. this.reflectivity = source.reflectivity;
  10281. this.refractionRatio = source.refractionRatio;
  10282. this.fog = source.fog;
  10283. this.wireframe = source.wireframe;
  10284. this.wireframeLinewidth = source.wireframeLinewidth;
  10285. this.wireframeLinecap = source.wireframeLinecap;
  10286. this.wireframeLinejoin = source.wireframeLinejoin;
  10287. this.vertexColors = source.vertexColors;
  10288. this.skinning = source.skinning;
  10289. this.morphTargets = source.morphTargets;
  10290. this.morphNormals = source.morphNormals;
  10291. return this;
  10292. };
  10293. // File:src/materials/MeshPhongMaterial.js
  10294. /**
  10295. * @author mrdoob / http://mrdoob.com/
  10296. * @author alteredq / http://alteredqualia.com/
  10297. *
  10298. * parameters = {
  10299. * color: <hex>,
  10300. * emissive: <hex>,
  10301. * specular: <hex>,
  10302. * shininess: <float>,
  10303. * opacity: <float>,
  10304. *
  10305. * map: new THREE.Texture( <Image> ),
  10306. *
  10307. * lightMap: new THREE.Texture( <Image> ),
  10308. * lightMapIntensity: <float>
  10309. *
  10310. * aoMap: new THREE.Texture( <Image> ),
  10311. * aoMapIntensity: <float>
  10312. *
  10313. * emissiveMap: new THREE.Texture( <Image> ),
  10314. *
  10315. * bumpMap: new THREE.Texture( <Image> ),
  10316. * bumpScale: <float>,
  10317. *
  10318. * normalMap: new THREE.Texture( <Image> ),
  10319. * normalScale: <Vector2>,
  10320. *
  10321. * displacementMap: new THREE.Texture( <Image> ),
  10322. * displacementScale: <float>,
  10323. * displacementBias: <float>,
  10324. *
  10325. * specularMap: new THREE.Texture( <Image> ),
  10326. *
  10327. * alphaMap: new THREE.Texture( <Image> ),
  10328. *
  10329. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  10330. * combine: THREE.Multiply,
  10331. * reflectivity: <float>,
  10332. * refractionRatio: <float>,
  10333. *
  10334. * shading: THREE.SmoothShading,
  10335. * blending: THREE.NormalBlending,
  10336. * depthTest: <bool>,
  10337. * depthWrite: <bool>,
  10338. *
  10339. * wireframe: <boolean>,
  10340. * wireframeLinewidth: <float>,
  10341. *
  10342. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10343. *
  10344. * skinning: <bool>,
  10345. * morphTargets: <bool>,
  10346. * morphNormals: <bool>,
  10347. *
  10348. * fog: <bool>
  10349. * }
  10350. */
  10351. THREE.MeshPhongMaterial = function ( parameters ) {
  10352. THREE.Material.call( this );
  10353. this.type = 'MeshPhongMaterial';
  10354. this.color = new THREE.Color( 0xffffff ); // diffuse
  10355. this.emissive = new THREE.Color( 0x000000 );
  10356. this.specular = new THREE.Color( 0x111111 );
  10357. this.shininess = 30;
  10358. this.metal = false;
  10359. this.map = null;
  10360. this.lightMap = null;
  10361. this.lightMapIntensity = 1.0;
  10362. this.aoMap = null;
  10363. this.aoMapIntensity = 1.0;
  10364. this.emissiveMap = null;
  10365. this.bumpMap = null;
  10366. this.bumpScale = 1;
  10367. this.normalMap = null;
  10368. this.normalScale = new THREE.Vector2( 1, 1 );
  10369. this.displacementMap = null;
  10370. this.displacementScale = 1;
  10371. this.displacementBias = 0;
  10372. this.specularMap = null;
  10373. this.alphaMap = null;
  10374. this.envMap = null;
  10375. this.combine = THREE.MultiplyOperation;
  10376. this.reflectivity = 1;
  10377. this.refractionRatio = 0.98;
  10378. this.fog = true;
  10379. this.shading = THREE.SmoothShading;
  10380. this.wireframe = false;
  10381. this.wireframeLinewidth = 1;
  10382. this.wireframeLinecap = 'round';
  10383. this.wireframeLinejoin = 'round';
  10384. this.vertexColors = THREE.NoColors;
  10385. this.skinning = false;
  10386. this.morphTargets = false;
  10387. this.morphNormals = false;
  10388. this.setValues( parameters );
  10389. };
  10390. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  10391. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  10392. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  10393. THREE.Material.prototype.copy.call( this, source );
  10394. this.color.copy( source.color );
  10395. this.emissive.copy( source.emissive );
  10396. this.specular.copy( source.specular );
  10397. this.shininess = source.shininess;
  10398. this.metal = source.metal;
  10399. this.map = source.map;
  10400. this.lightMap = source.lightMap;
  10401. this.lightMapIntensity = source.lightMapIntensity;
  10402. this.aoMap = source.aoMap;
  10403. this.aoMapIntensity = source.aoMapIntensity;
  10404. this.emissiveMap = source.emissiveMap;
  10405. this.bumpMap = source.bumpMap;
  10406. this.bumpScale = source.bumpScale;
  10407. this.normalMap = source.normalMap;
  10408. this.normalScale.copy( source.normalScale );
  10409. this.displacementMap = source.displacementMap;
  10410. this.displacementScale = source.displacementScale;
  10411. this.displacementBias = source.displacementBias;
  10412. this.specularMap = source.specularMap;
  10413. this.alphaMap = source.alphaMap;
  10414. this.envMap = source.envMap;
  10415. this.combine = source.combine;
  10416. this.reflectivity = source.reflectivity;
  10417. this.refractionRatio = source.refractionRatio;
  10418. this.fog = source.fog;
  10419. this.shading = source.shading;
  10420. this.wireframe = source.wireframe;
  10421. this.wireframeLinewidth = source.wireframeLinewidth;
  10422. this.wireframeLinecap = source.wireframeLinecap;
  10423. this.wireframeLinejoin = source.wireframeLinejoin;
  10424. this.vertexColors = source.vertexColors;
  10425. this.skinning = source.skinning;
  10426. this.morphTargets = source.morphTargets;
  10427. this.morphNormals = source.morphNormals;
  10428. return this;
  10429. };
  10430. // File:src/materials/MeshDepthMaterial.js
  10431. /**
  10432. * @author mrdoob / http://mrdoob.com/
  10433. * @author alteredq / http://alteredqualia.com/
  10434. *
  10435. * parameters = {
  10436. * opacity: <float>,
  10437. *
  10438. * blending: THREE.NormalBlending,
  10439. * depthTest: <bool>,
  10440. * depthWrite: <bool>,
  10441. *
  10442. * wireframe: <boolean>,
  10443. * wireframeLinewidth: <float>
  10444. * }
  10445. */
  10446. THREE.MeshDepthMaterial = function ( parameters ) {
  10447. THREE.Material.call( this );
  10448. this.type = 'MeshDepthMaterial';
  10449. this.morphTargets = false;
  10450. this.wireframe = false;
  10451. this.wireframeLinewidth = 1;
  10452. this.setValues( parameters );
  10453. };
  10454. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  10455. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  10456. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  10457. THREE.Material.prototype.copy.call( this, source );
  10458. this.wireframe = source.wireframe;
  10459. this.wireframeLinewidth = source.wireframeLinewidth;
  10460. return this;
  10461. };
  10462. // File:src/materials/MeshNormalMaterial.js
  10463. /**
  10464. * @author mrdoob / http://mrdoob.com/
  10465. *
  10466. * parameters = {
  10467. * opacity: <float>,
  10468. *
  10469. * shading: THREE.FlatShading,
  10470. * blending: THREE.NormalBlending,
  10471. * depthTest: <bool>,
  10472. * depthWrite: <bool>,
  10473. *
  10474. * wireframe: <boolean>,
  10475. * wireframeLinewidth: <float>
  10476. * }
  10477. */
  10478. THREE.MeshNormalMaterial = function ( parameters ) {
  10479. THREE.Material.call( this, parameters );
  10480. this.type = 'MeshNormalMaterial';
  10481. this.wireframe = false;
  10482. this.wireframeLinewidth = 1;
  10483. this.morphTargets = false;
  10484. this.setValues( parameters );
  10485. };
  10486. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  10487. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  10488. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  10489. THREE.Material.prototype.copy.call( this, source );
  10490. this.wireframe = source.wireframe;
  10491. this.wireframeLinewidth = source.wireframeLinewidth;
  10492. return this;
  10493. };
  10494. // File:src/materials/MultiMaterial.js
  10495. /**
  10496. * @author mrdoob / http://mrdoob.com/
  10497. */
  10498. THREE.MultiMaterial = function ( materials ) {
  10499. this.uuid = THREE.Math.generateUUID();
  10500. this.type = 'MultiMaterial';
  10501. this.materials = materials instanceof Array ? materials : [];
  10502. this.visible = true;
  10503. };
  10504. THREE.MultiMaterial.prototype = {
  10505. constructor: THREE.MultiMaterial,
  10506. toJSON: function () {
  10507. var output = {
  10508. metadata: {
  10509. version: 4.2,
  10510. type: 'material',
  10511. generator: 'MaterialExporter'
  10512. },
  10513. uuid: this.uuid,
  10514. type: this.type,
  10515. materials: []
  10516. };
  10517. for ( var i = 0, l = this.materials.length; i < l; i ++ ) {
  10518. output.materials.push( this.materials[ i ].toJSON() );
  10519. }
  10520. output.visible = this.visible;
  10521. return output;
  10522. },
  10523. clone: function () {
  10524. var material = new this.constructor();
  10525. for ( var i = 0; i < this.materials.length; i ++ ) {
  10526. material.materials.push( this.materials[ i ].clone() );
  10527. }
  10528. material.visible = this.visible;
  10529. return material;
  10530. }
  10531. };
  10532. // backwards compatibility
  10533. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  10534. // File:src/materials/PointsMaterial.js
  10535. /**
  10536. * @author mrdoob / http://mrdoob.com/
  10537. * @author alteredq / http://alteredqualia.com/
  10538. *
  10539. * parameters = {
  10540. * color: <hex>,
  10541. * opacity: <float>,
  10542. * map: new THREE.Texture( <Image> ),
  10543. *
  10544. * size: <float>,
  10545. * sizeAttenuation: <bool>,
  10546. *
  10547. * blending: THREE.NormalBlending,
  10548. * depthTest: <bool>,
  10549. * depthWrite: <bool>,
  10550. *
  10551. * vertexColors: <bool>,
  10552. *
  10553. * fog: <bool>
  10554. * }
  10555. */
  10556. THREE.PointsMaterial = function ( parameters ) {
  10557. THREE.Material.call( this );
  10558. this.type = 'PointsMaterial';
  10559. this.color = new THREE.Color( 0xffffff );
  10560. this.map = null;
  10561. this.size = 1;
  10562. this.sizeAttenuation = true;
  10563. this.vertexColors = THREE.NoColors;
  10564. this.fog = true;
  10565. this.setValues( parameters );
  10566. };
  10567. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  10568. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  10569. THREE.PointsMaterial.prototype.copy = function ( source ) {
  10570. THREE.Material.prototype.copy.call( this, source );
  10571. this.color.copy( source.color );
  10572. this.map = source.map;
  10573. this.size = source.size;
  10574. this.sizeAttenuation = source.sizeAttenuation;
  10575. this.vertexColors = source.vertexColors;
  10576. this.fog = source.fog;
  10577. return this;
  10578. };
  10579. // backwards compatibility
  10580. THREE.PointCloudMaterial = function ( parameters ) {
  10581. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  10582. return new THREE.PointsMaterial( parameters );
  10583. };
  10584. THREE.ParticleBasicMaterial = function ( parameters ) {
  10585. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  10586. return new THREE.PointsMaterial( parameters );
  10587. };
  10588. THREE.ParticleSystemMaterial = function ( parameters ) {
  10589. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  10590. return new THREE.PointsMaterial( parameters );
  10591. };
  10592. // File:src/materials/ShaderMaterial.js
  10593. /**
  10594. * @author alteredq / http://alteredqualia.com/
  10595. *
  10596. * parameters = {
  10597. * defines: { "label" : "value" },
  10598. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  10599. *
  10600. * fragmentShader: <string>,
  10601. * vertexShader: <string>,
  10602. *
  10603. * shading: THREE.SmoothShading,
  10604. * blending: THREE.NormalBlending,
  10605. * depthTest: <bool>,
  10606. * depthWrite: <bool>,
  10607. *
  10608. * wireframe: <boolean>,
  10609. * wireframeLinewidth: <float>,
  10610. *
  10611. * lights: <bool>,
  10612. *
  10613. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  10614. *
  10615. * skinning: <bool>,
  10616. * morphTargets: <bool>,
  10617. * morphNormals: <bool>,
  10618. *
  10619. * fog: <bool>
  10620. * }
  10621. */
  10622. THREE.ShaderMaterial = function ( parameters ) {
  10623. THREE.Material.call( this );
  10624. this.type = 'ShaderMaterial';
  10625. this.defines = {};
  10626. this.uniforms = {};
  10627. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  10628. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  10629. this.shading = THREE.SmoothShading;
  10630. this.linewidth = 1;
  10631. this.wireframe = false;
  10632. this.wireframeLinewidth = 1;
  10633. this.fog = false; // set to use scene fog
  10634. this.lights = false; // set to use scene lights
  10635. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  10636. this.skinning = false; // set to use skinning attribute streams
  10637. this.morphTargets = false; // set to use morph targets
  10638. this.morphNormals = false; // set to use morph normals
  10639. this.derivatives = false; // set to use derivatives
  10640. // When rendered geometry doesn't include these attributes but the material does,
  10641. // use these default values in WebGL. This avoids errors when buffer data is missing.
  10642. this.defaultAttributeValues = {
  10643. 'color': [ 1, 1, 1 ],
  10644. 'uv': [ 0, 0 ],
  10645. 'uv2': [ 0, 0 ]
  10646. };
  10647. this.index0AttributeName = undefined;
  10648. if ( parameters !== undefined ) {
  10649. if ( parameters.attributes !== undefined ) {
  10650. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  10651. }
  10652. this.setValues( parameters );
  10653. }
  10654. };
  10655. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  10656. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  10657. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  10658. THREE.Material.prototype.copy.call( this, source );
  10659. this.fragmentShader = source.fragmentShader;
  10660. this.vertexShader = source.vertexShader;
  10661. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  10662. this.attributes = source.attributes;
  10663. this.defines = source.defines;
  10664. this.shading = source.shading;
  10665. this.wireframe = source.wireframe;
  10666. this.wireframeLinewidth = source.wireframeLinewidth;
  10667. this.fog = source.fog;
  10668. this.lights = source.lights;
  10669. this.vertexColors = source.vertexColors;
  10670. this.skinning = source.skinning;
  10671. this.morphTargets = source.morphTargets;
  10672. this.morphNormals = source.morphNormals;
  10673. this.derivatives = source.derivatives;
  10674. return this;
  10675. };
  10676. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  10677. var data = THREE.Material.prototype.toJSON.call( this, meta );
  10678. data.uniforms = this.uniforms;
  10679. data.attributes = this.attributes;
  10680. data.vertexShader = this.vertexShader;
  10681. data.fragmentShader = this.fragmentShader;
  10682. return data;
  10683. };
  10684. // File:src/materials/RawShaderMaterial.js
  10685. /**
  10686. * @author mrdoob / http://mrdoob.com/
  10687. */
  10688. THREE.RawShaderMaterial = function ( parameters ) {
  10689. THREE.ShaderMaterial.call( this, parameters );
  10690. this.type = 'RawShaderMaterial';
  10691. };
  10692. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  10693. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  10694. // File:src/materials/SpriteMaterial.js
  10695. /**
  10696. * @author alteredq / http://alteredqualia.com/
  10697. *
  10698. * parameters = {
  10699. * color: <hex>,
  10700. * opacity: <float>,
  10701. * map: new THREE.Texture( <Image> ),
  10702. *
  10703. * blending: THREE.NormalBlending,
  10704. * depthTest: <bool>,
  10705. * depthWrite: <bool>,
  10706. *
  10707. * uvOffset: new THREE.Vector2(),
  10708. * uvScale: new THREE.Vector2(),
  10709. *
  10710. * fog: <bool>
  10711. * }
  10712. */
  10713. THREE.SpriteMaterial = function ( parameters ) {
  10714. THREE.Material.call( this );
  10715. this.type = 'SpriteMaterial';
  10716. this.color = new THREE.Color( 0xffffff );
  10717. this.map = null;
  10718. this.rotation = 0;
  10719. this.fog = false;
  10720. // set parameters
  10721. this.setValues( parameters );
  10722. };
  10723. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  10724. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  10725. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  10726. THREE.Material.prototype.copy.call( this, source );
  10727. this.color.copy( source.color );
  10728. this.map = source.map;
  10729. this.rotation = source.rotation;
  10730. this.fog = source.fog;
  10731. return this;
  10732. };
  10733. // File:src/textures/Texture.js
  10734. /**
  10735. * @author mrdoob / http://mrdoob.com/
  10736. * @author alteredq / http://alteredqualia.com/
  10737. * @author szimek / https://github.com/szimek/
  10738. */
  10739. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10740. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  10741. this.uuid = THREE.Math.generateUUID();
  10742. this.name = '';
  10743. this.sourceFile = '';
  10744. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  10745. this.mipmaps = [];
  10746. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  10747. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  10748. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  10749. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  10750. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  10751. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  10752. this.format = format !== undefined ? format : THREE.RGBAFormat;
  10753. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  10754. this.offset = new THREE.Vector2( 0, 0 );
  10755. this.repeat = new THREE.Vector2( 1, 1 );
  10756. this.generateMipmaps = true;
  10757. this.premultiplyAlpha = false;
  10758. this.flipY = true;
  10759. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  10760. this.version = 0;
  10761. this.onUpdate = null;
  10762. };
  10763. THREE.Texture.DEFAULT_IMAGE = undefined;
  10764. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  10765. THREE.Texture.prototype = {
  10766. constructor: THREE.Texture,
  10767. set needsUpdate ( value ) {
  10768. if ( value === true ) this.version ++;
  10769. },
  10770. clone: function () {
  10771. return new this.constructor().copy( this );
  10772. },
  10773. copy: function ( source ) {
  10774. this.image = source.image;
  10775. this.mipmaps = source.mipmaps.slice( 0 );
  10776. this.mapping = source.mapping;
  10777. this.wrapS = source.wrapS;
  10778. this.wrapT = source.wrapT;
  10779. this.magFilter = source.magFilter;
  10780. this.minFilter = source.minFilter;
  10781. this.anisotropy = source.anisotropy;
  10782. this.format = source.format;
  10783. this.type = source.type;
  10784. this.offset.copy( source.offset );
  10785. this.repeat.copy( source.repeat );
  10786. this.generateMipmaps = source.generateMipmaps;
  10787. this.premultiplyAlpha = source.premultiplyAlpha;
  10788. this.flipY = source.flipY;
  10789. this.unpackAlignment = source.unpackAlignment;
  10790. return this;
  10791. },
  10792. toJSON: function ( meta ) {
  10793. if ( meta.textures[ this.uuid ] !== undefined ) {
  10794. return meta.textures[ this.uuid ];
  10795. }
  10796. function getDataURL( image ) {
  10797. var canvas;
  10798. if ( image.toDataURL !== undefined ) {
  10799. canvas = image;
  10800. } else {
  10801. canvas = document.createElement( 'canvas' );
  10802. canvas.width = image.width;
  10803. canvas.height = image.height;
  10804. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  10805. }
  10806. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  10807. return canvas.toDataURL( 'image/jpeg', 0.6 );
  10808. } else {
  10809. return canvas.toDataURL( 'image/png' );
  10810. }
  10811. }
  10812. var output = {
  10813. metadata: {
  10814. version: 4.4,
  10815. type: 'Texture',
  10816. generator: 'Texture.toJSON'
  10817. },
  10818. uuid: this.uuid,
  10819. name: this.name,
  10820. mapping: this.mapping,
  10821. repeat: [ this.repeat.x, this.repeat.y ],
  10822. offset: [ this.offset.x, this.offset.y ],
  10823. wrap: [ this.wrapS, this.wrapT ],
  10824. minFilter: this.minFilter,
  10825. magFilter: this.magFilter,
  10826. anisotropy: this.anisotropy
  10827. };
  10828. if ( this.image !== undefined ) {
  10829. // TODO: Move to THREE.Image
  10830. var image = this.image;
  10831. if ( image.uuid === undefined ) {
  10832. image.uuid = THREE.Math.generateUUID(); // UGH
  10833. }
  10834. if ( meta.images[ image.uuid ] === undefined ) {
  10835. meta.images[ image.uuid ] = {
  10836. uuid: image.uuid,
  10837. url: getDataURL( image )
  10838. };
  10839. }
  10840. output.image = image.uuid;
  10841. }
  10842. meta.textures[ this.uuid ] = output;
  10843. return output;
  10844. },
  10845. dispose: function () {
  10846. this.dispatchEvent( { type: 'dispose' } );
  10847. },
  10848. transformUv: function ( uv ) {
  10849. if ( this.mapping !== THREE.UVMapping ) return;
  10850. uv.multiply( this.repeat );
  10851. uv.add( this.offset );
  10852. if ( uv.x < 0 || uv.x > 1 ) {
  10853. switch ( this.wrapS ) {
  10854. case THREE.RepeatWrapping:
  10855. uv.x = uv.x - Math.floor( uv.x );
  10856. break;
  10857. case THREE.ClampToEdgeWrapping:
  10858. uv.x = uv.x < 0 ? 0 : 1;
  10859. break;
  10860. case THREE.MirroredRepeatWrapping:
  10861. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  10862. uv.x = Math.ceil( uv.x ) - uv.x;
  10863. } else {
  10864. uv.x = uv.x - Math.floor( uv.x );
  10865. }
  10866. break;
  10867. }
  10868. }
  10869. if ( uv.y < 0 || uv.y > 1 ) {
  10870. switch ( this.wrapT ) {
  10871. case THREE.RepeatWrapping:
  10872. uv.y = uv.y - Math.floor( uv.y );
  10873. break;
  10874. case THREE.ClampToEdgeWrapping:
  10875. uv.y = uv.y < 0 ? 0 : 1;
  10876. break;
  10877. case THREE.MirroredRepeatWrapping:
  10878. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  10879. uv.y = Math.ceil( uv.y ) - uv.y;
  10880. } else {
  10881. uv.y = uv.y - Math.floor( uv.y );
  10882. }
  10883. break;
  10884. }
  10885. }
  10886. if ( this.flipY ) {
  10887. uv.y = 1 - uv.y;
  10888. }
  10889. }
  10890. };
  10891. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  10892. THREE.TextureIdCount = 0;
  10893. // File:src/textures/CanvasTexture.js
  10894. /**
  10895. * @author mrdoob / http://mrdoob.com/
  10896. */
  10897. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10898. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10899. this.needsUpdate = true;
  10900. };
  10901. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  10902. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  10903. // File:src/textures/CubeTexture.js
  10904. /**
  10905. * @author mrdoob / http://mrdoob.com/
  10906. */
  10907. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10908. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  10909. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10910. this.images = images;
  10911. this.flipY = false;
  10912. };
  10913. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  10914. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  10915. THREE.CubeTexture.prototype.copy = function ( source ) {
  10916. THREE.Texture.prototype.copy.call( this, source );
  10917. this.images = source.images;
  10918. return this;
  10919. };
  10920. // File:src/textures/CompressedTexture.js
  10921. /**
  10922. * @author alteredq / http://alteredqualia.com/
  10923. */
  10924. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10925. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10926. this.image = { width: width, height: height };
  10927. this.mipmaps = mipmaps;
  10928. // no flipping for cube textures
  10929. // (also flipping doesn't work for compressed textures )
  10930. this.flipY = false;
  10931. // can't generate mipmaps for compressed textures
  10932. // mips must be embedded in DDS files
  10933. this.generateMipmaps = false;
  10934. };
  10935. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  10936. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  10937. // File:src/textures/DataTexture.js
  10938. /**
  10939. * @author alteredq / http://alteredqualia.com/
  10940. */
  10941. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  10942. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10943. this.image = { data: data, width: width, height: height };
  10944. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  10945. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  10946. this.flipY = false;
  10947. this.generateMipmaps = false;
  10948. };
  10949. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  10950. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  10951. // File:src/textures/VideoTexture.js
  10952. /**
  10953. * @author mrdoob / http://mrdoob.com/
  10954. */
  10955. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  10956. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  10957. this.generateMipmaps = false;
  10958. var scope = this;
  10959. function update() {
  10960. requestAnimationFrame( update );
  10961. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  10962. scope.needsUpdate = true;
  10963. }
  10964. }
  10965. update();
  10966. };
  10967. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  10968. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  10969. // File:src/objects/Group.js
  10970. /**
  10971. * @author mrdoob / http://mrdoob.com/
  10972. */
  10973. THREE.Group = function () {
  10974. THREE.Object3D.call( this );
  10975. this.type = 'Group';
  10976. };
  10977. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  10978. THREE.Group.prototype.constructor = THREE.Group;
  10979. // File:src/objects/Points.js
  10980. /**
  10981. * @author alteredq / http://alteredqualia.com/
  10982. */
  10983. THREE.Points = function ( geometry, material ) {
  10984. THREE.Object3D.call( this );
  10985. this.type = 'Points';
  10986. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  10987. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  10988. };
  10989. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  10990. THREE.Points.prototype.constructor = THREE.Points;
  10991. THREE.Points.prototype.raycast = ( function () {
  10992. var inverseMatrix = new THREE.Matrix4();
  10993. var ray = new THREE.Ray();
  10994. return function raycast( raycaster, intersects ) {
  10995. var object = this;
  10996. var geometry = object.geometry;
  10997. var threshold = raycaster.params.Points.threshold;
  10998. inverseMatrix.getInverse( this.matrixWorld );
  10999. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11000. if ( geometry.boundingBox !== null ) {
  11001. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) {
  11002. return;
  11003. }
  11004. }
  11005. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  11006. var localThresholdSq = localThreshold * localThreshold;
  11007. var position = new THREE.Vector3();
  11008. function testPoint( point, index ) {
  11009. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  11010. if ( rayPointDistanceSq < localThresholdSq ) {
  11011. var intersectPoint = ray.closestPointToPoint( point );
  11012. intersectPoint.applyMatrix4( object.matrixWorld );
  11013. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  11014. if ( distance < raycaster.near || distance > raycaster.far ) return;
  11015. intersects.push( {
  11016. distance: distance,
  11017. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  11018. point: intersectPoint.clone(),
  11019. index: index,
  11020. face: null,
  11021. object: object
  11022. } );
  11023. }
  11024. }
  11025. if ( geometry instanceof THREE.BufferGeometry ) {
  11026. var index = geometry.index;
  11027. var attributes = geometry.attributes;
  11028. var positions = attributes.position.array;
  11029. if ( index !== null ) {
  11030. var indices = index.array;
  11031. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  11032. var a = indices[ i ];
  11033. position.fromArray( positions, a * 3 );
  11034. testPoint( position, a );
  11035. }
  11036. } else {
  11037. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  11038. position.fromArray( positions, i * 3 );
  11039. testPoint( position, i );
  11040. }
  11041. }
  11042. } else {
  11043. var vertices = geometry.vertices;
  11044. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  11045. testPoint( vertices[ i ], i );
  11046. }
  11047. }
  11048. };
  11049. }() );
  11050. THREE.Points.prototype.clone = function () {
  11051. return new this.constructor( this.geometry, this.material ).copy( this );
  11052. };
  11053. // Backwards compatibility
  11054. THREE.PointCloud = function ( geometry, material ) {
  11055. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  11056. return new THREE.Points( geometry, material );
  11057. };
  11058. THREE.ParticleSystem = function ( geometry, material ) {
  11059. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  11060. return new THREE.Points( geometry, material );
  11061. };
  11062. // File:src/objects/Line.js
  11063. /**
  11064. * @author mrdoob / http://mrdoob.com/
  11065. */
  11066. THREE.Line = function ( geometry, material, mode ) {
  11067. if ( mode === 1 ) {
  11068. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  11069. return new THREE.LineSegments( geometry, material );
  11070. }
  11071. THREE.Object3D.call( this );
  11072. this.type = 'Line';
  11073. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11074. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  11075. };
  11076. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  11077. THREE.Line.prototype.constructor = THREE.Line;
  11078. THREE.Line.prototype.raycast = ( function () {
  11079. var inverseMatrix = new THREE.Matrix4();
  11080. var ray = new THREE.Ray();
  11081. var sphere = new THREE.Sphere();
  11082. return function raycast( raycaster, intersects ) {
  11083. var precision = raycaster.linePrecision;
  11084. var precisionSq = precision * precision;
  11085. var geometry = this.geometry;
  11086. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11087. // Checking boundingSphere distance to ray
  11088. sphere.copy( geometry.boundingSphere );
  11089. sphere.applyMatrix4( this.matrixWorld );
  11090. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) {
  11091. return;
  11092. }
  11093. inverseMatrix.getInverse( this.matrixWorld );
  11094. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11095. var vStart = new THREE.Vector3();
  11096. var vEnd = new THREE.Vector3();
  11097. var interSegment = new THREE.Vector3();
  11098. var interRay = new THREE.Vector3();
  11099. var step = this instanceof THREE.LineSegments ? 2 : 1;
  11100. if ( geometry instanceof THREE.BufferGeometry ) {
  11101. var index = geometry.index;
  11102. var attributes = geometry.attributes;
  11103. if ( index !== null ) {
  11104. var indices = index.array;
  11105. var positions = attributes.position.array;
  11106. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  11107. var a = indices[ i ];
  11108. var b = indices[ i + 1 ];
  11109. vStart.fromArray( positions, a * 3 );
  11110. vEnd.fromArray( positions, b * 3 );
  11111. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11112. if ( distSq > precisionSq ) continue;
  11113. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11114. var distance = raycaster.ray.origin.distanceTo( interRay );
  11115. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11116. intersects.push( {
  11117. distance: distance,
  11118. // What do we want? intersection point on the ray or on the segment??
  11119. // point: raycaster.ray.at( distance ),
  11120. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11121. index: i,
  11122. face: null,
  11123. faceIndex: null,
  11124. object: this
  11125. } );
  11126. }
  11127. } else {
  11128. var positions = attributes.position.array;
  11129. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  11130. vStart.fromArray( positions, 3 * i );
  11131. vEnd.fromArray( positions, 3 * i + 3 );
  11132. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  11133. if ( distSq > precisionSq ) continue;
  11134. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11135. var distance = raycaster.ray.origin.distanceTo( interRay );
  11136. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11137. intersects.push( {
  11138. distance: distance,
  11139. // What do we want? intersection point on the ray or on the segment??
  11140. // point: raycaster.ray.at( distance ),
  11141. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11142. index: i,
  11143. face: null,
  11144. faceIndex: null,
  11145. object: this
  11146. } );
  11147. }
  11148. }
  11149. } else if ( geometry instanceof THREE.Geometry ) {
  11150. var vertices = geometry.vertices;
  11151. var nbVertices = vertices.length;
  11152. for ( var i = 0; i < nbVertices - 1; i += step ) {
  11153. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  11154. if ( distSq > precisionSq ) continue;
  11155. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  11156. var distance = raycaster.ray.origin.distanceTo( interRay );
  11157. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  11158. intersects.push( {
  11159. distance: distance,
  11160. // What do we want? intersection point on the ray or on the segment??
  11161. // point: raycaster.ray.at( distance ),
  11162. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  11163. index: i,
  11164. face: null,
  11165. faceIndex: null,
  11166. object: this
  11167. } );
  11168. }
  11169. }
  11170. };
  11171. }() );
  11172. THREE.Line.prototype.clone = function () {
  11173. return new this.constructor( this.geometry, this.material ).copy( this );
  11174. };
  11175. // DEPRECATED
  11176. THREE.LineStrip = 0;
  11177. THREE.LinePieces = 1;
  11178. // File:src/objects/LineSegments.js
  11179. /**
  11180. * @author mrdoob / http://mrdoob.com/
  11181. */
  11182. THREE.LineSegments = function ( geometry, material ) {
  11183. THREE.Line.call( this, geometry, material );
  11184. this.type = 'LineSegments';
  11185. };
  11186. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  11187. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  11188. // File:src/objects/Mesh.js
  11189. /**
  11190. * @author mrdoob / http://mrdoob.com/
  11191. * @author alteredq / http://alteredqualia.com/
  11192. * @author mikael emtinger / http://gomo.se/
  11193. * @author jonobr1 / http://jonobr1.com/
  11194. */
  11195. THREE.Mesh = function ( geometry, material ) {
  11196. THREE.Object3D.call( this );
  11197. this.type = 'Mesh';
  11198. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  11199. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  11200. this.updateMorphTargets();
  11201. };
  11202. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  11203. THREE.Mesh.prototype.constructor = THREE.Mesh;
  11204. THREE.Mesh.prototype.updateMorphTargets = function () {
  11205. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  11206. this.morphTargetBase = - 1;
  11207. this.morphTargetInfluences = [];
  11208. this.morphTargetDictionary = {};
  11209. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  11210. this.morphTargetInfluences.push( 0 );
  11211. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  11212. }
  11213. }
  11214. };
  11215. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  11216. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  11217. return this.morphTargetDictionary[ name ];
  11218. }
  11219. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  11220. return 0;
  11221. };
  11222. THREE.Mesh.prototype.raycast = ( function () {
  11223. var inverseMatrix = new THREE.Matrix4();
  11224. var ray = new THREE.Ray();
  11225. var sphere = new THREE.Sphere();
  11226. var vA = new THREE.Vector3();
  11227. var vB = new THREE.Vector3();
  11228. var vC = new THREE.Vector3();
  11229. var tempA = new THREE.Vector3();
  11230. var tempB = new THREE.Vector3();
  11231. var tempC = new THREE.Vector3();
  11232. var uvA = new THREE.Vector2();
  11233. var uvB = new THREE.Vector2();
  11234. var uvC = new THREE.Vector2();
  11235. var barycoord = new THREE.Vector3();
  11236. var intersectionPoint = new THREE.Vector3();
  11237. var intersectionPointWorld = new THREE.Vector3();
  11238. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  11239. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  11240. uv1.multiplyScalar( barycoord.x );
  11241. uv2.multiplyScalar( barycoord.y );
  11242. uv3.multiplyScalar( barycoord.z );
  11243. uv1.add( uv2 ).add( uv3 );
  11244. return uv1.clone();
  11245. }
  11246. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ){
  11247. var intersect;
  11248. var material = object.material;
  11249. if ( material.side === THREE.BackSide ) {
  11250. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  11251. } else {
  11252. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  11253. }
  11254. if ( intersect === null ) return null;
  11255. intersectionPointWorld.copy( point );
  11256. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  11257. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  11258. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  11259. return {
  11260. distance: distance,
  11261. point: intersectionPointWorld.clone(),
  11262. object: object
  11263. };
  11264. }
  11265. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  11266. vA.fromArray( positions, a * 3 );
  11267. vB.fromArray( positions, b * 3 );
  11268. vC.fromArray( positions, c * 3 );
  11269. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  11270. if ( intersection ) {
  11271. if ( uvs ) {
  11272. uvA.fromArray( uvs, a * 2 );
  11273. uvB.fromArray( uvs, b * 2 );
  11274. uvC.fromArray( uvs, c * 2 );
  11275. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  11276. }
  11277. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  11278. intersection.faceIndex = a;
  11279. }
  11280. return intersection;
  11281. }
  11282. return function raycast( raycaster, intersects ) {
  11283. var geometry = this.geometry;
  11284. var material = this.material;
  11285. if ( material === undefined ) return;
  11286. // Checking boundingSphere distance to ray
  11287. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  11288. var matrixWorld = this.matrixWorld;
  11289. sphere.copy( geometry.boundingSphere );
  11290. sphere.applyMatrix4( matrixWorld );
  11291. if ( raycaster.ray.isIntersectionSphere( sphere ) === false ) return;
  11292. // Check boundingBox before continuing
  11293. inverseMatrix.getInverse( matrixWorld );
  11294. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  11295. if ( geometry.boundingBox !== null ) {
  11296. if ( ray.isIntersectionBox( geometry.boundingBox ) === false ) return;
  11297. }
  11298. var uvs, intersection;
  11299. if ( geometry instanceof THREE.BufferGeometry ) {
  11300. var a, b, c;
  11301. var index = geometry.index;
  11302. var attributes = geometry.attributes;
  11303. var positions = attributes.position.array;
  11304. if ( attributes.uv !== undefined ){
  11305. uvs = attributes.uv.array;
  11306. }
  11307. if ( index !== null ) {
  11308. var indices = index.array;
  11309. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  11310. a = indices[ i ];
  11311. b = indices[ i + 1 ];
  11312. c = indices[ i + 2 ];
  11313. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  11314. if ( intersection ) {
  11315. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  11316. intersects.push( intersection );
  11317. }
  11318. }
  11319. } else {
  11320. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  11321. a = i / 3;
  11322. b = a + 1;
  11323. c = a + 2;
  11324. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  11325. if ( intersection ) {
  11326. intersection.index = a; // triangle number in positions buffer semantics
  11327. intersects.push( intersection );
  11328. }
  11329. }
  11330. }
  11331. } else if ( geometry instanceof THREE.Geometry ) {
  11332. var fvA, fvB, fvC;
  11333. var isFaceMaterial = material instanceof THREE.MeshFaceMaterial;
  11334. var materials = isFaceMaterial === true ? material.materials : null;
  11335. var vertices = geometry.vertices;
  11336. var faces = geometry.faces;
  11337. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  11338. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  11339. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  11340. var face = faces[ f ];
  11341. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  11342. if ( faceMaterial === undefined ) continue;
  11343. fvA = vertices[ face.a ];
  11344. fvB = vertices[ face.b ];
  11345. fvC = vertices[ face.c ];
  11346. if ( faceMaterial.morphTargets === true ) {
  11347. var morphTargets = geometry.morphTargets;
  11348. var morphInfluences = this.morphTargetInfluences;
  11349. vA.set( 0, 0, 0 );
  11350. vB.set( 0, 0, 0 );
  11351. vC.set( 0, 0, 0 );
  11352. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  11353. var influence = morphInfluences[ t ];
  11354. if ( influence === 0 ) continue;
  11355. var targets = morphTargets[ t ].vertices;
  11356. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  11357. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  11358. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  11359. }
  11360. vA.add( fvA );
  11361. vB.add( fvB );
  11362. vC.add( fvC );
  11363. fvA = vA;
  11364. fvB = vB;
  11365. fvC = vC;
  11366. }
  11367. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  11368. if ( intersection ) {
  11369. if ( uvs ) {
  11370. var uvs_f = uvs[ f ];
  11371. uvA.copy( uvs_f[ 0 ] );
  11372. uvB.copy( uvs_f[ 1 ] );
  11373. uvC.copy( uvs_f[ 2 ] );
  11374. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  11375. }
  11376. intersection.face = face;
  11377. intersection.faceIndex = f;
  11378. intersects.push( intersection );
  11379. }
  11380. }
  11381. }
  11382. };
  11383. }() );
  11384. THREE.Mesh.prototype.clone = function () {
  11385. return new this.constructor( this.geometry, this.material ).copy( this );
  11386. };
  11387. // File:src/objects/Bone.js
  11388. /**
  11389. * @author mikael emtinger / http://gomo.se/
  11390. * @author alteredq / http://alteredqualia.com/
  11391. * @author ikerr / http://verold.com
  11392. */
  11393. THREE.Bone = function ( skin ) {
  11394. THREE.Object3D.call( this );
  11395. this.type = 'Bone';
  11396. this.skin = skin;
  11397. };
  11398. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  11399. THREE.Bone.prototype.constructor = THREE.Bone;
  11400. THREE.Bone.prototype.copy = function ( source ) {
  11401. THREE.Object3D.prototype.copy.call( this, source );
  11402. this.skin = source.skin;
  11403. return this;
  11404. };
  11405. // File:src/objects/Skeleton.js
  11406. /**
  11407. * @author mikael emtinger / http://gomo.se/
  11408. * @author alteredq / http://alteredqualia.com/
  11409. * @author michael guerrero / http://realitymeltdown.com
  11410. * @author ikerr / http://verold.com
  11411. */
  11412. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  11413. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  11414. this.identityMatrix = new THREE.Matrix4();
  11415. // copy the bone array
  11416. bones = bones || [];
  11417. this.bones = bones.slice( 0 );
  11418. // create a bone texture or an array of floats
  11419. if ( this.useVertexTexture ) {
  11420. // layout (1 matrix = 4 pixels)
  11421. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  11422. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  11423. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  11424. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  11425. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  11426. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  11427. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  11428. size = Math.max( size, 4 );
  11429. this.boneTextureWidth = size;
  11430. this.boneTextureHeight = size;
  11431. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  11432. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  11433. } else {
  11434. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  11435. }
  11436. // use the supplied bone inverses or calculate the inverses
  11437. if ( boneInverses === undefined ) {
  11438. this.calculateInverses();
  11439. } else {
  11440. if ( this.bones.length === boneInverses.length ) {
  11441. this.boneInverses = boneInverses.slice( 0 );
  11442. } else {
  11443. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  11444. this.boneInverses = [];
  11445. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11446. this.boneInverses.push( new THREE.Matrix4() );
  11447. }
  11448. }
  11449. }
  11450. };
  11451. THREE.Skeleton.prototype.calculateInverses = function () {
  11452. this.boneInverses = [];
  11453. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11454. var inverse = new THREE.Matrix4();
  11455. if ( this.bones[ b ] ) {
  11456. inverse.getInverse( this.bones[ b ].matrixWorld );
  11457. }
  11458. this.boneInverses.push( inverse );
  11459. }
  11460. };
  11461. THREE.Skeleton.prototype.pose = function () {
  11462. var bone;
  11463. // recover the bind-time world matrices
  11464. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11465. bone = this.bones[ b ];
  11466. if ( bone ) {
  11467. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  11468. }
  11469. }
  11470. // compute the local matrices, positions, rotations and scales
  11471. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11472. bone = this.bones[ b ];
  11473. if ( bone ) {
  11474. if ( bone.parent ) {
  11475. bone.matrix.getInverse( bone.parent.matrixWorld );
  11476. bone.matrix.multiply( bone.matrixWorld );
  11477. } else {
  11478. bone.matrix.copy( bone.matrixWorld );
  11479. }
  11480. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  11481. }
  11482. }
  11483. };
  11484. THREE.Skeleton.prototype.update = ( function () {
  11485. var offsetMatrix = new THREE.Matrix4();
  11486. return function update() {
  11487. // flatten bone matrices to array
  11488. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  11489. // compute the offset between the current and the original transform
  11490. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  11491. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  11492. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  11493. }
  11494. if ( this.useVertexTexture ) {
  11495. this.boneTexture.needsUpdate = true;
  11496. }
  11497. };
  11498. } )();
  11499. THREE.Skeleton.prototype.clone = function () {
  11500. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  11501. };
  11502. // File:src/objects/SkinnedMesh.js
  11503. /**
  11504. * @author mikael emtinger / http://gomo.se/
  11505. * @author alteredq / http://alteredqualia.com/
  11506. * @author ikerr / http://verold.com
  11507. */
  11508. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  11509. THREE.Mesh.call( this, geometry, material );
  11510. this.type = 'SkinnedMesh';
  11511. this.bindMode = "attached";
  11512. this.bindMatrix = new THREE.Matrix4();
  11513. this.bindMatrixInverse = new THREE.Matrix4();
  11514. // init bones
  11515. // TODO: remove bone creation as there is no reason (other than
  11516. // convenience) for THREE.SkinnedMesh to do this.
  11517. var bones = [];
  11518. if ( this.geometry && this.geometry.bones !== undefined ) {
  11519. var bone, gbone;
  11520. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11521. gbone = this.geometry.bones[ b ];
  11522. bone = new THREE.Bone( this );
  11523. bones.push( bone );
  11524. bone.name = gbone.name;
  11525. bone.position.fromArray( gbone.pos );
  11526. bone.quaternion.fromArray( gbone.rotq );
  11527. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  11528. }
  11529. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  11530. gbone = this.geometry.bones[ b ];
  11531. if ( gbone.parent !== - 1 ) {
  11532. bones[ gbone.parent ].add( bones[ b ] );
  11533. } else {
  11534. this.add( bones[ b ] );
  11535. }
  11536. }
  11537. }
  11538. this.normalizeSkinWeights();
  11539. this.updateMatrixWorld( true );
  11540. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  11541. };
  11542. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  11543. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  11544. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  11545. this.skeleton = skeleton;
  11546. if ( bindMatrix === undefined ) {
  11547. this.updateMatrixWorld( true );
  11548. this.skeleton.calculateInverses();
  11549. bindMatrix = this.matrixWorld;
  11550. }
  11551. this.bindMatrix.copy( bindMatrix );
  11552. this.bindMatrixInverse.getInverse( bindMatrix );
  11553. };
  11554. THREE.SkinnedMesh.prototype.pose = function () {
  11555. this.skeleton.pose();
  11556. };
  11557. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  11558. if ( this.geometry instanceof THREE.Geometry ) {
  11559. for ( var i = 0; i < this.geometry.skinIndices.length; i ++ ) {
  11560. var sw = this.geometry.skinWeights[ i ];
  11561. var scale = 1.0 / sw.lengthManhattan();
  11562. if ( scale !== Infinity ) {
  11563. sw.multiplyScalar( scale );
  11564. } else {
  11565. sw.set( 1 ); // this will be normalized by the shader anyway
  11566. }
  11567. }
  11568. } else {
  11569. // skinning weights assumed to be normalized for THREE.BufferGeometry
  11570. }
  11571. };
  11572. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  11573. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  11574. if ( this.bindMode === "attached" ) {
  11575. this.bindMatrixInverse.getInverse( this.matrixWorld );
  11576. } else if ( this.bindMode === "detached" ) {
  11577. this.bindMatrixInverse.getInverse( this.bindMatrix );
  11578. } else {
  11579. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  11580. }
  11581. };
  11582. THREE.SkinnedMesh.prototype.clone = function() {
  11583. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  11584. };
  11585. // File:src/objects/LOD.js
  11586. /**
  11587. * @author mikael emtinger / http://gomo.se/
  11588. * @author alteredq / http://alteredqualia.com/
  11589. * @author mrdoob / http://mrdoob.com/
  11590. */
  11591. THREE.LOD = function () {
  11592. THREE.Object3D.call( this );
  11593. this.type = 'LOD';
  11594. Object.defineProperties( this, {
  11595. levels: {
  11596. enumerable: true,
  11597. value: []
  11598. },
  11599. objects: {
  11600. get: function () {
  11601. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  11602. return this.levels;
  11603. }
  11604. }
  11605. } );
  11606. };
  11607. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  11608. THREE.LOD.prototype.constructor = THREE.LOD;
  11609. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  11610. if ( distance === undefined ) distance = 0;
  11611. distance = Math.abs( distance );
  11612. var levels = this.levels;
  11613. for ( var l = 0; l < levels.length; l ++ ) {
  11614. if ( distance < levels[ l ].distance ) {
  11615. break;
  11616. }
  11617. }
  11618. levels.splice( l, 0, { distance: distance, object: object } );
  11619. this.add( object );
  11620. };
  11621. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  11622. var levels = this.levels;
  11623. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11624. if ( distance < levels[ i ].distance ) {
  11625. break;
  11626. }
  11627. }
  11628. return levels[ i - 1 ].object;
  11629. };
  11630. THREE.LOD.prototype.raycast = ( function () {
  11631. var matrixPosition = new THREE.Vector3();
  11632. return function raycast( raycaster, intersects ) {
  11633. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11634. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  11635. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  11636. };
  11637. }() );
  11638. THREE.LOD.prototype.update = function () {
  11639. var v1 = new THREE.Vector3();
  11640. var v2 = new THREE.Vector3();
  11641. return function update( camera ) {
  11642. var levels = this.levels;
  11643. if ( levels.length > 1 ) {
  11644. v1.setFromMatrixPosition( camera.matrixWorld );
  11645. v2.setFromMatrixPosition( this.matrixWorld );
  11646. var distance = v1.distanceTo( v2 );
  11647. levels[ 0 ].object.visible = true;
  11648. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  11649. if ( distance >= levels[ i ].distance ) {
  11650. levels[ i - 1 ].object.visible = false;
  11651. levels[ i ].object.visible = true;
  11652. } else {
  11653. break;
  11654. }
  11655. }
  11656. for ( ; i < l; i ++ ) {
  11657. levels[ i ].object.visible = false;
  11658. }
  11659. }
  11660. };
  11661. }();
  11662. THREE.LOD.prototype.copy = function ( source ) {
  11663. THREE.Object3D.prototype.copy.call( this, source, false );
  11664. var levels = source.levels;
  11665. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11666. var level = levels[ i ];
  11667. this.addLevel( level.object.clone(), level.distance );
  11668. }
  11669. return this;
  11670. };
  11671. THREE.LOD.prototype.toJSON = function ( meta ) {
  11672. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  11673. data.object.levels = [];
  11674. var levels = this.levels;
  11675. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  11676. var level = levels[ i ];
  11677. data.object.levels.push( {
  11678. object: level.object.uuid,
  11679. distance: level.distance
  11680. } );
  11681. }
  11682. return data;
  11683. };
  11684. // File:src/objects/Sprite.js
  11685. /**
  11686. * @author mikael emtinger / http://gomo.se/
  11687. * @author alteredq / http://alteredqualia.com/
  11688. */
  11689. THREE.Sprite = ( function () {
  11690. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  11691. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  11692. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  11693. var geometry = new THREE.BufferGeometry();
  11694. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  11695. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  11696. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  11697. return function Sprite( material ) {
  11698. THREE.Object3D.call( this );
  11699. this.type = 'Sprite';
  11700. this.geometry = geometry;
  11701. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  11702. };
  11703. } )();
  11704. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  11705. THREE.Sprite.prototype.constructor = THREE.Sprite;
  11706. THREE.Sprite.prototype.raycast = ( function () {
  11707. var matrixPosition = new THREE.Vector3();
  11708. return function raycast( raycaster, intersects ) {
  11709. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  11710. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  11711. var guessSizeSq = this.scale.x * this.scale.y;
  11712. if ( distanceSq > guessSizeSq ) {
  11713. return;
  11714. }
  11715. intersects.push( {
  11716. distance: Math.sqrt( distanceSq ),
  11717. point: this.position,
  11718. face: null,
  11719. object: this
  11720. } );
  11721. };
  11722. }() );
  11723. THREE.Sprite.prototype.clone = function () {
  11724. return new this.constructor( this.material ).copy( this );
  11725. };
  11726. // Backwards compatibility
  11727. THREE.Particle = THREE.Sprite;
  11728. // File:src/objects/LensFlare.js
  11729. /**
  11730. * @author mikael emtinger / http://gomo.se/
  11731. * @author alteredq / http://alteredqualia.com/
  11732. */
  11733. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  11734. THREE.Object3D.call( this );
  11735. this.lensFlares = [];
  11736. this.positionScreen = new THREE.Vector3();
  11737. this.customUpdateCallback = undefined;
  11738. if ( texture !== undefined ) {
  11739. this.add( texture, size, distance, blending, color );
  11740. }
  11741. };
  11742. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  11743. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  11744. /*
  11745. * Add: adds another flare
  11746. */
  11747. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  11748. if ( size === undefined ) size = - 1;
  11749. if ( distance === undefined ) distance = 0;
  11750. if ( opacity === undefined ) opacity = 1;
  11751. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  11752. if ( blending === undefined ) blending = THREE.NormalBlending;
  11753. distance = Math.min( distance, Math.max( 0, distance ) );
  11754. this.lensFlares.push( {
  11755. texture: texture, // THREE.Texture
  11756. size: size, // size in pixels (-1 = use texture.width)
  11757. distance: distance, // distance (0-1) from light source (0=at light source)
  11758. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  11759. scale: 1, // scale
  11760. rotation: 0, // rotation
  11761. opacity: opacity, // opacity
  11762. color: color, // color
  11763. blending: blending // blending
  11764. } );
  11765. };
  11766. /*
  11767. * Update lens flares update positions on all flares based on the screen position
  11768. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  11769. */
  11770. THREE.LensFlare.prototype.updateLensFlares = function () {
  11771. var f, fl = this.lensFlares.length;
  11772. var flare;
  11773. var vecX = - this.positionScreen.x * 2;
  11774. var vecY = - this.positionScreen.y * 2;
  11775. for ( f = 0; f < fl; f ++ ) {
  11776. flare = this.lensFlares[ f ];
  11777. flare.x = this.positionScreen.x + vecX * flare.distance;
  11778. flare.y = this.positionScreen.y + vecY * flare.distance;
  11779. flare.wantedRotation = flare.x * Math.PI * 0.25;
  11780. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  11781. }
  11782. };
  11783. THREE.LensFlare.prototype.copy = function ( source ) {
  11784. THREE.Object3D.prototype.copy.call( this, source );
  11785. this.positionScreen.copy( source.positionScreen );
  11786. this.customUpdateCallback = source.customUpdateCallback;
  11787. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  11788. this.lensFlares.push( source.lensFlares[ i ] );
  11789. }
  11790. return this;
  11791. };
  11792. // File:src/scenes/Scene.js
  11793. /**
  11794. * @author mrdoob / http://mrdoob.com/
  11795. */
  11796. THREE.Scene = function () {
  11797. THREE.Object3D.call( this );
  11798. this.type = 'Scene';
  11799. this.fog = null;
  11800. this.overrideMaterial = null;
  11801. this.autoUpdate = true; // checked by the renderer
  11802. };
  11803. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  11804. THREE.Scene.prototype.constructor = THREE.Scene;
  11805. THREE.Scene.prototype.copy = function ( source ) {
  11806. THREE.Object3D.prototype.copy.call( this, source );
  11807. if ( source.fog !== null ) this.fog = source.fog.clone();
  11808. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  11809. this.autoUpdate = source.autoUpdate;
  11810. this.matrixAutoUpdate = source.matrixAutoUpdate;
  11811. return this;
  11812. };
  11813. // File:src/scenes/Fog.js
  11814. /**
  11815. * @author mrdoob / http://mrdoob.com/
  11816. * @author alteredq / http://alteredqualia.com/
  11817. */
  11818. THREE.Fog = function ( color, near, far ) {
  11819. this.name = '';
  11820. this.color = new THREE.Color( color );
  11821. this.near = ( near !== undefined ) ? near : 1;
  11822. this.far = ( far !== undefined ) ? far : 1000;
  11823. };
  11824. THREE.Fog.prototype.clone = function () {
  11825. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  11826. };
  11827. // File:src/scenes/FogExp2.js
  11828. /**
  11829. * @author mrdoob / http://mrdoob.com/
  11830. * @author alteredq / http://alteredqualia.com/
  11831. */
  11832. THREE.FogExp2 = function ( color, density ) {
  11833. this.name = '';
  11834. this.color = new THREE.Color( color );
  11835. this.density = ( density !== undefined ) ? density : 0.00025;
  11836. };
  11837. THREE.FogExp2.prototype.clone = function () {
  11838. return new THREE.FogExp2( this.color.getHex(), this.density );
  11839. };
  11840. // File:src/renderers/shaders/ShaderChunk.js
  11841. THREE.ShaderChunk = {};
  11842. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  11843. THREE.ShaderChunk[ 'alphamap_fragment'] = "#ifdef USE_ALPHAMAP\n\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n\n#endif\n";
  11844. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  11845. THREE.ShaderChunk[ 'alphamap_pars_fragment'] = "#ifdef USE_ALPHAMAP\n\n uniform sampler2D alphaMap;\n\n#endif\n";
  11846. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  11847. THREE.ShaderChunk[ 'alphatest_fragment'] = "#ifdef ALPHATEST\n\n if ( diffuseColor.a < ALPHATEST ) discard;\n\n#endif\n";
  11848. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  11849. THREE.ShaderChunk[ 'aomap_fragment'] = "#ifdef USE_AOMAP\n\n totalAmbientLight *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n\n#endif\n";
  11850. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  11851. THREE.ShaderChunk[ 'aomap_pars_fragment'] = "#ifdef USE_AOMAP\n\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n\n#endif";
  11852. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  11853. THREE.ShaderChunk[ 'begin_vertex'] = "\nvec3 transformed = vec3( position );\n";
  11854. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  11855. THREE.ShaderChunk[ 'beginnormal_vertex'] = "\nvec3 objectNormal = vec3( normal );\n";
  11856. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  11857. THREE.ShaderChunk[ 'bumpmap_pars_fragment'] = "#ifdef USE_BUMPMAP\n\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n\n\n\n vec2 dHdxy_fwd() {\n\n vec2 dSTdx = dFdx( vUv );\n vec2 dSTdy = dFdy( vUv );\n\n float Hll = bumpScale * texture2D( bumpMap, vUv ).x;\n float dBx = bumpScale * texture2D( bumpMap, vUv + dSTdx ).x - Hll;\n float dBy = bumpScale * texture2D( bumpMap, vUv + dSTdy ).x - Hll;\n\n return vec2( dBx, dBy );\n\n }\n\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\n\n vec3 vSigmaX = dFdx( surf_pos );\n vec3 vSigmaY = dFdy( surf_pos );\n vec3 vN = surf_norm;\n vec3 R1 = cross( vSigmaY, vN );\n vec3 R2 = cross( vN, vSigmaX );\n\n float fDet = dot( vSigmaX, R1 );\n\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n\n }\n\n#endif\n";
  11858. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  11859. THREE.ShaderChunk[ 'color_fragment'] = "#ifdef USE_COLOR\n\n diffuseColor.rgb *= vColor;\n\n#endif";
  11860. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  11861. THREE.ShaderChunk[ 'color_pars_fragment'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif\n";
  11862. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  11863. THREE.ShaderChunk[ 'color_pars_vertex'] = "#ifdef USE_COLOR\n\n varying vec3 vColor;\n\n#endif";
  11864. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  11865. THREE.ShaderChunk[ 'color_vertex'] = "#ifdef USE_COLOR\n\n vColor.xyz = color.xyz;\n\n#endif";
  11866. // File:src/renderers/shaders/ShaderChunk/common.glsl
  11867. THREE.ShaderChunk[ 'common'] = "#define PI 3.14159\n#define PI2 6.28318\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\n\nvec3 transformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( matrix * vec4( normal, 0.0 ) ).xyz );\n\n}\n\nvec3 inverseTransformDirection( in vec3 normal, in mat4 matrix ) {\n\n return normalize( ( vec4( normal, 0.0 ) * matrix ).xyz );\n\n}\n\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n float distance = dot( planeNormal, point - pointOnPlane );\n\n return - distance * planeNormal + point;\n\n}\n\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return sign( dot( point - pointOnPlane, planeNormal ) );\n\n}\n\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n\n}\n\nfloat calcLightAttenuation( float lightDistance, float cutoffDistance, float decayExponent ) {\n\n if ( decayExponent > 0.0 ) {\n\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n\n }\n\n return 1.0;\n\n}\n\nvec3 F_Schlick( in vec3 specularColor, in float dotLH ) {\n\n\n float fresnel = exp2( ( -5.55437 * dotLH - 6.98316 ) * dotLH );\n\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n\n}\n\nfloat G_BlinnPhong_Implicit( /* in float dotNL, in float dotNV */ ) {\n\n\n return 0.25;\n\n}\n\nfloat D_BlinnPhong( in float shininess, in float dotNH ) {\n\n\n return ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n\n}\n\nvec3 BRDF_BlinnPhong( in vec3 specularColor, in float shininess, in vec3 normal, in vec3 lightDir, in vec3 viewDir ) {\n\n vec3 halfDir = normalize( lightDir + viewDir );\n\n float dotNH = saturate( dot( normal, halfDir ) );\n float dotLH = saturate( dot( lightDir, halfDir ) );\n\n vec3 F = F_Schlick( specularColor, dotLH );\n\n float G = G_BlinnPhong_Implicit( /* dotNL, dotNV */ );\n\n float D = D_BlinnPhong( shininess, dotNH );\n\n return F * G * D;\n\n}\n\nvec3 inputToLinear( in vec3 a ) {\n\n #ifdef GAMMA_INPUT\n\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n\nvec3 linearToOutput( in vec3 a ) {\n\n #ifdef GAMMA_OUTPUT\n\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n\n #else\n\n return a;\n\n #endif\n\n}\n";
  11868. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  11869. THREE.ShaderChunk[ 'defaultnormal_vertex'] = "#ifdef FLIP_SIDED\n\n objectNormal = -objectNormal;\n\n#endif\n\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  11870. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  11871. THREE.ShaderChunk[ 'displacementmap_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n\n#endif\n";
  11872. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  11873. THREE.ShaderChunk[ 'displacementmap_pars_vertex'] = "#ifdef USE_DISPLACEMENTMAP\n\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n\n#endif\n";
  11874. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  11875. 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";
  11876. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  11877. THREE.ShaderChunk[ 'emissivemap_pars_fragment'] = "#ifdef USE_EMISSIVEMAP\n\n uniform sampler2D emissiveMap;\n\n#endif\n";
  11878. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  11879. THREE.ShaderChunk[ 'envmap_fragment'] = "#ifdef USE_ENVMAP\n\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vec3 reflectVec = reflect( cameraToVertex, worldNormal );\n\n #else\n\n vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n\n #endif\n\n #else\n\n vec3 reflectVec = vReflect;\n\n #endif\n\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\n #elif defined( ENVMAP_TYPE_EQUIREC )\n vec2 sampleUV;\n sampleUV.y = saturate( flipNormal * reflectVec.y * 0.5 + 0.5 );\n sampleUV.x = atan( flipNormal * reflectVec.z, flipNormal * reflectVec.x ) * RECIPROCAL_PI2 + 0.5;\n vec4 envColor = texture2D( envMap, sampleUV );\n\n #elif defined( ENVMAP_TYPE_SPHERE )\n vec3 reflectView = flipNormal * normalize((viewMatrix * vec4( reflectVec, 0.0 )).xyz + vec3(0.0,0.0,1.0));\n vec4 envColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5 );\n #endif\n\n envColor.xyz = inputToLinear( envColor.xyz );\n\n #ifdef ENVMAP_BLENDING_MULTIPLY\n\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_MIX )\n\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\n #elif defined( ENVMAP_BLENDING_ADD )\n\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n\n #endif\n\n#endif\n";
  11880. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  11881. 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";
  11882. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  11883. 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";
  11884. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  11885. THREE.ShaderChunk[ 'envmap_vertex'] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG )\n\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n\n #ifdef ENVMAP_MODE_REFLECTION\n\n vReflect = reflect( cameraToVertex, worldNormal );\n\n #else\n\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n\n #endif\n\n#endif\n";
  11886. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  11887. 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";
  11888. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  11889. 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";
  11890. // File:src/renderers/shaders/ShaderChunk/hemilight_fragment.glsl
  11891. THREE.ShaderChunk[ 'hemilight_fragment'] = "#if MAX_HEMI_LIGHTS > 0\n\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = hemisphereLightDirection[ i ];\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vec3 lightColor = mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n totalAmbientLight += lightColor;\n\n }\n\n#endif\n\n";
  11892. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  11893. THREE.ShaderChunk[ 'lightmap_fragment'] = "#ifdef USE_LIGHTMAP\n\n totalAmbientLight += texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n\n#endif\n";
  11894. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  11895. THREE.ShaderChunk[ 'lightmap_pars_fragment'] = "#ifdef USE_LIGHTMAP\n\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n\n#endif";
  11896. // File:src/renderers/shaders/ShaderChunk/lights_lambert_pars_vertex.glsl
  11897. THREE.ShaderChunk[ 'lights_lambert_pars_vertex'] = "#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n";
  11898. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  11899. THREE.ShaderChunk[ 'lights_lambert_vertex'] = "vLightFront = vec3( 0.0 );\n\n#ifdef DOUBLE_SIDED\n\n vLightBack = vec3( 0.0 );\n\n#endif\n\nvec3 normal = normalize( transformedNormal );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec3 lVector = pointLightPosition[ i ] - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec3 lVector = lightPosition - mvPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], lightDir );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * attenuation * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * attenuation * saturate( - dotProduct );\n\n #endif\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = directionalLightDirection[ i ];\n\n\n float dotProduct = dot( normal, lightDir );\n\n vLightFront += lightColor * saturate( dotProduct );\n\n #ifdef DOUBLE_SIDED\n\n vLightBack += lightColor * saturate( - dotProduct );\n\n #endif\n\n }\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n for ( int i = 0; i < MAX_HEMI_LIGHTS; i ++ ) {\n\n vec3 lightDir = hemisphereLightDirection[ i ];\n\n\n float dotProduct = dot( normal, lightDir );\n\n float hemiDiffuseWeight = 0.5 * dotProduct + 0.5;\n\n vLightFront += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeight );\n\n #ifdef DOUBLE_SIDED\n\n float hemiDiffuseWeightBack = - 0.5 * dotProduct + 0.5;\n\n vLightBack += mix( hemisphereLightGroundColor[ i ], hemisphereLightSkyColor[ i ], hemiDiffuseWeightBack );\n\n #endif\n\n }\n\n#endif\n";
  11900. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  11901. THREE.ShaderChunk[ 'lights_phong_fragment'] = "vec3 viewDir = normalize( vViewPosition );\n\nvec3 totalDiffuseLight = vec3( 0.0 );\nvec3 totalSpecularLight = vec3( 0.0 );\n\n#if MAX_POINT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_POINT_LIGHTS; i ++ ) {\n\n vec3 lightColor = pointLightColor[ i ];\n\n vec3 lightPosition = pointLightPosition[ i ];\n vec3 lVector = lightPosition + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n\n float attenuation = calcLightAttenuation( length( lVector ), pointLightDistance[ i ], pointLightDecay[ i ] );\n\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n\n }\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n for ( int i = 0; i < MAX_SPOT_LIGHTS; i ++ ) {\n\n vec3 lightColor = spotLightColor[ i ];\n\n vec3 lightPosition = spotLightPosition[ i ];\n vec3 lVector = lightPosition + vViewPosition.xyz;\n vec3 lightDir = normalize( lVector );\n\n float spotEffect = dot( spotLightDirection[ i ], lightDir );\n\n if ( spotEffect > spotLightAngleCos[ i ] ) {\n\n spotEffect = saturate( pow( saturate( spotEffect ), spotLightExponent[ i ] ) );\n\n\n float attenuation = calcLightAttenuation( length( lVector ), spotLightDistance[ i ], spotLightDecay[ i ] );\n\n attenuation *= spotEffect;\n\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * attenuation * cosineTerm;\n\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * attenuation * cosineTerm;\n\n }\n\n }\n\n#endif\n\n#if MAX_DIR_LIGHTS > 0\n\n for ( int i = 0; i < MAX_DIR_LIGHTS; i ++ ) {\n\n vec3 lightColor = directionalLightColor[ i ];\n\n vec3 lightDir = directionalLightDirection[ i ];\n\n\n float cosineTerm = saturate( dot( normal, lightDir ) );\n\n totalDiffuseLight += lightColor * cosineTerm;\n\n\n vec3 brdf = BRDF_BlinnPhong( specular, shininess, normal, lightDir, viewDir );\n\n totalSpecularLight += brdf * specularStrength * lightColor * cosineTerm;\n\n }\n\n#endif\n";
  11902. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  11903. THREE.ShaderChunk[ 'lights_phong_pars_fragment'] = "uniform vec3 ambientLightColor;\n\n#if MAX_DIR_LIGHTS > 0\n\n uniform vec3 directionalLightColor[ MAX_DIR_LIGHTS ];\n uniform vec3 directionalLightDirection[ MAX_DIR_LIGHTS ];\n\n#endif\n\n#if MAX_HEMI_LIGHTS > 0\n\n uniform vec3 hemisphereLightSkyColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightGroundColor[ MAX_HEMI_LIGHTS ];\n uniform vec3 hemisphereLightDirection[ MAX_HEMI_LIGHTS ];\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightColor[ MAX_POINT_LIGHTS ];\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n uniform float pointLightDistance[ MAX_POINT_LIGHTS ];\n uniform float pointLightDecay[ MAX_POINT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0\n\n uniform vec3 spotLightColor[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightPosition[ MAX_SPOT_LIGHTS ];\n uniform vec3 spotLightDirection[ MAX_SPOT_LIGHTS ];\n uniform float spotLightAngleCos[ MAX_SPOT_LIGHTS ];\n uniform float spotLightExponent[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDistance[ MAX_SPOT_LIGHTS ];\n uniform float spotLightDecay[ MAX_SPOT_LIGHTS ];\n\n#endif\n\n#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\nvarying vec3 vViewPosition;\n\n#ifndef FLAT_SHADED\n\n varying vec3 vNormal;\n\n#endif\n";
  11904. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  11905. THREE.ShaderChunk[ 'lights_phong_pars_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n varying vec3 vWorldPosition;\n\n#endif\n\n#if MAX_POINT_LIGHTS > 0\n\n uniform vec3 pointLightPosition[ MAX_POINT_LIGHTS ];\n\n#endif\n";
  11906. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  11907. THREE.ShaderChunk[ 'lights_phong_vertex'] = "#if MAX_SPOT_LIGHTS > 0 || defined( USE_ENVMAP )\n\n vWorldPosition = worldPosition.xyz;\n\n#endif\n";
  11908. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  11909. THREE.ShaderChunk[ 'linear_to_gamma_fragment'] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  11910. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  11911. THREE.ShaderChunk[ 'logdepthbuf_fragment'] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n\n#endif";
  11912. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  11913. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment'] = "#ifdef USE_LOGDEPTHBUF\n\n uniform float logDepthBufFC;\n\n #ifdef USE_LOGDEPTHBUF_EXT\n\n varying float vFragDepth;\n\n #endif\n\n#endif\n";
  11914. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  11915. 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";
  11916. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  11917. 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";
  11918. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  11919. 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";
  11920. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  11921. THREE.ShaderChunk[ 'map_pars_fragment'] = "#ifdef USE_MAP\n\n uniform sampler2D map;\n\n#endif";
  11922. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  11923. 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";
  11924. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  11925. THREE.ShaderChunk[ 'map_particle_pars_fragment'] = "#ifdef USE_MAP\n\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n\n#endif\n";
  11926. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  11927. THREE.ShaderChunk[ 'morphnormal_vertex'] = "#ifdef USE_MORPHNORMALS\n\n objectNormal += ( morphNormal0 - normal ) * morphTargetInfluences[ 0 ];\n objectNormal += ( morphNormal1 - normal ) * morphTargetInfluences[ 1 ];\n objectNormal += ( morphNormal2 - normal ) * morphTargetInfluences[ 2 ];\n objectNormal += ( morphNormal3 - normal ) * morphTargetInfluences[ 3 ];\n\n#endif\n";
  11928. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  11929. 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";
  11930. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  11931. THREE.ShaderChunk[ 'morphtarget_vertex'] = "#ifdef USE_MORPHTARGETS\n\n transformed += ( morphTarget0 - position ) * morphTargetInfluences[ 0 ];\n transformed += ( morphTarget1 - position ) * morphTargetInfluences[ 1 ];\n transformed += ( morphTarget2 - position ) * morphTargetInfluences[ 2 ];\n transformed += ( morphTarget3 - position ) * morphTargetInfluences[ 3 ];\n\n #ifndef USE_MORPHNORMALS\n\n transformed += ( morphTarget4 - position ) * morphTargetInfluences[ 4 ];\n transformed += ( morphTarget5 - position ) * morphTargetInfluences[ 5 ];\n transformed += ( morphTarget6 - position ) * morphTargetInfluences[ 6 ];\n transformed += ( morphTarget7 - position ) * morphTargetInfluences[ 7 ];\n\n #endif\n\n#endif\n";
  11932. // File:src/renderers/shaders/ShaderChunk/normal_phong_fragment.glsl
  11933. THREE.ShaderChunk[ 'normal_phong_fragment'] = "#ifndef FLAT_SHADED\n\n vec3 normal = normalize( vNormal );\n\n #ifdef DOUBLE_SIDED\n\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n\n #endif\n\n#else\n\n vec3 fdx = dFdx( vViewPosition );\n vec3 fdy = dFdy( vViewPosition );\n vec3 normal = normalize( cross( fdx, fdy ) );\n\n#endif\n\n#ifdef USE_NORMALMAP\n\n normal = perturbNormal2Arb( -vViewPosition, normal );\n\n#elif defined( USE_BUMPMAP )\n\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n\n#endif\n\n";
  11934. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  11935. THREE.ShaderChunk[ 'normalmap_pars_fragment'] = "#ifdef USE_NORMALMAP\n\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n\n\n vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\n\n vec3 q0 = dFdx( eye_pos.xyz );\n vec3 q1 = dFdy( eye_pos.xyz );\n vec2 st0 = dFdx( vUv.st );\n vec2 st1 = dFdy( vUv.st );\n\n vec3 S = normalize( q0 * st1.t - q1 * st0.t );\n vec3 T = normalize( -q0 * st1.s + q1 * st0.s );\n vec3 N = normalize( surf_norm );\n\n vec3 mapN = texture2D( normalMap, vUv ).xyz * 2.0 - 1.0;\n mapN.xy = normalScale * mapN.xy;\n mat3 tsn = mat3( S, T, N );\n return normalize( tsn * mapN );\n\n }\n\n#endif\n";
  11936. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  11937. THREE.ShaderChunk[ 'project_vertex'] = "#ifdef USE_SKINNING\n\n vec4 mvPosition = modelViewMatrix * skinned;\n\n#else\n\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n\n#endif\n\ngl_Position = projectionMatrix * mvPosition;\n";
  11938. // File:src/renderers/shaders/ShaderChunk/shadowmap_fragment.glsl
  11939. THREE.ShaderChunk[ 'shadowmap_fragment'] = "#ifdef USE_SHADOWMAP\n\n for ( int i = 0; i < MAX_SHADOWS; i ++ ) {\n\n float texelSizeY = 1.0 / shadowMapSize[ i ].y;\n\n float shadow = 0.0;\n\n#if defined( POINT_LIGHT_SHADOWS )\n\n bool isPointLight = shadowDarkness[ i ] < 0.0;\n\n if ( isPointLight ) {\n\n float realShadowDarkness = abs( shadowDarkness[ i ] );\n\n vec3 lightToPosition = vShadowCoord[ i ].xyz;\n\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n\n\n #if defined( SHADOWMAP_TYPE_PCF )\n const float Dr = 1.25;\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n const float Dr = 2.25;\n #endif\n\n float os = Dr * 2.0 * texelSizeY;\n\n const vec3 Gsd = vec3( - 1, 0, 1 );\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xxy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xzy * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.zyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.xyx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxz * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yxx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D + Gsd.yzx * os, texelSizeY ) ), shadowBias[ i ], shadow );\n\n shadow *= realShadowDarkness * ( 1.0 / 21.0 );\n\n #else \n vec3 bd3D = normalize( lightToPosition );\n float dp = length( lightToPosition );\n\n adjustShadowValue1K( dp, texture2D( shadowMap[ i ], cubeToUV( bd3D, texelSizeY ) ), shadowBias[ i ], shadow );\n\n shadow *= realShadowDarkness;\n\n #endif\n\n } else {\n\n#endif \n float texelSizeX = 1.0 / shadowMapSize[ i ].x;\n\n vec3 shadowCoord = vShadowCoord[ i ].xyz / vShadowCoord[ i ].w;\n\n\n bvec4 inFrustumVec = bvec4 ( shadowCoord.x >= 0.0, shadowCoord.x <= 1.0, shadowCoord.y >= 0.0, shadowCoord.y <= 1.0 );\n bool inFrustum = all( inFrustumVec );\n\n bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n\n bool frustumTest = all( frustumTestVec );\n\n if ( frustumTest ) {\n\n #if defined( SHADOWMAP_TYPE_PCF )\n\n\n /*\n for ( float y = -1.25; y <= 1.25; y += 1.25 )\n for ( float x = -1.25; x <= 1.25; x += 1.25 ) {\n vec4 rgbaDepth = texture2D( shadowMap[ i ], vec2( x * xPixelOffset, y * yPixelOffset ) + shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n if ( fDepth < shadowCoord.z )\n shadow += 1.0;\n }\n shadow /= 9.0;\n */\n\n shadowCoord.z += shadowBias[ i ];\n\n const float ShadowDelta = 1.0 / 9.0;\n\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n\n float dx0 = - 1.25 * xPixelOffset;\n float dy0 = - 1.25 * yPixelOffset;\n float dx1 = 1.25 * xPixelOffset;\n float dy1 = 1.25 * yPixelOffset;\n\n float fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n\n fDepth = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n if ( fDepth < shadowCoord.z ) shadow += ShadowDelta;\n\n shadow *= shadowDarkness[ i ];\n\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n\n\n shadowCoord.z += shadowBias[ i ];\n\n float xPixelOffset = texelSizeX;\n float yPixelOffset = texelSizeY;\n\n float dx0 = - 1.0 * xPixelOffset;\n float dy0 = - 1.0 * yPixelOffset;\n float dx1 = 1.0 * xPixelOffset;\n float dy1 = 1.0 * yPixelOffset;\n\n mat3 shadowKernel;\n mat3 depthKernel;\n\n depthKernel[ 0 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy0 ) ) );\n depthKernel[ 0 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, 0.0 ) ) );\n depthKernel[ 0 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx0, dy1 ) ) );\n depthKernel[ 1 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy0 ) ) );\n depthKernel[ 1 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy ) );\n depthKernel[ 1 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( 0.0, dy1 ) ) );\n depthKernel[ 2 ][ 0 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy0 ) ) );\n depthKernel[ 2 ][ 1 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, 0.0 ) ) );\n depthKernel[ 2 ][ 2 ] = unpackDepth( texture2D( shadowMap[ i ], shadowCoord.xy + vec2( dx1, dy1 ) ) );\n\n vec3 shadowZ = vec3( shadowCoord.z );\n shadowKernel[ 0 ] = vec3( lessThan( depthKernel[ 0 ], shadowZ ) );\n shadowKernel[ 0 ] *= vec3( 0.25 );\n\n shadowKernel[ 1 ] = vec3( lessThan( depthKernel[ 1 ], shadowZ ) );\n shadowKernel[ 1 ] *= vec3( 0.25 );\n\n shadowKernel[ 2 ] = vec3( lessThan( depthKernel[ 2 ], shadowZ ) );\n shadowKernel[ 2 ] *= vec3( 0.25 );\n\n vec2 fractionalCoord = 1.0 - fract( shadowCoord.xy * shadowMapSize[ i ].xy );\n\n shadowKernel[ 0 ] = mix( shadowKernel[ 1 ], shadowKernel[ 0 ], fractionalCoord.x );\n shadowKernel[ 1 ] = mix( shadowKernel[ 2 ], shadowKernel[ 1 ], fractionalCoord.x );\n\n vec4 shadowValues;\n shadowValues.x = mix( shadowKernel[ 0 ][ 1 ], shadowKernel[ 0 ][ 0 ], fractionalCoord.y );\n shadowValues.y = mix( shadowKernel[ 0 ][ 2 ], shadowKernel[ 0 ][ 1 ], fractionalCoord.y );\n shadowValues.z = mix( shadowKernel[ 1 ][ 1 ], shadowKernel[ 1 ][ 0 ], fractionalCoord.y );\n shadowValues.w = mix( shadowKernel[ 1 ][ 2 ], shadowKernel[ 1 ][ 1 ], fractionalCoord.y );\n\n shadow = dot( shadowValues, vec4( 1.0 ) ) * shadowDarkness[ i ];\n\n #else \n shadowCoord.z += shadowBias[ i ];\n\n vec4 rgbaDepth = texture2D( shadowMap[ i ], shadowCoord.xy );\n float fDepth = unpackDepth( rgbaDepth );\n\n if ( fDepth < shadowCoord.z )\n shadow = shadowDarkness[ i ];\n\n #endif\n\n }\n\n#ifdef SHADOWMAP_DEBUG\n\n if ( inFrustum ) {\n\n if ( i == 0 ) {\n\n outgoingLight *= vec3( 1.0, 0.5, 0.0 );\n\n } else if ( i == 1 ) {\n\n outgoingLight *= vec3( 0.0, 1.0, 0.8 );\n\n } else {\n\n outgoingLight *= vec3( 0.0, 0.5, 1.0 );\n\n }\n\n }\n\n#endif\n\n#if defined( POINT_LIGHT_SHADOWS )\n\n }\n\n#endif\n\n shadowMask = shadowMask * vec3( 1.0 - shadow );\n\n }\n\n#endif\n";
  11940. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  11941. THREE.ShaderChunk[ 'shadowmap_pars_fragment'] = "#ifdef USE_SHADOWMAP\n\n uniform sampler2D shadowMap[ MAX_SHADOWS ];\n uniform vec2 shadowMapSize[ MAX_SHADOWS ];\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform float shadowBias[ MAX_SHADOWS ];\n\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n float unpackDepth( const in vec4 rgba_depth ) {\n\n const vec4 bit_shift = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n float depth = dot( rgba_depth, bit_shift );\n return depth;\n\n }\n\n #if defined(POINT_LIGHT_SHADOWS)\n\n\n void adjustShadowValue1K( const float testDepth, const vec4 textureData, const float bias, inout float shadowValue ) {\n\n const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );\n if ( testDepth >= dot( textureData, bitSh ) * 1000.0 + bias )\n shadowValue += 1.0;\n\n }\n\n\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n\n\n vec3 absV = abs( v );\n\n\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n\n\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n\n\n\n vec2 planar = v.xy;\n\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n\n if ( absV.z >= almostOne ) {\n\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n\n } else if ( absV.x >= almostOne ) {\n\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n\n } else if ( absV.y >= almostOne ) {\n\n float signY = sign( v.y );\n planar.x = v.x + 2.0 * signY + 2.0;\n planar.y = v.z * signY - 2.0;\n\n }\n\n\n return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n\n }\n\n #endif\n\n#endif\n";
  11942. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  11943. THREE.ShaderChunk[ 'shadowmap_pars_vertex'] = "#ifdef USE_SHADOWMAP\n\n uniform float shadowDarkness[ MAX_SHADOWS ];\n uniform mat4 shadowMatrix[ MAX_SHADOWS ];\n varying vec4 vShadowCoord[ MAX_SHADOWS ];\n\n#endif";
  11944. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  11945. 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";
  11946. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  11947. 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";
  11948. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  11949. 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";
  11950. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  11951. THREE.ShaderChunk[ 'skinning_vertex'] = "#ifdef USE_SKINNING\n\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\n\n vec4 skinned = vec4( 0.0 );\n skinned += boneMatX * skinVertex * skinWeight.x;\n skinned += boneMatY * skinVertex * skinWeight.y;\n skinned += boneMatZ * skinVertex * skinWeight.z;\n skinned += boneMatW * skinVertex * skinWeight.w;\n skinned = bindMatrixInverse * skinned;\n\n#endif\n";
  11952. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  11953. THREE.ShaderChunk[ 'skinnormal_vertex'] = "#ifdef USE_SKINNING\n\n mat4 skinMatrix = mat4( 0.0 );\n skinMatrix += skinWeight.x * boneMatX;\n skinMatrix += skinWeight.y * boneMatY;\n skinMatrix += skinWeight.z * boneMatZ;\n skinMatrix += skinWeight.w * boneMatW;\n skinMatrix = bindMatrixInverse * skinMatrix * bindMatrix;\n\n objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n\n#endif\n";
  11954. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  11955. 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";
  11956. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  11957. THREE.ShaderChunk[ 'specularmap_pars_fragment'] = "#ifdef USE_SPECULARMAP\n\n uniform sampler2D specularMap;\n\n#endif";
  11958. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  11959. THREE.ShaderChunk[ 'uv2_pars_fragment'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n varying vec2 vUv2;\n\n#endif";
  11960. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  11961. THREE.ShaderChunk[ 'uv2_pars_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n attribute vec2 uv2;\n varying vec2 vUv2;\n\n#endif";
  11962. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  11963. THREE.ShaderChunk[ 'uv2_vertex'] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n\n vUv2 = uv2;\n\n#endif";
  11964. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  11965. 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";
  11966. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  11967. 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";
  11968. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  11969. 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";
  11970. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  11971. THREE.ShaderChunk[ 'worldpos_vertex'] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n\n #ifdef USE_SKINNING\n\n vec4 worldPosition = modelMatrix * skinned;\n\n #else\n\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n\n #endif\n\n#endif\n";
  11972. // File:src/renderers/shaders/UniformsUtils.js
  11973. /**
  11974. * Uniform Utilities
  11975. */
  11976. THREE.UniformsUtils = {
  11977. merge: function ( uniforms ) {
  11978. var merged = {};
  11979. for ( var u = 0; u < uniforms.length; u ++ ) {
  11980. var tmp = this.clone( uniforms[ u ] );
  11981. for ( var p in tmp ) {
  11982. merged[ p ] = tmp[ p ];
  11983. }
  11984. }
  11985. return merged;
  11986. },
  11987. clone: function ( uniforms_src ) {
  11988. var uniforms_dst = {};
  11989. for ( var u in uniforms_src ) {
  11990. uniforms_dst[ u ] = {};
  11991. for ( var p in uniforms_src[ u ] ) {
  11992. var parameter_src = uniforms_src[ u ][ p ];
  11993. if ( parameter_src instanceof THREE.Color ||
  11994. parameter_src instanceof THREE.Vector2 ||
  11995. parameter_src instanceof THREE.Vector3 ||
  11996. parameter_src instanceof THREE.Vector4 ||
  11997. parameter_src instanceof THREE.Matrix3 ||
  11998. parameter_src instanceof THREE.Matrix4 ||
  11999. parameter_src instanceof THREE.Texture ) {
  12000. uniforms_dst[ u ][ p ] = parameter_src.clone();
  12001. } else if ( Array.isArray( parameter_src ) ) {
  12002. uniforms_dst[ u ][ p ] = parameter_src.slice();
  12003. } else {
  12004. uniforms_dst[ u ][ p ] = parameter_src;
  12005. }
  12006. }
  12007. }
  12008. return uniforms_dst;
  12009. }
  12010. };
  12011. // File:src/renderers/shaders/UniformsLib.js
  12012. /**
  12013. * Uniforms library for shared webgl shaders
  12014. */
  12015. THREE.UniformsLib = {
  12016. common: {
  12017. "diffuse" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  12018. "opacity" : { type: "f", value: 1.0 },
  12019. "map" : { type: "t", value: null },
  12020. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  12021. "specularMap" : { type: "t", value: null },
  12022. "alphaMap" : { type: "t", value: null },
  12023. "envMap" : { type: "t", value: null },
  12024. "flipEnvMap" : { type: "f", value: - 1 },
  12025. "reflectivity" : { type: "f", value: 1.0 },
  12026. "refractionRatio" : { type: "f", value: 0.98 }
  12027. },
  12028. aomap: {
  12029. "aoMap" : { type: "t", value: null },
  12030. "aoMapIntensity" : { type: "f", value: 1 },
  12031. },
  12032. lightmap: {
  12033. "lightMap" : { type: "t", value: null },
  12034. "lightMapIntensity" : { type: "f", value: 1 },
  12035. },
  12036. emissivemap: {
  12037. "emissiveMap" : { type: "t", value: null },
  12038. },
  12039. bumpmap: {
  12040. "bumpMap" : { type: "t", value: null },
  12041. "bumpScale" : { type: "f", value: 1 }
  12042. },
  12043. normalmap: {
  12044. "normalMap" : { type: "t", value: null },
  12045. "normalScale" : { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  12046. },
  12047. displacementmap: {
  12048. "displacementMap" : { type: "t", value: null },
  12049. "displacementScale" : { type: "f", value: 1 },
  12050. "displacementBias" : { type: "f", value: 0 }
  12051. },
  12052. fog : {
  12053. "fogDensity" : { type: "f", value: 0.00025 },
  12054. "fogNear" : { type: "f", value: 1 },
  12055. "fogFar" : { type: "f", value: 2000 },
  12056. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  12057. },
  12058. lights: {
  12059. "ambientLightColor" : { type: "fv", value: [] },
  12060. "directionalLightDirection" : { type: "fv", value: [] },
  12061. "directionalLightColor" : { type: "fv", value: [] },
  12062. "hemisphereLightDirection" : { type: "fv", value: [] },
  12063. "hemisphereLightSkyColor" : { type: "fv", value: [] },
  12064. "hemisphereLightGroundColor" : { type: "fv", value: [] },
  12065. "pointLightColor" : { type: "fv", value: [] },
  12066. "pointLightPosition" : { type: "fv", value: [] },
  12067. "pointLightDistance" : { type: "fv1", value: [] },
  12068. "pointLightDecay" : { type: "fv1", value: [] },
  12069. "spotLightColor" : { type: "fv", value: [] },
  12070. "spotLightPosition" : { type: "fv", value: [] },
  12071. "spotLightDirection" : { type: "fv", value: [] },
  12072. "spotLightDistance" : { type: "fv1", value: [] },
  12073. "spotLightAngleCos" : { type: "fv1", value: [] },
  12074. "spotLightExponent" : { type: "fv1", value: [] },
  12075. "spotLightDecay" : { type: "fv1", value: [] }
  12076. },
  12077. points: {
  12078. "psColor" : { type: "c", value: new THREE.Color( 0xeeeeee ) },
  12079. "opacity" : { type: "f", value: 1.0 },
  12080. "size" : { type: "f", value: 1.0 },
  12081. "scale" : { type: "f", value: 1.0 },
  12082. "map" : { type: "t", value: null },
  12083. "offsetRepeat" : { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  12084. "fogDensity" : { type: "f", value: 0.00025 },
  12085. "fogNear" : { type: "f", value: 1 },
  12086. "fogFar" : { type: "f", value: 2000 },
  12087. "fogColor" : { type: "c", value: new THREE.Color( 0xffffff ) }
  12088. },
  12089. shadowmap: {
  12090. "shadowMap": { type: "tv", value: [] },
  12091. "shadowMapSize": { type: "v2v", value: [] },
  12092. "shadowBias" : { type: "fv1", value: [] },
  12093. "shadowDarkness": { type: "fv1", value: [] },
  12094. "shadowMatrix" : { type: "m4v", value: [] }
  12095. }
  12096. };
  12097. // File:src/renderers/shaders/ShaderLib.js
  12098. /**
  12099. * Webgl Shader Library for three.js
  12100. *
  12101. * @author alteredq / http://alteredqualia.com/
  12102. * @author mrdoob / http://mrdoob.com/
  12103. * @author mikael emtinger / http://gomo.se/
  12104. */
  12105. THREE.ShaderLib = {
  12106. 'basic': {
  12107. uniforms: THREE.UniformsUtils.merge( [
  12108. THREE.UniformsLib[ "common" ],
  12109. THREE.UniformsLib[ "aomap" ],
  12110. THREE.UniformsLib[ "fog" ],
  12111. THREE.UniformsLib[ "shadowmap" ]
  12112. ] ),
  12113. vertexShader: [
  12114. THREE.ShaderChunk[ "common" ],
  12115. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12116. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12117. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12118. THREE.ShaderChunk[ "color_pars_vertex" ],
  12119. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12120. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12121. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12122. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12123. "void main() {",
  12124. THREE.ShaderChunk[ "uv_vertex" ],
  12125. THREE.ShaderChunk[ "uv2_vertex" ],
  12126. THREE.ShaderChunk[ "color_vertex" ],
  12127. THREE.ShaderChunk[ "skinbase_vertex" ],
  12128. " #ifdef USE_ENVMAP",
  12129. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12130. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12131. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12132. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12133. " #endif",
  12134. THREE.ShaderChunk[ "begin_vertex" ],
  12135. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12136. THREE.ShaderChunk[ "skinning_vertex" ],
  12137. THREE.ShaderChunk[ "project_vertex" ],
  12138. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12139. THREE.ShaderChunk[ "worldpos_vertex" ],
  12140. THREE.ShaderChunk[ "envmap_vertex" ],
  12141. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12142. "}"
  12143. ].join( "\n" ),
  12144. fragmentShader: [
  12145. "uniform vec3 diffuse;",
  12146. "uniform float opacity;",
  12147. THREE.ShaderChunk[ "common" ],
  12148. THREE.ShaderChunk[ "color_pars_fragment" ],
  12149. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12150. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12151. THREE.ShaderChunk[ "map_pars_fragment" ],
  12152. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12153. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12154. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12155. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12156. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12157. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12158. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12159. "void main() {",
  12160. " vec3 outgoingLight = vec3( 0.0 );",
  12161. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12162. " vec3 shadowMask = vec3( 1.0 );",
  12163. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12164. THREE.ShaderChunk[ "map_fragment" ],
  12165. THREE.ShaderChunk[ "color_fragment" ],
  12166. THREE.ShaderChunk[ "alphamap_fragment" ],
  12167. THREE.ShaderChunk[ "alphatest_fragment" ],
  12168. THREE.ShaderChunk[ "specularmap_fragment" ],
  12169. THREE.ShaderChunk[ "aomap_fragment" ],
  12170. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12171. " outgoingLight = diffuseColor.rgb * shadowMask;",
  12172. THREE.ShaderChunk[ "envmap_fragment" ],
  12173. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12174. THREE.ShaderChunk[ "fog_fragment" ],
  12175. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12176. "}"
  12177. ].join( "\n" )
  12178. },
  12179. 'lambert': {
  12180. uniforms: THREE.UniformsUtils.merge( [
  12181. THREE.UniformsLib[ "common" ],
  12182. THREE.UniformsLib[ "fog" ],
  12183. THREE.UniformsLib[ "lights" ],
  12184. THREE.UniformsLib[ "shadowmap" ],
  12185. {
  12186. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  12187. }
  12188. ] ),
  12189. vertexShader: [
  12190. "#define LAMBERT",
  12191. "varying vec3 vLightFront;",
  12192. "#ifdef DOUBLE_SIDED",
  12193. " varying vec3 vLightBack;",
  12194. "#endif",
  12195. THREE.ShaderChunk[ "common" ],
  12196. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12197. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12198. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12199. THREE.ShaderChunk[ "lights_lambert_pars_vertex" ],
  12200. THREE.ShaderChunk[ "color_pars_vertex" ],
  12201. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12202. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12203. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12204. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12205. "void main() {",
  12206. THREE.ShaderChunk[ "uv_vertex" ],
  12207. THREE.ShaderChunk[ "uv2_vertex" ],
  12208. THREE.ShaderChunk[ "color_vertex" ],
  12209. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12210. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12211. THREE.ShaderChunk[ "skinbase_vertex" ],
  12212. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12213. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12214. THREE.ShaderChunk[ "begin_vertex" ],
  12215. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12216. THREE.ShaderChunk[ "skinning_vertex" ],
  12217. THREE.ShaderChunk[ "project_vertex" ],
  12218. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12219. THREE.ShaderChunk[ "worldpos_vertex" ],
  12220. THREE.ShaderChunk[ "envmap_vertex" ],
  12221. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  12222. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12223. "}"
  12224. ].join( "\n" ),
  12225. fragmentShader: [
  12226. "uniform vec3 diffuse;",
  12227. "uniform vec3 emissive;",
  12228. "uniform float opacity;",
  12229. "uniform vec3 ambientLightColor;",
  12230. "varying vec3 vLightFront;",
  12231. "#ifdef DOUBLE_SIDED",
  12232. " varying vec3 vLightBack;",
  12233. "#endif",
  12234. THREE.ShaderChunk[ "common" ],
  12235. THREE.ShaderChunk[ "color_pars_fragment" ],
  12236. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12237. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12238. THREE.ShaderChunk[ "map_pars_fragment" ],
  12239. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12240. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12241. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12242. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12243. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12244. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12245. "void main() {",
  12246. " vec3 outgoingLight = vec3( 0.0 );", // outgoing light does not have an alpha, the surface does
  12247. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12248. " vec3 totalAmbientLight = ambientLightColor;",
  12249. " vec3 shadowMask = vec3( 1.0 );",
  12250. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12251. THREE.ShaderChunk[ "map_fragment" ],
  12252. THREE.ShaderChunk[ "color_fragment" ],
  12253. THREE.ShaderChunk[ "alphamap_fragment" ],
  12254. THREE.ShaderChunk[ "alphatest_fragment" ],
  12255. THREE.ShaderChunk[ "specularmap_fragment" ],
  12256. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12257. " #ifdef DOUBLE_SIDED",
  12258. " if ( gl_FrontFacing )",
  12259. " outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask + totalAmbientLight ) + emissive;",
  12260. " else",
  12261. " outgoingLight += diffuseColor.rgb * ( vLightBack * shadowMask + totalAmbientLight ) + emissive;",
  12262. " #else",
  12263. " outgoingLight += diffuseColor.rgb * ( vLightFront * shadowMask + totalAmbientLight ) + emissive;",
  12264. " #endif",
  12265. THREE.ShaderChunk[ "envmap_fragment" ],
  12266. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12267. THREE.ShaderChunk[ "fog_fragment" ],
  12268. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12269. "}"
  12270. ].join( "\n" )
  12271. },
  12272. 'phong': {
  12273. uniforms: THREE.UniformsUtils.merge( [
  12274. THREE.UniformsLib[ "common" ],
  12275. THREE.UniformsLib[ "aomap" ],
  12276. THREE.UniformsLib[ "lightmap" ],
  12277. THREE.UniformsLib[ "emissivemap" ],
  12278. THREE.UniformsLib[ "bumpmap" ],
  12279. THREE.UniformsLib[ "normalmap" ],
  12280. THREE.UniformsLib[ "displacementmap" ],
  12281. THREE.UniformsLib[ "fog" ],
  12282. THREE.UniformsLib[ "lights" ],
  12283. THREE.UniformsLib[ "shadowmap" ],
  12284. {
  12285. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  12286. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  12287. "shininess": { type: "f", value: 30 }
  12288. }
  12289. ] ),
  12290. vertexShader: [
  12291. "#define PHONG",
  12292. "varying vec3 vViewPosition;",
  12293. "#ifndef FLAT_SHADED",
  12294. " varying vec3 vNormal;",
  12295. "#endif",
  12296. THREE.ShaderChunk[ "common" ],
  12297. THREE.ShaderChunk[ "uv_pars_vertex" ],
  12298. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  12299. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  12300. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  12301. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  12302. THREE.ShaderChunk[ "color_pars_vertex" ],
  12303. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12304. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12305. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12306. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12307. "void main() {",
  12308. THREE.ShaderChunk[ "uv_vertex" ],
  12309. THREE.ShaderChunk[ "uv2_vertex" ],
  12310. THREE.ShaderChunk[ "color_vertex" ],
  12311. THREE.ShaderChunk[ "beginnormal_vertex" ],
  12312. THREE.ShaderChunk[ "morphnormal_vertex" ],
  12313. THREE.ShaderChunk[ "skinbase_vertex" ],
  12314. THREE.ShaderChunk[ "skinnormal_vertex" ],
  12315. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  12316. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  12317. " vNormal = normalize( transformedNormal );",
  12318. "#endif",
  12319. THREE.ShaderChunk[ "begin_vertex" ],
  12320. THREE.ShaderChunk[ "displacementmap_vertex" ],
  12321. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12322. THREE.ShaderChunk[ "skinning_vertex" ],
  12323. THREE.ShaderChunk[ "project_vertex" ],
  12324. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12325. " vViewPosition = - mvPosition.xyz;",
  12326. THREE.ShaderChunk[ "worldpos_vertex" ],
  12327. THREE.ShaderChunk[ "envmap_vertex" ],
  12328. THREE.ShaderChunk[ "lights_phong_vertex" ],
  12329. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12330. "}"
  12331. ].join( "\n" ),
  12332. fragmentShader: [
  12333. "#define PHONG",
  12334. "uniform vec3 diffuse;",
  12335. "uniform vec3 emissive;",
  12336. "uniform vec3 specular;",
  12337. "uniform float shininess;",
  12338. "uniform float opacity;",
  12339. THREE.ShaderChunk[ "common" ],
  12340. THREE.ShaderChunk[ "color_pars_fragment" ],
  12341. THREE.ShaderChunk[ "uv_pars_fragment" ],
  12342. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  12343. THREE.ShaderChunk[ "map_pars_fragment" ],
  12344. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  12345. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  12346. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  12347. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  12348. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  12349. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12350. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  12351. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12352. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  12353. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  12354. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  12355. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12356. "void main() {",
  12357. " vec3 outgoingLight = vec3( 0.0 );",
  12358. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12359. " vec3 totalAmbientLight = ambientLightColor;",
  12360. " vec3 totalEmissiveLight = emissive;",
  12361. " vec3 shadowMask = vec3( 1.0 );",
  12362. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12363. THREE.ShaderChunk[ "map_fragment" ],
  12364. THREE.ShaderChunk[ "color_fragment" ],
  12365. THREE.ShaderChunk[ "alphamap_fragment" ],
  12366. THREE.ShaderChunk[ "alphatest_fragment" ],
  12367. THREE.ShaderChunk[ "specularmap_fragment" ],
  12368. THREE.ShaderChunk[ "normal_phong_fragment" ],
  12369. THREE.ShaderChunk[ "lightmap_fragment" ],
  12370. THREE.ShaderChunk[ "hemilight_fragment" ],
  12371. THREE.ShaderChunk[ "aomap_fragment" ],
  12372. THREE.ShaderChunk[ "emissivemap_fragment" ],
  12373. THREE.ShaderChunk[ "lights_phong_fragment" ],
  12374. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12375. "totalDiffuseLight *= shadowMask;",
  12376. "totalSpecularLight *= shadowMask;",
  12377. "#ifdef METAL",
  12378. " outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) * specular + totalSpecularLight + totalEmissiveLight;",
  12379. "#else",
  12380. " outgoingLight += diffuseColor.rgb * ( totalDiffuseLight + totalAmbientLight ) + totalSpecularLight + totalEmissiveLight;",
  12381. "#endif",
  12382. THREE.ShaderChunk[ "envmap_fragment" ],
  12383. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  12384. THREE.ShaderChunk[ "fog_fragment" ],
  12385. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12386. "}"
  12387. ].join( "\n" )
  12388. },
  12389. 'points': {
  12390. uniforms: THREE.UniformsUtils.merge( [
  12391. THREE.UniformsLib[ "points" ],
  12392. THREE.UniformsLib[ "shadowmap" ]
  12393. ] ),
  12394. vertexShader: [
  12395. "uniform float size;",
  12396. "uniform float scale;",
  12397. THREE.ShaderChunk[ "common" ],
  12398. THREE.ShaderChunk[ "color_pars_vertex" ],
  12399. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  12400. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12401. "void main() {",
  12402. THREE.ShaderChunk[ "color_vertex" ],
  12403. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12404. " #ifdef USE_SIZEATTENUATION",
  12405. " gl_PointSize = size * ( scale / length( mvPosition.xyz ) );",
  12406. " #else",
  12407. " gl_PointSize = size;",
  12408. " #endif",
  12409. " gl_Position = projectionMatrix * mvPosition;",
  12410. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12411. THREE.ShaderChunk[ "worldpos_vertex" ],
  12412. THREE.ShaderChunk[ "shadowmap_vertex" ],
  12413. "}"
  12414. ].join( "\n" ),
  12415. fragmentShader: [
  12416. "uniform vec3 psColor;",
  12417. "uniform float opacity;",
  12418. THREE.ShaderChunk[ "common" ],
  12419. THREE.ShaderChunk[ "color_pars_fragment" ],
  12420. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  12421. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12422. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  12423. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12424. "void main() {",
  12425. " vec3 outgoingLight = vec3( 0.0 );",
  12426. " vec4 diffuseColor = vec4( psColor, opacity );",
  12427. " vec3 shadowMask = vec3( 1.0 );",
  12428. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12429. THREE.ShaderChunk[ "map_particle_fragment" ],
  12430. THREE.ShaderChunk[ "color_fragment" ],
  12431. THREE.ShaderChunk[ "alphatest_fragment" ],
  12432. THREE.ShaderChunk[ "shadowmap_fragment" ],
  12433. " outgoingLight = diffuseColor.rgb * shadowMask;",
  12434. THREE.ShaderChunk[ "fog_fragment" ],
  12435. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12436. "}"
  12437. ].join( "\n" )
  12438. },
  12439. 'dashed': {
  12440. uniforms: THREE.UniformsUtils.merge( [
  12441. THREE.UniformsLib[ "common" ],
  12442. THREE.UniformsLib[ "fog" ],
  12443. {
  12444. "scale" : { type: "f", value: 1 },
  12445. "dashSize" : { type: "f", value: 1 },
  12446. "totalSize": { type: "f", value: 2 }
  12447. }
  12448. ] ),
  12449. vertexShader: [
  12450. "uniform float scale;",
  12451. "attribute float lineDistance;",
  12452. "varying float vLineDistance;",
  12453. THREE.ShaderChunk[ "common" ],
  12454. THREE.ShaderChunk[ "color_pars_vertex" ],
  12455. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12456. "void main() {",
  12457. THREE.ShaderChunk[ "color_vertex" ],
  12458. " vLineDistance = scale * lineDistance;",
  12459. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  12460. " gl_Position = projectionMatrix * mvPosition;",
  12461. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12462. "}"
  12463. ].join( "\n" ),
  12464. fragmentShader: [
  12465. "uniform vec3 diffuse;",
  12466. "uniform float opacity;",
  12467. "uniform float dashSize;",
  12468. "uniform float totalSize;",
  12469. "varying float vLineDistance;",
  12470. THREE.ShaderChunk[ "common" ],
  12471. THREE.ShaderChunk[ "color_pars_fragment" ],
  12472. THREE.ShaderChunk[ "fog_pars_fragment" ],
  12473. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12474. "void main() {",
  12475. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  12476. " discard;",
  12477. " }",
  12478. " vec3 outgoingLight = vec3( 0.0 );",
  12479. " vec4 diffuseColor = vec4( diffuse, opacity );",
  12480. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12481. THREE.ShaderChunk[ "color_fragment" ],
  12482. " outgoingLight = diffuseColor.rgb;", // simple shader
  12483. THREE.ShaderChunk[ "fog_fragment" ],
  12484. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  12485. "}"
  12486. ].join( "\n" )
  12487. },
  12488. 'depth': {
  12489. uniforms: {
  12490. "mNear": { type: "f", value: 1.0 },
  12491. "mFar" : { type: "f", value: 2000.0 },
  12492. "opacity" : { type: "f", value: 1.0 }
  12493. },
  12494. vertexShader: [
  12495. THREE.ShaderChunk[ "common" ],
  12496. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12497. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12498. "void main() {",
  12499. THREE.ShaderChunk[ "begin_vertex" ],
  12500. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12501. THREE.ShaderChunk[ "project_vertex" ],
  12502. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12503. "}"
  12504. ].join( "\n" ),
  12505. fragmentShader: [
  12506. "uniform float mNear;",
  12507. "uniform float mFar;",
  12508. "uniform float opacity;",
  12509. THREE.ShaderChunk[ "common" ],
  12510. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12511. "void main() {",
  12512. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12513. " #ifdef USE_LOGDEPTHBUF_EXT",
  12514. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  12515. " #else",
  12516. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  12517. " #endif",
  12518. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  12519. " gl_FragColor = vec4( vec3( color ), opacity );",
  12520. "}"
  12521. ].join( "\n" )
  12522. },
  12523. 'normal': {
  12524. uniforms: {
  12525. "opacity" : { type: "f", value: 1.0 }
  12526. },
  12527. vertexShader: [
  12528. "varying vec3 vNormal;",
  12529. THREE.ShaderChunk[ "common" ],
  12530. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12531. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12532. "void main() {",
  12533. " vNormal = normalize( normalMatrix * normal );",
  12534. THREE.ShaderChunk[ "begin_vertex" ],
  12535. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12536. THREE.ShaderChunk[ "project_vertex" ],
  12537. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12538. "}"
  12539. ].join( "\n" ),
  12540. fragmentShader: [
  12541. "uniform float opacity;",
  12542. "varying vec3 vNormal;",
  12543. THREE.ShaderChunk[ "common" ],
  12544. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12545. "void main() {",
  12546. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  12547. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12548. "}"
  12549. ].join( "\n" )
  12550. },
  12551. /* -------------------------------------------------------------------------
  12552. // Cube map shader
  12553. ------------------------------------------------------------------------- */
  12554. 'cube': {
  12555. uniforms: { "tCube": { type: "t", value: null },
  12556. "tFlip": { type: "f", value: - 1 } },
  12557. vertexShader: [
  12558. "varying vec3 vWorldPosition;",
  12559. THREE.ShaderChunk[ "common" ],
  12560. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12561. "void main() {",
  12562. " vWorldPosition = transformDirection( position, modelMatrix );",
  12563. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12564. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12565. "}"
  12566. ].join( "\n" ),
  12567. fragmentShader: [
  12568. "uniform samplerCube tCube;",
  12569. "uniform float tFlip;",
  12570. "varying vec3 vWorldPosition;",
  12571. THREE.ShaderChunk[ "common" ],
  12572. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12573. "void main() {",
  12574. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12575. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12576. "}"
  12577. ].join( "\n" )
  12578. },
  12579. /* -------------------------------------------------------------------------
  12580. // Cube map shader
  12581. ------------------------------------------------------------------------- */
  12582. 'equirect': {
  12583. uniforms: { "tEquirect": { type: "t", value: null },
  12584. "tFlip": { type: "f", value: - 1 } },
  12585. vertexShader: [
  12586. "varying vec3 vWorldPosition;",
  12587. THREE.ShaderChunk[ "common" ],
  12588. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12589. "void main() {",
  12590. " vWorldPosition = transformDirection( position, modelMatrix );",
  12591. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  12592. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12593. "}"
  12594. ].join( "\n" ),
  12595. fragmentShader: [
  12596. "uniform sampler2D tEquirect;",
  12597. "uniform float tFlip;",
  12598. "varying vec3 vWorldPosition;",
  12599. THREE.ShaderChunk[ "common" ],
  12600. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12601. "void main() {",
  12602. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  12603. "vec3 direction = normalize( vWorldPosition );",
  12604. "vec2 sampleUV;",
  12605. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  12606. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  12607. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  12608. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12609. "}"
  12610. ].join( "\n" )
  12611. },
  12612. /* Depth encoding into RGBA texture
  12613. *
  12614. * based on SpiderGL shadow map example
  12615. * http://spidergl.org/example.php?id=6
  12616. *
  12617. * originally from
  12618. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  12619. *
  12620. * see also
  12621. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  12622. */
  12623. 'depthRGBA': {
  12624. uniforms: {},
  12625. vertexShader: [
  12626. THREE.ShaderChunk[ "common" ],
  12627. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12628. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12629. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  12630. "void main() {",
  12631. THREE.ShaderChunk[ "skinbase_vertex" ],
  12632. THREE.ShaderChunk[ "begin_vertex" ],
  12633. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12634. THREE.ShaderChunk[ "skinning_vertex" ],
  12635. THREE.ShaderChunk[ "project_vertex" ],
  12636. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  12637. "}"
  12638. ].join( "\n" ),
  12639. fragmentShader: [
  12640. THREE.ShaderChunk[ "common" ],
  12641. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  12642. "vec4 pack_depth( const in float depth ) {",
  12643. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12644. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12645. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );", // " vec4 res = fract( depth * bit_shift );",
  12646. " res -= res.xxyz * bit_mask;",
  12647. " return res;",
  12648. "}",
  12649. "void main() {",
  12650. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  12651. " #ifdef USE_LOGDEPTHBUF_EXT",
  12652. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  12653. " #else",
  12654. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  12655. " #endif",
  12656. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  12657. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  12658. //"gl_FragData[ 0 ] = pack_depth( z );",
  12659. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  12660. "}"
  12661. ].join( "\n" )
  12662. },
  12663. 'distanceRGBA': {
  12664. uniforms: {
  12665. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  12666. },
  12667. vertexShader: [
  12668. "varying vec4 vWorldPosition;",
  12669. THREE.ShaderChunk[ "common" ],
  12670. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  12671. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  12672. "void main() {",
  12673. THREE.ShaderChunk[ "skinbase_vertex" ],
  12674. THREE.ShaderChunk[ "begin_vertex" ],
  12675. THREE.ShaderChunk[ "morphtarget_vertex" ],
  12676. THREE.ShaderChunk[ "skinning_vertex" ],
  12677. THREE.ShaderChunk[ "project_vertex" ],
  12678. THREE.ShaderChunk[ "worldpos_vertex" ],
  12679. "vWorldPosition = worldPosition;",
  12680. "}"
  12681. ].join( "\n" ),
  12682. fragmentShader: [
  12683. "uniform vec3 lightPos;",
  12684. "varying vec4 vWorldPosition;",
  12685. THREE.ShaderChunk[ "common" ],
  12686. "vec4 pack1K ( float depth ) {",
  12687. " depth /= 1000.0;",
  12688. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  12689. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  12690. " vec4 res = fract( depth * bitSh );",
  12691. " res -= res.xxyz * bitMsk;",
  12692. " return res; ",
  12693. "}",
  12694. "float unpack1K ( vec4 color ) {",
  12695. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  12696. " return dot( color, bitSh ) * 1000.0;",
  12697. "}",
  12698. "void main () {",
  12699. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  12700. "}"
  12701. ].join( "\n" )
  12702. }
  12703. };
  12704. // File:src/renderers/WebGLRenderer.js
  12705. /**
  12706. * @author supereggbert / http://www.paulbrunt.co.uk/
  12707. * @author mrdoob / http://mrdoob.com/
  12708. * @author alteredq / http://alteredqualia.com/
  12709. * @author szimek / https://github.com/szimek/
  12710. */
  12711. THREE.WebGLRenderer = function ( parameters ) {
  12712. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  12713. parameters = parameters || {};
  12714. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  12715. _context = parameters.context !== undefined ? parameters.context : null,
  12716. _width = _canvas.width,
  12717. _height = _canvas.height,
  12718. pixelRatio = 1,
  12719. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  12720. _depth = parameters.depth !== undefined ? parameters.depth : true,
  12721. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  12722. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  12723. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  12724. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false,
  12725. _clearColor = new THREE.Color( 0x000000 ),
  12726. _clearAlpha = 0;
  12727. var lights = [];
  12728. var opaqueObjects = [];
  12729. var opaqueObjectsLastIndex = - 1;
  12730. var transparentObjects = [];
  12731. var transparentObjectsLastIndex = - 1;
  12732. var morphInfluences = new Float32Array( 8 );
  12733. var sprites = [];
  12734. var lensFlares = [];
  12735. // public properties
  12736. this.domElement = _canvas;
  12737. this.context = null;
  12738. // clearing
  12739. this.autoClear = true;
  12740. this.autoClearColor = true;
  12741. this.autoClearDepth = true;
  12742. this.autoClearStencil = true;
  12743. // scene graph
  12744. this.sortObjects = true;
  12745. // physically based shading
  12746. this.gammaFactor = 2.0; // for backwards compatibility
  12747. this.gammaInput = false;
  12748. this.gammaOutput = false;
  12749. // morphs
  12750. this.maxMorphTargets = 8;
  12751. this.maxMorphNormals = 4;
  12752. // flags
  12753. this.autoScaleCubemaps = true;
  12754. // internal properties
  12755. var _this = this,
  12756. // internal state cache
  12757. _currentProgram = null,
  12758. _currentFramebuffer = null,
  12759. _currentMaterialId = - 1,
  12760. _currentGeometryProgram = '',
  12761. _currentCamera = null,
  12762. _usedTextureUnits = 0,
  12763. _viewportX = 0,
  12764. _viewportY = 0,
  12765. _viewportWidth = _canvas.width,
  12766. _viewportHeight = _canvas.height,
  12767. _currentWidth = 0,
  12768. _currentHeight = 0,
  12769. // frustum
  12770. _frustum = new THREE.Frustum(),
  12771. // camera matrices cache
  12772. _projScreenMatrix = new THREE.Matrix4(),
  12773. _vector3 = new THREE.Vector3(),
  12774. // light arrays cache
  12775. _direction = new THREE.Vector3(),
  12776. _lightsNeedUpdate = true,
  12777. _lights = {
  12778. ambient: [ 0, 0, 0 ],
  12779. directional: { length: 0, colors: [], positions: [] },
  12780. point: { length: 0, colors: [], positions: [], distances: [], decays: [] },
  12781. spot: { length: 0, colors: [], positions: [], distances: [], directions: [], anglesCos: [], exponents: [], decays: [] },
  12782. hemi: { length: 0, skyColors: [], groundColors: [], positions: [] }
  12783. },
  12784. // info
  12785. _infoMemory = {
  12786. geometries: 0,
  12787. textures: 0
  12788. },
  12789. _infoRender = {
  12790. calls: 0,
  12791. vertices: 0,
  12792. faces: 0,
  12793. points: 0
  12794. };
  12795. this.info = {
  12796. render: _infoRender,
  12797. memory: _infoMemory,
  12798. programs: null
  12799. };
  12800. // initialize
  12801. var _gl;
  12802. try {
  12803. var attributes = {
  12804. alpha: _alpha,
  12805. depth: _depth,
  12806. stencil: _stencil,
  12807. antialias: _antialias,
  12808. premultipliedAlpha: _premultipliedAlpha,
  12809. preserveDrawingBuffer: _preserveDrawingBuffer
  12810. };
  12811. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  12812. if ( _gl === null ) {
  12813. if ( _canvas.getContext( 'webgl' ) !== null ) {
  12814. throw 'Error creating WebGL context with your selected attributes.';
  12815. } else {
  12816. throw 'Error creating WebGL context.';
  12817. }
  12818. }
  12819. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  12820. } catch ( error ) {
  12821. console.error( 'THREE.WebGLRenderer: ' + error );
  12822. }
  12823. var extensions = new THREE.WebGLExtensions( _gl );
  12824. extensions.get( 'OES_texture_float' );
  12825. extensions.get( 'OES_texture_float_linear' );
  12826. extensions.get( 'OES_texture_half_float' );
  12827. extensions.get( 'OES_texture_half_float_linear' );
  12828. extensions.get( 'OES_standard_derivatives' );
  12829. extensions.get( 'ANGLE_instanced_arrays' );
  12830. if ( extensions.get( 'OES_element_index_uint' ) ) {
  12831. THREE.BufferGeometry.MaxIndex = 4294967296;
  12832. }
  12833. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  12834. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  12835. var properties = new THREE.WebGLProperties();
  12836. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  12837. var programCache = new THREE.WebGLPrograms( this, capabilities );
  12838. this.info.programs = programCache.programs;
  12839. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  12840. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  12841. //
  12842. function glClearColor( r, g, b, a ) {
  12843. if ( _premultipliedAlpha === true ) {
  12844. r *= a; g *= a; b *= a;
  12845. }
  12846. _gl.clearColor( r, g, b, a );
  12847. }
  12848. function setDefaultGLState() {
  12849. state.init();
  12850. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12851. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12852. }
  12853. function resetGLState() {
  12854. _currentProgram = null;
  12855. _currentCamera = null;
  12856. _currentGeometryProgram = '';
  12857. _currentMaterialId = - 1;
  12858. _lightsNeedUpdate = true;
  12859. state.reset();
  12860. }
  12861. setDefaultGLState();
  12862. this.context = _gl;
  12863. this.capabilities = capabilities;
  12864. this.extensions = extensions;
  12865. this.state = state;
  12866. // shadow map
  12867. var shadowMap = new THREE.WebGLShadowMap( this, lights, objects );
  12868. this.shadowMap = shadowMap;
  12869. // Plugins
  12870. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  12871. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  12872. // API
  12873. this.getContext = function () {
  12874. return _gl;
  12875. };
  12876. this.getContextAttributes = function () {
  12877. return _gl.getContextAttributes();
  12878. };
  12879. this.forceContextLoss = function () {
  12880. extensions.get( 'WEBGL_lose_context' ).loseContext();
  12881. };
  12882. this.getMaxAnisotropy = ( function () {
  12883. var value;
  12884. return function getMaxAnisotropy() {
  12885. if ( value !== undefined ) return value;
  12886. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  12887. if ( extension !== null ) {
  12888. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  12889. } else {
  12890. value = 0;
  12891. }
  12892. return value;
  12893. }
  12894. } )();
  12895. this.getPrecision = function () {
  12896. return capabilities.precision;
  12897. };
  12898. this.getPixelRatio = function () {
  12899. return pixelRatio;
  12900. };
  12901. this.setPixelRatio = function ( value ) {
  12902. if ( value !== undefined ) pixelRatio = value;
  12903. };
  12904. this.getSize = function () {
  12905. return {
  12906. width: _width,
  12907. height: _height
  12908. };
  12909. };
  12910. this.setSize = function ( width, height, updateStyle ) {
  12911. _width = width;
  12912. _height = height;
  12913. _canvas.width = width * pixelRatio;
  12914. _canvas.height = height * pixelRatio;
  12915. if ( updateStyle !== false ) {
  12916. _canvas.style.width = width + 'px';
  12917. _canvas.style.height = height + 'px';
  12918. }
  12919. this.setViewport( 0, 0, width, height );
  12920. };
  12921. this.setViewport = function ( x, y, width, height ) {
  12922. _viewportX = x * pixelRatio;
  12923. _viewportY = y * pixelRatio;
  12924. _viewportWidth = width * pixelRatio;
  12925. _viewportHeight = height * pixelRatio;
  12926. _gl.viewport( _viewportX, _viewportY, _viewportWidth, _viewportHeight );
  12927. };
  12928. this.getViewport = function ( dimensions ) {
  12929. dimensions.x = _viewportX / pixelRatio;
  12930. dimensions.y = _viewportY / pixelRatio;
  12931. dimensions.z = _viewportWidth / pixelRatio;
  12932. dimensions.w = _viewportHeight / pixelRatio;
  12933. };
  12934. this.setScissor = function ( x, y, width, height ) {
  12935. _gl.scissor(
  12936. x * pixelRatio,
  12937. y * pixelRatio,
  12938. width * pixelRatio,
  12939. height * pixelRatio
  12940. );
  12941. };
  12942. this.enableScissorTest = function ( boolean ) {
  12943. state.setScissorTest( boolean );
  12944. };
  12945. // Clearing
  12946. this.getClearColor = function () {
  12947. return _clearColor;
  12948. };
  12949. this.setClearColor = function ( color, alpha ) {
  12950. _clearColor.set( color );
  12951. _clearAlpha = alpha !== undefined ? alpha : 1;
  12952. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12953. };
  12954. this.getClearAlpha = function () {
  12955. return _clearAlpha;
  12956. };
  12957. this.setClearAlpha = function ( alpha ) {
  12958. _clearAlpha = alpha;
  12959. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  12960. };
  12961. this.clear = function ( color, depth, stencil ) {
  12962. var bits = 0;
  12963. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  12964. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  12965. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  12966. _gl.clear( bits );
  12967. };
  12968. this.clearColor = function () {
  12969. _gl.clear( _gl.COLOR_BUFFER_BIT );
  12970. };
  12971. this.clearDepth = function () {
  12972. _gl.clear( _gl.DEPTH_BUFFER_BIT );
  12973. };
  12974. this.clearStencil = function () {
  12975. _gl.clear( _gl.STENCIL_BUFFER_BIT );
  12976. };
  12977. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  12978. this.setRenderTarget( renderTarget );
  12979. this.clear( color, depth, stencil );
  12980. };
  12981. // Reset
  12982. this.resetGLState = resetGLState;
  12983. this.dispose = function() {
  12984. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  12985. };
  12986. // Events
  12987. function onContextLost( event ) {
  12988. event.preventDefault();
  12989. resetGLState();
  12990. setDefaultGLState();
  12991. properties.clear();
  12992. };
  12993. function onTextureDispose( event ) {
  12994. var texture = event.target;
  12995. texture.removeEventListener( 'dispose', onTextureDispose );
  12996. deallocateTexture( texture );
  12997. _infoMemory.textures --;
  12998. }
  12999. function onRenderTargetDispose( event ) {
  13000. var renderTarget = event.target;
  13001. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  13002. deallocateRenderTarget( renderTarget );
  13003. _infoMemory.textures --;
  13004. }
  13005. function onMaterialDispose( event ) {
  13006. var material = event.target;
  13007. material.removeEventListener( 'dispose', onMaterialDispose );
  13008. deallocateMaterial( material );
  13009. }
  13010. // Buffer deallocation
  13011. function deallocateTexture( texture ) {
  13012. var textureProperties = properties.get( texture );
  13013. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  13014. // cube texture
  13015. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  13016. } else {
  13017. // 2D texture
  13018. if ( textureProperties.__webglInit === undefined ) return;
  13019. _gl.deleteTexture( textureProperties.__webglTexture );
  13020. }
  13021. // remove all webgl properties
  13022. properties.delete( texture );
  13023. }
  13024. function deallocateRenderTarget( renderTarget ) {
  13025. var renderTargetProperties = properties.get( renderTarget );
  13026. var textureProperties = properties.get( renderTarget.texture );
  13027. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  13028. _gl.deleteTexture( textureProperties.__webglTexture );
  13029. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  13030. for ( var i = 0; i < 6; i ++ ) {
  13031. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  13032. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer[ i ] );
  13033. }
  13034. } else {
  13035. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  13036. _gl.deleteRenderbuffer( renderTargetProperties.__webglRenderbuffer );
  13037. }
  13038. properties.delete( renderTarget.texture );
  13039. properties.delete( renderTarget );
  13040. }
  13041. function deallocateMaterial( material ) {
  13042. releaseMaterialProgramReference( material );
  13043. properties.delete( material );
  13044. }
  13045. function releaseMaterialProgramReference( material ) {
  13046. var programInfo = properties.get( material ).program;
  13047. material.program = undefined;
  13048. if ( programInfo !== undefined ) {
  13049. programCache.releaseProgram( programInfo );
  13050. }
  13051. }
  13052. // Buffer rendering
  13053. this.renderBufferImmediate = function ( object, program, material ) {
  13054. state.initAttributes();
  13055. var buffers = properties.get( object );
  13056. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  13057. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  13058. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  13059. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  13060. var attributes = program.getAttributes();
  13061. if ( object.hasPositions ) {
  13062. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  13063. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  13064. state.enableAttribute( attributes.position );
  13065. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  13066. }
  13067. if ( object.hasNormals ) {
  13068. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  13069. if ( material.type !== 'MeshPhongMaterial' && material.shading === THREE.FlatShading ) {
  13070. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  13071. var array = object.normalArray;
  13072. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  13073. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  13074. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  13075. array[ i + 0 ] = nx;
  13076. array[ i + 1 ] = ny;
  13077. array[ i + 2 ] = nz;
  13078. array[ i + 3 ] = nx;
  13079. array[ i + 4 ] = ny;
  13080. array[ i + 5 ] = nz;
  13081. array[ i + 6 ] = nx;
  13082. array[ i + 7 ] = ny;
  13083. array[ i + 8 ] = nz;
  13084. }
  13085. }
  13086. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  13087. state.enableAttribute( attributes.normal );
  13088. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  13089. }
  13090. if ( object.hasUvs && material.map ) {
  13091. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  13092. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  13093. state.enableAttribute( attributes.uv );
  13094. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  13095. }
  13096. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  13097. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  13098. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  13099. state.enableAttribute( attributes.color );
  13100. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  13101. }
  13102. state.disableUnusedAttributes();
  13103. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  13104. object.count = 0;
  13105. };
  13106. this.renderBufferDirect = function ( camera, lights, fog, geometry, material, object, group ) {
  13107. setMaterial( material );
  13108. var program = setProgram( camera, lights, fog, material, object );
  13109. var updateBuffers = false;
  13110. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  13111. if ( geometryProgram !== _currentGeometryProgram ) {
  13112. _currentGeometryProgram = geometryProgram;
  13113. updateBuffers = true;
  13114. }
  13115. // morph targets
  13116. var morphTargetInfluences = object.morphTargetInfluences;
  13117. if ( morphTargetInfluences !== undefined ) {
  13118. var activeInfluences = [];
  13119. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  13120. var influence = morphTargetInfluences[ i ];
  13121. activeInfluences.push( [ influence, i ] );
  13122. }
  13123. activeInfluences.sort( numericalSort );
  13124. if ( activeInfluences.length > 8 ) {
  13125. activeInfluences.length = 8;
  13126. }
  13127. var morphAttributes = geometry.morphAttributes;
  13128. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  13129. var influence = activeInfluences[ i ];
  13130. morphInfluences[ i ] = influence[ 0 ];
  13131. if ( influence[ 0 ] !== 0 ) {
  13132. var index = influence[ 1 ];
  13133. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  13134. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  13135. } else {
  13136. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  13137. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  13138. }
  13139. }
  13140. var uniforms = program.getUniforms();
  13141. if ( uniforms.morphTargetInfluences !== null ) {
  13142. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  13143. }
  13144. updateBuffers = true;
  13145. }
  13146. //
  13147. var index = geometry.index;
  13148. var position = geometry.attributes.position;
  13149. if ( material.wireframe === true ) {
  13150. index = objects.getWireframeAttribute( geometry );
  13151. }
  13152. var renderer;
  13153. if ( index !== null ) {
  13154. renderer = indexedBufferRenderer;
  13155. renderer.setIndex( index );
  13156. } else {
  13157. renderer = bufferRenderer;
  13158. }
  13159. if ( updateBuffers ) {
  13160. setupVertexAttributes( material, program, geometry );
  13161. if ( index !== null ) {
  13162. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  13163. }
  13164. }
  13165. //
  13166. var dataStart = 0;
  13167. var dataCount = Infinity;
  13168. if ( index !== null ) {
  13169. dataCount = index.count
  13170. } else if ( position !== undefined ) {
  13171. dataCount = position.count;
  13172. }
  13173. var rangeStart = geometry.drawRange.start;
  13174. var rangeCount = geometry.drawRange.count;
  13175. var groupStart = group !== null ? group.start : 0;
  13176. var groupCount = group !== null ? group.count : Infinity;
  13177. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  13178. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  13179. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  13180. //
  13181. if ( object instanceof THREE.Mesh ) {
  13182. if ( material.wireframe === true ) {
  13183. state.setLineWidth( material.wireframeLinewidth * pixelRatio );
  13184. renderer.setMode( _gl.LINES );
  13185. } else {
  13186. renderer.setMode( _gl.TRIANGLES );
  13187. }
  13188. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  13189. renderer.renderInstances( geometry );
  13190. } else {
  13191. renderer.render( drawStart, drawCount );
  13192. }
  13193. } else if ( object instanceof THREE.Line ) {
  13194. var lineWidth = material.linewidth;
  13195. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  13196. state.setLineWidth( lineWidth * pixelRatio );
  13197. if ( object instanceof THREE.LineSegments ) {
  13198. renderer.setMode( _gl.LINES );
  13199. } else {
  13200. renderer.setMode( _gl.LINE_STRIP );
  13201. }
  13202. renderer.render( drawStart, drawCount );
  13203. } else if ( object instanceof THREE.Points ) {
  13204. renderer.setMode( _gl.POINTS );
  13205. renderer.render( drawStart, drawCount );
  13206. }
  13207. };
  13208. function setupVertexAttributes( material, program, geometry, startIndex ) {
  13209. var extension;
  13210. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  13211. extension = extensions.get( 'ANGLE_instanced_arrays' );
  13212. if ( extension === null ) {
  13213. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  13214. return;
  13215. }
  13216. }
  13217. if ( startIndex === undefined ) startIndex = 0;
  13218. state.initAttributes();
  13219. var geometryAttributes = geometry.attributes;
  13220. var programAttributes = program.getAttributes();
  13221. var materialDefaultAttributeValues = material.defaultAttributeValues;
  13222. for ( var name in programAttributes ) {
  13223. var programAttribute = programAttributes[ name ];
  13224. if ( programAttribute >= 0 ) {
  13225. var geometryAttribute = geometryAttributes[ name ];
  13226. if ( geometryAttribute !== undefined ) {
  13227. var size = geometryAttribute.itemSize;
  13228. var buffer = objects.getAttributeBuffer( geometryAttribute );
  13229. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  13230. var data = geometryAttribute.data;
  13231. var stride = data.stride;
  13232. var offset = geometryAttribute.offset;
  13233. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  13234. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  13235. if ( geometry.maxInstancedCount === undefined ) {
  13236. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  13237. }
  13238. } else {
  13239. state.enableAttribute( programAttribute );
  13240. }
  13241. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13242. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  13243. } else {
  13244. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  13245. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  13246. if ( geometry.maxInstancedCount === undefined ) {
  13247. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  13248. }
  13249. } else {
  13250. state.enableAttribute( programAttribute );
  13251. }
  13252. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  13253. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  13254. }
  13255. } else if ( materialDefaultAttributeValues !== undefined ) {
  13256. var value = materialDefaultAttributeValues[ name ];
  13257. if ( value !== undefined ) {
  13258. switch ( value.length ) {
  13259. case 2:
  13260. _gl.vertexAttrib2fv( programAttribute, value );
  13261. break;
  13262. case 3:
  13263. _gl.vertexAttrib3fv( programAttribute, value );
  13264. break;
  13265. case 4:
  13266. _gl.vertexAttrib4fv( programAttribute, value );
  13267. break;
  13268. default:
  13269. _gl.vertexAttrib1fv( programAttribute, value );
  13270. }
  13271. }
  13272. }
  13273. }
  13274. }
  13275. state.disableUnusedAttributes();
  13276. }
  13277. // Sorting
  13278. function numericalSort ( a, b ) {
  13279. return b[ 0 ] - a[ 0 ];
  13280. }
  13281. function painterSortStable ( a, b ) {
  13282. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13283. return a.object.renderOrder - b.object.renderOrder;
  13284. } else if ( a.material.id !== b.material.id ) {
  13285. return a.material.id - b.material.id;
  13286. } else if ( a.z !== b.z ) {
  13287. return a.z - b.z;
  13288. } else {
  13289. return a.id - b.id;
  13290. }
  13291. }
  13292. function reversePainterSortStable ( a, b ) {
  13293. if ( a.object.renderOrder !== b.object.renderOrder ) {
  13294. return a.object.renderOrder - b.object.renderOrder;
  13295. } if ( a.z !== b.z ) {
  13296. return b.z - a.z;
  13297. } else {
  13298. return a.id - b.id;
  13299. }
  13300. }
  13301. // Rendering
  13302. this.render = function ( scene, camera, renderTarget, forceClear ) {
  13303. if ( camera instanceof THREE.Camera === false ) {
  13304. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  13305. return;
  13306. }
  13307. var fog = scene.fog;
  13308. // reset caching for this frame
  13309. _currentGeometryProgram = '';
  13310. _currentMaterialId = - 1;
  13311. _currentCamera = null;
  13312. _lightsNeedUpdate = true;
  13313. // update scene graph
  13314. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  13315. // update camera matrices and frustum
  13316. if ( camera.parent === null ) camera.updateMatrixWorld();
  13317. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  13318. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  13319. _frustum.setFromMatrix( _projScreenMatrix );
  13320. lights.length = 0;
  13321. opaqueObjectsLastIndex = - 1;
  13322. transparentObjectsLastIndex = - 1;
  13323. sprites.length = 0;
  13324. lensFlares.length = 0;
  13325. projectObject( scene );
  13326. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  13327. transparentObjects.length = transparentObjectsLastIndex + 1;
  13328. if ( _this.sortObjects === true ) {
  13329. opaqueObjects.sort( painterSortStable );
  13330. transparentObjects.sort( reversePainterSortStable );
  13331. }
  13332. //
  13333. shadowMap.render( scene );
  13334. //
  13335. _infoRender.calls = 0;
  13336. _infoRender.vertices = 0;
  13337. _infoRender.faces = 0;
  13338. _infoRender.points = 0;
  13339. this.setRenderTarget( renderTarget );
  13340. if ( this.autoClear || forceClear ) {
  13341. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  13342. }
  13343. //
  13344. if ( scene.overrideMaterial ) {
  13345. var overrideMaterial = scene.overrideMaterial;
  13346. renderObjects( opaqueObjects, camera, lights, fog, overrideMaterial );
  13347. renderObjects( transparentObjects, camera, lights, fog, overrideMaterial );
  13348. } else {
  13349. // opaque pass (front-to-back order)
  13350. state.setBlending( THREE.NoBlending );
  13351. renderObjects( opaqueObjects, camera, lights, fog );
  13352. // transparent pass (back-to-front order)
  13353. renderObjects( transparentObjects, camera, lights, fog );
  13354. }
  13355. // custom render plugins (post pass)
  13356. spritePlugin.render( scene, camera );
  13357. lensFlarePlugin.render( scene, camera, _currentWidth, _currentHeight );
  13358. // Generate mipmap if we're using any kind of mipmap filtering
  13359. if ( renderTarget ) {
  13360. var texture = renderTarget.texture;
  13361. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  13362. if ( texture.generateMipmaps && isTargetPowerOfTwo && texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  13363. updateRenderTargetMipmap( renderTarget );
  13364. }
  13365. }
  13366. // Ensure depth buffer writing is enabled so it can be cleared on next render
  13367. state.setDepthTest( true );
  13368. state.setDepthWrite( true );
  13369. state.setColorWrite( true );
  13370. // _gl.finish();
  13371. };
  13372. function pushRenderItem( object, geometry, material, z, group ) {
  13373. var array, index;
  13374. // allocate the next position in the appropriate array
  13375. if ( material.transparent ) {
  13376. array = transparentObjects;
  13377. index = ++ transparentObjectsLastIndex;
  13378. } else {
  13379. array = opaqueObjects;
  13380. index = ++ opaqueObjectsLastIndex;
  13381. }
  13382. // recycle existing render item or grow the array
  13383. var renderItem = array[ index ];
  13384. if ( renderItem !== undefined ) {
  13385. renderItem.id = object.id;
  13386. renderItem.object = object;
  13387. renderItem.geometry = geometry;
  13388. renderItem.material = material;
  13389. renderItem.z = _vector3.z;
  13390. renderItem.group = group;
  13391. } else {
  13392. renderItem = {
  13393. id: object.id,
  13394. object: object,
  13395. geometry: geometry,
  13396. material: material,
  13397. z: _vector3.z,
  13398. group: group
  13399. };
  13400. // assert( index === array.length );
  13401. array.push( renderItem );
  13402. }
  13403. }
  13404. function projectObject( object ) {
  13405. if ( object.visible === false ) return;
  13406. if ( object instanceof THREE.Light ) {
  13407. lights.push( object );
  13408. } else if ( object instanceof THREE.Sprite ) {
  13409. sprites.push( object );
  13410. } else if ( object instanceof THREE.LensFlare ) {
  13411. lensFlares.push( object );
  13412. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  13413. if ( _this.sortObjects === true ) {
  13414. _vector3.setFromMatrixPosition( object.matrixWorld );
  13415. _vector3.applyProjection( _projScreenMatrix );
  13416. }
  13417. pushRenderItem( object, null, object.material, _vector3.z, null );
  13418. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  13419. if ( object instanceof THREE.SkinnedMesh ) {
  13420. object.skeleton.update();
  13421. }
  13422. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  13423. var material = object.material;
  13424. if ( material.visible === true ) {
  13425. if ( _this.sortObjects === true ) {
  13426. _vector3.setFromMatrixPosition( object.matrixWorld );
  13427. _vector3.applyProjection( _projScreenMatrix );
  13428. }
  13429. var geometry = objects.update( object );
  13430. if ( material instanceof THREE.MeshFaceMaterial ) {
  13431. var groups = geometry.groups;
  13432. var materials = material.materials;
  13433. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  13434. var group = groups[ i ];
  13435. var groupMaterial = materials[ group.materialIndex ];
  13436. if ( groupMaterial.visible === true ) {
  13437. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  13438. }
  13439. }
  13440. } else {
  13441. pushRenderItem( object, geometry, material, _vector3.z, null );
  13442. }
  13443. }
  13444. }
  13445. }
  13446. var children = object.children;
  13447. for ( var i = 0, l = children.length; i < l; i ++ ) {
  13448. projectObject( children[ i ] );
  13449. }
  13450. }
  13451. function renderObjects( renderList, camera, lights, fog, overrideMaterial ) {
  13452. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  13453. var renderItem = renderList[ i ];
  13454. var object = renderItem.object;
  13455. var geometry = renderItem.geometry;
  13456. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  13457. var group = renderItem.group;
  13458. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  13459. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  13460. if ( object instanceof THREE.ImmediateRenderObject ) {
  13461. setMaterial( material );
  13462. var program = setProgram( camera, lights, fog, material, object );
  13463. _currentGeometryProgram = '';
  13464. object.render( function ( object ) {
  13465. _this.renderBufferImmediate( object, program, material );
  13466. } );
  13467. } else {
  13468. _this.renderBufferDirect( camera, lights, fog, geometry, material, object, group );
  13469. }
  13470. }
  13471. }
  13472. function initMaterial( material, lights, fog, object ) {
  13473. var materialProperties = properties.get( material );
  13474. var parameters = programCache.getParameters( material, lights, fog, object );
  13475. var code = programCache.getProgramCode( material, parameters );
  13476. var program = materialProperties.program;
  13477. var programChange = true;
  13478. if ( program === undefined ) {
  13479. // new material
  13480. material.addEventListener( 'dispose', onMaterialDispose );
  13481. } else if ( program.code !== code ) {
  13482. // changed glsl or parameters
  13483. releaseMaterialProgramReference( material );
  13484. } else if ( parameters.shaderID !== undefined ) {
  13485. // same glsl and uniform list
  13486. return;
  13487. } else {
  13488. // only rebuild uniform list
  13489. programChange = false;
  13490. }
  13491. if ( programChange ) {
  13492. if ( parameters.shaderID ) {
  13493. var shader = THREE.ShaderLib[ parameters.shaderID ];
  13494. materialProperties.__webglShader = {
  13495. name: material.type,
  13496. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  13497. vertexShader: shader.vertexShader,
  13498. fragmentShader: shader.fragmentShader
  13499. };
  13500. } else {
  13501. materialProperties.__webglShader = {
  13502. name: material.type,
  13503. uniforms: material.uniforms,
  13504. vertexShader: material.vertexShader,
  13505. fragmentShader: material.fragmentShader
  13506. };
  13507. }
  13508. material.__webglShader = materialProperties.__webglShader;
  13509. program = programCache.acquireProgram( material, parameters, code );
  13510. materialProperties.program = program;
  13511. material.program = program;
  13512. }
  13513. var attributes = program.getAttributes();
  13514. if ( material.morphTargets ) {
  13515. material.numSupportedMorphTargets = 0;
  13516. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  13517. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  13518. material.numSupportedMorphTargets ++;
  13519. }
  13520. }
  13521. }
  13522. if ( material.morphNormals ) {
  13523. material.numSupportedMorphNormals = 0;
  13524. for ( i = 0; i < _this.maxMorphNormals; i ++ ) {
  13525. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  13526. material.numSupportedMorphNormals ++;
  13527. }
  13528. }
  13529. }
  13530. materialProperties.uniformsList = [];
  13531. var uniformLocations = materialProperties.program.getUniforms();
  13532. for ( var u in materialProperties.__webglShader.uniforms ) {
  13533. var location = uniformLocations[ u ];
  13534. if ( location ) {
  13535. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  13536. }
  13537. }
  13538. }
  13539. function setMaterial( material ) {
  13540. setMaterialFaces( material );
  13541. if ( material.transparent === true ) {
  13542. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  13543. } else {
  13544. state.setBlending( THREE.NoBlending );
  13545. }
  13546. state.setDepthFunc( material.depthFunc );
  13547. state.setDepthTest( material.depthTest );
  13548. state.setDepthWrite( material.depthWrite );
  13549. state.setColorWrite( material.colorWrite );
  13550. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  13551. }
  13552. function setMaterialFaces( material ) {
  13553. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  13554. state.setFlipSided( material.side === THREE.BackSide );
  13555. }
  13556. function setProgram( camera, lights, fog, material, object ) {
  13557. _usedTextureUnits = 0;
  13558. var materialProperties = properties.get( material );
  13559. if ( material.needsUpdate || ! materialProperties.program ) {
  13560. initMaterial( material, lights, fog, object );
  13561. material.needsUpdate = false;
  13562. }
  13563. var refreshProgram = false;
  13564. var refreshMaterial = false;
  13565. var refreshLights = false;
  13566. var program = materialProperties.program,
  13567. p_uniforms = program.getUniforms(),
  13568. m_uniforms = materialProperties.__webglShader.uniforms;
  13569. if ( program.id !== _currentProgram ) {
  13570. _gl.useProgram( program.program );
  13571. _currentProgram = program.id;
  13572. refreshProgram = true;
  13573. refreshMaterial = true;
  13574. refreshLights = true;
  13575. }
  13576. if ( material.id !== _currentMaterialId ) {
  13577. if ( _currentMaterialId === - 1 ) refreshLights = true;
  13578. _currentMaterialId = material.id;
  13579. refreshMaterial = true;
  13580. }
  13581. if ( refreshProgram || camera !== _currentCamera ) {
  13582. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  13583. if ( capabilities.logarithmicDepthBuffer ) {
  13584. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  13585. }
  13586. if ( camera !== _currentCamera ) _currentCamera = camera;
  13587. // load material specific uniforms
  13588. // (shader material also gets them for the sake of genericity)
  13589. if ( material instanceof THREE.ShaderMaterial ||
  13590. material instanceof THREE.MeshPhongMaterial ||
  13591. material.envMap ) {
  13592. if ( p_uniforms.cameraPosition !== undefined ) {
  13593. _vector3.setFromMatrixPosition( camera.matrixWorld );
  13594. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  13595. }
  13596. }
  13597. if ( material instanceof THREE.MeshPhongMaterial ||
  13598. material instanceof THREE.MeshLambertMaterial ||
  13599. material instanceof THREE.MeshBasicMaterial ||
  13600. material instanceof THREE.ShaderMaterial ||
  13601. material.skinning ) {
  13602. if ( p_uniforms.viewMatrix !== undefined ) {
  13603. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  13604. }
  13605. }
  13606. }
  13607. // skinning uniforms must be set even if material didn't change
  13608. // auto-setting of texture unit for bone texture must go before other textures
  13609. // not sure why, but otherwise weird things happen
  13610. if ( material.skinning ) {
  13611. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  13612. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  13613. }
  13614. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  13615. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  13616. }
  13617. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  13618. if ( p_uniforms.boneTexture !== undefined ) {
  13619. var textureUnit = getTextureUnit();
  13620. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  13621. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  13622. }
  13623. if ( p_uniforms.boneTextureWidth !== undefined ) {
  13624. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  13625. }
  13626. if ( p_uniforms.boneTextureHeight !== undefined ) {
  13627. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  13628. }
  13629. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  13630. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  13631. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  13632. }
  13633. }
  13634. }
  13635. if ( refreshMaterial ) {
  13636. // refresh uniforms common to several materials
  13637. if ( fog && material.fog ) {
  13638. refreshUniformsFog( m_uniforms, fog );
  13639. }
  13640. if ( material instanceof THREE.MeshPhongMaterial ||
  13641. material instanceof THREE.MeshLambertMaterial ||
  13642. material.lights ) {
  13643. if ( _lightsNeedUpdate ) {
  13644. refreshLights = true;
  13645. setupLights( lights, camera );
  13646. _lightsNeedUpdate = false;
  13647. }
  13648. if ( refreshLights ) {
  13649. refreshUniformsLights( m_uniforms, _lights );
  13650. markUniformsLightsNeedsUpdate( m_uniforms, true );
  13651. } else {
  13652. markUniformsLightsNeedsUpdate( m_uniforms, false );
  13653. }
  13654. }
  13655. if ( material instanceof THREE.MeshBasicMaterial ||
  13656. material instanceof THREE.MeshLambertMaterial ||
  13657. material instanceof THREE.MeshPhongMaterial ) {
  13658. refreshUniformsCommon( m_uniforms, material );
  13659. }
  13660. // refresh single material specific uniforms
  13661. if ( material instanceof THREE.LineBasicMaterial ) {
  13662. refreshUniformsLine( m_uniforms, material );
  13663. } else if ( material instanceof THREE.LineDashedMaterial ) {
  13664. refreshUniformsLine( m_uniforms, material );
  13665. refreshUniformsDash( m_uniforms, material );
  13666. } else if ( material instanceof THREE.PointsMaterial ) {
  13667. refreshUniformsParticle( m_uniforms, material );
  13668. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  13669. refreshUniformsPhong( m_uniforms, material );
  13670. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  13671. m_uniforms.mNear.value = camera.near;
  13672. m_uniforms.mFar.value = camera.far;
  13673. m_uniforms.opacity.value = material.opacity;
  13674. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  13675. m_uniforms.opacity.value = material.opacity;
  13676. }
  13677. if ( object.receiveShadow && ! material._shadowPass ) {
  13678. refreshUniformsShadow( m_uniforms, lights, camera );
  13679. }
  13680. // load common uniforms
  13681. loadUniformsGeneric( materialProperties.uniformsList );
  13682. }
  13683. loadUniformsMatrices( p_uniforms, object );
  13684. if ( p_uniforms.modelMatrix !== undefined ) {
  13685. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  13686. }
  13687. return program;
  13688. }
  13689. // Uniforms (refresh uniforms objects)
  13690. function refreshUniformsCommon ( uniforms, material ) {
  13691. uniforms.opacity.value = material.opacity;
  13692. uniforms.diffuse.value = material.color;
  13693. if ( material.emissive ) {
  13694. uniforms.emissive.value = material.emissive;
  13695. }
  13696. uniforms.map.value = material.map;
  13697. uniforms.specularMap.value = material.specularMap;
  13698. uniforms.alphaMap.value = material.alphaMap;
  13699. if ( material.aoMap ) {
  13700. uniforms.aoMap.value = material.aoMap;
  13701. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  13702. }
  13703. // uv repeat and offset setting priorities
  13704. // 1. color map
  13705. // 2. specular map
  13706. // 3. normal map
  13707. // 4. bump map
  13708. // 5. alpha map
  13709. // 6. emissive map
  13710. var uvScaleMap;
  13711. if ( material.map ) {
  13712. uvScaleMap = material.map;
  13713. } else if ( material.specularMap ) {
  13714. uvScaleMap = material.specularMap;
  13715. } else if ( material.displacementMap ) {
  13716. uvScaleMap = material.displacementMap;
  13717. } else if ( material.normalMap ) {
  13718. uvScaleMap = material.normalMap;
  13719. } else if ( material.bumpMap ) {
  13720. uvScaleMap = material.bumpMap;
  13721. } else if ( material.alphaMap ) {
  13722. uvScaleMap = material.alphaMap;
  13723. } else if ( material.emissiveMap ) {
  13724. uvScaleMap = material.emissiveMap;
  13725. }
  13726. if ( uvScaleMap !== undefined ) {
  13727. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) uvScaleMap = uvScaleMap.texture;
  13728. var offset = uvScaleMap.offset;
  13729. var repeat = uvScaleMap.repeat;
  13730. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13731. }
  13732. uniforms.envMap.value = material.envMap;
  13733. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  13734. uniforms.reflectivity.value = material.reflectivity;
  13735. uniforms.refractionRatio.value = material.refractionRatio;
  13736. }
  13737. function refreshUniformsLine ( uniforms, material ) {
  13738. uniforms.diffuse.value = material.color;
  13739. uniforms.opacity.value = material.opacity;
  13740. }
  13741. function refreshUniformsDash ( uniforms, material ) {
  13742. uniforms.dashSize.value = material.dashSize;
  13743. uniforms.totalSize.value = material.dashSize + material.gapSize;
  13744. uniforms.scale.value = material.scale;
  13745. }
  13746. function refreshUniformsParticle ( uniforms, material ) {
  13747. uniforms.psColor.value = material.color;
  13748. uniforms.opacity.value = material.opacity;
  13749. uniforms.size.value = material.size;
  13750. uniforms.scale.value = _canvas.height / 2.0; // TODO: Cache this.
  13751. uniforms.map.value = material.map;
  13752. if ( material.map !== null ) {
  13753. var offset = material.map.offset;
  13754. var repeat = material.map.repeat;
  13755. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  13756. }
  13757. }
  13758. function refreshUniformsFog ( uniforms, fog ) {
  13759. uniforms.fogColor.value = fog.color;
  13760. if ( fog instanceof THREE.Fog ) {
  13761. uniforms.fogNear.value = fog.near;
  13762. uniforms.fogFar.value = fog.far;
  13763. } else if ( fog instanceof THREE.FogExp2 ) {
  13764. uniforms.fogDensity.value = fog.density;
  13765. }
  13766. }
  13767. function refreshUniformsPhong ( uniforms, material ) {
  13768. uniforms.specular.value = material.specular;
  13769. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  13770. if ( material.lightMap ) {
  13771. uniforms.lightMap.value = material.lightMap;
  13772. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  13773. }
  13774. if ( material.emissiveMap ) {
  13775. uniforms.emissiveMap.value = material.emissiveMap;
  13776. }
  13777. if ( material.bumpMap ) {
  13778. uniforms.bumpMap.value = material.bumpMap;
  13779. uniforms.bumpScale.value = material.bumpScale;
  13780. }
  13781. if ( material.normalMap ) {
  13782. uniforms.normalMap.value = material.normalMap;
  13783. uniforms.normalScale.value.copy( material.normalScale );
  13784. }
  13785. if ( material.displacementMap ) {
  13786. uniforms.displacementMap.value = material.displacementMap;
  13787. uniforms.displacementScale.value = material.displacementScale;
  13788. uniforms.displacementBias.value = material.displacementBias;
  13789. }
  13790. }
  13791. function refreshUniformsLights ( uniforms, lights ) {
  13792. uniforms.ambientLightColor.value = lights.ambient;
  13793. uniforms.directionalLightColor.value = lights.directional.colors;
  13794. uniforms.directionalLightDirection.value = lights.directional.positions;
  13795. uniforms.pointLightColor.value = lights.point.colors;
  13796. uniforms.pointLightPosition.value = lights.point.positions;
  13797. uniforms.pointLightDistance.value = lights.point.distances;
  13798. uniforms.pointLightDecay.value = lights.point.decays;
  13799. uniforms.spotLightColor.value = lights.spot.colors;
  13800. uniforms.spotLightPosition.value = lights.spot.positions;
  13801. uniforms.spotLightDistance.value = lights.spot.distances;
  13802. uniforms.spotLightDirection.value = lights.spot.directions;
  13803. uniforms.spotLightAngleCos.value = lights.spot.anglesCos;
  13804. uniforms.spotLightExponent.value = lights.spot.exponents;
  13805. uniforms.spotLightDecay.value = lights.spot.decays;
  13806. uniforms.hemisphereLightSkyColor.value = lights.hemi.skyColors;
  13807. uniforms.hemisphereLightGroundColor.value = lights.hemi.groundColors;
  13808. uniforms.hemisphereLightDirection.value = lights.hemi.positions;
  13809. }
  13810. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  13811. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  13812. uniforms.ambientLightColor.needsUpdate = value;
  13813. uniforms.directionalLightColor.needsUpdate = value;
  13814. uniforms.directionalLightDirection.needsUpdate = value;
  13815. uniforms.pointLightColor.needsUpdate = value;
  13816. uniforms.pointLightPosition.needsUpdate = value;
  13817. uniforms.pointLightDistance.needsUpdate = value;
  13818. uniforms.pointLightDecay.needsUpdate = value;
  13819. uniforms.spotLightColor.needsUpdate = value;
  13820. uniforms.spotLightPosition.needsUpdate = value;
  13821. uniforms.spotLightDistance.needsUpdate = value;
  13822. uniforms.spotLightDirection.needsUpdate = value;
  13823. uniforms.spotLightAngleCos.needsUpdate = value;
  13824. uniforms.spotLightExponent.needsUpdate = value;
  13825. uniforms.spotLightDecay.needsUpdate = value;
  13826. uniforms.hemisphereLightSkyColor.needsUpdate = value;
  13827. uniforms.hemisphereLightGroundColor.needsUpdate = value;
  13828. uniforms.hemisphereLightDirection.needsUpdate = value;
  13829. }
  13830. function refreshUniformsShadow ( uniforms, lights, camera ) {
  13831. if ( uniforms.shadowMatrix ) {
  13832. var j = 0;
  13833. for ( var i = 0, il = lights.length; i < il; i ++ ) {
  13834. var light = lights[ i ];
  13835. if ( light.castShadow === false ) continue;
  13836. if ( light instanceof THREE.PointLight || light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) {
  13837. var shadow = light.shadow;
  13838. if ( light instanceof THREE.PointLight ) {
  13839. // for point lights we set the shadow matrix to be a translation-only matrix
  13840. // equal to inverse of the light's position
  13841. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  13842. shadow.matrix.identity().setPosition( _vector3 );
  13843. // for point lights we set the sign of the shadowDarkness uniform to be negative
  13844. uniforms.shadowDarkness.value[ j ] = - 1.0;
  13845. } else {
  13846. uniforms.shadowDarkness.value[ j ] = 1.0;
  13847. }
  13848. uniforms.shadowMatrix.value[ j ] = shadow.matrix;
  13849. uniforms.shadowMap.value[ j ] = shadow.map;
  13850. uniforms.shadowMapSize.value[ j ] = shadow.mapSize;
  13851. uniforms.shadowBias.value[ j ] = shadow.bias;
  13852. j ++;
  13853. }
  13854. }
  13855. }
  13856. }
  13857. // Uniforms (load to GPU)
  13858. function loadUniformsMatrices ( uniforms, object ) {
  13859. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  13860. if ( uniforms.normalMatrix ) {
  13861. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  13862. }
  13863. }
  13864. function getTextureUnit() {
  13865. var textureUnit = _usedTextureUnits;
  13866. if ( textureUnit >= capabilities.maxTextures ) {
  13867. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  13868. }
  13869. _usedTextureUnits += 1;
  13870. return textureUnit;
  13871. }
  13872. function loadUniformsGeneric ( uniforms ) {
  13873. var texture, textureUnit;
  13874. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  13875. var uniform = uniforms[ j ][ 0 ];
  13876. // needsUpdate property is not added to all uniforms.
  13877. if ( uniform.needsUpdate === false ) continue;
  13878. var type = uniform.type;
  13879. var value = uniform.value;
  13880. var location = uniforms[ j ][ 1 ];
  13881. switch ( type ) {
  13882. case '1i':
  13883. _gl.uniform1i( location, value );
  13884. break;
  13885. case '1f':
  13886. _gl.uniform1f( location, value );
  13887. break;
  13888. case '2f':
  13889. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  13890. break;
  13891. case '3f':
  13892. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  13893. break;
  13894. case '4f':
  13895. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  13896. break;
  13897. case '1iv':
  13898. _gl.uniform1iv( location, value );
  13899. break;
  13900. case '3iv':
  13901. _gl.uniform3iv( location, value );
  13902. break;
  13903. case '1fv':
  13904. _gl.uniform1fv( location, value );
  13905. break;
  13906. case '2fv':
  13907. _gl.uniform2fv( location, value );
  13908. break;
  13909. case '3fv':
  13910. _gl.uniform3fv( location, value );
  13911. break;
  13912. case '4fv':
  13913. _gl.uniform4fv( location, value );
  13914. break;
  13915. case 'Matrix3fv':
  13916. _gl.uniformMatrix3fv( location, false, value );
  13917. break;
  13918. case 'Matrix4fv':
  13919. _gl.uniformMatrix4fv( location, false, value );
  13920. break;
  13921. //
  13922. case 'i':
  13923. // single integer
  13924. _gl.uniform1i( location, value );
  13925. break;
  13926. case 'f':
  13927. // single float
  13928. _gl.uniform1f( location, value );
  13929. break;
  13930. case 'v2':
  13931. // single THREE.Vector2
  13932. _gl.uniform2f( location, value.x, value.y );
  13933. break;
  13934. case 'v3':
  13935. // single THREE.Vector3
  13936. _gl.uniform3f( location, value.x, value.y, value.z );
  13937. break;
  13938. case 'v4':
  13939. // single THREE.Vector4
  13940. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  13941. break;
  13942. case 'c':
  13943. // single THREE.Color
  13944. _gl.uniform3f( location, value.r, value.g, value.b );
  13945. break;
  13946. case 'iv1':
  13947. // flat array of integers (JS or typed array)
  13948. _gl.uniform1iv( location, value );
  13949. break;
  13950. case 'iv':
  13951. // flat array of integers with 3 x N size (JS or typed array)
  13952. _gl.uniform3iv( location, value );
  13953. break;
  13954. case 'fv1':
  13955. // flat array of floats (JS or typed array)
  13956. _gl.uniform1fv( location, value );
  13957. break;
  13958. case 'fv':
  13959. // flat array of floats with 3 x N size (JS or typed array)
  13960. _gl.uniform3fv( location, value );
  13961. break;
  13962. case 'v2v':
  13963. // array of THREE.Vector2
  13964. if ( uniform._array === undefined ) {
  13965. uniform._array = new Float32Array( 2 * value.length );
  13966. }
  13967. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  13968. uniform._array[ i2 + 0 ] = value[ i ].x;
  13969. uniform._array[ i2 + 1 ] = value[ i ].y;
  13970. }
  13971. _gl.uniform2fv( location, uniform._array );
  13972. break;
  13973. case 'v3v':
  13974. // array of THREE.Vector3
  13975. if ( uniform._array === undefined ) {
  13976. uniform._array = new Float32Array( 3 * value.length );
  13977. }
  13978. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  13979. uniform._array[ i3 + 0 ] = value[ i ].x;
  13980. uniform._array[ i3 + 1 ] = value[ i ].y;
  13981. uniform._array[ i3 + 2 ] = value[ i ].z;
  13982. }
  13983. _gl.uniform3fv( location, uniform._array );
  13984. break;
  13985. case 'v4v':
  13986. // array of THREE.Vector4
  13987. if ( uniform._array === undefined ) {
  13988. uniform._array = new Float32Array( 4 * value.length );
  13989. }
  13990. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  13991. uniform._array[ i4 + 0 ] = value[ i ].x;
  13992. uniform._array[ i4 + 1 ] = value[ i ].y;
  13993. uniform._array[ i4 + 2 ] = value[ i ].z;
  13994. uniform._array[ i4 + 3 ] = value[ i ].w;
  13995. }
  13996. _gl.uniform4fv( location, uniform._array );
  13997. break;
  13998. case 'm3':
  13999. // single THREE.Matrix3
  14000. _gl.uniformMatrix3fv( location, false, value.elements );
  14001. break;
  14002. case 'm3v':
  14003. // array of THREE.Matrix3
  14004. if ( uniform._array === undefined ) {
  14005. uniform._array = new Float32Array( 9 * value.length );
  14006. }
  14007. for ( var i = 0, il = value.length; i < il; i ++ ) {
  14008. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  14009. }
  14010. _gl.uniformMatrix3fv( location, false, uniform._array );
  14011. break;
  14012. case 'm4':
  14013. // single THREE.Matrix4
  14014. _gl.uniformMatrix4fv( location, false, value.elements );
  14015. break;
  14016. case 'm4v':
  14017. // array of THREE.Matrix4
  14018. if ( uniform._array === undefined ) {
  14019. uniform._array = new Float32Array( 16 * value.length );
  14020. }
  14021. for ( var i = 0, il = value.length; i < il; i ++ ) {
  14022. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  14023. }
  14024. _gl.uniformMatrix4fv( location, false, uniform._array );
  14025. break;
  14026. case 't':
  14027. // single THREE.Texture (2d or cube)
  14028. texture = value;
  14029. textureUnit = getTextureUnit();
  14030. _gl.uniform1i( location, textureUnit );
  14031. if ( ! texture ) continue;
  14032. if ( texture instanceof THREE.CubeTexture ||
  14033. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  14034. // CompressedTexture can have Array in image :/
  14035. setCubeTexture( texture, textureUnit );
  14036. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  14037. setCubeTextureDynamic( texture.texture, textureUnit );
  14038. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  14039. _this.setTexture( texture.texture, textureUnit );
  14040. } else {
  14041. _this.setTexture( texture, textureUnit );
  14042. }
  14043. break;
  14044. case 'tv':
  14045. // array of THREE.Texture (2d or cube)
  14046. if ( uniform._array === undefined ) {
  14047. uniform._array = [];
  14048. }
  14049. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  14050. uniform._array[ i ] = getTextureUnit();
  14051. }
  14052. _gl.uniform1iv( location, uniform._array );
  14053. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  14054. texture = uniform.value[ i ];
  14055. textureUnit = uniform._array[ i ];
  14056. if ( ! texture ) continue;
  14057. if ( texture instanceof THREE.CubeTexture ||
  14058. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  14059. // CompressedTexture can have Array in image :/
  14060. setCubeTexture( texture, textureUnit );
  14061. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  14062. _this.setTexture( texture.texture, textureUnit );
  14063. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  14064. setCubeTextureDynamic( texture.texture, textureUnit );
  14065. } else {
  14066. _this.setTexture( texture, textureUnit );
  14067. }
  14068. }
  14069. break;
  14070. default:
  14071. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  14072. }
  14073. }
  14074. }
  14075. function setColorLinear( array, offset, color, intensity ) {
  14076. array[ offset + 0 ] = color.r * intensity;
  14077. array[ offset + 1 ] = color.g * intensity;
  14078. array[ offset + 2 ] = color.b * intensity;
  14079. }
  14080. function setupLights ( lights, camera ) {
  14081. var l, ll, light,
  14082. r = 0, g = 0, b = 0,
  14083. color, skyColor, groundColor,
  14084. intensity,
  14085. distance,
  14086. zlights = _lights,
  14087. viewMatrix = camera.matrixWorldInverse,
  14088. dirColors = zlights.directional.colors,
  14089. dirPositions = zlights.directional.positions,
  14090. pointColors = zlights.point.colors,
  14091. pointPositions = zlights.point.positions,
  14092. pointDistances = zlights.point.distances,
  14093. pointDecays = zlights.point.decays,
  14094. spotColors = zlights.spot.colors,
  14095. spotPositions = zlights.spot.positions,
  14096. spotDistances = zlights.spot.distances,
  14097. spotDirections = zlights.spot.directions,
  14098. spotAnglesCos = zlights.spot.anglesCos,
  14099. spotExponents = zlights.spot.exponents,
  14100. spotDecays = zlights.spot.decays,
  14101. hemiSkyColors = zlights.hemi.skyColors,
  14102. hemiGroundColors = zlights.hemi.groundColors,
  14103. hemiPositions = zlights.hemi.positions,
  14104. dirLength = 0,
  14105. pointLength = 0,
  14106. spotLength = 0,
  14107. hemiLength = 0,
  14108. dirCount = 0,
  14109. pointCount = 0,
  14110. spotCount = 0,
  14111. hemiCount = 0,
  14112. dirOffset = 0,
  14113. pointOffset = 0,
  14114. spotOffset = 0,
  14115. hemiOffset = 0;
  14116. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  14117. light = lights[ l ];
  14118. color = light.color;
  14119. intensity = light.intensity;
  14120. distance = light.distance;
  14121. if ( light instanceof THREE.AmbientLight ) {
  14122. if ( ! light.visible ) continue;
  14123. r += color.r;
  14124. g += color.g;
  14125. b += color.b;
  14126. } else if ( light instanceof THREE.DirectionalLight ) {
  14127. dirCount += 1;
  14128. if ( ! light.visible ) continue;
  14129. _direction.setFromMatrixPosition( light.matrixWorld );
  14130. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14131. _direction.sub( _vector3 );
  14132. _direction.transformDirection( viewMatrix );
  14133. dirOffset = dirLength * 3;
  14134. dirPositions[ dirOffset + 0 ] = _direction.x;
  14135. dirPositions[ dirOffset + 1 ] = _direction.y;
  14136. dirPositions[ dirOffset + 2 ] = _direction.z;
  14137. setColorLinear( dirColors, dirOffset, color, intensity );
  14138. dirLength += 1;
  14139. } else if ( light instanceof THREE.PointLight ) {
  14140. pointCount += 1;
  14141. if ( ! light.visible ) continue;
  14142. pointOffset = pointLength * 3;
  14143. setColorLinear( pointColors, pointOffset, color, intensity );
  14144. _vector3.setFromMatrixPosition( light.matrixWorld );
  14145. _vector3.applyMatrix4( viewMatrix );
  14146. pointPositions[ pointOffset + 0 ] = _vector3.x;
  14147. pointPositions[ pointOffset + 1 ] = _vector3.y;
  14148. pointPositions[ pointOffset + 2 ] = _vector3.z;
  14149. // distance is 0 if decay is 0, because there is no attenuation at all.
  14150. pointDistances[ pointLength ] = distance;
  14151. pointDecays[ pointLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14152. pointLength += 1;
  14153. } else if ( light instanceof THREE.SpotLight ) {
  14154. spotCount += 1;
  14155. if ( ! light.visible ) continue;
  14156. spotOffset = spotLength * 3;
  14157. setColorLinear( spotColors, spotOffset, color, intensity );
  14158. _direction.setFromMatrixPosition( light.matrixWorld );
  14159. _vector3.copy( _direction ).applyMatrix4( viewMatrix );
  14160. spotPositions[ spotOffset + 0 ] = _vector3.x;
  14161. spotPositions[ spotOffset + 1 ] = _vector3.y;
  14162. spotPositions[ spotOffset + 2 ] = _vector3.z;
  14163. spotDistances[ spotLength ] = distance;
  14164. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  14165. _direction.sub( _vector3 );
  14166. _direction.transformDirection( viewMatrix );
  14167. spotDirections[ spotOffset + 0 ] = _direction.x;
  14168. spotDirections[ spotOffset + 1 ] = _direction.y;
  14169. spotDirections[ spotOffset + 2 ] = _direction.z;
  14170. spotAnglesCos[ spotLength ] = Math.cos( light.angle );
  14171. spotExponents[ spotLength ] = light.exponent;
  14172. spotDecays[ spotLength ] = ( light.distance === 0 ) ? 0.0 : light.decay;
  14173. spotLength += 1;
  14174. } else if ( light instanceof THREE.HemisphereLight ) {
  14175. hemiCount += 1;
  14176. if ( ! light.visible ) continue;
  14177. _direction.setFromMatrixPosition( light.matrixWorld );
  14178. _direction.transformDirection( viewMatrix );
  14179. hemiOffset = hemiLength * 3;
  14180. hemiPositions[ hemiOffset + 0 ] = _direction.x;
  14181. hemiPositions[ hemiOffset + 1 ] = _direction.y;
  14182. hemiPositions[ hemiOffset + 2 ] = _direction.z;
  14183. skyColor = light.color;
  14184. groundColor = light.groundColor;
  14185. setColorLinear( hemiSkyColors, hemiOffset, skyColor, intensity );
  14186. setColorLinear( hemiGroundColors, hemiOffset, groundColor, intensity );
  14187. hemiLength += 1;
  14188. }
  14189. }
  14190. // null eventual remains from removed lights
  14191. // (this is to avoid if in shader)
  14192. for ( l = dirLength * 3, ll = Math.max( dirColors.length, dirCount * 3 ); l < ll; l ++ ) dirColors[ l ] = 0.0;
  14193. for ( l = pointLength * 3, ll = Math.max( pointColors.length, pointCount * 3 ); l < ll; l ++ ) pointColors[ l ] = 0.0;
  14194. for ( l = spotLength * 3, ll = Math.max( spotColors.length, spotCount * 3 ); l < ll; l ++ ) spotColors[ l ] = 0.0;
  14195. for ( l = hemiLength * 3, ll = Math.max( hemiSkyColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiSkyColors[ l ] = 0.0;
  14196. for ( l = hemiLength * 3, ll = Math.max( hemiGroundColors.length, hemiCount * 3 ); l < ll; l ++ ) hemiGroundColors[ l ] = 0.0;
  14197. zlights.directional.length = dirLength;
  14198. zlights.point.length = pointLength;
  14199. zlights.spot.length = spotLength;
  14200. zlights.hemi.length = hemiLength;
  14201. zlights.ambient[ 0 ] = r;
  14202. zlights.ambient[ 1 ] = g;
  14203. zlights.ambient[ 2 ] = b;
  14204. }
  14205. // GL state setting
  14206. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  14207. if ( cullFace === THREE.CullFaceNone ) {
  14208. state.disable( _gl.CULL_FACE );
  14209. } else {
  14210. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  14211. _gl.frontFace( _gl.CW );
  14212. } else {
  14213. _gl.frontFace( _gl.CCW );
  14214. }
  14215. if ( cullFace === THREE.CullFaceBack ) {
  14216. _gl.cullFace( _gl.BACK );
  14217. } else if ( cullFace === THREE.CullFaceFront ) {
  14218. _gl.cullFace( _gl.FRONT );
  14219. } else {
  14220. _gl.cullFace( _gl.FRONT_AND_BACK );
  14221. }
  14222. state.enable( _gl.CULL_FACE );
  14223. }
  14224. };
  14225. // Textures
  14226. function setTextureParameters ( textureType, texture, isImagePowerOfTwo ) {
  14227. var extension;
  14228. if ( isImagePowerOfTwo ) {
  14229. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  14230. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  14231. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  14232. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  14233. } else {
  14234. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  14235. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  14236. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  14237. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping. ( ' + texture.sourceFile + ' )' );
  14238. }
  14239. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  14240. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  14241. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  14242. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter. ( ' + texture.sourceFile + ' )' );
  14243. }
  14244. }
  14245. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  14246. if ( extension ) {
  14247. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  14248. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  14249. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  14250. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  14251. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  14252. }
  14253. }
  14254. }
  14255. function uploadTexture( textureProperties, texture, slot ) {
  14256. if ( textureProperties.__webglInit === undefined ) {
  14257. textureProperties.__webglInit = true;
  14258. texture.__webglInit = true;
  14259. texture.addEventListener( 'dispose', onTextureDispose );
  14260. textureProperties.__webglTexture = _gl.createTexture();
  14261. _infoMemory.textures ++;
  14262. }
  14263. state.activeTexture( _gl.TEXTURE0 + slot );
  14264. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14265. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14266. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  14267. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  14268. texture.image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  14269. var image = texture.image,
  14270. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  14271. glFormat = paramThreeToGL( texture.format ),
  14272. glType = paramThreeToGL( texture.type );
  14273. setTextureParameters( _gl.TEXTURE_2D, texture, isImagePowerOfTwo );
  14274. var mipmap, mipmaps = texture.mipmaps;
  14275. if ( texture instanceof THREE.DataTexture ) {
  14276. // use manually created mipmaps if available
  14277. // if there are no manual mipmaps
  14278. // set 0 level mipmap and then use GL to generate other mipmap levels
  14279. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14280. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14281. mipmap = mipmaps[ i ];
  14282. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14283. }
  14284. texture.generateMipmaps = false;
  14285. } else {
  14286. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  14287. }
  14288. } else if ( texture instanceof THREE.CompressedTexture ) {
  14289. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14290. mipmap = mipmaps[ i ];
  14291. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14292. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14293. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14294. } else {
  14295. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  14296. }
  14297. } else {
  14298. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14299. }
  14300. }
  14301. } else {
  14302. // regular Texture (image, video, canvas)
  14303. // use manually created mipmaps if available
  14304. // if there are no manual mipmaps
  14305. // set 0 level mipmap and then use GL to generate other mipmap levels
  14306. if ( mipmaps.length > 0 && isImagePowerOfTwo ) {
  14307. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  14308. mipmap = mipmaps[ i ];
  14309. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  14310. }
  14311. texture.generateMipmaps = false;
  14312. } else {
  14313. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, texture.image );
  14314. }
  14315. }
  14316. if ( texture.generateMipmaps && isImagePowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14317. textureProperties.__version = texture.version;
  14318. if ( texture.onUpdate ) texture.onUpdate( texture );
  14319. }
  14320. this.setTexture = function ( texture, slot ) {
  14321. var textureProperties = properties.get( texture );
  14322. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14323. var image = texture.image;
  14324. if ( image === undefined ) {
  14325. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  14326. return;
  14327. }
  14328. if ( image.complete === false ) {
  14329. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  14330. return;
  14331. }
  14332. uploadTexture( textureProperties, texture, slot );
  14333. return;
  14334. }
  14335. state.activeTexture( _gl.TEXTURE0 + slot );
  14336. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14337. };
  14338. function clampToMaxSize ( image, maxSize ) {
  14339. if ( image.width > maxSize || image.height > maxSize ) {
  14340. // Warning: Scaling through the canvas will only work with images that use
  14341. // premultiplied alpha.
  14342. var scale = maxSize / Math.max( image.width, image.height );
  14343. var canvas = document.createElement( 'canvas' );
  14344. canvas.width = Math.floor( image.width * scale );
  14345. canvas.height = Math.floor( image.height * scale );
  14346. var context = canvas.getContext( '2d' );
  14347. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  14348. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  14349. return canvas;
  14350. }
  14351. return image;
  14352. }
  14353. function setCubeTexture ( texture, slot ) {
  14354. var textureProperties = properties.get( texture );
  14355. if ( texture.image.length === 6 ) {
  14356. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  14357. if ( ! textureProperties.__image__webglTextureCube ) {
  14358. texture.addEventListener( 'dispose', onTextureDispose );
  14359. textureProperties.__image__webglTextureCube = _gl.createTexture();
  14360. _infoMemory.textures ++;
  14361. }
  14362. state.activeTexture( _gl.TEXTURE0 + slot );
  14363. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14364. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  14365. var isCompressed = texture instanceof THREE.CompressedTexture;
  14366. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  14367. var cubeImage = [];
  14368. for ( var i = 0; i < 6; i ++ ) {
  14369. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  14370. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  14371. } else {
  14372. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  14373. }
  14374. }
  14375. var image = cubeImage[ 0 ],
  14376. isImagePowerOfTwo = THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height ),
  14377. glFormat = paramThreeToGL( texture.format ),
  14378. glType = paramThreeToGL( texture.type );
  14379. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isImagePowerOfTwo );
  14380. for ( var i = 0; i < 6; i ++ ) {
  14381. if ( ! isCompressed ) {
  14382. if ( isDataTexture ) {
  14383. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  14384. } else {
  14385. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  14386. }
  14387. } else {
  14388. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  14389. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  14390. mipmap = mipmaps[ j ];
  14391. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  14392. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  14393. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  14394. } else {
  14395. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  14396. }
  14397. } else {
  14398. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  14399. }
  14400. }
  14401. }
  14402. }
  14403. if ( texture.generateMipmaps && isImagePowerOfTwo ) {
  14404. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14405. }
  14406. textureProperties.__version = texture.version;
  14407. if ( texture.onUpdate ) texture.onUpdate( texture );
  14408. } else {
  14409. state.activeTexture( _gl.TEXTURE0 + slot );
  14410. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  14411. }
  14412. }
  14413. }
  14414. function setCubeTextureDynamic ( texture, slot ) {
  14415. state.activeTexture( _gl.TEXTURE0 + slot );
  14416. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  14417. }
  14418. // Render targets
  14419. function setupFrameBuffer ( framebuffer, renderTarget, textureTarget ) {
  14420. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14421. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  14422. }
  14423. function setupRenderBuffer ( renderbuffer, renderTarget ) {
  14424. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  14425. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14426. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  14427. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14428. /* For some reason this is not working. Defaulting to RGBA4.
  14429. } else if ( ! renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14430. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.STENCIL_INDEX8, renderTarget.width, renderTarget.height );
  14431. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14432. */
  14433. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14434. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  14435. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  14436. } else {
  14437. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  14438. }
  14439. }
  14440. this.setRenderTarget = function ( renderTarget ) {
  14441. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  14442. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  14443. var renderTargetProperties = properties.get( renderTarget );
  14444. var textureProperties = properties.get( renderTarget.texture );
  14445. if ( renderTarget.depthBuffer === undefined ) renderTarget.depthBuffer = true;
  14446. if ( renderTarget.stencilBuffer === undefined ) renderTarget.stencilBuffer = true;
  14447. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  14448. textureProperties.__webglTexture = _gl.createTexture();
  14449. _infoMemory.textures ++;
  14450. // Setup texture, create render and frame buffers
  14451. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height ),
  14452. glFormat = paramThreeToGL( renderTarget.texture.format ),
  14453. glType = paramThreeToGL( renderTarget.texture.type );
  14454. if ( isCube ) {
  14455. renderTargetProperties.__webglFramebuffer = [];
  14456. renderTargetProperties.__webglRenderbuffer = [];
  14457. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  14458. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  14459. for ( var i = 0; i < 6; i ++ ) {
  14460. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  14461. renderTargetProperties.__webglRenderbuffer[ i ] = _gl.createRenderbuffer();
  14462. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14463. setupFrameBuffer( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  14464. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer[ i ], renderTarget );
  14465. }
  14466. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  14467. } else {
  14468. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  14469. if ( renderTarget.shareDepthFrom ) {
  14470. renderTargetProperties.__webglRenderbuffer = renderTarget.shareDepthFrom.__webglRenderbuffer;
  14471. } else {
  14472. renderTargetProperties.__webglRenderbuffer = _gl.createRenderbuffer();
  14473. }
  14474. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  14475. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  14476. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  14477. setupFrameBuffer( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.TEXTURE_2D );
  14478. if ( renderTarget.shareDepthFrom ) {
  14479. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  14480. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14481. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  14482. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderTargetProperties.__webglRenderbuffer );
  14483. }
  14484. } else {
  14485. setupRenderBuffer( renderTargetProperties.__webglRenderbuffer, renderTarget );
  14486. }
  14487. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  14488. }
  14489. // Release everything
  14490. if ( isCube ) {
  14491. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  14492. } else {
  14493. state.bindTexture( _gl.TEXTURE_2D, null );
  14494. }
  14495. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  14496. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  14497. }
  14498. var framebuffer, width, height, vx, vy;
  14499. if ( renderTarget ) {
  14500. var renderTargetProperties = properties.get( renderTarget );
  14501. if ( isCube ) {
  14502. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  14503. } else {
  14504. framebuffer = renderTargetProperties.__webglFramebuffer;
  14505. }
  14506. width = renderTarget.width;
  14507. height = renderTarget.height;
  14508. vx = 0;
  14509. vy = 0;
  14510. } else {
  14511. framebuffer = null;
  14512. width = _viewportWidth;
  14513. height = _viewportHeight;
  14514. vx = _viewportX;
  14515. vy = _viewportY;
  14516. }
  14517. if ( framebuffer !== _currentFramebuffer ) {
  14518. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14519. _gl.viewport( vx, vy, width, height );
  14520. _currentFramebuffer = framebuffer;
  14521. }
  14522. if ( isCube ) {
  14523. var textureProperties = properties.get( renderTarget.texture );
  14524. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, 0 );
  14525. }
  14526. _currentWidth = width;
  14527. _currentHeight = height;
  14528. };
  14529. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  14530. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  14531. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  14532. return;
  14533. }
  14534. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  14535. if ( framebuffer ) {
  14536. var restore = false;
  14537. if ( framebuffer !== _currentFramebuffer ) {
  14538. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  14539. restore = true;
  14540. }
  14541. try {
  14542. var texture = renderTarget.texture;
  14543. if ( texture.format !== THREE.RGBAFormat
  14544. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  14545. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  14546. return;
  14547. }
  14548. if ( texture.type !== THREE.UnsignedByteType
  14549. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  14550. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  14551. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  14552. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  14553. return;
  14554. }
  14555. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  14556. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  14557. } else {
  14558. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  14559. }
  14560. } finally {
  14561. if ( restore ) {
  14562. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  14563. }
  14564. }
  14565. }
  14566. };
  14567. function updateRenderTargetMipmap( renderTarget ) {
  14568. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  14569. var texture = properties.get( renderTarget.texture ).__webglTexture;
  14570. state.bindTexture( target, texture );
  14571. _gl.generateMipmap( target );
  14572. state.bindTexture( target, null );
  14573. }
  14574. // Fallback filters for non-power-of-2 textures
  14575. function filterFallback ( f ) {
  14576. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  14577. return _gl.NEAREST;
  14578. }
  14579. return _gl.LINEAR;
  14580. }
  14581. // Map three.js constants to WebGL constants
  14582. function paramThreeToGL ( p ) {
  14583. var extension;
  14584. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  14585. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  14586. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  14587. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  14588. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  14589. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  14590. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  14591. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  14592. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  14593. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  14594. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  14595. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  14596. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  14597. if ( p === THREE.ByteType ) return _gl.BYTE;
  14598. if ( p === THREE.ShortType ) return _gl.SHORT;
  14599. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  14600. if ( p === THREE.IntType ) return _gl.INT;
  14601. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  14602. if ( p === THREE.FloatType ) return _gl.FLOAT;
  14603. extension = extensions.get( 'OES_texture_half_float' );
  14604. if ( extension !== null ) {
  14605. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  14606. }
  14607. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  14608. if ( p === THREE.RGBFormat ) return _gl.RGB;
  14609. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  14610. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  14611. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  14612. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  14613. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  14614. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  14615. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  14616. if ( p === THREE.OneFactor ) return _gl.ONE;
  14617. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  14618. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  14619. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  14620. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  14621. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  14622. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  14623. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  14624. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  14625. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  14626. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14627. if ( extension !== null ) {
  14628. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  14629. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  14630. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  14631. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  14632. }
  14633. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14634. if ( extension !== null ) {
  14635. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  14636. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  14637. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  14638. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  14639. }
  14640. extension = extensions.get( 'EXT_blend_minmax' );
  14641. if ( extension !== null ) {
  14642. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  14643. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  14644. }
  14645. return 0;
  14646. }
  14647. // DEPRECATED
  14648. this.supportsFloatTextures = function () {
  14649. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  14650. return extensions.get( 'OES_texture_float' );
  14651. };
  14652. this.supportsHalfFloatTextures = function () {
  14653. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  14654. return extensions.get( 'OES_texture_half_float' );
  14655. };
  14656. this.supportsStandardDerivatives = function () {
  14657. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  14658. return extensions.get( 'OES_standard_derivatives' );
  14659. };
  14660. this.supportsCompressedTextureS3TC = function () {
  14661. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  14662. return extensions.get( 'WEBGL_compressed_texture_s3tc' );
  14663. };
  14664. this.supportsCompressedTexturePVRTC = function () {
  14665. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  14666. return extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  14667. };
  14668. this.supportsBlendMinMax = function () {
  14669. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  14670. return extensions.get( 'EXT_blend_minmax' );
  14671. };
  14672. this.supportsVertexTextures = function () {
  14673. return capabilities.vertexTextures;
  14674. };
  14675. this.supportsInstancedArrays = function () {
  14676. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  14677. return extensions.get( 'ANGLE_instanced_arrays' );
  14678. };
  14679. //
  14680. this.initMaterial = function () {
  14681. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  14682. };
  14683. this.addPrePlugin = function () {
  14684. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  14685. };
  14686. this.addPostPlugin = function () {
  14687. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  14688. };
  14689. this.updateShadowMap = function () {
  14690. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  14691. };
  14692. Object.defineProperties( this, {
  14693. shadowMapEnabled: {
  14694. get: function () {
  14695. return shadowMap.enabled;
  14696. },
  14697. set: function ( value ) {
  14698. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  14699. shadowMap.enabled = value;
  14700. }
  14701. },
  14702. shadowMapType: {
  14703. get: function () {
  14704. return shadowMap.type;
  14705. },
  14706. set: function ( value ) {
  14707. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  14708. shadowMap.type = value;
  14709. }
  14710. },
  14711. shadowMapCullFace: {
  14712. get: function () {
  14713. return shadowMap.cullFace;
  14714. },
  14715. set: function ( value ) {
  14716. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  14717. shadowMap.cullFace = value;
  14718. }
  14719. },
  14720. shadowMapDebug: {
  14721. get: function () {
  14722. return shadowMap.debug;
  14723. },
  14724. set: function ( value ) {
  14725. console.warn( 'THREE.WebGLRenderer: .shadowMapDebug is now .shadowMap.debug.' );
  14726. shadowMap.debug = value;
  14727. }
  14728. }
  14729. } );
  14730. };
  14731. // File:src/renderers/WebGLRenderTarget.js
  14732. /**
  14733. * @author szimek / https://github.com/szimek/
  14734. * @author alteredq / http://alteredqualia.com/
  14735. */
  14736. THREE.WebGLRenderTarget = function ( width, height, options ) {
  14737. this.uuid = THREE.Math.generateUUID();
  14738. this.width = width;
  14739. this.height = height;
  14740. options = options || {};
  14741. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  14742. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  14743. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  14744. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  14745. this.shareDepthFrom = options.shareDepthFrom !== undefined ? options.shareDepthFrom : null;
  14746. };
  14747. THREE.WebGLRenderTarget.prototype = {
  14748. constructor: THREE.WebGLRenderTarget,
  14749. get wrapS() {
  14750. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  14751. return this.texture.wrapS;
  14752. },
  14753. set wrapS( value ) {
  14754. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  14755. this.texture.wrapS = value;
  14756. },
  14757. get wrapT() {
  14758. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  14759. return this.texture.wrapT;
  14760. },
  14761. set wrapT( value ) {
  14762. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  14763. this.texture.wrapT = value;
  14764. },
  14765. get magFilter() {
  14766. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  14767. return this.texture.magFilter;
  14768. },
  14769. set magFilter( value ) {
  14770. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  14771. this.texture.magFilter = value;
  14772. },
  14773. get minFilter() {
  14774. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  14775. return this.texture.minFilter;
  14776. },
  14777. set minFilter( value ) {
  14778. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  14779. this.texture.minFilter = value;
  14780. },
  14781. get anisotropy() {
  14782. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  14783. return this.texture.anisotropy;
  14784. },
  14785. set anisotropy( value ) {
  14786. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  14787. this.texture.anisotropy = value;
  14788. },
  14789. get offset() {
  14790. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  14791. return this.texture.offset;
  14792. },
  14793. set offset( value ) {
  14794. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  14795. this.texture.offset = value;
  14796. },
  14797. get repeat() {
  14798. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  14799. return this.texture.repeat;
  14800. },
  14801. set repeat( value ) {
  14802. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  14803. this.texture.repeat = value;
  14804. },
  14805. get format() {
  14806. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  14807. return this.texture.format;
  14808. },
  14809. set format( value ) {
  14810. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  14811. this.texture.format = value;
  14812. },
  14813. get type() {
  14814. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  14815. return this.texture.type;
  14816. },
  14817. set type( value ) {
  14818. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  14819. this.texture.type = value;
  14820. },
  14821. get generateMipmaps() {
  14822. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  14823. return this.texture.generateMipmaps;
  14824. },
  14825. set generateMipmaps( value ) {
  14826. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  14827. this.texture.generateMipmaps = value;
  14828. },
  14829. //
  14830. setSize: function ( width, height ) {
  14831. if ( this.width !== width || this.height !== height ) {
  14832. this.width = width;
  14833. this.height = height;
  14834. this.dispose();
  14835. }
  14836. },
  14837. clone: function () {
  14838. return new this.constructor().copy( this );
  14839. },
  14840. copy: function ( source ) {
  14841. this.width = source.width;
  14842. this.height = source.height;
  14843. this.texture = source.texture.clone();
  14844. this.depthBuffer = source.depthBuffer;
  14845. this.stencilBuffer = source.stencilBuffer;
  14846. this.shareDepthFrom = source.shareDepthFrom;
  14847. return this;
  14848. },
  14849. dispose: function () {
  14850. this.dispatchEvent( { type: 'dispose' } );
  14851. }
  14852. };
  14853. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  14854. // File:src/renderers/WebGLRenderTargetCube.js
  14855. /**
  14856. * @author alteredq / http://alteredqualia.com
  14857. */
  14858. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  14859. THREE.WebGLRenderTarget.call( this, width, height, options );
  14860. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  14861. };
  14862. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  14863. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  14864. // File:src/renderers/webgl/WebGLBufferRenderer.js
  14865. /**
  14866. * @author mrdoob / http://mrdoob.com/
  14867. */
  14868. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14869. var mode;
  14870. function setMode( value ) {
  14871. mode = value;
  14872. }
  14873. function render( start, count ) {
  14874. _gl.drawArrays( mode, start, count );
  14875. _infoRender.calls ++;
  14876. _infoRender.vertices += count;
  14877. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14878. }
  14879. function renderInstances( geometry ) {
  14880. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14881. if ( extension === null ) {
  14882. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14883. return;
  14884. }
  14885. var position = geometry.attributes.position;
  14886. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  14887. extension.drawArraysInstancedANGLE( mode, 0, position.data.count, geometry.maxInstancedCount );
  14888. } else {
  14889. extension.drawArraysInstancedANGLE( mode, 0, position.count, geometry.maxInstancedCount );
  14890. }
  14891. }
  14892. this.setMode = setMode;
  14893. this.render = render;
  14894. this.renderInstances = renderInstances;
  14895. };
  14896. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  14897. /**
  14898. * @author mrdoob / http://mrdoob.com/
  14899. */
  14900. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  14901. var mode;
  14902. function setMode( value ) {
  14903. mode = value;
  14904. }
  14905. var type, size;
  14906. function setIndex( index ) {
  14907. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  14908. type = _gl.UNSIGNED_INT;
  14909. size = 4;
  14910. } else {
  14911. type = _gl.UNSIGNED_SHORT;
  14912. size = 2;
  14913. }
  14914. }
  14915. function render( start, count ) {
  14916. _gl.drawElements( mode, count, type, start * size );
  14917. _infoRender.calls ++;
  14918. _infoRender.vertices += count;
  14919. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  14920. }
  14921. function renderInstances( geometry ) {
  14922. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  14923. if ( extension === null ) {
  14924. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  14925. return;
  14926. }
  14927. var index = geometry.index;
  14928. extension.drawElementsInstancedANGLE( mode, index.array.length, type, 0, geometry.maxInstancedCount );
  14929. }
  14930. this.setMode = setMode;
  14931. this.setIndex = setIndex;
  14932. this.render = render;
  14933. this.renderInstances = renderInstances;
  14934. };
  14935. // File:src/renderers/webgl/WebGLExtensions.js
  14936. /**
  14937. * @author mrdoob / http://mrdoob.com/
  14938. */
  14939. THREE.WebGLExtensions = function ( gl ) {
  14940. var extensions = {};
  14941. this.get = function ( name ) {
  14942. if ( extensions[ name ] !== undefined ) {
  14943. return extensions[ name ];
  14944. }
  14945. var extension;
  14946. switch ( name ) {
  14947. case 'EXT_texture_filter_anisotropic':
  14948. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  14949. break;
  14950. case 'WEBGL_compressed_texture_s3tc':
  14951. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  14952. break;
  14953. case 'WEBGL_compressed_texture_pvrtc':
  14954. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  14955. break;
  14956. default:
  14957. extension = gl.getExtension( name );
  14958. }
  14959. if ( extension === null ) {
  14960. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  14961. }
  14962. extensions[ name ] = extension;
  14963. return extension;
  14964. };
  14965. };
  14966. // File:src/renderers/webgl/WebGLCapabilities.js
  14967. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  14968. function getMaxPrecision( precision ) {
  14969. if ( precision === 'highp' ) {
  14970. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  14971. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  14972. return 'highp';
  14973. }
  14974. precision = 'mediump';
  14975. }
  14976. if ( precision === 'mediump' ) {
  14977. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  14978. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  14979. return 'mediump';
  14980. }
  14981. }
  14982. return 'lowp';
  14983. }
  14984. this.getMaxPrecision = getMaxPrecision;
  14985. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  14986. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  14987. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  14988. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  14989. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  14990. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  14991. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  14992. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  14993. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  14994. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  14995. this.vertexTextures = this.maxVertexTextures > 0;
  14996. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  14997. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  14998. var _maxPrecision = getMaxPrecision( this.precision );
  14999. if ( _maxPrecision !== this.precision ) {
  15000. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  15001. this.precision = _maxPrecision;
  15002. }
  15003. if ( this.logarithmicDepthBuffer ) {
  15004. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  15005. }
  15006. };
  15007. // File:src/renderers/webgl/WebGLGeometries.js
  15008. /**
  15009. * @author mrdoob / http://mrdoob.com/
  15010. */
  15011. THREE.WebGLGeometries = function ( gl, properties, info ) {
  15012. var geometries = {};
  15013. function get( object ) {
  15014. var geometry = object.geometry;
  15015. if ( geometries[ geometry.id ] !== undefined ) {
  15016. return geometries[ geometry.id ];
  15017. }
  15018. geometry.addEventListener( 'dispose', onGeometryDispose );
  15019. var buffergeometry;
  15020. if ( geometry instanceof THREE.BufferGeometry ) {
  15021. buffergeometry = geometry;
  15022. } else if ( geometry instanceof THREE.Geometry ) {
  15023. if ( geometry._bufferGeometry === undefined ) {
  15024. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  15025. }
  15026. buffergeometry = geometry._bufferGeometry;
  15027. }
  15028. geometries[ geometry.id ] = buffergeometry;
  15029. info.memory.geometries ++;
  15030. return buffergeometry;
  15031. }
  15032. function onGeometryDispose( event ) {
  15033. var geometry = event.target;
  15034. var buffergeometry = geometries[ geometry.id ];
  15035. deleteAttributes( buffergeometry.attributes );
  15036. geometry.removeEventListener( 'dispose', onGeometryDispose );
  15037. delete geometries[ geometry.id ];
  15038. var property = properties.get( geometry );
  15039. if ( property.wireframe ) deleteAttribute( property.wireframe );
  15040. info.memory.geometries --;
  15041. }
  15042. function getAttributeBuffer( attribute ) {
  15043. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15044. return properties.get( attribute.data ).__webglBuffer;
  15045. }
  15046. return properties.get( attribute ).__webglBuffer;
  15047. }
  15048. function deleteAttribute( attribute ) {
  15049. var buffer = getAttributeBuffer( attribute );
  15050. if ( buffer !== undefined ) {
  15051. gl.deleteBuffer( buffer );
  15052. removeAttributeBuffer( attribute );
  15053. }
  15054. }
  15055. function deleteAttributes( attributes ) {
  15056. for ( var name in attributes ) {
  15057. deleteAttribute( attributes[ name ] );
  15058. }
  15059. }
  15060. function removeAttributeBuffer( attribute ) {
  15061. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15062. properties.delete( attribute.data );
  15063. } else {
  15064. properties.delete( attribute );
  15065. }
  15066. }
  15067. this.get = get;
  15068. };
  15069. // File:src/renderers/webgl/WebGLObjects.js
  15070. /**
  15071. * @author mrdoob / http://mrdoob.com/
  15072. */
  15073. THREE.WebGLObjects = function ( gl, properties, info ) {
  15074. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  15075. //
  15076. function update( object ) {
  15077. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  15078. var geometry = geometries.get( object );
  15079. if ( object.geometry instanceof THREE.Geometry ) {
  15080. geometry.updateFromObject( object );
  15081. }
  15082. var index = geometry.index;
  15083. var attributes = geometry.attributes;
  15084. if ( index !== null ) {
  15085. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  15086. }
  15087. for ( var name in attributes ) {
  15088. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  15089. }
  15090. // morph targets
  15091. var morphAttributes = geometry.morphAttributes;
  15092. for ( var name in morphAttributes ) {
  15093. var array = morphAttributes[ name ];
  15094. for ( var i = 0, l = array.length; i < l; i ++ ) {
  15095. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  15096. }
  15097. }
  15098. return geometry;
  15099. }
  15100. function updateAttribute( attribute, bufferType ) {
  15101. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  15102. var attributeProperties = properties.get( data );
  15103. if ( attributeProperties.__webglBuffer === undefined ) {
  15104. createBuffer( attributeProperties, data, bufferType );
  15105. } else if ( attributeProperties.version !== data.version ) {
  15106. updateBuffer( attributeProperties, data, bufferType );
  15107. }
  15108. }
  15109. function createBuffer( attributeProperties, data, bufferType ) {
  15110. attributeProperties.__webglBuffer = gl.createBuffer();
  15111. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15112. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  15113. gl.bufferData( bufferType, data.array, usage );
  15114. attributeProperties.version = data.version;
  15115. }
  15116. function updateBuffer( attributeProperties, data, bufferType ) {
  15117. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  15118. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  15119. // Not using update ranges
  15120. gl.bufferSubData( bufferType, 0, data.array );
  15121. } else if ( data.updateRange.count === 0 ) {
  15122. console.error( 'THREE.WebGLObjects.updateBuffer: dynamic THREE.BufferAttribute marked as needsUpdate but updateRange.count is 0, ensure you are using set methods or updating manually.' );
  15123. } else {
  15124. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  15125. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  15126. data.updateRange.count = 0; // reset range
  15127. }
  15128. attributeProperties.version = data.version;
  15129. }
  15130. function getAttributeBuffer( attribute ) {
  15131. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  15132. return properties.get( attribute.data ).__webglBuffer;
  15133. }
  15134. return properties.get( attribute ).__webglBuffer;
  15135. }
  15136. function getWireframeAttribute( geometry ) {
  15137. var property = properties.get( geometry );
  15138. if ( property.wireframe !== undefined ) {
  15139. return property.wireframe;
  15140. }
  15141. var indices = [];
  15142. var index = geometry.index;
  15143. var attributes = geometry.attributes;
  15144. var position = attributes.position;
  15145. // console.time( 'wireframe' );
  15146. if ( index !== null ) {
  15147. var edges = {};
  15148. var array = index.array;
  15149. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  15150. var a = array[ i + 0 ];
  15151. var b = array[ i + 1 ];
  15152. var c = array[ i + 2 ];
  15153. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  15154. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  15155. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  15156. }
  15157. } else {
  15158. var array = attributes.position.array;
  15159. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  15160. var a = i + 0;
  15161. var b = i + 1;
  15162. var c = i + 2;
  15163. indices.push( a, b, b, c, c, a );
  15164. }
  15165. }
  15166. // console.timeEnd( 'wireframe' );
  15167. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  15168. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  15169. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  15170. property.wireframe = attribute;
  15171. return attribute;
  15172. }
  15173. function checkEdge( edges, a, b ) {
  15174. if ( a > b ) {
  15175. var tmp = a;
  15176. a = b;
  15177. b = tmp;
  15178. }
  15179. var list = edges[ a ];
  15180. if ( list === undefined ) {
  15181. edges[ a ] = [ b ];
  15182. return true;
  15183. } else if ( list.indexOf( b ) === -1 ) {
  15184. list.push( b );
  15185. return true;
  15186. }
  15187. return false;
  15188. }
  15189. this.getAttributeBuffer = getAttributeBuffer;
  15190. this.getWireframeAttribute = getWireframeAttribute;
  15191. this.update = update;
  15192. };
  15193. // File:src/renderers/webgl/WebGLProgram.js
  15194. THREE.WebGLProgram = ( function () {
  15195. var programIdCount = 0;
  15196. function generateDefines( defines ) {
  15197. var chunks = [];
  15198. for ( var name in defines ) {
  15199. var value = defines[ name ];
  15200. if ( value === false ) continue;
  15201. chunks.push( '#define ' + name + ' ' + value );
  15202. }
  15203. return chunks.join( '\n' );
  15204. }
  15205. function fetchUniformLocations( gl, program, identifiers ) {
  15206. var uniforms = {};
  15207. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  15208. for ( var i = 0; i < n; i ++ ) {
  15209. var info = gl.getActiveUniform( program, i );
  15210. var name = info.name;
  15211. var location = gl.getUniformLocation( program, name );
  15212. // console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  15213. var suffixPos = name.lastIndexOf( '[0]' );
  15214. if ( suffixPos !== - 1 && suffixPos === name.length - 3 ) {
  15215. uniforms[ name.substr( 0, suffixPos ) ] = location;
  15216. }
  15217. uniforms[ name ] = location;
  15218. }
  15219. return uniforms;
  15220. }
  15221. function fetchAttributeLocations( gl, program, identifiers ) {
  15222. var attributes = {};
  15223. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  15224. for ( var i = 0; i < n; i ++ ) {
  15225. var info = gl.getActiveAttrib( program, i );
  15226. var name = info.name;
  15227. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  15228. attributes[ name ] = gl.getAttribLocation( program, name );
  15229. }
  15230. return attributes;
  15231. }
  15232. function filterEmptyLine( string ) {
  15233. return string !== '';
  15234. }
  15235. return function WebGLProgram( renderer, code, material, parameters ) {
  15236. var gl = renderer.context;
  15237. var defines = material.defines;
  15238. var vertexShader = material.__webglShader.vertexShader;
  15239. var fragmentShader = material.__webglShader.fragmentShader;
  15240. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  15241. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  15242. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  15243. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  15244. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  15245. }
  15246. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15247. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  15248. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15249. if ( parameters.envMap ) {
  15250. switch ( material.envMap.mapping ) {
  15251. case THREE.CubeReflectionMapping:
  15252. case THREE.CubeRefractionMapping:
  15253. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  15254. break;
  15255. case THREE.EquirectangularReflectionMapping:
  15256. case THREE.EquirectangularRefractionMapping:
  15257. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  15258. break;
  15259. case THREE.SphericalReflectionMapping:
  15260. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  15261. break;
  15262. }
  15263. switch ( material.envMap.mapping ) {
  15264. case THREE.CubeRefractionMapping:
  15265. case THREE.EquirectangularRefractionMapping:
  15266. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  15267. break;
  15268. }
  15269. switch ( material.combine ) {
  15270. case THREE.MultiplyOperation:
  15271. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  15272. break;
  15273. case THREE.MixOperation:
  15274. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  15275. break;
  15276. case THREE.AddOperation:
  15277. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  15278. break;
  15279. }
  15280. }
  15281. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  15282. // console.log( 'building new program ' );
  15283. //
  15284. var customDefines = generateDefines( defines );
  15285. //
  15286. var program = gl.createProgram();
  15287. var prefixVertex, prefixFragment;
  15288. if ( material instanceof THREE.RawShaderMaterial ) {
  15289. prefixVertex = '';
  15290. prefixFragment = '';
  15291. } else {
  15292. prefixVertex = [
  15293. 'precision ' + parameters.precision + ' float;',
  15294. 'precision ' + parameters.precision + ' int;',
  15295. '#define SHADER_NAME ' + material.__webglShader.name,
  15296. customDefines,
  15297. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  15298. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15299. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15300. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15301. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15302. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15303. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15304. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15305. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15306. '#define MAX_BONES ' + parameters.maxBones,
  15307. parameters.map ? '#define USE_MAP' : '',
  15308. parameters.envMap ? '#define USE_ENVMAP' : '',
  15309. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15310. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15311. parameters.aoMap ? '#define USE_AOMAP' : '',
  15312. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15313. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15314. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15315. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  15316. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15317. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15318. parameters.vertexColors ? '#define USE_COLOR' : '',
  15319. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15320. parameters.skinning ? '#define USE_SKINNING' : '',
  15321. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  15322. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  15323. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  15324. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15325. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15326. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15327. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15328. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15329. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15330. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  15331. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15332. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15333. 'uniform mat4 modelMatrix;',
  15334. 'uniform mat4 modelViewMatrix;',
  15335. 'uniform mat4 projectionMatrix;',
  15336. 'uniform mat4 viewMatrix;',
  15337. 'uniform mat3 normalMatrix;',
  15338. 'uniform vec3 cameraPosition;',
  15339. 'attribute vec3 position;',
  15340. 'attribute vec3 normal;',
  15341. 'attribute vec2 uv;',
  15342. '#ifdef USE_COLOR',
  15343. ' attribute vec3 color;',
  15344. '#endif',
  15345. '#ifdef USE_MORPHTARGETS',
  15346. ' attribute vec3 morphTarget0;',
  15347. ' attribute vec3 morphTarget1;',
  15348. ' attribute vec3 morphTarget2;',
  15349. ' attribute vec3 morphTarget3;',
  15350. ' #ifdef USE_MORPHNORMALS',
  15351. ' attribute vec3 morphNormal0;',
  15352. ' attribute vec3 morphNormal1;',
  15353. ' attribute vec3 morphNormal2;',
  15354. ' attribute vec3 morphNormal3;',
  15355. ' #else',
  15356. ' attribute vec3 morphTarget4;',
  15357. ' attribute vec3 morphTarget5;',
  15358. ' attribute vec3 morphTarget6;',
  15359. ' attribute vec3 morphTarget7;',
  15360. ' #endif',
  15361. '#endif',
  15362. '#ifdef USE_SKINNING',
  15363. ' attribute vec4 skinIndex;',
  15364. ' attribute vec4 skinWeight;',
  15365. '#endif',
  15366. '\n'
  15367. ].filter( filterEmptyLine ).join( '\n' );
  15368. prefixFragment = [
  15369. parameters.bumpMap || parameters.normalMap || parameters.flatShading || material.derivatives ? '#extension GL_OES_standard_derivatives : enable' : '',
  15370. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  15371. 'precision ' + parameters.precision + ' float;',
  15372. 'precision ' + parameters.precision + ' int;',
  15373. '#define SHADER_NAME ' + material.__webglShader.name,
  15374. customDefines,
  15375. '#define MAX_DIR_LIGHTS ' + parameters.maxDirLights,
  15376. '#define MAX_POINT_LIGHTS ' + parameters.maxPointLights,
  15377. '#define MAX_SPOT_LIGHTS ' + parameters.maxSpotLights,
  15378. '#define MAX_HEMI_LIGHTS ' + parameters.maxHemiLights,
  15379. '#define MAX_SHADOWS ' + parameters.maxShadows,
  15380. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  15381. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  15382. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  15383. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  15384. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  15385. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  15386. parameters.map ? '#define USE_MAP' : '',
  15387. parameters.envMap ? '#define USE_ENVMAP' : '',
  15388. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  15389. parameters.envMap ? '#define ' + envMapModeDefine : '',
  15390. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  15391. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  15392. parameters.aoMap ? '#define USE_AOMAP' : '',
  15393. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  15394. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  15395. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  15396. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  15397. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  15398. parameters.vertexColors ? '#define USE_COLOR' : '',
  15399. parameters.flatShading ? '#define FLAT_SHADED' : '',
  15400. parameters.metal ? '#define METAL' : '',
  15401. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  15402. parameters.flipSided ? '#define FLIP_SIDED' : '',
  15403. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  15404. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  15405. parameters.shadowMapDebug ? '#define SHADOWMAP_DEBUG' : '',
  15406. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  15407. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  15408. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  15409. 'uniform mat4 viewMatrix;',
  15410. 'uniform vec3 cameraPosition;',
  15411. '\n'
  15412. ].filter( filterEmptyLine ).join( '\n' );
  15413. }
  15414. var vertexGlsl = prefixVertex + vertexShader;
  15415. var fragmentGlsl = prefixFragment + fragmentShader;
  15416. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  15417. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  15418. gl.attachShader( program, glVertexShader );
  15419. gl.attachShader( program, glFragmentShader );
  15420. // Force a particular attribute to index 0.
  15421. if ( material.index0AttributeName !== undefined ) {
  15422. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  15423. } else if ( parameters.morphTargets === true ) {
  15424. // programs with morphTargets displace position out of attribute 0
  15425. gl.bindAttribLocation( program, 0, 'position' );
  15426. }
  15427. gl.linkProgram( program );
  15428. var programLog = gl.getProgramInfoLog( program );
  15429. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  15430. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  15431. var runnable = true;
  15432. var haveDiagnostics = true;
  15433. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  15434. runnable = false;
  15435. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  15436. } else if ( programLog !== '' ) {
  15437. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  15438. } else if ( vertexLog === '' || fragmentLog === '' ) {
  15439. haveDiagnostics = false;
  15440. }
  15441. if ( haveDiagnostics ) {
  15442. this.diagnostics = {
  15443. runnable: runnable,
  15444. material: material,
  15445. programLog: programLog,
  15446. vertexShader: {
  15447. log: vertexLog,
  15448. prefix: prefixVertex
  15449. },
  15450. fragmentShader: {
  15451. log: fragmentLog,
  15452. prefix: prefixFragment
  15453. }
  15454. };
  15455. }
  15456. // clean up
  15457. gl.deleteShader( glVertexShader );
  15458. gl.deleteShader( glFragmentShader );
  15459. // set up caching for uniform locations
  15460. var cachedUniforms;
  15461. this.getUniforms = function() {
  15462. if ( cachedUniforms === undefined ) {
  15463. cachedUniforms = fetchUniformLocations( gl, program );
  15464. }
  15465. return cachedUniforms;
  15466. };
  15467. // set up caching for attribute locations
  15468. var cachedAttributes;
  15469. this.getAttributes = function() {
  15470. if ( cachedAttributes === undefined ) {
  15471. cachedAttributes = fetchAttributeLocations( gl, program );
  15472. }
  15473. return cachedAttributes;
  15474. };
  15475. // free resource
  15476. this.destroy = function() {
  15477. gl.deleteProgram( program );
  15478. this.program = undefined;
  15479. };
  15480. // DEPRECATED
  15481. Object.defineProperties( this, {
  15482. uniforms: {
  15483. get: function() {
  15484. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  15485. return this.getUniforms();
  15486. }
  15487. },
  15488. attributes: {
  15489. get: function() {
  15490. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  15491. return this.getAttributes();
  15492. }
  15493. }
  15494. } );
  15495. //
  15496. this.id = programIdCount ++;
  15497. this.code = code;
  15498. this.usedTimes = 1;
  15499. this.program = program;
  15500. this.vertexShader = glVertexShader;
  15501. this.fragmentShader = glFragmentShader;
  15502. return this;
  15503. };
  15504. } )();
  15505. // File:src/renderers/webgl/WebGLPrograms.js
  15506. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  15507. var programs = [];
  15508. var shaderIDs = {
  15509. MeshDepthMaterial: 'depth',
  15510. MeshNormalMaterial: 'normal',
  15511. MeshBasicMaterial: 'basic',
  15512. MeshLambertMaterial: 'lambert',
  15513. MeshPhongMaterial: 'phong',
  15514. LineBasicMaterial: 'basic',
  15515. LineDashedMaterial: 'dashed',
  15516. PointsMaterial: 'points'
  15517. };
  15518. var parameterNames = [
  15519. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  15520. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "displacementMap", "specularMap",
  15521. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  15522. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  15523. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  15524. "maxMorphTargets", "maxMorphNormals", "maxDirLights", "maxPointLights",
  15525. "maxSpotLights", "maxHemiLights", "maxShadows", "shadowMapEnabled", "pointLightShadows",
  15526. "shadowMapType", "shadowMapDebug", "alphaTest", "metal", "doubleSided",
  15527. "flipSided"
  15528. ];
  15529. function allocateBones ( object ) {
  15530. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  15531. return 1024;
  15532. } else {
  15533. // default for when object is not specified
  15534. // ( for example when prebuilding shader to be used with multiple objects )
  15535. //
  15536. // - leave some extra space for other uniforms
  15537. // - limit here is ANGLE's 254 max uniform vectors
  15538. // (up to 54 should be safe)
  15539. var nVertexUniforms = capabilities.maxVertexUniforms;
  15540. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  15541. var maxBones = nVertexMatrices;
  15542. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  15543. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  15544. if ( maxBones < object.skeleton.bones.length ) {
  15545. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  15546. }
  15547. }
  15548. return maxBones;
  15549. }
  15550. }
  15551. function allocateLights( lights ) {
  15552. var dirLights = 0;
  15553. var pointLights = 0;
  15554. var spotLights = 0;
  15555. var hemiLights = 0;
  15556. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15557. var light = lights[ l ];
  15558. if ( light.visible === false ) continue;
  15559. if ( light instanceof THREE.DirectionalLight ) dirLights ++;
  15560. if ( light instanceof THREE.PointLight ) pointLights ++;
  15561. if ( light instanceof THREE.SpotLight ) spotLights ++;
  15562. if ( light instanceof THREE.HemisphereLight ) hemiLights ++;
  15563. }
  15564. return { 'directional': dirLights, 'point': pointLights, 'spot': spotLights, 'hemi': hemiLights };
  15565. }
  15566. function allocateShadows( lights ) {
  15567. var maxShadows = 0;
  15568. var pointLightShadows = 0;
  15569. for ( var l = 0, ll = lights.length; l < ll; l ++ ) {
  15570. var light = lights[ l ];
  15571. if ( ! light.castShadow ) continue;
  15572. if ( light instanceof THREE.SpotLight || light instanceof THREE.DirectionalLight ) maxShadows ++;
  15573. if ( light instanceof THREE.PointLight ) {
  15574. maxShadows ++;
  15575. pointLightShadows ++;
  15576. }
  15577. }
  15578. return { 'maxShadows': maxShadows, 'pointLightShadows': pointLightShadows };
  15579. }
  15580. this.getParameters = function ( material, lights, fog, object ) {
  15581. var shaderID = shaderIDs[ material.type ];
  15582. // heuristics to create shader parameters according to lights in the scene
  15583. // (not to blow over maxLights budget)
  15584. var maxLightCount = allocateLights( lights );
  15585. var allocatedShadows = allocateShadows( lights );
  15586. var maxBones = allocateBones( object );
  15587. var precision = renderer.getPrecision();
  15588. if ( material.precision !== null ) {
  15589. precision = capabilities.getMaxPrecision( material.precision );
  15590. if ( precision !== material.precision ) {
  15591. console.warn( 'THREE.WebGLRenderer.initMaterial:', material.precision, 'not supported, using', precision, 'instead.' );
  15592. }
  15593. }
  15594. var parameters = {
  15595. shaderID: shaderID,
  15596. precision: precision,
  15597. supportsVertexTextures: capabilities.vertexTextures,
  15598. map: !! material.map,
  15599. envMap: !! material.envMap,
  15600. envMapMode: material.envMap && material.envMap.mapping,
  15601. lightMap: !! material.lightMap,
  15602. aoMap: !! material.aoMap,
  15603. emissiveMap: !! material.emissiveMap,
  15604. bumpMap: !! material.bumpMap,
  15605. normalMap: !! material.normalMap,
  15606. displacementMap: !! material.displacementMap,
  15607. specularMap: !! material.specularMap,
  15608. alphaMap: !! material.alphaMap,
  15609. combine: material.combine,
  15610. vertexColors: material.vertexColors,
  15611. fog: fog,
  15612. useFog: material.fog,
  15613. fogExp: fog instanceof THREE.FogExp2,
  15614. flatShading: material.shading === THREE.FlatShading,
  15615. sizeAttenuation: material.sizeAttenuation,
  15616. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  15617. skinning: material.skinning,
  15618. maxBones: maxBones,
  15619. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  15620. morphTargets: material.morphTargets,
  15621. morphNormals: material.morphNormals,
  15622. maxMorphTargets: renderer.maxMorphTargets,
  15623. maxMorphNormals: renderer.maxMorphNormals,
  15624. maxDirLights: maxLightCount.directional,
  15625. maxPointLights: maxLightCount.point,
  15626. maxSpotLights: maxLightCount.spot,
  15627. maxHemiLights: maxLightCount.hemi,
  15628. maxShadows: allocatedShadows.maxShadows,
  15629. pointLightShadows: allocatedShadows.pointLightShadows,
  15630. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && allocatedShadows.maxShadows > 0,
  15631. shadowMapType: renderer.shadowMap.type,
  15632. shadowMapDebug: renderer.shadowMap.debug,
  15633. alphaTest: material.alphaTest,
  15634. metal: material.metal,
  15635. doubleSided: material.side === THREE.DoubleSide,
  15636. flipSided: material.side === THREE.BackSide
  15637. };
  15638. return parameters;
  15639. };
  15640. this.getProgramCode = function ( material, parameters ) {
  15641. var chunks = [];
  15642. if ( parameters.shaderID ) {
  15643. chunks.push( parameters.shaderID );
  15644. } else {
  15645. chunks.push( material.fragmentShader );
  15646. chunks.push( material.vertexShader );
  15647. }
  15648. if ( material.defines !== undefined ) {
  15649. for ( var name in material.defines ) {
  15650. chunks.push( name );
  15651. chunks.push( material.defines[ name ] );
  15652. }
  15653. }
  15654. for ( var i = 0; i < parameterNames.length; i ++ ) {
  15655. var parameterName = parameterNames[ i ];
  15656. chunks.push( parameterName );
  15657. chunks.push( parameters[ parameterName ] );
  15658. }
  15659. return chunks.join();
  15660. };
  15661. this.acquireProgram = function ( material, parameters, code ) {
  15662. var program;
  15663. // Check if code has been already compiled
  15664. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  15665. var programInfo = programs[ p ];
  15666. if ( programInfo.code === code ) {
  15667. program = programInfo;
  15668. ++ program.usedTimes;
  15669. break;
  15670. }
  15671. }
  15672. if ( program === undefined ) {
  15673. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  15674. programs.push( program );
  15675. }
  15676. return program;
  15677. };
  15678. this.releaseProgram = function( program ) {
  15679. if ( -- program.usedTimes === 0 ) {
  15680. // Remove from unordered set
  15681. var i = programs.indexOf( program );
  15682. programs[ i ] = programs[ programs.length - 1 ];
  15683. programs.pop();
  15684. // Free WebGL resources
  15685. program.destroy();
  15686. }
  15687. };
  15688. // Exposed for resource monitoring & error feedback via renderer.info:
  15689. this.programs = programs;
  15690. };
  15691. // File:src/renderers/webgl/WebGLProperties.js
  15692. /**
  15693. * @author fordacious / fordacious.github.io
  15694. */
  15695. THREE.WebGLProperties = function () {
  15696. var properties = {};
  15697. this.get = function ( object ) {
  15698. var uuid = object.uuid;
  15699. var map = properties[ uuid ];
  15700. if ( map === undefined ) {
  15701. map = {};
  15702. properties[ uuid ] = map;
  15703. }
  15704. return map;
  15705. };
  15706. this.delete = function ( object ) {
  15707. delete properties[ object.uuid ];
  15708. };
  15709. this.clear = function () {
  15710. properties = {};
  15711. };
  15712. };
  15713. // File:src/renderers/webgl/WebGLShader.js
  15714. THREE.WebGLShader = ( function () {
  15715. function addLineNumbers( string ) {
  15716. var lines = string.split( '\n' );
  15717. for ( var i = 0; i < lines.length; i ++ ) {
  15718. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  15719. }
  15720. return lines.join( '\n' );
  15721. }
  15722. return function WebGLShader( gl, type, string ) {
  15723. var shader = gl.createShader( type );
  15724. gl.shaderSource( shader, string );
  15725. gl.compileShader( shader );
  15726. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  15727. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  15728. }
  15729. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  15730. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  15731. }
  15732. // --enable-privileged-webgl-extension
  15733. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  15734. return shader;
  15735. };
  15736. } )();
  15737. // File:src/renderers/webgl/WebGLShadowMap.js
  15738. /**
  15739. * @author alteredq / http://alteredqualia.com/
  15740. * @author mrdoob / http://mrdoob.com/
  15741. */
  15742. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  15743. var _gl = _renderer.context,
  15744. _state = _renderer.state,
  15745. _frustum = new THREE.Frustum(),
  15746. _projScreenMatrix = new THREE.Matrix4(),
  15747. _min = new THREE.Vector3(),
  15748. _max = new THREE.Vector3(),
  15749. _lookTarget = new THREE.Vector3(),
  15750. _lightPositionWorld = new THREE.Vector3(),
  15751. _renderList = [],
  15752. _MorphingFlag = 1,
  15753. _SkinningFlag = 2,
  15754. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  15755. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  15756. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  15757. var cubeDirections = [
  15758. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  15759. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  15760. ];
  15761. var cubeUps = [
  15762. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  15763. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  15764. ];
  15765. var cube2DViewPorts = [
  15766. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  15767. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  15768. ];
  15769. var _vector4 = new THREE.Vector4();
  15770. // init
  15771. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  15772. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  15773. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  15774. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  15775. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  15776. var useMorphing = ( i & _MorphingFlag ) !== 0;
  15777. var useSkinning = ( i & _SkinningFlag ) !== 0;
  15778. var depthMaterial = new THREE.ShaderMaterial( {
  15779. uniforms: depthUniforms,
  15780. vertexShader: depthShader.vertexShader,
  15781. fragmentShader: depthShader.fragmentShader,
  15782. morphTargets: useMorphing,
  15783. skinning: useSkinning
  15784. } );
  15785. depthMaterial._shadowPass = true;
  15786. _depthMaterials[ i ] = depthMaterial;
  15787. var distanceMaterial = new THREE.ShaderMaterial( {
  15788. uniforms: distanceUniforms,
  15789. vertexShader: distanceShader.vertexShader,
  15790. fragmentShader: distanceShader.fragmentShader,
  15791. morphTargets: useMorphing,
  15792. skinning: useSkinning
  15793. } );
  15794. distanceMaterial._shadowPass = true;
  15795. _distanceMaterials[ i ] = distanceMaterial;
  15796. }
  15797. //
  15798. var scope = this;
  15799. this.enabled = false;
  15800. this.autoUpdate = true;
  15801. this.needsUpdate = false;
  15802. this.type = THREE.PCFShadowMap;
  15803. this.cullFace = THREE.CullFaceFront;
  15804. this.render = function ( scene ) {
  15805. var faceCount, isPointLight;
  15806. if ( scope.enabled === false ) return;
  15807. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  15808. // Set GL state for depth map.
  15809. _gl.clearColor( 1, 1, 1, 1 );
  15810. _state.disable( _gl.BLEND );
  15811. _state.enable( _gl.CULL_FACE );
  15812. _gl.frontFace( _gl.CCW );
  15813. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  15814. _state.setDepthTest( true );
  15815. // save the existing viewport so it can be restored later
  15816. _renderer.getViewport( _vector4 );
  15817. // render depth map
  15818. for ( var i = 0, il = _lights.length; i < il; i ++ ) {
  15819. var light = _lights[ i ];
  15820. if ( light.castShadow === false ) continue;
  15821. var shadow = light.shadow;
  15822. var shadowCamera = shadow.camera;
  15823. var shadowMapSize = shadow.mapSize;
  15824. if ( light instanceof THREE.PointLight ) {
  15825. faceCount = 6;
  15826. isPointLight = true;
  15827. var vpWidth = shadowMapSize.x / 4.0;
  15828. var vpHeight = shadowMapSize.y / 2.0;
  15829. // These viewports map a cube-map onto a 2D texture with the
  15830. // following orientation:
  15831. //
  15832. // xzXZ
  15833. // y Y
  15834. //
  15835. // X - Positive x direction
  15836. // x - Negative x direction
  15837. // Y - Positive y direction
  15838. // y - Negative y direction
  15839. // Z - Positive z direction
  15840. // z - Negative z direction
  15841. // positive X
  15842. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  15843. // negative X
  15844. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  15845. // positive Z
  15846. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  15847. // negative Z
  15848. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  15849. // positive Y
  15850. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  15851. // negative Y
  15852. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  15853. } else {
  15854. faceCount = 1;
  15855. isPointLight = false;
  15856. }
  15857. if ( shadow.map === null ) {
  15858. var shadowFilter = THREE.LinearFilter;
  15859. if ( scope.type === THREE.PCFSoftShadowMap ) {
  15860. shadowFilter = THREE.NearestFilter;
  15861. }
  15862. var pars = { minFilter: shadowFilter, magFilter: shadowFilter, format: THREE.RGBAFormat };
  15863. shadow.map = new THREE.WebGLRenderTarget( shadowMapSize.x, shadowMapSize.y, pars );
  15864. shadow.matrix = new THREE.Matrix4();
  15865. //
  15866. if ( light instanceof THREE.SpotLight ) {
  15867. shadowCamera.aspect = shadowMapSize.x / shadowMapSize.y;
  15868. }
  15869. shadowCamera.updateProjectionMatrix();
  15870. }
  15871. var shadowMap = shadow.map;
  15872. var shadowMatrix = shadow.matrix;
  15873. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  15874. shadowCamera.position.copy( _lightPositionWorld );
  15875. _renderer.setRenderTarget( shadowMap );
  15876. _renderer.clear();
  15877. // render shadow map for each cube face (if omni-directional) or
  15878. // run a single pass if not
  15879. for ( var face = 0; face < faceCount; face ++ ) {
  15880. if ( isPointLight ) {
  15881. _lookTarget.copy( shadowCamera.position );
  15882. _lookTarget.add( cubeDirections[ face ] );
  15883. shadowCamera.up.copy( cubeUps[ face ] );
  15884. shadowCamera.lookAt( _lookTarget );
  15885. var vpDimensions = cube2DViewPorts[ face ];
  15886. _renderer.setViewport( vpDimensions.x, vpDimensions.y, vpDimensions.z, vpDimensions.w );
  15887. } else {
  15888. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  15889. shadowCamera.lookAt( _lookTarget );
  15890. }
  15891. shadowCamera.updateMatrixWorld();
  15892. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  15893. // compute shadow matrix
  15894. shadowMatrix.set(
  15895. 0.5, 0.0, 0.0, 0.5,
  15896. 0.0, 0.5, 0.0, 0.5,
  15897. 0.0, 0.0, 0.5, 0.5,
  15898. 0.0, 0.0, 0.0, 1.0
  15899. );
  15900. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  15901. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  15902. // update camera matrices and frustum
  15903. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  15904. _frustum.setFromMatrix( _projScreenMatrix );
  15905. // set object matrices & frustum culling
  15906. _renderList.length = 0;
  15907. projectObject( scene, shadowCamera );
  15908. // render shadow map
  15909. // render regular objects
  15910. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  15911. var object = _renderList[ j ];
  15912. var geometry = _objects.update( object );
  15913. var material = object.material;
  15914. if ( material instanceof THREE.MeshFaceMaterial ) {
  15915. var groups = geometry.groups;
  15916. var materials = material.materials;
  15917. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  15918. var group = groups[ k ];
  15919. var groupMaterial = materials[ group.materialIndex ];
  15920. if ( groupMaterial.visible === true ) {
  15921. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  15922. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, group );
  15923. }
  15924. }
  15925. } else {
  15926. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  15927. _renderer.renderBufferDirect( shadowCamera, _lights, null, geometry, depthMaterial, object, null );
  15928. }
  15929. }
  15930. }
  15931. //We must call _renderer.resetGLState() at the end of each iteration of
  15932. // the light loop in order to force material updates for each light.
  15933. _renderer.resetGLState();
  15934. }
  15935. _renderer.setViewport( _vector4.x, _vector4.y, _vector4.z, _vector4.w );
  15936. // Restore GL state.
  15937. var clearColor = _renderer.getClearColor(),
  15938. clearAlpha = _renderer.getClearAlpha();
  15939. _renderer.setClearColor( clearColor, clearAlpha );
  15940. _state.enable( _gl.BLEND );
  15941. if ( scope.cullFace === THREE.CullFaceFront ) {
  15942. _gl.cullFace( _gl.BACK );
  15943. }
  15944. _renderer.resetGLState();
  15945. scope.needsUpdate = false;
  15946. };
  15947. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  15948. var geometry = object.geometry;
  15949. var newMaterial = null;
  15950. var materialVariants = _depthMaterials;
  15951. var customMaterial = object.customDepthMaterial;
  15952. if ( isPointLight ) {
  15953. materialVariants = _distanceMaterials;
  15954. customMaterial = object.customDistanceMaterial;
  15955. }
  15956. if ( ! customMaterial ) {
  15957. var useMorphing = geometry.morphTargets !== undefined &&
  15958. geometry.morphTargets.length > 0 && material.morphTargets;
  15959. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  15960. var variantIndex = 0;
  15961. if ( useMorphing ) variantIndex |= _MorphingFlag;
  15962. if ( useSkinning ) variantIndex |= _SkinningFlag;
  15963. newMaterial = materialVariants[ variantIndex ];
  15964. } else {
  15965. newMaterial = customMaterial;
  15966. }
  15967. newMaterial.visible = material.visible;
  15968. newMaterial.wireframe = material.wireframe;
  15969. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  15970. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  15971. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  15972. }
  15973. return newMaterial;
  15974. }
  15975. function projectObject( object, camera ) {
  15976. if ( object.visible === false ) return;
  15977. if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15978. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  15979. var material = object.material;
  15980. if ( material.visible === true ) {
  15981. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15982. _renderList.push( object );
  15983. }
  15984. }
  15985. }
  15986. var children = object.children;
  15987. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15988. projectObject( children[ i ], camera );
  15989. }
  15990. }
  15991. };
  15992. // File:src/renderers/webgl/WebGLState.js
  15993. /**
  15994. * @author mrdoob / http://mrdoob.com/
  15995. */
  15996. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  15997. var _this = this;
  15998. var newAttributes = new Uint8Array( 16 );
  15999. var enabledAttributes = new Uint8Array( 16 );
  16000. var attributeDivisors = new Uint8Array( 16 );
  16001. var capabilities = {};
  16002. var compressedTextureFormats = null;
  16003. var currentBlending = null;
  16004. var currentBlendEquation = null;
  16005. var currentBlendSrc = null;
  16006. var currentBlendDst = null;
  16007. var currentBlendEquationAlpha = null;
  16008. var currentBlendSrcAlpha = null;
  16009. var currentBlendDstAlpha = null;
  16010. var currentDepthFunc = null;
  16011. var currentDepthWrite = null;
  16012. var currentColorWrite = null;
  16013. var currentFlipSided = null;
  16014. var currentLineWidth = null;
  16015. var currentPolygonOffsetFactor = null;
  16016. var currentPolygonOffsetUnits = null;
  16017. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  16018. var currentTextureSlot = undefined;
  16019. var currentBoundTextures = {};
  16020. this.init = function () {
  16021. gl.clearColor( 0, 0, 0, 1 );
  16022. gl.clearDepth( 1 );
  16023. gl.clearStencil( 0 );
  16024. this.enable( gl.DEPTH_TEST );
  16025. gl.depthFunc( gl.LEQUAL );
  16026. gl.frontFace( gl.CCW );
  16027. gl.cullFace( gl.BACK );
  16028. this.enable( gl.CULL_FACE );
  16029. this.enable( gl.BLEND );
  16030. gl.blendEquation( gl.FUNC_ADD );
  16031. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  16032. };
  16033. this.initAttributes = function () {
  16034. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  16035. newAttributes[ i ] = 0;
  16036. }
  16037. };
  16038. this.enableAttribute = function ( attribute ) {
  16039. newAttributes[ attribute ] = 1;
  16040. if ( enabledAttributes[ attribute ] === 0 ) {
  16041. gl.enableVertexAttribArray( attribute );
  16042. enabledAttributes[ attribute ] = 1;
  16043. }
  16044. if ( attributeDivisors[ attribute ] !== 0 ) {
  16045. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  16046. extension.vertexAttribDivisorANGLE( attribute, 0 );
  16047. attributeDivisors[ attribute ] = 0;
  16048. }
  16049. };
  16050. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  16051. newAttributes[ attribute ] = 1;
  16052. if ( enabledAttributes[ attribute ] === 0 ) {
  16053. gl.enableVertexAttribArray( attribute );
  16054. enabledAttributes[ attribute ] = 1;
  16055. }
  16056. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  16057. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  16058. attributeDivisors[ attribute ] = meshPerAttribute;
  16059. }
  16060. };
  16061. this.disableUnusedAttributes = function () {
  16062. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  16063. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  16064. gl.disableVertexAttribArray( i );
  16065. enabledAttributes[ i ] = 0;
  16066. }
  16067. }
  16068. };
  16069. this.enable = function ( id ) {
  16070. if ( capabilities[ id ] !== true ) {
  16071. gl.enable( id );
  16072. capabilities[ id ] = true;
  16073. }
  16074. };
  16075. this.disable = function ( id ) {
  16076. if ( capabilities[ id ] !== false ) {
  16077. gl.disable( id );
  16078. capabilities[ id ] = false;
  16079. }
  16080. };
  16081. this.getCompressedTextureFormats = function () {
  16082. if ( compressedTextureFormats === null ) {
  16083. compressedTextureFormats = [];
  16084. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  16085. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ) {
  16086. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  16087. for ( var i = 0; i < formats.length; i ++ ) {
  16088. compressedTextureFormats.push( formats[ i ] );
  16089. }
  16090. }
  16091. }
  16092. return compressedTextureFormats;
  16093. };
  16094. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  16095. if ( blending !== currentBlending ) {
  16096. if ( blending === THREE.NoBlending ) {
  16097. this.disable( gl.BLEND );
  16098. } else if ( blending === THREE.AdditiveBlending ) {
  16099. this.enable( gl.BLEND );
  16100. gl.blendEquation( gl.FUNC_ADD );
  16101. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  16102. } else if ( blending === THREE.SubtractiveBlending ) {
  16103. // TODO: Find blendFuncSeparate() combination
  16104. this.enable( gl.BLEND );
  16105. gl.blendEquation( gl.FUNC_ADD );
  16106. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  16107. } else if ( blending === THREE.MultiplyBlending ) {
  16108. // TODO: Find blendFuncSeparate() combination
  16109. this.enable( gl.BLEND );
  16110. gl.blendEquation( gl.FUNC_ADD );
  16111. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  16112. } else if ( blending === THREE.CustomBlending ) {
  16113. this.enable( gl.BLEND );
  16114. } else {
  16115. this.enable( gl.BLEND );
  16116. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  16117. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  16118. }
  16119. currentBlending = blending;
  16120. }
  16121. if ( blending === THREE.CustomBlending ) {
  16122. blendEquationAlpha = blendEquationAlpha || blendEquation;
  16123. blendSrcAlpha = blendSrcAlpha || blendSrc;
  16124. blendDstAlpha = blendDstAlpha || blendDst;
  16125. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  16126. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  16127. currentBlendEquation = blendEquation;
  16128. currentBlendEquationAlpha = blendEquationAlpha;
  16129. }
  16130. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  16131. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  16132. currentBlendSrc = blendSrc;
  16133. currentBlendDst = blendDst;
  16134. currentBlendSrcAlpha = blendSrcAlpha;
  16135. currentBlendDstAlpha = blendDstAlpha;
  16136. }
  16137. } else {
  16138. currentBlendEquation = null;
  16139. currentBlendSrc = null;
  16140. currentBlendDst = null;
  16141. currentBlendEquationAlpha = null;
  16142. currentBlendSrcAlpha = null;
  16143. currentBlendDstAlpha = null;
  16144. }
  16145. };
  16146. this.setDepthFunc = function ( depthFunc ) {
  16147. if ( currentDepthFunc !== depthFunc ) {
  16148. if ( depthFunc ) {
  16149. switch ( depthFunc ) {
  16150. case THREE.NeverDepth:
  16151. gl.depthFunc( gl.NEVER );
  16152. break;
  16153. case THREE.AlwaysDepth:
  16154. gl.depthFunc( gl.ALWAYS );
  16155. break;
  16156. case THREE.LessDepth:
  16157. gl.depthFunc( gl.LESS );
  16158. break;
  16159. case THREE.LessEqualDepth:
  16160. gl.depthFunc( gl.LEQUAL );
  16161. break;
  16162. case THREE.EqualDepth:
  16163. gl.depthFunc( gl.EQUAL );
  16164. break;
  16165. case THREE.GreaterEqualDepth:
  16166. gl.depthFunc( gl.GEQUAL );
  16167. break;
  16168. case THREE.GreaterDepth:
  16169. gl.depthFunc( gl.GREATER );
  16170. break;
  16171. case THREE.NotEqualDepth:
  16172. gl.depthFunc( gl.NOTEQUAL );
  16173. break;
  16174. default:
  16175. gl.depthFunc( gl.LEQUAL );
  16176. }
  16177. } else {
  16178. gl.depthFunc( gl.LEQUAL );
  16179. }
  16180. currentDepthFunc = depthFunc;
  16181. }
  16182. };
  16183. this.setDepthTest = function ( depthTest ) {
  16184. if ( depthTest ) {
  16185. this.enable( gl.DEPTH_TEST );
  16186. } else {
  16187. this.disable( gl.DEPTH_TEST );
  16188. }
  16189. };
  16190. this.setDepthWrite = function ( depthWrite ) {
  16191. if ( currentDepthWrite !== depthWrite ) {
  16192. gl.depthMask( depthWrite );
  16193. currentDepthWrite = depthWrite;
  16194. }
  16195. };
  16196. this.setColorWrite = function ( colorWrite ) {
  16197. if ( currentColorWrite !== colorWrite ) {
  16198. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  16199. currentColorWrite = colorWrite;
  16200. }
  16201. };
  16202. this.setFlipSided = function ( flipSided ) {
  16203. if ( currentFlipSided !== flipSided ) {
  16204. if ( flipSided ) {
  16205. gl.frontFace( gl.CW );
  16206. } else {
  16207. gl.frontFace( gl.CCW );
  16208. }
  16209. currentFlipSided = flipSided;
  16210. }
  16211. };
  16212. this.setLineWidth = function ( width ) {
  16213. if ( width !== currentLineWidth ) {
  16214. gl.lineWidth( width );
  16215. currentLineWidth = width;
  16216. }
  16217. };
  16218. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  16219. if ( polygonOffset ) {
  16220. this.enable( gl.POLYGON_OFFSET_FILL );
  16221. } else {
  16222. this.disable( gl.POLYGON_OFFSET_FILL );
  16223. }
  16224. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  16225. gl.polygonOffset( factor, units );
  16226. currentPolygonOffsetFactor = factor;
  16227. currentPolygonOffsetUnits = units;
  16228. }
  16229. };
  16230. this.setScissorTest = function ( scissorTest ) {
  16231. if ( scissorTest ) {
  16232. this.enable( gl.SCISSOR_TEST );
  16233. } else {
  16234. this.disable( gl.SCISSOR_TEST );
  16235. }
  16236. };
  16237. // texture
  16238. this.activeTexture = function ( webglSlot ) {
  16239. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  16240. if ( currentTextureSlot !== webglSlot ) {
  16241. gl.activeTexture( webglSlot );
  16242. currentTextureSlot = webglSlot;
  16243. }
  16244. }
  16245. this.bindTexture = function ( webglType, webglTexture ) {
  16246. if ( currentTextureSlot === undefined ) {
  16247. _this.activeTexture();
  16248. }
  16249. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  16250. if ( boundTexture === undefined ) {
  16251. boundTexture = { type: undefined, texture: undefined };
  16252. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  16253. }
  16254. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  16255. gl.bindTexture( webglType, webglTexture );
  16256. boundTexture.type = webglType;
  16257. boundTexture.texture = webglTexture;
  16258. }
  16259. };
  16260. this.compressedTexImage2D = function () {
  16261. try {
  16262. gl.compressedTexImage2D.apply( gl, arguments );
  16263. } catch ( error ) {
  16264. console.error( error );
  16265. }
  16266. };
  16267. this.texImage2D = function () {
  16268. try {
  16269. gl.texImage2D.apply( gl, arguments );
  16270. } catch ( error ) {
  16271. console.error( error );
  16272. }
  16273. };
  16274. //
  16275. this.reset = function () {
  16276. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  16277. if ( enabledAttributes[ i ] === 1 ) {
  16278. gl.disableVertexAttribArray( i );
  16279. enabledAttributes[ i ] = 0;
  16280. }
  16281. }
  16282. capabilities = {};
  16283. compressedTextureFormats = null;
  16284. currentBlending = null;
  16285. currentDepthWrite = null;
  16286. currentColorWrite = null;
  16287. currentFlipSided = null;
  16288. };
  16289. };
  16290. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  16291. /**
  16292. * @author mikael emtinger / http://gomo.se/
  16293. * @author alteredq / http://alteredqualia.com/
  16294. */
  16295. THREE.LensFlarePlugin = function ( renderer, flares ) {
  16296. var gl = renderer.context;
  16297. var state = renderer.state;
  16298. var vertexBuffer, elementBuffer;
  16299. var program, attributes, uniforms;
  16300. var hasVertexTexture;
  16301. var tempTexture, occlusionTexture;
  16302. function init() {
  16303. var vertices = new Float32Array( [
  16304. - 1, - 1, 0, 0,
  16305. 1, - 1, 1, 0,
  16306. 1, 1, 1, 1,
  16307. - 1, 1, 0, 1
  16308. ] );
  16309. var faces = new Uint16Array( [
  16310. 0, 1, 2,
  16311. 0, 2, 3
  16312. ] );
  16313. // buffers
  16314. vertexBuffer = gl.createBuffer();
  16315. elementBuffer = gl.createBuffer();
  16316. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16317. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16318. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16319. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16320. // textures
  16321. tempTexture = gl.createTexture();
  16322. occlusionTexture = gl.createTexture();
  16323. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16324. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  16325. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16326. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16327. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16328. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16329. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16330. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  16331. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  16332. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  16333. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  16334. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  16335. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  16336. var shader;
  16337. if ( hasVertexTexture ) {
  16338. shader = {
  16339. vertexShader: [
  16340. "uniform lowp int renderType;",
  16341. "uniform vec3 screenPosition;",
  16342. "uniform vec2 scale;",
  16343. "uniform float rotation;",
  16344. "uniform sampler2D occlusionMap;",
  16345. "attribute vec2 position;",
  16346. "attribute vec2 uv;",
  16347. "varying vec2 vUV;",
  16348. "varying float vVisibility;",
  16349. "void main() {",
  16350. "vUV = uv;",
  16351. "vec2 pos = position;",
  16352. "if ( renderType == 2 ) {",
  16353. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  16354. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  16355. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  16356. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  16357. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  16358. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  16359. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  16360. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  16361. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  16362. "vVisibility = visibility.r / 9.0;",
  16363. "vVisibility *= 1.0 - visibility.g / 9.0;",
  16364. "vVisibility *= visibility.b / 9.0;",
  16365. "vVisibility *= 1.0 - visibility.a / 9.0;",
  16366. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16367. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16368. "}",
  16369. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16370. "}"
  16371. ].join( "\n" ),
  16372. fragmentShader: [
  16373. "uniform lowp int renderType;",
  16374. "uniform sampler2D map;",
  16375. "uniform float opacity;",
  16376. "uniform vec3 color;",
  16377. "varying vec2 vUV;",
  16378. "varying float vVisibility;",
  16379. "void main() {",
  16380. // pink square
  16381. "if ( renderType == 0 ) {",
  16382. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  16383. // restore
  16384. "} else if ( renderType == 1 ) {",
  16385. "gl_FragColor = texture2D( map, vUV );",
  16386. // flare
  16387. "} else {",
  16388. "vec4 texture = texture2D( map, vUV );",
  16389. "texture.a *= opacity * vVisibility;",
  16390. "gl_FragColor = texture;",
  16391. "gl_FragColor.rgb *= color;",
  16392. "}",
  16393. "}"
  16394. ].join( "\n" )
  16395. };
  16396. } else {
  16397. shader = {
  16398. vertexShader: [
  16399. "uniform lowp int renderType;",
  16400. "uniform vec3 screenPosition;",
  16401. "uniform vec2 scale;",
  16402. "uniform float rotation;",
  16403. "attribute vec2 position;",
  16404. "attribute vec2 uv;",
  16405. "varying vec2 vUV;",
  16406. "void main() {",
  16407. "vUV = uv;",
  16408. "vec2 pos = position;",
  16409. "if ( renderType == 2 ) {",
  16410. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  16411. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  16412. "}",
  16413. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  16414. "}"
  16415. ].join( "\n" ),
  16416. fragmentShader: [
  16417. "precision mediump float;",
  16418. "uniform lowp int renderType;",
  16419. "uniform sampler2D map;",
  16420. "uniform sampler2D occlusionMap;",
  16421. "uniform float opacity;",
  16422. "uniform vec3 color;",
  16423. "varying vec2 vUV;",
  16424. "void main() {",
  16425. // pink square
  16426. "if ( renderType == 0 ) {",
  16427. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  16428. // restore
  16429. "} else if ( renderType == 1 ) {",
  16430. "gl_FragColor = texture2D( map, vUV );",
  16431. // flare
  16432. "} else {",
  16433. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  16434. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  16435. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  16436. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  16437. "visibility = ( 1.0 - visibility / 4.0 );",
  16438. "vec4 texture = texture2D( map, vUV );",
  16439. "texture.a *= opacity * visibility;",
  16440. "gl_FragColor = texture;",
  16441. "gl_FragColor.rgb *= color;",
  16442. "}",
  16443. "}"
  16444. ].join( "\n" )
  16445. };
  16446. }
  16447. program = createProgram( shader );
  16448. attributes = {
  16449. vertex: gl.getAttribLocation ( program, "position" ),
  16450. uv: gl.getAttribLocation ( program, "uv" )
  16451. };
  16452. uniforms = {
  16453. renderType: gl.getUniformLocation( program, "renderType" ),
  16454. map: gl.getUniformLocation( program, "map" ),
  16455. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  16456. opacity: gl.getUniformLocation( program, "opacity" ),
  16457. color: gl.getUniformLocation( program, "color" ),
  16458. scale: gl.getUniformLocation( program, "scale" ),
  16459. rotation: gl.getUniformLocation( program, "rotation" ),
  16460. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  16461. };
  16462. }
  16463. /*
  16464. * Render lens flares
  16465. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  16466. * reads these back and calculates occlusion.
  16467. */
  16468. this.render = function ( scene, camera, viewportWidth, viewportHeight ) {
  16469. if ( flares.length === 0 ) return;
  16470. var tempPosition = new THREE.Vector3();
  16471. var invAspect = viewportHeight / viewportWidth,
  16472. halfViewportWidth = viewportWidth * 0.5,
  16473. halfViewportHeight = viewportHeight * 0.5;
  16474. var size = 16 / viewportHeight,
  16475. scale = new THREE.Vector2( size * invAspect, size );
  16476. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  16477. screenPositionPixels = new THREE.Vector2( 1, 1 );
  16478. if ( program === undefined ) {
  16479. init();
  16480. }
  16481. gl.useProgram( program );
  16482. state.initAttributes();
  16483. state.enableAttribute( attributes.vertex );
  16484. state.enableAttribute( attributes.uv );
  16485. state.disableUnusedAttributes();
  16486. // loop through all lens flares to update their occlusion and positions
  16487. // setup gl and common used attribs/uniforms
  16488. gl.uniform1i( uniforms.occlusionMap, 0 );
  16489. gl.uniform1i( uniforms.map, 1 );
  16490. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16491. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  16492. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16493. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16494. state.disable( gl.CULL_FACE );
  16495. gl.depthMask( false );
  16496. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  16497. size = 16 / viewportHeight;
  16498. scale.set( size * invAspect, size );
  16499. // calc object screen position
  16500. var flare = flares[ i ];
  16501. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  16502. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  16503. tempPosition.applyProjection( camera.projectionMatrix );
  16504. // setup arrays for gl programs
  16505. screenPosition.copy( tempPosition );
  16506. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  16507. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  16508. // screen cull
  16509. if ( hasVertexTexture || (
  16510. screenPositionPixels.x > 0 &&
  16511. screenPositionPixels.x < viewportWidth &&
  16512. screenPositionPixels.y > 0 &&
  16513. screenPositionPixels.y < viewportHeight ) ) {
  16514. // save current RGB to temp texture
  16515. state.activeTexture( gl.TEXTURE0 );
  16516. state.bindTexture( gl.TEXTURE_2D, null );
  16517. state.activeTexture( gl.TEXTURE1 );
  16518. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16519. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16520. // render pink quad
  16521. gl.uniform1i( uniforms.renderType, 0 );
  16522. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16523. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16524. state.disable( gl.BLEND );
  16525. state.enable( gl.DEPTH_TEST );
  16526. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16527. // copy result to occlusionMap
  16528. state.activeTexture( gl.TEXTURE0 );
  16529. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  16530. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, screenPositionPixels.x - 8, screenPositionPixels.y - 8, 16, 16, 0 );
  16531. // restore graphics
  16532. gl.uniform1i( uniforms.renderType, 1 );
  16533. state.disable( gl.DEPTH_TEST );
  16534. state.activeTexture( gl.TEXTURE1 );
  16535. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  16536. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16537. // update object positions
  16538. flare.positionScreen.copy( screenPosition );
  16539. if ( flare.customUpdateCallback ) {
  16540. flare.customUpdateCallback( flare );
  16541. } else {
  16542. flare.updateLensFlares();
  16543. }
  16544. // render flares
  16545. gl.uniform1i( uniforms.renderType, 2 );
  16546. state.enable( gl.BLEND );
  16547. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  16548. var sprite = flare.lensFlares[ j ];
  16549. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  16550. screenPosition.x = sprite.x;
  16551. screenPosition.y = sprite.y;
  16552. screenPosition.z = sprite.z;
  16553. size = sprite.size * sprite.scale / viewportHeight;
  16554. scale.x = size * invAspect;
  16555. scale.y = size;
  16556. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  16557. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  16558. gl.uniform1f( uniforms.rotation, sprite.rotation );
  16559. gl.uniform1f( uniforms.opacity, sprite.opacity );
  16560. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  16561. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  16562. renderer.setTexture( sprite.texture, 1 );
  16563. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16564. }
  16565. }
  16566. }
  16567. }
  16568. // restore gl
  16569. state.enable( gl.CULL_FACE );
  16570. state.enable( gl.DEPTH_TEST );
  16571. gl.depthMask( true );
  16572. renderer.resetGLState();
  16573. };
  16574. function createProgram ( shader ) {
  16575. var program = gl.createProgram();
  16576. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16577. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16578. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  16579. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  16580. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  16581. gl.compileShader( fragmentShader );
  16582. gl.compileShader( vertexShader );
  16583. gl.attachShader( program, fragmentShader );
  16584. gl.attachShader( program, vertexShader );
  16585. gl.linkProgram( program );
  16586. return program;
  16587. }
  16588. };
  16589. // File:src/renderers/webgl/plugins/SpritePlugin.js
  16590. /**
  16591. * @author mikael emtinger / http://gomo.se/
  16592. * @author alteredq / http://alteredqualia.com/
  16593. */
  16594. THREE.SpritePlugin = function ( renderer, sprites ) {
  16595. var gl = renderer.context;
  16596. var state = renderer.state;
  16597. var vertexBuffer, elementBuffer;
  16598. var program, attributes, uniforms;
  16599. var texture;
  16600. // decompose matrixWorld
  16601. var spritePosition = new THREE.Vector3();
  16602. var spriteRotation = new THREE.Quaternion();
  16603. var spriteScale = new THREE.Vector3();
  16604. function init() {
  16605. var vertices = new Float32Array( [
  16606. - 0.5, - 0.5, 0, 0,
  16607. 0.5, - 0.5, 1, 0,
  16608. 0.5, 0.5, 1, 1,
  16609. - 0.5, 0.5, 0, 1
  16610. ] );
  16611. var faces = new Uint16Array( [
  16612. 0, 1, 2,
  16613. 0, 2, 3
  16614. ] );
  16615. vertexBuffer = gl.createBuffer();
  16616. elementBuffer = gl.createBuffer();
  16617. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16618. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  16619. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16620. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  16621. program = createProgram();
  16622. attributes = {
  16623. position: gl.getAttribLocation ( program, 'position' ),
  16624. uv: gl.getAttribLocation ( program, 'uv' )
  16625. };
  16626. uniforms = {
  16627. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  16628. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  16629. rotation: gl.getUniformLocation( program, 'rotation' ),
  16630. scale: gl.getUniformLocation( program, 'scale' ),
  16631. color: gl.getUniformLocation( program, 'color' ),
  16632. map: gl.getUniformLocation( program, 'map' ),
  16633. opacity: gl.getUniformLocation( program, 'opacity' ),
  16634. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  16635. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  16636. fogType: gl.getUniformLocation( program, 'fogType' ),
  16637. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  16638. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  16639. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  16640. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  16641. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  16642. };
  16643. var canvas = document.createElement( 'canvas' );
  16644. canvas.width = 8;
  16645. canvas.height = 8;
  16646. var context = canvas.getContext( '2d' );
  16647. context.fillStyle = 'white';
  16648. context.fillRect( 0, 0, 8, 8 );
  16649. texture = new THREE.Texture( canvas );
  16650. texture.needsUpdate = true;
  16651. }
  16652. this.render = function ( scene, camera ) {
  16653. if ( sprites.length === 0 ) return;
  16654. // setup gl
  16655. if ( program === undefined ) {
  16656. init();
  16657. }
  16658. gl.useProgram( program );
  16659. state.initAttributes();
  16660. state.enableAttribute( attributes.position );
  16661. state.enableAttribute( attributes.uv );
  16662. state.disableUnusedAttributes();
  16663. state.disable( gl.CULL_FACE );
  16664. state.enable( gl.BLEND );
  16665. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  16666. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  16667. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  16668. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  16669. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  16670. state.activeTexture( gl.TEXTURE0 );
  16671. gl.uniform1i( uniforms.map, 0 );
  16672. var oldFogType = 0;
  16673. var sceneFogType = 0;
  16674. var fog = scene.fog;
  16675. if ( fog ) {
  16676. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  16677. if ( fog instanceof THREE.Fog ) {
  16678. gl.uniform1f( uniforms.fogNear, fog.near );
  16679. gl.uniform1f( uniforms.fogFar, fog.far );
  16680. gl.uniform1i( uniforms.fogType, 1 );
  16681. oldFogType = 1;
  16682. sceneFogType = 1;
  16683. } else if ( fog instanceof THREE.FogExp2 ) {
  16684. gl.uniform1f( uniforms.fogDensity, fog.density );
  16685. gl.uniform1i( uniforms.fogType, 2 );
  16686. oldFogType = 2;
  16687. sceneFogType = 2;
  16688. }
  16689. } else {
  16690. gl.uniform1i( uniforms.fogType, 0 );
  16691. oldFogType = 0;
  16692. sceneFogType = 0;
  16693. }
  16694. // update positions and sort
  16695. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16696. var sprite = sprites[ i ];
  16697. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  16698. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  16699. }
  16700. sprites.sort( painterSortStable );
  16701. // render all sprites
  16702. var scale = [];
  16703. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  16704. var sprite = sprites[ i ];
  16705. var material = sprite.material;
  16706. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  16707. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  16708. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  16709. scale[ 0 ] = spriteScale.x;
  16710. scale[ 1 ] = spriteScale.y;
  16711. var fogType = 0;
  16712. if ( scene.fog && material.fog ) {
  16713. fogType = sceneFogType;
  16714. }
  16715. if ( oldFogType !== fogType ) {
  16716. gl.uniform1i( uniforms.fogType, fogType );
  16717. oldFogType = fogType;
  16718. }
  16719. if ( material.map !== null ) {
  16720. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  16721. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  16722. } else {
  16723. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  16724. gl.uniform2f( uniforms.uvScale, 1, 1 );
  16725. }
  16726. gl.uniform1f( uniforms.opacity, material.opacity );
  16727. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  16728. gl.uniform1f( uniforms.rotation, material.rotation );
  16729. gl.uniform2fv( uniforms.scale, scale );
  16730. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  16731. state.setDepthTest( material.depthTest );
  16732. state.setDepthWrite( material.depthWrite );
  16733. if ( material.map && material.map.image && material.map.image.width ) {
  16734. renderer.setTexture( material.map, 0 );
  16735. } else {
  16736. renderer.setTexture( texture, 0 );
  16737. }
  16738. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  16739. }
  16740. // restore gl
  16741. state.enable( gl.CULL_FACE );
  16742. renderer.resetGLState();
  16743. };
  16744. function createProgram () {
  16745. var program = gl.createProgram();
  16746. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  16747. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  16748. gl.shaderSource( vertexShader, [
  16749. 'precision ' + renderer.getPrecision() + ' float;',
  16750. 'uniform mat4 modelViewMatrix;',
  16751. 'uniform mat4 projectionMatrix;',
  16752. 'uniform float rotation;',
  16753. 'uniform vec2 scale;',
  16754. 'uniform vec2 uvOffset;',
  16755. 'uniform vec2 uvScale;',
  16756. 'attribute vec2 position;',
  16757. 'attribute vec2 uv;',
  16758. 'varying vec2 vUV;',
  16759. 'void main() {',
  16760. 'vUV = uvOffset + uv * uvScale;',
  16761. 'vec2 alignedPosition = position * scale;',
  16762. 'vec2 rotatedPosition;',
  16763. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  16764. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  16765. 'vec4 finalPosition;',
  16766. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  16767. 'finalPosition.xy += rotatedPosition;',
  16768. 'finalPosition = projectionMatrix * finalPosition;',
  16769. 'gl_Position = finalPosition;',
  16770. '}'
  16771. ].join( '\n' ) );
  16772. gl.shaderSource( fragmentShader, [
  16773. 'precision ' + renderer.getPrecision() + ' float;',
  16774. 'uniform vec3 color;',
  16775. 'uniform sampler2D map;',
  16776. 'uniform float opacity;',
  16777. 'uniform int fogType;',
  16778. 'uniform vec3 fogColor;',
  16779. 'uniform float fogDensity;',
  16780. 'uniform float fogNear;',
  16781. 'uniform float fogFar;',
  16782. 'uniform float alphaTest;',
  16783. 'varying vec2 vUV;',
  16784. 'void main() {',
  16785. 'vec4 texture = texture2D( map, vUV );',
  16786. 'if ( texture.a < alphaTest ) discard;',
  16787. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  16788. 'if ( fogType > 0 ) {',
  16789. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  16790. 'float fogFactor = 0.0;',
  16791. 'if ( fogType == 1 ) {',
  16792. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  16793. '} else {',
  16794. 'const float LOG2 = 1.442695;',
  16795. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  16796. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  16797. '}',
  16798. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  16799. '}',
  16800. '}'
  16801. ].join( '\n' ) );
  16802. gl.compileShader( vertexShader );
  16803. gl.compileShader( fragmentShader );
  16804. gl.attachShader( program, vertexShader );
  16805. gl.attachShader( program, fragmentShader );
  16806. gl.linkProgram( program );
  16807. return program;
  16808. }
  16809. function painterSortStable ( a, b ) {
  16810. if ( a.z !== b.z ) {
  16811. return b.z - a.z;
  16812. } else {
  16813. return b.id - a.id;
  16814. }
  16815. }
  16816. };
  16817. // File:src/extras/GeometryUtils.js
  16818. /**
  16819. * @author mrdoob / http://mrdoob.com/
  16820. */
  16821. THREE.GeometryUtils = {
  16822. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  16823. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  16824. var matrix;
  16825. if ( geometry2 instanceof THREE.Mesh ) {
  16826. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  16827. matrix = geometry2.matrix;
  16828. geometry2 = geometry2.geometry;
  16829. }
  16830. geometry1.merge( geometry2, matrix, materialIndexOffset );
  16831. },
  16832. center: function ( geometry ) {
  16833. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  16834. return geometry.center();
  16835. }
  16836. };
  16837. // File:src/extras/ImageUtils.js
  16838. /**
  16839. * @author alteredq / http://alteredqualia.com/
  16840. * @author mrdoob / http://mrdoob.com/
  16841. * @author Daosheng Mu / https://github.com/DaoshengMu/
  16842. */
  16843. THREE.ImageUtils = {
  16844. crossOrigin: undefined,
  16845. loadTexture: function ( url, mapping, onLoad, onError ) {
  16846. var loader = new THREE.ImageLoader();
  16847. loader.crossOrigin = this.crossOrigin;
  16848. var texture = new THREE.Texture( undefined, mapping );
  16849. loader.load( url, function ( image ) {
  16850. texture.image = image;
  16851. texture.needsUpdate = true;
  16852. if ( onLoad ) onLoad( texture );
  16853. }, undefined, function ( event ) {
  16854. if ( onError ) onError( event );
  16855. } );
  16856. texture.sourceFile = url;
  16857. return texture;
  16858. },
  16859. loadTextureCube: function ( array, mapping, onLoad, onError ) {
  16860. var images = [];
  16861. var loader = new THREE.ImageLoader();
  16862. loader.crossOrigin = this.crossOrigin;
  16863. var texture = new THREE.CubeTexture( images, mapping );
  16864. var loaded = 0;
  16865. function loadTexture( i ) {
  16866. loader.load( array[ i ], function ( image ) {
  16867. texture.images[ i ] = image;
  16868. loaded += 1;
  16869. if ( loaded === 6 ) {
  16870. texture.needsUpdate = true;
  16871. if ( onLoad ) onLoad( texture );
  16872. }
  16873. }, undefined, onError );
  16874. }
  16875. for ( var i = 0, il = array.length; i < il; ++ i ) {
  16876. loadTexture( i );
  16877. }
  16878. return texture;
  16879. },
  16880. loadCompressedTexture: function () {
  16881. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' )
  16882. },
  16883. loadCompressedTextureCube: function () {
  16884. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' )
  16885. },
  16886. getNormalMap: function ( image, depth ) {
  16887. // Adapted from http://www.paulbrunt.co.uk/lab/heightnormal/
  16888. function cross( a, b ) {
  16889. 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 ] ];
  16890. }
  16891. function subtract( a, b ) {
  16892. return [ a[ 0 ] - b[ 0 ], a[ 1 ] - b[ 1 ], a[ 2 ] - b[ 2 ] ];
  16893. }
  16894. function normalize( a ) {
  16895. var l = Math.sqrt( a[ 0 ] * a[ 0 ] + a[ 1 ] * a[ 1 ] + a[ 2 ] * a[ 2 ] );
  16896. return [ a[ 0 ] / l, a[ 1 ] / l, a[ 2 ] / l ];
  16897. }
  16898. depth = depth | 1;
  16899. var width = image.width;
  16900. var height = image.height;
  16901. var canvas = document.createElement( 'canvas' );
  16902. canvas.width = width;
  16903. canvas.height = height;
  16904. var context = canvas.getContext( '2d' );
  16905. context.drawImage( image, 0, 0 );
  16906. var data = context.getImageData( 0, 0, width, height ).data;
  16907. var imageData = context.createImageData( width, height );
  16908. var output = imageData.data;
  16909. for ( var x = 0; x < width; x ++ ) {
  16910. for ( var y = 0; y < height; y ++ ) {
  16911. var ly = y - 1 < 0 ? 0 : y - 1;
  16912. var uy = y + 1 > height - 1 ? height - 1 : y + 1;
  16913. var lx = x - 1 < 0 ? 0 : x - 1;
  16914. var ux = x + 1 > width - 1 ? width - 1 : x + 1;
  16915. var points = [];
  16916. var origin = [ 0, 0, data[ ( y * width + x ) * 4 ] / 255 * depth ];
  16917. points.push( [ - 1, 0, data[ ( y * width + lx ) * 4 ] / 255 * depth ] );
  16918. points.push( [ - 1, - 1, data[ ( ly * width + lx ) * 4 ] / 255 * depth ] );
  16919. points.push( [ 0, - 1, data[ ( ly * width + x ) * 4 ] / 255 * depth ] );
  16920. points.push( [ 1, - 1, data[ ( ly * width + ux ) * 4 ] / 255 * depth ] );
  16921. points.push( [ 1, 0, data[ ( y * width + ux ) * 4 ] / 255 * depth ] );
  16922. points.push( [ 1, 1, data[ ( uy * width + ux ) * 4 ] / 255 * depth ] );
  16923. points.push( [ 0, 1, data[ ( uy * width + x ) * 4 ] / 255 * depth ] );
  16924. points.push( [ - 1, 1, data[ ( uy * width + lx ) * 4 ] / 255 * depth ] );
  16925. var normals = [];
  16926. var num_points = points.length;
  16927. for ( var i = 0; i < num_points; i ++ ) {
  16928. var v1 = points[ i ];
  16929. var v2 = points[ ( i + 1 ) % num_points ];
  16930. v1 = subtract( v1, origin );
  16931. v2 = subtract( v2, origin );
  16932. normals.push( normalize( cross( v1, v2 ) ) );
  16933. }
  16934. var normal = [ 0, 0, 0 ];
  16935. for ( var i = 0; i < normals.length; i ++ ) {
  16936. normal[ 0 ] += normals[ i ][ 0 ];
  16937. normal[ 1 ] += normals[ i ][ 1 ];
  16938. normal[ 2 ] += normals[ i ][ 2 ];
  16939. }
  16940. normal[ 0 ] /= normals.length;
  16941. normal[ 1 ] /= normals.length;
  16942. normal[ 2 ] /= normals.length;
  16943. var idx = ( y * width + x ) * 4;
  16944. output[ idx ] = ( ( normal[ 0 ] + 1.0 ) / 2.0 * 255 ) | 0;
  16945. output[ idx + 1 ] = ( ( normal[ 1 ] + 1.0 ) / 2.0 * 255 ) | 0;
  16946. output[ idx + 2 ] = ( normal[ 2 ] * 255 ) | 0;
  16947. output[ idx + 3 ] = 255;
  16948. }
  16949. }
  16950. context.putImageData( imageData, 0, 0 );
  16951. return canvas;
  16952. },
  16953. generateDataTexture: function ( width, height, color ) {
  16954. var size = width * height;
  16955. var data = new Uint8Array( 3 * size );
  16956. var r = Math.floor( color.r * 255 );
  16957. var g = Math.floor( color.g * 255 );
  16958. var b = Math.floor( color.b * 255 );
  16959. for ( var i = 0; i < size; i ++ ) {
  16960. data[ i * 3 ] = r;
  16961. data[ i * 3 + 1 ] = g;
  16962. data[ i * 3 + 2 ] = b;
  16963. }
  16964. var texture = new THREE.DataTexture( data, width, height, THREE.RGBFormat );
  16965. texture.needsUpdate = true;
  16966. return texture;
  16967. }
  16968. };
  16969. // File:src/extras/SceneUtils.js
  16970. /**
  16971. * @author alteredq / http://alteredqualia.com/
  16972. */
  16973. THREE.SceneUtils = {
  16974. createMultiMaterialObject: function ( geometry, materials ) {
  16975. var group = new THREE.Group();
  16976. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  16977. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  16978. }
  16979. return group;
  16980. },
  16981. detach: function ( child, parent, scene ) {
  16982. child.applyMatrix( parent.matrixWorld );
  16983. parent.remove( child );
  16984. scene.add( child );
  16985. },
  16986. attach: function ( child, scene, parent ) {
  16987. var matrixWorldInverse = new THREE.Matrix4();
  16988. matrixWorldInverse.getInverse( parent.matrixWorld );
  16989. child.applyMatrix( matrixWorldInverse );
  16990. scene.remove( child );
  16991. parent.add( child );
  16992. }
  16993. };
  16994. // File:src/extras/FontUtils.js
  16995. /**
  16996. * @author zz85 / http://www.lab4games.net/zz85/blog
  16997. * @author alteredq / http://alteredqualia.com/
  16998. *
  16999. * For Text operations in three.js (See TextGeometry)
  17000. *
  17001. * It uses techniques used in:
  17002. *
  17003. * Triangulation ported from AS3
  17004. * Simple Polygon Triangulation
  17005. * http://actionsnippet.com/?p=1462
  17006. *
  17007. * A Method to triangulate shapes with holes
  17008. * http://www.sakri.net/blog/2009/06/12/an-approach-to-triangulating-polygons-with-holes/
  17009. *
  17010. */
  17011. THREE.FontUtils = {
  17012. faces: {},
  17013. // Just for now. face[weight][style]
  17014. face: 'helvetiker',
  17015. weight: 'normal',
  17016. style: 'normal',
  17017. size: 150,
  17018. divisions: 10,
  17019. getFace: function () {
  17020. try {
  17021. return this.faces[ this.face.toLowerCase() ][ this.weight ][ this.style ];
  17022. } catch ( e ) {
  17023. throw "The font " + this.face + " with " + this.weight + " weight and " + this.style + " style is missing."
  17024. }
  17025. },
  17026. loadFace: function ( data ) {
  17027. var family = data.familyName.toLowerCase();
  17028. var ThreeFont = this;
  17029. ThreeFont.faces[ family ] = ThreeFont.faces[ family ] || {};
  17030. ThreeFont.faces[ family ][ data.cssFontWeight ] = ThreeFont.faces[ family ][ data.cssFontWeight ] || {};
  17031. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  17032. ThreeFont.faces[ family ][ data.cssFontWeight ][ data.cssFontStyle ] = data;
  17033. return data;
  17034. },
  17035. drawText: function ( text ) {
  17036. // RenderText
  17037. var i,
  17038. face = this.getFace(),
  17039. scale = this.size / face.resolution,
  17040. offset = 0,
  17041. chars = String( text ).split( '' ),
  17042. length = chars.length;
  17043. var fontPaths = [];
  17044. for ( i = 0; i < length; i ++ ) {
  17045. var path = new THREE.Path();
  17046. var ret = this.extractGlyphPoints( chars[ i ], face, scale, offset, path );
  17047. offset += ret.offset;
  17048. fontPaths.push( ret.path );
  17049. }
  17050. // get the width
  17051. var width = offset / 2;
  17052. //
  17053. // for ( p = 0; p < allPts.length; p++ ) {
  17054. //
  17055. // allPts[ p ].x -= width;
  17056. //
  17057. // }
  17058. //var extract = this.extractPoints( allPts, characterPts );
  17059. //extract.contour = allPts;
  17060. //extract.paths = fontPaths;
  17061. //extract.offset = width;
  17062. return { paths: fontPaths, offset: width };
  17063. },
  17064. extractGlyphPoints: function ( c, face, scale, offset, path ) {
  17065. var pts = [];
  17066. var i, i2, divisions,
  17067. outline, action, length,
  17068. scaleX, scaleY,
  17069. x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2,
  17070. laste,
  17071. glyph = face.glyphs[ c ] || face.glyphs[ '?' ];
  17072. if ( ! glyph ) return;
  17073. if ( glyph.o ) {
  17074. outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  17075. length = outline.length;
  17076. scaleX = scale;
  17077. scaleY = scale;
  17078. for ( i = 0; i < length; ) {
  17079. action = outline[ i ++ ];
  17080. //console.log( action );
  17081. switch ( action ) {
  17082. case 'm':
  17083. // Move To
  17084. x = outline[ i ++ ] * scaleX + offset;
  17085. y = outline[ i ++ ] * scaleY;
  17086. path.moveTo( x, y );
  17087. break;
  17088. case 'l':
  17089. // Line To
  17090. x = outline[ i ++ ] * scaleX + offset;
  17091. y = outline[ i ++ ] * scaleY;
  17092. path.lineTo( x, y );
  17093. break;
  17094. case 'q':
  17095. // QuadraticCurveTo
  17096. cpx = outline[ i ++ ] * scaleX + offset;
  17097. cpy = outline[ i ++ ] * scaleY;
  17098. cpx1 = outline[ i ++ ] * scaleX + offset;
  17099. cpy1 = outline[ i ++ ] * scaleY;
  17100. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  17101. laste = pts[ pts.length - 1 ];
  17102. if ( laste ) {
  17103. cpx0 = laste.x;
  17104. cpy0 = laste.y;
  17105. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  17106. var t = i2 / divisions;
  17107. THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  17108. THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  17109. }
  17110. }
  17111. break;
  17112. case 'b':
  17113. // Cubic Bezier Curve
  17114. cpx = outline[ i ++ ] * scaleX + offset;
  17115. cpy = outline[ i ++ ] * scaleY;
  17116. cpx1 = outline[ i ++ ] * scaleX + offset;
  17117. cpy1 = outline[ i ++ ] * scaleY;
  17118. cpx2 = outline[ i ++ ] * scaleX + offset;
  17119. cpy2 = outline[ i ++ ] * scaleY;
  17120. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  17121. laste = pts[ pts.length - 1 ];
  17122. if ( laste ) {
  17123. cpx0 = laste.x;
  17124. cpy0 = laste.y;
  17125. for ( i2 = 1, divisions = this.divisions; i2 <= divisions; i2 ++ ) {
  17126. var t = i2 / divisions;
  17127. THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  17128. THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  17129. }
  17130. }
  17131. break;
  17132. }
  17133. }
  17134. }
  17135. return { offset: glyph.ha * scale, path: path };
  17136. }
  17137. };
  17138. THREE.FontUtils.generateShapes = function ( text, parameters ) {
  17139. // Parameters
  17140. parameters = parameters || {};
  17141. var size = parameters.size !== undefined ? parameters.size : 100;
  17142. var curveSegments = parameters.curveSegments !== undefined ? parameters.curveSegments : 4;
  17143. var font = parameters.font !== undefined ? parameters.font : 'helvetiker';
  17144. var weight = parameters.weight !== undefined ? parameters.weight : 'normal';
  17145. var style = parameters.style !== undefined ? parameters.style : 'normal';
  17146. THREE.FontUtils.size = size;
  17147. THREE.FontUtils.divisions = curveSegments;
  17148. THREE.FontUtils.face = font;
  17149. THREE.FontUtils.weight = weight;
  17150. THREE.FontUtils.style = style;
  17151. // Get a Font data json object
  17152. var data = THREE.FontUtils.drawText( text );
  17153. var paths = data.paths;
  17154. var shapes = [];
  17155. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  17156. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  17157. }
  17158. return shapes;
  17159. };
  17160. /**
  17161. * This code is a quick port of code written in C++ which was submitted to
  17162. * flipcode.com by John W. Ratcliff // July 22, 2000
  17163. * See original code and more information here:
  17164. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  17165. *
  17166. * ported to actionscript by Zevan Rosser
  17167. * www.actionsnippet.com
  17168. *
  17169. * ported to javascript by Joshua Koo
  17170. * http://www.lab4games.net/zz85/blog
  17171. *
  17172. */
  17173. ( function ( namespace ) {
  17174. var EPSILON = 0.0000000001;
  17175. // takes in an contour array and returns
  17176. function process( contour, indices ) {
  17177. var n = contour.length;
  17178. if ( n < 3 ) return null;
  17179. var result = [],
  17180. verts = [],
  17181. vertIndices = [];
  17182. /* we want a counter-clockwise polygon in verts */
  17183. var u, v, w;
  17184. if ( area( contour ) > 0.0 ) {
  17185. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  17186. } else {
  17187. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  17188. }
  17189. var nv = n;
  17190. /* remove nv - 2 vertices, creating 1 triangle every time */
  17191. var count = 2 * nv; /* error detection */
  17192. for ( v = nv - 1; nv > 2; ) {
  17193. /* if we loop, it is probably a non-simple polygon */
  17194. if ( ( count -- ) <= 0 ) {
  17195. //** Triangulate: ERROR - probable bad polygon!
  17196. //throw ( "Warning, unable to triangulate polygon!" );
  17197. //return null;
  17198. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  17199. console.warn( 'THREE.FontUtils: Warning, unable to triangulate polygon! in Triangulate.process()' );
  17200. if ( indices ) return vertIndices;
  17201. return result;
  17202. }
  17203. /* three consecutive vertices in current polygon, <u,v,w> */
  17204. u = v; if ( nv <= u ) u = 0; /* previous */
  17205. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  17206. w = v + 1; if ( nv <= w ) w = 0; /* next */
  17207. if ( snip( contour, u, v, w, nv, verts ) ) {
  17208. var a, b, c, s, t;
  17209. /* true names of the vertices */
  17210. a = verts[ u ];
  17211. b = verts[ v ];
  17212. c = verts[ w ];
  17213. /* output Triangle */
  17214. result.push( [ contour[ a ],
  17215. contour[ b ],
  17216. contour[ c ] ] );
  17217. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  17218. /* remove v from the remaining polygon */
  17219. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  17220. verts[ s ] = verts[ t ];
  17221. }
  17222. nv --;
  17223. /* reset error detection counter */
  17224. count = 2 * nv;
  17225. }
  17226. }
  17227. if ( indices ) return vertIndices;
  17228. return result;
  17229. }
  17230. // calculate area of the contour polygon
  17231. function area( contour ) {
  17232. var n = contour.length;
  17233. var a = 0.0;
  17234. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  17235. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  17236. }
  17237. return a * 0.5;
  17238. }
  17239. function snip( contour, u, v, w, n, verts ) {
  17240. var p;
  17241. var ax, ay, bx, by;
  17242. var cx, cy, px, py;
  17243. ax = contour[ verts[ u ] ].x;
  17244. ay = contour[ verts[ u ] ].y;
  17245. bx = contour[ verts[ v ] ].x;
  17246. by = contour[ verts[ v ] ].y;
  17247. cx = contour[ verts[ w ] ].x;
  17248. cy = contour[ verts[ w ] ].y;
  17249. if ( EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  17250. var aX, aY, bX, bY, cX, cY;
  17251. var apx, apy, bpx, bpy, cpx, cpy;
  17252. var cCROSSap, bCROSScp, aCROSSbp;
  17253. aX = cx - bx; aY = cy - by;
  17254. bX = ax - cx; bY = ay - cy;
  17255. cX = bx - ax; cY = by - ay;
  17256. for ( p = 0; p < n; p ++ ) {
  17257. px = contour[ verts[ p ] ].x;
  17258. py = contour[ verts[ p ] ].y;
  17259. if ( ( ( px === ax ) && ( py === ay ) ) ||
  17260. ( ( px === bx ) && ( py === by ) ) ||
  17261. ( ( px === cx ) && ( py === cy ) ) ) continue;
  17262. apx = px - ax; apy = py - ay;
  17263. bpx = px - bx; bpy = py - by;
  17264. cpx = px - cx; cpy = py - cy;
  17265. // see if p is inside triangle abc
  17266. aCROSSbp = aX * bpy - aY * bpx;
  17267. cCROSSap = cX * apy - cY * apx;
  17268. bCROSScp = bX * cpy - bY * cpx;
  17269. if ( ( aCROSSbp >= - EPSILON ) && ( bCROSScp >= - EPSILON ) && ( cCROSSap >= - EPSILON ) ) return false;
  17270. }
  17271. return true;
  17272. }
  17273. namespace.Triangulate = process;
  17274. namespace.Triangulate.area = area;
  17275. return namespace;
  17276. } )( THREE.FontUtils );
  17277. // To use the typeface.js face files, hook up the API
  17278. THREE.typeface_js = { faces: THREE.FontUtils.faces, loadFace: THREE.FontUtils.loadFace };
  17279. if ( typeof self !== 'undefined' ) self._typeface_js = THREE.typeface_js;
  17280. // File:src/extras/audio/Audio.js
  17281. /**
  17282. * @author mrdoob / http://mrdoob.com/
  17283. */
  17284. THREE.Audio = function ( listener ) {
  17285. THREE.Object3D.call( this );
  17286. this.type = 'Audio';
  17287. this.context = listener.context;
  17288. this.source = this.context.createBufferSource();
  17289. this.source.onended = this.onEnded.bind( this );
  17290. this.gain = this.context.createGain();
  17291. this.gain.connect( this.context.destination );
  17292. this.panner = this.context.createPanner();
  17293. this.panner.connect( this.gain );
  17294. this.autoplay = false;
  17295. this.startTime = 0;
  17296. this.playbackRate = 1;
  17297. this.isPlaying = false;
  17298. };
  17299. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  17300. THREE.Audio.prototype.constructor = THREE.Audio;
  17301. THREE.Audio.prototype.load = function ( file ) {
  17302. var scope = this;
  17303. var request = new XMLHttpRequest();
  17304. request.open( 'GET', file, true );
  17305. request.responseType = 'arraybuffer';
  17306. request.onload = function ( e ) {
  17307. scope.context.decodeAudioData( this.response, function ( buffer ) {
  17308. scope.source.buffer = buffer;
  17309. if ( scope.autoplay ) scope.play();
  17310. } );
  17311. };
  17312. request.send();
  17313. return this;
  17314. };
  17315. THREE.Audio.prototype.play = function () {
  17316. if ( this.isPlaying === true ) {
  17317. console.warn( 'THREE.Audio: Audio is already playing.' );
  17318. return;
  17319. }
  17320. var source = this.context.createBufferSource();
  17321. source.buffer = this.source.buffer;
  17322. source.loop = this.source.loop;
  17323. source.onended = this.source.onended;
  17324. source.start( 0, this.startTime );
  17325. source.playbackRate.value = this.playbackRate;
  17326. this.isPlaying = true;
  17327. this.source = source;
  17328. this.connect();
  17329. };
  17330. THREE.Audio.prototype.pause = function () {
  17331. this.source.stop();
  17332. this.startTime = this.context.currentTime;
  17333. };
  17334. THREE.Audio.prototype.stop = function () {
  17335. this.source.stop();
  17336. this.startTime = 0;
  17337. };
  17338. THREE.Audio.prototype.connect = function () {
  17339. if ( this.filter !== undefined ) {
  17340. this.source.connect( this.filter );
  17341. this.filter.connect( this.panner );
  17342. } else {
  17343. this.source.connect( this.panner );
  17344. }
  17345. };
  17346. THREE.Audio.prototype.disconnect = function () {
  17347. if ( this.filter !== undefined ) {
  17348. this.source.disconnect( this.filter );
  17349. this.filter.disconnect( this.panner );
  17350. } else {
  17351. this.source.disconnect( this.panner );
  17352. }
  17353. };
  17354. THREE.Audio.prototype.setFilter = function ( value ) {
  17355. if ( this.isPlaying === true ) {
  17356. this.disconnect();
  17357. this.filter = value;
  17358. this.connect();
  17359. } else {
  17360. this.filter = value;
  17361. }
  17362. };
  17363. THREE.Audio.prototype.getFilter = function () {
  17364. return this.filter;
  17365. };
  17366. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  17367. this.playbackRate = value;
  17368. if ( this.isPlaying === true ) {
  17369. this.source.playbackRate.value = this.playbackRate;
  17370. }
  17371. };
  17372. THREE.Audio.prototype.getPlaybackRate = function () {
  17373. return this.playbackRate;
  17374. };
  17375. THREE.Audio.prototype.onEnded = function() {
  17376. this.isPlaying = false;
  17377. };
  17378. THREE.Audio.prototype.setLoop = function ( value ) {
  17379. this.source.loop = value;
  17380. };
  17381. THREE.Audio.prototype.getLoop = function () {
  17382. return this.source.loop;
  17383. };
  17384. THREE.Audio.prototype.setRefDistance = function ( value ) {
  17385. this.panner.refDistance = value;
  17386. };
  17387. THREE.Audio.prototype.getRefDistance = function () {
  17388. return this.panner.refDistance;
  17389. };
  17390. THREE.Audio.prototype.setRolloffFactor = function ( value ) {
  17391. this.panner.rolloffFactor = value;
  17392. };
  17393. THREE.Audio.prototype.getRolloffFactor = function () {
  17394. return this.panner.rolloffFactor;
  17395. };
  17396. THREE.Audio.prototype.setVolume = function ( value ) {
  17397. this.gain.gain.value = value;
  17398. };
  17399. THREE.Audio.prototype.getVolume = function () {
  17400. return this.gain.gain.value;
  17401. };
  17402. THREE.Audio.prototype.updateMatrixWorld = ( function () {
  17403. var position = new THREE.Vector3();
  17404. return function updateMatrixWorld( force ) {
  17405. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17406. position.setFromMatrixPosition( this.matrixWorld );
  17407. this.panner.setPosition( position.x, position.y, position.z );
  17408. };
  17409. } )();
  17410. // File:src/extras/audio/AudioListener.js
  17411. /**
  17412. * @author mrdoob / http://mrdoob.com/
  17413. */
  17414. THREE.AudioListener = function () {
  17415. THREE.Object3D.call( this );
  17416. this.type = 'AudioListener';
  17417. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  17418. };
  17419. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  17420. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  17421. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  17422. var position = new THREE.Vector3();
  17423. var quaternion = new THREE.Quaternion();
  17424. var scale = new THREE.Vector3();
  17425. var orientation = new THREE.Vector3();
  17426. return function updateMatrixWorld( force ) {
  17427. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  17428. var listener = this.context.listener;
  17429. var up = this.up;
  17430. this.matrixWorld.decompose( position, quaternion, scale );
  17431. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  17432. listener.setPosition( position.x, position.y, position.z );
  17433. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  17434. };
  17435. } )();
  17436. // File:src/extras/core/Curve.js
  17437. /**
  17438. * @author zz85 / http://www.lab4games.net/zz85/blog
  17439. * Extensible curve object
  17440. *
  17441. * Some common of Curve methods
  17442. * .getPoint(t), getTangent(t)
  17443. * .getPointAt(u), getTagentAt(u)
  17444. * .getPoints(), .getSpacedPoints()
  17445. * .getLength()
  17446. * .updateArcLengths()
  17447. *
  17448. * This following classes subclasses THREE.Curve:
  17449. *
  17450. * -- 2d classes --
  17451. * THREE.LineCurve
  17452. * THREE.QuadraticBezierCurve
  17453. * THREE.CubicBezierCurve
  17454. * THREE.SplineCurve
  17455. * THREE.ArcCurve
  17456. * THREE.EllipseCurve
  17457. *
  17458. * -- 3d classes --
  17459. * THREE.LineCurve3
  17460. * THREE.QuadraticBezierCurve3
  17461. * THREE.CubicBezierCurve3
  17462. * THREE.SplineCurve3
  17463. * THREE.ClosedSplineCurve3
  17464. *
  17465. * A series of curves can be represented as a THREE.CurvePath
  17466. *
  17467. **/
  17468. /**************************************************************
  17469. * Abstract Curve base class
  17470. **************************************************************/
  17471. THREE.Curve = function () {
  17472. };
  17473. THREE.Curve.prototype = {
  17474. constructor: THREE.Curve,
  17475. // Virtual base class method to overwrite and implement in subclasses
  17476. // - t [0 .. 1]
  17477. getPoint: function ( t ) {
  17478. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  17479. return null;
  17480. },
  17481. // Get point at relative position in curve according to arc length
  17482. // - u [0 .. 1]
  17483. getPointAt: function ( u ) {
  17484. var t = this.getUtoTmapping( u );
  17485. return this.getPoint( t );
  17486. },
  17487. // Get sequence of points using getPoint( t )
  17488. getPoints: function ( divisions ) {
  17489. if ( ! divisions ) divisions = 5;
  17490. var d, pts = [];
  17491. for ( d = 0; d <= divisions; d ++ ) {
  17492. pts.push( this.getPoint( d / divisions ) );
  17493. }
  17494. return pts;
  17495. },
  17496. // Get sequence of points using getPointAt( u )
  17497. getSpacedPoints: function ( divisions ) {
  17498. if ( ! divisions ) divisions = 5;
  17499. var d, pts = [];
  17500. for ( d = 0; d <= divisions; d ++ ) {
  17501. pts.push( this.getPointAt( d / divisions ) );
  17502. }
  17503. return pts;
  17504. },
  17505. // Get total curve arc length
  17506. getLength: function () {
  17507. var lengths = this.getLengths();
  17508. return lengths[ lengths.length - 1 ];
  17509. },
  17510. // Get list of cumulative segment lengths
  17511. getLengths: function ( divisions ) {
  17512. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  17513. if ( this.cacheArcLengths
  17514. && ( this.cacheArcLengths.length === divisions + 1 )
  17515. && ! this.needsUpdate ) {
  17516. //console.log( "cached", this.cacheArcLengths );
  17517. return this.cacheArcLengths;
  17518. }
  17519. this.needsUpdate = false;
  17520. var cache = [];
  17521. var current, last = this.getPoint( 0 );
  17522. var p, sum = 0;
  17523. cache.push( 0 );
  17524. for ( p = 1; p <= divisions; p ++ ) {
  17525. current = this.getPoint ( p / divisions );
  17526. sum += current.distanceTo( last );
  17527. cache.push( sum );
  17528. last = current;
  17529. }
  17530. this.cacheArcLengths = cache;
  17531. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  17532. },
  17533. updateArcLengths: function() {
  17534. this.needsUpdate = true;
  17535. this.getLengths();
  17536. },
  17537. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  17538. getUtoTmapping: function ( u, distance ) {
  17539. var arcLengths = this.getLengths();
  17540. var i = 0, il = arcLengths.length;
  17541. var targetArcLength; // The targeted u distance value to get
  17542. if ( distance ) {
  17543. targetArcLength = distance;
  17544. } else {
  17545. targetArcLength = u * arcLengths[ il - 1 ];
  17546. }
  17547. //var time = Date.now();
  17548. // binary search for the index with largest value smaller than target u distance
  17549. var low = 0, high = il - 1, comparison;
  17550. while ( low <= high ) {
  17551. 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
  17552. comparison = arcLengths[ i ] - targetArcLength;
  17553. if ( comparison < 0 ) {
  17554. low = i + 1;
  17555. } else if ( comparison > 0 ) {
  17556. high = i - 1;
  17557. } else {
  17558. high = i;
  17559. break;
  17560. // DONE
  17561. }
  17562. }
  17563. i = high;
  17564. //console.log('b' , i, low, high, Date.now()- time);
  17565. if ( arcLengths[ i ] === targetArcLength ) {
  17566. var t = i / ( il - 1 );
  17567. return t;
  17568. }
  17569. // we could get finer grain at lengths, or use simple interpolation between two points
  17570. var lengthBefore = arcLengths[ i ];
  17571. var lengthAfter = arcLengths[ i + 1 ];
  17572. var segmentLength = lengthAfter - lengthBefore;
  17573. // determine where we are between the 'before' and 'after' points
  17574. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  17575. // add that fractional amount to t
  17576. var t = ( i + segmentFraction ) / ( il - 1 );
  17577. return t;
  17578. },
  17579. // Returns a unit vector tangent at t
  17580. // In case any sub curve does not implement its tangent derivation,
  17581. // 2 points a small delta apart will be used to find its gradient
  17582. // which seems to give a reasonable approximation
  17583. getTangent: function( t ) {
  17584. var delta = 0.0001;
  17585. var t1 = t - delta;
  17586. var t2 = t + delta;
  17587. // Capping in case of danger
  17588. if ( t1 < 0 ) t1 = 0;
  17589. if ( t2 > 1 ) t2 = 1;
  17590. var pt1 = this.getPoint( t1 );
  17591. var pt2 = this.getPoint( t2 );
  17592. var vec = pt2.clone().sub( pt1 );
  17593. return vec.normalize();
  17594. },
  17595. getTangentAt: function ( u ) {
  17596. var t = this.getUtoTmapping( u );
  17597. return this.getTangent( t );
  17598. }
  17599. }
  17600. /**************************************************************
  17601. * Utils
  17602. **************************************************************/
  17603. THREE.Curve.Utils = {
  17604. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  17605. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  17606. },
  17607. // Puay Bing, thanks for helping with this derivative!
  17608. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  17609. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  17610. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  17611. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  17612. 3 * t * t * p3;
  17613. },
  17614. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  17615. // To check if my formulas are correct
  17616. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  17617. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  17618. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  17619. var h11 = 3 * t * t - 2 * t; // t3 − t2
  17620. return h00 + h10 + h01 + h11;
  17621. },
  17622. // Catmull-Rom
  17623. interpolate: function( p0, p1, p2, p3, t ) {
  17624. var v0 = ( p2 - p0 ) * 0.5;
  17625. var v1 = ( p3 - p1 ) * 0.5;
  17626. var t2 = t * t;
  17627. var t3 = t * t2;
  17628. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  17629. }
  17630. };
  17631. // TODO: Transformation for Curves?
  17632. /**************************************************************
  17633. * 3D Curves
  17634. **************************************************************/
  17635. // A Factory method for creating new curve subclasses
  17636. THREE.Curve.create = function ( constructor, getPointFunc ) {
  17637. constructor.prototype = Object.create( THREE.Curve.prototype );
  17638. constructor.prototype.constructor = constructor;
  17639. constructor.prototype.getPoint = getPointFunc;
  17640. return constructor;
  17641. };
  17642. // File:src/extras/core/CurvePath.js
  17643. /**
  17644. * @author zz85 / http://www.lab4games.net/zz85/blog
  17645. *
  17646. **/
  17647. /**************************************************************
  17648. * Curved Path - a curve path is simply a array of connected
  17649. * curves, but retains the api of a curve
  17650. **************************************************************/
  17651. THREE.CurvePath = function () {
  17652. this.curves = [];
  17653. this.bends = [];
  17654. this.autoClose = false; // Automatically closes the path
  17655. };
  17656. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  17657. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  17658. THREE.CurvePath.prototype.add = function ( curve ) {
  17659. this.curves.push( curve );
  17660. };
  17661. /*
  17662. THREE.CurvePath.prototype.checkConnection = function() {
  17663. // TODO
  17664. // If the ending of curve is not connected to the starting
  17665. // or the next curve, then, this is not a real path
  17666. };
  17667. */
  17668. THREE.CurvePath.prototype.closePath = function() {
  17669. // TODO Test
  17670. // and verify for vector3 (needs to implement equals)
  17671. // Add a line curve if start and end of lines are not connected
  17672. var startPoint = this.curves[ 0 ].getPoint( 0 );
  17673. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  17674. if ( ! startPoint.equals( endPoint ) ) {
  17675. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  17676. }
  17677. };
  17678. // To get accurate point with reference to
  17679. // entire path distance at time t,
  17680. // following has to be done:
  17681. // 1. Length of each sub path have to be known
  17682. // 2. Locate and identify type of curve
  17683. // 3. Get t for the curve
  17684. // 4. Return curve.getPointAt(t')
  17685. THREE.CurvePath.prototype.getPoint = function( t ) {
  17686. var d = t * this.getLength();
  17687. var curveLengths = this.getCurveLengths();
  17688. var i = 0;
  17689. // To think about boundaries points.
  17690. while ( i < curveLengths.length ) {
  17691. if ( curveLengths[ i ] >= d ) {
  17692. var diff = curveLengths[ i ] - d;
  17693. var curve = this.curves[ i ];
  17694. var u = 1 - diff / curve.getLength();
  17695. return curve.getPointAt( u );
  17696. }
  17697. i ++;
  17698. }
  17699. return null;
  17700. // loop where sum != 0, sum > d , sum+1 <d
  17701. };
  17702. /*
  17703. THREE.CurvePath.prototype.getTangent = function( t ) {
  17704. };
  17705. */
  17706. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  17707. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  17708. // getPoint() depends on getLength
  17709. THREE.CurvePath.prototype.getLength = function() {
  17710. var lens = this.getCurveLengths();
  17711. return lens[ lens.length - 1 ];
  17712. };
  17713. // Compute lengths and cache them
  17714. // We cannot overwrite getLengths() because UtoT mapping uses it.
  17715. THREE.CurvePath.prototype.getCurveLengths = function() {
  17716. // We use cache values if curves and cache array are same length
  17717. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  17718. return this.cacheLengths;
  17719. }
  17720. // Get length of sub-curve
  17721. // Push sums into cached array
  17722. var lengths = [], sums = 0;
  17723. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  17724. sums += this.curves[ i ].getLength();
  17725. lengths.push( sums );
  17726. }
  17727. this.cacheLengths = lengths;
  17728. return lengths;
  17729. };
  17730. // Returns min and max coordinates
  17731. THREE.CurvePath.prototype.getBoundingBox = function () {
  17732. var points = this.getPoints();
  17733. var maxX, maxY, maxZ;
  17734. var minX, minY, minZ;
  17735. maxX = maxY = Number.NEGATIVE_INFINITY;
  17736. minX = minY = Number.POSITIVE_INFINITY;
  17737. var v3 = points[ 0 ] instanceof THREE.Vector3;
  17738. var sum = v3 ? new THREE.Vector3() : new THREE.Vector2();
  17739. for ( var i = 0, l = points.length; i < l; i ++ ) {
  17740. var p = points[ i ];
  17741. if ( p.x > maxX ) maxX = p.x;
  17742. else if ( p.x < minX ) minX = p.x;
  17743. if ( p.y > maxY ) maxY = p.y;
  17744. else if ( p.y < minY ) minY = p.y;
  17745. if ( v3 ) {
  17746. if ( p.z > maxZ ) maxZ = p.z;
  17747. else if ( p.z < minZ ) minZ = p.z;
  17748. }
  17749. sum.add( p );
  17750. }
  17751. var ret = {
  17752. minX: minX,
  17753. minY: minY,
  17754. maxX: maxX,
  17755. maxY: maxY
  17756. };
  17757. if ( v3 ) {
  17758. ret.maxZ = maxZ;
  17759. ret.minZ = minZ;
  17760. }
  17761. return ret;
  17762. };
  17763. /**************************************************************
  17764. * Create Geometries Helpers
  17765. **************************************************************/
  17766. /// Generate geometry from path points (for Line or Points objects)
  17767. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  17768. var pts = this.getPoints( divisions, true );
  17769. return this.createGeometry( pts );
  17770. };
  17771. // Generate geometry from equidistant sampling along the path
  17772. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  17773. var pts = this.getSpacedPoints( divisions, true );
  17774. return this.createGeometry( pts );
  17775. };
  17776. THREE.CurvePath.prototype.createGeometry = function( points ) {
  17777. var geometry = new THREE.Geometry();
  17778. for ( var i = 0, l = points.length; i < l; i ++ ) {
  17779. var point = points[ i ];
  17780. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  17781. }
  17782. return geometry;
  17783. };
  17784. /**************************************************************
  17785. * Bend / Wrap Helper Methods
  17786. **************************************************************/
  17787. // Wrap path / Bend modifiers?
  17788. THREE.CurvePath.prototype.addWrapPath = function ( bendpath ) {
  17789. this.bends.push( bendpath );
  17790. };
  17791. THREE.CurvePath.prototype.getTransformedPoints = function( segments, bends ) {
  17792. var oldPts = this.getPoints( segments ); // getPoints getSpacedPoints
  17793. if ( ! bends ) {
  17794. bends = this.bends;
  17795. }
  17796. for ( var i = 0, l = bends.length; i < l; i ++ ) {
  17797. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  17798. }
  17799. return oldPts;
  17800. };
  17801. THREE.CurvePath.prototype.getTransformedSpacedPoints = function( segments, bends ) {
  17802. var oldPts = this.getSpacedPoints( segments );
  17803. if ( ! bends ) {
  17804. bends = this.bends;
  17805. }
  17806. for ( var i = 0, l = bends.length; i < l; i ++ ) {
  17807. oldPts = this.getWrapPoints( oldPts, bends[ i ] );
  17808. }
  17809. return oldPts;
  17810. };
  17811. // This returns getPoints() bend/wrapped around the contour of a path.
  17812. // Read http://www.planetclegg.com/projects/WarpingTextToSplines.html
  17813. THREE.CurvePath.prototype.getWrapPoints = function ( oldPts, path ) {
  17814. var bounds = this.getBoundingBox();
  17815. for ( var i = 0, l = oldPts.length; i < l; i ++ ) {
  17816. var p = oldPts[ i ];
  17817. var oldX = p.x;
  17818. var oldY = p.y;
  17819. var xNorm = oldX / bounds.maxX;
  17820. // If using actual distance, for length > path, requires line extrusions
  17821. //xNorm = path.getUtoTmapping(xNorm, oldX); // 3 styles. 1) wrap stretched. 2) wrap stretch by arc length 3) warp by actual distance
  17822. xNorm = path.getUtoTmapping( xNorm, oldX );
  17823. // check for out of bounds?
  17824. var pathPt = path.getPoint( xNorm );
  17825. var normal = path.getTangent( xNorm );
  17826. normal.set( - normal.y, normal.x ).multiplyScalar( oldY );
  17827. p.x = pathPt.x + normal.x;
  17828. p.y = pathPt.y + normal.y;
  17829. }
  17830. return oldPts;
  17831. };
  17832. // File:src/extras/core/Path.js
  17833. /**
  17834. * @author zz85 / http://www.lab4games.net/zz85/blog
  17835. * Creates free form 2d path using series of points, lines or curves.
  17836. *
  17837. **/
  17838. THREE.Path = function ( points ) {
  17839. THREE.CurvePath.call( this );
  17840. this.actions = [];
  17841. if ( points ) {
  17842. this.fromPoints( points );
  17843. }
  17844. };
  17845. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  17846. THREE.Path.prototype.constructor = THREE.Path;
  17847. THREE.PathActions = {
  17848. MOVE_TO: 'moveTo',
  17849. LINE_TO: 'lineTo',
  17850. QUADRATIC_CURVE_TO: 'quadraticCurveTo', // Bezier quadratic curve
  17851. BEZIER_CURVE_TO: 'bezierCurveTo', // Bezier cubic curve
  17852. CSPLINE_THRU: 'splineThru', // Catmull-Rom spline
  17853. ARC: 'arc', // Circle
  17854. ELLIPSE: 'ellipse'
  17855. };
  17856. // TODO Clean up PATH API
  17857. // Create path using straight lines to connect all points
  17858. // - vectors: array of Vector2
  17859. THREE.Path.prototype.fromPoints = function ( vectors ) {
  17860. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  17861. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  17862. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  17863. }
  17864. };
  17865. // startPath() endPath()?
  17866. THREE.Path.prototype.moveTo = function ( x, y ) {
  17867. var args = Array.prototype.slice.call( arguments );
  17868. this.actions.push( { action: THREE.PathActions.MOVE_TO, args: args } );
  17869. };
  17870. THREE.Path.prototype.lineTo = function ( x, y ) {
  17871. var args = Array.prototype.slice.call( arguments );
  17872. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17873. var x0 = lastargs[ lastargs.length - 2 ];
  17874. var y0 = lastargs[ lastargs.length - 1 ];
  17875. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  17876. this.curves.push( curve );
  17877. this.actions.push( { action: THREE.PathActions.LINE_TO, args: args } );
  17878. };
  17879. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  17880. var args = Array.prototype.slice.call( arguments );
  17881. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17882. var x0 = lastargs[ lastargs.length - 2 ];
  17883. var y0 = lastargs[ lastargs.length - 1 ];
  17884. var curve = new THREE.QuadraticBezierCurve(
  17885. new THREE.Vector2( x0, y0 ),
  17886. new THREE.Vector2( aCPx, aCPy ),
  17887. new THREE.Vector2( aX, aY )
  17888. );
  17889. this.curves.push( curve );
  17890. this.actions.push( { action: THREE.PathActions.QUADRATIC_CURVE_TO, args: args } );
  17891. };
  17892. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  17893. var args = Array.prototype.slice.call( arguments );
  17894. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17895. var x0 = lastargs[ lastargs.length - 2 ];
  17896. var y0 = lastargs[ lastargs.length - 1 ];
  17897. var curve = new THREE.CubicBezierCurve(
  17898. new THREE.Vector2( x0, y0 ),
  17899. new THREE.Vector2( aCP1x, aCP1y ),
  17900. new THREE.Vector2( aCP2x, aCP2y ),
  17901. new THREE.Vector2( aX, aY )
  17902. );
  17903. this.curves.push( curve );
  17904. this.actions.push( { action: THREE.PathActions.BEZIER_CURVE_TO, args: args } );
  17905. };
  17906. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  17907. var args = Array.prototype.slice.call( arguments );
  17908. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17909. var x0 = lastargs[ lastargs.length - 2 ];
  17910. var y0 = lastargs[ lastargs.length - 1 ];
  17911. var npts = [ new THREE.Vector2( x0, y0 ) ];
  17912. Array.prototype.push.apply( npts, pts );
  17913. var curve = new THREE.SplineCurve( npts );
  17914. this.curves.push( curve );
  17915. this.actions.push( { action: THREE.PathActions.CSPLINE_THRU, args: args } );
  17916. };
  17917. // FUTURE: Change the API or follow canvas API?
  17918. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17919. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17920. var x0 = lastargs[ lastargs.length - 2 ];
  17921. var y0 = lastargs[ lastargs.length - 1 ];
  17922. this.absarc( aX + x0, aY + y0, aRadius,
  17923. aStartAngle, aEndAngle, aClockwise );
  17924. };
  17925. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  17926. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  17927. };
  17928. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17929. var lastargs = this.actions[ this.actions.length - 1 ].args;
  17930. var x0 = lastargs[ lastargs.length - 2 ];
  17931. var y0 = lastargs[ lastargs.length - 1 ];
  17932. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  17933. };
  17934. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  17935. var args = [
  17936. aX, aY,
  17937. xRadius, yRadius,
  17938. aStartAngle, aEndAngle,
  17939. aClockwise,
  17940. aRotation || 0 // aRotation is optional.
  17941. ];
  17942. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  17943. this.curves.push( curve );
  17944. var lastPoint = curve.getPoint( 1 );
  17945. args.push( lastPoint.x );
  17946. args.push( lastPoint.y );
  17947. this.actions.push( { action: THREE.PathActions.ELLIPSE, args: args } );
  17948. };
  17949. THREE.Path.prototype.getSpacedPoints = function ( divisions, closedPath ) {
  17950. if ( ! divisions ) divisions = 40;
  17951. var points = [];
  17952. for ( var i = 0; i < divisions; i ++ ) {
  17953. points.push( this.getPoint( i / divisions ) );
  17954. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  17955. }
  17956. // if ( closedPath ) {
  17957. //
  17958. // points.push( points[ 0 ] );
  17959. //
  17960. // }
  17961. return points;
  17962. };
  17963. /* Return an array of vectors based on contour of the path */
  17964. THREE.Path.prototype.getPoints = function( divisions, closedPath ) {
  17965. if ( this.useSpacedPoints ) {
  17966. return this.getSpacedPoints( divisions, closedPath );
  17967. }
  17968. divisions = divisions || 12;
  17969. var points = [];
  17970. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  17971. laste, tx, ty;
  17972. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  17973. var item = this.actions[ i ];
  17974. var action = item.action;
  17975. var args = item.args;
  17976. switch ( action ) {
  17977. case THREE.PathActions.MOVE_TO:
  17978. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17979. break;
  17980. case THREE.PathActions.LINE_TO:
  17981. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  17982. break;
  17983. case THREE.PathActions.QUADRATIC_CURVE_TO:
  17984. cpx = args[ 2 ];
  17985. cpy = args[ 3 ];
  17986. cpx1 = args[ 0 ];
  17987. cpy1 = args[ 1 ];
  17988. if ( points.length > 0 ) {
  17989. laste = points[ points.length - 1 ];
  17990. cpx0 = laste.x;
  17991. cpy0 = laste.y;
  17992. } else {
  17993. laste = this.actions[ i - 1 ].args;
  17994. cpx0 = laste[ laste.length - 2 ];
  17995. cpy0 = laste[ laste.length - 1 ];
  17996. }
  17997. for ( var j = 1; j <= divisions; j ++ ) {
  17998. var t = j / divisions;
  17999. tx = THREE.Shape.Utils.b2( t, cpx0, cpx1, cpx );
  18000. ty = THREE.Shape.Utils.b2( t, cpy0, cpy1, cpy );
  18001. points.push( new THREE.Vector2( tx, ty ) );
  18002. }
  18003. break;
  18004. case THREE.PathActions.BEZIER_CURVE_TO:
  18005. cpx = args[ 4 ];
  18006. cpy = args[ 5 ];
  18007. cpx1 = args[ 0 ];
  18008. cpy1 = args[ 1 ];
  18009. cpx2 = args[ 2 ];
  18010. cpy2 = args[ 3 ];
  18011. if ( points.length > 0 ) {
  18012. laste = points[ points.length - 1 ];
  18013. cpx0 = laste.x;
  18014. cpy0 = laste.y;
  18015. } else {
  18016. laste = this.actions[ i - 1 ].args;
  18017. cpx0 = laste[ laste.length - 2 ];
  18018. cpy0 = laste[ laste.length - 1 ];
  18019. }
  18020. for ( var j = 1; j <= divisions; j ++ ) {
  18021. var t = j / divisions;
  18022. tx = THREE.Shape.Utils.b3( t, cpx0, cpx1, cpx2, cpx );
  18023. ty = THREE.Shape.Utils.b3( t, cpy0, cpy1, cpy2, cpy );
  18024. points.push( new THREE.Vector2( tx, ty ) );
  18025. }
  18026. break;
  18027. case THREE.PathActions.CSPLINE_THRU:
  18028. laste = this.actions[ i - 1 ].args;
  18029. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  18030. var spts = [ last ];
  18031. var n = divisions * args[ 0 ].length;
  18032. spts = spts.concat( args[ 0 ] );
  18033. var spline = new THREE.SplineCurve( spts );
  18034. for ( var j = 1; j <= n; j ++ ) {
  18035. points.push( spline.getPointAt( j / n ) );
  18036. }
  18037. break;
  18038. case THREE.PathActions.ARC:
  18039. var aX = args[ 0 ], aY = args[ 1 ],
  18040. aRadius = args[ 2 ],
  18041. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  18042. aClockwise = !! args[ 5 ];
  18043. var deltaAngle = aEndAngle - aStartAngle;
  18044. var angle;
  18045. var tdivisions = divisions * 2;
  18046. for ( var j = 1; j <= tdivisions; j ++ ) {
  18047. var t = j / tdivisions;
  18048. if ( ! aClockwise ) {
  18049. t = 1 - t;
  18050. }
  18051. angle = aStartAngle + t * deltaAngle;
  18052. tx = aX + aRadius * Math.cos( angle );
  18053. ty = aY + aRadius * Math.sin( angle );
  18054. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  18055. points.push( new THREE.Vector2( tx, ty ) );
  18056. }
  18057. //console.log(points);
  18058. break;
  18059. case THREE.PathActions.ELLIPSE:
  18060. var aX = args[ 0 ], aY = args[ 1 ],
  18061. xRadius = args[ 2 ],
  18062. yRadius = args[ 3 ],
  18063. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  18064. aClockwise = !! args[ 6 ],
  18065. aRotation = args[ 7 ];
  18066. var deltaAngle = aEndAngle - aStartAngle;
  18067. var angle;
  18068. var tdivisions = divisions * 2;
  18069. var cos, sin;
  18070. if ( aRotation !== 0 ) {
  18071. cos = Math.cos( aRotation );
  18072. sin = Math.sin( aRotation );
  18073. }
  18074. for ( var j = 1; j <= tdivisions; j ++ ) {
  18075. var t = j / tdivisions;
  18076. if ( ! aClockwise ) {
  18077. t = 1 - t;
  18078. }
  18079. angle = aStartAngle + t * deltaAngle;
  18080. tx = aX + xRadius * Math.cos( angle );
  18081. ty = aY + yRadius * Math.sin( angle );
  18082. if ( aRotation !== 0 ) {
  18083. var x = tx, y = ty;
  18084. // Rotate the point about the center of the ellipse.
  18085. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  18086. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  18087. }
  18088. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  18089. points.push( new THREE.Vector2( tx, ty ) );
  18090. }
  18091. //console.log(points);
  18092. break;
  18093. } // end switch
  18094. }
  18095. // Normalize to remove the closing point by default.
  18096. var lastPoint = points[ points.length - 1 ];
  18097. var EPSILON = 0.0000000001;
  18098. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < EPSILON &&
  18099. Math.abs( lastPoint.y - points[ 0 ].y ) < EPSILON )
  18100. points.splice( points.length - 1, 1 );
  18101. if ( closedPath ) {
  18102. points.push( points[ 0 ] );
  18103. }
  18104. return points;
  18105. };
  18106. //
  18107. // Breaks path into shapes
  18108. //
  18109. // Assumptions (if parameter isCCW==true the opposite holds):
  18110. // - solid shapes are defined clockwise (CW)
  18111. // - holes are defined counterclockwise (CCW)
  18112. //
  18113. // If parameter noHoles==true:
  18114. // - all subPaths are regarded as solid shapes
  18115. // - definition order CW/CCW has no relevance
  18116. //
  18117. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  18118. function extractSubpaths( inActions ) {
  18119. var subPaths = [], lastPath = new THREE.Path();
  18120. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  18121. var item = inActions[ i ];
  18122. var args = item.args;
  18123. var action = item.action;
  18124. if ( action === THREE.PathActions.MOVE_TO ) {
  18125. if ( lastPath.actions.length !== 0 ) {
  18126. subPaths.push( lastPath );
  18127. lastPath = new THREE.Path();
  18128. }
  18129. }
  18130. lastPath[ action ].apply( lastPath, args );
  18131. }
  18132. if ( lastPath.actions.length !== 0 ) {
  18133. subPaths.push( lastPath );
  18134. }
  18135. // console.log(subPaths);
  18136. return subPaths;
  18137. }
  18138. function toShapesNoHoles( inSubpaths ) {
  18139. var shapes = [];
  18140. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  18141. var tmpPath = inSubpaths[ i ];
  18142. var tmpShape = new THREE.Shape();
  18143. tmpShape.actions = tmpPath.actions;
  18144. tmpShape.curves = tmpPath.curves;
  18145. shapes.push( tmpShape );
  18146. }
  18147. //console.log("shape", shapes);
  18148. return shapes;
  18149. }
  18150. function isPointInsidePolygon( inPt, inPolygon ) {
  18151. var EPSILON = 0.0000000001;
  18152. var polyLen = inPolygon.length;
  18153. // inPt on polygon contour => immediate success or
  18154. // toggling of inside/outside at every single! intersection point of an edge
  18155. // with the horizontal line through inPt, left of inPt
  18156. // not counting lowerY endpoints of edges and whole edges on that line
  18157. var inside = false;
  18158. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  18159. var edgeLowPt = inPolygon[ p ];
  18160. var edgeHighPt = inPolygon[ q ];
  18161. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  18162. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  18163. if ( Math.abs( edgeDy ) > EPSILON ) {
  18164. // not parallel
  18165. if ( edgeDy < 0 ) {
  18166. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  18167. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  18168. }
  18169. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  18170. if ( inPt.y === edgeLowPt.y ) {
  18171. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  18172. // continue; // no intersection or edgeLowPt => doesn't count !!!
  18173. } else {
  18174. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  18175. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  18176. if ( perpEdge < 0 ) continue;
  18177. inside = ! inside; // true intersection left of inPt
  18178. }
  18179. } else {
  18180. // parallel or collinear
  18181. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  18182. // edge lies on the same horizontal line as inPt
  18183. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  18184. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  18185. // continue;
  18186. }
  18187. }
  18188. return inside;
  18189. }
  18190. var subPaths = extractSubpaths( this.actions );
  18191. if ( subPaths.length === 0 ) return [];
  18192. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  18193. var solid, tmpPath, tmpShape, shapes = [];
  18194. if ( subPaths.length === 1 ) {
  18195. tmpPath = subPaths[ 0 ];
  18196. tmpShape = new THREE.Shape();
  18197. tmpShape.actions = tmpPath.actions;
  18198. tmpShape.curves = tmpPath.curves;
  18199. shapes.push( tmpShape );
  18200. return shapes;
  18201. }
  18202. var holesFirst = ! THREE.Shape.Utils.isClockWise( subPaths[ 0 ].getPoints() );
  18203. holesFirst = isCCW ? ! holesFirst : holesFirst;
  18204. // console.log("Holes first", holesFirst);
  18205. var betterShapeHoles = [];
  18206. var newShapes = [];
  18207. var newShapeHoles = [];
  18208. var mainIdx = 0;
  18209. var tmpPoints;
  18210. newShapes[ mainIdx ] = undefined;
  18211. newShapeHoles[ mainIdx ] = [];
  18212. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  18213. tmpPath = subPaths[ i ];
  18214. tmpPoints = tmpPath.getPoints();
  18215. solid = THREE.Shape.Utils.isClockWise( tmpPoints );
  18216. solid = isCCW ? ! solid : solid;
  18217. if ( solid ) {
  18218. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  18219. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  18220. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  18221. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  18222. if ( holesFirst ) mainIdx ++;
  18223. newShapeHoles[ mainIdx ] = [];
  18224. //console.log('cw', i);
  18225. } else {
  18226. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  18227. //console.log('ccw', i);
  18228. }
  18229. }
  18230. // only Holes? -> probably all Shapes with wrong orientation
  18231. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  18232. if ( newShapes.length > 1 ) {
  18233. var ambiguous = false;
  18234. var toChange = [];
  18235. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18236. betterShapeHoles[ sIdx ] = [];
  18237. }
  18238. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  18239. var sho = newShapeHoles[ sIdx ];
  18240. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  18241. var ho = sho[ hIdx ];
  18242. var hole_unassigned = true;
  18243. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  18244. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  18245. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  18246. if ( hole_unassigned ) {
  18247. hole_unassigned = false;
  18248. betterShapeHoles[ s2Idx ].push( ho );
  18249. } else {
  18250. ambiguous = true;
  18251. }
  18252. }
  18253. }
  18254. if ( hole_unassigned ) {
  18255. betterShapeHoles[ sIdx ].push( ho );
  18256. }
  18257. }
  18258. }
  18259. // console.log("ambiguous: ", ambiguous);
  18260. if ( toChange.length > 0 ) {
  18261. // console.log("to change: ", toChange);
  18262. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  18263. }
  18264. }
  18265. var tmpHoles;
  18266. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  18267. tmpShape = newShapes[ i ].s;
  18268. shapes.push( tmpShape );
  18269. tmpHoles = newShapeHoles[ i ];
  18270. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  18271. tmpShape.holes.push( tmpHoles[ j ].h );
  18272. }
  18273. }
  18274. //console.log("shape", shapes);
  18275. return shapes;
  18276. };
  18277. // File:src/extras/core/Shape.js
  18278. /**
  18279. * @author zz85 / http://www.lab4games.net/zz85/blog
  18280. * Defines a 2d shape plane using paths.
  18281. **/
  18282. // STEP 1 Create a path.
  18283. // STEP 2 Turn path into shape.
  18284. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  18285. // STEP 3a - Extract points from each shape, turn to vertices
  18286. // STEP 3b - Triangulate each shape, add faces.
  18287. THREE.Shape = function () {
  18288. THREE.Path.apply( this, arguments );
  18289. this.holes = [];
  18290. };
  18291. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  18292. THREE.Shape.prototype.constructor = THREE.Shape;
  18293. // Convenience method to return ExtrudeGeometry
  18294. THREE.Shape.prototype.extrude = function ( options ) {
  18295. return new THREE.ExtrudeGeometry( this, options );
  18296. };
  18297. // Convenience method to return ShapeGeometry
  18298. THREE.Shape.prototype.makeGeometry = function ( options ) {
  18299. return new THREE.ShapeGeometry( this, options );
  18300. };
  18301. // Get points of holes
  18302. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  18303. var holesPts = [];
  18304. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  18305. holesPts[ i ] = this.holes[ i ].getTransformedPoints( divisions, this.bends );
  18306. }
  18307. return holesPts;
  18308. };
  18309. // Get points of holes (spaced by regular distance)
  18310. THREE.Shape.prototype.getSpacedPointsHoles = function ( divisions ) {
  18311. var holesPts = [];
  18312. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  18313. holesPts[ i ] = this.holes[ i ].getTransformedSpacedPoints( divisions, this.bends );
  18314. }
  18315. return holesPts;
  18316. };
  18317. // Get points of shape and holes (keypoints based on segments parameter)
  18318. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  18319. return {
  18320. shape: this.getTransformedPoints( divisions ),
  18321. holes: this.getPointsHoles( divisions )
  18322. };
  18323. };
  18324. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  18325. if ( this.useSpacedPoints ) {
  18326. return this.extractAllSpacedPoints( divisions );
  18327. }
  18328. return this.extractAllPoints( divisions );
  18329. };
  18330. /*
  18331. THREE.Shape.prototype.extractAllPointsWithBend = function ( divisions, bend ) {
  18332. return {
  18333. shape: this.transform( bend, divisions ),
  18334. holes: this.getPointsHoles( divisions, bend )
  18335. };
  18336. };
  18337. */
  18338. // Get points of shape and holes (spaced by regular distance)
  18339. THREE.Shape.prototype.extractAllSpacedPoints = function ( divisions ) {
  18340. return {
  18341. shape: this.getTransformedSpacedPoints( divisions ),
  18342. holes: this.getSpacedPointsHoles( divisions )
  18343. };
  18344. };
  18345. /**************************************************************
  18346. * Utils
  18347. **************************************************************/
  18348. THREE.Shape.Utils = {
  18349. triangulateShape: function ( contour, holes ) {
  18350. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  18351. // inOtherPt needs to be collinear to the inSegment
  18352. if ( inSegPt1.x !== inSegPt2.x ) {
  18353. if ( inSegPt1.x < inSegPt2.x ) {
  18354. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  18355. } else {
  18356. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  18357. }
  18358. } else {
  18359. if ( inSegPt1.y < inSegPt2.y ) {
  18360. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  18361. } else {
  18362. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  18363. }
  18364. }
  18365. }
  18366. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  18367. var EPSILON = 0.0000000001;
  18368. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  18369. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  18370. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  18371. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  18372. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  18373. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  18374. if ( Math.abs( limit ) > EPSILON ) {
  18375. // not parallel
  18376. var perpSeg2;
  18377. if ( limit > 0 ) {
  18378. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  18379. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  18380. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  18381. } else {
  18382. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  18383. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  18384. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  18385. }
  18386. // i.e. to reduce rounding errors
  18387. // intersection at endpoint of segment#1?
  18388. if ( perpSeg2 === 0 ) {
  18389. if ( ( inExcludeAdjacentSegs ) &&
  18390. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  18391. return [ inSeg1Pt1 ];
  18392. }
  18393. if ( perpSeg2 === limit ) {
  18394. if ( ( inExcludeAdjacentSegs ) &&
  18395. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  18396. return [ inSeg1Pt2 ];
  18397. }
  18398. // intersection at endpoint of segment#2?
  18399. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  18400. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  18401. // return real intersection point
  18402. var factorSeg1 = perpSeg2 / limit;
  18403. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  18404. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  18405. } else {
  18406. // parallel or collinear
  18407. if ( ( perpSeg1 !== 0 ) ||
  18408. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  18409. // they are collinear or degenerate
  18410. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  18411. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  18412. // both segments are points
  18413. if ( seg1Pt && seg2Pt ) {
  18414. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  18415. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  18416. return [ inSeg1Pt1 ]; // they are the same point
  18417. }
  18418. // segment#1 is a single point
  18419. if ( seg1Pt ) {
  18420. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  18421. return [ inSeg1Pt1 ];
  18422. }
  18423. // segment#2 is a single point
  18424. if ( seg2Pt ) {
  18425. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  18426. return [ inSeg2Pt1 ];
  18427. }
  18428. // they are collinear segments, which might overlap
  18429. var seg1min, seg1max, seg1minVal, seg1maxVal;
  18430. var seg2min, seg2max, seg2minVal, seg2maxVal;
  18431. if ( seg1dx !== 0 ) {
  18432. // the segments are NOT on a vertical line
  18433. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  18434. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  18435. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  18436. } else {
  18437. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  18438. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  18439. }
  18440. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  18441. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  18442. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  18443. } else {
  18444. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  18445. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  18446. }
  18447. } else {
  18448. // the segments are on a vertical line
  18449. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  18450. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  18451. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  18452. } else {
  18453. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  18454. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  18455. }
  18456. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  18457. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  18458. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  18459. } else {
  18460. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  18461. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  18462. }
  18463. }
  18464. if ( seg1minVal <= seg2minVal ) {
  18465. if ( seg1maxVal < seg2minVal ) return [];
  18466. if ( seg1maxVal === seg2minVal ) {
  18467. if ( inExcludeAdjacentSegs ) return [];
  18468. return [ seg2min ];
  18469. }
  18470. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  18471. return [ seg2min, seg2max ];
  18472. } else {
  18473. if ( seg1minVal > seg2maxVal ) return [];
  18474. if ( seg1minVal === seg2maxVal ) {
  18475. if ( inExcludeAdjacentSegs ) return [];
  18476. return [ seg1min ];
  18477. }
  18478. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  18479. return [ seg1min, seg2max ];
  18480. }
  18481. }
  18482. }
  18483. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  18484. // The order of legs is important
  18485. var EPSILON = 0.0000000001;
  18486. // translation of all points, so that Vertex is at (0,0)
  18487. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  18488. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  18489. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  18490. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  18491. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  18492. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  18493. if ( Math.abs( from2toAngle ) > EPSILON ) {
  18494. // angle != 180 deg.
  18495. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  18496. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  18497. if ( from2toAngle > 0 ) {
  18498. // main angle < 180 deg.
  18499. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  18500. } else {
  18501. // main angle > 180 deg.
  18502. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  18503. }
  18504. } else {
  18505. // angle == 180 deg.
  18506. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  18507. return ( from2otherAngle > 0 );
  18508. }
  18509. }
  18510. function removeHoles( contour, holes ) {
  18511. var shape = contour.concat(); // work on this shape
  18512. var hole;
  18513. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  18514. // Check if hole point lies within angle around shape point
  18515. var lastShapeIdx = shape.length - 1;
  18516. var prevShapeIdx = inShapeIdx - 1;
  18517. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  18518. var nextShapeIdx = inShapeIdx + 1;
  18519. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  18520. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  18521. if ( ! insideAngle ) {
  18522. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  18523. return false;
  18524. }
  18525. // Check if shape point lies within angle around hole point
  18526. var lastHoleIdx = hole.length - 1;
  18527. var prevHoleIdx = inHoleIdx - 1;
  18528. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  18529. var nextHoleIdx = inHoleIdx + 1;
  18530. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  18531. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  18532. if ( ! insideAngle ) {
  18533. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  18534. return false;
  18535. }
  18536. return true;
  18537. }
  18538. function intersectsShapeEdge( inShapePt, inHolePt ) {
  18539. // checks for intersections with shape edges
  18540. var sIdx, nextIdx, intersection;
  18541. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  18542. nextIdx = sIdx + 1; nextIdx %= shape.length;
  18543. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  18544. if ( intersection.length > 0 ) return true;
  18545. }
  18546. return false;
  18547. }
  18548. var indepHoles = [];
  18549. function intersectsHoleEdge( inShapePt, inHolePt ) {
  18550. // checks for intersections with hole edges
  18551. var ihIdx, chkHole,
  18552. hIdx, nextIdx, intersection;
  18553. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  18554. chkHole = holes[ indepHoles[ ihIdx ]];
  18555. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  18556. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  18557. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  18558. if ( intersection.length > 0 ) return true;
  18559. }
  18560. }
  18561. return false;
  18562. }
  18563. var holeIndex, shapeIndex,
  18564. shapePt, holePt,
  18565. holeIdx, cutKey, failedCuts = [],
  18566. tmpShape1, tmpShape2,
  18567. tmpHole1, tmpHole2;
  18568. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18569. indepHoles.push( h );
  18570. }
  18571. var minShapeIndex = 0;
  18572. var counter = indepHoles.length * 2;
  18573. while ( indepHoles.length > 0 ) {
  18574. counter --;
  18575. if ( counter < 0 ) {
  18576. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  18577. break;
  18578. }
  18579. // search for shape-vertex and hole-vertex,
  18580. // which can be connected without intersections
  18581. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  18582. shapePt = shape[ shapeIndex ];
  18583. holeIndex = - 1;
  18584. // search for hole which can be reached without intersections
  18585. for ( var h = 0; h < indepHoles.length; h ++ ) {
  18586. holeIdx = indepHoles[ h ];
  18587. // prevent multiple checks
  18588. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  18589. if ( failedCuts[ cutKey ] !== undefined ) continue;
  18590. hole = holes[ holeIdx ];
  18591. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  18592. holePt = hole[ h2 ];
  18593. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  18594. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  18595. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  18596. holeIndex = h2;
  18597. indepHoles.splice( h, 1 );
  18598. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  18599. tmpShape2 = shape.slice( shapeIndex );
  18600. tmpHole1 = hole.slice( holeIndex );
  18601. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  18602. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  18603. minShapeIndex = shapeIndex;
  18604. // Debug only, to show the selected cuts
  18605. // glob_CutLines.push( [ shapePt, holePt ] );
  18606. break;
  18607. }
  18608. if ( holeIndex >= 0 ) break; // hole-vertex found
  18609. failedCuts[ cutKey ] = true; // remember failure
  18610. }
  18611. if ( holeIndex >= 0 ) break; // hole-vertex found
  18612. }
  18613. }
  18614. return shape; /* shape with no holes */
  18615. }
  18616. var i, il, f, face,
  18617. key, index,
  18618. allPointsMap = {};
  18619. // 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.
  18620. var allpoints = contour.concat();
  18621. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  18622. Array.prototype.push.apply( allpoints, holes[ h ] );
  18623. }
  18624. //console.log( "allpoints",allpoints, allpoints.length );
  18625. // prepare all points map
  18626. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  18627. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  18628. if ( allPointsMap[ key ] !== undefined ) {
  18629. console.warn( "THREE.Shape: Duplicate point", key );
  18630. }
  18631. allPointsMap[ key ] = i;
  18632. }
  18633. // remove holes by cutting paths to holes and adding them to the shape
  18634. var shapeWithoutHoles = removeHoles( contour, holes );
  18635. var triangles = THREE.FontUtils.Triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  18636. //console.log( "triangles",triangles, triangles.length );
  18637. // check all face vertices against all points map
  18638. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  18639. face = triangles[ i ];
  18640. for ( f = 0; f < 3; f ++ ) {
  18641. key = face[ f ].x + ":" + face[ f ].y;
  18642. index = allPointsMap[ key ];
  18643. if ( index !== undefined ) {
  18644. face[ f ] = index;
  18645. }
  18646. }
  18647. }
  18648. return triangles.concat();
  18649. },
  18650. isClockWise: function ( pts ) {
  18651. return THREE.FontUtils.Triangulate.area( pts ) < 0;
  18652. },
  18653. // Bezier Curves formulas obtained from
  18654. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  18655. // Quad Bezier Functions
  18656. b2p0: function ( t, p ) {
  18657. var k = 1 - t;
  18658. return k * k * p;
  18659. },
  18660. b2p1: function ( t, p ) {
  18661. return 2 * ( 1 - t ) * t * p;
  18662. },
  18663. b2p2: function ( t, p ) {
  18664. return t * t * p;
  18665. },
  18666. b2: function ( t, p0, p1, p2 ) {
  18667. return this.b2p0( t, p0 ) + this.b2p1( t, p1 ) + this.b2p2( t, p2 );
  18668. },
  18669. // Cubic Bezier Functions
  18670. b3p0: function ( t, p ) {
  18671. var k = 1 - t;
  18672. return k * k * k * p;
  18673. },
  18674. b3p1: function ( t, p ) {
  18675. var k = 1 - t;
  18676. return 3 * k * k * t * p;
  18677. },
  18678. b3p2: function ( t, p ) {
  18679. var k = 1 - t;
  18680. return 3 * k * t * t * p;
  18681. },
  18682. b3p3: function ( t, p ) {
  18683. return t * t * t * p;
  18684. },
  18685. b3: function ( t, p0, p1, p2, p3 ) {
  18686. return this.b3p0( t, p0 ) + this.b3p1( t, p1 ) + this.b3p2( t, p2 ) + this.b3p3( t, p3 );
  18687. }
  18688. };
  18689. // File:src/extras/curves/LineCurve.js
  18690. /**************************************************************
  18691. * Line
  18692. **************************************************************/
  18693. THREE.LineCurve = function ( v1, v2 ) {
  18694. this.v1 = v1;
  18695. this.v2 = v2;
  18696. };
  18697. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  18698. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  18699. THREE.LineCurve.prototype.getPoint = function ( t ) {
  18700. var point = this.v2.clone().sub( this.v1 );
  18701. point.multiplyScalar( t ).add( this.v1 );
  18702. return point;
  18703. };
  18704. // Line curve is linear, so we can overwrite default getPointAt
  18705. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  18706. return this.getPoint( u );
  18707. };
  18708. THREE.LineCurve.prototype.getTangent = function( t ) {
  18709. var tangent = this.v2.clone().sub( this.v1 );
  18710. return tangent.normalize();
  18711. };
  18712. // File:src/extras/curves/QuadraticBezierCurve.js
  18713. /**************************************************************
  18714. * Quadratic Bezier curve
  18715. **************************************************************/
  18716. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  18717. this.v0 = v0;
  18718. this.v1 = v1;
  18719. this.v2 = v2;
  18720. };
  18721. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18722. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  18723. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  18724. var vector = new THREE.Vector2();
  18725. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  18726. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  18727. return vector;
  18728. };
  18729. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  18730. var vector = new THREE.Vector2();
  18731. vector.x = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x );
  18732. vector.y = THREE.Curve.Utils.tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y );
  18733. // returns unit vector
  18734. return vector.normalize();
  18735. };
  18736. // File:src/extras/curves/CubicBezierCurve.js
  18737. /**************************************************************
  18738. * Cubic Bezier curve
  18739. **************************************************************/
  18740. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  18741. this.v0 = v0;
  18742. this.v1 = v1;
  18743. this.v2 = v2;
  18744. this.v3 = v3;
  18745. };
  18746. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  18747. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  18748. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  18749. var tx, ty;
  18750. tx = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18751. ty = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18752. return new THREE.Vector2( tx, ty );
  18753. };
  18754. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  18755. var tx, ty;
  18756. tx = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18757. ty = THREE.Curve.Utils.tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18758. var tangent = new THREE.Vector2( tx, ty );
  18759. tangent.normalize();
  18760. return tangent;
  18761. };
  18762. // File:src/extras/curves/SplineCurve.js
  18763. /**************************************************************
  18764. * Spline curve
  18765. **************************************************************/
  18766. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  18767. this.points = ( points == undefined ) ? [] : points;
  18768. };
  18769. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  18770. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  18771. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  18772. var points = this.points;
  18773. var point = ( points.length - 1 ) * t;
  18774. var intPoint = Math.floor( point );
  18775. var weight = point - intPoint;
  18776. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  18777. var point1 = points[ intPoint ];
  18778. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18779. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18780. var vector = new THREE.Vector2();
  18781. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  18782. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  18783. return vector;
  18784. };
  18785. // File:src/extras/curves/EllipseCurve.js
  18786. /**************************************************************
  18787. * Ellipse curve
  18788. **************************************************************/
  18789. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  18790. this.aX = aX;
  18791. this.aY = aY;
  18792. this.xRadius = xRadius;
  18793. this.yRadius = yRadius;
  18794. this.aStartAngle = aStartAngle;
  18795. this.aEndAngle = aEndAngle;
  18796. this.aClockwise = aClockwise;
  18797. this.aRotation = aRotation || 0;
  18798. };
  18799. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  18800. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  18801. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  18802. var deltaAngle = this.aEndAngle - this.aStartAngle;
  18803. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  18804. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  18805. var angle;
  18806. if ( this.aClockwise === true ) {
  18807. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  18808. } else {
  18809. angle = this.aStartAngle + t * deltaAngle;
  18810. }
  18811. var x = this.aX + this.xRadius * Math.cos( angle );
  18812. var y = this.aY + this.yRadius * Math.sin( angle );
  18813. if ( this.aRotation !== 0 ) {
  18814. var cos = Math.cos( this.aRotation );
  18815. var sin = Math.sin( this.aRotation );
  18816. var tx = x, ty = y;
  18817. // Rotate the point about the center of the ellipse.
  18818. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  18819. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  18820. }
  18821. return new THREE.Vector2( x, y );
  18822. };
  18823. // File:src/extras/curves/ArcCurve.js
  18824. /**************************************************************
  18825. * Arc curve
  18826. **************************************************************/
  18827. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  18828. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  18829. };
  18830. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  18831. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  18832. // File:src/extras/curves/LineCurve3.js
  18833. /**************************************************************
  18834. * Line3D
  18835. **************************************************************/
  18836. THREE.LineCurve3 = THREE.Curve.create(
  18837. function ( v1, v2 ) {
  18838. this.v1 = v1;
  18839. this.v2 = v2;
  18840. },
  18841. function ( t ) {
  18842. var vector = new THREE.Vector3();
  18843. vector.subVectors( this.v2, this.v1 ); // diff
  18844. vector.multiplyScalar( t );
  18845. vector.add( this.v1 );
  18846. return vector;
  18847. }
  18848. );
  18849. // File:src/extras/curves/QuadraticBezierCurve3.js
  18850. /**************************************************************
  18851. * Quadratic Bezier 3D curve
  18852. **************************************************************/
  18853. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  18854. function ( v0, v1, v2 ) {
  18855. this.v0 = v0;
  18856. this.v1 = v1;
  18857. this.v2 = v2;
  18858. },
  18859. function ( t ) {
  18860. var vector = new THREE.Vector3();
  18861. vector.x = THREE.Shape.Utils.b2( t, this.v0.x, this.v1.x, this.v2.x );
  18862. vector.y = THREE.Shape.Utils.b2( t, this.v0.y, this.v1.y, this.v2.y );
  18863. vector.z = THREE.Shape.Utils.b2( t, this.v0.z, this.v1.z, this.v2.z );
  18864. return vector;
  18865. }
  18866. );
  18867. // File:src/extras/curves/CubicBezierCurve3.js
  18868. /**************************************************************
  18869. * Cubic Bezier 3D curve
  18870. **************************************************************/
  18871. THREE.CubicBezierCurve3 = THREE.Curve.create(
  18872. function ( v0, v1, v2, v3 ) {
  18873. this.v0 = v0;
  18874. this.v1 = v1;
  18875. this.v2 = v2;
  18876. this.v3 = v3;
  18877. },
  18878. function ( t ) {
  18879. var vector = new THREE.Vector3();
  18880. vector.x = THREE.Shape.Utils.b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x );
  18881. vector.y = THREE.Shape.Utils.b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y );
  18882. vector.z = THREE.Shape.Utils.b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z );
  18883. return vector;
  18884. }
  18885. );
  18886. // File:src/extras/curves/SplineCurve3.js
  18887. /**************************************************************
  18888. * Spline 3D curve
  18889. **************************************************************/
  18890. THREE.SplineCurve3 = THREE.Curve.create(
  18891. function ( points /* array of Vector3 */ ) {
  18892. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  18893. this.points = ( points == undefined ) ? [] : points;
  18894. },
  18895. function ( t ) {
  18896. var points = this.points;
  18897. var point = ( points.length - 1 ) * t;
  18898. var intPoint = Math.floor( point );
  18899. var weight = point - intPoint;
  18900. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  18901. var point1 = points[ intPoint ];
  18902. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  18903. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  18904. var vector = new THREE.Vector3();
  18905. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  18906. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  18907. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  18908. return vector;
  18909. }
  18910. );
  18911. // File:src/extras/curves/CatmullRomCurve3.js
  18912. /**
  18913. * @author zz85 https://github.com/zz85
  18914. *
  18915. * Centripetal CatmullRom Curve - which is useful for avoiding
  18916. * cusps and self-intersections in non-uniform catmull rom curves.
  18917. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  18918. *
  18919. * curve.type accepts centripetal(default), chordal and catmullrom
  18920. * curve.tension is used for catmullrom which defaults to 0.5
  18921. */
  18922. THREE.CatmullRomCurve3 = ( function() {
  18923. var
  18924. tmp = new THREE.Vector3(),
  18925. px = new CubicPoly(),
  18926. py = new CubicPoly(),
  18927. pz = new CubicPoly();
  18928. /*
  18929. Based on an optimized c++ solution in
  18930. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  18931. - http://ideone.com/NoEbVM
  18932. This CubicPoly class could be used for reusing some variables and calculations,
  18933. but for three.js curve use, it could be possible inlined and flatten into a single function call
  18934. which can be placed in CurveUtils.
  18935. */
  18936. function CubicPoly() {
  18937. }
  18938. /*
  18939. * Compute coefficients for a cubic polynomial
  18940. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  18941. * such that
  18942. * p(0) = x0, p(1) = x1
  18943. * and
  18944. * p'(0) = t0, p'(1) = t1.
  18945. */
  18946. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  18947. this.c0 = x0;
  18948. this.c1 = t0;
  18949. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  18950. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  18951. };
  18952. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  18953. // compute tangents when parameterized in [t1,t2]
  18954. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  18955. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  18956. // rescale tangents for parametrization in [0,1]
  18957. t1 *= dt1;
  18958. t2 *= dt1;
  18959. // initCubicPoly
  18960. this.init( x1, x2, t1, t2 );
  18961. };
  18962. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  18963. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  18964. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  18965. };
  18966. CubicPoly.prototype.calc = function( t ) {
  18967. var t2 = t * t;
  18968. var t3 = t2 * t;
  18969. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  18970. };
  18971. // Subclass Three.js curve
  18972. return THREE.Curve.create(
  18973. function ( p /* array of Vector3 */ ) {
  18974. this.points = p || [];
  18975. },
  18976. function ( t ) {
  18977. var points = this.points,
  18978. point, intPoint, weight, l;
  18979. l = points.length;
  18980. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  18981. point = ( l - 1 ) * t;
  18982. intPoint = Math.floor( point );
  18983. weight = point - intPoint;
  18984. if ( weight === 0 && intPoint === l - 1 ) {
  18985. intPoint = l - 2;
  18986. weight = 1;
  18987. }
  18988. var p0, p1, p2, p3;
  18989. if ( intPoint === 0 ) {
  18990. // extrapolate first point
  18991. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  18992. p0 = tmp;
  18993. } else {
  18994. p0 = points[ intPoint - 1 ];
  18995. }
  18996. p1 = points[ intPoint ];
  18997. p2 = points[ intPoint + 1 ];
  18998. if ( intPoint + 2 < l ) {
  18999. p3 = points[ intPoint + 2 ]
  19000. } else {
  19001. // extrapolate last point
  19002. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 2 ] );
  19003. p3 = tmp;
  19004. }
  19005. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  19006. // init Centripetal / Chordal Catmull-Rom
  19007. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  19008. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  19009. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  19010. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  19011. // safety check for repeated points
  19012. if ( dt1 < 1e-4 ) dt1 = 1.0;
  19013. if ( dt0 < 1e-4 ) dt0 = dt1;
  19014. if ( dt2 < 1e-4 ) dt2 = dt1;
  19015. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  19016. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  19017. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  19018. } else if ( this.type === 'catmullrom' ) {
  19019. var tension = this.tension !== undefined ? this.tension : 0.5;
  19020. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  19021. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  19022. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  19023. }
  19024. var v = new THREE.Vector3(
  19025. px.calc( weight ),
  19026. py.calc( weight ),
  19027. pz.calc( weight )
  19028. );
  19029. return v;
  19030. }
  19031. );
  19032. } )();
  19033. // File:src/extras/curves/ClosedSplineCurve3.js
  19034. /**************************************************************
  19035. * Closed Spline 3D curve
  19036. **************************************************************/
  19037. THREE.ClosedSplineCurve3 = THREE.Curve.create(
  19038. function ( points /* array of Vector3 */ ) {
  19039. this.points = ( points == undefined ) ? [] : points;
  19040. },
  19041. function ( t ) {
  19042. var points = this.points;
  19043. var point = ( points.length - 0 ) * t; // This needs to be from 0-length +1
  19044. var intPoint = Math.floor( point );
  19045. var weight = point - intPoint;
  19046. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  19047. var point0 = points[ ( intPoint - 1 ) % points.length ];
  19048. var point1 = points[ ( intPoint ) % points.length ];
  19049. var point2 = points[ ( intPoint + 1 ) % points.length ];
  19050. var point3 = points[ ( intPoint + 2 ) % points.length ];
  19051. var vector = new THREE.Vector3();
  19052. vector.x = THREE.Curve.Utils.interpolate( point0.x, point1.x, point2.x, point3.x, weight );
  19053. vector.y = THREE.Curve.Utils.interpolate( point0.y, point1.y, point2.y, point3.y, weight );
  19054. vector.z = THREE.Curve.Utils.interpolate( point0.z, point1.z, point2.z, point3.z, weight );
  19055. return vector;
  19056. }
  19057. );
  19058. // File:src/extras/geometries/BoxGeometry.js
  19059. /**
  19060. * @author mrdoob / http://mrdoob.com/
  19061. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  19062. */
  19063. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  19064. THREE.Geometry.call( this );
  19065. this.type = 'BoxGeometry';
  19066. this.parameters = {
  19067. width: width,
  19068. height: height,
  19069. depth: depth,
  19070. widthSegments: widthSegments,
  19071. heightSegments: heightSegments,
  19072. depthSegments: depthSegments
  19073. };
  19074. this.widthSegments = widthSegments || 1;
  19075. this.heightSegments = heightSegments || 1;
  19076. this.depthSegments = depthSegments || 1;
  19077. var scope = this;
  19078. var width_half = width / 2;
  19079. var height_half = height / 2;
  19080. var depth_half = depth / 2;
  19081. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  19082. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  19083. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  19084. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  19085. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  19086. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  19087. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  19088. var w, ix, iy,
  19089. gridX = scope.widthSegments,
  19090. gridY = scope.heightSegments,
  19091. width_half = width / 2,
  19092. height_half = height / 2,
  19093. offset = scope.vertices.length;
  19094. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  19095. w = 'z';
  19096. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  19097. w = 'y';
  19098. gridY = scope.depthSegments;
  19099. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  19100. w = 'x';
  19101. gridX = scope.depthSegments;
  19102. }
  19103. var gridX1 = gridX + 1,
  19104. gridY1 = gridY + 1,
  19105. segment_width = width / gridX,
  19106. segment_height = height / gridY,
  19107. normal = new THREE.Vector3();
  19108. normal[ w ] = depth > 0 ? 1 : - 1;
  19109. for ( iy = 0; iy < gridY1; iy ++ ) {
  19110. for ( ix = 0; ix < gridX1; ix ++ ) {
  19111. var vector = new THREE.Vector3();
  19112. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  19113. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  19114. vector[ w ] = depth;
  19115. scope.vertices.push( vector );
  19116. }
  19117. }
  19118. for ( iy = 0; iy < gridY; iy ++ ) {
  19119. for ( ix = 0; ix < gridX; ix ++ ) {
  19120. var a = ix + gridX1 * iy;
  19121. var b = ix + gridX1 * ( iy + 1 );
  19122. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  19123. var d = ( ix + 1 ) + gridX1 * iy;
  19124. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  19125. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  19126. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  19127. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  19128. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  19129. face.normal.copy( normal );
  19130. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  19131. face.materialIndex = materialIndex;
  19132. scope.faces.push( face );
  19133. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  19134. face = new THREE.Face3( b + offset, c + offset, d + offset );
  19135. face.normal.copy( normal );
  19136. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  19137. face.materialIndex = materialIndex;
  19138. scope.faces.push( face );
  19139. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  19140. }
  19141. }
  19142. }
  19143. this.mergeVertices();
  19144. };
  19145. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19146. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  19147. THREE.BoxGeometry.prototype.clone = function () {
  19148. var parameters = this.parameters;
  19149. return new THREE.BoxGeometry(
  19150. parameters.width,
  19151. parameters.height,
  19152. parameters.depth,
  19153. parameters.widthSegments,
  19154. parameters.heightSegments,
  19155. parameters.depthSegments
  19156. );
  19157. };
  19158. THREE.CubeGeometry = THREE.BoxGeometry; // backwards compatibility
  19159. // File:src/extras/geometries/CircleGeometry.js
  19160. /**
  19161. * @author hughes
  19162. */
  19163. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  19164. THREE.Geometry.call( this );
  19165. this.type = 'CircleGeometry';
  19166. this.parameters = {
  19167. radius: radius,
  19168. segments: segments,
  19169. thetaStart: thetaStart,
  19170. thetaLength: thetaLength
  19171. };
  19172. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  19173. };
  19174. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19175. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  19176. THREE.CircleGeometry.prototype.clone = function () {
  19177. var parameters = this.parameters;
  19178. return new THREE.CircleGeometry(
  19179. parameters.radius,
  19180. parameters.segments,
  19181. parameters.thetaStart,
  19182. parameters.thetaLength
  19183. );
  19184. };
  19185. // File:src/extras/geometries/CircleBufferGeometry.js
  19186. /**
  19187. * @author benaadams / https://twitter.com/ben_a_adams
  19188. */
  19189. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  19190. THREE.BufferGeometry.call( this );
  19191. this.type = 'CircleBufferGeometry';
  19192. this.parameters = {
  19193. radius: radius,
  19194. segments: segments,
  19195. thetaStart: thetaStart,
  19196. thetaLength: thetaLength
  19197. };
  19198. radius = radius || 50;
  19199. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  19200. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19201. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  19202. var vertices = segments + 2;
  19203. var positions = new Float32Array( vertices * 3 );
  19204. var normals = new Float32Array( vertices * 3 );
  19205. var uvs = new Float32Array( vertices * 2 );
  19206. // center data is already zero, but need to set a few extras
  19207. normals[ 2 ] = 1.0;
  19208. uvs[ 0 ] = 0.5;
  19209. uvs[ 1 ] = 0.5;
  19210. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  19211. var segment = thetaStart + s / segments * thetaLength;
  19212. positions[ i ] = radius * Math.cos( segment );
  19213. positions[ i + 1 ] = radius * Math.sin( segment );
  19214. normals[ i + 2 ] = 1; // normal z
  19215. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  19216. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  19217. }
  19218. var indices = [];
  19219. for ( var i = 1; i <= segments; i ++ ) {
  19220. indices.push( i, i + 1, 0 );
  19221. }
  19222. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  19223. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  19224. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  19225. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  19226. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  19227. };
  19228. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19229. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  19230. THREE.CircleBufferGeometry.prototype.clone = function () {
  19231. var parameters = this.parameters;
  19232. return new THREE.CircleBufferGeometry(
  19233. parameters.radius,
  19234. parameters.segments,
  19235. parameters.thetaStart,
  19236. parameters.thetaLength
  19237. );
  19238. };
  19239. // File:src/extras/geometries/CylinderGeometry.js
  19240. /**
  19241. * @author mrdoob / http://mrdoob.com/
  19242. */
  19243. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  19244. THREE.Geometry.call( this );
  19245. this.type = 'CylinderGeometry';
  19246. this.parameters = {
  19247. radiusTop: radiusTop,
  19248. radiusBottom: radiusBottom,
  19249. height: height,
  19250. radialSegments: radialSegments,
  19251. heightSegments: heightSegments,
  19252. openEnded: openEnded,
  19253. thetaStart: thetaStart,
  19254. thetaLength: thetaLength
  19255. };
  19256. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  19257. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  19258. height = height !== undefined ? height : 100;
  19259. radialSegments = radialSegments || 8;
  19260. heightSegments = heightSegments || 1;
  19261. openEnded = openEnded !== undefined ? openEnded : false;
  19262. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  19263. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  19264. var heightHalf = height / 2;
  19265. var x, y, vertices = [], uvs = [];
  19266. for ( y = 0; y <= heightSegments; y ++ ) {
  19267. var verticesRow = [];
  19268. var uvsRow = [];
  19269. var v = y / heightSegments;
  19270. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  19271. for ( x = 0; x <= radialSegments; x ++ ) {
  19272. var u = x / radialSegments;
  19273. var vertex = new THREE.Vector3();
  19274. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  19275. vertex.y = - v * height + heightHalf;
  19276. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  19277. this.vertices.push( vertex );
  19278. verticesRow.push( this.vertices.length - 1 );
  19279. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  19280. }
  19281. vertices.push( verticesRow );
  19282. uvs.push( uvsRow );
  19283. }
  19284. var tanTheta = ( radiusBottom - radiusTop ) / height;
  19285. var na, nb;
  19286. for ( x = 0; x < radialSegments; x ++ ) {
  19287. if ( radiusTop !== 0 ) {
  19288. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  19289. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  19290. } else {
  19291. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  19292. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  19293. }
  19294. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  19295. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  19296. for ( y = 0; y < heightSegments; y ++ ) {
  19297. var v1 = vertices[ y ][ x ];
  19298. var v2 = vertices[ y + 1 ][ x ];
  19299. var v3 = vertices[ y + 1 ][ x + 1 ];
  19300. var v4 = vertices[ y ][ x + 1 ];
  19301. var n1 = na.clone();
  19302. var n2 = na.clone();
  19303. var n3 = nb.clone();
  19304. var n4 = nb.clone();
  19305. var uv1 = uvs[ y ][ x ].clone();
  19306. var uv2 = uvs[ y + 1 ][ x ].clone();
  19307. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  19308. var uv4 = uvs[ y ][ x + 1 ].clone();
  19309. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  19310. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  19311. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  19312. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  19313. }
  19314. }
  19315. // top cap
  19316. if ( openEnded === false && radiusTop > 0 ) {
  19317. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  19318. for ( x = 0; x < radialSegments; x ++ ) {
  19319. var v1 = vertices[ 0 ][ x ];
  19320. var v2 = vertices[ 0 ][ x + 1 ];
  19321. var v3 = this.vertices.length - 1;
  19322. var n1 = new THREE.Vector3( 0, 1, 0 );
  19323. var n2 = new THREE.Vector3( 0, 1, 0 );
  19324. var n3 = new THREE.Vector3( 0, 1, 0 );
  19325. var uv1 = uvs[ 0 ][ x ].clone();
  19326. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  19327. var uv3 = new THREE.Vector2( uv2.x, 0 );
  19328. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  19329. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19330. }
  19331. }
  19332. // bottom cap
  19333. if ( openEnded === false && radiusBottom > 0 ) {
  19334. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  19335. for ( x = 0; x < radialSegments; x ++ ) {
  19336. var v1 = vertices[ heightSegments ][ x + 1 ];
  19337. var v2 = vertices[ heightSegments ][ x ];
  19338. var v3 = this.vertices.length - 1;
  19339. var n1 = new THREE.Vector3( 0, - 1, 0 );
  19340. var n2 = new THREE.Vector3( 0, - 1, 0 );
  19341. var n3 = new THREE.Vector3( 0, - 1, 0 );
  19342. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  19343. var uv2 = uvs[ heightSegments ][ x ].clone();
  19344. var uv3 = new THREE.Vector2( uv2.x, 1 );
  19345. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  19346. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  19347. }
  19348. }
  19349. this.computeFaceNormals();
  19350. };
  19351. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19352. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  19353. THREE.CylinderGeometry.prototype.clone = function () {
  19354. var parameters = this.parameters;
  19355. return new THREE.CylinderGeometry(
  19356. parameters.radiusTop,
  19357. parameters.radiusBottom,
  19358. parameters.height,
  19359. parameters.radialSegments,
  19360. parameters.heightSegments,
  19361. parameters.openEnded,
  19362. parameters.thetaStart,
  19363. parameters.thetaLength
  19364. );
  19365. };
  19366. // File:src/extras/geometries/EdgesGeometry.js
  19367. /**
  19368. * @author WestLangley / http://github.com/WestLangley
  19369. */
  19370. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  19371. THREE.BufferGeometry.call( this );
  19372. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  19373. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  19374. var edge = [ 0, 0 ], hash = {};
  19375. function sortFunction( a, b ) {
  19376. return a - b;
  19377. }
  19378. var keys = [ 'a', 'b', 'c' ];
  19379. var geometry2;
  19380. if ( geometry instanceof THREE.BufferGeometry ) {
  19381. geometry2 = new THREE.Geometry();
  19382. geometry2.fromBufferGeometry( geometry );
  19383. } else {
  19384. geometry2 = geometry.clone();
  19385. }
  19386. geometry2.mergeVertices();
  19387. geometry2.computeFaceNormals();
  19388. var vertices = geometry2.vertices;
  19389. var faces = geometry2.faces;
  19390. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  19391. var face = faces[ i ];
  19392. for ( var j = 0; j < 3; j ++ ) {
  19393. edge[ 0 ] = face[ keys[ j ] ];
  19394. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  19395. edge.sort( sortFunction );
  19396. var key = edge.toString();
  19397. if ( hash[ key ] === undefined ) {
  19398. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  19399. } else {
  19400. hash[ key ].face2 = i;
  19401. }
  19402. }
  19403. }
  19404. var coords = [];
  19405. for ( var key in hash ) {
  19406. var h = hash[ key ];
  19407. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  19408. var vertex = vertices[ h.vert1 ];
  19409. coords.push( vertex.x );
  19410. coords.push( vertex.y );
  19411. coords.push( vertex.z );
  19412. vertex = vertices[ h.vert2 ];
  19413. coords.push( vertex.x );
  19414. coords.push( vertex.y );
  19415. coords.push( vertex.z );
  19416. }
  19417. }
  19418. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  19419. };
  19420. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  19421. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  19422. // File:src/extras/geometries/ExtrudeGeometry.js
  19423. /**
  19424. * @author zz85 / http://www.lab4games.net/zz85/blog
  19425. *
  19426. * Creates extruded geometry from a path shape.
  19427. *
  19428. * parameters = {
  19429. *
  19430. * curveSegments: <int>, // number of points on the curves
  19431. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  19432. * amount: <int>, // Depth to extrude the shape
  19433. *
  19434. * bevelEnabled: <bool>, // turn on bevel
  19435. * bevelThickness: <float>, // how deep into the original shape bevel goes
  19436. * bevelSize: <float>, // how far from shape outline is bevel
  19437. * bevelSegments: <int>, // number of bevel layers
  19438. *
  19439. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  19440. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  19441. *
  19442. * uvGenerator: <Object> // object that provides UV generator functions
  19443. *
  19444. * }
  19445. **/
  19446. THREE.ExtrudeGeometry = function ( shapes, options ) {
  19447. if ( typeof( shapes ) === "undefined" ) {
  19448. shapes = [];
  19449. return;
  19450. }
  19451. THREE.Geometry.call( this );
  19452. this.type = 'ExtrudeGeometry';
  19453. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  19454. this.addShapeList( shapes, options );
  19455. this.computeFaceNormals();
  19456. // can't really use automatic vertex normals
  19457. // as then front and back sides get smoothed too
  19458. // should do separate smoothing just for sides
  19459. //this.computeVertexNormals();
  19460. //console.log( "took", ( Date.now() - startTime ) );
  19461. };
  19462. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19463. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  19464. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19465. var sl = shapes.length;
  19466. for ( var s = 0; s < sl; s ++ ) {
  19467. var shape = shapes[ s ];
  19468. this.addShape( shape, options );
  19469. }
  19470. };
  19471. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  19472. var amount = options.amount !== undefined ? options.amount : 100;
  19473. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  19474. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  19475. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  19476. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  19477. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19478. var steps = options.steps !== undefined ? options.steps : 1;
  19479. var extrudePath = options.extrudePath;
  19480. var extrudePts, extrudeByPath = false;
  19481. // Use default WorldUVGenerator if no UV generators are specified.
  19482. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  19483. var splineTube, binormal, normal, position2;
  19484. if ( extrudePath ) {
  19485. extrudePts = extrudePath.getSpacedPoints( steps );
  19486. extrudeByPath = true;
  19487. bevelEnabled = false; // bevels not supported for path extrusion
  19488. // SETUP TNB variables
  19489. // Reuse TNB from TubeGeomtry for now.
  19490. // TODO1 - have a .isClosed in spline?
  19491. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  19492. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  19493. binormal = new THREE.Vector3();
  19494. normal = new THREE.Vector3();
  19495. position2 = new THREE.Vector3();
  19496. }
  19497. // Safeguards if bevels are not enabled
  19498. if ( ! bevelEnabled ) {
  19499. bevelSegments = 0;
  19500. bevelThickness = 0;
  19501. bevelSize = 0;
  19502. }
  19503. // Variables initialization
  19504. var ahole, h, hl; // looping of holes
  19505. var scope = this;
  19506. var shapesOffset = this.vertices.length;
  19507. var shapePoints = shape.extractPoints( curveSegments );
  19508. var vertices = shapePoints.shape;
  19509. var holes = shapePoints.holes;
  19510. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19511. if ( reverse ) {
  19512. vertices = vertices.reverse();
  19513. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  19514. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19515. ahole = holes[ h ];
  19516. if ( THREE.Shape.Utils.isClockWise( ahole ) ) {
  19517. holes[ h ] = ahole.reverse();
  19518. }
  19519. }
  19520. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  19521. }
  19522. var faces = THREE.Shape.Utils.triangulateShape ( vertices, holes );
  19523. /* Vertices */
  19524. var contour = vertices; // vertices has all points but contour has only points of circumference
  19525. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19526. ahole = holes[ h ];
  19527. vertices = vertices.concat( ahole );
  19528. }
  19529. function scalePt2 ( pt, vec, size ) {
  19530. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  19531. return vec.clone().multiplyScalar( size ).add( pt );
  19532. }
  19533. var b, bs, t, z,
  19534. vert, vlen = vertices.length,
  19535. face, flen = faces.length;
  19536. // Find directions for point movement
  19537. function getBevelVec( inPt, inPrev, inNext ) {
  19538. var EPSILON = 0.0000000001;
  19539. // computes for inPt the corresponding point inPt' on a new contour
  19540. // shifted by 1 unit (length of normalized vector) to the left
  19541. // if we walk along contour clockwise, this new contour is outside the old one
  19542. //
  19543. // inPt' is the intersection of the two lines parallel to the two
  19544. // adjacent edges of inPt at a distance of 1 unit on the left side.
  19545. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  19546. // good reading for geometry algorithms (here: line-line intersection)
  19547. // http://geomalgorithms.com/a05-_intersect-1.html
  19548. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  19549. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  19550. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  19551. // check for collinear edges
  19552. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19553. if ( Math.abs( collinear0 ) > EPSILON ) {
  19554. // not collinear
  19555. // length of vectors for normalizing
  19556. var v_prev_len = Math.sqrt( v_prev_lensq );
  19557. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  19558. // shift adjacent points by unit vectors to the left
  19559. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  19560. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  19561. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  19562. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  19563. // scaling factor for v_prev to intersection point
  19564. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  19565. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  19566. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  19567. // vector from inPt to intersection point
  19568. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  19569. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  19570. // Don't normalize!, otherwise sharp corners become ugly
  19571. // but prevent crazy spikes
  19572. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  19573. if ( v_trans_lensq <= 2 ) {
  19574. return new THREE.Vector2( v_trans_x, v_trans_y );
  19575. } else {
  19576. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  19577. }
  19578. } else {
  19579. // handle special case of collinear edges
  19580. var direction_eq = false; // assumes: opposite
  19581. if ( v_prev_x > EPSILON ) {
  19582. if ( v_next_x > EPSILON ) {
  19583. direction_eq = true;
  19584. }
  19585. } else {
  19586. if ( v_prev_x < - EPSILON ) {
  19587. if ( v_next_x < - EPSILON ) {
  19588. direction_eq = true;
  19589. }
  19590. } else {
  19591. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  19592. direction_eq = true;
  19593. }
  19594. }
  19595. }
  19596. if ( direction_eq ) {
  19597. // console.log("Warning: lines are a straight sequence");
  19598. v_trans_x = - v_prev_y;
  19599. v_trans_y = v_prev_x;
  19600. shrink_by = Math.sqrt( v_prev_lensq );
  19601. } else {
  19602. // console.log("Warning: lines are a straight spike");
  19603. v_trans_x = v_prev_x;
  19604. v_trans_y = v_prev_y;
  19605. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  19606. }
  19607. }
  19608. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  19609. }
  19610. var contourMovements = [];
  19611. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19612. if ( j === il ) j = 0;
  19613. if ( k === il ) k = 0;
  19614. // (j)---(i)---(k)
  19615. // console.log('i,j,k', i, j , k)
  19616. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  19617. }
  19618. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  19619. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19620. ahole = holes[ h ];
  19621. oneHoleMovements = [];
  19622. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  19623. if ( j === il ) j = 0;
  19624. if ( k === il ) k = 0;
  19625. // (j)---(i)---(k)
  19626. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  19627. }
  19628. holesMovements.push( oneHoleMovements );
  19629. verticesMovements = verticesMovements.concat( oneHoleMovements );
  19630. }
  19631. // Loop bevelSegments, 1 for the front, 1 for the back
  19632. for ( b = 0; b < bevelSegments; b ++ ) {
  19633. //for ( b = bevelSegments; b > 0; b -- ) {
  19634. t = b / bevelSegments;
  19635. z = bevelThickness * ( 1 - t );
  19636. //z = bevelThickness * t;
  19637. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  19638. //bs = bevelSize * t; // linear
  19639. // contract shape
  19640. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19641. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19642. v( vert.x, vert.y, - z );
  19643. }
  19644. // expand holes
  19645. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19646. ahole = holes[ h ];
  19647. oneHoleMovements = holesMovements[ h ];
  19648. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19649. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19650. v( vert.x, vert.y, - z );
  19651. }
  19652. }
  19653. }
  19654. bs = bevelSize;
  19655. // Back facing vertices
  19656. for ( i = 0; i < vlen; i ++ ) {
  19657. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19658. if ( ! extrudeByPath ) {
  19659. v( vert.x, vert.y, 0 );
  19660. } else {
  19661. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  19662. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  19663. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  19664. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  19665. v( position2.x, position2.y, position2.z );
  19666. }
  19667. }
  19668. // Add stepped vertices...
  19669. // Including front facing vertices
  19670. var s;
  19671. for ( s = 1; s <= steps; s ++ ) {
  19672. for ( i = 0; i < vlen; i ++ ) {
  19673. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  19674. if ( ! extrudeByPath ) {
  19675. v( vert.x, vert.y, amount / steps * s );
  19676. } else {
  19677. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  19678. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  19679. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  19680. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  19681. v( position2.x, position2.y, position2.z );
  19682. }
  19683. }
  19684. }
  19685. // Add bevel segments planes
  19686. //for ( b = 1; b <= bevelSegments; b ++ ) {
  19687. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  19688. t = b / bevelSegments;
  19689. z = bevelThickness * ( 1 - t );
  19690. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  19691. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  19692. // contract shape
  19693. for ( i = 0, il = contour.length; i < il; i ++ ) {
  19694. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  19695. v( vert.x, vert.y, amount + z );
  19696. }
  19697. // expand holes
  19698. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19699. ahole = holes[ h ];
  19700. oneHoleMovements = holesMovements[ h ];
  19701. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  19702. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  19703. if ( ! extrudeByPath ) {
  19704. v( vert.x, vert.y, amount + z );
  19705. } else {
  19706. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  19707. }
  19708. }
  19709. }
  19710. }
  19711. /* Faces */
  19712. // Top and bottom faces
  19713. buildLidFaces();
  19714. // Sides faces
  19715. buildSideFaces();
  19716. ///// Internal functions
  19717. function buildLidFaces() {
  19718. if ( bevelEnabled ) {
  19719. var layer = 0; // steps + 1
  19720. var offset = vlen * layer;
  19721. // Bottom faces
  19722. for ( i = 0; i < flen; i ++ ) {
  19723. face = faces[ i ];
  19724. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  19725. }
  19726. layer = steps + bevelSegments * 2;
  19727. offset = vlen * layer;
  19728. // Top faces
  19729. for ( i = 0; i < flen; i ++ ) {
  19730. face = faces[ i ];
  19731. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  19732. }
  19733. } else {
  19734. // Bottom faces
  19735. for ( i = 0; i < flen; i ++ ) {
  19736. face = faces[ i ];
  19737. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  19738. }
  19739. // Top faces
  19740. for ( i = 0; i < flen; i ++ ) {
  19741. face = faces[ i ];
  19742. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  19743. }
  19744. }
  19745. }
  19746. // Create faces for the z-sides of the shape
  19747. function buildSideFaces() {
  19748. var layeroffset = 0;
  19749. sidewalls( contour, layeroffset );
  19750. layeroffset += contour.length;
  19751. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  19752. ahole = holes[ h ];
  19753. sidewalls( ahole, layeroffset );
  19754. //, true
  19755. layeroffset += ahole.length;
  19756. }
  19757. }
  19758. function sidewalls( contour, layeroffset ) {
  19759. var j, k;
  19760. i = contour.length;
  19761. while ( -- i >= 0 ) {
  19762. j = i;
  19763. k = i - 1;
  19764. if ( k < 0 ) k = contour.length - 1;
  19765. //console.log('b', i,j, i-1, k,vertices.length);
  19766. var s = 0, sl = steps + bevelSegments * 2;
  19767. for ( s = 0; s < sl; s ++ ) {
  19768. var slen1 = vlen * s;
  19769. var slen2 = vlen * ( s + 1 );
  19770. var a = layeroffset + j + slen1,
  19771. b = layeroffset + k + slen1,
  19772. c = layeroffset + k + slen2,
  19773. d = layeroffset + j + slen2;
  19774. f4( a, b, c, d, contour, s, sl, j, k );
  19775. }
  19776. }
  19777. }
  19778. function v( x, y, z ) {
  19779. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  19780. }
  19781. function f3( a, b, c ) {
  19782. a += shapesOffset;
  19783. b += shapesOffset;
  19784. c += shapesOffset;
  19785. scope.faces.push( new THREE.Face3( a, b, c ) );
  19786. var uvs = uvgen.generateTopUV( scope, a, b, c );
  19787. scope.faceVertexUvs[ 0 ].push( uvs );
  19788. }
  19789. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  19790. a += shapesOffset;
  19791. b += shapesOffset;
  19792. c += shapesOffset;
  19793. d += shapesOffset;
  19794. scope.faces.push( new THREE.Face3( a, b, d ) );
  19795. scope.faces.push( new THREE.Face3( b, c, d ) );
  19796. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  19797. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  19798. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  19799. }
  19800. };
  19801. THREE.ExtrudeGeometry.WorldUVGenerator = {
  19802. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  19803. var vertices = geometry.vertices;
  19804. var a = vertices[ indexA ];
  19805. var b = vertices[ indexB ];
  19806. var c = vertices[ indexC ];
  19807. return [
  19808. new THREE.Vector2( a.x, a.y ),
  19809. new THREE.Vector2( b.x, b.y ),
  19810. new THREE.Vector2( c.x, c.y )
  19811. ];
  19812. },
  19813. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  19814. var vertices = geometry.vertices;
  19815. var a = vertices[ indexA ];
  19816. var b = vertices[ indexB ];
  19817. var c = vertices[ indexC ];
  19818. var d = vertices[ indexD ];
  19819. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  19820. return [
  19821. new THREE.Vector2( a.x, 1 - a.z ),
  19822. new THREE.Vector2( b.x, 1 - b.z ),
  19823. new THREE.Vector2( c.x, 1 - c.z ),
  19824. new THREE.Vector2( d.x, 1 - d.z )
  19825. ];
  19826. } else {
  19827. return [
  19828. new THREE.Vector2( a.y, 1 - a.z ),
  19829. new THREE.Vector2( b.y, 1 - b.z ),
  19830. new THREE.Vector2( c.y, 1 - c.z ),
  19831. new THREE.Vector2( d.y, 1 - d.z )
  19832. ];
  19833. }
  19834. }
  19835. };
  19836. // File:src/extras/geometries/ShapeGeometry.js
  19837. /**
  19838. * @author jonobr1 / http://jonobr1.com
  19839. *
  19840. * Creates a one-sided polygonal geometry from a path shape. Similar to
  19841. * ExtrudeGeometry.
  19842. *
  19843. * parameters = {
  19844. *
  19845. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  19846. *
  19847. * material: <int> // material index for front and back faces
  19848. * uvGenerator: <Object> // object that provides UV generator functions
  19849. *
  19850. * }
  19851. **/
  19852. THREE.ShapeGeometry = function ( shapes, options ) {
  19853. THREE.Geometry.call( this );
  19854. this.type = 'ShapeGeometry';
  19855. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  19856. this.addShapeList( shapes, options );
  19857. this.computeFaceNormals();
  19858. };
  19859. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19860. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  19861. /**
  19862. * Add an array of shapes to THREE.ShapeGeometry.
  19863. */
  19864. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  19865. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  19866. this.addShape( shapes[ i ], options );
  19867. }
  19868. return this;
  19869. };
  19870. /**
  19871. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  19872. */
  19873. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  19874. if ( options === undefined ) options = {};
  19875. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  19876. var material = options.material;
  19877. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  19878. //
  19879. var i, l, hole;
  19880. var shapesOffset = this.vertices.length;
  19881. var shapePoints = shape.extractPoints( curveSegments );
  19882. var vertices = shapePoints.shape;
  19883. var holes = shapePoints.holes;
  19884. var reverse = ! THREE.Shape.Utils.isClockWise( vertices );
  19885. if ( reverse ) {
  19886. vertices = vertices.reverse();
  19887. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  19888. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19889. hole = holes[ i ];
  19890. if ( THREE.Shape.Utils.isClockWise( hole ) ) {
  19891. holes[ i ] = hole.reverse();
  19892. }
  19893. }
  19894. reverse = false;
  19895. }
  19896. var faces = THREE.Shape.Utils.triangulateShape( vertices, holes );
  19897. // Vertices
  19898. for ( i = 0, l = holes.length; i < l; i ++ ) {
  19899. hole = holes[ i ];
  19900. vertices = vertices.concat( hole );
  19901. }
  19902. //
  19903. var vert, vlen = vertices.length;
  19904. var face, flen = faces.length;
  19905. for ( i = 0; i < vlen; i ++ ) {
  19906. vert = vertices[ i ];
  19907. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  19908. }
  19909. for ( i = 0; i < flen; i ++ ) {
  19910. face = faces[ i ];
  19911. var a = face[ 0 ] + shapesOffset;
  19912. var b = face[ 1 ] + shapesOffset;
  19913. var c = face[ 2 ] + shapesOffset;
  19914. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  19915. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  19916. }
  19917. };
  19918. // File:src/extras/geometries/LatheGeometry.js
  19919. /**
  19920. * @author astrodud / http://astrodud.isgreat.org/
  19921. * @author zz85 / https://github.com/zz85
  19922. * @author bhouston / http://clara.io
  19923. */
  19924. // points - to create a closed torus, one must use a set of points
  19925. // like so: [ a, b, c, d, a ], see first is the same as last.
  19926. // segments - the number of circumference segments to create
  19927. // phiStart - the starting radian
  19928. // phiLength - the radian (0 to 2*PI) range of the lathed section
  19929. // 2*pi is a closed lathe, less than 2PI is a portion.
  19930. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  19931. THREE.Geometry.call( this );
  19932. this.type = 'LatheGeometry';
  19933. this.parameters = {
  19934. points: points,
  19935. segments: segments,
  19936. phiStart: phiStart,
  19937. phiLength: phiLength
  19938. };
  19939. segments = segments || 12;
  19940. phiStart = phiStart || 0;
  19941. phiLength = phiLength || 2 * Math.PI;
  19942. var inversePointLength = 1.0 / ( points.length - 1 );
  19943. var inverseSegments = 1.0 / segments;
  19944. for ( var i = 0, il = segments; i <= il; i ++ ) {
  19945. var phi = phiStart + i * inverseSegments * phiLength;
  19946. var c = Math.cos( phi ),
  19947. s = Math.sin( phi );
  19948. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  19949. var pt = points[ j ];
  19950. var vertex = new THREE.Vector3();
  19951. vertex.x = c * pt.x - s * pt.y;
  19952. vertex.y = s * pt.x + c * pt.y;
  19953. vertex.z = pt.z;
  19954. this.vertices.push( vertex );
  19955. }
  19956. }
  19957. var np = points.length;
  19958. for ( var i = 0, il = segments; i < il; i ++ ) {
  19959. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  19960. var base = j + np * i;
  19961. var a = base;
  19962. var b = base + np;
  19963. var c = base + 1 + np;
  19964. var d = base + 1;
  19965. var u0 = i * inverseSegments;
  19966. var v0 = j * inversePointLength;
  19967. var u1 = u0 + inverseSegments;
  19968. var v1 = v0 + inversePointLength;
  19969. this.faces.push( new THREE.Face3( a, b, d ) );
  19970. this.faceVertexUvs[ 0 ].push( [
  19971. new THREE.Vector2( u0, v0 ),
  19972. new THREE.Vector2( u1, v0 ),
  19973. new THREE.Vector2( u0, v1 )
  19974. ] );
  19975. this.faces.push( new THREE.Face3( b, c, d ) );
  19976. this.faceVertexUvs[ 0 ].push( [
  19977. new THREE.Vector2( u1, v0 ),
  19978. new THREE.Vector2( u1, v1 ),
  19979. new THREE.Vector2( u0, v1 )
  19980. ] );
  19981. }
  19982. }
  19983. this.mergeVertices();
  19984. this.computeFaceNormals();
  19985. this.computeVertexNormals();
  19986. };
  19987. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  19988. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  19989. // File:src/extras/geometries/PlaneGeometry.js
  19990. /**
  19991. * @author mrdoob / http://mrdoob.com/
  19992. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  19993. */
  19994. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  19995. THREE.Geometry.call( this );
  19996. this.type = 'PlaneGeometry';
  19997. this.parameters = {
  19998. width: width,
  19999. height: height,
  20000. widthSegments: widthSegments,
  20001. heightSegments: heightSegments
  20002. };
  20003. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  20004. };
  20005. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20006. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  20007. THREE.PlaneGeometry.prototype.clone = function () {
  20008. var parameters = this.parameters;
  20009. return new THREE.PlaneGeometry(
  20010. parameters.width,
  20011. parameters.height,
  20012. parameters.widthSegments,
  20013. parameters.heightSegments
  20014. );
  20015. };
  20016. // File:src/extras/geometries/PlaneBufferGeometry.js
  20017. /**
  20018. * @author mrdoob / http://mrdoob.com/
  20019. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  20020. */
  20021. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  20022. THREE.BufferGeometry.call( this );
  20023. this.type = 'PlaneBufferGeometry';
  20024. this.parameters = {
  20025. width: width,
  20026. height: height,
  20027. widthSegments: widthSegments,
  20028. heightSegments: heightSegments
  20029. };
  20030. var width_half = width / 2;
  20031. var height_half = height / 2;
  20032. var gridX = Math.floor( widthSegments ) || 1;
  20033. var gridY = Math.floor( heightSegments ) || 1;
  20034. var gridX1 = gridX + 1;
  20035. var gridY1 = gridY + 1;
  20036. var segment_width = width / gridX;
  20037. var segment_height = height / gridY;
  20038. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  20039. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  20040. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  20041. var offset = 0;
  20042. var offset2 = 0;
  20043. for ( var iy = 0; iy < gridY1; iy ++ ) {
  20044. var y = iy * segment_height - height_half;
  20045. for ( var ix = 0; ix < gridX1; ix ++ ) {
  20046. var x = ix * segment_width - width_half;
  20047. vertices[ offset ] = x;
  20048. vertices[ offset + 1 ] = - y;
  20049. normals[ offset + 2 ] = 1;
  20050. uvs[ offset2 ] = ix / gridX;
  20051. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  20052. offset += 3;
  20053. offset2 += 2;
  20054. }
  20055. }
  20056. offset = 0;
  20057. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  20058. for ( var iy = 0; iy < gridY; iy ++ ) {
  20059. for ( var ix = 0; ix < gridX; ix ++ ) {
  20060. var a = ix + gridX1 * iy;
  20061. var b = ix + gridX1 * ( iy + 1 );
  20062. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  20063. var d = ( ix + 1 ) + gridX1 * iy;
  20064. indices[ offset ] = a;
  20065. indices[ offset + 1 ] = b;
  20066. indices[ offset + 2 ] = d;
  20067. indices[ offset + 3 ] = b;
  20068. indices[ offset + 4 ] = c;
  20069. indices[ offset + 5 ] = d;
  20070. offset += 6;
  20071. }
  20072. }
  20073. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  20074. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  20075. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  20076. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  20077. };
  20078. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20079. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  20080. THREE.PlaneBufferGeometry.prototype.clone = function () {
  20081. var parameters = this.parameters;
  20082. return new THREE.PlaneBufferGeometry(
  20083. parameters.width,
  20084. parameters.height,
  20085. parameters.widthSegments,
  20086. parameters.heightSegments
  20087. );
  20088. };
  20089. // File:src/extras/geometries/RingGeometry.js
  20090. /**
  20091. * @author Kaleb Murphy
  20092. */
  20093. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  20094. THREE.Geometry.call( this );
  20095. this.type = 'RingGeometry';
  20096. this.parameters = {
  20097. innerRadius: innerRadius,
  20098. outerRadius: outerRadius,
  20099. thetaSegments: thetaSegments,
  20100. phiSegments: phiSegments,
  20101. thetaStart: thetaStart,
  20102. thetaLength: thetaLength
  20103. };
  20104. innerRadius = innerRadius || 0;
  20105. outerRadius = outerRadius || 50;
  20106. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20107. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  20108. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  20109. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  20110. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  20111. for ( i = 0; i < phiSegments + 1; i ++ ) {
  20112. // concentric circles inside ring
  20113. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  20114. // number of segments per circle
  20115. var vertex = new THREE.Vector3();
  20116. var segment = thetaStart + o / thetaSegments * thetaLength;
  20117. vertex.x = radius * Math.cos( segment );
  20118. vertex.y = radius * Math.sin( segment );
  20119. this.vertices.push( vertex );
  20120. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  20121. }
  20122. radius += radiusStep;
  20123. }
  20124. var n = new THREE.Vector3( 0, 0, 1 );
  20125. for ( i = 0; i < phiSegments; i ++ ) {
  20126. // concentric circles inside ring
  20127. var thetaSegment = i * ( thetaSegments + 1 );
  20128. for ( o = 0; o < thetaSegments ; o ++ ) {
  20129. // number of segments per circle
  20130. var segment = o + thetaSegment;
  20131. var v1 = segment;
  20132. var v2 = segment + thetaSegments + 1;
  20133. var v3 = segment + thetaSegments + 2;
  20134. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  20135. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  20136. v1 = segment;
  20137. v2 = segment + thetaSegments + 2;
  20138. v3 = segment + 1;
  20139. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  20140. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  20141. }
  20142. }
  20143. this.computeFaceNormals();
  20144. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20145. };
  20146. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20147. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  20148. THREE.RingGeometry.prototype.clone = function () {
  20149. var parameters = this.parameters;
  20150. return new THREE.RingGeometry(
  20151. parameters.innerRadius,
  20152. parameters.outerRadius,
  20153. parameters.thetaSegments,
  20154. parameters.phiSegments,
  20155. parameters.thetaStart,
  20156. parameters.thetaLength
  20157. );
  20158. };
  20159. // File:src/extras/geometries/SphereGeometry.js
  20160. /**
  20161. * @author mrdoob / http://mrdoob.com/
  20162. */
  20163. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  20164. THREE.Geometry.call( this );
  20165. this.type = 'SphereGeometry';
  20166. this.parameters = {
  20167. radius: radius,
  20168. widthSegments: widthSegments,
  20169. heightSegments: heightSegments,
  20170. phiStart: phiStart,
  20171. phiLength: phiLength,
  20172. thetaStart: thetaStart,
  20173. thetaLength: thetaLength
  20174. };
  20175. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  20176. };
  20177. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20178. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  20179. THREE.SphereGeometry.prototype.clone = function () {
  20180. var parameters = this.parameters;
  20181. return new THREE.SphereGeometry(
  20182. parameters.radius,
  20183. parameters.widthSegments,
  20184. parameters.heightSegments,
  20185. parameters.phiStart,
  20186. parameters.phiLength,
  20187. parameters.thetaStart,
  20188. parameters.thetaLength
  20189. );
  20190. };
  20191. // File:src/extras/geometries/SphereBufferGeometry.js
  20192. /**
  20193. * @author benaadams / https://twitter.com/ben_a_adams
  20194. * based on THREE.SphereGeometry
  20195. */
  20196. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  20197. THREE.BufferGeometry.call( this );
  20198. this.type = 'SphereBufferGeometry';
  20199. this.parameters = {
  20200. radius: radius,
  20201. widthSegments: widthSegments,
  20202. heightSegments: heightSegments,
  20203. phiStart: phiStart,
  20204. phiLength: phiLength,
  20205. thetaStart: thetaStart,
  20206. thetaLength: thetaLength
  20207. };
  20208. radius = radius || 50;
  20209. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  20210. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  20211. phiStart = phiStart !== undefined ? phiStart : 0;
  20212. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  20213. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  20214. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  20215. var thetaEnd = thetaStart + thetaLength;
  20216. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  20217. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  20218. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  20219. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  20220. var index = 0, vertices = [], normal = new THREE.Vector3();
  20221. for ( var y = 0; y <= heightSegments; y ++ ) {
  20222. var verticesRow = [];
  20223. var v = y / heightSegments;
  20224. for ( var x = 0; x <= widthSegments; x ++ ) {
  20225. var u = x / widthSegments;
  20226. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20227. var py = radius * Math.cos( thetaStart + v * thetaLength );
  20228. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  20229. normal.set( px, py, pz ).normalize();
  20230. positions.setXYZ( index, px, py, pz );
  20231. normals.setXYZ( index, normal.x, normal.y, normal.z );
  20232. uvs.setXY( index, u, 1 - v );
  20233. verticesRow.push( index );
  20234. index ++;
  20235. }
  20236. vertices.push( verticesRow );
  20237. }
  20238. var indices = [];
  20239. for ( var y = 0; y < heightSegments; y ++ ) {
  20240. for ( var x = 0; x < widthSegments; x ++ ) {
  20241. var v1 = vertices[ y ][ x + 1 ];
  20242. var v2 = vertices[ y ][ x ];
  20243. var v3 = vertices[ y + 1 ][ x ];
  20244. var v4 = vertices[ y + 1 ][ x + 1 ];
  20245. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  20246. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  20247. }
  20248. }
  20249. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  20250. this.addAttribute( 'position', positions );
  20251. this.addAttribute( 'normal', normals );
  20252. this.addAttribute( 'uv', uvs );
  20253. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20254. };
  20255. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  20256. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  20257. THREE.SphereBufferGeometry.prototype.clone = function () {
  20258. var parameters = this.parameters;
  20259. return new THREE.SphereBufferGeometry(
  20260. parameters.radius,
  20261. parameters.widthSegments,
  20262. parameters.heightSegments,
  20263. parameters.phiStart,
  20264. parameters.phiLength,
  20265. parameters.thetaStart,
  20266. parameters.thetaLength
  20267. );
  20268. };
  20269. // File:src/extras/geometries/TextGeometry.js
  20270. /**
  20271. * @author zz85 / http://www.lab4games.net/zz85/blog
  20272. * @author alteredq / http://alteredqualia.com/
  20273. *
  20274. * For creating 3D text geometry in three.js
  20275. *
  20276. * Text = 3D Text
  20277. *
  20278. * parameters = {
  20279. * size: <float>, // size of the text
  20280. * height: <float>, // thickness to extrude text
  20281. * curveSegments: <int>, // number of points on the curves
  20282. *
  20283. * font: <string>, // font name
  20284. * weight: <string>, // font weight (normal, bold)
  20285. * style: <string>, // font style (normal, italics)
  20286. *
  20287. * bevelEnabled: <bool>, // turn on bevel
  20288. * bevelThickness: <float>, // how deep into text bevel goes
  20289. * bevelSize: <float>, // how far from text outline is bevel
  20290. * }
  20291. *
  20292. */
  20293. /* Usage Examples
  20294. // TextGeometry wrapper
  20295. var text3d = new TextGeometry( text, options );
  20296. // Complete manner
  20297. var textShapes = THREE.FontUtils.generateShapes( text, options );
  20298. var text3d = new ExtrudeGeometry( textShapes, options );
  20299. */
  20300. THREE.TextGeometry = function ( text, parameters ) {
  20301. parameters = parameters || {};
  20302. var textShapes = THREE.FontUtils.generateShapes( text, parameters );
  20303. // translate parameters to ExtrudeGeometry API
  20304. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  20305. // defaults
  20306. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  20307. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  20308. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  20309. THREE.ExtrudeGeometry.call( this, textShapes, parameters );
  20310. this.type = 'TextGeometry';
  20311. };
  20312. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  20313. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  20314. // File:src/extras/geometries/TorusGeometry.js
  20315. /**
  20316. * @author oosmoxiecode
  20317. * @author mrdoob / http://mrdoob.com/
  20318. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  20319. */
  20320. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  20321. THREE.Geometry.call( this );
  20322. this.type = 'TorusGeometry';
  20323. this.parameters = {
  20324. radius: radius,
  20325. tube: tube,
  20326. radialSegments: radialSegments,
  20327. tubularSegments: tubularSegments,
  20328. arc: arc
  20329. };
  20330. radius = radius || 100;
  20331. tube = tube || 40;
  20332. radialSegments = radialSegments || 8;
  20333. tubularSegments = tubularSegments || 6;
  20334. arc = arc || Math.PI * 2;
  20335. var center = new THREE.Vector3(), uvs = [], normals = [];
  20336. for ( var j = 0; j <= radialSegments; j ++ ) {
  20337. for ( var i = 0; i <= tubularSegments; i ++ ) {
  20338. var u = i / tubularSegments * arc;
  20339. var v = j / radialSegments * Math.PI * 2;
  20340. center.x = radius * Math.cos( u );
  20341. center.y = radius * Math.sin( u );
  20342. var vertex = new THREE.Vector3();
  20343. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  20344. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  20345. vertex.z = tube * Math.sin( v );
  20346. this.vertices.push( vertex );
  20347. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  20348. normals.push( vertex.clone().sub( center ).normalize() );
  20349. }
  20350. }
  20351. for ( var j = 1; j <= radialSegments; j ++ ) {
  20352. for ( var i = 1; i <= tubularSegments; i ++ ) {
  20353. var a = ( tubularSegments + 1 ) * j + i - 1;
  20354. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  20355. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  20356. var d = ( tubularSegments + 1 ) * j + i;
  20357. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  20358. this.faces.push( face );
  20359. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  20360. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  20361. this.faces.push( face );
  20362. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  20363. }
  20364. }
  20365. this.computeFaceNormals();
  20366. };
  20367. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20368. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  20369. THREE.TorusGeometry.prototype.clone = function () {
  20370. var parameters = this.parameters;
  20371. return new THREE.TorusGeometry(
  20372. parameters.radius,
  20373. parameters.tube,
  20374. parameters.radialSegments,
  20375. parameters.tubularSegments,
  20376. parameters.arc
  20377. );
  20378. };
  20379. // File:src/extras/geometries/TorusKnotGeometry.js
  20380. /**
  20381. * @author oosmoxiecode
  20382. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  20383. */
  20384. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  20385. THREE.Geometry.call( this );
  20386. this.type = 'TorusKnotGeometry';
  20387. this.parameters = {
  20388. radius: radius,
  20389. tube: tube,
  20390. radialSegments: radialSegments,
  20391. tubularSegments: tubularSegments,
  20392. p: p,
  20393. q: q,
  20394. heightScale: heightScale
  20395. };
  20396. radius = radius || 100;
  20397. tube = tube || 40;
  20398. radialSegments = radialSegments || 64;
  20399. tubularSegments = tubularSegments || 8;
  20400. p = p || 2;
  20401. q = q || 3;
  20402. heightScale = heightScale || 1;
  20403. var grid = new Array( radialSegments );
  20404. var tang = new THREE.Vector3();
  20405. var n = new THREE.Vector3();
  20406. var bitan = new THREE.Vector3();
  20407. for ( var i = 0; i < radialSegments; ++ i ) {
  20408. grid[ i ] = new Array( tubularSegments );
  20409. var u = i / radialSegments * 2 * p * Math.PI;
  20410. var p1 = getPos( u, q, p, radius, heightScale );
  20411. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  20412. tang.subVectors( p2, p1 );
  20413. n.addVectors( p2, p1 );
  20414. bitan.crossVectors( tang, n );
  20415. n.crossVectors( bitan, tang );
  20416. bitan.normalize();
  20417. n.normalize();
  20418. for ( var j = 0; j < tubularSegments; ++ j ) {
  20419. var v = j / tubularSegments * 2 * Math.PI;
  20420. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20421. var cy = tube * Math.sin( v );
  20422. var pos = new THREE.Vector3();
  20423. pos.x = p1.x + cx * n.x + cy * bitan.x;
  20424. pos.y = p1.y + cx * n.y + cy * bitan.y;
  20425. pos.z = p1.z + cx * n.z + cy * bitan.z;
  20426. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  20427. }
  20428. }
  20429. for ( var i = 0; i < radialSegments; ++ i ) {
  20430. for ( var j = 0; j < tubularSegments; ++ j ) {
  20431. var ip = ( i + 1 ) % radialSegments;
  20432. var jp = ( j + 1 ) % tubularSegments;
  20433. var a = grid[ i ][ j ];
  20434. var b = grid[ ip ][ j ];
  20435. var c = grid[ ip ][ jp ];
  20436. var d = grid[ i ][ jp ];
  20437. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  20438. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  20439. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  20440. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  20441. this.faces.push( new THREE.Face3( a, b, d ) );
  20442. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20443. this.faces.push( new THREE.Face3( b, c, d ) );
  20444. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20445. }
  20446. }
  20447. this.computeFaceNormals();
  20448. this.computeVertexNormals();
  20449. function getPos( u, in_q, in_p, radius, heightScale ) {
  20450. var cu = Math.cos( u );
  20451. var su = Math.sin( u );
  20452. var quOverP = in_q / in_p * u;
  20453. var cs = Math.cos( quOverP );
  20454. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  20455. var ty = radius * ( 2 + cs ) * su * 0.5;
  20456. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  20457. return new THREE.Vector3( tx, ty, tz );
  20458. }
  20459. };
  20460. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20461. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  20462. THREE.TorusKnotGeometry.prototype.clone = function () {
  20463. var parameters = this.parameters;
  20464. return new THREE.TorusKnotGeometry(
  20465. parameters.radius,
  20466. parameters.tube,
  20467. parameters.radialSegments,
  20468. parameters.tubularSegments,
  20469. parameters.p,
  20470. parameters.q,
  20471. parameters.heightScale
  20472. );
  20473. };
  20474. // File:src/extras/geometries/TubeGeometry.js
  20475. /**
  20476. * @author WestLangley / https://github.com/WestLangley
  20477. * @author zz85 / https://github.com/zz85
  20478. * @author miningold / https://github.com/miningold
  20479. * @author jonobr1 / https://github.com/jonobr1
  20480. *
  20481. * Modified from the TorusKnotGeometry by @oosmoxiecode
  20482. *
  20483. * Creates a tube which extrudes along a 3d spline
  20484. *
  20485. * Uses parallel transport frames as described in
  20486. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  20487. */
  20488. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  20489. THREE.Geometry.call( this );
  20490. this.type = 'TubeGeometry';
  20491. this.parameters = {
  20492. path: path,
  20493. segments: segments,
  20494. radius: radius,
  20495. radialSegments: radialSegments,
  20496. closed: closed,
  20497. taper: taper
  20498. };
  20499. segments = segments || 64;
  20500. radius = radius || 1;
  20501. radialSegments = radialSegments || 8;
  20502. closed = closed || false;
  20503. taper = taper || THREE.TubeGeometry.NoTaper;
  20504. var grid = [];
  20505. var scope = this,
  20506. tangent,
  20507. normal,
  20508. binormal,
  20509. numpoints = segments + 1,
  20510. u, v, r,
  20511. cx, cy,
  20512. pos, pos2 = new THREE.Vector3(),
  20513. i, j,
  20514. ip, jp,
  20515. a, b, c, d,
  20516. uva, uvb, uvc, uvd;
  20517. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  20518. tangents = frames.tangents,
  20519. normals = frames.normals,
  20520. binormals = frames.binormals;
  20521. // proxy internals
  20522. this.tangents = tangents;
  20523. this.normals = normals;
  20524. this.binormals = binormals;
  20525. function vert( x, y, z ) {
  20526. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  20527. }
  20528. // construct the grid
  20529. for ( i = 0; i < numpoints; i ++ ) {
  20530. grid[ i ] = [];
  20531. u = i / ( numpoints - 1 );
  20532. pos = path.getPointAt( u );
  20533. tangent = tangents[ i ];
  20534. normal = normals[ i ];
  20535. binormal = binormals[ i ];
  20536. r = radius * taper( u );
  20537. for ( j = 0; j < radialSegments; j ++ ) {
  20538. v = j / radialSegments * 2 * Math.PI;
  20539. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  20540. cy = r * Math.sin( v );
  20541. pos2.copy( pos );
  20542. pos2.x += cx * normal.x + cy * binormal.x;
  20543. pos2.y += cx * normal.y + cy * binormal.y;
  20544. pos2.z += cx * normal.z + cy * binormal.z;
  20545. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  20546. }
  20547. }
  20548. // construct the mesh
  20549. for ( i = 0; i < segments; i ++ ) {
  20550. for ( j = 0; j < radialSegments; j ++ ) {
  20551. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  20552. jp = ( j + 1 ) % radialSegments;
  20553. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  20554. b = grid[ ip ][ j ];
  20555. c = grid[ ip ][ jp ];
  20556. d = grid[ i ][ jp ];
  20557. uva = new THREE.Vector2( i / segments, j / radialSegments );
  20558. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  20559. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  20560. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  20561. this.faces.push( new THREE.Face3( a, b, d ) );
  20562. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  20563. this.faces.push( new THREE.Face3( b, c, d ) );
  20564. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  20565. }
  20566. }
  20567. this.computeFaceNormals();
  20568. this.computeVertexNormals();
  20569. };
  20570. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20571. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  20572. THREE.TubeGeometry.prototype.clone = function() {
  20573. return new this.constructor( this.parameters.path,
  20574. this.parameters.segments, this.parameters.radius, this.parameters.radialSegments,
  20575. this.parameters.closed, this.parameters.taper
  20576. );
  20577. };
  20578. THREE.TubeGeometry.NoTaper = function ( u ) {
  20579. return 1;
  20580. };
  20581. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  20582. return Math.sin( Math.PI * u );
  20583. };
  20584. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  20585. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  20586. var normal = new THREE.Vector3(),
  20587. tangents = [],
  20588. normals = [],
  20589. binormals = [],
  20590. vec = new THREE.Vector3(),
  20591. mat = new THREE.Matrix4(),
  20592. numpoints = segments + 1,
  20593. theta,
  20594. epsilon = 0.0001,
  20595. smallest,
  20596. tx, ty, tz,
  20597. i, u;
  20598. // expose internals
  20599. this.tangents = tangents;
  20600. this.normals = normals;
  20601. this.binormals = binormals;
  20602. // compute the tangent vectors for each segment on the path
  20603. for ( i = 0; i < numpoints; i ++ ) {
  20604. u = i / ( numpoints - 1 );
  20605. tangents[ i ] = path.getTangentAt( u );
  20606. tangents[ i ].normalize();
  20607. }
  20608. initialNormal3();
  20609. /*
  20610. function initialNormal1(lastBinormal) {
  20611. // fixed start binormal. Has dangers of 0 vectors
  20612. normals[ 0 ] = new THREE.Vector3();
  20613. binormals[ 0 ] = new THREE.Vector3();
  20614. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  20615. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  20616. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20617. }
  20618. function initialNormal2() {
  20619. // This uses the Frenet-Serret formula for deriving binormal
  20620. var t2 = path.getTangentAt( epsilon );
  20621. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  20622. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  20623. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  20624. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  20625. }
  20626. */
  20627. function initialNormal3() {
  20628. // select an initial normal vector perpendicular to the first tangent vector,
  20629. // and in the direction of the smallest tangent xyz component
  20630. normals[ 0 ] = new THREE.Vector3();
  20631. binormals[ 0 ] = new THREE.Vector3();
  20632. smallest = Number.MAX_VALUE;
  20633. tx = Math.abs( tangents[ 0 ].x );
  20634. ty = Math.abs( tangents[ 0 ].y );
  20635. tz = Math.abs( tangents[ 0 ].z );
  20636. if ( tx <= smallest ) {
  20637. smallest = tx;
  20638. normal.set( 1, 0, 0 );
  20639. }
  20640. if ( ty <= smallest ) {
  20641. smallest = ty;
  20642. normal.set( 0, 1, 0 );
  20643. }
  20644. if ( tz <= smallest ) {
  20645. normal.set( 0, 0, 1 );
  20646. }
  20647. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  20648. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  20649. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  20650. }
  20651. // compute the slowly-varying normal and binormal vectors for each segment on the path
  20652. for ( i = 1; i < numpoints; i ++ ) {
  20653. normals[ i ] = normals[ i - 1 ].clone();
  20654. binormals[ i ] = binormals[ i - 1 ].clone();
  20655. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  20656. if ( vec.length() > epsilon ) {
  20657. vec.normalize();
  20658. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  20659. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  20660. }
  20661. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20662. }
  20663. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  20664. if ( closed ) {
  20665. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  20666. theta /= ( numpoints - 1 );
  20667. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  20668. theta = - theta;
  20669. }
  20670. for ( i = 1; i < numpoints; i ++ ) {
  20671. // twist a little...
  20672. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  20673. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  20674. }
  20675. }
  20676. };
  20677. // File:src/extras/geometries/PolyhedronGeometry.js
  20678. /**
  20679. * @author clockworkgeek / https://github.com/clockworkgeek
  20680. * @author timothypratley / https://github.com/timothypratley
  20681. * @author WestLangley / http://github.com/WestLangley
  20682. */
  20683. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  20684. THREE.Geometry.call( this );
  20685. this.type = 'PolyhedronGeometry';
  20686. this.parameters = {
  20687. vertices: vertices,
  20688. indices: indices,
  20689. radius: radius,
  20690. detail: detail
  20691. };
  20692. radius = radius || 1;
  20693. detail = detail || 0;
  20694. var that = this;
  20695. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  20696. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  20697. }
  20698. var p = this.vertices;
  20699. var faces = [];
  20700. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  20701. var v1 = p[ indices[ i ] ];
  20702. var v2 = p[ indices[ i + 1 ] ];
  20703. var v3 = p[ indices[ i + 2 ] ];
  20704. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  20705. }
  20706. var centroid = new THREE.Vector3();
  20707. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  20708. subdivide( faces[ i ], detail );
  20709. }
  20710. // Handle case when face straddles the seam
  20711. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  20712. var uvs = this.faceVertexUvs[ 0 ][ i ];
  20713. var x0 = uvs[ 0 ].x;
  20714. var x1 = uvs[ 1 ].x;
  20715. var x2 = uvs[ 2 ].x;
  20716. var max = Math.max( x0, Math.max( x1, x2 ) );
  20717. var min = Math.min( x0, Math.min( x1, x2 ) );
  20718. if ( max > 0.9 && min < 0.1 ) {
  20719. // 0.9 is somewhat arbitrary
  20720. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  20721. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  20722. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  20723. }
  20724. }
  20725. // Apply radius
  20726. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  20727. this.vertices[ i ].multiplyScalar( radius );
  20728. }
  20729. // Merge vertices
  20730. this.mergeVertices();
  20731. this.computeFaceNormals();
  20732. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  20733. // Project vector onto sphere's surface
  20734. function prepare( vector ) {
  20735. var vertex = vector.normalize().clone();
  20736. vertex.index = that.vertices.push( vertex ) - 1;
  20737. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  20738. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  20739. var v = inclination( vector ) / Math.PI + 0.5;
  20740. vertex.uv = new THREE.Vector2( u, 1 - v );
  20741. return vertex;
  20742. }
  20743. // Approximate a curved face with recursively sub-divided triangles.
  20744. function make( v1, v2, v3, materialIndex ) {
  20745. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  20746. that.faces.push( face );
  20747. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  20748. var azi = azimuth( centroid );
  20749. that.faceVertexUvs[ 0 ].push( [
  20750. correctUV( v1.uv, v1, azi ),
  20751. correctUV( v2.uv, v2, azi ),
  20752. correctUV( v3.uv, v3, azi )
  20753. ] );
  20754. }
  20755. // Analytically subdivide a face to the required detail level.
  20756. function subdivide( face, detail ) {
  20757. var cols = Math.pow( 2, detail );
  20758. var a = prepare( that.vertices[ face.a ] );
  20759. var b = prepare( that.vertices[ face.b ] );
  20760. var c = prepare( that.vertices[ face.c ] );
  20761. var v = [];
  20762. var materialIndex = face.materialIndex;
  20763. // Construct all of the vertices for this subdivision.
  20764. for ( var i = 0 ; i <= cols; i ++ ) {
  20765. v[ i ] = [];
  20766. var aj = prepare( a.clone().lerp( c, i / cols ) );
  20767. var bj = prepare( b.clone().lerp( c, i / cols ) );
  20768. var rows = cols - i;
  20769. for ( var j = 0; j <= rows; j ++ ) {
  20770. if ( j === 0 && i === cols ) {
  20771. v[ i ][ j ] = aj;
  20772. } else {
  20773. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  20774. }
  20775. }
  20776. }
  20777. // Construct all of the faces.
  20778. for ( var i = 0; i < cols ; i ++ ) {
  20779. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  20780. var k = Math.floor( j / 2 );
  20781. if ( j % 2 === 0 ) {
  20782. make(
  20783. v[ i ][ k + 1 ],
  20784. v[ i + 1 ][ k ],
  20785. v[ i ][ k ],
  20786. materialIndex
  20787. );
  20788. } else {
  20789. make(
  20790. v[ i ][ k + 1 ],
  20791. v[ i + 1 ][ k + 1 ],
  20792. v[ i + 1 ][ k ],
  20793. materialIndex
  20794. );
  20795. }
  20796. }
  20797. }
  20798. }
  20799. // Angle around the Y axis, counter-clockwise when looking from above.
  20800. function azimuth( vector ) {
  20801. return Math.atan2( vector.z, - vector.x );
  20802. }
  20803. // Angle above the XZ plane.
  20804. function inclination( vector ) {
  20805. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  20806. }
  20807. // Texture fixing helper. Spheres have some odd behaviours.
  20808. function correctUV( uv, vector, azimuth ) {
  20809. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  20810. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  20811. return uv.clone();
  20812. }
  20813. };
  20814. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  20815. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  20816. THREE.PolyhedronGeometry.prototype.clone = function () {
  20817. var parameters = this.parameters;
  20818. return new THREE.PolyhedronGeometry(
  20819. parameters.vertices,
  20820. parameters.indices,
  20821. parameters.radius,
  20822. parameters.detail
  20823. );
  20824. };
  20825. // File:src/extras/geometries/DodecahedronGeometry.js
  20826. /**
  20827. * @author Abe Pazos / https://hamoid.com
  20828. */
  20829. THREE.DodecahedronGeometry = function ( radius, detail ) {
  20830. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20831. var r = 1 / t;
  20832. var vertices = [
  20833. // (±1, ±1, ±1)
  20834. - 1, - 1, - 1, - 1, - 1, 1,
  20835. - 1, 1, - 1, - 1, 1, 1,
  20836. 1, - 1, - 1, 1, - 1, 1,
  20837. 1, 1, - 1, 1, 1, 1,
  20838. // (0, ±1/φ, ±φ)
  20839. 0, - r, - t, 0, - r, t,
  20840. 0, r, - t, 0, r, t,
  20841. // (±1/φ, ±φ, 0)
  20842. - r, - t, 0, - r, t, 0,
  20843. r, - t, 0, r, t, 0,
  20844. // (±φ, 0, ±1/φ)
  20845. - t, 0, - r, t, 0, - r,
  20846. - t, 0, r, t, 0, r
  20847. ];
  20848. var indices = [
  20849. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  20850. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  20851. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  20852. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  20853. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  20854. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  20855. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  20856. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  20857. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  20858. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  20859. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  20860. 1, 12, 14, 1, 14, 5, 1, 5, 9
  20861. ];
  20862. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20863. this.type = 'DodecahedronGeometry';
  20864. this.parameters = {
  20865. radius: radius,
  20866. detail: detail
  20867. };
  20868. };
  20869. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20870. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  20871. THREE.DodecahedronGeometry.prototype.clone = function () {
  20872. var parameters = this.parameters;
  20873. return new THREE.DodecahedronGeometry(
  20874. parameters.radius,
  20875. parameters.detail
  20876. );
  20877. };
  20878. // File:src/extras/geometries/IcosahedronGeometry.js
  20879. /**
  20880. * @author timothypratley / https://github.com/timothypratley
  20881. */
  20882. THREE.IcosahedronGeometry = function ( radius, detail ) {
  20883. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  20884. var vertices = [
  20885. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  20886. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  20887. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  20888. ];
  20889. var indices = [
  20890. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  20891. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  20892. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  20893. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  20894. ];
  20895. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20896. this.type = 'IcosahedronGeometry';
  20897. this.parameters = {
  20898. radius: radius,
  20899. detail: detail
  20900. };
  20901. };
  20902. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20903. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  20904. THREE.IcosahedronGeometry.prototype.clone = function () {
  20905. var parameters = this.parameters;
  20906. return new THREE.IcosahedronGeometry(
  20907. parameters.radius,
  20908. parameters.detail
  20909. );
  20910. };
  20911. // File:src/extras/geometries/OctahedronGeometry.js
  20912. /**
  20913. * @author timothypratley / https://github.com/timothypratley
  20914. */
  20915. THREE.OctahedronGeometry = function ( radius, detail ) {
  20916. var vertices = [
  20917. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  20918. ];
  20919. var indices = [
  20920. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  20921. ];
  20922. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20923. this.type = 'OctahedronGeometry';
  20924. this.parameters = {
  20925. radius: radius,
  20926. detail: detail
  20927. };
  20928. };
  20929. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20930. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  20931. THREE.OctahedronGeometry.prototype.clone = function () {
  20932. var parameters = this.parameters;
  20933. return new THREE.OctahedronGeometry(
  20934. parameters.radius,
  20935. parameters.detail
  20936. );
  20937. };
  20938. // File:src/extras/geometries/TetrahedronGeometry.js
  20939. /**
  20940. * @author timothypratley / https://github.com/timothypratley
  20941. */
  20942. THREE.TetrahedronGeometry = function ( radius, detail ) {
  20943. var vertices = [
  20944. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  20945. ];
  20946. var indices = [
  20947. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  20948. ];
  20949. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  20950. this.type = 'TetrahedronGeometry';
  20951. this.parameters = {
  20952. radius: radius,
  20953. detail: detail
  20954. };
  20955. };
  20956. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  20957. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  20958. THREE.TetrahedronGeometry.prototype.clone = function () {
  20959. var parameters = this.parameters;
  20960. return new THREE.TetrahedronGeometry(
  20961. parameters.radius,
  20962. parameters.detail
  20963. );
  20964. };
  20965. // File:src/extras/geometries/ParametricGeometry.js
  20966. /**
  20967. * @author zz85 / https://github.com/zz85
  20968. * Parametric Surfaces Geometry
  20969. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  20970. *
  20971. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  20972. *
  20973. */
  20974. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  20975. THREE.Geometry.call( this );
  20976. this.type = 'ParametricGeometry';
  20977. this.parameters = {
  20978. func: func,
  20979. slices: slices,
  20980. stacks: stacks
  20981. };
  20982. var verts = this.vertices;
  20983. var faces = this.faces;
  20984. var uvs = this.faceVertexUvs[ 0 ];
  20985. var i, j, p;
  20986. var u, v;
  20987. var sliceCount = slices + 1;
  20988. for ( i = 0; i <= stacks; i ++ ) {
  20989. v = i / stacks;
  20990. for ( j = 0; j <= slices; j ++ ) {
  20991. u = j / slices;
  20992. p = func( u, v );
  20993. verts.push( p );
  20994. }
  20995. }
  20996. var a, b, c, d;
  20997. var uva, uvb, uvc, uvd;
  20998. for ( i = 0; i < stacks; i ++ ) {
  20999. for ( j = 0; j < slices; j ++ ) {
  21000. a = i * sliceCount + j;
  21001. b = i * sliceCount + j + 1;
  21002. c = ( i + 1 ) * sliceCount + j + 1;
  21003. d = ( i + 1 ) * sliceCount + j;
  21004. uva = new THREE.Vector2( j / slices, i / stacks );
  21005. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  21006. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  21007. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  21008. faces.push( new THREE.Face3( a, b, d ) );
  21009. uvs.push( [ uva, uvb, uvd ] );
  21010. faces.push( new THREE.Face3( b, c, d ) );
  21011. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  21012. }
  21013. }
  21014. // console.log(this);
  21015. // magic bullet
  21016. // var diff = this.mergeVertices();
  21017. // console.log('removed ', diff, ' vertices by merging');
  21018. this.computeFaceNormals();
  21019. this.computeVertexNormals();
  21020. };
  21021. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21022. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  21023. // File:src/extras/geometries/WireframeGeometry.js
  21024. /**
  21025. * @author mrdoob / http://mrdoob.com/
  21026. */
  21027. THREE.WireframeGeometry = function ( geometry ) {
  21028. THREE.BufferGeometry.call( this );
  21029. var edge = [ 0, 0 ], hash = {};
  21030. function sortFunction( a, b ) {
  21031. return a - b;
  21032. }
  21033. var keys = [ 'a', 'b', 'c' ];
  21034. if ( geometry instanceof THREE.Geometry ) {
  21035. var vertices = geometry.vertices;
  21036. var faces = geometry.faces;
  21037. var numEdges = 0;
  21038. // allocate maximal size
  21039. var edges = new Uint32Array( 6 * faces.length );
  21040. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21041. var face = faces[ i ];
  21042. for ( var j = 0; j < 3; j ++ ) {
  21043. edge[ 0 ] = face[ keys[ j ] ];
  21044. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21045. edge.sort( sortFunction );
  21046. var key = edge.toString();
  21047. if ( hash[ key ] === undefined ) {
  21048. edges[ 2 * numEdges ] = edge[ 0 ];
  21049. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  21050. hash[ key ] = true;
  21051. numEdges ++;
  21052. }
  21053. }
  21054. }
  21055. var coords = new Float32Array( numEdges * 2 * 3 );
  21056. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  21057. for ( var j = 0; j < 2; j ++ ) {
  21058. var vertex = vertices[ edges [ 2 * i + j ] ];
  21059. var index = 6 * i + 3 * j;
  21060. coords[ index + 0 ] = vertex.x;
  21061. coords[ index + 1 ] = vertex.y;
  21062. coords[ index + 2 ] = vertex.z;
  21063. }
  21064. }
  21065. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21066. } else if ( geometry instanceof THREE.BufferGeometry ) {
  21067. if ( geometry.index !== null ) {
  21068. // Indexed BufferGeometry
  21069. var indices = geometry.index.array;
  21070. var vertices = geometry.attributes.position;
  21071. var drawcalls = geometry.drawcalls;
  21072. var numEdges = 0;
  21073. if ( drawcalls.length === 0 ) {
  21074. geometry.addGroup( 0, indices.length );
  21075. }
  21076. // allocate maximal size
  21077. var edges = new Uint32Array( 2 * indices.length );
  21078. for ( var o = 0, ol = drawcalls.length; o < ol; ++ o ) {
  21079. var drawcall = drawcalls[ o ];
  21080. var start = drawcall.start;
  21081. var count = drawcall.count;
  21082. for ( var i = start, il = start + count; i < il; i += 3 ) {
  21083. for ( var j = 0; j < 3; j ++ ) {
  21084. edge[ 0 ] = indices[ i + j ];
  21085. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  21086. edge.sort( sortFunction );
  21087. var key = edge.toString();
  21088. if ( hash[ key ] === undefined ) {
  21089. edges[ 2 * numEdges ] = edge[ 0 ];
  21090. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  21091. hash[ key ] = true;
  21092. numEdges ++;
  21093. }
  21094. }
  21095. }
  21096. }
  21097. var coords = new Float32Array( numEdges * 2 * 3 );
  21098. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  21099. for ( var j = 0; j < 2; j ++ ) {
  21100. var index = 6 * i + 3 * j;
  21101. var index2 = edges[ 2 * i + j ];
  21102. coords[ index + 0 ] = vertices.getX( index2 );
  21103. coords[ index + 1 ] = vertices.getY( index2 );
  21104. coords[ index + 2 ] = vertices.getZ( index2 );
  21105. }
  21106. }
  21107. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21108. } else {
  21109. // non-indexed BufferGeometry
  21110. var vertices = geometry.attributes.position.array;
  21111. var numEdges = vertices.length / 3;
  21112. var numTris = numEdges / 3;
  21113. var coords = new Float32Array( numEdges * 2 * 3 );
  21114. for ( var i = 0, l = numTris; i < l; i ++ ) {
  21115. for ( var j = 0; j < 3; j ++ ) {
  21116. var index = 18 * i + 6 * j;
  21117. var index1 = 9 * i + 3 * j;
  21118. coords[ index + 0 ] = vertices[ index1 ];
  21119. coords[ index + 1 ] = vertices[ index1 + 1 ];
  21120. coords[ index + 2 ] = vertices[ index1 + 2 ];
  21121. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  21122. coords[ index + 3 ] = vertices[ index2 ];
  21123. coords[ index + 4 ] = vertices[ index2 + 1 ];
  21124. coords[ index + 5 ] = vertices[ index2 + 2 ];
  21125. }
  21126. }
  21127. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  21128. }
  21129. }
  21130. };
  21131. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21132. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  21133. // File:src/extras/helpers/AxisHelper.js
  21134. /**
  21135. * @author sroucheray / http://sroucheray.org/
  21136. * @author mrdoob / http://mrdoob.com/
  21137. */
  21138. THREE.AxisHelper = function ( size ) {
  21139. size = size || 1;
  21140. var vertices = new Float32Array( [
  21141. 0, 0, 0, size, 0, 0,
  21142. 0, 0, 0, 0, size, 0,
  21143. 0, 0, 0, 0, 0, size
  21144. ] );
  21145. var colors = new Float32Array( [
  21146. 1, 0, 0, 1, 0.6, 0,
  21147. 0, 1, 0, 0.6, 1, 0,
  21148. 0, 0, 1, 0, 0.6, 1
  21149. ] );
  21150. var geometry = new THREE.BufferGeometry();
  21151. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  21152. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  21153. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21154. THREE.LineSegments.call( this, geometry, material );
  21155. };
  21156. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21157. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  21158. // File:src/extras/helpers/ArrowHelper.js
  21159. /**
  21160. * @author WestLangley / http://github.com/WestLangley
  21161. * @author zz85 / http://github.com/zz85
  21162. * @author bhouston / http://clara.io
  21163. *
  21164. * Creates an arrow for visualizing directions
  21165. *
  21166. * Parameters:
  21167. * dir - Vector3
  21168. * origin - Vector3
  21169. * length - Number
  21170. * color - color in hex value
  21171. * headLength - Number
  21172. * headWidth - Number
  21173. */
  21174. THREE.ArrowHelper = ( function () {
  21175. var lineGeometry = new THREE.Geometry();
  21176. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  21177. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  21178. coneGeometry.translate( 0, - 0.5, 0 );
  21179. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  21180. // dir is assumed to be normalized
  21181. THREE.Object3D.call( this );
  21182. if ( color === undefined ) color = 0xffff00;
  21183. if ( length === undefined ) length = 1;
  21184. if ( headLength === undefined ) headLength = 0.2 * length;
  21185. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  21186. this.position.copy( origin );
  21187. if ( headLength < length ) {
  21188. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  21189. this.line.matrixAutoUpdate = false;
  21190. this.add( this.line );
  21191. }
  21192. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  21193. this.cone.matrixAutoUpdate = false;
  21194. this.add( this.cone );
  21195. this.setDirection( dir );
  21196. this.setLength( length, headLength, headWidth );
  21197. }
  21198. }() );
  21199. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  21200. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  21201. THREE.ArrowHelper.prototype.setDirection = ( function () {
  21202. var axis = new THREE.Vector3();
  21203. var radians;
  21204. return function setDirection( dir ) {
  21205. // dir is assumed to be normalized
  21206. if ( dir.y > 0.99999 ) {
  21207. this.quaternion.set( 0, 0, 0, 1 );
  21208. } else if ( dir.y < - 0.99999 ) {
  21209. this.quaternion.set( 1, 0, 0, 0 );
  21210. } else {
  21211. axis.set( dir.z, 0, - dir.x ).normalize();
  21212. radians = Math.acos( dir.y );
  21213. this.quaternion.setFromAxisAngle( axis, radians );
  21214. }
  21215. };
  21216. }() );
  21217. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  21218. if ( headLength === undefined ) headLength = 0.2 * length;
  21219. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  21220. if ( headLength < length ){
  21221. this.line.scale.set( 1, length - headLength, 1 );
  21222. this.line.updateMatrix();
  21223. }
  21224. this.cone.scale.set( headWidth, headLength, headWidth );
  21225. this.cone.position.y = length;
  21226. this.cone.updateMatrix();
  21227. };
  21228. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  21229. if ( this.line !== undefined ) this.line.material.color.set( color );
  21230. this.cone.material.color.set( color );
  21231. };
  21232. // File:src/extras/helpers/BoxHelper.js
  21233. /**
  21234. * @author mrdoob / http://mrdoob.com/
  21235. */
  21236. THREE.BoxHelper = function ( object ) {
  21237. var indices = new Uint16Array( [ 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6, 7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 ] );
  21238. var positions = new Float32Array( 8 * 3 );
  21239. var geometry = new THREE.BufferGeometry();
  21240. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  21241. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21242. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  21243. if ( object !== undefined ) {
  21244. this.update( object );
  21245. }
  21246. };
  21247. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21248. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  21249. THREE.BoxHelper.prototype.update = ( function () {
  21250. var box = new THREE.Box3();
  21251. return function ( object ) {
  21252. box.setFromObject( object );
  21253. if ( box.empty() ) return;
  21254. var min = box.min;
  21255. var max = box.max;
  21256. /*
  21257. 5____4
  21258. 1/___0/|
  21259. | 6__|_7
  21260. 2/___3/
  21261. 0: max.x, max.y, max.z
  21262. 1: min.x, max.y, max.z
  21263. 2: min.x, min.y, max.z
  21264. 3: max.x, min.y, max.z
  21265. 4: max.x, max.y, min.z
  21266. 5: min.x, max.y, min.z
  21267. 6: min.x, min.y, min.z
  21268. 7: max.x, min.y, min.z
  21269. */
  21270. var position = this.geometry.attributes.position;
  21271. var array = position.array;
  21272. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  21273. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  21274. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  21275. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  21276. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  21277. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  21278. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  21279. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  21280. position.needsUpdate = true;
  21281. this.geometry.computeBoundingSphere();
  21282. }
  21283. } )();
  21284. // File:src/extras/helpers/BoundingBoxHelper.js
  21285. /**
  21286. * @author WestLangley / http://github.com/WestLangley
  21287. */
  21288. // a helper to show the world-axis-aligned bounding box for an object
  21289. THREE.BoundingBoxHelper = function ( object, hex ) {
  21290. var color = ( hex !== undefined ) ? hex : 0x888888;
  21291. this.object = object;
  21292. this.box = new THREE.Box3();
  21293. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  21294. };
  21295. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  21296. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  21297. THREE.BoundingBoxHelper.prototype.update = function () {
  21298. this.box.setFromObject( this.object );
  21299. this.box.size( this.scale );
  21300. this.box.center( this.position );
  21301. };
  21302. // File:src/extras/helpers/CameraHelper.js
  21303. /**
  21304. * @author alteredq / http://alteredqualia.com/
  21305. *
  21306. * - shows frustum, line of sight and up of the camera
  21307. * - suitable for fast updates
  21308. * - based on frustum visualization in lightgl.js shadowmap example
  21309. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  21310. */
  21311. THREE.CameraHelper = function ( camera ) {
  21312. var geometry = new THREE.Geometry();
  21313. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  21314. var pointMap = {};
  21315. // colors
  21316. var hexFrustum = 0xffaa00;
  21317. var hexCone = 0xff0000;
  21318. var hexUp = 0x00aaff;
  21319. var hexTarget = 0xffffff;
  21320. var hexCross = 0x333333;
  21321. // near
  21322. addLine( "n1", "n2", hexFrustum );
  21323. addLine( "n2", "n4", hexFrustum );
  21324. addLine( "n4", "n3", hexFrustum );
  21325. addLine( "n3", "n1", hexFrustum );
  21326. // far
  21327. addLine( "f1", "f2", hexFrustum );
  21328. addLine( "f2", "f4", hexFrustum );
  21329. addLine( "f4", "f3", hexFrustum );
  21330. addLine( "f3", "f1", hexFrustum );
  21331. // sides
  21332. addLine( "n1", "f1", hexFrustum );
  21333. addLine( "n2", "f2", hexFrustum );
  21334. addLine( "n3", "f3", hexFrustum );
  21335. addLine( "n4", "f4", hexFrustum );
  21336. // cone
  21337. addLine( "p", "n1", hexCone );
  21338. addLine( "p", "n2", hexCone );
  21339. addLine( "p", "n3", hexCone );
  21340. addLine( "p", "n4", hexCone );
  21341. // up
  21342. addLine( "u1", "u2", hexUp );
  21343. addLine( "u2", "u3", hexUp );
  21344. addLine( "u3", "u1", hexUp );
  21345. // target
  21346. addLine( "c", "t", hexTarget );
  21347. addLine( "p", "c", hexCross );
  21348. // cross
  21349. addLine( "cn1", "cn2", hexCross );
  21350. addLine( "cn3", "cn4", hexCross );
  21351. addLine( "cf1", "cf2", hexCross );
  21352. addLine( "cf3", "cf4", hexCross );
  21353. function addLine( a, b, hex ) {
  21354. addPoint( a, hex );
  21355. addPoint( b, hex );
  21356. }
  21357. function addPoint( id, hex ) {
  21358. geometry.vertices.push( new THREE.Vector3() );
  21359. geometry.colors.push( new THREE.Color( hex ) );
  21360. if ( pointMap[ id ] === undefined ) {
  21361. pointMap[ id ] = [];
  21362. }
  21363. pointMap[ id ].push( geometry.vertices.length - 1 );
  21364. }
  21365. THREE.LineSegments.call( this, geometry, material );
  21366. this.camera = camera;
  21367. this.camera.updateProjectionMatrix();
  21368. this.matrix = camera.matrixWorld;
  21369. this.matrixAutoUpdate = false;
  21370. this.pointMap = pointMap;
  21371. this.update();
  21372. };
  21373. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21374. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  21375. THREE.CameraHelper.prototype.update = function () {
  21376. var geometry, pointMap;
  21377. var vector = new THREE.Vector3();
  21378. var camera = new THREE.Camera();
  21379. function setPoint( point, x, y, z ) {
  21380. vector.set( x, y, z ).unproject( camera );
  21381. var points = pointMap[ point ];
  21382. if ( points !== undefined ) {
  21383. for ( var i = 0, il = points.length; i < il; i ++ ) {
  21384. geometry.vertices[ points[ i ] ].copy( vector );
  21385. }
  21386. }
  21387. }
  21388. return function () {
  21389. geometry = this.geometry;
  21390. pointMap = this.pointMap;
  21391. var w = 1, h = 1;
  21392. // we need just camera projection matrix
  21393. // world matrix must be identity
  21394. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  21395. // center / target
  21396. setPoint( "c", 0, 0, - 1 );
  21397. setPoint( "t", 0, 0, 1 );
  21398. // near
  21399. setPoint( "n1", - w, - h, - 1 );
  21400. setPoint( "n2", w, - h, - 1 );
  21401. setPoint( "n3", - w, h, - 1 );
  21402. setPoint( "n4", w, h, - 1 );
  21403. // far
  21404. setPoint( "f1", - w, - h, 1 );
  21405. setPoint( "f2", w, - h, 1 );
  21406. setPoint( "f3", - w, h, 1 );
  21407. setPoint( "f4", w, h, 1 );
  21408. // up
  21409. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  21410. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  21411. setPoint( "u3", 0, h * 2, - 1 );
  21412. // cross
  21413. setPoint( "cf1", - w, 0, 1 );
  21414. setPoint( "cf2", w, 0, 1 );
  21415. setPoint( "cf3", 0, - h, 1 );
  21416. setPoint( "cf4", 0, h, 1 );
  21417. setPoint( "cn1", - w, 0, - 1 );
  21418. setPoint( "cn2", w, 0, - 1 );
  21419. setPoint( "cn3", 0, - h, - 1 );
  21420. setPoint( "cn4", 0, h, - 1 );
  21421. geometry.verticesNeedUpdate = true;
  21422. };
  21423. }();
  21424. // File:src/extras/helpers/DirectionalLightHelper.js
  21425. /**
  21426. * @author alteredq / http://alteredqualia.com/
  21427. * @author mrdoob / http://mrdoob.com/
  21428. * @author WestLangley / http://github.com/WestLangley
  21429. */
  21430. THREE.DirectionalLightHelper = function ( light, size ) {
  21431. THREE.Object3D.call( this );
  21432. this.light = light;
  21433. this.light.updateMatrixWorld();
  21434. this.matrix = light.matrixWorld;
  21435. this.matrixAutoUpdate = false;
  21436. size = size || 1;
  21437. var geometry = new THREE.Geometry();
  21438. geometry.vertices.push(
  21439. new THREE.Vector3( - size, size, 0 ),
  21440. new THREE.Vector3( size, size, 0 ),
  21441. new THREE.Vector3( size, - size, 0 ),
  21442. new THREE.Vector3( - size, - size, 0 ),
  21443. new THREE.Vector3( - size, size, 0 )
  21444. );
  21445. var material = new THREE.LineBasicMaterial( { fog: false } );
  21446. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21447. this.lightPlane = new THREE.Line( geometry, material );
  21448. this.add( this.lightPlane );
  21449. geometry = new THREE.Geometry();
  21450. geometry.vertices.push(
  21451. new THREE.Vector3(),
  21452. new THREE.Vector3()
  21453. );
  21454. material = new THREE.LineBasicMaterial( { fog: false } );
  21455. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21456. this.targetLine = new THREE.Line( geometry, material );
  21457. this.add( this.targetLine );
  21458. this.update();
  21459. };
  21460. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21461. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  21462. THREE.DirectionalLightHelper.prototype.dispose = function () {
  21463. this.lightPlane.geometry.dispose();
  21464. this.lightPlane.material.dispose();
  21465. this.targetLine.geometry.dispose();
  21466. this.targetLine.material.dispose();
  21467. };
  21468. THREE.DirectionalLightHelper.prototype.update = function () {
  21469. var v1 = new THREE.Vector3();
  21470. var v2 = new THREE.Vector3();
  21471. var v3 = new THREE.Vector3();
  21472. return function () {
  21473. v1.setFromMatrixPosition( this.light.matrixWorld );
  21474. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  21475. v3.subVectors( v2, v1 );
  21476. this.lightPlane.lookAt( v3 );
  21477. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21478. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  21479. this.targetLine.geometry.verticesNeedUpdate = true;
  21480. this.targetLine.material.color.copy( this.lightPlane.material.color );
  21481. };
  21482. }();
  21483. // File:src/extras/helpers/EdgesHelper.js
  21484. /**
  21485. * @author WestLangley / http://github.com/WestLangley
  21486. * @param object THREE.Mesh whose geometry will be used
  21487. * @param hex line color
  21488. * @param thresholdAngle the minimum angle (in degrees),
  21489. * between the face normals of adjacent faces,
  21490. * that is required to render an edge. A value of 10 means
  21491. * an edge is only rendered if the angle is at least 10 degrees.
  21492. */
  21493. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  21494. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21495. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  21496. this.matrix = object.matrixWorld;
  21497. this.matrixAutoUpdate = false;
  21498. };
  21499. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21500. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  21501. // File:src/extras/helpers/FaceNormalsHelper.js
  21502. /**
  21503. * @author mrdoob / http://mrdoob.com/
  21504. * @author WestLangley / http://github.com/WestLangley
  21505. */
  21506. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  21507. // FaceNormalsHelper only supports THREE.Geometry
  21508. this.object = object;
  21509. this.size = ( size !== undefined ) ? size : 1;
  21510. var color = ( hex !== undefined ) ? hex : 0xffff00;
  21511. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21512. //
  21513. var nNormals = 0;
  21514. var objGeometry = this.object.geometry;
  21515. if ( objGeometry instanceof THREE.Geometry ) {
  21516. nNormals = objGeometry.faces.length;
  21517. } else {
  21518. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  21519. }
  21520. //
  21521. var geometry = new THREE.BufferGeometry();
  21522. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21523. geometry.addAttribute( 'position', positions );
  21524. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21525. //
  21526. this.matrixAutoUpdate = false;
  21527. this.update();
  21528. };
  21529. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21530. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  21531. THREE.FaceNormalsHelper.prototype.update = ( function () {
  21532. var v1 = new THREE.Vector3();
  21533. var v2 = new THREE.Vector3();
  21534. var normalMatrix = new THREE.Matrix3();
  21535. return function update() {
  21536. this.object.updateMatrixWorld( true );
  21537. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21538. var matrixWorld = this.object.matrixWorld;
  21539. var position = this.geometry.attributes.position;
  21540. //
  21541. var objGeometry = this.object.geometry;
  21542. var vertices = objGeometry.vertices;
  21543. var faces = objGeometry.faces;
  21544. var idx = 0;
  21545. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21546. var face = faces[ i ];
  21547. var normal = face.normal;
  21548. v1.copy( vertices[ face.a ] )
  21549. .add( vertices[ face.b ] )
  21550. .add( vertices[ face.c ] )
  21551. .divideScalar( 3 )
  21552. .applyMatrix4( matrixWorld );
  21553. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21554. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21555. idx = idx + 1;
  21556. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21557. idx = idx + 1;
  21558. }
  21559. position.needsUpdate = true;
  21560. return this;
  21561. }
  21562. }() );
  21563. // File:src/extras/helpers/GridHelper.js
  21564. /**
  21565. * @author mrdoob / http://mrdoob.com/
  21566. */
  21567. THREE.GridHelper = function ( size, step ) {
  21568. var geometry = new THREE.Geometry();
  21569. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  21570. this.color1 = new THREE.Color( 0x444444 );
  21571. this.color2 = new THREE.Color( 0x888888 );
  21572. for ( var i = - size; i <= size; i += step ) {
  21573. geometry.vertices.push(
  21574. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  21575. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  21576. );
  21577. var color = i === 0 ? this.color1 : this.color2;
  21578. geometry.colors.push( color, color, color, color );
  21579. }
  21580. THREE.LineSegments.call( this, geometry, material );
  21581. };
  21582. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21583. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  21584. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  21585. this.color1.set( colorCenterLine );
  21586. this.color2.set( colorGrid );
  21587. this.geometry.colorsNeedUpdate = true;
  21588. };
  21589. // File:src/extras/helpers/HemisphereLightHelper.js
  21590. /**
  21591. * @author alteredq / http://alteredqualia.com/
  21592. * @author mrdoob / http://mrdoob.com/
  21593. */
  21594. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  21595. THREE.Object3D.call( this );
  21596. this.light = light;
  21597. this.light.updateMatrixWorld();
  21598. this.matrix = light.matrixWorld;
  21599. this.matrixAutoUpdate = false;
  21600. this.colors = [ new THREE.Color(), new THREE.Color() ];
  21601. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21602. geometry.rotateX( - Math.PI / 2 );
  21603. for ( var i = 0, il = 8; i < il; i ++ ) {
  21604. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  21605. }
  21606. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  21607. this.lightSphere = new THREE.Mesh( geometry, material );
  21608. this.add( this.lightSphere );
  21609. this.update();
  21610. };
  21611. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21612. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  21613. THREE.HemisphereLightHelper.prototype.dispose = function () {
  21614. this.lightSphere.geometry.dispose();
  21615. this.lightSphere.material.dispose();
  21616. };
  21617. THREE.HemisphereLightHelper.prototype.update = function () {
  21618. var vector = new THREE.Vector3();
  21619. return function () {
  21620. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  21621. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  21622. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  21623. this.lightSphere.geometry.colorsNeedUpdate = true;
  21624. }
  21625. }();
  21626. // File:src/extras/helpers/PointLightHelper.js
  21627. /**
  21628. * @author alteredq / http://alteredqualia.com/
  21629. * @author mrdoob / http://mrdoob.com/
  21630. */
  21631. THREE.PointLightHelper = function ( light, sphereSize ) {
  21632. this.light = light;
  21633. this.light.updateMatrixWorld();
  21634. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  21635. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21636. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21637. THREE.Mesh.call( this, geometry, material );
  21638. this.matrix = this.light.matrixWorld;
  21639. this.matrixAutoUpdate = false;
  21640. /*
  21641. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  21642. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  21643. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  21644. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  21645. var d = light.distance;
  21646. if ( d === 0.0 ) {
  21647. this.lightDistance.visible = false;
  21648. } else {
  21649. this.lightDistance.scale.set( d, d, d );
  21650. }
  21651. this.add( this.lightDistance );
  21652. */
  21653. };
  21654. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  21655. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  21656. THREE.PointLightHelper.prototype.dispose = function () {
  21657. this.geometry.dispose();
  21658. this.material.dispose();
  21659. };
  21660. THREE.PointLightHelper.prototype.update = function () {
  21661. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21662. /*
  21663. var d = this.light.distance;
  21664. if ( d === 0.0 ) {
  21665. this.lightDistance.visible = false;
  21666. } else {
  21667. this.lightDistance.visible = true;
  21668. this.lightDistance.scale.set( d, d, d );
  21669. }
  21670. */
  21671. };
  21672. // File:src/extras/helpers/SkeletonHelper.js
  21673. /**
  21674. * @author Sean Griffin / http://twitter.com/sgrif
  21675. * @author Michael Guerrero / http://realitymeltdown.com
  21676. * @author mrdoob / http://mrdoob.com/
  21677. * @author ikerr / http://verold.com
  21678. */
  21679. THREE.SkeletonHelper = function ( object ) {
  21680. this.bones = this.getBoneList( object );
  21681. var geometry = new THREE.Geometry();
  21682. for ( var i = 0; i < this.bones.length; i ++ ) {
  21683. var bone = this.bones[ i ];
  21684. if ( bone.parent instanceof THREE.Bone ) {
  21685. geometry.vertices.push( new THREE.Vector3() );
  21686. geometry.vertices.push( new THREE.Vector3() );
  21687. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  21688. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  21689. }
  21690. }
  21691. geometry.dynamic = true;
  21692. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  21693. THREE.LineSegments.call( this, geometry, material );
  21694. this.root = object;
  21695. this.matrix = object.matrixWorld;
  21696. this.matrixAutoUpdate = false;
  21697. this.update();
  21698. };
  21699. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21700. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  21701. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  21702. var boneList = [];
  21703. if ( object instanceof THREE.Bone ) {
  21704. boneList.push( object );
  21705. }
  21706. for ( var i = 0; i < object.children.length; i ++ ) {
  21707. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  21708. }
  21709. return boneList;
  21710. };
  21711. THREE.SkeletonHelper.prototype.update = function () {
  21712. var geometry = this.geometry;
  21713. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  21714. var boneMatrix = new THREE.Matrix4();
  21715. var j = 0;
  21716. for ( var i = 0; i < this.bones.length; i ++ ) {
  21717. var bone = this.bones[ i ];
  21718. if ( bone.parent instanceof THREE.Bone ) {
  21719. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  21720. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  21721. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  21722. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  21723. j += 2;
  21724. }
  21725. }
  21726. geometry.verticesNeedUpdate = true;
  21727. geometry.computeBoundingSphere();
  21728. };
  21729. // File:src/extras/helpers/SpotLightHelper.js
  21730. /**
  21731. * @author alteredq / http://alteredqualia.com/
  21732. * @author mrdoob / http://mrdoob.com/
  21733. * @author WestLangley / http://github.com/WestLangley
  21734. */
  21735. THREE.SpotLightHelper = function ( light ) {
  21736. THREE.Object3D.call( this );
  21737. this.light = light;
  21738. this.light.updateMatrixWorld();
  21739. this.matrix = light.matrixWorld;
  21740. this.matrixAutoUpdate = false;
  21741. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  21742. geometry.translate( 0, - 0.5, 0 );
  21743. geometry.rotateX( - Math.PI / 2 );
  21744. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  21745. this.cone = new THREE.Mesh( geometry, material );
  21746. this.add( this.cone );
  21747. this.update();
  21748. };
  21749. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  21750. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  21751. THREE.SpotLightHelper.prototype.dispose = function () {
  21752. this.cone.geometry.dispose();
  21753. this.cone.material.dispose();
  21754. };
  21755. THREE.SpotLightHelper.prototype.update = function () {
  21756. var vector = new THREE.Vector3();
  21757. var vector2 = new THREE.Vector3();
  21758. return function () {
  21759. var coneLength = this.light.distance ? this.light.distance : 10000;
  21760. var coneWidth = coneLength * Math.tan( this.light.angle );
  21761. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  21762. vector.setFromMatrixPosition( this.light.matrixWorld );
  21763. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  21764. this.cone.lookAt( vector2.sub( vector ) );
  21765. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  21766. };
  21767. }();
  21768. // File:src/extras/helpers/VertexNormalsHelper.js
  21769. /**
  21770. * @author mrdoob / http://mrdoob.com/
  21771. * @author WestLangley / http://github.com/WestLangley
  21772. */
  21773. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  21774. this.object = object;
  21775. this.size = ( size !== undefined ) ? size : 1;
  21776. var color = ( hex !== undefined ) ? hex : 0xff0000;
  21777. var width = ( linewidth !== undefined ) ? linewidth : 1;
  21778. //
  21779. var nNormals = 0;
  21780. var objGeometry = this.object.geometry;
  21781. if ( objGeometry instanceof THREE.Geometry ) {
  21782. nNormals = objGeometry.faces.length * 3;
  21783. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21784. nNormals = objGeometry.attributes.normal.count
  21785. }
  21786. //
  21787. var geometry = new THREE.BufferGeometry();
  21788. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  21789. geometry.addAttribute( 'position', positions );
  21790. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  21791. //
  21792. this.matrixAutoUpdate = false;
  21793. this.update();
  21794. };
  21795. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21796. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  21797. THREE.VertexNormalsHelper.prototype.update = ( function () {
  21798. var v1 = new THREE.Vector3();
  21799. var v2 = new THREE.Vector3();
  21800. var normalMatrix = new THREE.Matrix3();
  21801. return function update() {
  21802. var keys = [ 'a', 'b', 'c' ];
  21803. this.object.updateMatrixWorld( true );
  21804. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  21805. var matrixWorld = this.object.matrixWorld;
  21806. var position = this.geometry.attributes.position;
  21807. //
  21808. var objGeometry = this.object.geometry;
  21809. if ( objGeometry instanceof THREE.Geometry ) {
  21810. var vertices = objGeometry.vertices;
  21811. var faces = objGeometry.faces;
  21812. var idx = 0;
  21813. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21814. var face = faces[ i ];
  21815. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  21816. var vertex = vertices[ face[ keys[ j ] ] ];
  21817. var normal = face.vertexNormals[ j ];
  21818. v1.copy( vertex ).applyMatrix4( matrixWorld );
  21819. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21820. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21821. idx = idx + 1;
  21822. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21823. idx = idx + 1;
  21824. }
  21825. }
  21826. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  21827. var objPos = objGeometry.attributes.position;
  21828. var objNorm = objGeometry.attributes.normal;
  21829. var idx = 0;
  21830. // for simplicity, ignore index and drawcalls, and render every normal
  21831. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  21832. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  21833. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  21834. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  21835. position.setXYZ( idx, v1.x, v1.y, v1.z );
  21836. idx = idx + 1;
  21837. position.setXYZ( idx, v2.x, v2.y, v2.z );
  21838. idx = idx + 1;
  21839. }
  21840. }
  21841. position.needsUpdate = true;
  21842. return this;
  21843. }
  21844. }() );
  21845. // File:src/extras/helpers/WireframeHelper.js
  21846. /**
  21847. * @author mrdoob / http://mrdoob.com/
  21848. */
  21849. THREE.WireframeHelper = function ( object, hex ) {
  21850. var color = ( hex !== undefined ) ? hex : 0xffffff;
  21851. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  21852. this.matrix = object.matrixWorld;
  21853. this.matrixAutoUpdate = false;
  21854. };
  21855. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  21856. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  21857. // File:src/extras/objects/ImmediateRenderObject.js
  21858. /**
  21859. * @author alteredq / http://alteredqualia.com/
  21860. */
  21861. THREE.ImmediateRenderObject = function ( material ) {
  21862. THREE.Object3D.call( this );
  21863. this.material = material;
  21864. this.render = function ( renderCallback ) {};
  21865. };
  21866. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  21867. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  21868. // File:src/extras/objects/MorphBlendMesh.js
  21869. /**
  21870. * @author alteredq / http://alteredqualia.com/
  21871. */
  21872. THREE.MorphBlendMesh = function( geometry, material ) {
  21873. THREE.Mesh.call( this, geometry, material );
  21874. this.animationsMap = {};
  21875. this.animationsList = [];
  21876. // prepare default animation
  21877. // (all frames played together in 1 second)
  21878. var numFrames = this.geometry.morphTargets.length;
  21879. var name = "__default";
  21880. var startFrame = 0;
  21881. var endFrame = numFrames - 1;
  21882. var fps = numFrames / 1;
  21883. this.createAnimation( name, startFrame, endFrame, fps );
  21884. this.setAnimationWeight( name, 1 );
  21885. };
  21886. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  21887. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  21888. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  21889. var animation = {
  21890. start: start,
  21891. end: end,
  21892. length: end - start + 1,
  21893. fps: fps,
  21894. duration: ( end - start ) / fps,
  21895. lastFrame: 0,
  21896. currentFrame: 0,
  21897. active: false,
  21898. time: 0,
  21899. direction: 1,
  21900. weight: 1,
  21901. directionBackwards: false,
  21902. mirroredLoop: false
  21903. };
  21904. this.animationsMap[ name ] = animation;
  21905. this.animationsList.push( animation );
  21906. };
  21907. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  21908. var pattern = /([a-z]+)_?(\d+)/;
  21909. var firstAnimation, frameRanges = {};
  21910. var geometry = this.geometry;
  21911. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  21912. var morph = geometry.morphTargets[ i ];
  21913. var chunks = morph.name.match( pattern );
  21914. if ( chunks && chunks.length > 1 ) {
  21915. var name = chunks[ 1 ];
  21916. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  21917. var range = frameRanges[ name ];
  21918. if ( i < range.start ) range.start = i;
  21919. if ( i > range.end ) range.end = i;
  21920. if ( ! firstAnimation ) firstAnimation = name;
  21921. }
  21922. }
  21923. for ( var name in frameRanges ) {
  21924. var range = frameRanges[ name ];
  21925. this.createAnimation( name, range.start, range.end, fps );
  21926. }
  21927. this.firstAnimation = firstAnimation;
  21928. };
  21929. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  21930. var animation = this.animationsMap[ name ];
  21931. if ( animation ) {
  21932. animation.direction = 1;
  21933. animation.directionBackwards = false;
  21934. }
  21935. };
  21936. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  21937. var animation = this.animationsMap[ name ];
  21938. if ( animation ) {
  21939. animation.direction = - 1;
  21940. animation.directionBackwards = true;
  21941. }
  21942. };
  21943. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  21944. var animation = this.animationsMap[ name ];
  21945. if ( animation ) {
  21946. animation.fps = fps;
  21947. animation.duration = ( animation.end - animation.start ) / animation.fps;
  21948. }
  21949. };
  21950. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  21951. var animation = this.animationsMap[ name ];
  21952. if ( animation ) {
  21953. animation.duration = duration;
  21954. animation.fps = ( animation.end - animation.start ) / animation.duration;
  21955. }
  21956. };
  21957. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  21958. var animation = this.animationsMap[ name ];
  21959. if ( animation ) {
  21960. animation.weight = weight;
  21961. }
  21962. };
  21963. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  21964. var animation = this.animationsMap[ name ];
  21965. if ( animation ) {
  21966. animation.time = time;
  21967. }
  21968. };
  21969. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  21970. var time = 0;
  21971. var animation = this.animationsMap[ name ];
  21972. if ( animation ) {
  21973. time = animation.time;
  21974. }
  21975. return time;
  21976. };
  21977. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  21978. var duration = - 1;
  21979. var animation = this.animationsMap[ name ];
  21980. if ( animation ) {
  21981. duration = animation.duration;
  21982. }
  21983. return duration;
  21984. };
  21985. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  21986. var animation = this.animationsMap[ name ];
  21987. if ( animation ) {
  21988. animation.time = 0;
  21989. animation.active = true;
  21990. } else {
  21991. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  21992. }
  21993. };
  21994. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  21995. var animation = this.animationsMap[ name ];
  21996. if ( animation ) {
  21997. animation.active = false;
  21998. }
  21999. };
  22000. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  22001. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  22002. var animation = this.animationsList[ i ];
  22003. if ( ! animation.active ) continue;
  22004. var frameTime = animation.duration / animation.length;
  22005. animation.time += animation.direction * delta;
  22006. if ( animation.mirroredLoop ) {
  22007. if ( animation.time > animation.duration || animation.time < 0 ) {
  22008. animation.direction *= - 1;
  22009. if ( animation.time > animation.duration ) {
  22010. animation.time = animation.duration;
  22011. animation.directionBackwards = true;
  22012. }
  22013. if ( animation.time < 0 ) {
  22014. animation.time = 0;
  22015. animation.directionBackwards = false;
  22016. }
  22017. }
  22018. } else {
  22019. animation.time = animation.time % animation.duration;
  22020. if ( animation.time < 0 ) animation.time += animation.duration;
  22021. }
  22022. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  22023. var weight = animation.weight;
  22024. if ( keyframe !== animation.currentFrame ) {
  22025. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  22026. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  22027. this.morphTargetInfluences[ keyframe ] = 0;
  22028. animation.lastFrame = animation.currentFrame;
  22029. animation.currentFrame = keyframe;
  22030. }
  22031. var mix = ( animation.time % frameTime ) / frameTime;
  22032. if ( animation.directionBackwards ) mix = 1 - mix;
  22033. if ( animation.currentFrame !== animation.lastFrame ) {
  22034. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  22035. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  22036. } else {
  22037. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  22038. }
  22039. }
  22040. };