three.js 887 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560
  1. // File:src/Three.js
  2. /**
  3. * @author mrdoob / http://mrdoob.com/
  4. */
  5. var THREE = { REVISION: '74' };
  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. //
  13. if ( Number.EPSILON === undefined ) {
  14. Number.EPSILON = Math.pow( 2, - 52 );
  15. }
  16. //
  17. if ( Math.sign === undefined ) {
  18. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/sign
  19. Math.sign = function ( x ) {
  20. return ( x < 0 ) ? - 1 : ( x > 0 ) ? 1 : + x;
  21. };
  22. }
  23. if ( Function.prototype.name === undefined && Object.defineProperty !== undefined ) {
  24. // Missing in IE9-11.
  25. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/name
  26. Object.defineProperty( Function.prototype, 'name', {
  27. get: function () {
  28. return this.toString().match( /^\s*function\s*(\S*)\s*\(/ )[ 1 ];
  29. }
  30. } );
  31. }
  32. if ( Object.assign === undefined ) {
  33. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
  34. Object.defineProperty( Object, 'assign', {
  35. writable: true,
  36. configurable: true,
  37. value: function ( target ) {
  38. 'use strict';
  39. if ( target === undefined || target === null ) {
  40. throw new TypeError( "Cannot convert first argument to object" );
  41. }
  42. var to = Object( target );
  43. for ( var i = 1, n = arguments.length; i !== n; ++ i ) {
  44. var nextSource = arguments[ i ];
  45. if ( nextSource === undefined || nextSource === null ) continue;
  46. nextSource = Object( nextSource );
  47. var keysArray = Object.keys( nextSource );
  48. for ( var nextIndex = 0, len = keysArray.length; nextIndex !== len; ++ nextIndex ) {
  49. var nextKey = keysArray[ nextIndex ];
  50. var desc = Object.getOwnPropertyDescriptor( nextSource, nextKey );
  51. if ( desc !== undefined && desc.enumerable ) {
  52. to[ nextKey ] = nextSource[ nextKey ];
  53. }
  54. }
  55. }
  56. return to;
  57. }
  58. } );
  59. }
  60. // https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent.button
  61. THREE.MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2 };
  62. // GL STATE CONSTANTS
  63. THREE.CullFaceNone = 0;
  64. THREE.CullFaceBack = 1;
  65. THREE.CullFaceFront = 2;
  66. THREE.CullFaceFrontBack = 3;
  67. THREE.FrontFaceDirectionCW = 0;
  68. THREE.FrontFaceDirectionCCW = 1;
  69. // SHADOWING TYPES
  70. THREE.BasicShadowMap = 0;
  71. THREE.PCFShadowMap = 1;
  72. THREE.PCFSoftShadowMap = 2;
  73. // MATERIAL CONSTANTS
  74. // side
  75. THREE.FrontSide = 0;
  76. THREE.BackSide = 1;
  77. THREE.DoubleSide = 2;
  78. // shading
  79. THREE.FlatShading = 1;
  80. THREE.SmoothShading = 2;
  81. // colors
  82. THREE.NoColors = 0;
  83. THREE.FaceColors = 1;
  84. THREE.VertexColors = 2;
  85. // blending modes
  86. THREE.NoBlending = 0;
  87. THREE.NormalBlending = 1;
  88. THREE.AdditiveBlending = 2;
  89. THREE.SubtractiveBlending = 3;
  90. THREE.MultiplyBlending = 4;
  91. THREE.CustomBlending = 5;
  92. // custom blending equations
  93. // (numbers start from 100 not to clash with other
  94. // mappings to OpenGL constants defined in Texture.js)
  95. THREE.AddEquation = 100;
  96. THREE.SubtractEquation = 101;
  97. THREE.ReverseSubtractEquation = 102;
  98. THREE.MinEquation = 103;
  99. THREE.MaxEquation = 104;
  100. // custom blending destination factors
  101. THREE.ZeroFactor = 200;
  102. THREE.OneFactor = 201;
  103. THREE.SrcColorFactor = 202;
  104. THREE.OneMinusSrcColorFactor = 203;
  105. THREE.SrcAlphaFactor = 204;
  106. THREE.OneMinusSrcAlphaFactor = 205;
  107. THREE.DstAlphaFactor = 206;
  108. THREE.OneMinusDstAlphaFactor = 207;
  109. // custom blending source factors
  110. //THREE.ZeroFactor = 200;
  111. //THREE.OneFactor = 201;
  112. //THREE.SrcAlphaFactor = 204;
  113. //THREE.OneMinusSrcAlphaFactor = 205;
  114. //THREE.DstAlphaFactor = 206;
  115. //THREE.OneMinusDstAlphaFactor = 207;
  116. THREE.DstColorFactor = 208;
  117. THREE.OneMinusDstColorFactor = 209;
  118. THREE.SrcAlphaSaturateFactor = 210;
  119. // depth modes
  120. THREE.NeverDepth = 0;
  121. THREE.AlwaysDepth = 1;
  122. THREE.LessDepth = 2;
  123. THREE.LessEqualDepth = 3;
  124. THREE.EqualDepth = 4;
  125. THREE.GreaterEqualDepth = 5;
  126. THREE.GreaterDepth = 6;
  127. THREE.NotEqualDepth = 7;
  128. // TEXTURE CONSTANTS
  129. THREE.MultiplyOperation = 0;
  130. THREE.MixOperation = 1;
  131. THREE.AddOperation = 2;
  132. // Mapping modes
  133. THREE.UVMapping = 300;
  134. THREE.CubeReflectionMapping = 301;
  135. THREE.CubeRefractionMapping = 302;
  136. THREE.EquirectangularReflectionMapping = 303;
  137. THREE.EquirectangularRefractionMapping = 304;
  138. THREE.SphericalReflectionMapping = 305;
  139. // Wrapping modes
  140. THREE.RepeatWrapping = 1000;
  141. THREE.ClampToEdgeWrapping = 1001;
  142. THREE.MirroredRepeatWrapping = 1002;
  143. // Filters
  144. THREE.NearestFilter = 1003;
  145. THREE.NearestMipMapNearestFilter = 1004;
  146. THREE.NearestMipMapLinearFilter = 1005;
  147. THREE.LinearFilter = 1006;
  148. THREE.LinearMipMapNearestFilter = 1007;
  149. THREE.LinearMipMapLinearFilter = 1008;
  150. // Data types
  151. THREE.UnsignedByteType = 1009;
  152. THREE.ByteType = 1010;
  153. THREE.ShortType = 1011;
  154. THREE.UnsignedShortType = 1012;
  155. THREE.IntType = 1013;
  156. THREE.UnsignedIntType = 1014;
  157. THREE.FloatType = 1015;
  158. THREE.HalfFloatType = 1025;
  159. // Pixel types
  160. //THREE.UnsignedByteType = 1009;
  161. THREE.UnsignedShort4444Type = 1016;
  162. THREE.UnsignedShort5551Type = 1017;
  163. THREE.UnsignedShort565Type = 1018;
  164. // Pixel formats
  165. THREE.AlphaFormat = 1019;
  166. THREE.RGBFormat = 1020;
  167. THREE.RGBAFormat = 1021;
  168. THREE.LuminanceFormat = 1022;
  169. THREE.LuminanceAlphaFormat = 1023;
  170. // THREE.RGBEFormat handled as THREE.RGBAFormat in shaders
  171. THREE.RGBEFormat = THREE.RGBAFormat; //1024;
  172. // DDS / ST3C Compressed texture formats
  173. THREE.RGB_S3TC_DXT1_Format = 2001;
  174. THREE.RGBA_S3TC_DXT1_Format = 2002;
  175. THREE.RGBA_S3TC_DXT3_Format = 2003;
  176. THREE.RGBA_S3TC_DXT5_Format = 2004;
  177. // PVRTC compressed texture formats
  178. THREE.RGB_PVRTC_4BPPV1_Format = 2100;
  179. THREE.RGB_PVRTC_2BPPV1_Format = 2101;
  180. THREE.RGBA_PVRTC_4BPPV1_Format = 2102;
  181. THREE.RGBA_PVRTC_2BPPV1_Format = 2103;
  182. // ETC compressed texture formats
  183. THREE.RGB_ETC1_Format = 2151;
  184. // Loop styles for AnimationAction
  185. THREE.LoopOnce = 2200;
  186. THREE.LoopRepeat = 2201;
  187. THREE.LoopPingPong = 2202;
  188. // Interpolation
  189. THREE.InterpolateDiscrete = 2300;
  190. THREE.InterpolateLinear = 2301;
  191. THREE.InterpolateSmooth = 2302;
  192. // Interpolant ending modes
  193. THREE.ZeroCurvatureEnding = 2400;
  194. THREE.ZeroSlopeEnding = 2401;
  195. THREE.WrapAroundEnding = 2402;
  196. // Triangle Draw modes
  197. THREE.TrianglesDrawMode = 0;
  198. THREE.TriangleStripDrawMode = 1;
  199. THREE.TriangleFanDrawMode = 2;
  200. // File:src/math/Color.js
  201. /**
  202. * @author mrdoob / http://mrdoob.com/
  203. */
  204. THREE.Color = function ( color ) {
  205. if ( arguments.length === 3 ) {
  206. return this.fromArray( arguments );
  207. }
  208. return this.set( color );
  209. };
  210. THREE.Color.prototype = {
  211. constructor: THREE.Color,
  212. r: 1, g: 1, b: 1,
  213. set: function ( value ) {
  214. if ( value instanceof THREE.Color ) {
  215. this.copy( value );
  216. } else if ( typeof value === 'number' ) {
  217. this.setHex( value );
  218. } else if ( typeof value === 'string' ) {
  219. this.setStyle( value );
  220. }
  221. return this;
  222. },
  223. setScalar: function ( scalar ) {
  224. this.r = scalar;
  225. this.g = scalar;
  226. this.b = scalar;
  227. },
  228. setHex: function ( hex ) {
  229. hex = Math.floor( hex );
  230. this.r = ( hex >> 16 & 255 ) / 255;
  231. this.g = ( hex >> 8 & 255 ) / 255;
  232. this.b = ( hex & 255 ) / 255;
  233. return this;
  234. },
  235. setRGB: function ( r, g, b ) {
  236. this.r = r;
  237. this.g = g;
  238. this.b = b;
  239. return this;
  240. },
  241. setHSL: function () {
  242. function hue2rgb( p, q, t ) {
  243. if ( t < 0 ) t += 1;
  244. if ( t > 1 ) t -= 1;
  245. if ( t < 1 / 6 ) return p + ( q - p ) * 6 * t;
  246. if ( t < 1 / 2 ) return q;
  247. if ( t < 2 / 3 ) return p + ( q - p ) * 6 * ( 2 / 3 - t );
  248. return p;
  249. }
  250. return function ( h, s, l ) {
  251. // h,s,l ranges are in 0.0 - 1.0
  252. h = THREE.Math.euclideanModulo( h, 1 );
  253. s = THREE.Math.clamp( s, 0, 1 );
  254. l = THREE.Math.clamp( l, 0, 1 );
  255. if ( s === 0 ) {
  256. this.r = this.g = this.b = l;
  257. } else {
  258. var p = l <= 0.5 ? l * ( 1 + s ) : l + s - ( l * s );
  259. var q = ( 2 * l ) - p;
  260. this.r = hue2rgb( q, p, h + 1 / 3 );
  261. this.g = hue2rgb( q, p, h );
  262. this.b = hue2rgb( q, p, h - 1 / 3 );
  263. }
  264. return this;
  265. };
  266. }(),
  267. setStyle: function ( style ) {
  268. function handleAlpha( string ) {
  269. if ( string === undefined ) return;
  270. if ( parseFloat( string ) < 1 ) {
  271. console.warn( 'THREE.Color: Alpha component of ' + style + ' will be ignored.' );
  272. }
  273. }
  274. var m;
  275. if ( m = /^((?:rgb|hsl)a?)\(\s*([^\)]*)\)/.exec( style ) ) {
  276. // rgb / hsl
  277. var color;
  278. var name = m[ 1 ];
  279. var components = m[ 2 ];
  280. switch ( name ) {
  281. case 'rgb':
  282. case 'rgba':
  283. if ( color = /^(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  284. // rgb(255,0,0) rgba(255,0,0,0.5)
  285. this.r = Math.min( 255, parseInt( color[ 1 ], 10 ) ) / 255;
  286. this.g = Math.min( 255, parseInt( color[ 2 ], 10 ) ) / 255;
  287. this.b = Math.min( 255, parseInt( color[ 3 ], 10 ) ) / 255;
  288. handleAlpha( color[ 5 ] );
  289. return this;
  290. }
  291. if ( color = /^(\d+)\%\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  292. // rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
  293. this.r = Math.min( 100, parseInt( color[ 1 ], 10 ) ) / 100;
  294. this.g = Math.min( 100, parseInt( color[ 2 ], 10 ) ) / 100;
  295. this.b = Math.min( 100, parseInt( color[ 3 ], 10 ) ) / 100;
  296. handleAlpha( color[ 5 ] );
  297. return this;
  298. }
  299. break;
  300. case 'hsl':
  301. case 'hsla':
  302. if ( color = /^([0-9]*\.?[0-9]+)\s*,\s*(\d+)\%\s*,\s*(\d+)\%\s*(,\s*([0-9]*\.?[0-9]+)\s*)?$/.exec( components ) ) {
  303. // hsl(120,50%,50%) hsla(120,50%,50%,0.5)
  304. var h = parseFloat( color[ 1 ] ) / 360;
  305. var s = parseInt( color[ 2 ], 10 ) / 100;
  306. var l = parseInt( color[ 3 ], 10 ) / 100;
  307. handleAlpha( color[ 5 ] );
  308. return this.setHSL( h, s, l );
  309. }
  310. break;
  311. }
  312. } else if ( m = /^\#([A-Fa-f0-9]+)$/.exec( style ) ) {
  313. // hex color
  314. var hex = m[ 1 ];
  315. var size = hex.length;
  316. if ( size === 3 ) {
  317. // #ff0
  318. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 0 ), 16 ) / 255;
  319. this.g = parseInt( hex.charAt( 1 ) + hex.charAt( 1 ), 16 ) / 255;
  320. this.b = parseInt( hex.charAt( 2 ) + hex.charAt( 2 ), 16 ) / 255;
  321. return this;
  322. } else if ( size === 6 ) {
  323. // #ff0000
  324. this.r = parseInt( hex.charAt( 0 ) + hex.charAt( 1 ), 16 ) / 255;
  325. this.g = parseInt( hex.charAt( 2 ) + hex.charAt( 3 ), 16 ) / 255;
  326. this.b = parseInt( hex.charAt( 4 ) + hex.charAt( 5 ), 16 ) / 255;
  327. return this;
  328. }
  329. }
  330. if ( style && style.length > 0 ) {
  331. // color keywords
  332. var hex = THREE.ColorKeywords[ style ];
  333. if ( hex !== undefined ) {
  334. // red
  335. this.setHex( hex );
  336. } else {
  337. // unknown color
  338. console.warn( 'THREE.Color: Unknown color ' + style );
  339. }
  340. }
  341. return this;
  342. },
  343. clone: function () {
  344. return new this.constructor( this.r, this.g, this.b );
  345. },
  346. copy: function ( color ) {
  347. this.r = color.r;
  348. this.g = color.g;
  349. this.b = color.b;
  350. return this;
  351. },
  352. copyGammaToLinear: function ( color, gammaFactor ) {
  353. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  354. this.r = Math.pow( color.r, gammaFactor );
  355. this.g = Math.pow( color.g, gammaFactor );
  356. this.b = Math.pow( color.b, gammaFactor );
  357. return this;
  358. },
  359. copyLinearToGamma: function ( color, gammaFactor ) {
  360. if ( gammaFactor === undefined ) gammaFactor = 2.0;
  361. var safeInverse = ( gammaFactor > 0 ) ? ( 1.0 / gammaFactor ) : 1.0;
  362. this.r = Math.pow( color.r, safeInverse );
  363. this.g = Math.pow( color.g, safeInverse );
  364. this.b = Math.pow( color.b, safeInverse );
  365. return this;
  366. },
  367. convertGammaToLinear: function () {
  368. var r = this.r, g = this.g, b = this.b;
  369. this.r = r * r;
  370. this.g = g * g;
  371. this.b = b * b;
  372. return this;
  373. },
  374. convertLinearToGamma: function () {
  375. this.r = Math.sqrt( this.r );
  376. this.g = Math.sqrt( this.g );
  377. this.b = Math.sqrt( this.b );
  378. return this;
  379. },
  380. getHex: function () {
  381. return ( this.r * 255 ) << 16 ^ ( this.g * 255 ) << 8 ^ ( this.b * 255 ) << 0;
  382. },
  383. getHexString: function () {
  384. return ( '000000' + this.getHex().toString( 16 ) ).slice( - 6 );
  385. },
  386. getHSL: function ( optionalTarget ) {
  387. // h,s,l ranges are in 0.0 - 1.0
  388. var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
  389. var r = this.r, g = this.g, b = this.b;
  390. var max = Math.max( r, g, b );
  391. var min = Math.min( r, g, b );
  392. var hue, saturation;
  393. var lightness = ( min + max ) / 2.0;
  394. if ( min === max ) {
  395. hue = 0;
  396. saturation = 0;
  397. } else {
  398. var delta = max - min;
  399. saturation = lightness <= 0.5 ? delta / ( max + min ) : delta / ( 2 - max - min );
  400. switch ( max ) {
  401. case r: hue = ( g - b ) / delta + ( g < b ? 6 : 0 ); break;
  402. case g: hue = ( b - r ) / delta + 2; break;
  403. case b: hue = ( r - g ) / delta + 4; break;
  404. }
  405. hue /= 6;
  406. }
  407. hsl.h = hue;
  408. hsl.s = saturation;
  409. hsl.l = lightness;
  410. return hsl;
  411. },
  412. getStyle: function () {
  413. return 'rgb(' + ( ( this.r * 255 ) | 0 ) + ',' + ( ( this.g * 255 ) | 0 ) + ',' + ( ( this.b * 255 ) | 0 ) + ')';
  414. },
  415. offsetHSL: function ( h, s, l ) {
  416. var hsl = this.getHSL();
  417. hsl.h += h; hsl.s += s; hsl.l += l;
  418. this.setHSL( hsl.h, hsl.s, hsl.l );
  419. return this;
  420. },
  421. add: function ( color ) {
  422. this.r += color.r;
  423. this.g += color.g;
  424. this.b += color.b;
  425. return this;
  426. },
  427. addColors: function ( color1, color2 ) {
  428. this.r = color1.r + color2.r;
  429. this.g = color1.g + color2.g;
  430. this.b = color1.b + color2.b;
  431. return this;
  432. },
  433. addScalar: function ( s ) {
  434. this.r += s;
  435. this.g += s;
  436. this.b += s;
  437. return this;
  438. },
  439. multiply: function ( color ) {
  440. this.r *= color.r;
  441. this.g *= color.g;
  442. this.b *= color.b;
  443. return this;
  444. },
  445. multiplyScalar: function ( s ) {
  446. this.r *= s;
  447. this.g *= s;
  448. this.b *= s;
  449. return this;
  450. },
  451. lerp: function ( color, alpha ) {
  452. this.r += ( color.r - this.r ) * alpha;
  453. this.g += ( color.g - this.g ) * alpha;
  454. this.b += ( color.b - this.b ) * alpha;
  455. return this;
  456. },
  457. equals: function ( c ) {
  458. return ( c.r === this.r ) && ( c.g === this.g ) && ( c.b === this.b );
  459. },
  460. fromArray: function ( array, offset ) {
  461. if ( offset === undefined ) offset = 0;
  462. this.r = array[ offset ];
  463. this.g = array[ offset + 1 ];
  464. this.b = array[ offset + 2 ];
  465. return this;
  466. },
  467. toArray: function ( array, offset ) {
  468. if ( array === undefined ) array = [];
  469. if ( offset === undefined ) offset = 0;
  470. array[ offset ] = this.r;
  471. array[ offset + 1 ] = this.g;
  472. array[ offset + 2 ] = this.b;
  473. return array;
  474. }
  475. };
  476. THREE.ColorKeywords = { 'aliceblue': 0xF0F8FF, 'antiquewhite': 0xFAEBD7, 'aqua': 0x00FFFF, 'aquamarine': 0x7FFFD4, 'azure': 0xF0FFFF,
  477. 'beige': 0xF5F5DC, 'bisque': 0xFFE4C4, 'black': 0x000000, 'blanchedalmond': 0xFFEBCD, 'blue': 0x0000FF, 'blueviolet': 0x8A2BE2,
  478. 'brown': 0xA52A2A, 'burlywood': 0xDEB887, 'cadetblue': 0x5F9EA0, 'chartreuse': 0x7FFF00, 'chocolate': 0xD2691E, 'coral': 0xFF7F50,
  479. 'cornflowerblue': 0x6495ED, 'cornsilk': 0xFFF8DC, 'crimson': 0xDC143C, 'cyan': 0x00FFFF, 'darkblue': 0x00008B, 'darkcyan': 0x008B8B,
  480. 'darkgoldenrod': 0xB8860B, 'darkgray': 0xA9A9A9, 'darkgreen': 0x006400, 'darkgrey': 0xA9A9A9, 'darkkhaki': 0xBDB76B, 'darkmagenta': 0x8B008B,
  481. 'darkolivegreen': 0x556B2F, 'darkorange': 0xFF8C00, 'darkorchid': 0x9932CC, 'darkred': 0x8B0000, 'darksalmon': 0xE9967A, 'darkseagreen': 0x8FBC8F,
  482. 'darkslateblue': 0x483D8B, 'darkslategray': 0x2F4F4F, 'darkslategrey': 0x2F4F4F, 'darkturquoise': 0x00CED1, 'darkviolet': 0x9400D3,
  483. 'deeppink': 0xFF1493, 'deepskyblue': 0x00BFFF, 'dimgray': 0x696969, 'dimgrey': 0x696969, 'dodgerblue': 0x1E90FF, 'firebrick': 0xB22222,
  484. 'floralwhite': 0xFFFAF0, 'forestgreen': 0x228B22, 'fuchsia': 0xFF00FF, 'gainsboro': 0xDCDCDC, 'ghostwhite': 0xF8F8FF, 'gold': 0xFFD700,
  485. 'goldenrod': 0xDAA520, 'gray': 0x808080, 'green': 0x008000, 'greenyellow': 0xADFF2F, 'grey': 0x808080, 'honeydew': 0xF0FFF0, 'hotpink': 0xFF69B4,
  486. 'indianred': 0xCD5C5C, 'indigo': 0x4B0082, 'ivory': 0xFFFFF0, 'khaki': 0xF0E68C, 'lavender': 0xE6E6FA, 'lavenderblush': 0xFFF0F5, 'lawngreen': 0x7CFC00,
  487. 'lemonchiffon': 0xFFFACD, 'lightblue': 0xADD8E6, 'lightcoral': 0xF08080, 'lightcyan': 0xE0FFFF, 'lightgoldenrodyellow': 0xFAFAD2, 'lightgray': 0xD3D3D3,
  488. 'lightgreen': 0x90EE90, 'lightgrey': 0xD3D3D3, 'lightpink': 0xFFB6C1, 'lightsalmon': 0xFFA07A, 'lightseagreen': 0x20B2AA, 'lightskyblue': 0x87CEFA,
  489. 'lightslategray': 0x778899, 'lightslategrey': 0x778899, 'lightsteelblue': 0xB0C4DE, 'lightyellow': 0xFFFFE0, 'lime': 0x00FF00, 'limegreen': 0x32CD32,
  490. 'linen': 0xFAF0E6, 'magenta': 0xFF00FF, 'maroon': 0x800000, 'mediumaquamarine': 0x66CDAA, 'mediumblue': 0x0000CD, 'mediumorchid': 0xBA55D3,
  491. 'mediumpurple': 0x9370DB, 'mediumseagreen': 0x3CB371, 'mediumslateblue': 0x7B68EE, 'mediumspringgreen': 0x00FA9A, 'mediumturquoise': 0x48D1CC,
  492. 'mediumvioletred': 0xC71585, 'midnightblue': 0x191970, 'mintcream': 0xF5FFFA, 'mistyrose': 0xFFE4E1, 'moccasin': 0xFFE4B5, 'navajowhite': 0xFFDEAD,
  493. 'navy': 0x000080, 'oldlace': 0xFDF5E6, 'olive': 0x808000, 'olivedrab': 0x6B8E23, 'orange': 0xFFA500, 'orangered': 0xFF4500, 'orchid': 0xDA70D6,
  494. 'palegoldenrod': 0xEEE8AA, 'palegreen': 0x98FB98, 'paleturquoise': 0xAFEEEE, 'palevioletred': 0xDB7093, 'papayawhip': 0xFFEFD5, 'peachpuff': 0xFFDAB9,
  495. 'peru': 0xCD853F, 'pink': 0xFFC0CB, 'plum': 0xDDA0DD, 'powderblue': 0xB0E0E6, 'purple': 0x800080, 'red': 0xFF0000, 'rosybrown': 0xBC8F8F,
  496. 'royalblue': 0x4169E1, 'saddlebrown': 0x8B4513, 'salmon': 0xFA8072, 'sandybrown': 0xF4A460, 'seagreen': 0x2E8B57, 'seashell': 0xFFF5EE,
  497. 'sienna': 0xA0522D, 'silver': 0xC0C0C0, 'skyblue': 0x87CEEB, 'slateblue': 0x6A5ACD, 'slategray': 0x708090, 'slategrey': 0x708090, 'snow': 0xFFFAFA,
  498. 'springgreen': 0x00FF7F, 'steelblue': 0x4682B4, 'tan': 0xD2B48C, 'teal': 0x008080, 'thistle': 0xD8BFD8, 'tomato': 0xFF6347, 'turquoise': 0x40E0D0,
  499. 'violet': 0xEE82EE, 'wheat': 0xF5DEB3, 'white': 0xFFFFFF, 'whitesmoke': 0xF5F5F5, 'yellow': 0xFFFF00, 'yellowgreen': 0x9ACD32 };
  500. // File:src/math/Quaternion.js
  501. /**
  502. * @author mikael emtinger / http://gomo.se/
  503. * @author alteredq / http://alteredqualia.com/
  504. * @author WestLangley / http://github.com/WestLangley
  505. * @author bhouston / http://clara.io
  506. */
  507. THREE.Quaternion = function ( x, y, z, w ) {
  508. this._x = x || 0;
  509. this._y = y || 0;
  510. this._z = z || 0;
  511. this._w = ( w !== undefined ) ? w : 1;
  512. };
  513. THREE.Quaternion.prototype = {
  514. constructor: THREE.Quaternion,
  515. get x () {
  516. return this._x;
  517. },
  518. set x ( value ) {
  519. this._x = value;
  520. this.onChangeCallback();
  521. },
  522. get y () {
  523. return this._y;
  524. },
  525. set y ( value ) {
  526. this._y = value;
  527. this.onChangeCallback();
  528. },
  529. get z () {
  530. return this._z;
  531. },
  532. set z ( value ) {
  533. this._z = value;
  534. this.onChangeCallback();
  535. },
  536. get w () {
  537. return this._w;
  538. },
  539. set w ( value ) {
  540. this._w = value;
  541. this.onChangeCallback();
  542. },
  543. set: function ( x, y, z, w ) {
  544. this._x = x;
  545. this._y = y;
  546. this._z = z;
  547. this._w = w;
  548. this.onChangeCallback();
  549. return this;
  550. },
  551. clone: function () {
  552. return new this.constructor( this._x, this._y, this._z, this._w );
  553. },
  554. copy: function ( quaternion ) {
  555. this._x = quaternion.x;
  556. this._y = quaternion.y;
  557. this._z = quaternion.z;
  558. this._w = quaternion.w;
  559. this.onChangeCallback();
  560. return this;
  561. },
  562. setFromEuler: function ( euler, update ) {
  563. if ( euler instanceof THREE.Euler === false ) {
  564. throw new Error( 'THREE.Quaternion: .setFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  565. }
  566. // http://www.mathworks.com/matlabcentral/fileexchange/
  567. // 20696-function-to-convert-between-dcm-euler-angles-quaternions-and-euler-vectors/
  568. // content/SpinCalc.m
  569. var c1 = Math.cos( euler._x / 2 );
  570. var c2 = Math.cos( euler._y / 2 );
  571. var c3 = Math.cos( euler._z / 2 );
  572. var s1 = Math.sin( euler._x / 2 );
  573. var s2 = Math.sin( euler._y / 2 );
  574. var s3 = Math.sin( euler._z / 2 );
  575. var order = euler.order;
  576. if ( order === 'XYZ' ) {
  577. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  578. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  579. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  580. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  581. } else if ( order === 'YXZ' ) {
  582. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  583. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  584. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  585. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  586. } else if ( order === 'ZXY' ) {
  587. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  588. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  589. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  590. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  591. } else if ( order === 'ZYX' ) {
  592. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  593. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  594. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  595. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  596. } else if ( order === 'YZX' ) {
  597. this._x = s1 * c2 * c3 + c1 * s2 * s3;
  598. this._y = c1 * s2 * c3 + s1 * c2 * s3;
  599. this._z = c1 * c2 * s3 - s1 * s2 * c3;
  600. this._w = c1 * c2 * c3 - s1 * s2 * s3;
  601. } else if ( order === 'XZY' ) {
  602. this._x = s1 * c2 * c3 - c1 * s2 * s3;
  603. this._y = c1 * s2 * c3 - s1 * c2 * s3;
  604. this._z = c1 * c2 * s3 + s1 * s2 * c3;
  605. this._w = c1 * c2 * c3 + s1 * s2 * s3;
  606. }
  607. if ( update !== false ) this.onChangeCallback();
  608. return this;
  609. },
  610. setFromAxisAngle: function ( axis, angle ) {
  611. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
  612. // assumes axis is normalized
  613. var halfAngle = angle / 2, s = Math.sin( halfAngle );
  614. this._x = axis.x * s;
  615. this._y = axis.y * s;
  616. this._z = axis.z * s;
  617. this._w = Math.cos( halfAngle );
  618. this.onChangeCallback();
  619. return this;
  620. },
  621. setFromRotationMatrix: function ( m ) {
  622. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion/index.htm
  623. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  624. var te = m.elements,
  625. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  626. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  627. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ],
  628. trace = m11 + m22 + m33,
  629. s;
  630. if ( trace > 0 ) {
  631. s = 0.5 / Math.sqrt( trace + 1.0 );
  632. this._w = 0.25 / s;
  633. this._x = ( m32 - m23 ) * s;
  634. this._y = ( m13 - m31 ) * s;
  635. this._z = ( m21 - m12 ) * s;
  636. } else if ( m11 > m22 && m11 > m33 ) {
  637. s = 2.0 * Math.sqrt( 1.0 + m11 - m22 - m33 );
  638. this._w = ( m32 - m23 ) / s;
  639. this._x = 0.25 * s;
  640. this._y = ( m12 + m21 ) / s;
  641. this._z = ( m13 + m31 ) / s;
  642. } else if ( m22 > m33 ) {
  643. s = 2.0 * Math.sqrt( 1.0 + m22 - m11 - m33 );
  644. this._w = ( m13 - m31 ) / s;
  645. this._x = ( m12 + m21 ) / s;
  646. this._y = 0.25 * s;
  647. this._z = ( m23 + m32 ) / s;
  648. } else {
  649. s = 2.0 * Math.sqrt( 1.0 + m33 - m11 - m22 );
  650. this._w = ( m21 - m12 ) / s;
  651. this._x = ( m13 + m31 ) / s;
  652. this._y = ( m23 + m32 ) / s;
  653. this._z = 0.25 * s;
  654. }
  655. this.onChangeCallback();
  656. return this;
  657. },
  658. setFromUnitVectors: function () {
  659. // http://lolengine.net/blog/2014/02/24/quaternion-from-two-vectors-final
  660. // assumes direction vectors vFrom and vTo are normalized
  661. var v1, r;
  662. var EPS = 0.000001;
  663. return function ( vFrom, vTo ) {
  664. if ( v1 === undefined ) v1 = new THREE.Vector3();
  665. r = vFrom.dot( vTo ) + 1;
  666. if ( r < EPS ) {
  667. r = 0;
  668. if ( Math.abs( vFrom.x ) > Math.abs( vFrom.z ) ) {
  669. v1.set( - vFrom.y, vFrom.x, 0 );
  670. } else {
  671. v1.set( 0, - vFrom.z, vFrom.y );
  672. }
  673. } else {
  674. v1.crossVectors( vFrom, vTo );
  675. }
  676. this._x = v1.x;
  677. this._y = v1.y;
  678. this._z = v1.z;
  679. this._w = r;
  680. this.normalize();
  681. return this;
  682. };
  683. }(),
  684. inverse: function () {
  685. this.conjugate().normalize();
  686. return this;
  687. },
  688. conjugate: function () {
  689. this._x *= - 1;
  690. this._y *= - 1;
  691. this._z *= - 1;
  692. this.onChangeCallback();
  693. return this;
  694. },
  695. dot: function ( v ) {
  696. return this._x * v._x + this._y * v._y + this._z * v._z + this._w * v._w;
  697. },
  698. lengthSq: function () {
  699. return this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w;
  700. },
  701. length: function () {
  702. return Math.sqrt( this._x * this._x + this._y * this._y + this._z * this._z + this._w * this._w );
  703. },
  704. normalize: function () {
  705. var l = this.length();
  706. if ( l === 0 ) {
  707. this._x = 0;
  708. this._y = 0;
  709. this._z = 0;
  710. this._w = 1;
  711. } else {
  712. l = 1 / l;
  713. this._x = this._x * l;
  714. this._y = this._y * l;
  715. this._z = this._z * l;
  716. this._w = this._w * l;
  717. }
  718. this.onChangeCallback();
  719. return this;
  720. },
  721. multiply: function ( q, p ) {
  722. if ( p !== undefined ) {
  723. console.warn( 'THREE.Quaternion: .multiply() now only accepts one argument. Use .multiplyQuaternions( a, b ) instead.' );
  724. return this.multiplyQuaternions( q, p );
  725. }
  726. return this.multiplyQuaternions( this, q );
  727. },
  728. multiplyQuaternions: function ( a, b ) {
  729. // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
  730. var qax = a._x, qay = a._y, qaz = a._z, qaw = a._w;
  731. var qbx = b._x, qby = b._y, qbz = b._z, qbw = b._w;
  732. this._x = qax * qbw + qaw * qbx + qay * qbz - qaz * qby;
  733. this._y = qay * qbw + qaw * qby + qaz * qbx - qax * qbz;
  734. this._z = qaz * qbw + qaw * qbz + qax * qby - qay * qbx;
  735. this._w = qaw * qbw - qax * qbx - qay * qby - qaz * qbz;
  736. this.onChangeCallback();
  737. return this;
  738. },
  739. slerp: function ( qb, t ) {
  740. if ( t === 0 ) return this;
  741. if ( t === 1 ) return this.copy( qb );
  742. var x = this._x, y = this._y, z = this._z, w = this._w;
  743. // http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/slerp/
  744. var cosHalfTheta = w * qb._w + x * qb._x + y * qb._y + z * qb._z;
  745. if ( cosHalfTheta < 0 ) {
  746. this._w = - qb._w;
  747. this._x = - qb._x;
  748. this._y = - qb._y;
  749. this._z = - qb._z;
  750. cosHalfTheta = - cosHalfTheta;
  751. } else {
  752. this.copy( qb );
  753. }
  754. if ( cosHalfTheta >= 1.0 ) {
  755. this._w = w;
  756. this._x = x;
  757. this._y = y;
  758. this._z = z;
  759. return this;
  760. }
  761. var sinHalfTheta = Math.sqrt( 1.0 - cosHalfTheta * cosHalfTheta );
  762. if ( Math.abs( sinHalfTheta ) < 0.001 ) {
  763. this._w = 0.5 * ( w + this._w );
  764. this._x = 0.5 * ( x + this._x );
  765. this._y = 0.5 * ( y + this._y );
  766. this._z = 0.5 * ( z + this._z );
  767. return this;
  768. }
  769. var halfTheta = Math.atan2( sinHalfTheta, cosHalfTheta );
  770. var ratioA = Math.sin( ( 1 - t ) * halfTheta ) / sinHalfTheta,
  771. ratioB = Math.sin( t * halfTheta ) / sinHalfTheta;
  772. this._w = ( w * ratioA + this._w * ratioB );
  773. this._x = ( x * ratioA + this._x * ratioB );
  774. this._y = ( y * ratioA + this._y * ratioB );
  775. this._z = ( z * ratioA + this._z * ratioB );
  776. this.onChangeCallback();
  777. return this;
  778. },
  779. equals: function ( quaternion ) {
  780. return ( quaternion._x === this._x ) && ( quaternion._y === this._y ) && ( quaternion._z === this._z ) && ( quaternion._w === this._w );
  781. },
  782. fromArray: function ( array, offset ) {
  783. if ( offset === undefined ) offset = 0;
  784. this._x = array[ offset ];
  785. this._y = array[ offset + 1 ];
  786. this._z = array[ offset + 2 ];
  787. this._w = array[ offset + 3 ];
  788. this.onChangeCallback();
  789. return this;
  790. },
  791. toArray: function ( array, offset ) {
  792. if ( array === undefined ) array = [];
  793. if ( offset === undefined ) offset = 0;
  794. array[ offset ] = this._x;
  795. array[ offset + 1 ] = this._y;
  796. array[ offset + 2 ] = this._z;
  797. array[ offset + 3 ] = this._w;
  798. return array;
  799. },
  800. onChange: function ( callback ) {
  801. this.onChangeCallback = callback;
  802. return this;
  803. },
  804. onChangeCallback: function () {}
  805. };
  806. Object.assign( THREE.Quaternion, {
  807. slerp: function( qa, qb, qm, t ) {
  808. return qm.copy( qa ).slerp( qb, t );
  809. },
  810. slerpFlat: function(
  811. dst, dstOffset, src0, srcOffset0, src1, srcOffset1, t ) {
  812. // fuzz-free, array-based Quaternion SLERP operation
  813. var x0 = src0[ srcOffset0 + 0 ],
  814. y0 = src0[ srcOffset0 + 1 ],
  815. z0 = src0[ srcOffset0 + 2 ],
  816. w0 = src0[ srcOffset0 + 3 ],
  817. x1 = src1[ srcOffset1 + 0 ],
  818. y1 = src1[ srcOffset1 + 1 ],
  819. z1 = src1[ srcOffset1 + 2 ],
  820. w1 = src1[ srcOffset1 + 3 ];
  821. if ( w0 !== w1 || x0 !== x1 || y0 !== y1 || z0 !== z1 ) {
  822. var s = 1 - t,
  823. cos = x0 * x1 + y0 * y1 + z0 * z1 + w0 * w1,
  824. dir = ( cos >= 0 ? 1 : - 1 ),
  825. sqrSin = 1 - cos * cos;
  826. // Skip the Slerp for tiny steps to avoid numeric problems:
  827. if ( sqrSin > Number.EPSILON ) {
  828. var sin = Math.sqrt( sqrSin ),
  829. len = Math.atan2( sin, cos * dir );
  830. s = Math.sin( s * len ) / sin;
  831. t = Math.sin( t * len ) / sin;
  832. }
  833. var tDir = t * dir;
  834. x0 = x0 * s + x1 * tDir;
  835. y0 = y0 * s + y1 * tDir;
  836. z0 = z0 * s + z1 * tDir;
  837. w0 = w0 * s + w1 * tDir;
  838. // Normalize in case we just did a lerp:
  839. if ( s === 1 - t ) {
  840. var f = 1 / Math.sqrt( x0 * x0 + y0 * y0 + z0 * z0 + w0 * w0 );
  841. x0 *= f;
  842. y0 *= f;
  843. z0 *= f;
  844. w0 *= f;
  845. }
  846. }
  847. dst[ dstOffset ] = x0;
  848. dst[ dstOffset + 1 ] = y0;
  849. dst[ dstOffset + 2 ] = z0;
  850. dst[ dstOffset + 3 ] = w0;
  851. }
  852. } );
  853. // File:src/math/Vector2.js
  854. /**
  855. * @author mrdoob / http://mrdoob.com/
  856. * @author philogb / http://blog.thejit.org/
  857. * @author egraether / http://egraether.com/
  858. * @author zz85 / http://www.lab4games.net/zz85/blog
  859. */
  860. THREE.Vector2 = function ( x, y ) {
  861. this.x = x || 0;
  862. this.y = y || 0;
  863. };
  864. THREE.Vector2.prototype = {
  865. constructor: THREE.Vector2,
  866. get width() {
  867. return this.x;
  868. },
  869. set width( value ) {
  870. this.x = value;
  871. },
  872. get height() {
  873. return this.y;
  874. },
  875. set height( value ) {
  876. this.y = value;
  877. },
  878. //
  879. set: function ( x, y ) {
  880. this.x = x;
  881. this.y = y;
  882. return this;
  883. },
  884. setScalar: function ( scalar ) {
  885. this.x = scalar;
  886. this.y = scalar;
  887. return this;
  888. },
  889. setX: function ( x ) {
  890. this.x = x;
  891. return this;
  892. },
  893. setY: function ( y ) {
  894. this.y = y;
  895. return this;
  896. },
  897. setComponent: function ( index, value ) {
  898. switch ( index ) {
  899. case 0: this.x = value; break;
  900. case 1: this.y = value; break;
  901. default: throw new Error( 'index is out of range: ' + index );
  902. }
  903. },
  904. getComponent: function ( index ) {
  905. switch ( index ) {
  906. case 0: return this.x;
  907. case 1: return this.y;
  908. default: throw new Error( 'index is out of range: ' + index );
  909. }
  910. },
  911. clone: function () {
  912. return new this.constructor( this.x, this.y );
  913. },
  914. copy: function ( v ) {
  915. this.x = v.x;
  916. this.y = v.y;
  917. return this;
  918. },
  919. add: function ( v, w ) {
  920. if ( w !== undefined ) {
  921. console.warn( 'THREE.Vector2: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  922. return this.addVectors( v, w );
  923. }
  924. this.x += v.x;
  925. this.y += v.y;
  926. return this;
  927. },
  928. addScalar: function ( s ) {
  929. this.x += s;
  930. this.y += s;
  931. return this;
  932. },
  933. addVectors: function ( a, b ) {
  934. this.x = a.x + b.x;
  935. this.y = a.y + b.y;
  936. return this;
  937. },
  938. addScaledVector: function ( v, s ) {
  939. this.x += v.x * s;
  940. this.y += v.y * s;
  941. return this;
  942. },
  943. sub: function ( v, w ) {
  944. if ( w !== undefined ) {
  945. console.warn( 'THREE.Vector2: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  946. return this.subVectors( v, w );
  947. }
  948. this.x -= v.x;
  949. this.y -= v.y;
  950. return this;
  951. },
  952. subScalar: function ( s ) {
  953. this.x -= s;
  954. this.y -= s;
  955. return this;
  956. },
  957. subVectors: function ( a, b ) {
  958. this.x = a.x - b.x;
  959. this.y = a.y - b.y;
  960. return this;
  961. },
  962. multiply: function ( v ) {
  963. this.x *= v.x;
  964. this.y *= v.y;
  965. return this;
  966. },
  967. multiplyScalar: function ( scalar ) {
  968. if ( isFinite( scalar ) ) {
  969. this.x *= scalar;
  970. this.y *= scalar;
  971. } else {
  972. this.x = 0;
  973. this.y = 0;
  974. }
  975. return this;
  976. },
  977. divide: function ( v ) {
  978. this.x /= v.x;
  979. this.y /= v.y;
  980. return this;
  981. },
  982. divideScalar: function ( scalar ) {
  983. return this.multiplyScalar( 1 / scalar );
  984. },
  985. min: function ( v ) {
  986. this.x = Math.min( this.x, v.x );
  987. this.y = Math.min( this.y, v.y );
  988. return this;
  989. },
  990. max: function ( v ) {
  991. this.x = Math.max( this.x, v.x );
  992. this.y = Math.max( this.y, v.y );
  993. return this;
  994. },
  995. clamp: function ( min, max ) {
  996. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  997. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  998. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  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. clampLength: function ( min, max ) {
  1014. var length = this.length();
  1015. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1016. return this;
  1017. },
  1018. floor: function () {
  1019. this.x = Math.floor( this.x );
  1020. this.y = Math.floor( this.y );
  1021. return this;
  1022. },
  1023. ceil: function () {
  1024. this.x = Math.ceil( this.x );
  1025. this.y = Math.ceil( this.y );
  1026. return this;
  1027. },
  1028. round: function () {
  1029. this.x = Math.round( this.x );
  1030. this.y = Math.round( this.y );
  1031. return this;
  1032. },
  1033. roundToZero: function () {
  1034. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1035. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1036. return this;
  1037. },
  1038. negate: function () {
  1039. this.x = - this.x;
  1040. this.y = - this.y;
  1041. return this;
  1042. },
  1043. dot: function ( v ) {
  1044. return this.x * v.x + this.y * v.y;
  1045. },
  1046. lengthSq: function () {
  1047. return this.x * this.x + this.y * this.y;
  1048. },
  1049. length: function () {
  1050. return Math.sqrt( this.x * this.x + this.y * this.y );
  1051. },
  1052. lengthManhattan: function() {
  1053. return Math.abs( this.x ) + Math.abs( this.y );
  1054. },
  1055. normalize: function () {
  1056. return this.divideScalar( this.length() );
  1057. },
  1058. angle: function () {
  1059. // computes the angle in radians with respect to the positive x-axis
  1060. var angle = Math.atan2( this.y, this.x );
  1061. if ( angle < 0 ) angle += 2 * Math.PI;
  1062. return angle;
  1063. },
  1064. distanceTo: function ( v ) {
  1065. return Math.sqrt( this.distanceToSquared( v ) );
  1066. },
  1067. distanceToSquared: function ( v ) {
  1068. var dx = this.x - v.x, dy = this.y - v.y;
  1069. return dx * dx + dy * dy;
  1070. },
  1071. setLength: function ( length ) {
  1072. return this.multiplyScalar( length / this.length() );
  1073. },
  1074. lerp: function ( v, alpha ) {
  1075. this.x += ( v.x - this.x ) * alpha;
  1076. this.y += ( v.y - this.y ) * alpha;
  1077. return this;
  1078. },
  1079. lerpVectors: function ( v1, v2, alpha ) {
  1080. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1081. return this;
  1082. },
  1083. equals: function ( v ) {
  1084. return ( ( v.x === this.x ) && ( v.y === this.y ) );
  1085. },
  1086. fromArray: function ( array, offset ) {
  1087. if ( offset === undefined ) offset = 0;
  1088. this.x = array[ offset ];
  1089. this.y = array[ offset + 1 ];
  1090. return this;
  1091. },
  1092. toArray: function ( array, offset ) {
  1093. if ( array === undefined ) array = [];
  1094. if ( offset === undefined ) offset = 0;
  1095. array[ offset ] = this.x;
  1096. array[ offset + 1 ] = this.y;
  1097. return array;
  1098. },
  1099. fromAttribute: function ( attribute, index, offset ) {
  1100. if ( offset === undefined ) offset = 0;
  1101. index = index * attribute.itemSize + offset;
  1102. this.x = attribute.array[ index ];
  1103. this.y = attribute.array[ index + 1 ];
  1104. return this;
  1105. },
  1106. rotateAround: function ( center, angle ) {
  1107. var c = Math.cos( angle ), s = Math.sin( angle );
  1108. var x = this.x - center.x;
  1109. var y = this.y - center.y;
  1110. this.x = x * c - y * s + center.x;
  1111. this.y = x * s + y * c + center.y;
  1112. return this;
  1113. }
  1114. };
  1115. // File:src/math/Vector3.js
  1116. /**
  1117. * @author mrdoob / http://mrdoob.com/
  1118. * @author *kile / http://kile.stravaganza.org/
  1119. * @author philogb / http://blog.thejit.org/
  1120. * @author mikael emtinger / http://gomo.se/
  1121. * @author egraether / http://egraether.com/
  1122. * @author WestLangley / http://github.com/WestLangley
  1123. */
  1124. THREE.Vector3 = function ( x, y, z ) {
  1125. this.x = x || 0;
  1126. this.y = y || 0;
  1127. this.z = z || 0;
  1128. };
  1129. THREE.Vector3.prototype = {
  1130. constructor: THREE.Vector3,
  1131. set: function ( x, y, z ) {
  1132. this.x = x;
  1133. this.y = y;
  1134. this.z = z;
  1135. return this;
  1136. },
  1137. setScalar: function ( scalar ) {
  1138. this.x = scalar;
  1139. this.y = scalar;
  1140. this.z = scalar;
  1141. return this;
  1142. },
  1143. setX: function ( x ) {
  1144. this.x = x;
  1145. return this;
  1146. },
  1147. setY: function ( y ) {
  1148. this.y = y;
  1149. return this;
  1150. },
  1151. setZ: function ( z ) {
  1152. this.z = z;
  1153. return this;
  1154. },
  1155. setComponent: function ( index, value ) {
  1156. switch ( index ) {
  1157. case 0: this.x = value; break;
  1158. case 1: this.y = value; break;
  1159. case 2: this.z = value; break;
  1160. default: throw new Error( 'index is out of range: ' + index );
  1161. }
  1162. },
  1163. getComponent: function ( index ) {
  1164. switch ( index ) {
  1165. case 0: return this.x;
  1166. case 1: return this.y;
  1167. case 2: return this.z;
  1168. default: throw new Error( 'index is out of range: ' + index );
  1169. }
  1170. },
  1171. clone: function () {
  1172. return new this.constructor( this.x, this.y, this.z );
  1173. },
  1174. copy: function ( v ) {
  1175. this.x = v.x;
  1176. this.y = v.y;
  1177. this.z = v.z;
  1178. return this;
  1179. },
  1180. add: function ( v, w ) {
  1181. if ( w !== undefined ) {
  1182. console.warn( 'THREE.Vector3: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1183. return this.addVectors( v, w );
  1184. }
  1185. this.x += v.x;
  1186. this.y += v.y;
  1187. this.z += v.z;
  1188. return this;
  1189. },
  1190. addScalar: function ( s ) {
  1191. this.x += s;
  1192. this.y += s;
  1193. this.z += s;
  1194. return this;
  1195. },
  1196. addVectors: function ( a, b ) {
  1197. this.x = a.x + b.x;
  1198. this.y = a.y + b.y;
  1199. this.z = a.z + b.z;
  1200. return this;
  1201. },
  1202. addScaledVector: function ( v, s ) {
  1203. this.x += v.x * s;
  1204. this.y += v.y * s;
  1205. this.z += v.z * s;
  1206. return this;
  1207. },
  1208. sub: function ( v, w ) {
  1209. if ( w !== undefined ) {
  1210. console.warn( 'THREE.Vector3: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1211. return this.subVectors( v, w );
  1212. }
  1213. this.x -= v.x;
  1214. this.y -= v.y;
  1215. this.z -= v.z;
  1216. return this;
  1217. },
  1218. subScalar: function ( s ) {
  1219. this.x -= s;
  1220. this.y -= s;
  1221. this.z -= s;
  1222. return this;
  1223. },
  1224. subVectors: function ( a, b ) {
  1225. this.x = a.x - b.x;
  1226. this.y = a.y - b.y;
  1227. this.z = a.z - b.z;
  1228. return this;
  1229. },
  1230. multiply: function ( v, w ) {
  1231. if ( w !== undefined ) {
  1232. console.warn( 'THREE.Vector3: .multiply() now only accepts one argument. Use .multiplyVectors( a, b ) instead.' );
  1233. return this.multiplyVectors( v, w );
  1234. }
  1235. this.x *= v.x;
  1236. this.y *= v.y;
  1237. this.z *= v.z;
  1238. return this;
  1239. },
  1240. multiplyScalar: function ( scalar ) {
  1241. if ( isFinite( scalar ) ) {
  1242. this.x *= scalar;
  1243. this.y *= scalar;
  1244. this.z *= scalar;
  1245. } else {
  1246. this.x = 0;
  1247. this.y = 0;
  1248. this.z = 0;
  1249. }
  1250. return this;
  1251. },
  1252. multiplyVectors: function ( a, b ) {
  1253. this.x = a.x * b.x;
  1254. this.y = a.y * b.y;
  1255. this.z = a.z * b.z;
  1256. return this;
  1257. },
  1258. applyEuler: function () {
  1259. var quaternion;
  1260. return function applyEuler( euler ) {
  1261. if ( euler instanceof THREE.Euler === false ) {
  1262. console.error( 'THREE.Vector3: .applyEuler() now expects an Euler rotation rather than a Vector3 and order.' );
  1263. }
  1264. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1265. this.applyQuaternion( quaternion.setFromEuler( euler ) );
  1266. return this;
  1267. };
  1268. }(),
  1269. applyAxisAngle: function () {
  1270. var quaternion;
  1271. return function applyAxisAngle( axis, angle ) {
  1272. if ( quaternion === undefined ) quaternion = new THREE.Quaternion();
  1273. this.applyQuaternion( quaternion.setFromAxisAngle( axis, angle ) );
  1274. return this;
  1275. };
  1276. }(),
  1277. applyMatrix3: function ( m ) {
  1278. var x = this.x;
  1279. var y = this.y;
  1280. var z = this.z;
  1281. var e = m.elements;
  1282. this.x = e[ 0 ] * x + e[ 3 ] * y + e[ 6 ] * z;
  1283. this.y = e[ 1 ] * x + e[ 4 ] * y + e[ 7 ] * z;
  1284. this.z = e[ 2 ] * x + e[ 5 ] * y + e[ 8 ] * z;
  1285. return this;
  1286. },
  1287. applyMatrix4: function ( m ) {
  1288. // input: THREE.Matrix4 affine matrix
  1289. var x = this.x, y = this.y, z = this.z;
  1290. var e = m.elements;
  1291. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ];
  1292. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ];
  1293. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ];
  1294. return this;
  1295. },
  1296. applyProjection: function ( m ) {
  1297. // input: THREE.Matrix4 projection matrix
  1298. var x = this.x, y = this.y, z = this.z;
  1299. var e = m.elements;
  1300. var d = 1 / ( e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] ); // perspective divide
  1301. this.x = ( e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] ) * d;
  1302. this.y = ( e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] ) * d;
  1303. this.z = ( e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] ) * d;
  1304. return this;
  1305. },
  1306. applyQuaternion: function ( q ) {
  1307. var x = this.x;
  1308. var y = this.y;
  1309. var z = this.z;
  1310. var qx = q.x;
  1311. var qy = q.y;
  1312. var qz = q.z;
  1313. var qw = q.w;
  1314. // calculate quat * vector
  1315. var ix = qw * x + qy * z - qz * y;
  1316. var iy = qw * y + qz * x - qx * z;
  1317. var iz = qw * z + qx * y - qy * x;
  1318. var iw = - qx * x - qy * y - qz * z;
  1319. // calculate result * inverse quat
  1320. this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
  1321. this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
  1322. this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
  1323. return this;
  1324. },
  1325. project: function () {
  1326. var matrix;
  1327. return function project( camera ) {
  1328. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1329. matrix.multiplyMatrices( camera.projectionMatrix, matrix.getInverse( camera.matrixWorld ) );
  1330. return this.applyProjection( matrix );
  1331. };
  1332. }(),
  1333. unproject: function () {
  1334. var matrix;
  1335. return function unproject( camera ) {
  1336. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  1337. matrix.multiplyMatrices( camera.matrixWorld, matrix.getInverse( camera.projectionMatrix ) );
  1338. return this.applyProjection( matrix );
  1339. };
  1340. }(),
  1341. transformDirection: function ( m ) {
  1342. // input: THREE.Matrix4 affine matrix
  1343. // vector interpreted as a direction
  1344. var x = this.x, y = this.y, z = this.z;
  1345. var e = m.elements;
  1346. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z;
  1347. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z;
  1348. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z;
  1349. this.normalize();
  1350. return this;
  1351. },
  1352. divide: function ( v ) {
  1353. this.x /= v.x;
  1354. this.y /= v.y;
  1355. this.z /= v.z;
  1356. return this;
  1357. },
  1358. divideScalar: function ( scalar ) {
  1359. return this.multiplyScalar( 1 / scalar );
  1360. },
  1361. min: function ( v ) {
  1362. this.x = Math.min( this.x, v.x );
  1363. this.y = Math.min( this.y, v.y );
  1364. this.z = Math.min( this.z, v.z );
  1365. return this;
  1366. },
  1367. max: function ( v ) {
  1368. this.x = Math.max( this.x, v.x );
  1369. this.y = Math.max( this.y, v.y );
  1370. this.z = Math.max( this.z, v.z );
  1371. return this;
  1372. },
  1373. clamp: function ( min, max ) {
  1374. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1375. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1376. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1377. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1378. return this;
  1379. },
  1380. clampScalar: function () {
  1381. var min, max;
  1382. return function clampScalar( minVal, maxVal ) {
  1383. if ( min === undefined ) {
  1384. min = new THREE.Vector3();
  1385. max = new THREE.Vector3();
  1386. }
  1387. min.set( minVal, minVal, minVal );
  1388. max.set( maxVal, maxVal, maxVal );
  1389. return this.clamp( min, max );
  1390. };
  1391. }(),
  1392. clampLength: function ( min, max ) {
  1393. var length = this.length();
  1394. this.multiplyScalar( Math.max( min, Math.min( max, length ) ) / length );
  1395. return this;
  1396. },
  1397. floor: function () {
  1398. this.x = Math.floor( this.x );
  1399. this.y = Math.floor( this.y );
  1400. this.z = Math.floor( this.z );
  1401. return this;
  1402. },
  1403. ceil: function () {
  1404. this.x = Math.ceil( this.x );
  1405. this.y = Math.ceil( this.y );
  1406. this.z = Math.ceil( this.z );
  1407. return this;
  1408. },
  1409. round: function () {
  1410. this.x = Math.round( this.x );
  1411. this.y = Math.round( this.y );
  1412. this.z = Math.round( this.z );
  1413. return this;
  1414. },
  1415. roundToZero: function () {
  1416. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1417. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1418. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1419. return this;
  1420. },
  1421. negate: function () {
  1422. this.x = - this.x;
  1423. this.y = - this.y;
  1424. this.z = - this.z;
  1425. return this;
  1426. },
  1427. dot: function ( v ) {
  1428. return this.x * v.x + this.y * v.y + this.z * v.z;
  1429. },
  1430. lengthSq: function () {
  1431. return this.x * this.x + this.y * this.y + this.z * this.z;
  1432. },
  1433. length: function () {
  1434. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z );
  1435. },
  1436. lengthManhattan: function () {
  1437. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z );
  1438. },
  1439. normalize: function () {
  1440. return this.divideScalar( this.length() );
  1441. },
  1442. setLength: function ( length ) {
  1443. return this.multiplyScalar( length / this.length() );
  1444. },
  1445. lerp: function ( v, alpha ) {
  1446. this.x += ( v.x - this.x ) * alpha;
  1447. this.y += ( v.y - this.y ) * alpha;
  1448. this.z += ( v.z - this.z ) * alpha;
  1449. return this;
  1450. },
  1451. lerpVectors: function ( v1, v2, alpha ) {
  1452. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1453. return this;
  1454. },
  1455. cross: function ( v, w ) {
  1456. if ( w !== undefined ) {
  1457. console.warn( 'THREE.Vector3: .cross() now only accepts one argument. Use .crossVectors( a, b ) instead.' );
  1458. return this.crossVectors( v, w );
  1459. }
  1460. var x = this.x, y = this.y, z = this.z;
  1461. this.x = y * v.z - z * v.y;
  1462. this.y = z * v.x - x * v.z;
  1463. this.z = x * v.y - y * v.x;
  1464. return this;
  1465. },
  1466. crossVectors: function ( a, b ) {
  1467. var ax = a.x, ay = a.y, az = a.z;
  1468. var bx = b.x, by = b.y, bz = b.z;
  1469. this.x = ay * bz - az * by;
  1470. this.y = az * bx - ax * bz;
  1471. this.z = ax * by - ay * bx;
  1472. return this;
  1473. },
  1474. projectOnVector: function () {
  1475. var v1, dot;
  1476. return function projectOnVector( vector ) {
  1477. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1478. v1.copy( vector ).normalize();
  1479. dot = this.dot( v1 );
  1480. return this.copy( v1 ).multiplyScalar( dot );
  1481. };
  1482. }(),
  1483. projectOnPlane: function () {
  1484. var v1;
  1485. return function projectOnPlane( planeNormal ) {
  1486. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1487. v1.copy( this ).projectOnVector( planeNormal );
  1488. return this.sub( v1 );
  1489. }
  1490. }(),
  1491. reflect: function () {
  1492. // reflect incident vector off plane orthogonal to normal
  1493. // normal is assumed to have unit length
  1494. var v1;
  1495. return function reflect( normal ) {
  1496. if ( v1 === undefined ) v1 = new THREE.Vector3();
  1497. return this.sub( v1.copy( normal ).multiplyScalar( 2 * this.dot( normal ) ) );
  1498. }
  1499. }(),
  1500. angleTo: function ( v ) {
  1501. var theta = this.dot( v ) / ( Math.sqrt( this.lengthSq() * v.lengthSq() ) );
  1502. // clamp, to handle numerical problems
  1503. return Math.acos( THREE.Math.clamp( theta, - 1, 1 ) );
  1504. },
  1505. distanceTo: function ( v ) {
  1506. return Math.sqrt( this.distanceToSquared( v ) );
  1507. },
  1508. distanceToSquared: function ( v ) {
  1509. var dx = this.x - v.x;
  1510. var dy = this.y - v.y;
  1511. var dz = this.z - v.z;
  1512. return dx * dx + dy * dy + dz * dz;
  1513. },
  1514. setFromMatrixPosition: function ( m ) {
  1515. this.x = m.elements[ 12 ];
  1516. this.y = m.elements[ 13 ];
  1517. this.z = m.elements[ 14 ];
  1518. return this;
  1519. },
  1520. setFromMatrixScale: function ( m ) {
  1521. var sx = this.set( m.elements[ 0 ], m.elements[ 1 ], m.elements[ 2 ] ).length();
  1522. var sy = this.set( m.elements[ 4 ], m.elements[ 5 ], m.elements[ 6 ] ).length();
  1523. var sz = this.set( m.elements[ 8 ], m.elements[ 9 ], m.elements[ 10 ] ).length();
  1524. this.x = sx;
  1525. this.y = sy;
  1526. this.z = sz;
  1527. return this;
  1528. },
  1529. setFromMatrixColumn: function ( index, matrix ) {
  1530. var offset = index * 4;
  1531. var me = matrix.elements;
  1532. this.x = me[ offset ];
  1533. this.y = me[ offset + 1 ];
  1534. this.z = me[ offset + 2 ];
  1535. return this;
  1536. },
  1537. equals: function ( v ) {
  1538. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) );
  1539. },
  1540. fromArray: function ( array, offset ) {
  1541. if ( offset === undefined ) offset = 0;
  1542. this.x = array[ offset ];
  1543. this.y = array[ offset + 1 ];
  1544. this.z = array[ offset + 2 ];
  1545. return this;
  1546. },
  1547. toArray: function ( array, offset ) {
  1548. if ( array === undefined ) array = [];
  1549. if ( offset === undefined ) offset = 0;
  1550. array[ offset ] = this.x;
  1551. array[ offset + 1 ] = this.y;
  1552. array[ offset + 2 ] = this.z;
  1553. return array;
  1554. },
  1555. fromAttribute: function ( attribute, index, offset ) {
  1556. if ( offset === undefined ) offset = 0;
  1557. index = index * attribute.itemSize + offset;
  1558. this.x = attribute.array[ index ];
  1559. this.y = attribute.array[ index + 1 ];
  1560. this.z = attribute.array[ index + 2 ];
  1561. return this;
  1562. }
  1563. };
  1564. // File:src/math/Vector4.js
  1565. /**
  1566. * @author supereggbert / http://www.paulbrunt.co.uk/
  1567. * @author philogb / http://blog.thejit.org/
  1568. * @author mikael emtinger / http://gomo.se/
  1569. * @author egraether / http://egraether.com/
  1570. * @author WestLangley / http://github.com/WestLangley
  1571. */
  1572. THREE.Vector4 = function ( x, y, z, w ) {
  1573. this.x = x || 0;
  1574. this.y = y || 0;
  1575. this.z = z || 0;
  1576. this.w = ( w !== undefined ) ? w : 1;
  1577. };
  1578. THREE.Vector4.prototype = {
  1579. constructor: THREE.Vector4,
  1580. set: function ( x, y, z, w ) {
  1581. this.x = x;
  1582. this.y = y;
  1583. this.z = z;
  1584. this.w = w;
  1585. return this;
  1586. },
  1587. setScalar: function ( scalar ) {
  1588. this.x = scalar;
  1589. this.y = scalar;
  1590. this.z = scalar;
  1591. this.w = scalar;
  1592. return this;
  1593. },
  1594. setX: function ( x ) {
  1595. this.x = x;
  1596. return this;
  1597. },
  1598. setY: function ( y ) {
  1599. this.y = y;
  1600. return this;
  1601. },
  1602. setZ: function ( z ) {
  1603. this.z = z;
  1604. return this;
  1605. },
  1606. setW: function ( w ) {
  1607. this.w = w;
  1608. return this;
  1609. },
  1610. setComponent: function ( index, value ) {
  1611. switch ( index ) {
  1612. case 0: this.x = value; break;
  1613. case 1: this.y = value; break;
  1614. case 2: this.z = value; break;
  1615. case 3: this.w = value; break;
  1616. default: throw new Error( 'index is out of range: ' + index );
  1617. }
  1618. },
  1619. getComponent: function ( index ) {
  1620. switch ( index ) {
  1621. case 0: return this.x;
  1622. case 1: return this.y;
  1623. case 2: return this.z;
  1624. case 3: return this.w;
  1625. default: throw new Error( 'index is out of range: ' + index );
  1626. }
  1627. },
  1628. clone: function () {
  1629. return new this.constructor( this.x, this.y, this.z, this.w );
  1630. },
  1631. copy: function ( v ) {
  1632. this.x = v.x;
  1633. this.y = v.y;
  1634. this.z = v.z;
  1635. this.w = ( v.w !== undefined ) ? v.w : 1;
  1636. return this;
  1637. },
  1638. add: function ( v, w ) {
  1639. if ( w !== undefined ) {
  1640. console.warn( 'THREE.Vector4: .add() now only accepts one argument. Use .addVectors( a, b ) instead.' );
  1641. return this.addVectors( v, w );
  1642. }
  1643. this.x += v.x;
  1644. this.y += v.y;
  1645. this.z += v.z;
  1646. this.w += v.w;
  1647. return this;
  1648. },
  1649. addScalar: function ( s ) {
  1650. this.x += s;
  1651. this.y += s;
  1652. this.z += s;
  1653. this.w += s;
  1654. return this;
  1655. },
  1656. addVectors: function ( a, b ) {
  1657. this.x = a.x + b.x;
  1658. this.y = a.y + b.y;
  1659. this.z = a.z + b.z;
  1660. this.w = a.w + b.w;
  1661. return this;
  1662. },
  1663. addScaledVector: function ( v, s ) {
  1664. this.x += v.x * s;
  1665. this.y += v.y * s;
  1666. this.z += v.z * s;
  1667. this.w += v.w * s;
  1668. return this;
  1669. },
  1670. sub: function ( v, w ) {
  1671. if ( w !== undefined ) {
  1672. console.warn( 'THREE.Vector4: .sub() now only accepts one argument. Use .subVectors( a, b ) instead.' );
  1673. return this.subVectors( v, w );
  1674. }
  1675. this.x -= v.x;
  1676. this.y -= v.y;
  1677. this.z -= v.z;
  1678. this.w -= v.w;
  1679. return this;
  1680. },
  1681. subScalar: function ( s ) {
  1682. this.x -= s;
  1683. this.y -= s;
  1684. this.z -= s;
  1685. this.w -= s;
  1686. return this;
  1687. },
  1688. subVectors: function ( a, b ) {
  1689. this.x = a.x - b.x;
  1690. this.y = a.y - b.y;
  1691. this.z = a.z - b.z;
  1692. this.w = a.w - b.w;
  1693. return this;
  1694. },
  1695. multiplyScalar: function ( scalar ) {
  1696. if ( isFinite( scalar ) ) {
  1697. this.x *= scalar;
  1698. this.y *= scalar;
  1699. this.z *= scalar;
  1700. this.w *= scalar;
  1701. } else {
  1702. this.x = 0;
  1703. this.y = 0;
  1704. this.z = 0;
  1705. this.w = 0;
  1706. }
  1707. return this;
  1708. },
  1709. applyMatrix4: function ( m ) {
  1710. var x = this.x;
  1711. var y = this.y;
  1712. var z = this.z;
  1713. var w = this.w;
  1714. var e = m.elements;
  1715. this.x = e[ 0 ] * x + e[ 4 ] * y + e[ 8 ] * z + e[ 12 ] * w;
  1716. this.y = e[ 1 ] * x + e[ 5 ] * y + e[ 9 ] * z + e[ 13 ] * w;
  1717. this.z = e[ 2 ] * x + e[ 6 ] * y + e[ 10 ] * z + e[ 14 ] * w;
  1718. this.w = e[ 3 ] * x + e[ 7 ] * y + e[ 11 ] * z + e[ 15 ] * w;
  1719. return this;
  1720. },
  1721. divideScalar: function ( scalar ) {
  1722. return this.multiplyScalar( 1 / scalar );
  1723. },
  1724. setAxisAngleFromQuaternion: function ( q ) {
  1725. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/quaternionToAngle/index.htm
  1726. // q is assumed to be normalized
  1727. this.w = 2 * Math.acos( q.w );
  1728. var s = Math.sqrt( 1 - q.w * q.w );
  1729. if ( s < 0.0001 ) {
  1730. this.x = 1;
  1731. this.y = 0;
  1732. this.z = 0;
  1733. } else {
  1734. this.x = q.x / s;
  1735. this.y = q.y / s;
  1736. this.z = q.z / s;
  1737. }
  1738. return this;
  1739. },
  1740. setAxisAngleFromRotationMatrix: function ( m ) {
  1741. // http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToAngle/index.htm
  1742. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  1743. var angle, x, y, z, // variables for result
  1744. epsilon = 0.01, // margin to allow for rounding errors
  1745. epsilon2 = 0.1, // margin to distinguish between 0 and 180 degrees
  1746. te = m.elements,
  1747. m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ],
  1748. m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ],
  1749. m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  1750. if ( ( Math.abs( m12 - m21 ) < epsilon )
  1751. && ( Math.abs( m13 - m31 ) < epsilon )
  1752. && ( Math.abs( m23 - m32 ) < epsilon ) ) {
  1753. // singularity found
  1754. // first check for identity matrix which must have +1 for all terms
  1755. // in leading diagonal and zero in other terms
  1756. if ( ( Math.abs( m12 + m21 ) < epsilon2 )
  1757. && ( Math.abs( m13 + m31 ) < epsilon2 )
  1758. && ( Math.abs( m23 + m32 ) < epsilon2 )
  1759. && ( Math.abs( m11 + m22 + m33 - 3 ) < epsilon2 ) ) {
  1760. // this singularity is identity matrix so angle = 0
  1761. this.set( 1, 0, 0, 0 );
  1762. return this; // zero angle, arbitrary axis
  1763. }
  1764. // otherwise this singularity is angle = 180
  1765. angle = Math.PI;
  1766. var xx = ( m11 + 1 ) / 2;
  1767. var yy = ( m22 + 1 ) / 2;
  1768. var zz = ( m33 + 1 ) / 2;
  1769. var xy = ( m12 + m21 ) / 4;
  1770. var xz = ( m13 + m31 ) / 4;
  1771. var yz = ( m23 + m32 ) / 4;
  1772. if ( ( xx > yy ) && ( xx > zz ) ) {
  1773. // m11 is the largest diagonal term
  1774. if ( xx < epsilon ) {
  1775. x = 0;
  1776. y = 0.707106781;
  1777. z = 0.707106781;
  1778. } else {
  1779. x = Math.sqrt( xx );
  1780. y = xy / x;
  1781. z = xz / x;
  1782. }
  1783. } else if ( yy > zz ) {
  1784. // m22 is the largest diagonal term
  1785. if ( yy < epsilon ) {
  1786. x = 0.707106781;
  1787. y = 0;
  1788. z = 0.707106781;
  1789. } else {
  1790. y = Math.sqrt( yy );
  1791. x = xy / y;
  1792. z = yz / y;
  1793. }
  1794. } else {
  1795. // m33 is the largest diagonal term so base result on this
  1796. if ( zz < epsilon ) {
  1797. x = 0.707106781;
  1798. y = 0.707106781;
  1799. z = 0;
  1800. } else {
  1801. z = Math.sqrt( zz );
  1802. x = xz / z;
  1803. y = yz / z;
  1804. }
  1805. }
  1806. this.set( x, y, z, angle );
  1807. return this; // return 180 deg rotation
  1808. }
  1809. // as we have reached here there are no singularities so we can handle normally
  1810. var s = Math.sqrt( ( m32 - m23 ) * ( m32 - m23 )
  1811. + ( m13 - m31 ) * ( m13 - m31 )
  1812. + ( m21 - m12 ) * ( m21 - m12 ) ); // used to normalize
  1813. if ( Math.abs( s ) < 0.001 ) s = 1;
  1814. // prevent divide by zero, should not happen if matrix is orthogonal and should be
  1815. // caught by singularity test above, but I've left it in just in case
  1816. this.x = ( m32 - m23 ) / s;
  1817. this.y = ( m13 - m31 ) / s;
  1818. this.z = ( m21 - m12 ) / s;
  1819. this.w = Math.acos( ( m11 + m22 + m33 - 1 ) / 2 );
  1820. return this;
  1821. },
  1822. min: function ( v ) {
  1823. this.x = Math.min( this.x, v.x );
  1824. this.y = Math.min( this.y, v.y );
  1825. this.z = Math.min( this.z, v.z );
  1826. this.w = Math.min( this.w, v.w );
  1827. return this;
  1828. },
  1829. max: function ( v ) {
  1830. this.x = Math.max( this.x, v.x );
  1831. this.y = Math.max( this.y, v.y );
  1832. this.z = Math.max( this.z, v.z );
  1833. this.w = Math.max( this.w, v.w );
  1834. return this;
  1835. },
  1836. clamp: function ( min, max ) {
  1837. // This function assumes min < max, if this assumption isn't true it will not operate correctly
  1838. this.x = Math.max( min.x, Math.min( max.x, this.x ) );
  1839. this.y = Math.max( min.y, Math.min( max.y, this.y ) );
  1840. this.z = Math.max( min.z, Math.min( max.z, this.z ) );
  1841. this.w = Math.max( min.w, Math.min( max.w, this.w ) );
  1842. return this;
  1843. },
  1844. clampScalar: function () {
  1845. var min, max;
  1846. return function clampScalar( minVal, maxVal ) {
  1847. if ( min === undefined ) {
  1848. min = new THREE.Vector4();
  1849. max = new THREE.Vector4();
  1850. }
  1851. min.set( minVal, minVal, minVal, minVal );
  1852. max.set( maxVal, maxVal, maxVal, maxVal );
  1853. return this.clamp( min, max );
  1854. };
  1855. }(),
  1856. floor: function () {
  1857. this.x = Math.floor( this.x );
  1858. this.y = Math.floor( this.y );
  1859. this.z = Math.floor( this.z );
  1860. this.w = Math.floor( this.w );
  1861. return this;
  1862. },
  1863. ceil: function () {
  1864. this.x = Math.ceil( this.x );
  1865. this.y = Math.ceil( this.y );
  1866. this.z = Math.ceil( this.z );
  1867. this.w = Math.ceil( this.w );
  1868. return this;
  1869. },
  1870. round: function () {
  1871. this.x = Math.round( this.x );
  1872. this.y = Math.round( this.y );
  1873. this.z = Math.round( this.z );
  1874. this.w = Math.round( this.w );
  1875. return this;
  1876. },
  1877. roundToZero: function () {
  1878. this.x = ( this.x < 0 ) ? Math.ceil( this.x ) : Math.floor( this.x );
  1879. this.y = ( this.y < 0 ) ? Math.ceil( this.y ) : Math.floor( this.y );
  1880. this.z = ( this.z < 0 ) ? Math.ceil( this.z ) : Math.floor( this.z );
  1881. this.w = ( this.w < 0 ) ? Math.ceil( this.w ) : Math.floor( this.w );
  1882. return this;
  1883. },
  1884. negate: function () {
  1885. this.x = - this.x;
  1886. this.y = - this.y;
  1887. this.z = - this.z;
  1888. this.w = - this.w;
  1889. return this;
  1890. },
  1891. dot: function ( v ) {
  1892. return this.x * v.x + this.y * v.y + this.z * v.z + this.w * v.w;
  1893. },
  1894. lengthSq: function () {
  1895. return this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w;
  1896. },
  1897. length: function () {
  1898. return Math.sqrt( this.x * this.x + this.y * this.y + this.z * this.z + this.w * this.w );
  1899. },
  1900. lengthManhattan: function () {
  1901. return Math.abs( this.x ) + Math.abs( this.y ) + Math.abs( this.z ) + Math.abs( this.w );
  1902. },
  1903. normalize: function () {
  1904. return this.divideScalar( this.length() );
  1905. },
  1906. setLength: function ( length ) {
  1907. return this.multiplyScalar( length / this.length() );
  1908. },
  1909. lerp: function ( v, alpha ) {
  1910. this.x += ( v.x - this.x ) * alpha;
  1911. this.y += ( v.y - this.y ) * alpha;
  1912. this.z += ( v.z - this.z ) * alpha;
  1913. this.w += ( v.w - this.w ) * alpha;
  1914. return this;
  1915. },
  1916. lerpVectors: function ( v1, v2, alpha ) {
  1917. this.subVectors( v2, v1 ).multiplyScalar( alpha ).add( v1 );
  1918. return this;
  1919. },
  1920. equals: function ( v ) {
  1921. return ( ( v.x === this.x ) && ( v.y === this.y ) && ( v.z === this.z ) && ( v.w === this.w ) );
  1922. },
  1923. fromArray: function ( array, offset ) {
  1924. if ( offset === undefined ) offset = 0;
  1925. this.x = array[ offset ];
  1926. this.y = array[ offset + 1 ];
  1927. this.z = array[ offset + 2 ];
  1928. this.w = array[ offset + 3 ];
  1929. return this;
  1930. },
  1931. toArray: function ( array, offset ) {
  1932. if ( array === undefined ) array = [];
  1933. if ( offset === undefined ) offset = 0;
  1934. array[ offset ] = this.x;
  1935. array[ offset + 1 ] = this.y;
  1936. array[ offset + 2 ] = this.z;
  1937. array[ offset + 3 ] = this.w;
  1938. return array;
  1939. },
  1940. fromAttribute: function ( attribute, index, offset ) {
  1941. if ( offset === undefined ) offset = 0;
  1942. index = index * attribute.itemSize + offset;
  1943. this.x = attribute.array[ index ];
  1944. this.y = attribute.array[ index + 1 ];
  1945. this.z = attribute.array[ index + 2 ];
  1946. this.w = attribute.array[ index + 3 ];
  1947. return this;
  1948. }
  1949. };
  1950. // File:src/math/Euler.js
  1951. /**
  1952. * @author mrdoob / http://mrdoob.com/
  1953. * @author WestLangley / http://github.com/WestLangley
  1954. * @author bhouston / http://clara.io
  1955. */
  1956. THREE.Euler = function ( x, y, z, order ) {
  1957. this._x = x || 0;
  1958. this._y = y || 0;
  1959. this._z = z || 0;
  1960. this._order = order || THREE.Euler.DefaultOrder;
  1961. };
  1962. THREE.Euler.RotationOrders = [ 'XYZ', 'YZX', 'ZXY', 'XZY', 'YXZ', 'ZYX' ];
  1963. THREE.Euler.DefaultOrder = 'XYZ';
  1964. THREE.Euler.prototype = {
  1965. constructor: THREE.Euler,
  1966. get x () {
  1967. return this._x;
  1968. },
  1969. set x ( value ) {
  1970. this._x = value;
  1971. this.onChangeCallback();
  1972. },
  1973. get y () {
  1974. return this._y;
  1975. },
  1976. set y ( value ) {
  1977. this._y = value;
  1978. this.onChangeCallback();
  1979. },
  1980. get z () {
  1981. return this._z;
  1982. },
  1983. set z ( value ) {
  1984. this._z = value;
  1985. this.onChangeCallback();
  1986. },
  1987. get order () {
  1988. return this._order;
  1989. },
  1990. set order ( value ) {
  1991. this._order = value;
  1992. this.onChangeCallback();
  1993. },
  1994. set: function ( x, y, z, order ) {
  1995. this._x = x;
  1996. this._y = y;
  1997. this._z = z;
  1998. this._order = order || this._order;
  1999. this.onChangeCallback();
  2000. return this;
  2001. },
  2002. clone: function () {
  2003. return new this.constructor( this._x, this._y, this._z, this._order );
  2004. },
  2005. copy: function ( euler ) {
  2006. this._x = euler._x;
  2007. this._y = euler._y;
  2008. this._z = euler._z;
  2009. this._order = euler._order;
  2010. this.onChangeCallback();
  2011. return this;
  2012. },
  2013. setFromRotationMatrix: function ( m, order, update ) {
  2014. var clamp = THREE.Math.clamp;
  2015. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  2016. var te = m.elements;
  2017. var m11 = te[ 0 ], m12 = te[ 4 ], m13 = te[ 8 ];
  2018. var m21 = te[ 1 ], m22 = te[ 5 ], m23 = te[ 9 ];
  2019. var m31 = te[ 2 ], m32 = te[ 6 ], m33 = te[ 10 ];
  2020. order = order || this._order;
  2021. if ( order === 'XYZ' ) {
  2022. this._y = Math.asin( clamp( m13, - 1, 1 ) );
  2023. if ( Math.abs( m13 ) < 0.99999 ) {
  2024. this._x = Math.atan2( - m23, m33 );
  2025. this._z = Math.atan2( - m12, m11 );
  2026. } else {
  2027. this._x = Math.atan2( m32, m22 );
  2028. this._z = 0;
  2029. }
  2030. } else if ( order === 'YXZ' ) {
  2031. this._x = Math.asin( - clamp( m23, - 1, 1 ) );
  2032. if ( Math.abs( m23 ) < 0.99999 ) {
  2033. this._y = Math.atan2( m13, m33 );
  2034. this._z = Math.atan2( m21, m22 );
  2035. } else {
  2036. this._y = Math.atan2( - m31, m11 );
  2037. this._z = 0;
  2038. }
  2039. } else if ( order === 'ZXY' ) {
  2040. this._x = Math.asin( clamp( m32, - 1, 1 ) );
  2041. if ( Math.abs( m32 ) < 0.99999 ) {
  2042. this._y = Math.atan2( - m31, m33 );
  2043. this._z = Math.atan2( - m12, m22 );
  2044. } else {
  2045. this._y = 0;
  2046. this._z = Math.atan2( m21, m11 );
  2047. }
  2048. } else if ( order === 'ZYX' ) {
  2049. this._y = Math.asin( - clamp( m31, - 1, 1 ) );
  2050. if ( Math.abs( m31 ) < 0.99999 ) {
  2051. this._x = Math.atan2( m32, m33 );
  2052. this._z = Math.atan2( m21, m11 );
  2053. } else {
  2054. this._x = 0;
  2055. this._z = Math.atan2( - m12, m22 );
  2056. }
  2057. } else if ( order === 'YZX' ) {
  2058. this._z = Math.asin( clamp( m21, - 1, 1 ) );
  2059. if ( Math.abs( m21 ) < 0.99999 ) {
  2060. this._x = Math.atan2( - m23, m22 );
  2061. this._y = Math.atan2( - m31, m11 );
  2062. } else {
  2063. this._x = 0;
  2064. this._y = Math.atan2( m13, m33 );
  2065. }
  2066. } else if ( order === 'XZY' ) {
  2067. this._z = Math.asin( - clamp( m12, - 1, 1 ) );
  2068. if ( Math.abs( m12 ) < 0.99999 ) {
  2069. this._x = Math.atan2( m32, m22 );
  2070. this._y = Math.atan2( m13, m11 );
  2071. } else {
  2072. this._x = Math.atan2( - m23, m33 );
  2073. this._y = 0;
  2074. }
  2075. } else {
  2076. console.warn( 'THREE.Euler: .setFromRotationMatrix() given unsupported order: ' + order )
  2077. }
  2078. this._order = order;
  2079. if ( update !== false ) this.onChangeCallback();
  2080. return this;
  2081. },
  2082. setFromQuaternion: function () {
  2083. var matrix;
  2084. return function ( q, order, update ) {
  2085. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  2086. matrix.makeRotationFromQuaternion( q );
  2087. this.setFromRotationMatrix( matrix, order, update );
  2088. return this;
  2089. };
  2090. }(),
  2091. setFromVector3: function ( v, order ) {
  2092. return this.set( v.x, v.y, v.z, order || this._order );
  2093. },
  2094. reorder: function () {
  2095. // WARNING: this discards revolution information -bhouston
  2096. var q = new THREE.Quaternion();
  2097. return function ( newOrder ) {
  2098. q.setFromEuler( this );
  2099. this.setFromQuaternion( q, newOrder );
  2100. };
  2101. }(),
  2102. equals: function ( euler ) {
  2103. return ( euler._x === this._x ) && ( euler._y === this._y ) && ( euler._z === this._z ) && ( euler._order === this._order );
  2104. },
  2105. fromArray: function ( array ) {
  2106. this._x = array[ 0 ];
  2107. this._y = array[ 1 ];
  2108. this._z = array[ 2 ];
  2109. if ( array[ 3 ] !== undefined ) this._order = array[ 3 ];
  2110. this.onChangeCallback();
  2111. return this;
  2112. },
  2113. toArray: function ( array, offset ) {
  2114. if ( array === undefined ) array = [];
  2115. if ( offset === undefined ) offset = 0;
  2116. array[ offset ] = this._x;
  2117. array[ offset + 1 ] = this._y;
  2118. array[ offset + 2 ] = this._z;
  2119. array[ offset + 3 ] = this._order;
  2120. return array;
  2121. },
  2122. toVector3: function ( optionalResult ) {
  2123. if ( optionalResult ) {
  2124. return optionalResult.set( this._x, this._y, this._z );
  2125. } else {
  2126. return new THREE.Vector3( this._x, this._y, this._z );
  2127. }
  2128. },
  2129. onChange: function ( callback ) {
  2130. this.onChangeCallback = callback;
  2131. return this;
  2132. },
  2133. onChangeCallback: function () {}
  2134. };
  2135. // File:src/math/Line3.js
  2136. /**
  2137. * @author bhouston / http://clara.io
  2138. */
  2139. THREE.Line3 = function ( start, end ) {
  2140. this.start = ( start !== undefined ) ? start : new THREE.Vector3();
  2141. this.end = ( end !== undefined ) ? end : new THREE.Vector3();
  2142. };
  2143. THREE.Line3.prototype = {
  2144. constructor: THREE.Line3,
  2145. set: function ( start, end ) {
  2146. this.start.copy( start );
  2147. this.end.copy( end );
  2148. return this;
  2149. },
  2150. clone: function () {
  2151. return new this.constructor().copy( this );
  2152. },
  2153. copy: function ( line ) {
  2154. this.start.copy( line.start );
  2155. this.end.copy( line.end );
  2156. return this;
  2157. },
  2158. center: function ( optionalTarget ) {
  2159. var result = optionalTarget || new THREE.Vector3();
  2160. return result.addVectors( this.start, this.end ).multiplyScalar( 0.5 );
  2161. },
  2162. delta: function ( optionalTarget ) {
  2163. var result = optionalTarget || new THREE.Vector3();
  2164. return result.subVectors( this.end, this.start );
  2165. },
  2166. distanceSq: function () {
  2167. return this.start.distanceToSquared( this.end );
  2168. },
  2169. distance: function () {
  2170. return this.start.distanceTo( this.end );
  2171. },
  2172. at: function ( t, optionalTarget ) {
  2173. var result = optionalTarget || new THREE.Vector3();
  2174. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2175. },
  2176. closestPointToPointParameter: function () {
  2177. var startP = new THREE.Vector3();
  2178. var startEnd = new THREE.Vector3();
  2179. return function ( point, clampToLine ) {
  2180. startP.subVectors( point, this.start );
  2181. startEnd.subVectors( this.end, this.start );
  2182. var startEnd2 = startEnd.dot( startEnd );
  2183. var startEnd_startP = startEnd.dot( startP );
  2184. var t = startEnd_startP / startEnd2;
  2185. if ( clampToLine ) {
  2186. t = THREE.Math.clamp( t, 0, 1 );
  2187. }
  2188. return t;
  2189. };
  2190. }(),
  2191. closestPointToPoint: function ( point, clampToLine, optionalTarget ) {
  2192. var t = this.closestPointToPointParameter( point, clampToLine );
  2193. var result = optionalTarget || new THREE.Vector3();
  2194. return this.delta( result ).multiplyScalar( t ).add( this.start );
  2195. },
  2196. applyMatrix4: function ( matrix ) {
  2197. this.start.applyMatrix4( matrix );
  2198. this.end.applyMatrix4( matrix );
  2199. return this;
  2200. },
  2201. equals: function ( line ) {
  2202. return line.start.equals( this.start ) && line.end.equals( this.end );
  2203. }
  2204. };
  2205. // File:src/math/Box2.js
  2206. /**
  2207. * @author bhouston / http://clara.io
  2208. */
  2209. THREE.Box2 = function ( min, max ) {
  2210. this.min = ( min !== undefined ) ? min : new THREE.Vector2( + Infinity, + Infinity );
  2211. this.max = ( max !== undefined ) ? max : new THREE.Vector2( - Infinity, - Infinity );
  2212. };
  2213. THREE.Box2.prototype = {
  2214. constructor: THREE.Box2,
  2215. set: function ( min, max ) {
  2216. this.min.copy( min );
  2217. this.max.copy( max );
  2218. return this;
  2219. },
  2220. setFromPoints: function ( points ) {
  2221. this.makeEmpty();
  2222. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2223. this.expandByPoint( points[ i ] );
  2224. }
  2225. return this;
  2226. },
  2227. setFromCenterAndSize: function () {
  2228. var v1 = new THREE.Vector2();
  2229. return function ( center, size ) {
  2230. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2231. this.min.copy( center ).sub( halfSize );
  2232. this.max.copy( center ).add( halfSize );
  2233. return this;
  2234. };
  2235. }(),
  2236. clone: function () {
  2237. return new this.constructor().copy( this );
  2238. },
  2239. copy: function ( box ) {
  2240. this.min.copy( box.min );
  2241. this.max.copy( box.max );
  2242. return this;
  2243. },
  2244. makeEmpty: function () {
  2245. this.min.x = this.min.y = + Infinity;
  2246. this.max.x = this.max.y = - Infinity;
  2247. return this;
  2248. },
  2249. isEmpty: function () {
  2250. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2251. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y );
  2252. },
  2253. center: function ( optionalTarget ) {
  2254. var result = optionalTarget || new THREE.Vector2();
  2255. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2256. },
  2257. size: function ( optionalTarget ) {
  2258. var result = optionalTarget || new THREE.Vector2();
  2259. return result.subVectors( this.max, this.min );
  2260. },
  2261. expandByPoint: function ( point ) {
  2262. this.min.min( point );
  2263. this.max.max( point );
  2264. return this;
  2265. },
  2266. expandByVector: function ( vector ) {
  2267. this.min.sub( vector );
  2268. this.max.add( vector );
  2269. return this;
  2270. },
  2271. expandByScalar: function ( scalar ) {
  2272. this.min.addScalar( - scalar );
  2273. this.max.addScalar( scalar );
  2274. return this;
  2275. },
  2276. containsPoint: function ( point ) {
  2277. if ( point.x < this.min.x || point.x > this.max.x ||
  2278. point.y < this.min.y || point.y > this.max.y ) {
  2279. return false;
  2280. }
  2281. return true;
  2282. },
  2283. containsBox: function ( box ) {
  2284. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2285. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) ) {
  2286. return true;
  2287. }
  2288. return false;
  2289. },
  2290. getParameter: function ( point, optionalTarget ) {
  2291. // This can potentially have a divide by zero if the box
  2292. // has a size dimension of 0.
  2293. var result = optionalTarget || new THREE.Vector2();
  2294. return result.set(
  2295. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2296. ( point.y - this.min.y ) / ( this.max.y - this.min.y )
  2297. );
  2298. },
  2299. intersectsBox: function ( box ) {
  2300. // using 6 splitting planes to rule out intersections.
  2301. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2302. box.max.y < this.min.y || box.min.y > this.max.y ) {
  2303. return false;
  2304. }
  2305. return true;
  2306. },
  2307. clampPoint: function ( point, optionalTarget ) {
  2308. var result = optionalTarget || new THREE.Vector2();
  2309. return result.copy( point ).clamp( this.min, this.max );
  2310. },
  2311. distanceToPoint: function () {
  2312. var v1 = new THREE.Vector2();
  2313. return function ( point ) {
  2314. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2315. return clampedPoint.sub( point ).length();
  2316. };
  2317. }(),
  2318. intersect: function ( box ) {
  2319. this.min.max( box.min );
  2320. this.max.min( box.max );
  2321. return this;
  2322. },
  2323. union: function ( box ) {
  2324. this.min.min( box.min );
  2325. this.max.max( box.max );
  2326. return this;
  2327. },
  2328. translate: function ( offset ) {
  2329. this.min.add( offset );
  2330. this.max.add( offset );
  2331. return this;
  2332. },
  2333. equals: function ( box ) {
  2334. return box.min.equals( this.min ) && box.max.equals( this.max );
  2335. }
  2336. };
  2337. // File:src/math/Box3.js
  2338. /**
  2339. * @author bhouston / http://clara.io
  2340. * @author WestLangley / http://github.com/WestLangley
  2341. */
  2342. THREE.Box3 = function ( min, max ) {
  2343. this.min = ( min !== undefined ) ? min : new THREE.Vector3( + Infinity, + Infinity, + Infinity );
  2344. this.max = ( max !== undefined ) ? max : new THREE.Vector3( - Infinity, - Infinity, - Infinity );
  2345. };
  2346. THREE.Box3.prototype = {
  2347. constructor: THREE.Box3,
  2348. set: function ( min, max ) {
  2349. this.min.copy( min );
  2350. this.max.copy( max );
  2351. return this;
  2352. },
  2353. setFromArray: function ( array ) {
  2354. this.makeEmpty();
  2355. var minX = + Infinity;
  2356. var minY = + Infinity;
  2357. var minZ = + Infinity;
  2358. var maxX = - Infinity;
  2359. var maxY = - Infinity;
  2360. var maxZ = - Infinity;
  2361. for ( var i = 0, il = array.length; i < il; i += 3 ) {
  2362. var x = array[ i ];
  2363. var y = array[ i + 1 ];
  2364. var z = array[ i + 2 ];
  2365. if ( x < minX ) minX = x;
  2366. if ( y < minY ) minY = y;
  2367. if ( z < minZ ) minZ = z;
  2368. if ( x > maxX ) maxX = x;
  2369. if ( y > maxY ) maxY = y;
  2370. if ( z > maxZ ) maxZ = z;
  2371. }
  2372. this.min.set( minX, minY, minZ );
  2373. this.max.set( maxX, maxY, maxZ );
  2374. },
  2375. setFromPoints: function ( points ) {
  2376. this.makeEmpty();
  2377. for ( var i = 0, il = points.length; i < il; i ++ ) {
  2378. this.expandByPoint( points[ i ] );
  2379. }
  2380. return this;
  2381. },
  2382. setFromCenterAndSize: function () {
  2383. var v1 = new THREE.Vector3();
  2384. return function ( center, size ) {
  2385. var halfSize = v1.copy( size ).multiplyScalar( 0.5 );
  2386. this.min.copy( center ).sub( halfSize );
  2387. this.max.copy( center ).add( halfSize );
  2388. return this;
  2389. };
  2390. }(),
  2391. setFromObject: function () {
  2392. // Computes the world-axis-aligned bounding box of an object (including its children),
  2393. // accounting for both the object's, and children's, world transforms
  2394. var box;
  2395. return function ( object ) {
  2396. if ( box === undefined ) box = new THREE.Box3();
  2397. var scope = this;
  2398. this.makeEmpty();
  2399. object.updateMatrixWorld( true );
  2400. object.traverse( function ( node ) {
  2401. var geometry = node.geometry;
  2402. if ( geometry !== undefined ) {
  2403. if ( geometry.boundingBox === null ) {
  2404. geometry.computeBoundingBox();
  2405. }
  2406. box.copy( geometry.boundingBox );
  2407. box.applyMatrix4( node.matrixWorld );
  2408. scope.union( box );
  2409. }
  2410. } );
  2411. return this;
  2412. };
  2413. }(),
  2414. clone: function () {
  2415. return new this.constructor().copy( this );
  2416. },
  2417. copy: function ( box ) {
  2418. this.min.copy( box.min );
  2419. this.max.copy( box.max );
  2420. return this;
  2421. },
  2422. makeEmpty: function () {
  2423. this.min.x = this.min.y = this.min.z = + Infinity;
  2424. this.max.x = this.max.y = this.max.z = - Infinity;
  2425. return this;
  2426. },
  2427. isEmpty: function () {
  2428. // this is a more robust check for empty than ( volume <= 0 ) because volume can get positive with two negative axes
  2429. return ( this.max.x < this.min.x ) || ( this.max.y < this.min.y ) || ( this.max.z < this.min.z );
  2430. },
  2431. center: function ( optionalTarget ) {
  2432. var result = optionalTarget || new THREE.Vector3();
  2433. return result.addVectors( this.min, this.max ).multiplyScalar( 0.5 );
  2434. },
  2435. size: function ( optionalTarget ) {
  2436. var result = optionalTarget || new THREE.Vector3();
  2437. return result.subVectors( this.max, this.min );
  2438. },
  2439. expandByPoint: function ( point ) {
  2440. this.min.min( point );
  2441. this.max.max( point );
  2442. return this;
  2443. },
  2444. expandByVector: function ( vector ) {
  2445. this.min.sub( vector );
  2446. this.max.add( vector );
  2447. return this;
  2448. },
  2449. expandByScalar: function ( scalar ) {
  2450. this.min.addScalar( - scalar );
  2451. this.max.addScalar( scalar );
  2452. return this;
  2453. },
  2454. containsPoint: function ( point ) {
  2455. if ( point.x < this.min.x || point.x > this.max.x ||
  2456. point.y < this.min.y || point.y > this.max.y ||
  2457. point.z < this.min.z || point.z > this.max.z ) {
  2458. return false;
  2459. }
  2460. return true;
  2461. },
  2462. containsBox: function ( box ) {
  2463. if ( ( this.min.x <= box.min.x ) && ( box.max.x <= this.max.x ) &&
  2464. ( this.min.y <= box.min.y ) && ( box.max.y <= this.max.y ) &&
  2465. ( this.min.z <= box.min.z ) && ( box.max.z <= this.max.z ) ) {
  2466. return true;
  2467. }
  2468. return false;
  2469. },
  2470. getParameter: function ( point, optionalTarget ) {
  2471. // This can potentially have a divide by zero if the box
  2472. // has a size dimension of 0.
  2473. var result = optionalTarget || new THREE.Vector3();
  2474. return result.set(
  2475. ( point.x - this.min.x ) / ( this.max.x - this.min.x ),
  2476. ( point.y - this.min.y ) / ( this.max.y - this.min.y ),
  2477. ( point.z - this.min.z ) / ( this.max.z - this.min.z )
  2478. );
  2479. },
  2480. intersectsBox: function ( box ) {
  2481. // using 6 splitting planes to rule out intersections.
  2482. if ( box.max.x < this.min.x || box.min.x > this.max.x ||
  2483. box.max.y < this.min.y || box.min.y > this.max.y ||
  2484. box.max.z < this.min.z || box.min.z > this.max.z ) {
  2485. return false;
  2486. }
  2487. return true;
  2488. },
  2489. intersectsSphere: ( function () {
  2490. var closestPoint;
  2491. return function intersectsSphere( sphere ) {
  2492. if ( closestPoint === undefined ) closestPoint = new THREE.Vector3();
  2493. // Find the point on the AABB closest to the sphere center.
  2494. this.clampPoint( sphere.center, closestPoint );
  2495. // If that point is inside the sphere, the AABB and sphere intersect.
  2496. return closestPoint.distanceToSquared( sphere.center ) <= ( sphere.radius * sphere.radius );
  2497. };
  2498. } )(),
  2499. intersectsPlane: function ( plane ) {
  2500. // We compute the minimum and maximum dot product values. If those values
  2501. // are on the same side (back or front) of the plane, then there is no intersection.
  2502. var min, max;
  2503. if ( plane.normal.x > 0 ) {
  2504. min = plane.normal.x * this.min.x;
  2505. max = plane.normal.x * this.max.x;
  2506. } else {
  2507. min = plane.normal.x * this.max.x;
  2508. max = plane.normal.x * this.min.x;
  2509. }
  2510. if ( plane.normal.y > 0 ) {
  2511. min += plane.normal.y * this.min.y;
  2512. max += plane.normal.y * this.max.y;
  2513. } else {
  2514. min += plane.normal.y * this.max.y;
  2515. max += plane.normal.y * this.min.y;
  2516. }
  2517. if ( plane.normal.z > 0 ) {
  2518. min += plane.normal.z * this.min.z;
  2519. max += plane.normal.z * this.max.z;
  2520. } else {
  2521. min += plane.normal.z * this.max.z;
  2522. max += plane.normal.z * this.min.z;
  2523. }
  2524. return ( min <= plane.constant && max >= plane.constant );
  2525. },
  2526. clampPoint: function ( point, optionalTarget ) {
  2527. var result = optionalTarget || new THREE.Vector3();
  2528. return result.copy( point ).clamp( this.min, this.max );
  2529. },
  2530. distanceToPoint: function () {
  2531. var v1 = new THREE.Vector3();
  2532. return function ( point ) {
  2533. var clampedPoint = v1.copy( point ).clamp( this.min, this.max );
  2534. return clampedPoint.sub( point ).length();
  2535. };
  2536. }(),
  2537. getBoundingSphere: function () {
  2538. var v1 = new THREE.Vector3();
  2539. return function ( optionalTarget ) {
  2540. var result = optionalTarget || new THREE.Sphere();
  2541. result.center = this.center();
  2542. result.radius = this.size( v1 ).length() * 0.5;
  2543. return result;
  2544. };
  2545. }(),
  2546. intersect: function ( box ) {
  2547. this.min.max( box.min );
  2548. this.max.min( box.max );
  2549. return this;
  2550. },
  2551. union: function ( box ) {
  2552. this.min.min( box.min );
  2553. this.max.max( box.max );
  2554. return this;
  2555. },
  2556. applyMatrix4: function () {
  2557. var points = [
  2558. new THREE.Vector3(),
  2559. new THREE.Vector3(),
  2560. new THREE.Vector3(),
  2561. new THREE.Vector3(),
  2562. new THREE.Vector3(),
  2563. new THREE.Vector3(),
  2564. new THREE.Vector3(),
  2565. new THREE.Vector3()
  2566. ];
  2567. return function ( matrix ) {
  2568. // NOTE: I am using a binary pattern to specify all 2^3 combinations below
  2569. points[ 0 ].set( this.min.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 000
  2570. points[ 1 ].set( this.min.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 001
  2571. points[ 2 ].set( this.min.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 010
  2572. points[ 3 ].set( this.min.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 011
  2573. points[ 4 ].set( this.max.x, this.min.y, this.min.z ).applyMatrix4( matrix ); // 100
  2574. points[ 5 ].set( this.max.x, this.min.y, this.max.z ).applyMatrix4( matrix ); // 101
  2575. points[ 6 ].set( this.max.x, this.max.y, this.min.z ).applyMatrix4( matrix ); // 110
  2576. points[ 7 ].set( this.max.x, this.max.y, this.max.z ).applyMatrix4( matrix ); // 111
  2577. this.makeEmpty();
  2578. this.setFromPoints( points );
  2579. return this;
  2580. };
  2581. }(),
  2582. translate: function ( offset ) {
  2583. this.min.add( offset );
  2584. this.max.add( offset );
  2585. return this;
  2586. },
  2587. equals: function ( box ) {
  2588. return box.min.equals( this.min ) && box.max.equals( this.max );
  2589. }
  2590. };
  2591. // File:src/math/Matrix3.js
  2592. /**
  2593. * @author alteredq / http://alteredqualia.com/
  2594. * @author WestLangley / http://github.com/WestLangley
  2595. * @author bhouston / http://clara.io
  2596. */
  2597. THREE.Matrix3 = function () {
  2598. this.elements = new Float32Array( [
  2599. 1, 0, 0,
  2600. 0, 1, 0,
  2601. 0, 0, 1
  2602. ] );
  2603. if ( arguments.length > 0 ) {
  2604. console.error( 'THREE.Matrix3: the constructor no longer reads arguments. use .set() instead.' );
  2605. }
  2606. };
  2607. THREE.Matrix3.prototype = {
  2608. constructor: THREE.Matrix3,
  2609. set: function ( n11, n12, n13, n21, n22, n23, n31, n32, n33 ) {
  2610. var te = this.elements;
  2611. te[ 0 ] = n11; te[ 3 ] = n12; te[ 6 ] = n13;
  2612. te[ 1 ] = n21; te[ 4 ] = n22; te[ 7 ] = n23;
  2613. te[ 2 ] = n31; te[ 5 ] = n32; te[ 8 ] = n33;
  2614. return this;
  2615. },
  2616. identity: function () {
  2617. this.set(
  2618. 1, 0, 0,
  2619. 0, 1, 0,
  2620. 0, 0, 1
  2621. );
  2622. return this;
  2623. },
  2624. clone: function () {
  2625. return new this.constructor().fromArray( this.elements );
  2626. },
  2627. copy: function ( m ) {
  2628. var me = m.elements;
  2629. this.set(
  2630. me[ 0 ], me[ 3 ], me[ 6 ],
  2631. me[ 1 ], me[ 4 ], me[ 7 ],
  2632. me[ 2 ], me[ 5 ], me[ 8 ]
  2633. );
  2634. return this;
  2635. },
  2636. applyToVector3Array: function () {
  2637. var v1;
  2638. return function ( array, offset, length ) {
  2639. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2640. if ( offset === undefined ) offset = 0;
  2641. if ( length === undefined ) length = array.length;
  2642. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  2643. v1.fromArray( array, j );
  2644. v1.applyMatrix3( this );
  2645. v1.toArray( array, j );
  2646. }
  2647. return array;
  2648. };
  2649. }(),
  2650. applyToBuffer: function () {
  2651. var v1;
  2652. return function applyToBuffer( buffer, offset, length ) {
  2653. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2654. if ( offset === undefined ) offset = 0;
  2655. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  2656. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  2657. v1.x = buffer.getX( j );
  2658. v1.y = buffer.getY( j );
  2659. v1.z = buffer.getZ( j );
  2660. v1.applyMatrix3( this );
  2661. buffer.setXYZ( v1.x, v1.y, v1.z );
  2662. }
  2663. return buffer;
  2664. };
  2665. }(),
  2666. multiplyScalar: function ( s ) {
  2667. var te = this.elements;
  2668. te[ 0 ] *= s; te[ 3 ] *= s; te[ 6 ] *= s;
  2669. te[ 1 ] *= s; te[ 4 ] *= s; te[ 7 ] *= s;
  2670. te[ 2 ] *= s; te[ 5 ] *= s; te[ 8 ] *= s;
  2671. return this;
  2672. },
  2673. determinant: function () {
  2674. var te = this.elements;
  2675. var a = te[ 0 ], b = te[ 1 ], c = te[ 2 ],
  2676. d = te[ 3 ], e = te[ 4 ], f = te[ 5 ],
  2677. g = te[ 6 ], h = te[ 7 ], i = te[ 8 ];
  2678. return a * e * i - a * f * h - b * d * i + b * f * g + c * d * h - c * e * g;
  2679. },
  2680. getInverse: function ( matrix, throwOnDegenerate ) {
  2681. // input: THREE.Matrix4
  2682. // ( based on http://code.google.com/p/webgl-mjs/ )
  2683. var me = matrix.elements;
  2684. var te = this.elements;
  2685. te[ 0 ] = me[ 10 ] * me[ 5 ] - me[ 6 ] * me[ 9 ];
  2686. te[ 1 ] = - me[ 10 ] * me[ 1 ] + me[ 2 ] * me[ 9 ];
  2687. te[ 2 ] = me[ 6 ] * me[ 1 ] - me[ 2 ] * me[ 5 ];
  2688. te[ 3 ] = - me[ 10 ] * me[ 4 ] + me[ 6 ] * me[ 8 ];
  2689. te[ 4 ] = me[ 10 ] * me[ 0 ] - me[ 2 ] * me[ 8 ];
  2690. te[ 5 ] = - me[ 6 ] * me[ 0 ] + me[ 2 ] * me[ 4 ];
  2691. te[ 6 ] = me[ 9 ] * me[ 4 ] - me[ 5 ] * me[ 8 ];
  2692. te[ 7 ] = - me[ 9 ] * me[ 0 ] + me[ 1 ] * me[ 8 ];
  2693. te[ 8 ] = me[ 5 ] * me[ 0 ] - me[ 1 ] * me[ 4 ];
  2694. var det = me[ 0 ] * te[ 0 ] + me[ 1 ] * te[ 3 ] + me[ 2 ] * te[ 6 ];
  2695. // no inverse
  2696. if ( det === 0 ) {
  2697. var msg = "THREE.Matrix3.getInverse(): can't invert matrix, determinant is 0";
  2698. if ( throwOnDegenerate || false ) {
  2699. throw new Error( msg );
  2700. } else {
  2701. console.warn( msg );
  2702. }
  2703. this.identity();
  2704. return this;
  2705. }
  2706. this.multiplyScalar( 1.0 / det );
  2707. return this;
  2708. },
  2709. transpose: function () {
  2710. var tmp, m = this.elements;
  2711. tmp = m[ 1 ]; m[ 1 ] = m[ 3 ]; m[ 3 ] = tmp;
  2712. tmp = m[ 2 ]; m[ 2 ] = m[ 6 ]; m[ 6 ] = tmp;
  2713. tmp = m[ 5 ]; m[ 5 ] = m[ 7 ]; m[ 7 ] = tmp;
  2714. return this;
  2715. },
  2716. flattenToArrayOffset: function ( array, offset ) {
  2717. var te = this.elements;
  2718. array[ offset ] = te[ 0 ];
  2719. array[ offset + 1 ] = te[ 1 ];
  2720. array[ offset + 2 ] = te[ 2 ];
  2721. array[ offset + 3 ] = te[ 3 ];
  2722. array[ offset + 4 ] = te[ 4 ];
  2723. array[ offset + 5 ] = te[ 5 ];
  2724. array[ offset + 6 ] = te[ 6 ];
  2725. array[ offset + 7 ] = te[ 7 ];
  2726. array[ offset + 8 ] = te[ 8 ];
  2727. return array;
  2728. },
  2729. getNormalMatrix: function ( m ) {
  2730. // input: THREE.Matrix4
  2731. this.getInverse( m ).transpose();
  2732. return this;
  2733. },
  2734. transposeIntoArray: function ( r ) {
  2735. var m = this.elements;
  2736. r[ 0 ] = m[ 0 ];
  2737. r[ 1 ] = m[ 3 ];
  2738. r[ 2 ] = m[ 6 ];
  2739. r[ 3 ] = m[ 1 ];
  2740. r[ 4 ] = m[ 4 ];
  2741. r[ 5 ] = m[ 7 ];
  2742. r[ 6 ] = m[ 2 ];
  2743. r[ 7 ] = m[ 5 ];
  2744. r[ 8 ] = m[ 8 ];
  2745. return this;
  2746. },
  2747. fromArray: function ( array ) {
  2748. this.elements.set( array );
  2749. return this;
  2750. },
  2751. toArray: function () {
  2752. var te = this.elements;
  2753. return [
  2754. te[ 0 ], te[ 1 ], te[ 2 ],
  2755. te[ 3 ], te[ 4 ], te[ 5 ],
  2756. te[ 6 ], te[ 7 ], te[ 8 ]
  2757. ];
  2758. }
  2759. };
  2760. // File:src/math/Matrix4.js
  2761. /**
  2762. * @author mrdoob / http://mrdoob.com/
  2763. * @author supereggbert / http://www.paulbrunt.co.uk/
  2764. * @author philogb / http://blog.thejit.org/
  2765. * @author jordi_ros / http://plattsoft.com
  2766. * @author D1plo1d / http://github.com/D1plo1d
  2767. * @author alteredq / http://alteredqualia.com/
  2768. * @author mikael emtinger / http://gomo.se/
  2769. * @author timknip / http://www.floorplanner.com/
  2770. * @author bhouston / http://clara.io
  2771. * @author WestLangley / http://github.com/WestLangley
  2772. */
  2773. THREE.Matrix4 = function () {
  2774. this.elements = new Float32Array( [
  2775. 1, 0, 0, 0,
  2776. 0, 1, 0, 0,
  2777. 0, 0, 1, 0,
  2778. 0, 0, 0, 1
  2779. ] );
  2780. if ( arguments.length > 0 ) {
  2781. console.error( 'THREE.Matrix4: the constructor no longer reads arguments. use .set() instead.' );
  2782. }
  2783. };
  2784. THREE.Matrix4.prototype = {
  2785. constructor: THREE.Matrix4,
  2786. set: function ( n11, n12, n13, n14, n21, n22, n23, n24, n31, n32, n33, n34, n41, n42, n43, n44 ) {
  2787. var te = this.elements;
  2788. te[ 0 ] = n11; te[ 4 ] = n12; te[ 8 ] = n13; te[ 12 ] = n14;
  2789. te[ 1 ] = n21; te[ 5 ] = n22; te[ 9 ] = n23; te[ 13 ] = n24;
  2790. te[ 2 ] = n31; te[ 6 ] = n32; te[ 10 ] = n33; te[ 14 ] = n34;
  2791. te[ 3 ] = n41; te[ 7 ] = n42; te[ 11 ] = n43; te[ 15 ] = n44;
  2792. return this;
  2793. },
  2794. identity: function () {
  2795. this.set(
  2796. 1, 0, 0, 0,
  2797. 0, 1, 0, 0,
  2798. 0, 0, 1, 0,
  2799. 0, 0, 0, 1
  2800. );
  2801. return this;
  2802. },
  2803. clone: function () {
  2804. return new THREE.Matrix4().fromArray( this.elements );
  2805. },
  2806. copy: function ( m ) {
  2807. this.elements.set( m.elements );
  2808. return this;
  2809. },
  2810. copyPosition: function ( m ) {
  2811. var te = this.elements;
  2812. var me = m.elements;
  2813. te[ 12 ] = me[ 12 ];
  2814. te[ 13 ] = me[ 13 ];
  2815. te[ 14 ] = me[ 14 ];
  2816. return this;
  2817. },
  2818. extractBasis: function ( xAxis, yAxis, zAxis ) {
  2819. var te = this.elements;
  2820. xAxis.set( te[ 0 ], te[ 1 ], te[ 2 ] );
  2821. yAxis.set( te[ 4 ], te[ 5 ], te[ 6 ] );
  2822. zAxis.set( te[ 8 ], te[ 9 ], te[ 10 ] );
  2823. return this;
  2824. },
  2825. makeBasis: function ( xAxis, yAxis, zAxis ) {
  2826. this.set(
  2827. xAxis.x, yAxis.x, zAxis.x, 0,
  2828. xAxis.y, yAxis.y, zAxis.y, 0,
  2829. xAxis.z, yAxis.z, zAxis.z, 0,
  2830. 0, 0, 0, 1
  2831. );
  2832. return this;
  2833. },
  2834. extractRotation: function () {
  2835. var v1;
  2836. return function ( m ) {
  2837. if ( v1 === undefined ) v1 = new THREE.Vector3();
  2838. var te = this.elements;
  2839. var me = m.elements;
  2840. var scaleX = 1 / v1.set( me[ 0 ], me[ 1 ], me[ 2 ] ).length();
  2841. var scaleY = 1 / v1.set( me[ 4 ], me[ 5 ], me[ 6 ] ).length();
  2842. var scaleZ = 1 / v1.set( me[ 8 ], me[ 9 ], me[ 10 ] ).length();
  2843. te[ 0 ] = me[ 0 ] * scaleX;
  2844. te[ 1 ] = me[ 1 ] * scaleX;
  2845. te[ 2 ] = me[ 2 ] * scaleX;
  2846. te[ 4 ] = me[ 4 ] * scaleY;
  2847. te[ 5 ] = me[ 5 ] * scaleY;
  2848. te[ 6 ] = me[ 6 ] * scaleY;
  2849. te[ 8 ] = me[ 8 ] * scaleZ;
  2850. te[ 9 ] = me[ 9 ] * scaleZ;
  2851. te[ 10 ] = me[ 10 ] * scaleZ;
  2852. return this;
  2853. };
  2854. }(),
  2855. makeRotationFromEuler: function ( euler ) {
  2856. if ( euler instanceof THREE.Euler === false ) {
  2857. console.error( 'THREE.Matrix: .makeRotationFromEuler() now expects a Euler rotation rather than a Vector3 and order.' );
  2858. }
  2859. var te = this.elements;
  2860. var x = euler.x, y = euler.y, z = euler.z;
  2861. var a = Math.cos( x ), b = Math.sin( x );
  2862. var c = Math.cos( y ), d = Math.sin( y );
  2863. var e = Math.cos( z ), f = Math.sin( z );
  2864. if ( euler.order === 'XYZ' ) {
  2865. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2866. te[ 0 ] = c * e;
  2867. te[ 4 ] = - c * f;
  2868. te[ 8 ] = d;
  2869. te[ 1 ] = af + be * d;
  2870. te[ 5 ] = ae - bf * d;
  2871. te[ 9 ] = - b * c;
  2872. te[ 2 ] = bf - ae * d;
  2873. te[ 6 ] = be + af * d;
  2874. te[ 10 ] = a * c;
  2875. } else if ( euler.order === 'YXZ' ) {
  2876. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2877. te[ 0 ] = ce + df * b;
  2878. te[ 4 ] = de * b - cf;
  2879. te[ 8 ] = a * d;
  2880. te[ 1 ] = a * f;
  2881. te[ 5 ] = a * e;
  2882. te[ 9 ] = - b;
  2883. te[ 2 ] = cf * b - de;
  2884. te[ 6 ] = df + ce * b;
  2885. te[ 10 ] = a * c;
  2886. } else if ( euler.order === 'ZXY' ) {
  2887. var ce = c * e, cf = c * f, de = d * e, df = d * f;
  2888. te[ 0 ] = ce - df * b;
  2889. te[ 4 ] = - a * f;
  2890. te[ 8 ] = de + cf * b;
  2891. te[ 1 ] = cf + de * b;
  2892. te[ 5 ] = a * e;
  2893. te[ 9 ] = df - ce * b;
  2894. te[ 2 ] = - a * d;
  2895. te[ 6 ] = b;
  2896. te[ 10 ] = a * c;
  2897. } else if ( euler.order === 'ZYX' ) {
  2898. var ae = a * e, af = a * f, be = b * e, bf = b * f;
  2899. te[ 0 ] = c * e;
  2900. te[ 4 ] = be * d - af;
  2901. te[ 8 ] = ae * d + bf;
  2902. te[ 1 ] = c * f;
  2903. te[ 5 ] = bf * d + ae;
  2904. te[ 9 ] = af * d - be;
  2905. te[ 2 ] = - d;
  2906. te[ 6 ] = b * c;
  2907. te[ 10 ] = a * c;
  2908. } else if ( euler.order === 'YZX' ) {
  2909. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2910. te[ 0 ] = c * e;
  2911. te[ 4 ] = bd - ac * f;
  2912. te[ 8 ] = bc * f + ad;
  2913. te[ 1 ] = f;
  2914. te[ 5 ] = a * e;
  2915. te[ 9 ] = - b * e;
  2916. te[ 2 ] = - d * e;
  2917. te[ 6 ] = ad * f + bc;
  2918. te[ 10 ] = ac - bd * f;
  2919. } else if ( euler.order === 'XZY' ) {
  2920. var ac = a * c, ad = a * d, bc = b * c, bd = b * d;
  2921. te[ 0 ] = c * e;
  2922. te[ 4 ] = - f;
  2923. te[ 8 ] = d * e;
  2924. te[ 1 ] = ac * f + bd;
  2925. te[ 5 ] = a * e;
  2926. te[ 9 ] = ad * f - bc;
  2927. te[ 2 ] = bc * f - ad;
  2928. te[ 6 ] = b * e;
  2929. te[ 10 ] = bd * f + ac;
  2930. }
  2931. // last column
  2932. te[ 3 ] = 0;
  2933. te[ 7 ] = 0;
  2934. te[ 11 ] = 0;
  2935. // bottom row
  2936. te[ 12 ] = 0;
  2937. te[ 13 ] = 0;
  2938. te[ 14 ] = 0;
  2939. te[ 15 ] = 1;
  2940. return this;
  2941. },
  2942. makeRotationFromQuaternion: function ( q ) {
  2943. var te = this.elements;
  2944. var x = q.x, y = q.y, z = q.z, w = q.w;
  2945. var x2 = x + x, y2 = y + y, z2 = z + z;
  2946. var xx = x * x2, xy = x * y2, xz = x * z2;
  2947. var yy = y * y2, yz = y * z2, zz = z * z2;
  2948. var wx = w * x2, wy = w * y2, wz = w * z2;
  2949. te[ 0 ] = 1 - ( yy + zz );
  2950. te[ 4 ] = xy - wz;
  2951. te[ 8 ] = xz + wy;
  2952. te[ 1 ] = xy + wz;
  2953. te[ 5 ] = 1 - ( xx + zz );
  2954. te[ 9 ] = yz - wx;
  2955. te[ 2 ] = xz - wy;
  2956. te[ 6 ] = yz + wx;
  2957. te[ 10 ] = 1 - ( xx + yy );
  2958. // last column
  2959. te[ 3 ] = 0;
  2960. te[ 7 ] = 0;
  2961. te[ 11 ] = 0;
  2962. // bottom row
  2963. te[ 12 ] = 0;
  2964. te[ 13 ] = 0;
  2965. te[ 14 ] = 0;
  2966. te[ 15 ] = 1;
  2967. return this;
  2968. },
  2969. lookAt: function () {
  2970. var x, y, z;
  2971. return function ( eye, target, up ) {
  2972. if ( x === undefined ) x = new THREE.Vector3();
  2973. if ( y === undefined ) y = new THREE.Vector3();
  2974. if ( z === undefined ) z = new THREE.Vector3();
  2975. var te = this.elements;
  2976. z.subVectors( eye, target ).normalize();
  2977. if ( z.lengthSq() === 0 ) {
  2978. z.z = 1;
  2979. }
  2980. x.crossVectors( up, z ).normalize();
  2981. if ( x.lengthSq() === 0 ) {
  2982. z.x += 0.0001;
  2983. x.crossVectors( up, z ).normalize();
  2984. }
  2985. y.crossVectors( z, x );
  2986. te[ 0 ] = x.x; te[ 4 ] = y.x; te[ 8 ] = z.x;
  2987. te[ 1 ] = x.y; te[ 5 ] = y.y; te[ 9 ] = z.y;
  2988. te[ 2 ] = x.z; te[ 6 ] = y.z; te[ 10 ] = z.z;
  2989. return this;
  2990. };
  2991. }(),
  2992. multiply: function ( m, n ) {
  2993. if ( n !== undefined ) {
  2994. console.warn( 'THREE.Matrix4: .multiply() now only accepts one argument. Use .multiplyMatrices( a, b ) instead.' );
  2995. return this.multiplyMatrices( m, n );
  2996. }
  2997. return this.multiplyMatrices( this, m );
  2998. },
  2999. multiplyMatrices: function ( a, b ) {
  3000. var ae = a.elements;
  3001. var be = b.elements;
  3002. var te = this.elements;
  3003. var a11 = ae[ 0 ], a12 = ae[ 4 ], a13 = ae[ 8 ], a14 = ae[ 12 ];
  3004. var a21 = ae[ 1 ], a22 = ae[ 5 ], a23 = ae[ 9 ], a24 = ae[ 13 ];
  3005. var a31 = ae[ 2 ], a32 = ae[ 6 ], a33 = ae[ 10 ], a34 = ae[ 14 ];
  3006. var a41 = ae[ 3 ], a42 = ae[ 7 ], a43 = ae[ 11 ], a44 = ae[ 15 ];
  3007. var b11 = be[ 0 ], b12 = be[ 4 ], b13 = be[ 8 ], b14 = be[ 12 ];
  3008. var b21 = be[ 1 ], b22 = be[ 5 ], b23 = be[ 9 ], b24 = be[ 13 ];
  3009. var b31 = be[ 2 ], b32 = be[ 6 ], b33 = be[ 10 ], b34 = be[ 14 ];
  3010. var b41 = be[ 3 ], b42 = be[ 7 ], b43 = be[ 11 ], b44 = be[ 15 ];
  3011. te[ 0 ] = a11 * b11 + a12 * b21 + a13 * b31 + a14 * b41;
  3012. te[ 4 ] = a11 * b12 + a12 * b22 + a13 * b32 + a14 * b42;
  3013. te[ 8 ] = a11 * b13 + a12 * b23 + a13 * b33 + a14 * b43;
  3014. te[ 12 ] = a11 * b14 + a12 * b24 + a13 * b34 + a14 * b44;
  3015. te[ 1 ] = a21 * b11 + a22 * b21 + a23 * b31 + a24 * b41;
  3016. te[ 5 ] = a21 * b12 + a22 * b22 + a23 * b32 + a24 * b42;
  3017. te[ 9 ] = a21 * b13 + a22 * b23 + a23 * b33 + a24 * b43;
  3018. te[ 13 ] = a21 * b14 + a22 * b24 + a23 * b34 + a24 * b44;
  3019. te[ 2 ] = a31 * b11 + a32 * b21 + a33 * b31 + a34 * b41;
  3020. te[ 6 ] = a31 * b12 + a32 * b22 + a33 * b32 + a34 * b42;
  3021. te[ 10 ] = a31 * b13 + a32 * b23 + a33 * b33 + a34 * b43;
  3022. te[ 14 ] = a31 * b14 + a32 * b24 + a33 * b34 + a34 * b44;
  3023. te[ 3 ] = a41 * b11 + a42 * b21 + a43 * b31 + a44 * b41;
  3024. te[ 7 ] = a41 * b12 + a42 * b22 + a43 * b32 + a44 * b42;
  3025. te[ 11 ] = a41 * b13 + a42 * b23 + a43 * b33 + a44 * b43;
  3026. te[ 15 ] = a41 * b14 + a42 * b24 + a43 * b34 + a44 * b44;
  3027. return this;
  3028. },
  3029. multiplyToArray: function ( a, b, r ) {
  3030. var te = this.elements;
  3031. this.multiplyMatrices( a, b );
  3032. r[ 0 ] = te[ 0 ]; r[ 1 ] = te[ 1 ]; r[ 2 ] = te[ 2 ]; r[ 3 ] = te[ 3 ];
  3033. r[ 4 ] = te[ 4 ]; r[ 5 ] = te[ 5 ]; r[ 6 ] = te[ 6 ]; r[ 7 ] = te[ 7 ];
  3034. r[ 8 ] = te[ 8 ]; r[ 9 ] = te[ 9 ]; r[ 10 ] = te[ 10 ]; r[ 11 ] = te[ 11 ];
  3035. r[ 12 ] = te[ 12 ]; r[ 13 ] = te[ 13 ]; r[ 14 ] = te[ 14 ]; r[ 15 ] = te[ 15 ];
  3036. return this;
  3037. },
  3038. multiplyScalar: function ( s ) {
  3039. var te = this.elements;
  3040. te[ 0 ] *= s; te[ 4 ] *= s; te[ 8 ] *= s; te[ 12 ] *= s;
  3041. te[ 1 ] *= s; te[ 5 ] *= s; te[ 9 ] *= s; te[ 13 ] *= s;
  3042. te[ 2 ] *= s; te[ 6 ] *= s; te[ 10 ] *= s; te[ 14 ] *= s;
  3043. te[ 3 ] *= s; te[ 7 ] *= s; te[ 11 ] *= s; te[ 15 ] *= s;
  3044. return this;
  3045. },
  3046. applyToVector3Array: function () {
  3047. var v1;
  3048. return function ( array, offset, length ) {
  3049. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3050. if ( offset === undefined ) offset = 0;
  3051. if ( length === undefined ) length = array.length;
  3052. for ( var i = 0, j = offset; i < length; i += 3, j += 3 ) {
  3053. v1.fromArray( array, j );
  3054. v1.applyMatrix4( this );
  3055. v1.toArray( array, j );
  3056. }
  3057. return array;
  3058. };
  3059. }(),
  3060. applyToBuffer: function () {
  3061. var v1;
  3062. return function applyToBuffer( buffer, offset, length ) {
  3063. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3064. if ( offset === undefined ) offset = 0;
  3065. if ( length === undefined ) length = buffer.length / buffer.itemSize;
  3066. for ( var i = 0, j = offset; i < length; i ++, j ++ ) {
  3067. v1.x = buffer.getX( j );
  3068. v1.y = buffer.getY( j );
  3069. v1.z = buffer.getZ( j );
  3070. v1.applyMatrix4( this );
  3071. buffer.setXYZ( v1.x, v1.y, v1.z );
  3072. }
  3073. return buffer;
  3074. };
  3075. }(),
  3076. determinant: function () {
  3077. var te = this.elements;
  3078. var n11 = te[ 0 ], n12 = te[ 4 ], n13 = te[ 8 ], n14 = te[ 12 ];
  3079. var n21 = te[ 1 ], n22 = te[ 5 ], n23 = te[ 9 ], n24 = te[ 13 ];
  3080. var n31 = te[ 2 ], n32 = te[ 6 ], n33 = te[ 10 ], n34 = te[ 14 ];
  3081. var n41 = te[ 3 ], n42 = te[ 7 ], n43 = te[ 11 ], n44 = te[ 15 ];
  3082. //TODO: make this more efficient
  3083. //( based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm )
  3084. return (
  3085. n41 * (
  3086. + n14 * n23 * n32
  3087. - n13 * n24 * n32
  3088. - n14 * n22 * n33
  3089. + n12 * n24 * n33
  3090. + n13 * n22 * n34
  3091. - n12 * n23 * n34
  3092. ) +
  3093. n42 * (
  3094. + n11 * n23 * n34
  3095. - n11 * n24 * n33
  3096. + n14 * n21 * n33
  3097. - n13 * n21 * n34
  3098. + n13 * n24 * n31
  3099. - n14 * n23 * n31
  3100. ) +
  3101. n43 * (
  3102. + n11 * n24 * n32
  3103. - n11 * n22 * n34
  3104. - n14 * n21 * n32
  3105. + n12 * n21 * n34
  3106. + n14 * n22 * n31
  3107. - n12 * n24 * n31
  3108. ) +
  3109. n44 * (
  3110. - n13 * n22 * n31
  3111. - n11 * n23 * n32
  3112. + n11 * n22 * n33
  3113. + n13 * n21 * n32
  3114. - n12 * n21 * n33
  3115. + n12 * n23 * n31
  3116. )
  3117. );
  3118. },
  3119. transpose: function () {
  3120. var te = this.elements;
  3121. var tmp;
  3122. tmp = te[ 1 ]; te[ 1 ] = te[ 4 ]; te[ 4 ] = tmp;
  3123. tmp = te[ 2 ]; te[ 2 ] = te[ 8 ]; te[ 8 ] = tmp;
  3124. tmp = te[ 6 ]; te[ 6 ] = te[ 9 ]; te[ 9 ] = tmp;
  3125. tmp = te[ 3 ]; te[ 3 ] = te[ 12 ]; te[ 12 ] = tmp;
  3126. tmp = te[ 7 ]; te[ 7 ] = te[ 13 ]; te[ 13 ] = tmp;
  3127. tmp = te[ 11 ]; te[ 11 ] = te[ 14 ]; te[ 14 ] = tmp;
  3128. return this;
  3129. },
  3130. flattenToArrayOffset: function ( array, offset ) {
  3131. var te = this.elements;
  3132. array[ offset ] = te[ 0 ];
  3133. array[ offset + 1 ] = te[ 1 ];
  3134. array[ offset + 2 ] = te[ 2 ];
  3135. array[ offset + 3 ] = te[ 3 ];
  3136. array[ offset + 4 ] = te[ 4 ];
  3137. array[ offset + 5 ] = te[ 5 ];
  3138. array[ offset + 6 ] = te[ 6 ];
  3139. array[ offset + 7 ] = te[ 7 ];
  3140. array[ offset + 8 ] = te[ 8 ];
  3141. array[ offset + 9 ] = te[ 9 ];
  3142. array[ offset + 10 ] = te[ 10 ];
  3143. array[ offset + 11 ] = te[ 11 ];
  3144. array[ offset + 12 ] = te[ 12 ];
  3145. array[ offset + 13 ] = te[ 13 ];
  3146. array[ offset + 14 ] = te[ 14 ];
  3147. array[ offset + 15 ] = te[ 15 ];
  3148. return array;
  3149. },
  3150. getPosition: function () {
  3151. var v1;
  3152. return function () {
  3153. if ( v1 === undefined ) v1 = new THREE.Vector3();
  3154. console.warn( 'THREE.Matrix4: .getPosition() has been removed. Use Vector3.setFromMatrixPosition( matrix ) instead.' );
  3155. var te = this.elements;
  3156. return v1.set( te[ 12 ], te[ 13 ], te[ 14 ] );
  3157. };
  3158. }(),
  3159. setPosition: function ( v ) {
  3160. var te = this.elements;
  3161. te[ 12 ] = v.x;
  3162. te[ 13 ] = v.y;
  3163. te[ 14 ] = v.z;
  3164. return this;
  3165. },
  3166. getInverse: function ( m, throwOnInvertible ) {
  3167. // based on http://www.euclideanspace.com/maths/algebra/matrix/functions/inverse/fourD/index.htm
  3168. var te = this.elements;
  3169. var me = m.elements;
  3170. var n11 = me[ 0 ], n12 = me[ 4 ], n13 = me[ 8 ], n14 = me[ 12 ];
  3171. var n21 = me[ 1 ], n22 = me[ 5 ], n23 = me[ 9 ], n24 = me[ 13 ];
  3172. var n31 = me[ 2 ], n32 = me[ 6 ], n33 = me[ 10 ], n34 = me[ 14 ];
  3173. var n41 = me[ 3 ], n42 = me[ 7 ], n43 = me[ 11 ], n44 = me[ 15 ];
  3174. te[ 0 ] = n23 * n34 * n42 - n24 * n33 * n42 + n24 * n32 * n43 - n22 * n34 * n43 - n23 * n32 * n44 + n22 * n33 * n44;
  3175. te[ 4 ] = n14 * n33 * n42 - n13 * n34 * n42 - n14 * n32 * n43 + n12 * n34 * n43 + n13 * n32 * n44 - n12 * n33 * n44;
  3176. te[ 8 ] = n13 * n24 * n42 - n14 * n23 * n42 + n14 * n22 * n43 - n12 * n24 * n43 - n13 * n22 * n44 + n12 * n23 * n44;
  3177. te[ 12 ] = n14 * n23 * n32 - n13 * n24 * n32 - n14 * n22 * n33 + n12 * n24 * n33 + n13 * n22 * n34 - n12 * n23 * n34;
  3178. te[ 1 ] = n24 * n33 * n41 - n23 * n34 * n41 - n24 * n31 * n43 + n21 * n34 * n43 + n23 * n31 * n44 - n21 * n33 * n44;
  3179. te[ 5 ] = n13 * n34 * n41 - n14 * n33 * n41 + n14 * n31 * n43 - n11 * n34 * n43 - n13 * n31 * n44 + n11 * n33 * n44;
  3180. te[ 9 ] = n14 * n23 * n41 - n13 * n24 * n41 - n14 * n21 * n43 + n11 * n24 * n43 + n13 * n21 * n44 - n11 * n23 * n44;
  3181. te[ 13 ] = n13 * n24 * n31 - n14 * n23 * n31 + n14 * n21 * n33 - n11 * n24 * n33 - n13 * n21 * n34 + n11 * n23 * n34;
  3182. te[ 2 ] = n22 * n34 * n41 - n24 * n32 * n41 + n24 * n31 * n42 - n21 * n34 * n42 - n22 * n31 * n44 + n21 * n32 * n44;
  3183. te[ 6 ] = n14 * n32 * n41 - n12 * n34 * n41 - n14 * n31 * n42 + n11 * n34 * n42 + n12 * n31 * n44 - n11 * n32 * n44;
  3184. te[ 10 ] = n12 * n24 * n41 - n14 * n22 * n41 + n14 * n21 * n42 - n11 * n24 * n42 - n12 * n21 * n44 + n11 * n22 * n44;
  3185. te[ 14 ] = n14 * n22 * n31 - n12 * n24 * n31 - n14 * n21 * n32 + n11 * n24 * n32 + n12 * n21 * n34 - n11 * n22 * n34;
  3186. te[ 3 ] = n23 * n32 * n41 - n22 * n33 * n41 - n23 * n31 * n42 + n21 * n33 * n42 + n22 * n31 * n43 - n21 * n32 * n43;
  3187. te[ 7 ] = n12 * n33 * n41 - n13 * n32 * n41 + n13 * n31 * n42 - n11 * n33 * n42 - n12 * n31 * n43 + n11 * n32 * n43;
  3188. te[ 11 ] = n13 * n22 * n41 - n12 * n23 * n41 - n13 * n21 * n42 + n11 * n23 * n42 + n12 * n21 * n43 - n11 * n22 * n43;
  3189. te[ 15 ] = n12 * n23 * n31 - n13 * n22 * n31 + n13 * n21 * n32 - n11 * n23 * n32 - n12 * n21 * n33 + n11 * n22 * n33;
  3190. var det = n11 * te[ 0 ] + n21 * te[ 4 ] + n31 * te[ 8 ] + n41 * te[ 12 ];
  3191. if ( det === 0 ) {
  3192. var msg = "THREE.Matrix4.getInverse(): can't invert matrix, determinant is 0";
  3193. if ( throwOnInvertible || false ) {
  3194. throw new Error( msg );
  3195. } else {
  3196. console.warn( msg );
  3197. }
  3198. this.identity();
  3199. return this;
  3200. }
  3201. this.multiplyScalar( 1 / det );
  3202. return this;
  3203. },
  3204. scale: function ( v ) {
  3205. var te = this.elements;
  3206. var x = v.x, y = v.y, z = v.z;
  3207. te[ 0 ] *= x; te[ 4 ] *= y; te[ 8 ] *= z;
  3208. te[ 1 ] *= x; te[ 5 ] *= y; te[ 9 ] *= z;
  3209. te[ 2 ] *= x; te[ 6 ] *= y; te[ 10 ] *= z;
  3210. te[ 3 ] *= x; te[ 7 ] *= y; te[ 11 ] *= z;
  3211. return this;
  3212. },
  3213. getMaxScaleOnAxis: function () {
  3214. var te = this.elements;
  3215. var scaleXSq = te[ 0 ] * te[ 0 ] + te[ 1 ] * te[ 1 ] + te[ 2 ] * te[ 2 ];
  3216. var scaleYSq = te[ 4 ] * te[ 4 ] + te[ 5 ] * te[ 5 ] + te[ 6 ] * te[ 6 ];
  3217. var scaleZSq = te[ 8 ] * te[ 8 ] + te[ 9 ] * te[ 9 ] + te[ 10 ] * te[ 10 ];
  3218. return Math.sqrt( Math.max( scaleXSq, scaleYSq, scaleZSq ) );
  3219. },
  3220. makeTranslation: function ( x, y, z ) {
  3221. this.set(
  3222. 1, 0, 0, x,
  3223. 0, 1, 0, y,
  3224. 0, 0, 1, z,
  3225. 0, 0, 0, 1
  3226. );
  3227. return this;
  3228. },
  3229. makeRotationX: function ( theta ) {
  3230. var c = Math.cos( theta ), s = Math.sin( theta );
  3231. this.set(
  3232. 1, 0, 0, 0,
  3233. 0, c, - s, 0,
  3234. 0, s, c, 0,
  3235. 0, 0, 0, 1
  3236. );
  3237. return this;
  3238. },
  3239. makeRotationY: function ( theta ) {
  3240. var c = Math.cos( theta ), s = Math.sin( theta );
  3241. this.set(
  3242. c, 0, s, 0,
  3243. 0, 1, 0, 0,
  3244. - s, 0, c, 0,
  3245. 0, 0, 0, 1
  3246. );
  3247. return this;
  3248. },
  3249. makeRotationZ: function ( theta ) {
  3250. var c = Math.cos( theta ), s = Math.sin( theta );
  3251. this.set(
  3252. c, - s, 0, 0,
  3253. s, c, 0, 0,
  3254. 0, 0, 1, 0,
  3255. 0, 0, 0, 1
  3256. );
  3257. return this;
  3258. },
  3259. makeRotationAxis: function ( axis, angle ) {
  3260. // Based on http://www.gamedev.net/reference/articles/article1199.asp
  3261. var c = Math.cos( angle );
  3262. var s = Math.sin( angle );
  3263. var t = 1 - c;
  3264. var x = axis.x, y = axis.y, z = axis.z;
  3265. var tx = t * x, ty = t * y;
  3266. this.set(
  3267. tx * x + c, tx * y - s * z, tx * z + s * y, 0,
  3268. tx * y + s * z, ty * y + c, ty * z - s * x, 0,
  3269. tx * z - s * y, ty * z + s * x, t * z * z + c, 0,
  3270. 0, 0, 0, 1
  3271. );
  3272. return this;
  3273. },
  3274. makeScale: function ( x, y, z ) {
  3275. this.set(
  3276. x, 0, 0, 0,
  3277. 0, y, 0, 0,
  3278. 0, 0, z, 0,
  3279. 0, 0, 0, 1
  3280. );
  3281. return this;
  3282. },
  3283. compose: function ( position, quaternion, scale ) {
  3284. this.makeRotationFromQuaternion( quaternion );
  3285. this.scale( scale );
  3286. this.setPosition( position );
  3287. return this;
  3288. },
  3289. decompose: function () {
  3290. var vector, matrix;
  3291. return function ( position, quaternion, scale ) {
  3292. if ( vector === undefined ) vector = new THREE.Vector3();
  3293. if ( matrix === undefined ) matrix = new THREE.Matrix4();
  3294. var te = this.elements;
  3295. var sx = vector.set( te[ 0 ], te[ 1 ], te[ 2 ] ).length();
  3296. var sy = vector.set( te[ 4 ], te[ 5 ], te[ 6 ] ).length();
  3297. var sz = vector.set( te[ 8 ], te[ 9 ], te[ 10 ] ).length();
  3298. // if determine is negative, we need to invert one scale
  3299. var det = this.determinant();
  3300. if ( det < 0 ) {
  3301. sx = - sx;
  3302. }
  3303. position.x = te[ 12 ];
  3304. position.y = te[ 13 ];
  3305. position.z = te[ 14 ];
  3306. // scale the rotation part
  3307. matrix.elements.set( this.elements ); // at this point matrix is incomplete so we can't use .copy()
  3308. var invSX = 1 / sx;
  3309. var invSY = 1 / sy;
  3310. var invSZ = 1 / sz;
  3311. matrix.elements[ 0 ] *= invSX;
  3312. matrix.elements[ 1 ] *= invSX;
  3313. matrix.elements[ 2 ] *= invSX;
  3314. matrix.elements[ 4 ] *= invSY;
  3315. matrix.elements[ 5 ] *= invSY;
  3316. matrix.elements[ 6 ] *= invSY;
  3317. matrix.elements[ 8 ] *= invSZ;
  3318. matrix.elements[ 9 ] *= invSZ;
  3319. matrix.elements[ 10 ] *= invSZ;
  3320. quaternion.setFromRotationMatrix( matrix );
  3321. scale.x = sx;
  3322. scale.y = sy;
  3323. scale.z = sz;
  3324. return this;
  3325. };
  3326. }(),
  3327. makeFrustum: function ( left, right, bottom, top, near, far ) {
  3328. var te = this.elements;
  3329. var x = 2 * near / ( right - left );
  3330. var y = 2 * near / ( top - bottom );
  3331. var a = ( right + left ) / ( right - left );
  3332. var b = ( top + bottom ) / ( top - bottom );
  3333. var c = - ( far + near ) / ( far - near );
  3334. var d = - 2 * far * near / ( far - near );
  3335. te[ 0 ] = x; te[ 4 ] = 0; te[ 8 ] = a; te[ 12 ] = 0;
  3336. te[ 1 ] = 0; te[ 5 ] = y; te[ 9 ] = b; te[ 13 ] = 0;
  3337. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = c; te[ 14 ] = d;
  3338. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = - 1; te[ 15 ] = 0;
  3339. return this;
  3340. },
  3341. makePerspective: function ( fov, aspect, near, far ) {
  3342. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  3343. var ymin = - ymax;
  3344. var xmin = ymin * aspect;
  3345. var xmax = ymax * aspect;
  3346. return this.makeFrustum( xmin, xmax, ymin, ymax, near, far );
  3347. },
  3348. makeOrthographic: function ( left, right, top, bottom, near, far ) {
  3349. var te = this.elements;
  3350. var w = right - left;
  3351. var h = top - bottom;
  3352. var p = far - near;
  3353. var x = ( right + left ) / w;
  3354. var y = ( top + bottom ) / h;
  3355. var z = ( far + near ) / p;
  3356. te[ 0 ] = 2 / w; te[ 4 ] = 0; te[ 8 ] = 0; te[ 12 ] = - x;
  3357. te[ 1 ] = 0; te[ 5 ] = 2 / h; te[ 9 ] = 0; te[ 13 ] = - y;
  3358. te[ 2 ] = 0; te[ 6 ] = 0; te[ 10 ] = - 2 / p; te[ 14 ] = - z;
  3359. te[ 3 ] = 0; te[ 7 ] = 0; te[ 11 ] = 0; te[ 15 ] = 1;
  3360. return this;
  3361. },
  3362. equals: function ( matrix ) {
  3363. var te = this.elements;
  3364. var me = matrix.elements;
  3365. for ( var i = 0; i < 16; i ++ ) {
  3366. if ( te[ i ] !== me[ i ] ) return false;
  3367. }
  3368. return true;
  3369. },
  3370. fromArray: function ( array ) {
  3371. this.elements.set( array );
  3372. return this;
  3373. },
  3374. toArray: function () {
  3375. var te = this.elements;
  3376. return [
  3377. te[ 0 ], te[ 1 ], te[ 2 ], te[ 3 ],
  3378. te[ 4 ], te[ 5 ], te[ 6 ], te[ 7 ],
  3379. te[ 8 ], te[ 9 ], te[ 10 ], te[ 11 ],
  3380. te[ 12 ], te[ 13 ], te[ 14 ], te[ 15 ]
  3381. ];
  3382. }
  3383. };
  3384. // File:src/math/Ray.js
  3385. /**
  3386. * @author bhouston / http://clara.io
  3387. */
  3388. THREE.Ray = function ( origin, direction ) {
  3389. this.origin = ( origin !== undefined ) ? origin : new THREE.Vector3();
  3390. this.direction = ( direction !== undefined ) ? direction : new THREE.Vector3();
  3391. };
  3392. THREE.Ray.prototype = {
  3393. constructor: THREE.Ray,
  3394. set: function ( origin, direction ) {
  3395. this.origin.copy( origin );
  3396. this.direction.copy( direction );
  3397. return this;
  3398. },
  3399. clone: function () {
  3400. return new this.constructor().copy( this );
  3401. },
  3402. copy: function ( ray ) {
  3403. this.origin.copy( ray.origin );
  3404. this.direction.copy( ray.direction );
  3405. return this;
  3406. },
  3407. at: function ( t, optionalTarget ) {
  3408. var result = optionalTarget || new THREE.Vector3();
  3409. return result.copy( this.direction ).multiplyScalar( t ).add( this.origin );
  3410. },
  3411. lookAt: function ( v ) {
  3412. this.direction.copy( v ).sub( this.origin ).normalize();
  3413. },
  3414. recast: function () {
  3415. var v1 = new THREE.Vector3();
  3416. return function ( t ) {
  3417. this.origin.copy( this.at( t, v1 ) );
  3418. return this;
  3419. };
  3420. }(),
  3421. closestPointToPoint: function ( point, optionalTarget ) {
  3422. var result = optionalTarget || new THREE.Vector3();
  3423. result.subVectors( point, this.origin );
  3424. var directionDistance = result.dot( this.direction );
  3425. if ( directionDistance < 0 ) {
  3426. return result.copy( this.origin );
  3427. }
  3428. return result.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3429. },
  3430. distanceToPoint: function ( point ) {
  3431. return Math.sqrt( this.distanceSqToPoint( point ) );
  3432. },
  3433. distanceSqToPoint: function () {
  3434. var v1 = new THREE.Vector3();
  3435. return function ( point ) {
  3436. var directionDistance = v1.subVectors( point, this.origin ).dot( this.direction );
  3437. // point behind the ray
  3438. if ( directionDistance < 0 ) {
  3439. return this.origin.distanceToSquared( point );
  3440. }
  3441. v1.copy( this.direction ).multiplyScalar( directionDistance ).add( this.origin );
  3442. return v1.distanceToSquared( point );
  3443. };
  3444. }(),
  3445. distanceSqToSegment: function () {
  3446. var segCenter = new THREE.Vector3();
  3447. var segDir = new THREE.Vector3();
  3448. var diff = new THREE.Vector3();
  3449. return function ( v0, v1, optionalPointOnRay, optionalPointOnSegment ) {
  3450. // from http://www.geometrictools.com/LibMathematics/Distance/Wm5DistRay3Segment3.cpp
  3451. // It returns the min distance between the ray and the segment
  3452. // defined by v0 and v1
  3453. // It can also set two optional targets :
  3454. // - The closest point on the ray
  3455. // - The closest point on the segment
  3456. segCenter.copy( v0 ).add( v1 ).multiplyScalar( 0.5 );
  3457. segDir.copy( v1 ).sub( v0 ).normalize();
  3458. diff.copy( this.origin ).sub( segCenter );
  3459. var segExtent = v0.distanceTo( v1 ) * 0.5;
  3460. var a01 = - this.direction.dot( segDir );
  3461. var b0 = diff.dot( this.direction );
  3462. var b1 = - diff.dot( segDir );
  3463. var c = diff.lengthSq();
  3464. var det = Math.abs( 1 - a01 * a01 );
  3465. var s0, s1, sqrDist, extDet;
  3466. if ( det > 0 ) {
  3467. // The ray and segment are not parallel.
  3468. s0 = a01 * b1 - b0;
  3469. s1 = a01 * b0 - b1;
  3470. extDet = segExtent * det;
  3471. if ( s0 >= 0 ) {
  3472. if ( s1 >= - extDet ) {
  3473. if ( s1 <= extDet ) {
  3474. // region 0
  3475. // Minimum at interior points of ray and segment.
  3476. var invDet = 1 / det;
  3477. s0 *= invDet;
  3478. s1 *= invDet;
  3479. sqrDist = s0 * ( s0 + a01 * s1 + 2 * b0 ) + s1 * ( a01 * s0 + s1 + 2 * b1 ) + c;
  3480. } else {
  3481. // region 1
  3482. s1 = segExtent;
  3483. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3484. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3485. }
  3486. } else {
  3487. // region 5
  3488. s1 = - segExtent;
  3489. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3490. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3491. }
  3492. } else {
  3493. if ( s1 <= - extDet ) {
  3494. // region 4
  3495. s0 = Math.max( 0, - ( - a01 * segExtent + b0 ) );
  3496. s1 = ( s0 > 0 ) ? - segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3497. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3498. } else if ( s1 <= extDet ) {
  3499. // region 3
  3500. s0 = 0;
  3501. s1 = Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3502. sqrDist = s1 * ( s1 + 2 * b1 ) + c;
  3503. } else {
  3504. // region 2
  3505. s0 = Math.max( 0, - ( a01 * segExtent + b0 ) );
  3506. s1 = ( s0 > 0 ) ? segExtent : Math.min( Math.max( - segExtent, - b1 ), segExtent );
  3507. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3508. }
  3509. }
  3510. } else {
  3511. // Ray and segment are parallel.
  3512. s1 = ( a01 > 0 ) ? - segExtent : segExtent;
  3513. s0 = Math.max( 0, - ( a01 * s1 + b0 ) );
  3514. sqrDist = - s0 * s0 + s1 * ( s1 + 2 * b1 ) + c;
  3515. }
  3516. if ( optionalPointOnRay ) {
  3517. optionalPointOnRay.copy( this.direction ).multiplyScalar( s0 ).add( this.origin );
  3518. }
  3519. if ( optionalPointOnSegment ) {
  3520. optionalPointOnSegment.copy( segDir ).multiplyScalar( s1 ).add( segCenter );
  3521. }
  3522. return sqrDist;
  3523. };
  3524. }(),
  3525. intersectSphere: function () {
  3526. var v1 = new THREE.Vector3();
  3527. return function ( sphere, optionalTarget ) {
  3528. v1.subVectors( sphere.center, this.origin );
  3529. var tca = v1.dot( this.direction );
  3530. var d2 = v1.dot( v1 ) - tca * tca;
  3531. var radius2 = sphere.radius * sphere.radius;
  3532. if ( d2 > radius2 ) return null;
  3533. var thc = Math.sqrt( radius2 - d2 );
  3534. // t0 = first intersect point - entrance on front of sphere
  3535. var t0 = tca - thc;
  3536. // t1 = second intersect point - exit point on back of sphere
  3537. var t1 = tca + thc;
  3538. // test to see if both t0 and t1 are behind the ray - if so, return null
  3539. if ( t0 < 0 && t1 < 0 ) return null;
  3540. // test to see if t0 is behind the ray:
  3541. // if it is, the ray is inside the sphere, so return the second exit point scaled by t1,
  3542. // in order to always return an intersect point that is in front of the ray.
  3543. if ( t0 < 0 ) return this.at( t1, optionalTarget );
  3544. // else t0 is in front of the ray, so return the first collision point scaled by t0
  3545. return this.at( t0, optionalTarget );
  3546. }
  3547. }(),
  3548. intersectsSphere: function ( sphere ) {
  3549. return this.distanceToPoint( sphere.center ) <= sphere.radius;
  3550. },
  3551. distanceToPlane: function ( plane ) {
  3552. var denominator = plane.normal.dot( this.direction );
  3553. if ( denominator === 0 ) {
  3554. // line is coplanar, return origin
  3555. if ( plane.distanceToPoint( this.origin ) === 0 ) {
  3556. return 0;
  3557. }
  3558. // Null is preferable to undefined since undefined means.... it is undefined
  3559. return null;
  3560. }
  3561. var t = - ( this.origin.dot( plane.normal ) + plane.constant ) / denominator;
  3562. // Return if the ray never intersects the plane
  3563. return t >= 0 ? t : null;
  3564. },
  3565. intersectPlane: function ( plane, optionalTarget ) {
  3566. var t = this.distanceToPlane( plane );
  3567. if ( t === null ) {
  3568. return null;
  3569. }
  3570. return this.at( t, optionalTarget );
  3571. },
  3572. intersectsPlane: function ( plane ) {
  3573. // check if the ray lies on the plane first
  3574. var distToPoint = plane.distanceToPoint( this.origin );
  3575. if ( distToPoint === 0 ) {
  3576. return true;
  3577. }
  3578. var denominator = plane.normal.dot( this.direction );
  3579. if ( denominator * distToPoint < 0 ) {
  3580. return true;
  3581. }
  3582. // ray origin is behind the plane (and is pointing behind it)
  3583. return false;
  3584. },
  3585. intersectBox: function ( box, optionalTarget ) {
  3586. var tmin, tmax, tymin, tymax, tzmin, tzmax;
  3587. var invdirx = 1 / this.direction.x,
  3588. invdiry = 1 / this.direction.y,
  3589. invdirz = 1 / this.direction.z;
  3590. var origin = this.origin;
  3591. if ( invdirx >= 0 ) {
  3592. tmin = ( box.min.x - origin.x ) * invdirx;
  3593. tmax = ( box.max.x - origin.x ) * invdirx;
  3594. } else {
  3595. tmin = ( box.max.x - origin.x ) * invdirx;
  3596. tmax = ( box.min.x - origin.x ) * invdirx;
  3597. }
  3598. if ( invdiry >= 0 ) {
  3599. tymin = ( box.min.y - origin.y ) * invdiry;
  3600. tymax = ( box.max.y - origin.y ) * invdiry;
  3601. } else {
  3602. tymin = ( box.max.y - origin.y ) * invdiry;
  3603. tymax = ( box.min.y - origin.y ) * invdiry;
  3604. }
  3605. if ( ( tmin > tymax ) || ( tymin > tmax ) ) return null;
  3606. // These lines also handle the case where tmin or tmax is NaN
  3607. // (result of 0 * Infinity). x !== x returns true if x is NaN
  3608. if ( tymin > tmin || tmin !== tmin ) tmin = tymin;
  3609. if ( tymax < tmax || tmax !== tmax ) tmax = tymax;
  3610. if ( invdirz >= 0 ) {
  3611. tzmin = ( box.min.z - origin.z ) * invdirz;
  3612. tzmax = ( box.max.z - origin.z ) * invdirz;
  3613. } else {
  3614. tzmin = ( box.max.z - origin.z ) * invdirz;
  3615. tzmax = ( box.min.z - origin.z ) * invdirz;
  3616. }
  3617. if ( ( tmin > tzmax ) || ( tzmin > tmax ) ) return null;
  3618. if ( tzmin > tmin || tmin !== tmin ) tmin = tzmin;
  3619. if ( tzmax < tmax || tmax !== tmax ) tmax = tzmax;
  3620. //return point closest to the ray (positive side)
  3621. if ( tmax < 0 ) return null;
  3622. return this.at( tmin >= 0 ? tmin : tmax, optionalTarget );
  3623. },
  3624. intersectsBox: ( function () {
  3625. var v = new THREE.Vector3();
  3626. return function ( box ) {
  3627. return this.intersectBox( box, v ) !== null;
  3628. };
  3629. } )(),
  3630. intersectTriangle: function () {
  3631. // Compute the offset origin, edges, and normal.
  3632. var diff = new THREE.Vector3();
  3633. var edge1 = new THREE.Vector3();
  3634. var edge2 = new THREE.Vector3();
  3635. var normal = new THREE.Vector3();
  3636. return function ( a, b, c, backfaceCulling, optionalTarget ) {
  3637. // from http://www.geometrictools.com/LibMathematics/Intersection/Wm5IntrRay3Triangle3.cpp
  3638. edge1.subVectors( b, a );
  3639. edge2.subVectors( c, a );
  3640. normal.crossVectors( edge1, edge2 );
  3641. // Solve Q + t*D = b1*E1 + b2*E2 (Q = kDiff, D = ray direction,
  3642. // E1 = kEdge1, E2 = kEdge2, N = Cross(E1,E2)) by
  3643. // |Dot(D,N)|*b1 = sign(Dot(D,N))*Dot(D,Cross(Q,E2))
  3644. // |Dot(D,N)|*b2 = sign(Dot(D,N))*Dot(D,Cross(E1,Q))
  3645. // |Dot(D,N)|*t = -sign(Dot(D,N))*Dot(Q,N)
  3646. var DdN = this.direction.dot( normal );
  3647. var sign;
  3648. if ( DdN > 0 ) {
  3649. if ( backfaceCulling ) return null;
  3650. sign = 1;
  3651. } else if ( DdN < 0 ) {
  3652. sign = - 1;
  3653. DdN = - DdN;
  3654. } else {
  3655. return null;
  3656. }
  3657. diff.subVectors( this.origin, a );
  3658. var DdQxE2 = sign * this.direction.dot( edge2.crossVectors( diff, edge2 ) );
  3659. // b1 < 0, no intersection
  3660. if ( DdQxE2 < 0 ) {
  3661. return null;
  3662. }
  3663. var DdE1xQ = sign * this.direction.dot( edge1.cross( diff ) );
  3664. // b2 < 0, no intersection
  3665. if ( DdE1xQ < 0 ) {
  3666. return null;
  3667. }
  3668. // b1+b2 > 1, no intersection
  3669. if ( DdQxE2 + DdE1xQ > DdN ) {
  3670. return null;
  3671. }
  3672. // Line intersects triangle, check if ray does.
  3673. var QdN = - sign * diff.dot( normal );
  3674. // t < 0, no intersection
  3675. if ( QdN < 0 ) {
  3676. return null;
  3677. }
  3678. // Ray intersects triangle.
  3679. return this.at( QdN / DdN, optionalTarget );
  3680. };
  3681. }(),
  3682. applyMatrix4: function ( matrix4 ) {
  3683. this.direction.add( this.origin ).applyMatrix4( matrix4 );
  3684. this.origin.applyMatrix4( matrix4 );
  3685. this.direction.sub( this.origin );
  3686. this.direction.normalize();
  3687. return this;
  3688. },
  3689. equals: function ( ray ) {
  3690. return ray.origin.equals( this.origin ) && ray.direction.equals( this.direction );
  3691. }
  3692. };
  3693. // File:src/math/Sphere.js
  3694. /**
  3695. * @author bhouston / http://clara.io
  3696. * @author mrdoob / http://mrdoob.com/
  3697. */
  3698. THREE.Sphere = function ( center, radius ) {
  3699. this.center = ( center !== undefined ) ? center : new THREE.Vector3();
  3700. this.radius = ( radius !== undefined ) ? radius : 0;
  3701. };
  3702. THREE.Sphere.prototype = {
  3703. constructor: THREE.Sphere,
  3704. set: function ( center, radius ) {
  3705. this.center.copy( center );
  3706. this.radius = radius;
  3707. return this;
  3708. },
  3709. setFromPoints: function () {
  3710. var box = new THREE.Box3();
  3711. return function ( points, optionalCenter ) {
  3712. var center = this.center;
  3713. if ( optionalCenter !== undefined ) {
  3714. center.copy( optionalCenter );
  3715. } else {
  3716. box.setFromPoints( points ).center( center );
  3717. }
  3718. var maxRadiusSq = 0;
  3719. for ( var i = 0, il = points.length; i < il; i ++ ) {
  3720. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( points[ i ] ) );
  3721. }
  3722. this.radius = Math.sqrt( maxRadiusSq );
  3723. return this;
  3724. };
  3725. }(),
  3726. clone: function () {
  3727. return new this.constructor().copy( this );
  3728. },
  3729. copy: function ( sphere ) {
  3730. this.center.copy( sphere.center );
  3731. this.radius = sphere.radius;
  3732. return this;
  3733. },
  3734. empty: function () {
  3735. return ( this.radius <= 0 );
  3736. },
  3737. containsPoint: function ( point ) {
  3738. return ( point.distanceToSquared( this.center ) <= ( this.radius * this.radius ) );
  3739. },
  3740. distanceToPoint: function ( point ) {
  3741. return ( point.distanceTo( this.center ) - this.radius );
  3742. },
  3743. intersectsSphere: function ( sphere ) {
  3744. var radiusSum = this.radius + sphere.radius;
  3745. return sphere.center.distanceToSquared( this.center ) <= ( radiusSum * radiusSum );
  3746. },
  3747. intersectsBox: function ( box ) {
  3748. return box.intersectsSphere( this );
  3749. },
  3750. intersectsPlane: function ( plane ) {
  3751. // We use the following equation to compute the signed distance from
  3752. // the center of the sphere to the plane.
  3753. //
  3754. // distance = q * n - d
  3755. //
  3756. // If this distance is greater than the radius of the sphere,
  3757. // then there is no intersection.
  3758. return Math.abs( this.center.dot( plane.normal ) - plane.constant ) <= this.radius;
  3759. },
  3760. clampPoint: function ( point, optionalTarget ) {
  3761. var deltaLengthSq = this.center.distanceToSquared( point );
  3762. var result = optionalTarget || new THREE.Vector3();
  3763. result.copy( point );
  3764. if ( deltaLengthSq > ( this.radius * this.radius ) ) {
  3765. result.sub( this.center ).normalize();
  3766. result.multiplyScalar( this.radius ).add( this.center );
  3767. }
  3768. return result;
  3769. },
  3770. getBoundingBox: function ( optionalTarget ) {
  3771. var box = optionalTarget || new THREE.Box3();
  3772. box.set( this.center, this.center );
  3773. box.expandByScalar( this.radius );
  3774. return box;
  3775. },
  3776. applyMatrix4: function ( matrix ) {
  3777. this.center.applyMatrix4( matrix );
  3778. this.radius = this.radius * matrix.getMaxScaleOnAxis();
  3779. return this;
  3780. },
  3781. translate: function ( offset ) {
  3782. this.center.add( offset );
  3783. return this;
  3784. },
  3785. equals: function ( sphere ) {
  3786. return sphere.center.equals( this.center ) && ( sphere.radius === this.radius );
  3787. }
  3788. };
  3789. // File:src/math/Frustum.js
  3790. /**
  3791. * @author mrdoob / http://mrdoob.com/
  3792. * @author alteredq / http://alteredqualia.com/
  3793. * @author bhouston / http://clara.io
  3794. */
  3795. THREE.Frustum = function ( p0, p1, p2, p3, p4, p5 ) {
  3796. this.planes = [
  3797. ( p0 !== undefined ) ? p0 : new THREE.Plane(),
  3798. ( p1 !== undefined ) ? p1 : new THREE.Plane(),
  3799. ( p2 !== undefined ) ? p2 : new THREE.Plane(),
  3800. ( p3 !== undefined ) ? p3 : new THREE.Plane(),
  3801. ( p4 !== undefined ) ? p4 : new THREE.Plane(),
  3802. ( p5 !== undefined ) ? p5 : new THREE.Plane()
  3803. ];
  3804. };
  3805. THREE.Frustum.prototype = {
  3806. constructor: THREE.Frustum,
  3807. set: function ( p0, p1, p2, p3, p4, p5 ) {
  3808. var planes = this.planes;
  3809. planes[ 0 ].copy( p0 );
  3810. planes[ 1 ].copy( p1 );
  3811. planes[ 2 ].copy( p2 );
  3812. planes[ 3 ].copy( p3 );
  3813. planes[ 4 ].copy( p4 );
  3814. planes[ 5 ].copy( p5 );
  3815. return this;
  3816. },
  3817. clone: function () {
  3818. return new this.constructor().copy( this );
  3819. },
  3820. copy: function ( frustum ) {
  3821. var planes = this.planes;
  3822. for ( var i = 0; i < 6; i ++ ) {
  3823. planes[ i ].copy( frustum.planes[ i ] );
  3824. }
  3825. return this;
  3826. },
  3827. setFromMatrix: function ( m ) {
  3828. var planes = this.planes;
  3829. var me = m.elements;
  3830. var me0 = me[ 0 ], me1 = me[ 1 ], me2 = me[ 2 ], me3 = me[ 3 ];
  3831. var me4 = me[ 4 ], me5 = me[ 5 ], me6 = me[ 6 ], me7 = me[ 7 ];
  3832. var me8 = me[ 8 ], me9 = me[ 9 ], me10 = me[ 10 ], me11 = me[ 11 ];
  3833. var me12 = me[ 12 ], me13 = me[ 13 ], me14 = me[ 14 ], me15 = me[ 15 ];
  3834. planes[ 0 ].setComponents( me3 - me0, me7 - me4, me11 - me8, me15 - me12 ).normalize();
  3835. planes[ 1 ].setComponents( me3 + me0, me7 + me4, me11 + me8, me15 + me12 ).normalize();
  3836. planes[ 2 ].setComponents( me3 + me1, me7 + me5, me11 + me9, me15 + me13 ).normalize();
  3837. planes[ 3 ].setComponents( me3 - me1, me7 - me5, me11 - me9, me15 - me13 ).normalize();
  3838. planes[ 4 ].setComponents( me3 - me2, me7 - me6, me11 - me10, me15 - me14 ).normalize();
  3839. planes[ 5 ].setComponents( me3 + me2, me7 + me6, me11 + me10, me15 + me14 ).normalize();
  3840. return this;
  3841. },
  3842. intersectsObject: function () {
  3843. var sphere = new THREE.Sphere();
  3844. return function ( object ) {
  3845. var geometry = object.geometry;
  3846. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  3847. sphere.copy( geometry.boundingSphere );
  3848. sphere.applyMatrix4( object.matrixWorld );
  3849. return this.intersectsSphere( sphere );
  3850. };
  3851. }(),
  3852. intersectsSphere: function ( sphere ) {
  3853. var planes = this.planes;
  3854. var center = sphere.center;
  3855. var negRadius = - sphere.radius;
  3856. for ( var i = 0; i < 6; i ++ ) {
  3857. var distance = planes[ i ].distanceToPoint( center );
  3858. if ( distance < negRadius ) {
  3859. return false;
  3860. }
  3861. }
  3862. return true;
  3863. },
  3864. intersectsBox: function () {
  3865. var p1 = new THREE.Vector3(),
  3866. p2 = new THREE.Vector3();
  3867. return function ( box ) {
  3868. var planes = this.planes;
  3869. for ( var i = 0; i < 6 ; i ++ ) {
  3870. var plane = planes[ i ];
  3871. p1.x = plane.normal.x > 0 ? box.min.x : box.max.x;
  3872. p2.x = plane.normal.x > 0 ? box.max.x : box.min.x;
  3873. p1.y = plane.normal.y > 0 ? box.min.y : box.max.y;
  3874. p2.y = plane.normal.y > 0 ? box.max.y : box.min.y;
  3875. p1.z = plane.normal.z > 0 ? box.min.z : box.max.z;
  3876. p2.z = plane.normal.z > 0 ? box.max.z : box.min.z;
  3877. var d1 = plane.distanceToPoint( p1 );
  3878. var d2 = plane.distanceToPoint( p2 );
  3879. // if both outside plane, no intersection
  3880. if ( d1 < 0 && d2 < 0 ) {
  3881. return false;
  3882. }
  3883. }
  3884. return true;
  3885. };
  3886. }(),
  3887. containsPoint: function ( point ) {
  3888. var planes = this.planes;
  3889. for ( var i = 0; i < 6; i ++ ) {
  3890. if ( planes[ i ].distanceToPoint( point ) < 0 ) {
  3891. return false;
  3892. }
  3893. }
  3894. return true;
  3895. }
  3896. };
  3897. // File:src/math/Plane.js
  3898. /**
  3899. * @author bhouston / http://clara.io
  3900. */
  3901. THREE.Plane = function ( normal, constant ) {
  3902. this.normal = ( normal !== undefined ) ? normal : new THREE.Vector3( 1, 0, 0 );
  3903. this.constant = ( constant !== undefined ) ? constant : 0;
  3904. };
  3905. THREE.Plane.prototype = {
  3906. constructor: THREE.Plane,
  3907. set: function ( normal, constant ) {
  3908. this.normal.copy( normal );
  3909. this.constant = constant;
  3910. return this;
  3911. },
  3912. setComponents: function ( x, y, z, w ) {
  3913. this.normal.set( x, y, z );
  3914. this.constant = w;
  3915. return this;
  3916. },
  3917. setFromNormalAndCoplanarPoint: function ( normal, point ) {
  3918. this.normal.copy( normal );
  3919. this.constant = - point.dot( this.normal ); // must be this.normal, not normal, as this.normal is normalized
  3920. return this;
  3921. },
  3922. setFromCoplanarPoints: function () {
  3923. var v1 = new THREE.Vector3();
  3924. var v2 = new THREE.Vector3();
  3925. return function ( a, b, c ) {
  3926. var normal = v1.subVectors( c, b ).cross( v2.subVectors( a, b ) ).normalize();
  3927. // Q: should an error be thrown if normal is zero (e.g. degenerate plane)?
  3928. this.setFromNormalAndCoplanarPoint( normal, a );
  3929. return this;
  3930. };
  3931. }(),
  3932. clone: function () {
  3933. return new this.constructor().copy( this );
  3934. },
  3935. copy: function ( plane ) {
  3936. this.normal.copy( plane.normal );
  3937. this.constant = plane.constant;
  3938. return this;
  3939. },
  3940. normalize: function () {
  3941. // Note: will lead to a divide by zero if the plane is invalid.
  3942. var inverseNormalLength = 1.0 / this.normal.length();
  3943. this.normal.multiplyScalar( inverseNormalLength );
  3944. this.constant *= inverseNormalLength;
  3945. return this;
  3946. },
  3947. negate: function () {
  3948. this.constant *= - 1;
  3949. this.normal.negate();
  3950. return this;
  3951. },
  3952. distanceToPoint: function ( point ) {
  3953. return this.normal.dot( point ) + this.constant;
  3954. },
  3955. distanceToSphere: function ( sphere ) {
  3956. return this.distanceToPoint( sphere.center ) - sphere.radius;
  3957. },
  3958. projectPoint: function ( point, optionalTarget ) {
  3959. return this.orthoPoint( point, optionalTarget ).sub( point ).negate();
  3960. },
  3961. orthoPoint: function ( point, optionalTarget ) {
  3962. var perpendicularMagnitude = this.distanceToPoint( point );
  3963. var result = optionalTarget || new THREE.Vector3();
  3964. return result.copy( this.normal ).multiplyScalar( perpendicularMagnitude );
  3965. },
  3966. intersectLine: function () {
  3967. var v1 = new THREE.Vector3();
  3968. return function ( line, optionalTarget ) {
  3969. var result = optionalTarget || new THREE.Vector3();
  3970. var direction = line.delta( v1 );
  3971. var denominator = this.normal.dot( direction );
  3972. if ( denominator === 0 ) {
  3973. // line is coplanar, return origin
  3974. if ( this.distanceToPoint( line.start ) === 0 ) {
  3975. return result.copy( line.start );
  3976. }
  3977. // Unsure if this is the correct method to handle this case.
  3978. return undefined;
  3979. }
  3980. var t = - ( line.start.dot( this.normal ) + this.constant ) / denominator;
  3981. if ( t < 0 || t > 1 ) {
  3982. return undefined;
  3983. }
  3984. return result.copy( direction ).multiplyScalar( t ).add( line.start );
  3985. };
  3986. }(),
  3987. intersectsLine: function ( line ) {
  3988. // Note: this tests if a line intersects the plane, not whether it (or its end-points) are coplanar with it.
  3989. var startSign = this.distanceToPoint( line.start );
  3990. var endSign = this.distanceToPoint( line.end );
  3991. return ( startSign < 0 && endSign > 0 ) || ( endSign < 0 && startSign > 0 );
  3992. },
  3993. intersectsBox: function ( box ) {
  3994. return box.intersectsPlane( this );
  3995. },
  3996. intersectsSphere: function ( sphere ) {
  3997. return sphere.intersectsPlane( this );
  3998. },
  3999. coplanarPoint: function ( optionalTarget ) {
  4000. var result = optionalTarget || new THREE.Vector3();
  4001. return result.copy( this.normal ).multiplyScalar( - this.constant );
  4002. },
  4003. applyMatrix4: function () {
  4004. var v1 = new THREE.Vector3();
  4005. var v2 = new THREE.Vector3();
  4006. var m1 = new THREE.Matrix3();
  4007. return function ( matrix, optionalNormalMatrix ) {
  4008. // compute new normal based on theory here:
  4009. // http://www.songho.ca/opengl/gl_normaltransform.html
  4010. var normalMatrix = optionalNormalMatrix || m1.getNormalMatrix( matrix );
  4011. var newNormal = v1.copy( this.normal ).applyMatrix3( normalMatrix );
  4012. var newCoplanarPoint = this.coplanarPoint( v2 );
  4013. newCoplanarPoint.applyMatrix4( matrix );
  4014. this.setFromNormalAndCoplanarPoint( newNormal, newCoplanarPoint );
  4015. return this;
  4016. };
  4017. }(),
  4018. translate: function ( offset ) {
  4019. this.constant = this.constant - offset.dot( this.normal );
  4020. return this;
  4021. },
  4022. equals: function ( plane ) {
  4023. return plane.normal.equals( this.normal ) && ( plane.constant === this.constant );
  4024. }
  4025. };
  4026. // File:src/math/Math.js
  4027. /**
  4028. * @author alteredq / http://alteredqualia.com/
  4029. * @author mrdoob / http://mrdoob.com/
  4030. */
  4031. THREE.Math = {
  4032. generateUUID: function () {
  4033. // http://www.broofa.com/Tools/Math.uuid.htm
  4034. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split( '' );
  4035. var uuid = new Array( 36 );
  4036. var rnd = 0, r;
  4037. return function () {
  4038. for ( var i = 0; i < 36; i ++ ) {
  4039. if ( i === 8 || i === 13 || i === 18 || i === 23 ) {
  4040. uuid[ i ] = '-';
  4041. } else if ( i === 14 ) {
  4042. uuid[ i ] = '4';
  4043. } else {
  4044. if ( rnd <= 0x02 ) rnd = 0x2000000 + ( Math.random() * 0x1000000 ) | 0;
  4045. r = rnd & 0xf;
  4046. rnd = rnd >> 4;
  4047. uuid[ i ] = chars[ ( i === 19 ) ? ( r & 0x3 ) | 0x8 : r ];
  4048. }
  4049. }
  4050. return uuid.join( '' );
  4051. };
  4052. }(),
  4053. clamp: function ( value, min, max ) {
  4054. return Math.max( min, Math.min( max, value ) );
  4055. },
  4056. // compute euclidian modulo of m % n
  4057. // https://en.wikipedia.org/wiki/Modulo_operation
  4058. euclideanModulo: function ( n, m ) {
  4059. return ( ( n % m ) + m ) % m;
  4060. },
  4061. // Linear mapping from range <a1, a2> to range <b1, b2>
  4062. mapLinear: function ( x, a1, a2, b1, b2 ) {
  4063. return b1 + ( x - a1 ) * ( b2 - b1 ) / ( a2 - a1 );
  4064. },
  4065. // http://en.wikipedia.org/wiki/Smoothstep
  4066. smoothstep: function ( x, min, max ) {
  4067. if ( x <= min ) return 0;
  4068. if ( x >= max ) return 1;
  4069. x = ( x - min ) / ( max - min );
  4070. return x * x * ( 3 - 2 * x );
  4071. },
  4072. smootherstep: function ( x, min, max ) {
  4073. if ( x <= min ) return 0;
  4074. if ( x >= max ) return 1;
  4075. x = ( x - min ) / ( max - min );
  4076. return x * x * x * ( x * ( x * 6 - 15 ) + 10 );
  4077. },
  4078. random16: function () {
  4079. console.warn( 'THREE.Math.random16() has been deprecated. Use Math.random() instead.' );
  4080. return Math.random();
  4081. },
  4082. // Random integer from <low, high> interval
  4083. randInt: function ( low, high ) {
  4084. return low + Math.floor( Math.random() * ( high - low + 1 ) );
  4085. },
  4086. // Random float from <low, high> interval
  4087. randFloat: function ( low, high ) {
  4088. return low + Math.random() * ( high - low );
  4089. },
  4090. // Random float from <-range/2, range/2> interval
  4091. randFloatSpread: function ( range ) {
  4092. return range * ( 0.5 - Math.random() );
  4093. },
  4094. degToRad: function () {
  4095. var degreeToRadiansFactor = Math.PI / 180;
  4096. return function ( degrees ) {
  4097. return degrees * degreeToRadiansFactor;
  4098. };
  4099. }(),
  4100. radToDeg: function () {
  4101. var radianToDegreesFactor = 180 / Math.PI;
  4102. return function ( radians ) {
  4103. return radians * radianToDegreesFactor;
  4104. };
  4105. }(),
  4106. isPowerOfTwo: function ( value ) {
  4107. return ( value & ( value - 1 ) ) === 0 && value !== 0;
  4108. },
  4109. nearestPowerOfTwo: function ( value ) {
  4110. return Math.pow( 2, Math.round( Math.log( value ) / Math.LN2 ) );
  4111. },
  4112. nextPowerOfTwo: function ( value ) {
  4113. value --;
  4114. value |= value >> 1;
  4115. value |= value >> 2;
  4116. value |= value >> 4;
  4117. value |= value >> 8;
  4118. value |= value >> 16;
  4119. value ++;
  4120. return value;
  4121. }
  4122. };
  4123. // File:src/math/Spline.js
  4124. /**
  4125. * Spline from Tween.js, slightly optimized (and trashed)
  4126. * http://sole.github.com/tween.js/examples/05_spline.html
  4127. *
  4128. * @author mrdoob / http://mrdoob.com/
  4129. * @author alteredq / http://alteredqualia.com/
  4130. */
  4131. THREE.Spline = function ( points ) {
  4132. this.points = points;
  4133. var c = [], v3 = { x: 0, y: 0, z: 0 },
  4134. point, intPoint, weight, w2, w3,
  4135. pa, pb, pc, pd;
  4136. this.initFromArray = function ( a ) {
  4137. this.points = [];
  4138. for ( var i = 0; i < a.length; i ++ ) {
  4139. this.points[ i ] = { x: a[ i ][ 0 ], y: a[ i ][ 1 ], z: a[ i ][ 2 ] };
  4140. }
  4141. };
  4142. this.getPoint = function ( k ) {
  4143. point = ( this.points.length - 1 ) * k;
  4144. intPoint = Math.floor( point );
  4145. weight = point - intPoint;
  4146. c[ 0 ] = intPoint === 0 ? intPoint : intPoint - 1;
  4147. c[ 1 ] = intPoint;
  4148. c[ 2 ] = intPoint > this.points.length - 2 ? this.points.length - 1 : intPoint + 1;
  4149. c[ 3 ] = intPoint > this.points.length - 3 ? this.points.length - 1 : intPoint + 2;
  4150. pa = this.points[ c[ 0 ] ];
  4151. pb = this.points[ c[ 1 ] ];
  4152. pc = this.points[ c[ 2 ] ];
  4153. pd = this.points[ c[ 3 ] ];
  4154. w2 = weight * weight;
  4155. w3 = weight * w2;
  4156. v3.x = interpolate( pa.x, pb.x, pc.x, pd.x, weight, w2, w3 );
  4157. v3.y = interpolate( pa.y, pb.y, pc.y, pd.y, weight, w2, w3 );
  4158. v3.z = interpolate( pa.z, pb.z, pc.z, pd.z, weight, w2, w3 );
  4159. return v3;
  4160. };
  4161. this.getControlPointsArray = function () {
  4162. var i, p, l = this.points.length,
  4163. coords = [];
  4164. for ( i = 0; i < l; i ++ ) {
  4165. p = this.points[ i ];
  4166. coords[ i ] = [ p.x, p.y, p.z ];
  4167. }
  4168. return coords;
  4169. };
  4170. // approximate length by summing linear segments
  4171. this.getLength = function ( nSubDivisions ) {
  4172. var i, index, nSamples, position,
  4173. point = 0, intPoint = 0, oldIntPoint = 0,
  4174. oldPosition = new THREE.Vector3(),
  4175. tmpVec = new THREE.Vector3(),
  4176. chunkLengths = [],
  4177. totalLength = 0;
  4178. // first point has 0 length
  4179. chunkLengths[ 0 ] = 0;
  4180. if ( ! nSubDivisions ) nSubDivisions = 100;
  4181. nSamples = this.points.length * nSubDivisions;
  4182. oldPosition.copy( this.points[ 0 ] );
  4183. for ( i = 1; i < nSamples; i ++ ) {
  4184. index = i / nSamples;
  4185. position = this.getPoint( index );
  4186. tmpVec.copy( position );
  4187. totalLength += tmpVec.distanceTo( oldPosition );
  4188. oldPosition.copy( position );
  4189. point = ( this.points.length - 1 ) * index;
  4190. intPoint = Math.floor( point );
  4191. if ( intPoint !== oldIntPoint ) {
  4192. chunkLengths[ intPoint ] = totalLength;
  4193. oldIntPoint = intPoint;
  4194. }
  4195. }
  4196. // last point ends with total length
  4197. chunkLengths[ chunkLengths.length ] = totalLength;
  4198. return { chunks: chunkLengths, total: totalLength };
  4199. };
  4200. this.reparametrizeByArcLength = function ( samplingCoef ) {
  4201. var i, j,
  4202. index, indexCurrent, indexNext,
  4203. realDistance,
  4204. sampling, position,
  4205. newpoints = [],
  4206. tmpVec = new THREE.Vector3(),
  4207. sl = this.getLength();
  4208. newpoints.push( tmpVec.copy( this.points[ 0 ] ).clone() );
  4209. for ( i = 1; i < this.points.length; i ++ ) {
  4210. //tmpVec.copy( this.points[ i - 1 ] );
  4211. //linearDistance = tmpVec.distanceTo( this.points[ i ] );
  4212. realDistance = sl.chunks[ i ] - sl.chunks[ i - 1 ];
  4213. sampling = Math.ceil( samplingCoef * realDistance / sl.total );
  4214. indexCurrent = ( i - 1 ) / ( this.points.length - 1 );
  4215. indexNext = i / ( this.points.length - 1 );
  4216. for ( j = 1; j < sampling - 1; j ++ ) {
  4217. index = indexCurrent + j * ( 1 / sampling ) * ( indexNext - indexCurrent );
  4218. position = this.getPoint( index );
  4219. newpoints.push( tmpVec.copy( position ).clone() );
  4220. }
  4221. newpoints.push( tmpVec.copy( this.points[ i ] ).clone() );
  4222. }
  4223. this.points = newpoints;
  4224. };
  4225. // Catmull-Rom
  4226. function interpolate( p0, p1, p2, p3, t, t2, t3 ) {
  4227. var v0 = ( p2 - p0 ) * 0.5,
  4228. v1 = ( p3 - p1 ) * 0.5;
  4229. return ( 2 * ( p1 - p2 ) + v0 + v1 ) * t3 + ( - 3 * ( p1 - p2 ) - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  4230. }
  4231. };
  4232. // File:src/math/Triangle.js
  4233. /**
  4234. * @author bhouston / http://clara.io
  4235. * @author mrdoob / http://mrdoob.com/
  4236. */
  4237. THREE.Triangle = function ( a, b, c ) {
  4238. this.a = ( a !== undefined ) ? a : new THREE.Vector3();
  4239. this.b = ( b !== undefined ) ? b : new THREE.Vector3();
  4240. this.c = ( c !== undefined ) ? c : new THREE.Vector3();
  4241. };
  4242. THREE.Triangle.normal = function () {
  4243. var v0 = new THREE.Vector3();
  4244. return function ( a, b, c, optionalTarget ) {
  4245. var result = optionalTarget || new THREE.Vector3();
  4246. result.subVectors( c, b );
  4247. v0.subVectors( a, b );
  4248. result.cross( v0 );
  4249. var resultLengthSq = result.lengthSq();
  4250. if ( resultLengthSq > 0 ) {
  4251. return result.multiplyScalar( 1 / Math.sqrt( resultLengthSq ) );
  4252. }
  4253. return result.set( 0, 0, 0 );
  4254. };
  4255. }();
  4256. // static/instance method to calculate barycentric coordinates
  4257. // based on: http://www.blackpawn.com/texts/pointinpoly/default.html
  4258. THREE.Triangle.barycoordFromPoint = function () {
  4259. var v0 = new THREE.Vector3();
  4260. var v1 = new THREE.Vector3();
  4261. var v2 = new THREE.Vector3();
  4262. return function ( point, a, b, c, optionalTarget ) {
  4263. v0.subVectors( c, a );
  4264. v1.subVectors( b, a );
  4265. v2.subVectors( point, a );
  4266. var dot00 = v0.dot( v0 );
  4267. var dot01 = v0.dot( v1 );
  4268. var dot02 = v0.dot( v2 );
  4269. var dot11 = v1.dot( v1 );
  4270. var dot12 = v1.dot( v2 );
  4271. var denom = ( dot00 * dot11 - dot01 * dot01 );
  4272. var result = optionalTarget || new THREE.Vector3();
  4273. // collinear or singular triangle
  4274. if ( denom === 0 ) {
  4275. // arbitrary location outside of triangle?
  4276. // not sure if this is the best idea, maybe should be returning undefined
  4277. return result.set( - 2, - 1, - 1 );
  4278. }
  4279. var invDenom = 1 / denom;
  4280. var u = ( dot11 * dot02 - dot01 * dot12 ) * invDenom;
  4281. var v = ( dot00 * dot12 - dot01 * dot02 ) * invDenom;
  4282. // barycentric coordinates must always sum to 1
  4283. return result.set( 1 - u - v, v, u );
  4284. };
  4285. }();
  4286. THREE.Triangle.containsPoint = function () {
  4287. var v1 = new THREE.Vector3();
  4288. return function ( point, a, b, c ) {
  4289. var result = THREE.Triangle.barycoordFromPoint( point, a, b, c, v1 );
  4290. return ( result.x >= 0 ) && ( result.y >= 0 ) && ( ( result.x + result.y ) <= 1 );
  4291. };
  4292. }();
  4293. THREE.Triangle.prototype = {
  4294. constructor: THREE.Triangle,
  4295. set: function ( a, b, c ) {
  4296. this.a.copy( a );
  4297. this.b.copy( b );
  4298. this.c.copy( c );
  4299. return this;
  4300. },
  4301. setFromPointsAndIndices: function ( points, i0, i1, i2 ) {
  4302. this.a.copy( points[ i0 ] );
  4303. this.b.copy( points[ i1 ] );
  4304. this.c.copy( points[ i2 ] );
  4305. return this;
  4306. },
  4307. clone: function () {
  4308. return new this.constructor().copy( this );
  4309. },
  4310. copy: function ( triangle ) {
  4311. this.a.copy( triangle.a );
  4312. this.b.copy( triangle.b );
  4313. this.c.copy( triangle.c );
  4314. return this;
  4315. },
  4316. area: function () {
  4317. var v0 = new THREE.Vector3();
  4318. var v1 = new THREE.Vector3();
  4319. return function () {
  4320. v0.subVectors( this.c, this.b );
  4321. v1.subVectors( this.a, this.b );
  4322. return v0.cross( v1 ).length() * 0.5;
  4323. };
  4324. }(),
  4325. midpoint: function ( optionalTarget ) {
  4326. var result = optionalTarget || new THREE.Vector3();
  4327. return result.addVectors( this.a, this.b ).add( this.c ).multiplyScalar( 1 / 3 );
  4328. },
  4329. normal: function ( optionalTarget ) {
  4330. return THREE.Triangle.normal( this.a, this.b, this.c, optionalTarget );
  4331. },
  4332. plane: function ( optionalTarget ) {
  4333. var result = optionalTarget || new THREE.Plane();
  4334. return result.setFromCoplanarPoints( this.a, this.b, this.c );
  4335. },
  4336. barycoordFromPoint: function ( point, optionalTarget ) {
  4337. return THREE.Triangle.barycoordFromPoint( point, this.a, this.b, this.c, optionalTarget );
  4338. },
  4339. containsPoint: function ( point ) {
  4340. return THREE.Triangle.containsPoint( point, this.a, this.b, this.c );
  4341. },
  4342. equals: function ( triangle ) {
  4343. return triangle.a.equals( this.a ) && triangle.b.equals( this.b ) && triangle.c.equals( this.c );
  4344. }
  4345. };
  4346. // File:src/math/Interpolant.js
  4347. /**
  4348. * Abstract base class of interpolants over parametric samples.
  4349. *
  4350. * The parameter domain is one dimensional, typically the time or a path
  4351. * along a curve defined by the data.
  4352. *
  4353. * The sample values can have any dimensionality and derived classes may
  4354. * apply special interpretations to the data.
  4355. *
  4356. * This class provides the interval seek in a Template Method, deferring
  4357. * the actual interpolation to derived classes.
  4358. *
  4359. * Time complexity is O(1) for linear access crossing at most two points
  4360. * and O(log N) for random access, where N is the number of positions.
  4361. *
  4362. * References:
  4363. *
  4364. * http://www.oodesign.com/template-method-pattern.html
  4365. *
  4366. * @author tschw
  4367. */
  4368. THREE.Interpolant = function(
  4369. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4370. this.parameterPositions = parameterPositions;
  4371. this._cachedIndex = 0;
  4372. this.resultBuffer = resultBuffer !== undefined ?
  4373. resultBuffer : new sampleValues.constructor( sampleSize );
  4374. this.sampleValues = sampleValues;
  4375. this.valueSize = sampleSize;
  4376. };
  4377. THREE.Interpolant.prototype = {
  4378. constructor: THREE.Interpolant,
  4379. evaluate: function( t ) {
  4380. var pp = this.parameterPositions,
  4381. i1 = this._cachedIndex,
  4382. t1 = pp[ i1 ],
  4383. t0 = pp[ i1 - 1 ];
  4384. validate_interval: {
  4385. seek: {
  4386. var right;
  4387. linear_scan: {
  4388. //- See http://jsperf.com/comparison-to-undefined/3
  4389. //- slower code:
  4390. //-
  4391. //- if ( t >= t1 || t1 === undefined ) {
  4392. forward_scan: if ( ! ( t < t1 ) ) {
  4393. for ( var giveUpAt = i1 + 2; ;) {
  4394. if ( t1 === undefined ) {
  4395. if ( t < t0 ) break forward_scan;
  4396. // after end
  4397. i1 = pp.length;
  4398. this._cachedIndex = i1;
  4399. return this.afterEnd_( i1 - 1, t, t0 );
  4400. }
  4401. if ( i1 === giveUpAt ) break; // this loop
  4402. t0 = t1;
  4403. t1 = pp[ ++ i1 ];
  4404. if ( t < t1 ) {
  4405. // we have arrived at the sought interval
  4406. break seek;
  4407. }
  4408. }
  4409. // prepare binary search on the right side of the index
  4410. right = pp.length;
  4411. break linear_scan;
  4412. }
  4413. //- slower code:
  4414. //- if ( t < t0 || t0 === undefined ) {
  4415. if ( ! ( t >= t0 ) ) {
  4416. // looping?
  4417. var t1global = pp[ 1 ];
  4418. if ( t < t1global ) {
  4419. i1 = 2; // + 1, using the scan for the details
  4420. t0 = t1global;
  4421. }
  4422. // linear reverse scan
  4423. for ( var giveUpAt = i1 - 2; ;) {
  4424. if ( t0 === undefined ) {
  4425. // before start
  4426. this._cachedIndex = 0;
  4427. return this.beforeStart_( 0, t, t1 );
  4428. }
  4429. if ( i1 === giveUpAt ) break; // this loop
  4430. t1 = t0;
  4431. t0 = pp[ -- i1 - 1 ];
  4432. if ( t >= t0 ) {
  4433. // we have arrived at the sought interval
  4434. break seek;
  4435. }
  4436. }
  4437. // prepare binary search on the left side of the index
  4438. right = i1;
  4439. i1 = 0;
  4440. break linear_scan;
  4441. }
  4442. // the interval is valid
  4443. break validate_interval;
  4444. } // linear scan
  4445. // binary search
  4446. while ( i1 < right ) {
  4447. var mid = ( i1 + right ) >>> 1;
  4448. if ( t < pp[ mid ] ) {
  4449. right = mid;
  4450. } else {
  4451. i1 = mid + 1;
  4452. }
  4453. }
  4454. t1 = pp[ i1 ];
  4455. t0 = pp[ i1 - 1 ];
  4456. // check boundary cases, again
  4457. if ( t0 === undefined ) {
  4458. this._cachedIndex = 0;
  4459. return this.beforeStart_( 0, t, t1 );
  4460. }
  4461. if ( t1 === undefined ) {
  4462. i1 = pp.length;
  4463. this._cachedIndex = i1;
  4464. return this.afterEnd_( i1 - 1, t0, t );
  4465. }
  4466. } // seek
  4467. this._cachedIndex = i1;
  4468. this.intervalChanged_( i1, t0, t1 );
  4469. } // validate_interval
  4470. return this.interpolate_( i1, t0, t, t1 );
  4471. },
  4472. settings: null, // optional, subclass-specific settings structure
  4473. // Note: The indirection allows central control of many interpolants.
  4474. // --- Protected interface
  4475. DefaultSettings_: {},
  4476. getSettings_: function() {
  4477. return this.settings || this.DefaultSettings_;
  4478. },
  4479. copySampleValue_: function( index ) {
  4480. // copies a sample value to the result buffer
  4481. var result = this.resultBuffer,
  4482. values = this.sampleValues,
  4483. stride = this.valueSize,
  4484. offset = index * stride;
  4485. for ( var i = 0; i !== stride; ++ i ) {
  4486. result[ i ] = values[ offset + i ];
  4487. }
  4488. return result;
  4489. },
  4490. // Template methods for derived classes:
  4491. interpolate_: function( i1, t0, t, t1 ) {
  4492. throw new Error( "call to abstract method" );
  4493. // implementations shall return this.resultBuffer
  4494. },
  4495. intervalChanged_: function( i1, t0, t1 ) {
  4496. // empty
  4497. }
  4498. };
  4499. Object.assign( THREE.Interpolant.prototype, {
  4500. beforeStart_: //( 0, t, t0 ), returns this.resultBuffer
  4501. THREE.Interpolant.prototype.copySampleValue_,
  4502. afterEnd_: //( N-1, tN-1, t ), returns this.resultBuffer
  4503. THREE.Interpolant.prototype.copySampleValue_
  4504. } );
  4505. // File:src/math/interpolants/CubicInterpolant.js
  4506. /**
  4507. * Fast and simple cubic spline interpolant.
  4508. *
  4509. * It was derived from a Hermitian construction setting the first derivative
  4510. * at each sample position to the linear slope between neighboring positions
  4511. * over their parameter interval.
  4512. *
  4513. * @author tschw
  4514. */
  4515. THREE.CubicInterpolant = function(
  4516. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4517. THREE.Interpolant.call(
  4518. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4519. this._weightPrev = -0;
  4520. this._offsetPrev = -0;
  4521. this._weightNext = -0;
  4522. this._offsetNext = -0;
  4523. };
  4524. THREE.CubicInterpolant.prototype =
  4525. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4526. constructor: THREE.CubicInterpolant,
  4527. DefaultSettings_: {
  4528. endingStart: THREE.ZeroCurvatureEnding,
  4529. endingEnd: THREE.ZeroCurvatureEnding
  4530. },
  4531. intervalChanged_: function( i1, t0, t1 ) {
  4532. var pp = this.parameterPositions,
  4533. iPrev = i1 - 2,
  4534. iNext = i1 + 1,
  4535. tPrev = pp[ iPrev ],
  4536. tNext = pp[ iNext ];
  4537. if ( tPrev === undefined ) {
  4538. switch ( this.getSettings_().endingStart ) {
  4539. case THREE.ZeroSlopeEnding:
  4540. // f'(t0) = 0
  4541. iPrev = i1;
  4542. tPrev = 2 * t0 - t1;
  4543. break;
  4544. case THREE.WrapAroundEnding:
  4545. // use the other end of the curve
  4546. iPrev = pp.length - 2;
  4547. tPrev = t0 + pp[ iPrev ] - pp[ iPrev + 1 ];
  4548. break;
  4549. default: // ZeroCurvatureEnding
  4550. // f''(t0) = 0 a.k.a. Natural Spline
  4551. iPrev = i1;
  4552. tPrev = t1;
  4553. }
  4554. }
  4555. if ( tNext === undefined ) {
  4556. switch ( this.getSettings_().endingEnd ) {
  4557. case THREE.ZeroSlopeEnding:
  4558. // f'(tN) = 0
  4559. iNext = i1;
  4560. tNext = 2 * t1 - t0;
  4561. break;
  4562. case THREE.WrapAroundEnding:
  4563. // use the other end of the curve
  4564. iNext = 1;
  4565. tNext = t1 + pp[ 1 ] - pp[ 0 ];
  4566. break;
  4567. default: // ZeroCurvatureEnding
  4568. // f''(tN) = 0, a.k.a. Natural Spline
  4569. iNext = i1 - 1;
  4570. tNext = t0;
  4571. }
  4572. }
  4573. var halfDt = ( t1 - t0 ) * 0.5,
  4574. stride = this.valueSize;
  4575. this._weightPrev = halfDt / ( t0 - tPrev );
  4576. this._weightNext = halfDt / ( tNext - t1 );
  4577. this._offsetPrev = iPrev * stride;
  4578. this._offsetNext = iNext * stride;
  4579. },
  4580. interpolate_: function( i1, t0, t, t1 ) {
  4581. var result = this.resultBuffer,
  4582. values = this.sampleValues,
  4583. stride = this.valueSize,
  4584. o1 = i1 * stride, o0 = o1 - stride,
  4585. oP = this._offsetPrev, oN = this._offsetNext,
  4586. wP = this._weightPrev, wN = this._weightNext,
  4587. p = ( t - t0 ) / ( t1 - t0 ),
  4588. pp = p * p,
  4589. ppp = pp * p;
  4590. // evaluate polynomials
  4591. var sP = - wP * ppp + 2 * wP * pp - wP * p;
  4592. var s0 = ( 1 + wP ) * ppp + (-1.5 - 2 * wP ) * pp + ( -0.5 + wP ) * p + 1;
  4593. var s1 = (-1 - wN ) * ppp + ( 1.5 + wN ) * pp + 0.5 * p;
  4594. var sN = wN * ppp - wN * pp;
  4595. // combine data linearly
  4596. for ( var i = 0; i !== stride; ++ i ) {
  4597. result[ i ] =
  4598. sP * values[ oP + i ] +
  4599. s0 * values[ o0 + i ] +
  4600. s1 * values[ o1 + i ] +
  4601. sN * values[ oN + i ];
  4602. }
  4603. return result;
  4604. }
  4605. } );
  4606. // File:src/math/interpolants/DiscreteInterpolant.js
  4607. /**
  4608. *
  4609. * Interpolant that evaluates to the sample value at the position preceeding
  4610. * the parameter.
  4611. *
  4612. * @author tschw
  4613. */
  4614. THREE.DiscreteInterpolant = function(
  4615. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4616. THREE.Interpolant.call(
  4617. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4618. };
  4619. THREE.DiscreteInterpolant.prototype =
  4620. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4621. constructor: THREE.DiscreteInterpolant,
  4622. interpolate_: function( i1, t0, t, t1 ) {
  4623. return this.copySampleValue_( i1 - 1 );
  4624. }
  4625. } );
  4626. // File:src/math/interpolants/LinearInterpolant.js
  4627. /**
  4628. * @author tschw
  4629. */
  4630. THREE.LinearInterpolant = function(
  4631. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4632. THREE.Interpolant.call(
  4633. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4634. };
  4635. THREE.LinearInterpolant.prototype =
  4636. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4637. constructor: THREE.LinearInterpolant,
  4638. interpolate_: function( i1, t0, t, t1 ) {
  4639. var result = this.resultBuffer,
  4640. values = this.sampleValues,
  4641. stride = this.valueSize,
  4642. offset1 = i1 * stride,
  4643. offset0 = offset1 - stride,
  4644. weight1 = ( t - t0 ) / ( t1 - t0 ),
  4645. weight0 = 1 - weight1;
  4646. for ( var i = 0; i !== stride; ++ i ) {
  4647. result[ i ] =
  4648. values[ offset0 + i ] * weight0 +
  4649. values[ offset1 + i ] * weight1;
  4650. }
  4651. return result;
  4652. }
  4653. } );
  4654. // File:src/math/interpolants/QuaternionLinearInterpolant.js
  4655. /**
  4656. * Spherical linear unit quaternion interpolant.
  4657. *
  4658. * @author tschw
  4659. */
  4660. THREE.QuaternionLinearInterpolant = function(
  4661. parameterPositions, sampleValues, sampleSize, resultBuffer ) {
  4662. THREE.Interpolant.call(
  4663. this, parameterPositions, sampleValues, sampleSize, resultBuffer );
  4664. };
  4665. THREE.QuaternionLinearInterpolant.prototype =
  4666. Object.assign( Object.create( THREE.Interpolant.prototype ), {
  4667. constructor: THREE.QuaternionLinearInterpolant,
  4668. interpolate_: function( i1, t0, t, t1 ) {
  4669. var result = this.resultBuffer,
  4670. values = this.sampleValues,
  4671. stride = this.valueSize,
  4672. offset = i1 * stride,
  4673. alpha = ( t - t0 ) / ( t1 - t0 );
  4674. for ( var end = offset + stride; offset !== end; offset += 4 ) {
  4675. THREE.Quaternion.slerpFlat( result, 0,
  4676. values, offset - stride, values, offset, alpha );
  4677. }
  4678. return result;
  4679. }
  4680. } );
  4681. // File:src/core/Clock.js
  4682. /**
  4683. * @author alteredq / http://alteredqualia.com/
  4684. */
  4685. THREE.Clock = function ( autoStart ) {
  4686. this.autoStart = ( autoStart !== undefined ) ? autoStart : true;
  4687. this.startTime = 0;
  4688. this.oldTime = 0;
  4689. this.elapsedTime = 0;
  4690. this.running = false;
  4691. };
  4692. THREE.Clock.prototype = {
  4693. constructor: THREE.Clock,
  4694. start: function () {
  4695. this.startTime = performance.now();
  4696. this.oldTime = this.startTime;
  4697. this.running = true;
  4698. },
  4699. stop: function () {
  4700. this.getElapsedTime();
  4701. this.running = false;
  4702. },
  4703. getElapsedTime: function () {
  4704. this.getDelta();
  4705. return this.elapsedTime;
  4706. },
  4707. getDelta: function () {
  4708. var diff = 0;
  4709. if ( this.autoStart && ! this.running ) {
  4710. this.start();
  4711. }
  4712. if ( this.running ) {
  4713. var newTime = performance.now();
  4714. diff = 0.001 * ( newTime - this.oldTime );
  4715. this.oldTime = newTime;
  4716. this.elapsedTime += diff;
  4717. }
  4718. return diff;
  4719. }
  4720. };
  4721. // File:src/core/EventDispatcher.js
  4722. /**
  4723. * https://github.com/mrdoob/eventdispatcher.js/
  4724. */
  4725. THREE.EventDispatcher = function () {};
  4726. THREE.EventDispatcher.prototype = {
  4727. constructor: THREE.EventDispatcher,
  4728. apply: function ( object ) {
  4729. object.addEventListener = THREE.EventDispatcher.prototype.addEventListener;
  4730. object.hasEventListener = THREE.EventDispatcher.prototype.hasEventListener;
  4731. object.removeEventListener = THREE.EventDispatcher.prototype.removeEventListener;
  4732. object.dispatchEvent = THREE.EventDispatcher.prototype.dispatchEvent;
  4733. },
  4734. addEventListener: function ( type, listener ) {
  4735. if ( this._listeners === undefined ) this._listeners = {};
  4736. var listeners = this._listeners;
  4737. if ( listeners[ type ] === undefined ) {
  4738. listeners[ type ] = [];
  4739. }
  4740. if ( listeners[ type ].indexOf( listener ) === - 1 ) {
  4741. listeners[ type ].push( listener );
  4742. }
  4743. },
  4744. hasEventListener: function ( type, listener ) {
  4745. if ( this._listeners === undefined ) return false;
  4746. var listeners = this._listeners;
  4747. if ( listeners[ type ] !== undefined && listeners[ type ].indexOf( listener ) !== - 1 ) {
  4748. return true;
  4749. }
  4750. return false;
  4751. },
  4752. removeEventListener: function ( type, listener ) {
  4753. if ( this._listeners === undefined ) return;
  4754. var listeners = this._listeners;
  4755. var listenerArray = listeners[ type ];
  4756. if ( listenerArray !== undefined ) {
  4757. var index = listenerArray.indexOf( listener );
  4758. if ( index !== - 1 ) {
  4759. listenerArray.splice( index, 1 );
  4760. }
  4761. }
  4762. },
  4763. dispatchEvent: function ( event ) {
  4764. if ( this._listeners === undefined ) return;
  4765. var listeners = this._listeners;
  4766. var listenerArray = listeners[ event.type ];
  4767. if ( listenerArray !== undefined ) {
  4768. event.target = this;
  4769. var array = [];
  4770. var length = listenerArray.length;
  4771. for ( var i = 0; i < length; i ++ ) {
  4772. array[ i ] = listenerArray[ i ];
  4773. }
  4774. for ( var i = 0; i < length; i ++ ) {
  4775. array[ i ].call( this, event );
  4776. }
  4777. }
  4778. }
  4779. };
  4780. // File:src/core/Layers.js
  4781. /**
  4782. * @author mrdoob / http://mrdoob.com/
  4783. */
  4784. THREE.Layers = function () {
  4785. this.mask = 1;
  4786. };
  4787. THREE.Layers.prototype = {
  4788. constructor: THREE.Layers,
  4789. set: function ( channel ) {
  4790. this.mask = 1 << channel;
  4791. },
  4792. enable: function ( channel ) {
  4793. this.mask |= 1 << channel;
  4794. },
  4795. toggle: function ( channel ) {
  4796. this.mask ^= 1 << channel;
  4797. },
  4798. disable: function ( channel ) {
  4799. this.mask &= ~ ( 1 << channel );
  4800. },
  4801. test: function ( layers ) {
  4802. return ( this.mask & layers.mask ) !== 0;
  4803. }
  4804. };
  4805. // File:src/core/Raycaster.js
  4806. /**
  4807. * @author mrdoob / http://mrdoob.com/
  4808. * @author bhouston / http://clara.io/
  4809. * @author stephomi / http://stephaneginier.com/
  4810. */
  4811. ( function ( THREE ) {
  4812. THREE.Raycaster = function ( origin, direction, near, far ) {
  4813. this.ray = new THREE.Ray( origin, direction );
  4814. // direction is assumed to be normalized (for accurate distance calculations)
  4815. this.near = near || 0;
  4816. this.far = far || Infinity;
  4817. this.params = {
  4818. Mesh: {},
  4819. Line: {},
  4820. LOD: {},
  4821. Points: { threshold: 1 },
  4822. Sprite: {}
  4823. };
  4824. Object.defineProperties( this.params, {
  4825. PointCloud: {
  4826. get: function () {
  4827. console.warn( 'THREE.Raycaster: params.PointCloud has been renamed to params.Points.' );
  4828. return this.Points;
  4829. }
  4830. }
  4831. } );
  4832. };
  4833. function ascSort( a, b ) {
  4834. return a.distance - b.distance;
  4835. }
  4836. function intersectObject( object, raycaster, intersects, recursive ) {
  4837. if ( object.visible === false ) return;
  4838. object.raycast( raycaster, intersects );
  4839. if ( recursive === true ) {
  4840. var children = object.children;
  4841. for ( var i = 0, l = children.length; i < l; i ++ ) {
  4842. intersectObject( children[ i ], raycaster, intersects, true );
  4843. }
  4844. }
  4845. }
  4846. //
  4847. THREE.Raycaster.prototype = {
  4848. constructor: THREE.Raycaster,
  4849. linePrecision: 1,
  4850. set: function ( origin, direction ) {
  4851. // direction is assumed to be normalized (for accurate distance calculations)
  4852. this.ray.set( origin, direction );
  4853. },
  4854. setFromCamera: function ( coords, camera ) {
  4855. if ( camera instanceof THREE.PerspectiveCamera ) {
  4856. this.ray.origin.setFromMatrixPosition( camera.matrixWorld );
  4857. this.ray.direction.set( coords.x, coords.y, 0.5 ).unproject( camera ).sub( this.ray.origin ).normalize();
  4858. } else if ( camera instanceof THREE.OrthographicCamera ) {
  4859. this.ray.origin.set( coords.x, coords.y, - 1 ).unproject( camera );
  4860. this.ray.direction.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld );
  4861. } else {
  4862. console.error( 'THREE.Raycaster: Unsupported camera type.' );
  4863. }
  4864. },
  4865. intersectObject: function ( object, recursive ) {
  4866. var intersects = [];
  4867. intersectObject( object, this, intersects, recursive );
  4868. intersects.sort( ascSort );
  4869. return intersects;
  4870. },
  4871. intersectObjects: function ( objects, recursive ) {
  4872. var intersects = [];
  4873. if ( Array.isArray( objects ) === false ) {
  4874. console.warn( 'THREE.Raycaster.intersectObjects: objects is not an Array.' );
  4875. return intersects;
  4876. }
  4877. for ( var i = 0, l = objects.length; i < l; i ++ ) {
  4878. intersectObject( objects[ i ], this, intersects, recursive );
  4879. }
  4880. intersects.sort( ascSort );
  4881. return intersects;
  4882. }
  4883. };
  4884. }( THREE ) );
  4885. // File:src/core/Object3D.js
  4886. /**
  4887. * @author mrdoob / http://mrdoob.com/
  4888. * @author mikael emtinger / http://gomo.se/
  4889. * @author alteredq / http://alteredqualia.com/
  4890. * @author WestLangley / http://github.com/WestLangley
  4891. * @author elephantatwork / www.elephantatwork.ch
  4892. */
  4893. THREE.Object3D = function () {
  4894. Object.defineProperty( this, 'id', { value: THREE.Object3DIdCount ++ } );
  4895. this.uuid = THREE.Math.generateUUID();
  4896. this.name = '';
  4897. this.type = 'Object3D';
  4898. this.parent = null;
  4899. this.children = [];
  4900. this.up = THREE.Object3D.DefaultUp.clone();
  4901. var position = new THREE.Vector3();
  4902. var rotation = new THREE.Euler();
  4903. var quaternion = new THREE.Quaternion();
  4904. var scale = new THREE.Vector3( 1, 1, 1 );
  4905. function onRotationChange() {
  4906. quaternion.setFromEuler( rotation, false );
  4907. }
  4908. function onQuaternionChange() {
  4909. rotation.setFromQuaternion( quaternion, undefined, false );
  4910. }
  4911. rotation.onChange( onRotationChange );
  4912. quaternion.onChange( onQuaternionChange );
  4913. Object.defineProperties( this, {
  4914. position: {
  4915. enumerable: true,
  4916. value: position
  4917. },
  4918. rotation: {
  4919. enumerable: true,
  4920. value: rotation
  4921. },
  4922. quaternion: {
  4923. enumerable: true,
  4924. value: quaternion
  4925. },
  4926. scale: {
  4927. enumerable: true,
  4928. value: scale
  4929. },
  4930. modelViewMatrix: {
  4931. value: new THREE.Matrix4()
  4932. },
  4933. normalMatrix: {
  4934. value: new THREE.Matrix3()
  4935. }
  4936. } );
  4937. this.rotationAutoUpdate = true;
  4938. this.matrix = new THREE.Matrix4();
  4939. this.matrixWorld = new THREE.Matrix4();
  4940. this.matrixAutoUpdate = THREE.Object3D.DefaultMatrixAutoUpdate;
  4941. this.matrixWorldNeedsUpdate = false;
  4942. this.layers = new THREE.Layers();
  4943. this.visible = true;
  4944. this.castShadow = false;
  4945. this.receiveShadow = false;
  4946. this.frustumCulled = true;
  4947. this.renderOrder = 0;
  4948. this.userData = {};
  4949. };
  4950. THREE.Object3D.DefaultUp = new THREE.Vector3( 0, 1, 0 );
  4951. THREE.Object3D.DefaultMatrixAutoUpdate = true;
  4952. THREE.Object3D.prototype = {
  4953. constructor: THREE.Object3D,
  4954. applyMatrix: function ( matrix ) {
  4955. this.matrix.multiplyMatrices( matrix, this.matrix );
  4956. this.matrix.decompose( this.position, this.quaternion, this.scale );
  4957. },
  4958. setRotationFromAxisAngle: function ( axis, angle ) {
  4959. // assumes axis is normalized
  4960. this.quaternion.setFromAxisAngle( axis, angle );
  4961. },
  4962. setRotationFromEuler: function ( euler ) {
  4963. this.quaternion.setFromEuler( euler, true );
  4964. },
  4965. setRotationFromMatrix: function ( m ) {
  4966. // assumes the upper 3x3 of m is a pure rotation matrix (i.e, unscaled)
  4967. this.quaternion.setFromRotationMatrix( m );
  4968. },
  4969. setRotationFromQuaternion: function ( q ) {
  4970. // assumes q is normalized
  4971. this.quaternion.copy( q );
  4972. },
  4973. rotateOnAxis: function () {
  4974. // rotate object on axis in object space
  4975. // axis is assumed to be normalized
  4976. var q1 = new THREE.Quaternion();
  4977. return function ( axis, angle ) {
  4978. q1.setFromAxisAngle( axis, angle );
  4979. this.quaternion.multiply( q1 );
  4980. return this;
  4981. };
  4982. }(),
  4983. rotateX: function () {
  4984. var v1 = new THREE.Vector3( 1, 0, 0 );
  4985. return function ( angle ) {
  4986. return this.rotateOnAxis( v1, angle );
  4987. };
  4988. }(),
  4989. rotateY: function () {
  4990. var v1 = new THREE.Vector3( 0, 1, 0 );
  4991. return function ( angle ) {
  4992. return this.rotateOnAxis( v1, angle );
  4993. };
  4994. }(),
  4995. rotateZ: function () {
  4996. var v1 = new THREE.Vector3( 0, 0, 1 );
  4997. return function ( angle ) {
  4998. return this.rotateOnAxis( v1, angle );
  4999. };
  5000. }(),
  5001. translateOnAxis: function () {
  5002. // translate object by distance along axis in object space
  5003. // axis is assumed to be normalized
  5004. var v1 = new THREE.Vector3();
  5005. return function ( axis, distance ) {
  5006. v1.copy( axis ).applyQuaternion( this.quaternion );
  5007. this.position.add( v1.multiplyScalar( distance ) );
  5008. return this;
  5009. };
  5010. }(),
  5011. translateX: function () {
  5012. var v1 = new THREE.Vector3( 1, 0, 0 );
  5013. return function ( distance ) {
  5014. return this.translateOnAxis( v1, distance );
  5015. };
  5016. }(),
  5017. translateY: function () {
  5018. var v1 = new THREE.Vector3( 0, 1, 0 );
  5019. return function ( distance ) {
  5020. return this.translateOnAxis( v1, distance );
  5021. };
  5022. }(),
  5023. translateZ: function () {
  5024. var v1 = new THREE.Vector3( 0, 0, 1 );
  5025. return function ( distance ) {
  5026. return this.translateOnAxis( v1, distance );
  5027. };
  5028. }(),
  5029. localToWorld: function ( vector ) {
  5030. return vector.applyMatrix4( this.matrixWorld );
  5031. },
  5032. worldToLocal: function () {
  5033. var m1 = new THREE.Matrix4();
  5034. return function ( vector ) {
  5035. return vector.applyMatrix4( m1.getInverse( this.matrixWorld ) );
  5036. };
  5037. }(),
  5038. lookAt: function () {
  5039. // This routine does not support objects with rotated and/or translated parent(s)
  5040. var m1 = new THREE.Matrix4();
  5041. return function ( vector ) {
  5042. m1.lookAt( vector, this.position, this.up );
  5043. this.quaternion.setFromRotationMatrix( m1 );
  5044. };
  5045. }(),
  5046. add: function ( object ) {
  5047. if ( arguments.length > 1 ) {
  5048. for ( var i = 0; i < arguments.length; i ++ ) {
  5049. this.add( arguments[ i ] );
  5050. }
  5051. return this;
  5052. }
  5053. if ( object === this ) {
  5054. console.error( "THREE.Object3D.add: object can't be added as a child of itself.", object );
  5055. return this;
  5056. }
  5057. if ( object instanceof THREE.Object3D ) {
  5058. if ( object.parent !== null ) {
  5059. object.parent.remove( object );
  5060. }
  5061. object.parent = this;
  5062. object.dispatchEvent( { type: 'added' } );
  5063. this.children.push( object );
  5064. } else {
  5065. console.error( "THREE.Object3D.add: object not an instance of THREE.Object3D.", object );
  5066. }
  5067. return this;
  5068. },
  5069. remove: function ( object ) {
  5070. if ( arguments.length > 1 ) {
  5071. for ( var i = 0; i < arguments.length; i ++ ) {
  5072. this.remove( arguments[ i ] );
  5073. }
  5074. }
  5075. var index = this.children.indexOf( object );
  5076. if ( index !== - 1 ) {
  5077. object.parent = null;
  5078. object.dispatchEvent( { type: 'removed' } );
  5079. this.children.splice( index, 1 );
  5080. }
  5081. },
  5082. getObjectById: function ( id ) {
  5083. return this.getObjectByProperty( 'id', id );
  5084. },
  5085. getObjectByName: function ( name ) {
  5086. return this.getObjectByProperty( 'name', name );
  5087. },
  5088. getObjectByProperty: function ( name, value ) {
  5089. if ( this[ name ] === value ) return this;
  5090. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5091. var child = this.children[ i ];
  5092. var object = child.getObjectByProperty( name, value );
  5093. if ( object !== undefined ) {
  5094. return object;
  5095. }
  5096. }
  5097. return undefined;
  5098. },
  5099. getWorldPosition: function ( optionalTarget ) {
  5100. var result = optionalTarget || new THREE.Vector3();
  5101. this.updateMatrixWorld( true );
  5102. return result.setFromMatrixPosition( this.matrixWorld );
  5103. },
  5104. getWorldQuaternion: function () {
  5105. var position = new THREE.Vector3();
  5106. var scale = new THREE.Vector3();
  5107. return function ( optionalTarget ) {
  5108. var result = optionalTarget || new THREE.Quaternion();
  5109. this.updateMatrixWorld( true );
  5110. this.matrixWorld.decompose( position, result, scale );
  5111. return result;
  5112. };
  5113. }(),
  5114. getWorldRotation: function () {
  5115. var quaternion = new THREE.Quaternion();
  5116. return function ( optionalTarget ) {
  5117. var result = optionalTarget || new THREE.Euler();
  5118. this.getWorldQuaternion( quaternion );
  5119. return result.setFromQuaternion( quaternion, this.rotation.order, false );
  5120. };
  5121. }(),
  5122. getWorldScale: function () {
  5123. var position = new THREE.Vector3();
  5124. var quaternion = new THREE.Quaternion();
  5125. return function ( optionalTarget ) {
  5126. var result = optionalTarget || new THREE.Vector3();
  5127. this.updateMatrixWorld( true );
  5128. this.matrixWorld.decompose( position, quaternion, result );
  5129. return result;
  5130. };
  5131. }(),
  5132. getWorldDirection: function () {
  5133. var quaternion = new THREE.Quaternion();
  5134. return function ( optionalTarget ) {
  5135. var result = optionalTarget || new THREE.Vector3();
  5136. this.getWorldQuaternion( quaternion );
  5137. return result.set( 0, 0, 1 ).applyQuaternion( quaternion );
  5138. };
  5139. }(),
  5140. raycast: function () {},
  5141. traverse: function ( callback ) {
  5142. callback( this );
  5143. var children = this.children;
  5144. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5145. children[ i ].traverse( callback );
  5146. }
  5147. },
  5148. traverseVisible: function ( callback ) {
  5149. if ( this.visible === false ) return;
  5150. callback( this );
  5151. var children = this.children;
  5152. for ( var i = 0, l = children.length; i < l; i ++ ) {
  5153. children[ i ].traverseVisible( callback );
  5154. }
  5155. },
  5156. traverseAncestors: function ( callback ) {
  5157. var parent = this.parent;
  5158. if ( parent !== null ) {
  5159. callback( parent );
  5160. parent.traverseAncestors( callback );
  5161. }
  5162. },
  5163. updateMatrix: function () {
  5164. this.matrix.compose( this.position, this.quaternion, this.scale );
  5165. this.matrixWorldNeedsUpdate = true;
  5166. },
  5167. updateMatrixWorld: function ( force ) {
  5168. if ( this.matrixAutoUpdate === true ) this.updateMatrix();
  5169. if ( this.matrixWorldNeedsUpdate === true || force === true ) {
  5170. if ( this.parent === null ) {
  5171. this.matrixWorld.copy( this.matrix );
  5172. } else {
  5173. this.matrixWorld.multiplyMatrices( this.parent.matrixWorld, this.matrix );
  5174. }
  5175. this.matrixWorldNeedsUpdate = false;
  5176. force = true;
  5177. }
  5178. // update children
  5179. for ( var i = 0, l = this.children.length; i < l; i ++ ) {
  5180. this.children[ i ].updateMatrixWorld( force );
  5181. }
  5182. },
  5183. toJSON: function ( meta ) {
  5184. var isRootObject = ( meta === undefined );
  5185. var output = {};
  5186. // meta is a hash used to collect geometries, materials.
  5187. // not providing it implies that this is the root object
  5188. // being serialized.
  5189. if ( isRootObject ) {
  5190. // initialize meta obj
  5191. meta = {
  5192. geometries: {},
  5193. materials: {},
  5194. textures: {},
  5195. images: {}
  5196. };
  5197. output.metadata = {
  5198. version: 4.4,
  5199. type: 'Object',
  5200. generator: 'Object3D.toJSON'
  5201. };
  5202. }
  5203. // standard Object3D serialization
  5204. var object = {};
  5205. object.uuid = this.uuid;
  5206. object.type = this.type;
  5207. if ( this.name !== '' ) object.name = this.name;
  5208. if ( JSON.stringify( this.userData ) !== '{}' ) object.userData = this.userData;
  5209. if ( this.castShadow === true ) object.castShadow = true;
  5210. if ( this.receiveShadow === true ) object.receiveShadow = true;
  5211. if ( this.visible === false ) object.visible = false;
  5212. object.matrix = this.matrix.toArray();
  5213. //
  5214. if ( this.geometry !== undefined ) {
  5215. if ( meta.geometries[ this.geometry.uuid ] === undefined ) {
  5216. meta.geometries[ this.geometry.uuid ] = this.geometry.toJSON( meta );
  5217. }
  5218. object.geometry = this.geometry.uuid;
  5219. }
  5220. if ( this.material !== undefined ) {
  5221. if ( meta.materials[ this.material.uuid ] === undefined ) {
  5222. meta.materials[ this.material.uuid ] = this.material.toJSON( meta );
  5223. }
  5224. object.material = this.material.uuid;
  5225. }
  5226. //
  5227. if ( this.children.length > 0 ) {
  5228. object.children = [];
  5229. for ( var i = 0; i < this.children.length; i ++ ) {
  5230. object.children.push( this.children[ i ].toJSON( meta ).object );
  5231. }
  5232. }
  5233. if ( isRootObject ) {
  5234. var geometries = extractFromCache( meta.geometries );
  5235. var materials = extractFromCache( meta.materials );
  5236. var textures = extractFromCache( meta.textures );
  5237. var images = extractFromCache( meta.images );
  5238. if ( geometries.length > 0 ) output.geometries = geometries;
  5239. if ( materials.length > 0 ) output.materials = materials;
  5240. if ( textures.length > 0 ) output.textures = textures;
  5241. if ( images.length > 0 ) output.images = images;
  5242. }
  5243. output.object = object;
  5244. return output;
  5245. // extract data from the cache hash
  5246. // remove metadata on each item
  5247. // and return as array
  5248. function extractFromCache ( cache ) {
  5249. var values = [];
  5250. for ( var key in cache ) {
  5251. var data = cache[ key ];
  5252. delete data.metadata;
  5253. values.push( data );
  5254. }
  5255. return values;
  5256. }
  5257. },
  5258. clone: function ( recursive ) {
  5259. return new this.constructor().copy( this, recursive );
  5260. },
  5261. copy: function ( source, recursive ) {
  5262. if ( recursive === undefined ) recursive = true;
  5263. this.name = source.name;
  5264. this.up.copy( source.up );
  5265. this.position.copy( source.position );
  5266. this.quaternion.copy( source.quaternion );
  5267. this.scale.copy( source.scale );
  5268. this.rotationAutoUpdate = source.rotationAutoUpdate;
  5269. this.matrix.copy( source.matrix );
  5270. this.matrixWorld.copy( source.matrixWorld );
  5271. this.matrixAutoUpdate = source.matrixAutoUpdate;
  5272. this.matrixWorldNeedsUpdate = source.matrixWorldNeedsUpdate;
  5273. this.visible = source.visible;
  5274. this.castShadow = source.castShadow;
  5275. this.receiveShadow = source.receiveShadow;
  5276. this.frustumCulled = source.frustumCulled;
  5277. this.renderOrder = source.renderOrder;
  5278. this.userData = JSON.parse( JSON.stringify( source.userData ) );
  5279. if ( recursive === true ) {
  5280. for ( var i = 0; i < source.children.length; i ++ ) {
  5281. var child = source.children[ i ];
  5282. this.add( child.clone() );
  5283. }
  5284. }
  5285. return this;
  5286. }
  5287. };
  5288. THREE.EventDispatcher.prototype.apply( THREE.Object3D.prototype );
  5289. THREE.Object3DIdCount = 0;
  5290. // File:src/core/Face3.js
  5291. /**
  5292. * @author mrdoob / http://mrdoob.com/
  5293. * @author alteredq / http://alteredqualia.com/
  5294. */
  5295. THREE.Face3 = function ( a, b, c, normal, color, materialIndex ) {
  5296. this.a = a;
  5297. this.b = b;
  5298. this.c = c;
  5299. this.normal = normal instanceof THREE.Vector3 ? normal : new THREE.Vector3();
  5300. this.vertexNormals = Array.isArray( normal ) ? normal : [];
  5301. this.color = color instanceof THREE.Color ? color : new THREE.Color();
  5302. this.vertexColors = Array.isArray( color ) ? color : [];
  5303. this.materialIndex = materialIndex !== undefined ? materialIndex : 0;
  5304. };
  5305. THREE.Face3.prototype = {
  5306. constructor: THREE.Face3,
  5307. clone: function () {
  5308. return new this.constructor().copy( this );
  5309. },
  5310. copy: function ( source ) {
  5311. this.a = source.a;
  5312. this.b = source.b;
  5313. this.c = source.c;
  5314. this.normal.copy( source.normal );
  5315. this.color.copy( source.color );
  5316. this.materialIndex = source.materialIndex;
  5317. for ( var i = 0, il = source.vertexNormals.length; i < il; i ++ ) {
  5318. this.vertexNormals[ i ] = source.vertexNormals[ i ].clone();
  5319. }
  5320. for ( var i = 0, il = source.vertexColors.length; i < il; i ++ ) {
  5321. this.vertexColors[ i ] = source.vertexColors[ i ].clone();
  5322. }
  5323. return this;
  5324. }
  5325. };
  5326. // File:src/core/BufferAttribute.js
  5327. /**
  5328. * @author mrdoob / http://mrdoob.com/
  5329. */
  5330. THREE.BufferAttribute = function ( array, itemSize ) {
  5331. this.uuid = THREE.Math.generateUUID();
  5332. this.array = array;
  5333. this.itemSize = itemSize;
  5334. this.dynamic = false;
  5335. this.updateRange = { offset: 0, count: - 1 };
  5336. this.version = 0;
  5337. };
  5338. THREE.BufferAttribute.prototype = {
  5339. constructor: THREE.BufferAttribute,
  5340. get count() {
  5341. return this.array.length / this.itemSize;
  5342. },
  5343. set needsUpdate( value ) {
  5344. if ( value === true ) this.version ++;
  5345. },
  5346. setDynamic: function ( value ) {
  5347. this.dynamic = value;
  5348. return this;
  5349. },
  5350. copy: function ( source ) {
  5351. this.array = new source.array.constructor( source.array );
  5352. this.itemSize = source.itemSize;
  5353. this.dynamic = source.dynamic;
  5354. return this;
  5355. },
  5356. copyAt: function ( index1, attribute, index2 ) {
  5357. index1 *= this.itemSize;
  5358. index2 *= attribute.itemSize;
  5359. for ( var i = 0, l = this.itemSize; i < l; i ++ ) {
  5360. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5361. }
  5362. return this;
  5363. },
  5364. copyArray: function ( array ) {
  5365. this.array.set( array );
  5366. return this;
  5367. },
  5368. copyColorsArray: function ( colors ) {
  5369. var array = this.array, offset = 0;
  5370. for ( var i = 0, l = colors.length; i < l; i ++ ) {
  5371. var color = colors[ i ];
  5372. if ( color === undefined ) {
  5373. console.warn( 'THREE.BufferAttribute.copyColorsArray(): color is undefined', i );
  5374. color = new THREE.Color();
  5375. }
  5376. array[ offset ++ ] = color.r;
  5377. array[ offset ++ ] = color.g;
  5378. array[ offset ++ ] = color.b;
  5379. }
  5380. return this;
  5381. },
  5382. copyIndicesArray: function ( indices ) {
  5383. var array = this.array, offset = 0;
  5384. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  5385. var index = indices[ i ];
  5386. array[ offset ++ ] = index.a;
  5387. array[ offset ++ ] = index.b;
  5388. array[ offset ++ ] = index.c;
  5389. }
  5390. return this;
  5391. },
  5392. copyVector2sArray: function ( vectors ) {
  5393. var array = this.array, offset = 0;
  5394. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5395. var vector = vectors[ i ];
  5396. if ( vector === undefined ) {
  5397. console.warn( 'THREE.BufferAttribute.copyVector2sArray(): vector is undefined', i );
  5398. vector = new THREE.Vector2();
  5399. }
  5400. array[ offset ++ ] = vector.x;
  5401. array[ offset ++ ] = vector.y;
  5402. }
  5403. return this;
  5404. },
  5405. copyVector3sArray: function ( vectors ) {
  5406. var array = this.array, offset = 0;
  5407. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5408. var vector = vectors[ i ];
  5409. if ( vector === undefined ) {
  5410. console.warn( 'THREE.BufferAttribute.copyVector3sArray(): vector is undefined', i );
  5411. vector = new THREE.Vector3();
  5412. }
  5413. array[ offset ++ ] = vector.x;
  5414. array[ offset ++ ] = vector.y;
  5415. array[ offset ++ ] = vector.z;
  5416. }
  5417. return this;
  5418. },
  5419. copyVector4sArray: function ( vectors ) {
  5420. var array = this.array, offset = 0;
  5421. for ( var i = 0, l = vectors.length; i < l; i ++ ) {
  5422. var vector = vectors[ i ];
  5423. if ( vector === undefined ) {
  5424. console.warn( 'THREE.BufferAttribute.copyVector4sArray(): vector is undefined', i );
  5425. vector = new THREE.Vector4();
  5426. }
  5427. array[ offset ++ ] = vector.x;
  5428. array[ offset ++ ] = vector.y;
  5429. array[ offset ++ ] = vector.z;
  5430. array[ offset ++ ] = vector.w;
  5431. }
  5432. return this;
  5433. },
  5434. set: function ( value, offset ) {
  5435. if ( offset === undefined ) offset = 0;
  5436. this.array.set( value, offset );
  5437. return this;
  5438. },
  5439. getX: function ( index ) {
  5440. return this.array[ index * this.itemSize ];
  5441. },
  5442. setX: function ( index, x ) {
  5443. this.array[ index * this.itemSize ] = x;
  5444. return this;
  5445. },
  5446. getY: function ( index ) {
  5447. return this.array[ index * this.itemSize + 1 ];
  5448. },
  5449. setY: function ( index, y ) {
  5450. this.array[ index * this.itemSize + 1 ] = y;
  5451. return this;
  5452. },
  5453. getZ: function ( index ) {
  5454. return this.array[ index * this.itemSize + 2 ];
  5455. },
  5456. setZ: function ( index, z ) {
  5457. this.array[ index * this.itemSize + 2 ] = z;
  5458. return this;
  5459. },
  5460. getW: function ( index ) {
  5461. return this.array[ index * this.itemSize + 3 ];
  5462. },
  5463. setW: function ( index, w ) {
  5464. this.array[ index * this.itemSize + 3 ] = w;
  5465. return this;
  5466. },
  5467. setXY: function ( index, x, y ) {
  5468. index *= this.itemSize;
  5469. this.array[ index + 0 ] = x;
  5470. this.array[ index + 1 ] = y;
  5471. return this;
  5472. },
  5473. setXYZ: function ( index, x, y, z ) {
  5474. index *= this.itemSize;
  5475. this.array[ index + 0 ] = x;
  5476. this.array[ index + 1 ] = y;
  5477. this.array[ index + 2 ] = z;
  5478. return this;
  5479. },
  5480. setXYZW: function ( index, x, y, z, w ) {
  5481. index *= this.itemSize;
  5482. this.array[ index + 0 ] = x;
  5483. this.array[ index + 1 ] = y;
  5484. this.array[ index + 2 ] = z;
  5485. this.array[ index + 3 ] = w;
  5486. return this;
  5487. },
  5488. clone: function () {
  5489. return new this.constructor().copy( this );
  5490. }
  5491. };
  5492. //
  5493. THREE.Int8Attribute = function ( array, itemSize ) {
  5494. return new THREE.BufferAttribute( new Int8Array( array ), itemSize );
  5495. };
  5496. THREE.Uint8Attribute = function ( array, itemSize ) {
  5497. return new THREE.BufferAttribute( new Uint8Array( array ), itemSize );
  5498. };
  5499. THREE.Uint8ClampedAttribute = function ( array, itemSize ) {
  5500. return new THREE.BufferAttribute( new Uint8ClampedArray( array ), itemSize );
  5501. };
  5502. THREE.Int16Attribute = function ( array, itemSize ) {
  5503. return new THREE.BufferAttribute( new Int16Array( array ), itemSize );
  5504. };
  5505. THREE.Uint16Attribute = function ( array, itemSize ) {
  5506. return new THREE.BufferAttribute( new Uint16Array( array ), itemSize );
  5507. };
  5508. THREE.Int32Attribute = function ( array, itemSize ) {
  5509. return new THREE.BufferAttribute( new Int32Array( array ), itemSize );
  5510. };
  5511. THREE.Uint32Attribute = function ( array, itemSize ) {
  5512. return new THREE.BufferAttribute( new Uint32Array( array ), itemSize );
  5513. };
  5514. THREE.Float32Attribute = function ( array, itemSize ) {
  5515. return new THREE.BufferAttribute( new Float32Array( array ), itemSize );
  5516. };
  5517. THREE.Float64Attribute = function ( array, itemSize ) {
  5518. return new THREE.BufferAttribute( new Float64Array( array ), itemSize );
  5519. };
  5520. // Deprecated
  5521. THREE.DynamicBufferAttribute = function ( array, itemSize ) {
  5522. console.warn( 'THREE.DynamicBufferAttribute has been removed. Use new THREE.BufferAttribute().setDynamic( true ) instead.' );
  5523. return new THREE.BufferAttribute( array, itemSize ).setDynamic( true );
  5524. };
  5525. // File:src/core/InstancedBufferAttribute.js
  5526. /**
  5527. * @author benaadams / https://twitter.com/ben_a_adams
  5528. */
  5529. THREE.InstancedBufferAttribute = function ( array, itemSize, meshPerAttribute ) {
  5530. THREE.BufferAttribute.call( this, array, itemSize );
  5531. this.meshPerAttribute = meshPerAttribute || 1;
  5532. };
  5533. THREE.InstancedBufferAttribute.prototype = Object.create( THREE.BufferAttribute.prototype );
  5534. THREE.InstancedBufferAttribute.prototype.constructor = THREE.InstancedBufferAttribute;
  5535. THREE.InstancedBufferAttribute.prototype.copy = function ( source ) {
  5536. THREE.BufferAttribute.prototype.copy.call( this, source );
  5537. this.meshPerAttribute = source.meshPerAttribute;
  5538. return this;
  5539. };
  5540. // File:src/core/InterleavedBuffer.js
  5541. /**
  5542. * @author benaadams / https://twitter.com/ben_a_adams
  5543. */
  5544. THREE.InterleavedBuffer = function ( array, stride ) {
  5545. this.uuid = THREE.Math.generateUUID();
  5546. this.array = array;
  5547. this.stride = stride;
  5548. this.dynamic = false;
  5549. this.updateRange = { offset: 0, count: - 1 };
  5550. this.version = 0;
  5551. };
  5552. THREE.InterleavedBuffer.prototype = {
  5553. constructor: THREE.InterleavedBuffer,
  5554. get length () {
  5555. return this.array.length;
  5556. },
  5557. get count () {
  5558. return this.array.length / this.stride;
  5559. },
  5560. set needsUpdate( value ) {
  5561. if ( value === true ) this.version ++;
  5562. },
  5563. setDynamic: function ( value ) {
  5564. this.dynamic = value;
  5565. return this;
  5566. },
  5567. copy: function ( source ) {
  5568. this.array = new source.array.constructor( source.array );
  5569. this.stride = source.stride;
  5570. this.dynamic = source.dynamic;
  5571. return this;
  5572. },
  5573. copyAt: function ( index1, attribute, index2 ) {
  5574. index1 *= this.stride;
  5575. index2 *= attribute.stride;
  5576. for ( var i = 0, l = this.stride; i < l; i ++ ) {
  5577. this.array[ index1 + i ] = attribute.array[ index2 + i ];
  5578. }
  5579. return this;
  5580. },
  5581. set: function ( value, offset ) {
  5582. if ( offset === undefined ) offset = 0;
  5583. this.array.set( value, offset );
  5584. return this;
  5585. },
  5586. clone: function () {
  5587. return new this.constructor().copy( this );
  5588. }
  5589. };
  5590. // File:src/core/InstancedInterleavedBuffer.js
  5591. /**
  5592. * @author benaadams / https://twitter.com/ben_a_adams
  5593. */
  5594. THREE.InstancedInterleavedBuffer = function ( array, stride, meshPerAttribute ) {
  5595. THREE.InterleavedBuffer.call( this, array, stride );
  5596. this.meshPerAttribute = meshPerAttribute || 1;
  5597. };
  5598. THREE.InstancedInterleavedBuffer.prototype = Object.create( THREE.InterleavedBuffer.prototype );
  5599. THREE.InstancedInterleavedBuffer.prototype.constructor = THREE.InstancedInterleavedBuffer;
  5600. THREE.InstancedInterleavedBuffer.prototype.copy = function ( source ) {
  5601. THREE.InterleavedBuffer.prototype.copy.call( this, source );
  5602. this.meshPerAttribute = source.meshPerAttribute;
  5603. return this;
  5604. };
  5605. // File:src/core/InterleavedBufferAttribute.js
  5606. /**
  5607. * @author benaadams / https://twitter.com/ben_a_adams
  5608. */
  5609. THREE.InterleavedBufferAttribute = function ( interleavedBuffer, itemSize, offset ) {
  5610. this.uuid = THREE.Math.generateUUID();
  5611. this.data = interleavedBuffer;
  5612. this.itemSize = itemSize;
  5613. this.offset = offset;
  5614. };
  5615. THREE.InterleavedBufferAttribute.prototype = {
  5616. constructor: THREE.InterleavedBufferAttribute,
  5617. get length() {
  5618. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  5619. return this.array.length;
  5620. },
  5621. get count() {
  5622. return this.data.count;
  5623. },
  5624. setX: function ( index, x ) {
  5625. this.data.array[ index * this.data.stride + this.offset ] = x;
  5626. return this;
  5627. },
  5628. setY: function ( index, y ) {
  5629. this.data.array[ index * this.data.stride + this.offset + 1 ] = y;
  5630. return this;
  5631. },
  5632. setZ: function ( index, z ) {
  5633. this.data.array[ index * this.data.stride + this.offset + 2 ] = z;
  5634. return this;
  5635. },
  5636. setW: function ( index, w ) {
  5637. this.data.array[ index * this.data.stride + this.offset + 3 ] = w;
  5638. return this;
  5639. },
  5640. getX: function ( index ) {
  5641. return this.data.array[ index * this.data.stride + this.offset ];
  5642. },
  5643. getY: function ( index ) {
  5644. return this.data.array[ index * this.data.stride + this.offset + 1 ];
  5645. },
  5646. getZ: function ( index ) {
  5647. return this.data.array[ index * this.data.stride + this.offset + 2 ];
  5648. },
  5649. getW: function ( index ) {
  5650. return this.data.array[ index * this.data.stride + this.offset + 3 ];
  5651. },
  5652. setXY: function ( index, x, y ) {
  5653. index = index * this.data.stride + this.offset;
  5654. this.data.array[ index + 0 ] = x;
  5655. this.data.array[ index + 1 ] = y;
  5656. return this;
  5657. },
  5658. setXYZ: function ( index, x, y, z ) {
  5659. index = index * this.data.stride + this.offset;
  5660. this.data.array[ index + 0 ] = x;
  5661. this.data.array[ index + 1 ] = y;
  5662. this.data.array[ index + 2 ] = z;
  5663. return this;
  5664. },
  5665. setXYZW: function ( index, x, y, z, w ) {
  5666. index = index * this.data.stride + this.offset;
  5667. this.data.array[ index + 0 ] = x;
  5668. this.data.array[ index + 1 ] = y;
  5669. this.data.array[ index + 2 ] = z;
  5670. this.data.array[ index + 3 ] = w;
  5671. return this;
  5672. }
  5673. };
  5674. // File:src/core/Geometry.js
  5675. /**
  5676. * @author mrdoob / http://mrdoob.com/
  5677. * @author kile / http://kile.stravaganza.org/
  5678. * @author alteredq / http://alteredqualia.com/
  5679. * @author mikael emtinger / http://gomo.se/
  5680. * @author zz85 / http://www.lab4games.net/zz85/blog
  5681. * @author bhouston / http://clara.io
  5682. */
  5683. THREE.Geometry = function () {
  5684. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  5685. this.uuid = THREE.Math.generateUUID();
  5686. this.name = '';
  5687. this.type = 'Geometry';
  5688. this.vertices = [];
  5689. this.colors = [];
  5690. this.faces = [];
  5691. this.faceVertexUvs = [ [] ];
  5692. this.morphTargets = [];
  5693. this.morphNormals = [];
  5694. this.skinWeights = [];
  5695. this.skinIndices = [];
  5696. this.lineDistances = [];
  5697. this.boundingBox = null;
  5698. this.boundingSphere = null;
  5699. // update flags
  5700. this.verticesNeedUpdate = false;
  5701. this.elementsNeedUpdate = false;
  5702. this.uvsNeedUpdate = false;
  5703. this.normalsNeedUpdate = false;
  5704. this.colorsNeedUpdate = false;
  5705. this.lineDistancesNeedUpdate = false;
  5706. this.groupsNeedUpdate = false;
  5707. };
  5708. THREE.Geometry.prototype = {
  5709. constructor: THREE.Geometry,
  5710. applyMatrix: function ( matrix ) {
  5711. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  5712. for ( var i = 0, il = this.vertices.length; i < il; i ++ ) {
  5713. var vertex = this.vertices[ i ];
  5714. vertex.applyMatrix4( matrix );
  5715. }
  5716. for ( var i = 0, il = this.faces.length; i < il; i ++ ) {
  5717. var face = this.faces[ i ];
  5718. face.normal.applyMatrix3( normalMatrix ).normalize();
  5719. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  5720. face.vertexNormals[ j ].applyMatrix3( normalMatrix ).normalize();
  5721. }
  5722. }
  5723. if ( this.boundingBox !== null ) {
  5724. this.computeBoundingBox();
  5725. }
  5726. if ( this.boundingSphere !== null ) {
  5727. this.computeBoundingSphere();
  5728. }
  5729. this.verticesNeedUpdate = true;
  5730. this.normalsNeedUpdate = true;
  5731. },
  5732. rotateX: function () {
  5733. // rotate geometry around world x-axis
  5734. var m1;
  5735. return function rotateX( angle ) {
  5736. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5737. m1.makeRotationX( angle );
  5738. this.applyMatrix( m1 );
  5739. return this;
  5740. };
  5741. }(),
  5742. rotateY: function () {
  5743. // rotate geometry around world y-axis
  5744. var m1;
  5745. return function rotateY( angle ) {
  5746. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5747. m1.makeRotationY( angle );
  5748. this.applyMatrix( m1 );
  5749. return this;
  5750. };
  5751. }(),
  5752. rotateZ: function () {
  5753. // rotate geometry around world z-axis
  5754. var m1;
  5755. return function rotateZ( angle ) {
  5756. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5757. m1.makeRotationZ( angle );
  5758. this.applyMatrix( m1 );
  5759. return this;
  5760. };
  5761. }(),
  5762. translate: function () {
  5763. // translate geometry
  5764. var m1;
  5765. return function translate( x, y, z ) {
  5766. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5767. m1.makeTranslation( x, y, z );
  5768. this.applyMatrix( m1 );
  5769. return this;
  5770. };
  5771. }(),
  5772. scale: function () {
  5773. // scale geometry
  5774. var m1;
  5775. return function scale( x, y, z ) {
  5776. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  5777. m1.makeScale( x, y, z );
  5778. this.applyMatrix( m1 );
  5779. return this;
  5780. };
  5781. }(),
  5782. lookAt: function () {
  5783. var obj;
  5784. return function lookAt( vector ) {
  5785. if ( obj === undefined ) obj = new THREE.Object3D();
  5786. obj.lookAt( vector );
  5787. obj.updateMatrix();
  5788. this.applyMatrix( obj.matrix );
  5789. };
  5790. }(),
  5791. fromBufferGeometry: function ( geometry ) {
  5792. var scope = this;
  5793. var indices = geometry.index !== null ? geometry.index.array : undefined;
  5794. var attributes = geometry.attributes;
  5795. var positions = attributes.position.array;
  5796. var normals = attributes.normal !== undefined ? attributes.normal.array : undefined;
  5797. var colors = attributes.color !== undefined ? attributes.color.array : undefined;
  5798. var uvs = attributes.uv !== undefined ? attributes.uv.array : undefined;
  5799. var uvs2 = attributes.uv2 !== undefined ? attributes.uv2.array : undefined;
  5800. if ( uvs2 !== undefined ) this.faceVertexUvs[ 1 ] = [];
  5801. var tempNormals = [];
  5802. var tempUVs = [];
  5803. var tempUVs2 = [];
  5804. for ( var i = 0, j = 0; i < positions.length; i += 3, j += 2 ) {
  5805. scope.vertices.push( new THREE.Vector3( positions[ i ], positions[ i + 1 ], positions[ i + 2 ] ) );
  5806. if ( normals !== undefined ) {
  5807. tempNormals.push( new THREE.Vector3( normals[ i ], normals[ i + 1 ], normals[ i + 2 ] ) );
  5808. }
  5809. if ( colors !== undefined ) {
  5810. scope.colors.push( new THREE.Color( colors[ i ], colors[ i + 1 ], colors[ i + 2 ] ) );
  5811. }
  5812. if ( uvs !== undefined ) {
  5813. tempUVs.push( new THREE.Vector2( uvs[ j ], uvs[ j + 1 ] ) );
  5814. }
  5815. if ( uvs2 !== undefined ) {
  5816. tempUVs2.push( new THREE.Vector2( uvs2[ j ], uvs2[ j + 1 ] ) );
  5817. }
  5818. }
  5819. function addFace( a, b, c ) {
  5820. var vertexNormals = normals !== undefined ? [ tempNormals[ a ].clone(), tempNormals[ b ].clone(), tempNormals[ c ].clone() ] : [];
  5821. var vertexColors = colors !== undefined ? [ scope.colors[ a ].clone(), scope.colors[ b ].clone(), scope.colors[ c ].clone() ] : [];
  5822. var face = new THREE.Face3( a, b, c, vertexNormals, vertexColors );
  5823. scope.faces.push( face );
  5824. if ( uvs !== undefined ) {
  5825. scope.faceVertexUvs[ 0 ].push( [ tempUVs[ a ].clone(), tempUVs[ b ].clone(), tempUVs[ c ].clone() ] );
  5826. }
  5827. if ( uvs2 !== undefined ) {
  5828. scope.faceVertexUvs[ 1 ].push( [ tempUVs2[ a ].clone(), tempUVs2[ b ].clone(), tempUVs2[ c ].clone() ] );
  5829. }
  5830. }
  5831. if ( indices !== undefined ) {
  5832. var groups = geometry.groups;
  5833. if ( groups.length > 0 ) {
  5834. for ( var i = 0; i < groups.length; i ++ ) {
  5835. var group = groups[ i ];
  5836. var start = group.start;
  5837. var count = group.count;
  5838. for ( var j = start, jl = start + count; j < jl; j += 3 ) {
  5839. addFace( indices[ j ], indices[ j + 1 ], indices[ j + 2 ] );
  5840. }
  5841. }
  5842. } else {
  5843. for ( var i = 0; i < indices.length; i += 3 ) {
  5844. addFace( indices[ i ], indices[ i + 1 ], indices[ i + 2 ] );
  5845. }
  5846. }
  5847. } else {
  5848. for ( var i = 0; i < positions.length / 3; i += 3 ) {
  5849. addFace( i, i + 1, i + 2 );
  5850. }
  5851. }
  5852. this.computeFaceNormals();
  5853. if ( geometry.boundingBox !== null ) {
  5854. this.boundingBox = geometry.boundingBox.clone();
  5855. }
  5856. if ( geometry.boundingSphere !== null ) {
  5857. this.boundingSphere = geometry.boundingSphere.clone();
  5858. }
  5859. return this;
  5860. },
  5861. center: function () {
  5862. this.computeBoundingBox();
  5863. var offset = this.boundingBox.center().negate();
  5864. this.translate( offset.x, offset.y, offset.z );
  5865. return offset;
  5866. },
  5867. normalize: function () {
  5868. this.computeBoundingSphere();
  5869. var center = this.boundingSphere.center;
  5870. var radius = this.boundingSphere.radius;
  5871. var s = radius === 0 ? 1 : 1.0 / radius;
  5872. var matrix = new THREE.Matrix4();
  5873. matrix.set(
  5874. s, 0, 0, - s * center.x,
  5875. 0, s, 0, - s * center.y,
  5876. 0, 0, s, - s * center.z,
  5877. 0, 0, 0, 1
  5878. );
  5879. this.applyMatrix( matrix );
  5880. return this;
  5881. },
  5882. computeFaceNormals: function () {
  5883. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5884. for ( var f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5885. var face = this.faces[ f ];
  5886. var vA = this.vertices[ face.a ];
  5887. var vB = this.vertices[ face.b ];
  5888. var vC = this.vertices[ face.c ];
  5889. cb.subVectors( vC, vB );
  5890. ab.subVectors( vA, vB );
  5891. cb.cross( ab );
  5892. cb.normalize();
  5893. face.normal.copy( cb );
  5894. }
  5895. },
  5896. computeVertexNormals: function ( areaWeighted ) {
  5897. if ( areaWeighted === undefined ) areaWeighted = true;
  5898. var v, vl, f, fl, face, vertices;
  5899. vertices = new Array( this.vertices.length );
  5900. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5901. vertices[ v ] = new THREE.Vector3();
  5902. }
  5903. if ( areaWeighted ) {
  5904. // vertex normals weighted by triangle areas
  5905. // http://www.iquilezles.org/www/articles/normals/normals.htm
  5906. var vA, vB, vC;
  5907. var cb = new THREE.Vector3(), ab = new THREE.Vector3();
  5908. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5909. face = this.faces[ f ];
  5910. vA = this.vertices[ face.a ];
  5911. vB = this.vertices[ face.b ];
  5912. vC = this.vertices[ face.c ];
  5913. cb.subVectors( vC, vB );
  5914. ab.subVectors( vA, vB );
  5915. cb.cross( ab );
  5916. vertices[ face.a ].add( cb );
  5917. vertices[ face.b ].add( cb );
  5918. vertices[ face.c ].add( cb );
  5919. }
  5920. } else {
  5921. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5922. face = this.faces[ f ];
  5923. vertices[ face.a ].add( face.normal );
  5924. vertices[ face.b ].add( face.normal );
  5925. vertices[ face.c ].add( face.normal );
  5926. }
  5927. }
  5928. for ( v = 0, vl = this.vertices.length; v < vl; v ++ ) {
  5929. vertices[ v ].normalize();
  5930. }
  5931. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5932. face = this.faces[ f ];
  5933. var vertexNormals = face.vertexNormals;
  5934. if ( vertexNormals.length === 3 ) {
  5935. vertexNormals[ 0 ].copy( vertices[ face.a ] );
  5936. vertexNormals[ 1 ].copy( vertices[ face.b ] );
  5937. vertexNormals[ 2 ].copy( vertices[ face.c ] );
  5938. } else {
  5939. vertexNormals[ 0 ] = vertices[ face.a ].clone();
  5940. vertexNormals[ 1 ] = vertices[ face.b ].clone();
  5941. vertexNormals[ 2 ] = vertices[ face.c ].clone();
  5942. }
  5943. }
  5944. if ( this.faces.length > 0 ) {
  5945. this.normalsNeedUpdate = true;
  5946. }
  5947. },
  5948. computeMorphNormals: function () {
  5949. var i, il, f, fl, face;
  5950. // save original normals
  5951. // - create temp variables on first access
  5952. // otherwise just copy (for faster repeated calls)
  5953. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5954. face = this.faces[ f ];
  5955. if ( ! face.__originalFaceNormal ) {
  5956. face.__originalFaceNormal = face.normal.clone();
  5957. } else {
  5958. face.__originalFaceNormal.copy( face.normal );
  5959. }
  5960. if ( ! face.__originalVertexNormals ) face.__originalVertexNormals = [];
  5961. for ( i = 0, il = face.vertexNormals.length; i < il; i ++ ) {
  5962. if ( ! face.__originalVertexNormals[ i ] ) {
  5963. face.__originalVertexNormals[ i ] = face.vertexNormals[ i ].clone();
  5964. } else {
  5965. face.__originalVertexNormals[ i ].copy( face.vertexNormals[ i ] );
  5966. }
  5967. }
  5968. }
  5969. // use temp geometry to compute face and vertex normals for each morph
  5970. var tmpGeo = new THREE.Geometry();
  5971. tmpGeo.faces = this.faces;
  5972. for ( i = 0, il = this.morphTargets.length; i < il; i ++ ) {
  5973. // create on first access
  5974. if ( ! this.morphNormals[ i ] ) {
  5975. this.morphNormals[ i ] = {};
  5976. this.morphNormals[ i ].faceNormals = [];
  5977. this.morphNormals[ i ].vertexNormals = [];
  5978. var dstNormalsFace = this.morphNormals[ i ].faceNormals;
  5979. var dstNormalsVertex = this.morphNormals[ i ].vertexNormals;
  5980. var faceNormal, vertexNormals;
  5981. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5982. faceNormal = new THREE.Vector3();
  5983. vertexNormals = { a: new THREE.Vector3(), b: new THREE.Vector3(), c: new THREE.Vector3() };
  5984. dstNormalsFace.push( faceNormal );
  5985. dstNormalsVertex.push( vertexNormals );
  5986. }
  5987. }
  5988. var morphNormals = this.morphNormals[ i ];
  5989. // set vertices to morph target
  5990. tmpGeo.vertices = this.morphTargets[ i ].vertices;
  5991. // compute morph normals
  5992. tmpGeo.computeFaceNormals();
  5993. tmpGeo.computeVertexNormals();
  5994. // store morph normals
  5995. var faceNormal, vertexNormals;
  5996. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  5997. face = this.faces[ f ];
  5998. faceNormal = morphNormals.faceNormals[ f ];
  5999. vertexNormals = morphNormals.vertexNormals[ f ];
  6000. faceNormal.copy( face.normal );
  6001. vertexNormals.a.copy( face.vertexNormals[ 0 ] );
  6002. vertexNormals.b.copy( face.vertexNormals[ 1 ] );
  6003. vertexNormals.c.copy( face.vertexNormals[ 2 ] );
  6004. }
  6005. }
  6006. // restore original normals
  6007. for ( f = 0, fl = this.faces.length; f < fl; f ++ ) {
  6008. face = this.faces[ f ];
  6009. face.normal = face.__originalFaceNormal;
  6010. face.vertexNormals = face.__originalVertexNormals;
  6011. }
  6012. },
  6013. computeTangents: function () {
  6014. console.warn( 'THREE.Geometry: .computeTangents() has been removed.' );
  6015. },
  6016. computeLineDistances: function () {
  6017. var d = 0;
  6018. var vertices = this.vertices;
  6019. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6020. if ( i > 0 ) {
  6021. d += vertices[ i ].distanceTo( vertices[ i - 1 ] );
  6022. }
  6023. this.lineDistances[ i ] = d;
  6024. }
  6025. },
  6026. computeBoundingBox: function () {
  6027. if ( this.boundingBox === null ) {
  6028. this.boundingBox = new THREE.Box3();
  6029. }
  6030. this.boundingBox.setFromPoints( this.vertices );
  6031. },
  6032. computeBoundingSphere: function () {
  6033. if ( this.boundingSphere === null ) {
  6034. this.boundingSphere = new THREE.Sphere();
  6035. }
  6036. this.boundingSphere.setFromPoints( this.vertices );
  6037. },
  6038. merge: function ( geometry, matrix, materialIndexOffset ) {
  6039. if ( geometry instanceof THREE.Geometry === false ) {
  6040. console.error( 'THREE.Geometry.merge(): geometry not an instance of THREE.Geometry.', geometry );
  6041. return;
  6042. }
  6043. var normalMatrix,
  6044. vertexOffset = this.vertices.length,
  6045. vertices1 = this.vertices,
  6046. vertices2 = geometry.vertices,
  6047. faces1 = this.faces,
  6048. faces2 = geometry.faces,
  6049. uvs1 = this.faceVertexUvs[ 0 ],
  6050. uvs2 = geometry.faceVertexUvs[ 0 ];
  6051. if ( materialIndexOffset === undefined ) materialIndexOffset = 0;
  6052. if ( matrix !== undefined ) {
  6053. normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6054. }
  6055. // vertices
  6056. for ( var i = 0, il = vertices2.length; i < il; i ++ ) {
  6057. var vertex = vertices2[ i ];
  6058. var vertexCopy = vertex.clone();
  6059. if ( matrix !== undefined ) vertexCopy.applyMatrix4( matrix );
  6060. vertices1.push( vertexCopy );
  6061. }
  6062. // faces
  6063. for ( i = 0, il = faces2.length; i < il; i ++ ) {
  6064. var face = faces2[ i ], faceCopy, normal, color,
  6065. faceVertexNormals = face.vertexNormals,
  6066. faceVertexColors = face.vertexColors;
  6067. faceCopy = new THREE.Face3( face.a + vertexOffset, face.b + vertexOffset, face.c + vertexOffset );
  6068. faceCopy.normal.copy( face.normal );
  6069. if ( normalMatrix !== undefined ) {
  6070. faceCopy.normal.applyMatrix3( normalMatrix ).normalize();
  6071. }
  6072. for ( var j = 0, jl = faceVertexNormals.length; j < jl; j ++ ) {
  6073. normal = faceVertexNormals[ j ].clone();
  6074. if ( normalMatrix !== undefined ) {
  6075. normal.applyMatrix3( normalMatrix ).normalize();
  6076. }
  6077. faceCopy.vertexNormals.push( normal );
  6078. }
  6079. faceCopy.color.copy( face.color );
  6080. for ( var j = 0, jl = faceVertexColors.length; j < jl; j ++ ) {
  6081. color = faceVertexColors[ j ];
  6082. faceCopy.vertexColors.push( color.clone() );
  6083. }
  6084. faceCopy.materialIndex = face.materialIndex + materialIndexOffset;
  6085. faces1.push( faceCopy );
  6086. }
  6087. // uvs
  6088. for ( i = 0, il = uvs2.length; i < il; i ++ ) {
  6089. var uv = uvs2[ i ], uvCopy = [];
  6090. if ( uv === undefined ) {
  6091. continue;
  6092. }
  6093. for ( var j = 0, jl = uv.length; j < jl; j ++ ) {
  6094. uvCopy.push( uv[ j ].clone() );
  6095. }
  6096. uvs1.push( uvCopy );
  6097. }
  6098. },
  6099. mergeMesh: function ( mesh ) {
  6100. if ( mesh instanceof THREE.Mesh === false ) {
  6101. console.error( 'THREE.Geometry.mergeMesh(): mesh not an instance of THREE.Mesh.', mesh );
  6102. return;
  6103. }
  6104. mesh.matrixAutoUpdate && mesh.updateMatrix();
  6105. this.merge( mesh.geometry, mesh.matrix );
  6106. },
  6107. /*
  6108. * Checks for duplicate vertices with hashmap.
  6109. * Duplicated vertices are removed
  6110. * and faces' vertices are updated.
  6111. */
  6112. mergeVertices: function () {
  6113. var verticesMap = {}; // Hashmap for looking up vertices by position coordinates (and making sure they are unique)
  6114. var unique = [], changes = [];
  6115. var v, key;
  6116. var precisionPoints = 4; // number of decimal points, e.g. 4 for epsilon of 0.0001
  6117. var precision = Math.pow( 10, precisionPoints );
  6118. var i, il, face;
  6119. var indices, j, jl;
  6120. for ( i = 0, il = this.vertices.length; i < il; i ++ ) {
  6121. v = this.vertices[ i ];
  6122. key = Math.round( v.x * precision ) + '_' + Math.round( v.y * precision ) + '_' + Math.round( v.z * precision );
  6123. if ( verticesMap[ key ] === undefined ) {
  6124. verticesMap[ key ] = i;
  6125. unique.push( this.vertices[ i ] );
  6126. changes[ i ] = unique.length - 1;
  6127. } else {
  6128. //console.log('Duplicate vertex found. ', i, ' could be using ', verticesMap[key]);
  6129. changes[ i ] = changes[ verticesMap[ key ] ];
  6130. }
  6131. }
  6132. // if faces are completely degenerate after merging vertices, we
  6133. // have to remove them from the geometry.
  6134. var faceIndicesToRemove = [];
  6135. for ( i = 0, il = this.faces.length; i < il; i ++ ) {
  6136. face = this.faces[ i ];
  6137. face.a = changes[ face.a ];
  6138. face.b = changes[ face.b ];
  6139. face.c = changes[ face.c ];
  6140. indices = [ face.a, face.b, face.c ];
  6141. var dupIndex = - 1;
  6142. // if any duplicate vertices are found in a Face3
  6143. // we have to remove the face as nothing can be saved
  6144. for ( var n = 0; n < 3; n ++ ) {
  6145. if ( indices[ n ] === indices[ ( n + 1 ) % 3 ] ) {
  6146. dupIndex = n;
  6147. faceIndicesToRemove.push( i );
  6148. break;
  6149. }
  6150. }
  6151. }
  6152. for ( i = faceIndicesToRemove.length - 1; i >= 0; i -- ) {
  6153. var idx = faceIndicesToRemove[ i ];
  6154. this.faces.splice( idx, 1 );
  6155. for ( j = 0, jl = this.faceVertexUvs.length; j < jl; j ++ ) {
  6156. this.faceVertexUvs[ j ].splice( idx, 1 );
  6157. }
  6158. }
  6159. // Use unique set of vertices
  6160. var diff = this.vertices.length - unique.length;
  6161. this.vertices = unique;
  6162. return diff;
  6163. },
  6164. sortFacesByMaterialIndex: function () {
  6165. var faces = this.faces;
  6166. var length = faces.length;
  6167. // tag faces
  6168. for ( var i = 0; i < length; i ++ ) {
  6169. faces[ i ]._id = i;
  6170. }
  6171. // sort faces
  6172. function materialIndexSort( a, b ) {
  6173. return a.materialIndex - b.materialIndex;
  6174. }
  6175. faces.sort( materialIndexSort );
  6176. // sort uvs
  6177. var uvs1 = this.faceVertexUvs[ 0 ];
  6178. var uvs2 = this.faceVertexUvs[ 1 ];
  6179. var newUvs1, newUvs2;
  6180. if ( uvs1 && uvs1.length === length ) newUvs1 = [];
  6181. if ( uvs2 && uvs2.length === length ) newUvs2 = [];
  6182. for ( var i = 0; i < length; i ++ ) {
  6183. var id = faces[ i ]._id;
  6184. if ( newUvs1 ) newUvs1.push( uvs1[ id ] );
  6185. if ( newUvs2 ) newUvs2.push( uvs2[ id ] );
  6186. }
  6187. if ( newUvs1 ) this.faceVertexUvs[ 0 ] = newUvs1;
  6188. if ( newUvs2 ) this.faceVertexUvs[ 1 ] = newUvs2;
  6189. },
  6190. toJSON: function () {
  6191. var data = {
  6192. metadata: {
  6193. version: 4.4,
  6194. type: 'Geometry',
  6195. generator: 'Geometry.toJSON'
  6196. }
  6197. };
  6198. // standard Geometry serialization
  6199. data.uuid = this.uuid;
  6200. data.type = this.type;
  6201. if ( this.name !== '' ) data.name = this.name;
  6202. if ( this.parameters !== undefined ) {
  6203. var parameters = this.parameters;
  6204. for ( var key in parameters ) {
  6205. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  6206. }
  6207. return data;
  6208. }
  6209. var vertices = [];
  6210. for ( var i = 0; i < this.vertices.length; i ++ ) {
  6211. var vertex = this.vertices[ i ];
  6212. vertices.push( vertex.x, vertex.y, vertex.z );
  6213. }
  6214. var faces = [];
  6215. var normals = [];
  6216. var normalsHash = {};
  6217. var colors = [];
  6218. var colorsHash = {};
  6219. var uvs = [];
  6220. var uvsHash = {};
  6221. for ( var i = 0; i < this.faces.length; i ++ ) {
  6222. var face = this.faces[ i ];
  6223. var hasMaterial = true;
  6224. var hasFaceUv = false; // deprecated
  6225. var hasFaceVertexUv = this.faceVertexUvs[ 0 ][ i ] !== undefined;
  6226. var hasFaceNormal = face.normal.length() > 0;
  6227. var hasFaceVertexNormal = face.vertexNormals.length > 0;
  6228. var hasFaceColor = face.color.r !== 1 || face.color.g !== 1 || face.color.b !== 1;
  6229. var hasFaceVertexColor = face.vertexColors.length > 0;
  6230. var faceType = 0;
  6231. faceType = setBit( faceType, 0, 0 ); // isQuad
  6232. faceType = setBit( faceType, 1, hasMaterial );
  6233. faceType = setBit( faceType, 2, hasFaceUv );
  6234. faceType = setBit( faceType, 3, hasFaceVertexUv );
  6235. faceType = setBit( faceType, 4, hasFaceNormal );
  6236. faceType = setBit( faceType, 5, hasFaceVertexNormal );
  6237. faceType = setBit( faceType, 6, hasFaceColor );
  6238. faceType = setBit( faceType, 7, hasFaceVertexColor );
  6239. faces.push( faceType );
  6240. faces.push( face.a, face.b, face.c );
  6241. faces.push( face.materialIndex );
  6242. if ( hasFaceVertexUv ) {
  6243. var faceVertexUvs = this.faceVertexUvs[ 0 ][ i ];
  6244. faces.push(
  6245. getUvIndex( faceVertexUvs[ 0 ] ),
  6246. getUvIndex( faceVertexUvs[ 1 ] ),
  6247. getUvIndex( faceVertexUvs[ 2 ] )
  6248. );
  6249. }
  6250. if ( hasFaceNormal ) {
  6251. faces.push( getNormalIndex( face.normal ) );
  6252. }
  6253. if ( hasFaceVertexNormal ) {
  6254. var vertexNormals = face.vertexNormals;
  6255. faces.push(
  6256. getNormalIndex( vertexNormals[ 0 ] ),
  6257. getNormalIndex( vertexNormals[ 1 ] ),
  6258. getNormalIndex( vertexNormals[ 2 ] )
  6259. );
  6260. }
  6261. if ( hasFaceColor ) {
  6262. faces.push( getColorIndex( face.color ) );
  6263. }
  6264. if ( hasFaceVertexColor ) {
  6265. var vertexColors = face.vertexColors;
  6266. faces.push(
  6267. getColorIndex( vertexColors[ 0 ] ),
  6268. getColorIndex( vertexColors[ 1 ] ),
  6269. getColorIndex( vertexColors[ 2 ] )
  6270. );
  6271. }
  6272. }
  6273. function setBit( value, position, enabled ) {
  6274. return enabled ? value | ( 1 << position ) : value & ( ~ ( 1 << position ) );
  6275. }
  6276. function getNormalIndex( normal ) {
  6277. var hash = normal.x.toString() + normal.y.toString() + normal.z.toString();
  6278. if ( normalsHash[ hash ] !== undefined ) {
  6279. return normalsHash[ hash ];
  6280. }
  6281. normalsHash[ hash ] = normals.length / 3;
  6282. normals.push( normal.x, normal.y, normal.z );
  6283. return normalsHash[ hash ];
  6284. }
  6285. function getColorIndex( color ) {
  6286. var hash = color.r.toString() + color.g.toString() + color.b.toString();
  6287. if ( colorsHash[ hash ] !== undefined ) {
  6288. return colorsHash[ hash ];
  6289. }
  6290. colorsHash[ hash ] = colors.length;
  6291. colors.push( color.getHex() );
  6292. return colorsHash[ hash ];
  6293. }
  6294. function getUvIndex( uv ) {
  6295. var hash = uv.x.toString() + uv.y.toString();
  6296. if ( uvsHash[ hash ] !== undefined ) {
  6297. return uvsHash[ hash ];
  6298. }
  6299. uvsHash[ hash ] = uvs.length / 2;
  6300. uvs.push( uv.x, uv.y );
  6301. return uvsHash[ hash ];
  6302. }
  6303. data.data = {};
  6304. data.data.vertices = vertices;
  6305. data.data.normals = normals;
  6306. if ( colors.length > 0 ) data.data.colors = colors;
  6307. if ( uvs.length > 0 ) data.data.uvs = [ uvs ]; // temporal backward compatibility
  6308. data.data.faces = faces;
  6309. return data;
  6310. },
  6311. clone: function () {
  6312. /*
  6313. // Handle primitives
  6314. var parameters = this.parameters;
  6315. if ( parameters !== undefined ) {
  6316. var values = [];
  6317. for ( var key in parameters ) {
  6318. values.push( parameters[ key ] );
  6319. }
  6320. var geometry = Object.create( this.constructor.prototype );
  6321. this.constructor.apply( geometry, values );
  6322. return geometry;
  6323. }
  6324. return new this.constructor().copy( this );
  6325. */
  6326. return new THREE.Geometry().copy( this );
  6327. },
  6328. copy: function ( source ) {
  6329. this.vertices = [];
  6330. this.faces = [];
  6331. this.faceVertexUvs = [ [] ];
  6332. var vertices = source.vertices;
  6333. for ( var i = 0, il = vertices.length; i < il; i ++ ) {
  6334. this.vertices.push( vertices[ i ].clone() );
  6335. }
  6336. var faces = source.faces;
  6337. for ( var i = 0, il = faces.length; i < il; i ++ ) {
  6338. this.faces.push( faces[ i ].clone() );
  6339. }
  6340. for ( var i = 0, il = source.faceVertexUvs.length; i < il; i ++ ) {
  6341. var faceVertexUvs = source.faceVertexUvs[ i ];
  6342. if ( this.faceVertexUvs[ i ] === undefined ) {
  6343. this.faceVertexUvs[ i ] = [];
  6344. }
  6345. for ( var j = 0, jl = faceVertexUvs.length; j < jl; j ++ ) {
  6346. var uvs = faceVertexUvs[ j ], uvsCopy = [];
  6347. for ( var k = 0, kl = uvs.length; k < kl; k ++ ) {
  6348. var uv = uvs[ k ];
  6349. uvsCopy.push( uv.clone() );
  6350. }
  6351. this.faceVertexUvs[ i ].push( uvsCopy );
  6352. }
  6353. }
  6354. return this;
  6355. },
  6356. dispose: function () {
  6357. this.dispatchEvent( { type: 'dispose' } );
  6358. }
  6359. };
  6360. THREE.EventDispatcher.prototype.apply( THREE.Geometry.prototype );
  6361. THREE.GeometryIdCount = 0;
  6362. // File:src/core/DirectGeometry.js
  6363. /**
  6364. * @author mrdoob / http://mrdoob.com/
  6365. */
  6366. THREE.DirectGeometry = function () {
  6367. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6368. this.uuid = THREE.Math.generateUUID();
  6369. this.name = '';
  6370. this.type = 'DirectGeometry';
  6371. this.indices = [];
  6372. this.vertices = [];
  6373. this.normals = [];
  6374. this.colors = [];
  6375. this.uvs = [];
  6376. this.uvs2 = [];
  6377. this.groups = [];
  6378. this.morphTargets = {};
  6379. this.skinWeights = [];
  6380. this.skinIndices = [];
  6381. // this.lineDistances = [];
  6382. this.boundingBox = null;
  6383. this.boundingSphere = null;
  6384. // update flags
  6385. this.verticesNeedUpdate = false;
  6386. this.normalsNeedUpdate = false;
  6387. this.colorsNeedUpdate = false;
  6388. this.uvsNeedUpdate = false;
  6389. this.groupsNeedUpdate = false;
  6390. };
  6391. THREE.DirectGeometry.prototype = {
  6392. constructor: THREE.DirectGeometry,
  6393. computeBoundingBox: THREE.Geometry.prototype.computeBoundingBox,
  6394. computeBoundingSphere: THREE.Geometry.prototype.computeBoundingSphere,
  6395. computeFaceNormals: function () {
  6396. console.warn( 'THREE.DirectGeometry: computeFaceNormals() is not a method of this type of geometry.' );
  6397. },
  6398. computeVertexNormals: function () {
  6399. console.warn( 'THREE.DirectGeometry: computeVertexNormals() is not a method of this type of geometry.' );
  6400. },
  6401. computeGroups: function ( geometry ) {
  6402. var group;
  6403. var groups = [];
  6404. var materialIndex;
  6405. var faces = geometry.faces;
  6406. for ( var i = 0; i < faces.length; i ++ ) {
  6407. var face = faces[ i ];
  6408. // materials
  6409. if ( face.materialIndex !== materialIndex ) {
  6410. materialIndex = face.materialIndex;
  6411. if ( group !== undefined ) {
  6412. group.count = ( i * 3 ) - group.start;
  6413. groups.push( group );
  6414. }
  6415. group = {
  6416. start: i * 3,
  6417. materialIndex: materialIndex
  6418. };
  6419. }
  6420. }
  6421. if ( group !== undefined ) {
  6422. group.count = ( i * 3 ) - group.start;
  6423. groups.push( group );
  6424. }
  6425. this.groups = groups;
  6426. },
  6427. fromGeometry: function ( geometry ) {
  6428. var faces = geometry.faces;
  6429. var vertices = geometry.vertices;
  6430. var faceVertexUvs = geometry.faceVertexUvs;
  6431. var hasFaceVertexUv = faceVertexUvs[ 0 ] && faceVertexUvs[ 0 ].length > 0;
  6432. var hasFaceVertexUv2 = faceVertexUvs[ 1 ] && faceVertexUvs[ 1 ].length > 0;
  6433. // morphs
  6434. var morphTargets = geometry.morphTargets;
  6435. var morphTargetsLength = morphTargets.length;
  6436. var morphTargetsPosition;
  6437. if ( morphTargetsLength > 0 ) {
  6438. morphTargetsPosition = [];
  6439. for ( var i = 0; i < morphTargetsLength; i ++ ) {
  6440. morphTargetsPosition[ i ] = [];
  6441. }
  6442. this.morphTargets.position = morphTargetsPosition;
  6443. }
  6444. var morphNormals = geometry.morphNormals;
  6445. var morphNormalsLength = morphNormals.length;
  6446. var morphTargetsNormal;
  6447. if ( morphNormalsLength > 0 ) {
  6448. morphTargetsNormal = [];
  6449. for ( var i = 0; i < morphNormalsLength; i ++ ) {
  6450. morphTargetsNormal[ i ] = [];
  6451. }
  6452. this.morphTargets.normal = morphTargetsNormal;
  6453. }
  6454. // skins
  6455. var skinIndices = geometry.skinIndices;
  6456. var skinWeights = geometry.skinWeights;
  6457. var hasSkinIndices = skinIndices.length === vertices.length;
  6458. var hasSkinWeights = skinWeights.length === vertices.length;
  6459. //
  6460. for ( var i = 0; i < faces.length; i ++ ) {
  6461. var face = faces[ i ];
  6462. this.vertices.push( vertices[ face.a ], vertices[ face.b ], vertices[ face.c ] );
  6463. var vertexNormals = face.vertexNormals;
  6464. if ( vertexNormals.length === 3 ) {
  6465. this.normals.push( vertexNormals[ 0 ], vertexNormals[ 1 ], vertexNormals[ 2 ] );
  6466. } else {
  6467. var normal = face.normal;
  6468. this.normals.push( normal, normal, normal );
  6469. }
  6470. var vertexColors = face.vertexColors;
  6471. if ( vertexColors.length === 3 ) {
  6472. this.colors.push( vertexColors[ 0 ], vertexColors[ 1 ], vertexColors[ 2 ] );
  6473. } else {
  6474. var color = face.color;
  6475. this.colors.push( color, color, color );
  6476. }
  6477. if ( hasFaceVertexUv === true ) {
  6478. var vertexUvs = faceVertexUvs[ 0 ][ i ];
  6479. if ( vertexUvs !== undefined ) {
  6480. this.uvs.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6481. } else {
  6482. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv ', i );
  6483. this.uvs.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6484. }
  6485. }
  6486. if ( hasFaceVertexUv2 === true ) {
  6487. var vertexUvs = faceVertexUvs[ 1 ][ i ];
  6488. if ( vertexUvs !== undefined ) {
  6489. this.uvs2.push( vertexUvs[ 0 ], vertexUvs[ 1 ], vertexUvs[ 2 ] );
  6490. } else {
  6491. console.warn( 'THREE.DirectGeometry.fromGeometry(): Undefined vertexUv2 ', i );
  6492. this.uvs2.push( new THREE.Vector2(), new THREE.Vector2(), new THREE.Vector2() );
  6493. }
  6494. }
  6495. // morphs
  6496. for ( var j = 0; j < morphTargetsLength; j ++ ) {
  6497. var morphTarget = morphTargets[ j ].vertices;
  6498. morphTargetsPosition[ j ].push( morphTarget[ face.a ], morphTarget[ face.b ], morphTarget[ face.c ] );
  6499. }
  6500. for ( var j = 0; j < morphNormalsLength; j ++ ) {
  6501. var morphNormal = morphNormals[ j ].vertexNormals[ i ];
  6502. morphTargetsNormal[ j ].push( morphNormal.a, morphNormal.b, morphNormal.c );
  6503. }
  6504. // skins
  6505. if ( hasSkinIndices ) {
  6506. this.skinIndices.push( skinIndices[ face.a ], skinIndices[ face.b ], skinIndices[ face.c ] );
  6507. }
  6508. if ( hasSkinWeights ) {
  6509. this.skinWeights.push( skinWeights[ face.a ], skinWeights[ face.b ], skinWeights[ face.c ] );
  6510. }
  6511. }
  6512. this.computeGroups( geometry );
  6513. this.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6514. this.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6515. this.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6516. this.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6517. this.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6518. return this;
  6519. },
  6520. dispose: function () {
  6521. this.dispatchEvent( { type: 'dispose' } );
  6522. }
  6523. };
  6524. THREE.EventDispatcher.prototype.apply( THREE.DirectGeometry.prototype );
  6525. // File:src/core/BufferGeometry.js
  6526. /**
  6527. * @author alteredq / http://alteredqualia.com/
  6528. * @author mrdoob / http://mrdoob.com/
  6529. */
  6530. THREE.BufferGeometry = function () {
  6531. Object.defineProperty( this, 'id', { value: THREE.GeometryIdCount ++ } );
  6532. this.uuid = THREE.Math.generateUUID();
  6533. this.name = '';
  6534. this.type = 'BufferGeometry';
  6535. this.index = null;
  6536. this.attributes = {};
  6537. this.morphAttributes = {};
  6538. this.groups = [];
  6539. this.boundingBox = null;
  6540. this.boundingSphere = null;
  6541. this.drawRange = { start: 0, count: Infinity };
  6542. };
  6543. THREE.BufferGeometry.prototype = {
  6544. constructor: THREE.BufferGeometry,
  6545. getIndex: function () {
  6546. return this.index;
  6547. },
  6548. setIndex: function ( index ) {
  6549. this.index = index;
  6550. },
  6551. addAttribute: function ( name, attribute ) {
  6552. if ( attribute instanceof THREE.BufferAttribute === false && attribute instanceof THREE.InterleavedBufferAttribute === false ) {
  6553. console.warn( 'THREE.BufferGeometry: .addAttribute() now expects ( name, attribute ).' );
  6554. this.addAttribute( name, new THREE.BufferAttribute( arguments[ 1 ], arguments[ 2 ] ) );
  6555. return;
  6556. }
  6557. if ( name === 'index' ) {
  6558. console.warn( 'THREE.BufferGeometry.addAttribute: Use .setIndex() for index attribute.' );
  6559. this.setIndex( attribute );
  6560. return;
  6561. }
  6562. this.attributes[ name ] = attribute;
  6563. return this;
  6564. },
  6565. getAttribute: function ( name ) {
  6566. return this.attributes[ name ];
  6567. },
  6568. removeAttribute: function ( name ) {
  6569. delete this.attributes[ name ];
  6570. return this;
  6571. },
  6572. addGroup: function ( start, count, materialIndex ) {
  6573. this.groups.push( {
  6574. start: start,
  6575. count: count,
  6576. materialIndex: materialIndex !== undefined ? materialIndex : 0
  6577. } );
  6578. },
  6579. clearGroups: function () {
  6580. this.groups = [];
  6581. },
  6582. setDrawRange: function ( start, count ) {
  6583. this.drawRange.start = start;
  6584. this.drawRange.count = count;
  6585. },
  6586. applyMatrix: function ( matrix ) {
  6587. var position = this.attributes.position;
  6588. if ( position !== undefined ) {
  6589. matrix.applyToVector3Array( position.array );
  6590. position.needsUpdate = true;
  6591. }
  6592. var normal = this.attributes.normal;
  6593. if ( normal !== undefined ) {
  6594. var normalMatrix = new THREE.Matrix3().getNormalMatrix( matrix );
  6595. normalMatrix.applyToVector3Array( normal.array );
  6596. normal.needsUpdate = true;
  6597. }
  6598. if ( this.boundingBox !== null ) {
  6599. this.computeBoundingBox();
  6600. }
  6601. if ( this.boundingSphere !== null ) {
  6602. this.computeBoundingSphere();
  6603. }
  6604. },
  6605. rotateX: function () {
  6606. // rotate geometry around world x-axis
  6607. var m1;
  6608. return function rotateX( angle ) {
  6609. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6610. m1.makeRotationX( angle );
  6611. this.applyMatrix( m1 );
  6612. return this;
  6613. };
  6614. }(),
  6615. rotateY: function () {
  6616. // rotate geometry around world y-axis
  6617. var m1;
  6618. return function rotateY( angle ) {
  6619. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6620. m1.makeRotationY( angle );
  6621. this.applyMatrix( m1 );
  6622. return this;
  6623. };
  6624. }(),
  6625. rotateZ: function () {
  6626. // rotate geometry around world z-axis
  6627. var m1;
  6628. return function rotateZ( angle ) {
  6629. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6630. m1.makeRotationZ( angle );
  6631. this.applyMatrix( m1 );
  6632. return this;
  6633. };
  6634. }(),
  6635. translate: function () {
  6636. // translate geometry
  6637. var m1;
  6638. return function translate( x, y, z ) {
  6639. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6640. m1.makeTranslation( x, y, z );
  6641. this.applyMatrix( m1 );
  6642. return this;
  6643. };
  6644. }(),
  6645. scale: function () {
  6646. // scale geometry
  6647. var m1;
  6648. return function scale( x, y, z ) {
  6649. if ( m1 === undefined ) m1 = new THREE.Matrix4();
  6650. m1.makeScale( x, y, z );
  6651. this.applyMatrix( m1 );
  6652. return this;
  6653. };
  6654. }(),
  6655. lookAt: function () {
  6656. var obj;
  6657. return function lookAt( vector ) {
  6658. if ( obj === undefined ) obj = new THREE.Object3D();
  6659. obj.lookAt( vector );
  6660. obj.updateMatrix();
  6661. this.applyMatrix( obj.matrix );
  6662. };
  6663. }(),
  6664. center: function () {
  6665. this.computeBoundingBox();
  6666. var offset = this.boundingBox.center().negate();
  6667. this.translate( offset.x, offset.y, offset.z );
  6668. return offset;
  6669. },
  6670. setFromObject: function ( object ) {
  6671. // console.log( 'THREE.BufferGeometry.setFromObject(). Converting', object, this );
  6672. var geometry = object.geometry;
  6673. if ( object instanceof THREE.Points || object instanceof THREE.Line ) {
  6674. var positions = new THREE.Float32Attribute( geometry.vertices.length * 3, 3 );
  6675. var colors = new THREE.Float32Attribute( geometry.colors.length * 3, 3 );
  6676. this.addAttribute( 'position', positions.copyVector3sArray( geometry.vertices ) );
  6677. this.addAttribute( 'color', colors.copyColorsArray( geometry.colors ) );
  6678. if ( geometry.lineDistances && geometry.lineDistances.length === geometry.vertices.length ) {
  6679. var lineDistances = new THREE.Float32Attribute( geometry.lineDistances.length, 1 );
  6680. this.addAttribute( 'lineDistance', lineDistances.copyArray( geometry.lineDistances ) );
  6681. }
  6682. if ( geometry.boundingSphere !== null ) {
  6683. this.boundingSphere = geometry.boundingSphere.clone();
  6684. }
  6685. if ( geometry.boundingBox !== null ) {
  6686. this.boundingBox = geometry.boundingBox.clone();
  6687. }
  6688. } else if ( object instanceof THREE.Mesh ) {
  6689. if ( geometry instanceof THREE.Geometry ) {
  6690. this.fromGeometry( geometry );
  6691. }
  6692. }
  6693. return this;
  6694. },
  6695. updateFromObject: function ( object ) {
  6696. var geometry = object.geometry;
  6697. if ( object instanceof THREE.Mesh ) {
  6698. var direct = geometry.__directGeometry;
  6699. if ( direct === undefined ) {
  6700. return this.fromGeometry( geometry );
  6701. }
  6702. direct.verticesNeedUpdate = geometry.verticesNeedUpdate;
  6703. direct.normalsNeedUpdate = geometry.normalsNeedUpdate;
  6704. direct.colorsNeedUpdate = geometry.colorsNeedUpdate;
  6705. direct.uvsNeedUpdate = geometry.uvsNeedUpdate;
  6706. direct.groupsNeedUpdate = geometry.groupsNeedUpdate;
  6707. geometry.verticesNeedUpdate = false;
  6708. geometry.normalsNeedUpdate = false;
  6709. geometry.colorsNeedUpdate = false;
  6710. geometry.uvsNeedUpdate = false;
  6711. geometry.groupsNeedUpdate = false;
  6712. geometry = direct;
  6713. }
  6714. if ( geometry.verticesNeedUpdate === true ) {
  6715. var attribute = this.attributes.position;
  6716. if ( attribute !== undefined ) {
  6717. attribute.copyVector3sArray( geometry.vertices );
  6718. attribute.needsUpdate = true;
  6719. }
  6720. geometry.verticesNeedUpdate = false;
  6721. }
  6722. if ( geometry.normalsNeedUpdate === true ) {
  6723. var attribute = this.attributes.normal;
  6724. if ( attribute !== undefined ) {
  6725. attribute.copyVector3sArray( geometry.normals );
  6726. attribute.needsUpdate = true;
  6727. }
  6728. geometry.normalsNeedUpdate = false;
  6729. }
  6730. if ( geometry.colorsNeedUpdate === true ) {
  6731. var attribute = this.attributes.color;
  6732. if ( attribute !== undefined ) {
  6733. attribute.copyColorsArray( geometry.colors );
  6734. attribute.needsUpdate = true;
  6735. }
  6736. geometry.colorsNeedUpdate = false;
  6737. }
  6738. if ( geometry.uvsNeedUpdate ) {
  6739. var attribute = this.attributes.uv;
  6740. if ( attribute !== undefined ) {
  6741. attribute.copyVector2sArray( geometry.uvs );
  6742. attribute.needsUpdate = true;
  6743. }
  6744. geometry.uvsNeedUpdate = false;
  6745. }
  6746. if ( geometry.lineDistancesNeedUpdate ) {
  6747. var attribute = this.attributes.lineDistance;
  6748. if ( attribute !== undefined ) {
  6749. attribute.copyArray( geometry.lineDistances );
  6750. attribute.needsUpdate = true;
  6751. }
  6752. geometry.lineDistancesNeedUpdate = false;
  6753. }
  6754. if ( geometry.groupsNeedUpdate ) {
  6755. geometry.computeGroups( object.geometry );
  6756. this.groups = geometry.groups;
  6757. geometry.groupsNeedUpdate = false;
  6758. }
  6759. return this;
  6760. },
  6761. fromGeometry: function ( geometry ) {
  6762. geometry.__directGeometry = new THREE.DirectGeometry().fromGeometry( geometry );
  6763. return this.fromDirectGeometry( geometry.__directGeometry );
  6764. },
  6765. fromDirectGeometry: function ( geometry ) {
  6766. var positions = new Float32Array( geometry.vertices.length * 3 );
  6767. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ).copyVector3sArray( geometry.vertices ) );
  6768. if ( geometry.normals.length > 0 ) {
  6769. var normals = new Float32Array( geometry.normals.length * 3 );
  6770. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ).copyVector3sArray( geometry.normals ) );
  6771. }
  6772. if ( geometry.colors.length > 0 ) {
  6773. var colors = new Float32Array( geometry.colors.length * 3 );
  6774. this.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ).copyColorsArray( geometry.colors ) );
  6775. }
  6776. if ( geometry.uvs.length > 0 ) {
  6777. var uvs = new Float32Array( geometry.uvs.length * 2 );
  6778. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ).copyVector2sArray( geometry.uvs ) );
  6779. }
  6780. if ( geometry.uvs2.length > 0 ) {
  6781. var uvs2 = new Float32Array( geometry.uvs2.length * 2 );
  6782. this.addAttribute( 'uv2', new THREE.BufferAttribute( uvs2, 2 ).copyVector2sArray( geometry.uvs2 ) );
  6783. }
  6784. if ( geometry.indices.length > 0 ) {
  6785. var TypeArray = geometry.vertices.length > 65535 ? Uint32Array : Uint16Array;
  6786. var indices = new TypeArray( geometry.indices.length * 3 );
  6787. this.setIndex( new THREE.BufferAttribute( indices, 1 ).copyIndicesArray( geometry.indices ) );
  6788. }
  6789. // groups
  6790. this.groups = geometry.groups;
  6791. // morphs
  6792. for ( var name in geometry.morphTargets ) {
  6793. var array = [];
  6794. var morphTargets = geometry.morphTargets[ name ];
  6795. for ( var i = 0, l = morphTargets.length; i < l; i ++ ) {
  6796. var morphTarget = morphTargets[ i ];
  6797. var attribute = new THREE.Float32Attribute( morphTarget.length * 3, 3 );
  6798. array.push( attribute.copyVector3sArray( morphTarget ) );
  6799. }
  6800. this.morphAttributes[ name ] = array;
  6801. }
  6802. // skinning
  6803. if ( geometry.skinIndices.length > 0 ) {
  6804. var skinIndices = new THREE.Float32Attribute( geometry.skinIndices.length * 4, 4 );
  6805. this.addAttribute( 'skinIndex', skinIndices.copyVector4sArray( geometry.skinIndices ) );
  6806. }
  6807. if ( geometry.skinWeights.length > 0 ) {
  6808. var skinWeights = new THREE.Float32Attribute( geometry.skinWeights.length * 4, 4 );
  6809. this.addAttribute( 'skinWeight', skinWeights.copyVector4sArray( geometry.skinWeights ) );
  6810. }
  6811. //
  6812. if ( geometry.boundingSphere !== null ) {
  6813. this.boundingSphere = geometry.boundingSphere.clone();
  6814. }
  6815. if ( geometry.boundingBox !== null ) {
  6816. this.boundingBox = geometry.boundingBox.clone();
  6817. }
  6818. return this;
  6819. },
  6820. computeBoundingBox: function () {
  6821. var vector = new THREE.Vector3();
  6822. return function () {
  6823. if ( this.boundingBox === null ) {
  6824. this.boundingBox = new THREE.Box3();
  6825. }
  6826. var positions = this.attributes.position.array;
  6827. if ( positions ) {
  6828. this.boundingBox.setFromArray( positions );
  6829. }
  6830. if ( positions === undefined || positions.length === 0 ) {
  6831. this.boundingBox.min.set( 0, 0, 0 );
  6832. this.boundingBox.max.set( 0, 0, 0 );
  6833. }
  6834. if ( isNaN( this.boundingBox.min.x ) || isNaN( this.boundingBox.min.y ) || isNaN( this.boundingBox.min.z ) ) {
  6835. console.error( 'THREE.BufferGeometry.computeBoundingBox: Computed min/max have NaN values. The "position" attribute is likely to have NaN values.', this );
  6836. }
  6837. };
  6838. }(),
  6839. computeBoundingSphere: function () {
  6840. var box = new THREE.Box3();
  6841. var vector = new THREE.Vector3();
  6842. return function () {
  6843. if ( this.boundingSphere === null ) {
  6844. this.boundingSphere = new THREE.Sphere();
  6845. }
  6846. var positions = this.attributes.position.array;
  6847. if ( positions ) {
  6848. var center = this.boundingSphere.center;
  6849. box.setFromArray( positions );
  6850. box.center( center );
  6851. // hoping to find a boundingSphere with a radius smaller than the
  6852. // boundingSphere of the boundingBox: sqrt(3) smaller in the best case
  6853. var maxRadiusSq = 0;
  6854. for ( var i = 0, il = positions.length; i < il; i += 3 ) {
  6855. vector.fromArray( positions, i );
  6856. maxRadiusSq = Math.max( maxRadiusSq, center.distanceToSquared( vector ) );
  6857. }
  6858. this.boundingSphere.radius = Math.sqrt( maxRadiusSq );
  6859. if ( isNaN( this.boundingSphere.radius ) ) {
  6860. console.error( 'THREE.BufferGeometry.computeBoundingSphere(): Computed radius is NaN. The "position" attribute is likely to have NaN values.', this );
  6861. }
  6862. }
  6863. };
  6864. }(),
  6865. computeFaceNormals: function () {
  6866. // backwards compatibility
  6867. },
  6868. computeVertexNormals: function () {
  6869. var index = this.index;
  6870. var attributes = this.attributes;
  6871. var groups = this.groups;
  6872. if ( attributes.position ) {
  6873. var positions = attributes.position.array;
  6874. if ( attributes.normal === undefined ) {
  6875. this.addAttribute( 'normal', new THREE.BufferAttribute( new Float32Array( positions.length ), 3 ) );
  6876. } else {
  6877. // reset existing normals to zero
  6878. var array = attributes.normal.array;
  6879. for ( var i = 0, il = array.length; i < il; i ++ ) {
  6880. array[ i ] = 0;
  6881. }
  6882. }
  6883. var normals = attributes.normal.array;
  6884. var vA, vB, vC,
  6885. pA = new THREE.Vector3(),
  6886. pB = new THREE.Vector3(),
  6887. pC = new THREE.Vector3(),
  6888. cb = new THREE.Vector3(),
  6889. ab = new THREE.Vector3();
  6890. // indexed elements
  6891. if ( index ) {
  6892. var indices = index.array;
  6893. if ( groups.length === 0 ) {
  6894. this.addGroup( 0, indices.length );
  6895. }
  6896. for ( var j = 0, jl = groups.length; j < jl; ++ j ) {
  6897. var group = groups[ j ];
  6898. var start = group.start;
  6899. var count = group.count;
  6900. for ( var i = start, il = start + count; i < il; i += 3 ) {
  6901. vA = indices[ i + 0 ] * 3;
  6902. vB = indices[ i + 1 ] * 3;
  6903. vC = indices[ i + 2 ] * 3;
  6904. pA.fromArray( positions, vA );
  6905. pB.fromArray( positions, vB );
  6906. pC.fromArray( positions, vC );
  6907. cb.subVectors( pC, pB );
  6908. ab.subVectors( pA, pB );
  6909. cb.cross( ab );
  6910. normals[ vA ] += cb.x;
  6911. normals[ vA + 1 ] += cb.y;
  6912. normals[ vA + 2 ] += cb.z;
  6913. normals[ vB ] += cb.x;
  6914. normals[ vB + 1 ] += cb.y;
  6915. normals[ vB + 2 ] += cb.z;
  6916. normals[ vC ] += cb.x;
  6917. normals[ vC + 1 ] += cb.y;
  6918. normals[ vC + 2 ] += cb.z;
  6919. }
  6920. }
  6921. } else {
  6922. // non-indexed elements (unconnected triangle soup)
  6923. for ( var i = 0, il = positions.length; i < il; i += 9 ) {
  6924. pA.fromArray( positions, i );
  6925. pB.fromArray( positions, i + 3 );
  6926. pC.fromArray( positions, i + 6 );
  6927. cb.subVectors( pC, pB );
  6928. ab.subVectors( pA, pB );
  6929. cb.cross( ab );
  6930. normals[ i ] = cb.x;
  6931. normals[ i + 1 ] = cb.y;
  6932. normals[ i + 2 ] = cb.z;
  6933. normals[ i + 3 ] = cb.x;
  6934. normals[ i + 4 ] = cb.y;
  6935. normals[ i + 5 ] = cb.z;
  6936. normals[ i + 6 ] = cb.x;
  6937. normals[ i + 7 ] = cb.y;
  6938. normals[ i + 8 ] = cb.z;
  6939. }
  6940. }
  6941. this.normalizeNormals();
  6942. attributes.normal.needsUpdate = true;
  6943. }
  6944. },
  6945. merge: function ( geometry, offset ) {
  6946. if ( geometry instanceof THREE.BufferGeometry === false ) {
  6947. console.error( 'THREE.BufferGeometry.merge(): geometry not an instance of THREE.BufferGeometry.', geometry );
  6948. return;
  6949. }
  6950. if ( offset === undefined ) offset = 0;
  6951. var attributes = this.attributes;
  6952. for ( var key in attributes ) {
  6953. if ( geometry.attributes[ key ] === undefined ) continue;
  6954. var attribute1 = attributes[ key ];
  6955. var attributeArray1 = attribute1.array;
  6956. var attribute2 = geometry.attributes[ key ];
  6957. var attributeArray2 = attribute2.array;
  6958. var attributeSize = attribute2.itemSize;
  6959. for ( var i = 0, j = attributeSize * offset; i < attributeArray2.length; i ++, j ++ ) {
  6960. attributeArray1[ j ] = attributeArray2[ i ];
  6961. }
  6962. }
  6963. return this;
  6964. },
  6965. normalizeNormals: function () {
  6966. var normals = this.attributes.normal.array;
  6967. var x, y, z, n;
  6968. for ( var i = 0, il = normals.length; i < il; i += 3 ) {
  6969. x = normals[ i ];
  6970. y = normals[ i + 1 ];
  6971. z = normals[ i + 2 ];
  6972. n = 1.0 / Math.sqrt( x * x + y * y + z * z );
  6973. normals[ i ] *= n;
  6974. normals[ i + 1 ] *= n;
  6975. normals[ i + 2 ] *= n;
  6976. }
  6977. },
  6978. toNonIndexed: function () {
  6979. if ( this.index === null ) {
  6980. console.warn( 'THREE.BufferGeometry.toNonIndexed(): Geometry is already non-indexed.' );
  6981. return this;
  6982. }
  6983. var geometry2 = new THREE.BufferGeometry();
  6984. var indices = this.index.array;
  6985. var attributes = this.attributes;
  6986. for ( var name in attributes ) {
  6987. var attribute = attributes[ name ];
  6988. var array = attribute.array;
  6989. var itemSize = attribute.itemSize;
  6990. var array2 = new array.constructor( indices.length * itemSize );
  6991. var index = 0, index2 = 0;
  6992. for ( var i = 0, l = indices.length; i < l; i ++ ) {
  6993. index = indices[ i ] * itemSize;
  6994. for ( var j = 0; j < itemSize; j ++ ) {
  6995. array2[ index2 ++ ] = array[ index ++ ];
  6996. }
  6997. }
  6998. geometry2.addAttribute( name, new THREE.BufferAttribute( array2, itemSize ) );
  6999. }
  7000. return geometry2;
  7001. },
  7002. toJSON: function () {
  7003. var data = {
  7004. metadata: {
  7005. version: 4.4,
  7006. type: 'BufferGeometry',
  7007. generator: 'BufferGeometry.toJSON'
  7008. }
  7009. };
  7010. // standard BufferGeometry serialization
  7011. data.uuid = this.uuid;
  7012. data.type = this.type;
  7013. if ( this.name !== '' ) data.name = this.name;
  7014. if ( this.parameters !== undefined ) {
  7015. var parameters = this.parameters;
  7016. for ( var key in parameters ) {
  7017. if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];
  7018. }
  7019. return data;
  7020. }
  7021. data.data = { attributes: {} };
  7022. var index = this.index;
  7023. if ( index !== null ) {
  7024. var array = Array.prototype.slice.call( index.array );
  7025. data.data.index = {
  7026. type: index.array.constructor.name,
  7027. array: array
  7028. };
  7029. }
  7030. var attributes = this.attributes;
  7031. for ( var key in attributes ) {
  7032. var attribute = attributes[ key ];
  7033. var array = Array.prototype.slice.call( attribute.array );
  7034. data.data.attributes[ key ] = {
  7035. itemSize: attribute.itemSize,
  7036. type: attribute.array.constructor.name,
  7037. array: array
  7038. };
  7039. }
  7040. var groups = this.groups;
  7041. if ( groups.length > 0 ) {
  7042. data.data.groups = JSON.parse( JSON.stringify( groups ) );
  7043. }
  7044. var boundingSphere = this.boundingSphere;
  7045. if ( boundingSphere !== null ) {
  7046. data.data.boundingSphere = {
  7047. center: boundingSphere.center.toArray(),
  7048. radius: boundingSphere.radius
  7049. };
  7050. }
  7051. return data;
  7052. },
  7053. clone: function () {
  7054. /*
  7055. // Handle primitives
  7056. var parameters = this.parameters;
  7057. if ( parameters !== undefined ) {
  7058. var values = [];
  7059. for ( var key in parameters ) {
  7060. values.push( parameters[ key ] );
  7061. }
  7062. var geometry = Object.create( this.constructor.prototype );
  7063. this.constructor.apply( geometry, values );
  7064. return geometry;
  7065. }
  7066. return new this.constructor().copy( this );
  7067. */
  7068. return new THREE.BufferGeometry().copy( this );
  7069. },
  7070. copy: function ( source ) {
  7071. var index = source.index;
  7072. if ( index !== null ) {
  7073. this.setIndex( index.clone() );
  7074. }
  7075. var attributes = source.attributes;
  7076. for ( var name in attributes ) {
  7077. var attribute = attributes[ name ];
  7078. this.addAttribute( name, attribute.clone() );
  7079. }
  7080. var groups = source.groups;
  7081. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7082. var group = groups[ i ];
  7083. this.addGroup( group.start, group.count );
  7084. }
  7085. return this;
  7086. },
  7087. dispose: function () {
  7088. this.dispatchEvent( { type: 'dispose' } );
  7089. }
  7090. };
  7091. THREE.EventDispatcher.prototype.apply( THREE.BufferGeometry.prototype );
  7092. THREE.BufferGeometry.MaxIndex = 65535;
  7093. // File:src/core/InstancedBufferGeometry.js
  7094. /**
  7095. * @author benaadams / https://twitter.com/ben_a_adams
  7096. */
  7097. THREE.InstancedBufferGeometry = function () {
  7098. THREE.BufferGeometry.call( this );
  7099. this.type = 'InstancedBufferGeometry';
  7100. this.maxInstancedCount = undefined;
  7101. };
  7102. THREE.InstancedBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  7103. THREE.InstancedBufferGeometry.prototype.constructor = THREE.InstancedBufferGeometry;
  7104. THREE.InstancedBufferGeometry.prototype.addGroup = function ( start, count, instances ) {
  7105. this.groups.push( {
  7106. start: start,
  7107. count: count,
  7108. instances: instances
  7109. } );
  7110. };
  7111. THREE.InstancedBufferGeometry.prototype.copy = function ( source ) {
  7112. var index = source.index;
  7113. if ( index !== null ) {
  7114. this.setIndex( index.clone() );
  7115. }
  7116. var attributes = source.attributes;
  7117. for ( var name in attributes ) {
  7118. var attribute = attributes[ name ];
  7119. this.addAttribute( name, attribute.clone() );
  7120. }
  7121. var groups = source.groups;
  7122. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  7123. var group = groups[ i ];
  7124. this.addGroup( group.start, group.count, group.instances );
  7125. }
  7126. return this;
  7127. };
  7128. THREE.EventDispatcher.prototype.apply( THREE.InstancedBufferGeometry.prototype );
  7129. // File:src/core/Uniform.js
  7130. /**
  7131. * @author mrdoob / http://mrdoob.com/
  7132. */
  7133. THREE.Uniform = function ( type, value ) {
  7134. this.type = type;
  7135. this.value = value;
  7136. this.dynamic = false;
  7137. };
  7138. THREE.Uniform.prototype = {
  7139. constructor: THREE.Uniform,
  7140. onUpdate: function ( callback ) {
  7141. this.dynamic = true;
  7142. this.onUpdateCallback = callback;
  7143. return this;
  7144. }
  7145. };
  7146. // File:src/animation/AnimationClip.js
  7147. /**
  7148. *
  7149. * Reusable set of Tracks that represent an animation.
  7150. *
  7151. * @author Ben Houston / http://clara.io/
  7152. * @author David Sarno / http://lighthaus.us/
  7153. */
  7154. THREE.AnimationClip = function ( name, duration, tracks ) {
  7155. this.name = name || THREE.Math.generateUUID();
  7156. this.tracks = tracks;
  7157. this.duration = ( duration !== undefined ) ? duration : -1;
  7158. // this means it should figure out its duration by scanning the tracks
  7159. if ( this.duration < 0 ) {
  7160. this.resetDuration();
  7161. }
  7162. // maybe only do these on demand, as doing them here could potentially slow down loading
  7163. // but leaving these here during development as this ensures a lot of testing of these functions
  7164. this.trim();
  7165. this.optimize();
  7166. };
  7167. THREE.AnimationClip.prototype = {
  7168. constructor: THREE.AnimationClip,
  7169. resetDuration: function() {
  7170. var tracks = this.tracks,
  7171. duration = 0;
  7172. for ( var i = 0, n = tracks.length; i !== n; ++ i ) {
  7173. var track = this.tracks[ i ];
  7174. duration = Math.max(
  7175. duration, track.times[ track.times.length - 1 ] );
  7176. }
  7177. this.duration = duration;
  7178. },
  7179. trim: function() {
  7180. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7181. this.tracks[ i ].trim( 0, this.duration );
  7182. }
  7183. return this;
  7184. },
  7185. optimize: function() {
  7186. for ( var i = 0; i < this.tracks.length; i ++ ) {
  7187. this.tracks[ i ].optimize();
  7188. }
  7189. return this;
  7190. }
  7191. };
  7192. // Static methods:
  7193. Object.assign( THREE.AnimationClip, {
  7194. parse: function( json ) {
  7195. var tracks = [],
  7196. jsonTracks = json.tracks,
  7197. frameTime = 1.0 / ( json.fps || 1.0 );
  7198. for ( var i = 0, n = jsonTracks.length; i !== n; ++ i ) {
  7199. tracks.push( THREE.KeyframeTrack.parse( jsonTracks[ i ] ).scale( frameTime ) );
  7200. }
  7201. return new THREE.AnimationClip( json.name, json.duration, tracks );
  7202. },
  7203. toJSON: function( clip ) {
  7204. var tracks = [],
  7205. clipTracks = clip.tracks;
  7206. var json = {
  7207. 'name': clip.name,
  7208. 'duration': clip.duration,
  7209. 'tracks': tracks
  7210. };
  7211. for ( var i = 0, n = clipTracks.length; i !== n; ++ i ) {
  7212. tracks.push( THREE.KeyframeTrack.toJSON( clipTracks[ i ] ) );
  7213. }
  7214. return json;
  7215. },
  7216. CreateFromMorphTargetSequence: function( name, morphTargetSequence, fps ) {
  7217. var numMorphTargets = morphTargetSequence.length;
  7218. var tracks = [];
  7219. for ( var i = 0; i < numMorphTargets; i ++ ) {
  7220. var times = [];
  7221. var values = [];
  7222. times.push(
  7223. ( i + numMorphTargets - 1 ) % numMorphTargets,
  7224. i,
  7225. ( i + 1 ) % numMorphTargets );
  7226. values.push( 0, 1, 0 );
  7227. var order = THREE.AnimationUtils.getKeyframeOrder( times );
  7228. times = THREE.AnimationUtils.sortedArray( times, 1, order );
  7229. values = THREE.AnimationUtils.sortedArray( values, 1, order );
  7230. // if there is a key at the first frame, duplicate it as the
  7231. // last frame as well for perfect loop.
  7232. if ( times[ 0 ] === 0 ) {
  7233. times.push( numMorphTargets );
  7234. values.push( values[ 0 ] );
  7235. }
  7236. tracks.push(
  7237. new THREE.NumberKeyframeTrack(
  7238. '.morphTargetInfluences[' + morphTargetSequence[ i ].name + ']',
  7239. times, values
  7240. ).scale( 1.0 / fps ) );
  7241. }
  7242. return new THREE.AnimationClip( name, -1, tracks );
  7243. },
  7244. findByName: function( clipArray, name ) {
  7245. for ( var i = 0; i < clipArray.length; i ++ ) {
  7246. if ( clipArray[ i ].name === name ) {
  7247. return clipArray[ i ];
  7248. }
  7249. }
  7250. return null;
  7251. },
  7252. CreateClipsFromMorphTargetSequences: function( morphTargets, fps ) {
  7253. var animationToMorphTargets = {};
  7254. // tested with https://regex101.com/ on trick sequences
  7255. // such flamingo_flyA_003, flamingo_run1_003, crdeath0059
  7256. var pattern = /^([\w-]*?)([\d]+)$/;
  7257. // sort morph target names into animation groups based
  7258. // patterns like Walk_001, Walk_002, Run_001, Run_002
  7259. for ( var i = 0, il = morphTargets.length; i < il; i ++ ) {
  7260. var morphTarget = morphTargets[ i ];
  7261. var parts = morphTarget.name.match( pattern );
  7262. if ( parts && parts.length > 1 ) {
  7263. var name = parts[ 1 ];
  7264. var animationMorphTargets = animationToMorphTargets[ name ];
  7265. if ( ! animationMorphTargets ) {
  7266. animationToMorphTargets[ name ] = animationMorphTargets = [];
  7267. }
  7268. animationMorphTargets.push( morphTarget );
  7269. }
  7270. }
  7271. var clips = [];
  7272. for ( var name in animationToMorphTargets ) {
  7273. clips.push( THREE.AnimationClip.CreateFromMorphTargetSequence( name, animationToMorphTargets[ name ], fps ) );
  7274. }
  7275. return clips;
  7276. },
  7277. // parse the animation.hierarchy format
  7278. parseAnimation: function( animation, bones, nodeName ) {
  7279. if ( ! animation ) {
  7280. console.error( " no animation in JSONLoader data" );
  7281. return null;
  7282. }
  7283. var addNonemptyTrack = function(
  7284. trackType, trackName, animationKeys, propertyName, destTracks ) {
  7285. // only return track if there are actually keys.
  7286. if ( animationKeys.length !== 0 ) {
  7287. var times = [];
  7288. var values = [];
  7289. THREE.AnimationUtils.flattenJSON(
  7290. animationKeys, times, values, propertyName );
  7291. // empty keys are filtered out, so check again
  7292. if ( times.length !== 0 ) {
  7293. destTracks.push( new trackType( trackName, times, values ) );
  7294. }
  7295. }
  7296. };
  7297. var tracks = [];
  7298. var clipName = animation.name || 'default';
  7299. // automatic length determination in AnimationClip.
  7300. var duration = animation.length || -1;
  7301. var fps = animation.fps || 30;
  7302. var hierarchyTracks = animation.hierarchy || [];
  7303. for ( var h = 0; h < hierarchyTracks.length; h ++ ) {
  7304. var animationKeys = hierarchyTracks[ h ].keys;
  7305. // skip empty tracks
  7306. if ( ! animationKeys || animationKeys.length == 0 ) continue;
  7307. // process morph targets in a way exactly compatible
  7308. // with AnimationHandler.init( animation )
  7309. if ( animationKeys[0].morphTargets ) {
  7310. // figure out all morph targets used in this track
  7311. var morphTargetNames = {};
  7312. for ( var k = 0; k < animationKeys.length; k ++ ) {
  7313. if ( animationKeys[k].morphTargets ) {
  7314. for ( var m = 0; m < animationKeys[k].morphTargets.length; m ++ ) {
  7315. morphTargetNames[ animationKeys[k].morphTargets[m] ] = -1;
  7316. }
  7317. }
  7318. }
  7319. // create a track for each morph target with all zero
  7320. // morphTargetInfluences except for the keys in which
  7321. // the morphTarget is named.
  7322. for ( var morphTargetName in morphTargetNames ) {
  7323. var times = [];
  7324. var values = [];
  7325. for ( var m = 0;
  7326. m !== animationKeys[k].morphTargets.length; ++ m ) {
  7327. var animationKey = animationKeys[k];
  7328. times.push( animationKey.time );
  7329. values.push( ( animationKey.morphTarget === morphTargetName ) ? 1 : 0 )
  7330. }
  7331. tracks.push( new THREE.NumberKeyframeTrack(
  7332. '.morphTargetInfluence[' + morphTargetName + ']', times, values ) );
  7333. }
  7334. duration = morphTargetNames.length * ( fps || 1.0 );
  7335. } else {
  7336. // ...assume skeletal animation
  7337. var boneName = '.bones[' + bones[ h ].name + ']';
  7338. addNonemptyTrack(
  7339. THREE.VectorKeyframeTrack, boneName + '.position',
  7340. animationKeys, 'pos', tracks );
  7341. addNonemptyTrack(
  7342. THREE.QuaternionKeyframeTrack, boneName + '.quaternion',
  7343. animationKeys, 'rot', tracks );
  7344. addNonemptyTrack(
  7345. THREE.VectorKeyframeTrack, boneName + '.scale',
  7346. animationKeys, 'scl', tracks );
  7347. }
  7348. }
  7349. if ( tracks.length === 0 ) {
  7350. return null;
  7351. }
  7352. var clip = new THREE.AnimationClip( clipName, duration, tracks );
  7353. return clip;
  7354. }
  7355. } );
  7356. // File:src/animation/AnimationMixer.js
  7357. /**
  7358. *
  7359. * Player for AnimationClips.
  7360. *
  7361. *
  7362. * @author Ben Houston / http://clara.io/
  7363. * @author David Sarno / http://lighthaus.us/
  7364. * @author tschw
  7365. */
  7366. THREE.AnimationMixer = function( root ) {
  7367. this._root = root;
  7368. this._initMemoryManager();
  7369. this._accuIndex = 0;
  7370. this.time = 0;
  7371. this.timeScale = 1.0;
  7372. };
  7373. THREE.AnimationMixer.prototype = {
  7374. constructor: THREE.AnimationMixer,
  7375. // return an action for a clip optionally using a custom root target
  7376. // object (this method allocates a lot of dynamic memory in case a
  7377. // previously unknown clip/root combination is specified)
  7378. clipAction: function( clip, optionalRoot ) {
  7379. var root = optionalRoot || this._root,
  7380. rootUuid = root.uuid,
  7381. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7382. clipObject = ( clip !== clipName ) ? clip : null,
  7383. actionsForClip = this._actionsByClip[ clipName ],
  7384. prototypeAction;
  7385. if ( actionsForClip !== undefined ) {
  7386. var existingAction =
  7387. actionsForClip.actionByRoot[ rootUuid ];
  7388. if ( existingAction !== undefined ) {
  7389. return existingAction;
  7390. }
  7391. // we know the clip, so we don't have to parse all
  7392. // the bindings again but can just copy
  7393. prototypeAction = actionsForClip.knownActions[ 0 ];
  7394. // also, take the clip from the prototype action
  7395. clipObject = prototypeAction._clip;
  7396. if ( clip !== clipName && clip !== clipObject ) {
  7397. throw new Error(
  7398. "Different clips with the same name detected!" );
  7399. }
  7400. }
  7401. // clip must be known when specified via string
  7402. if ( clipObject === null ) return null;
  7403. // allocate all resources required to run it
  7404. var newAction = new THREE.
  7405. AnimationMixer._Action( this, clipObject, optionalRoot );
  7406. this._bindAction( newAction, prototypeAction );
  7407. // and make the action known to the memory manager
  7408. this._addInactiveAction( newAction, clipName, rootUuid );
  7409. return newAction;
  7410. },
  7411. // get an existing action
  7412. existingAction: function( clip, optionalRoot ) {
  7413. var root = optionalRoot || this._root,
  7414. rootUuid = root.uuid,
  7415. clipName = ( typeof clip === 'string' ) ? clip : clip.name,
  7416. actionsForClip = this._actionsByClip[ clipName ];
  7417. if ( actionsForClip !== undefined ) {
  7418. return actionsForClip.actionByRoot[ rootUuid ] || null;
  7419. }
  7420. return null;
  7421. },
  7422. // deactivates all previously scheduled actions
  7423. stopAllAction: function() {
  7424. var actions = this._actions,
  7425. nActions = this._nActiveActions,
  7426. bindings = this._bindings,
  7427. nBindings = this._nActiveBindings;
  7428. this._nActiveActions = 0;
  7429. this._nActiveBindings = 0;
  7430. for ( var i = 0; i !== nActions; ++ i ) {
  7431. actions[ i ].reset();
  7432. }
  7433. for ( var i = 0; i !== nBindings; ++ i ) {
  7434. bindings[ i ].useCount = 0;
  7435. }
  7436. return this;
  7437. },
  7438. // advance the time and update apply the animation
  7439. update: function( deltaTime ) {
  7440. deltaTime *= this.timeScale;
  7441. var actions = this._actions,
  7442. nActions = this._nActiveActions,
  7443. time = this.time += deltaTime,
  7444. timeDirection = Math.sign( deltaTime ),
  7445. accuIndex = this._accuIndex ^= 1;
  7446. // run active actions
  7447. for ( var i = 0; i !== nActions; ++ i ) {
  7448. var action = actions[ i ];
  7449. if ( action.enabled ) {
  7450. action._update( time, deltaTime, timeDirection, accuIndex );
  7451. }
  7452. }
  7453. // update scene graph
  7454. var bindings = this._bindings,
  7455. nBindings = this._nActiveBindings;
  7456. for ( var i = 0; i !== nBindings; ++ i ) {
  7457. bindings[ i ].apply( accuIndex );
  7458. }
  7459. return this;
  7460. },
  7461. // return this mixer's root target object
  7462. getRoot: function() {
  7463. return this._root;
  7464. },
  7465. // free all resources specific to a particular clip
  7466. uncacheClip: function( clip ) {
  7467. var actions = this._actions,
  7468. clipName = clip.name,
  7469. actionsByClip = this._actionsByClip,
  7470. actionsForClip = actionsByClip[ clipName ];
  7471. if ( actionsForClip !== undefined ) {
  7472. // note: just calling _removeInactiveAction would mess up the
  7473. // iteration state and also require updating the state we can
  7474. // just throw away
  7475. var actionsToRemove = actionsForClip.knownActions;
  7476. for ( var i = 0, n = actionsToRemove.length; i !== n; ++ i ) {
  7477. var action = actionsToRemove[ i ];
  7478. this._deactivateAction( action );
  7479. var cacheIndex = action._cacheIndex,
  7480. lastInactiveAction = actions[ actions.length - 1 ];
  7481. action._cacheIndex = null;
  7482. action._byClipCacheIndex = null;
  7483. lastInactiveAction._cacheIndex = cacheIndex;
  7484. actions[ cacheIndex ] = lastInactiveAction;
  7485. actions.pop();
  7486. this._removeInactiveBindingsForAction( action );
  7487. }
  7488. delete actionsByClip[ clipName ];
  7489. }
  7490. },
  7491. // free all resources specific to a particular root target object
  7492. uncacheRoot: function( root ) {
  7493. var rootUuid = root.uuid,
  7494. actionsByClip = this._actionsByClip;
  7495. for ( var clipName in actionsByClip ) {
  7496. var actionByRoot = actionsByClip[ clipName ].actionByRoot,
  7497. action = actionByRoot[ rootUuid ];
  7498. if ( action !== undefined ) {
  7499. this._deactivateAction( action );
  7500. this._removeInactiveAction( action );
  7501. }
  7502. }
  7503. var bindingsByRoot = this._bindingsByRootAndName,
  7504. bindingByName = bindingsByRoot[ rootUuid ];
  7505. if ( bindingByName !== undefined ) {
  7506. for ( var trackName in bindingByName ) {
  7507. var binding = bindingByName[ trackName ];
  7508. binding.restoreOriginalState();
  7509. this._removeInactiveBinding( binding );
  7510. }
  7511. }
  7512. },
  7513. // remove a targeted clip from the cache
  7514. uncacheAction: function( clip, optionalRoot ) {
  7515. var action = this.existingAction( clip, optionalRoot );
  7516. if ( action !== null ) {
  7517. this._deactivateAction( action );
  7518. this._removeInactiveAction( action );
  7519. }
  7520. }
  7521. };
  7522. THREE.EventDispatcher.prototype.apply( THREE.AnimationMixer.prototype );
  7523. THREE.AnimationMixer._Action =
  7524. function( mixer, clip, localRoot ) {
  7525. this._mixer = mixer;
  7526. this._clip = clip;
  7527. this._localRoot = localRoot || null;
  7528. var tracks = clip.tracks,
  7529. nTracks = tracks.length,
  7530. interpolants = new Array( nTracks );
  7531. var interpolantSettings = {
  7532. endingStart: THREE.ZeroCurvatureEnding,
  7533. endingEnd: THREE.ZeroCurvatureEnding
  7534. };
  7535. for ( var i = 0; i !== nTracks; ++ i ) {
  7536. var interpolant = tracks[ i ].createInterpolant( null );
  7537. interpolants[ i ] = interpolant;
  7538. interpolant.settings = interpolantSettings
  7539. }
  7540. this._interpolantSettings = interpolantSettings;
  7541. this._interpolants = interpolants; // bound by the mixer
  7542. // inside: PropertyMixer (managed by the mixer)
  7543. this._propertyBindings = new Array( nTracks );
  7544. this._cacheIndex = null; // for the memory manager
  7545. this._byClipCacheIndex = null; // for the memory manager
  7546. this._timeScaleInterpolant = null;
  7547. this._weightInterpolant = null;
  7548. this.loop = THREE.LoopRepeat;
  7549. this._loopCount = -1;
  7550. // global mixer time when the action is to be started
  7551. // it's set back to 'null' upon start of the action
  7552. this._startTime = null;
  7553. // scaled local time of the action
  7554. // gets clamped or wrapped to 0..clip.duration according to loop
  7555. this.time = 0;
  7556. this.timeScale = 1;
  7557. this._effectiveTimeScale = 1;
  7558. this.weight = 1;
  7559. this._effectiveWeight = 1;
  7560. this.repetitions = Infinity; // no. of repetitions when looping
  7561. this.paused = false; // false -> zero effective time scale
  7562. this.enabled = true; // true -> zero effective weight
  7563. this.clampWhenFinished = false; // keep feeding the last frame?
  7564. this.zeroSlopeAtStart = true; // for smooth interpolation w/o separate
  7565. this.zeroSlopeAtEnd = true; // clips for start, loop and end
  7566. };
  7567. THREE.AnimationMixer._Action.prototype = {
  7568. constructor: THREE.AnimationMixer._Action,
  7569. // State & Scheduling
  7570. play: function() {
  7571. this._mixer._activateAction( this );
  7572. return this;
  7573. },
  7574. stop: function() {
  7575. this._mixer._deactivateAction( this );
  7576. return this.reset();
  7577. },
  7578. reset: function() {
  7579. this.paused = false;
  7580. this.enabled = true;
  7581. this.time = 0; // restart clip
  7582. this._loopCount = -1; // forget previous loops
  7583. this._startTime = null; // forget scheduling
  7584. return this.stopFading().stopWarping();
  7585. },
  7586. isRunning: function() {
  7587. var start = this._startTime;
  7588. return this.enabled && ! this.paused && this.timeScale !== 0 &&
  7589. this._startTime === null && this._mixer._isActiveAction( this )
  7590. },
  7591. // return true when play has been called
  7592. isScheduled: function() {
  7593. return this._mixer._isActiveAction( this );
  7594. },
  7595. startAt: function( time ) {
  7596. this._startTime = time;
  7597. return this;
  7598. },
  7599. setLoop: function( mode, repetitions ) {
  7600. this.loop = mode;
  7601. this.repetitions = repetitions;
  7602. return this;
  7603. },
  7604. // Weight
  7605. // set the weight stopping any scheduled fading
  7606. // although .enabled = false yields an effective weight of zero, this
  7607. // method does *not* change .enabled, because it would be confusing
  7608. setEffectiveWeight: function( weight ) {
  7609. this.weight = weight;
  7610. // note: same logic as when updated at runtime
  7611. this._effectiveWeight = this.enabled ? weight : 0;
  7612. return this.stopFading();
  7613. },
  7614. // return the weight considering fading and .enabled
  7615. getEffectiveWeight: function() {
  7616. return this._effectiveWeight;
  7617. },
  7618. fadeIn: function( duration ) {
  7619. return this._scheduleFading( duration, 0, 1 );
  7620. },
  7621. fadeOut: function( duration ) {
  7622. return this._scheduleFading( duration, 1, 0 );
  7623. },
  7624. crossFadeFrom: function( fadeOutAction, duration, warp ) {
  7625. var mixer = this._mixer;
  7626. fadeOutAction.fadeOut( duration );
  7627. this.fadeIn( duration );
  7628. if( warp ) {
  7629. var fadeInDuration = this._clip.duration,
  7630. fadeOutDuration = fadeOutAction._clip.duration,
  7631. startEndRatio = fadeOutDuration / fadeInDuration,
  7632. endStartRatio = fadeInDuration / fadeOutDuration;
  7633. fadeOutAction.warp( 1.0, startEndRatio, duration );
  7634. this.warp( endStartRatio, 1.0, duration );
  7635. }
  7636. return this;
  7637. },
  7638. crossFadeTo: function( fadeInAction, duration, warp ) {
  7639. return fadeInAction.crossFadeFrom( this, duration, warp );
  7640. },
  7641. stopFading: function() {
  7642. var weightInterpolant = this._weightInterpolant;
  7643. if ( weightInterpolant !== null ) {
  7644. this._weightInterpolant = null;
  7645. this._mixer._takeBackControlInterpolant( weightInterpolant );
  7646. }
  7647. return this;
  7648. },
  7649. // Time Scale Control
  7650. // set the weight stopping any scheduled warping
  7651. // although .paused = true yields an effective time scale of zero, this
  7652. // method does *not* change .paused, because it would be confusing
  7653. setEffectiveTimeScale: function( timeScale ) {
  7654. this.timeScale = timeScale;
  7655. this._effectiveTimeScale = this.paused ? 0 :timeScale;
  7656. return this.stopWarping();
  7657. },
  7658. // return the time scale considering warping and .paused
  7659. getEffectiveTimeScale: function() {
  7660. return this._effectiveTimeScale;
  7661. },
  7662. setDuration: function( duration ) {
  7663. this.timeScale = this._clip.duration / duration;
  7664. return this.stopWarping();
  7665. },
  7666. syncWith: function( action ) {
  7667. this.time = action.time;
  7668. this.timeScale = action.timeScale;
  7669. return this.stopWarping();
  7670. },
  7671. halt: function( duration ) {
  7672. return this.warp( this._currentTimeScale, 0, duration );
  7673. },
  7674. warp: function( startTimeScale, endTimeScale, duration ) {
  7675. var mixer = this._mixer, now = mixer.time,
  7676. interpolant = this._timeScaleInterpolant,
  7677. timeScale = this.timeScale;
  7678. if ( interpolant === null ) {
  7679. interpolant = mixer._lendControlInterpolant(),
  7680. this._timeScaleInterpolant = interpolant;
  7681. }
  7682. var times = interpolant.parameterPositions,
  7683. values = interpolant.sampleValues;
  7684. times[ 0 ] = now;
  7685. times[ 1 ] = now + duration;
  7686. values[ 0 ] = startTimeScale / timeScale;
  7687. values[ 1 ] = endTimeScale / timeScale;
  7688. return this;
  7689. },
  7690. stopWarping: function() {
  7691. var timeScaleInterpolant = this._timeScaleInterpolant;
  7692. if ( timeScaleInterpolant !== null ) {
  7693. this._timeScaleInterpolant = null;
  7694. this._mixer._takeBackControlInterpolant( timeScaleInterpolant );
  7695. }
  7696. return this;
  7697. },
  7698. // Object Accessors
  7699. getMixer: function() {
  7700. return this._mixer;
  7701. },
  7702. getClip: function() {
  7703. return this._clip;
  7704. },
  7705. getRoot: function() {
  7706. return this._localRoot || this._mixer._root;
  7707. },
  7708. // Interna
  7709. _update: function( time, deltaTime, timeDirection, accuIndex ) {
  7710. // called by the mixer
  7711. var startTime = this._startTime;
  7712. if ( startTime !== null ) {
  7713. // check for scheduled start of action
  7714. var timeRunning = ( time - startTime ) * timeDirection;
  7715. if ( timeRunning < 0 || timeDirection === 0 ) {
  7716. return; // yet to come / don't decide when delta = 0
  7717. }
  7718. // start
  7719. this._startTime = null; // unschedule
  7720. deltaTime = timeDirection * timeRunning;
  7721. }
  7722. // apply time scale and advance time
  7723. deltaTime *= this._updateTimeScale( time );
  7724. var clipTime = this._updateTime( deltaTime );
  7725. // note: _updateTime may disable the action resulting in
  7726. // an effective weight of 0
  7727. var weight = this._updateWeight( time );
  7728. if ( weight > 0 ) {
  7729. var interpolants = this._interpolants;
  7730. var propertyMixers = this._propertyBindings;
  7731. for ( var j = 0, m = interpolants.length; j !== m; ++ j ) {
  7732. interpolants[ j ].evaluate( clipTime );
  7733. propertyMixers[ j ].accumulate( accuIndex, weight );
  7734. }
  7735. }
  7736. },
  7737. _updateWeight: function( time ) {
  7738. var weight = 0;
  7739. if ( this.enabled ) {
  7740. weight = this.weight;
  7741. var interpolant = this._weightInterpolant;
  7742. if ( interpolant !== null ) {
  7743. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7744. weight *= interpolantValue;
  7745. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7746. this.stopFading();
  7747. if ( interpolantValue === 0 ) {
  7748. // faded out, disable
  7749. this.enabled = false;
  7750. }
  7751. }
  7752. }
  7753. }
  7754. this._effectiveWeight = weight;
  7755. return weight;
  7756. },
  7757. _updateTimeScale: function( time ) {
  7758. var timeScale = 0;
  7759. if ( ! this.paused ) {
  7760. timeScale = this.timeScale;
  7761. var interpolant = this._timeScaleInterpolant;
  7762. if ( interpolant !== null ) {
  7763. var interpolantValue = interpolant.evaluate( time )[ 0 ];
  7764. timeScale *= interpolantValue;
  7765. if ( time > interpolant.parameterPositions[ 1 ] ) {
  7766. this.stopWarping();
  7767. if ( timeScale === 0 ) {
  7768. // motion has halted, pause
  7769. this.pause = true;
  7770. } else {
  7771. // warp done - apply final time scale
  7772. this.timeScale = timeScale;
  7773. }
  7774. }
  7775. }
  7776. }
  7777. this._effectiveTimeScale = timeScale;
  7778. return timeScale;
  7779. },
  7780. _updateTime: function( deltaTime ) {
  7781. var time = this.time + deltaTime;
  7782. if ( deltaTime === 0 ) return time;
  7783. var duration = this._clip.duration,
  7784. loop = this.loop,
  7785. loopCount = this._loopCount,
  7786. pingPong = false;
  7787. switch ( loop ) {
  7788. case THREE.LoopOnce:
  7789. if ( loopCount === -1 ) {
  7790. // just started
  7791. this.loopCount = 0;
  7792. this._setEndings( true, true, false );
  7793. }
  7794. if ( time >= duration ) {
  7795. time = duration;
  7796. } else if ( time < 0 ) {
  7797. time = 0;
  7798. } else break;
  7799. // reached the end
  7800. if ( this.clampWhenFinished ) this.pause = true;
  7801. else this.enabled = false;
  7802. this._mixer.dispatchEvent( {
  7803. type: 'finished', action: this,
  7804. direction: deltaTime < 0 ? -1 : 1
  7805. } );
  7806. break;
  7807. case THREE.LoopPingPong:
  7808. pingPong = true;
  7809. case THREE.LoopRepeat:
  7810. if ( loopCount === -1 ) {
  7811. // just started
  7812. if ( deltaTime > 0 ) {
  7813. loopCount = 0;
  7814. this._setEndings(
  7815. true, this.repetitions === 0, pingPong );
  7816. } else {
  7817. // when looping in reverse direction, the initial
  7818. // transition through zero counts as a repetition,
  7819. // so leave loopCount at -1
  7820. this._setEndings(
  7821. this.repetitions === 0, true, pingPong );
  7822. }
  7823. }
  7824. if ( time >= duration || time < 0 ) {
  7825. // wrap around
  7826. var loopDelta = Math.floor( time / duration ); // signed
  7827. time -= duration * loopDelta;
  7828. loopCount += Math.abs( loopDelta );
  7829. var pending = this.repetitions - loopCount;
  7830. if ( pending < 0 ) {
  7831. // stop (switch state, clamp time, fire event)
  7832. if ( this.clampWhenFinished ) this.paused = true;
  7833. else this.enabled = false;
  7834. time = deltaTime > 0 ? duration : 0;
  7835. this._mixer.dispatchEvent( {
  7836. type: 'finished', action: this,
  7837. direction: deltaTime > 0 ? 1 : -1
  7838. } );
  7839. break;
  7840. } else if ( pending === 0 ) {
  7841. // transition to last round
  7842. var atStart = deltaTime < 0;
  7843. this._setEndings( atStart, ! atStart, pingPong );
  7844. } else {
  7845. this._setEndings( false, false, pingPong );
  7846. }
  7847. this._loopCount = loopCount;
  7848. this._mixer.dispatchEvent( {
  7849. type: 'loop', action: this, loopDelta: loopDelta
  7850. } );
  7851. }
  7852. if ( loop === THREE.LoopPingPong && ( loopCount & 1 ) === 1 ) {
  7853. // invert time for the "pong round"
  7854. this.time = time;
  7855. return duration - time;
  7856. }
  7857. break;
  7858. }
  7859. this.time = time;
  7860. return time;
  7861. },
  7862. _setEndings: function( atStart, atEnd, pingPong ) {
  7863. var settings = this._interpolantSettings;
  7864. if ( pingPong ) {
  7865. settings.endingStart = THREE.ZeroSlopeEnding;
  7866. settings.endingEnd = THREE.ZeroSlopeEnding;
  7867. } else {
  7868. // assuming for LoopOnce atStart == atEnd == true
  7869. if ( atStart ) {
  7870. settings.endingStart = this.zeroSlopeAtStart ?
  7871. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7872. } else {
  7873. settings.endingStart = THREE.WrapAroundEnding;
  7874. }
  7875. if ( atEnd ) {
  7876. settings.endingEnd = this.zeroSlopeAtEnd ?
  7877. THREE.ZeroSlopeEnding : THREE.ZeroCurvatureEnding;
  7878. } else {
  7879. settings.endingEnd = THREE.WrapAroundEnding;
  7880. }
  7881. }
  7882. },
  7883. _scheduleFading: function( duration, weightNow, weightThen ) {
  7884. var mixer = this._mixer, now = mixer.time,
  7885. interpolant = this._weightInterpolant;
  7886. if ( interpolant === null ) {
  7887. interpolant = mixer._lendControlInterpolant(),
  7888. this._weightInterpolant = interpolant;
  7889. }
  7890. var times = interpolant.parameterPositions,
  7891. values = interpolant.sampleValues;
  7892. times[ 0 ] = now; values[ 0 ] = weightNow;
  7893. times[ 1 ] = now + duration; values[ 1 ] = weightThen;
  7894. return this;
  7895. }
  7896. };
  7897. // Implementation details:
  7898. Object.assign( THREE.AnimationMixer.prototype, {
  7899. _bindAction: function( action, prototypeAction ) {
  7900. var root = action._localRoot || this._root,
  7901. tracks = action._clip.tracks,
  7902. nTracks = tracks.length,
  7903. bindings = action._propertyBindings,
  7904. interpolants = action._interpolants,
  7905. rootUuid = root.uuid,
  7906. bindingsByRoot = this._bindingsByRootAndName,
  7907. bindingsByName = bindingsByRoot[ rootUuid ];
  7908. if ( bindingsByName === undefined ) {
  7909. bindingsByName = {};
  7910. bindingsByRoot[ rootUuid ] = bindingsByName;
  7911. }
  7912. for ( var i = 0; i !== nTracks; ++ i ) {
  7913. var track = tracks[ i ],
  7914. trackName = track.name,
  7915. binding = bindingsByName[ trackName ];
  7916. if ( binding !== undefined ) {
  7917. bindings[ i ] = binding;
  7918. } else {
  7919. binding = bindings[ i ];
  7920. if ( binding !== undefined ) {
  7921. // existing binding, make sure the cache knows
  7922. if ( binding._cacheIndex === null ) {
  7923. ++ binding.referenceCount;
  7924. this._addInactiveBinding( binding, rootUuid, trackName );
  7925. }
  7926. continue;
  7927. }
  7928. var path = prototypeAction && prototypeAction.
  7929. _propertyBindings[ i ].binding.parsedPath;
  7930. binding = new THREE.PropertyMixer(
  7931. THREE.PropertyBinding.create( root, trackName, path ),
  7932. track.ValueTypeName, track.getValueSize() );
  7933. ++ binding.referenceCount;
  7934. this._addInactiveBinding( binding, rootUuid, trackName );
  7935. bindings[ i ] = binding;
  7936. }
  7937. interpolants[ i ].resultBuffer = binding.buffer;
  7938. }
  7939. },
  7940. _activateAction: function( action ) {
  7941. if ( ! this._isActiveAction( action ) ) {
  7942. if ( action._cacheIndex === null ) {
  7943. // this action has been forgotten by the cache, but the user
  7944. // appears to be still using it -> rebind
  7945. var rootUuid = ( action._localRoot || this._root ).uuid,
  7946. clipName = action._clip.name,
  7947. actionsForClip = this._actionsByClip[ clipName ];
  7948. this._bindAction( action,
  7949. actionsForClip && actionsForClip.knownActions[ 0 ] );
  7950. this._addInactiveAction( action, clipName, rootUuid );
  7951. }
  7952. var bindings = action._propertyBindings;
  7953. // increment reference counts / sort out state
  7954. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7955. var binding = bindings[ i ];
  7956. if ( binding.useCount ++ === 0 ) {
  7957. this._lendBinding( binding );
  7958. binding.saveOriginalState();
  7959. }
  7960. }
  7961. this._lendAction( action );
  7962. }
  7963. },
  7964. _deactivateAction: function( action ) {
  7965. if ( this._isActiveAction( action ) ) {
  7966. var bindings = action._propertyBindings;
  7967. // decrement reference counts / sort out state
  7968. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  7969. var binding = bindings[ i ];
  7970. if ( -- binding.useCount === 0 ) {
  7971. binding.restoreOriginalState();
  7972. this._takeBackBinding( binding );
  7973. }
  7974. }
  7975. this._takeBackAction( action );
  7976. }
  7977. },
  7978. // Memory manager
  7979. _initMemoryManager: function() {
  7980. this._actions = []; // 'nActiveActions' followed by inactive ones
  7981. this._nActiveActions = 0;
  7982. this._actionsByClip = {};
  7983. // inside:
  7984. // {
  7985. // knownActions: Array< _Action > - used as prototypes
  7986. // actionByRoot: _Action - lookup
  7987. // }
  7988. this._bindings = []; // 'nActiveBindings' followed by inactive ones
  7989. this._nActiveBindings = 0;
  7990. this._bindingsByRootAndName = {}; // inside: Map< name, PropertyMixer >
  7991. this._controlInterpolants = []; // same game as above
  7992. this._nActiveControlInterpolants = 0;
  7993. var scope = this;
  7994. this.stats = {
  7995. actions: {
  7996. get total() { return scope._actions.length; },
  7997. get inUse() { return scope._nActiveActions; }
  7998. },
  7999. bindings: {
  8000. get total() { return scope._bindings.length; },
  8001. get inUse() { return scope._nActiveBindings; }
  8002. },
  8003. controlInterpolants: {
  8004. get total() { return scope._controlInterpolants.length; },
  8005. get inUse() { return scope._nActiveControlInterpolants; }
  8006. }
  8007. };
  8008. },
  8009. // Memory management for _Action objects
  8010. _isActiveAction: function( action ) {
  8011. var index = action._cacheIndex;
  8012. return index !== null && index < this._nActiveActions;
  8013. },
  8014. _addInactiveAction: function( action, clipName, rootUuid ) {
  8015. var actions = this._actions,
  8016. actionsByClip = this._actionsByClip,
  8017. actionsForClip = actionsByClip[ clipName ];
  8018. if ( actionsForClip === undefined ) {
  8019. actionsForClip = {
  8020. knownActions: [ action ],
  8021. actionByRoot: {}
  8022. };
  8023. action._byClipCacheIndex = 0;
  8024. actionsByClip[ clipName ] = actionsForClip;
  8025. } else {
  8026. var knownActions = actionsForClip.knownActions;
  8027. action._byClipCacheIndex = knownActions.length;
  8028. knownActions.push( action );
  8029. }
  8030. action._cacheIndex = actions.length;
  8031. actions.push( action );
  8032. actionsForClip.actionByRoot[ rootUuid ] = action;
  8033. },
  8034. _removeInactiveAction: function( action ) {
  8035. var actions = this._actions,
  8036. lastInactiveAction = actions[ actions.length - 1 ],
  8037. cacheIndex = action._cacheIndex;
  8038. lastInactiveAction._cacheIndex = cacheIndex;
  8039. actions[ cacheIndex ] = lastInactiveAction;
  8040. actions.pop();
  8041. action._cacheIndex = null;
  8042. var clipName = action._clip.name,
  8043. actionsByClip = this._actionsByClip,
  8044. actionsForClip = actionsByClip[ clipName ],
  8045. knownActionsForClip = actionsForClip.knownActions,
  8046. lastKnownAction =
  8047. knownActionsForClip[ knownActionsForClip.length - 1 ],
  8048. byClipCacheIndex = action._byClipCacheIndex;
  8049. lastKnownAction._byClipCacheIndex = byClipCacheIndex;
  8050. knownActionsForClip[ byClipCacheIndex ] = lastKnownAction;
  8051. knownActionsForClip.pop();
  8052. action._byClipCacheIndex = null;
  8053. var actionByRoot = actionsForClip.actionByRoot,
  8054. rootUuid = ( actions._localRoot || this._root ).uuid;
  8055. delete actionByRoot[ rootUuid ];
  8056. if ( knownActionsForClip.length === 0 ) {
  8057. delete actionsByClip[ clipName ];
  8058. }
  8059. this._removeInactiveBindingsForAction( action );
  8060. },
  8061. _removeInactiveBindingsForAction: function( action ) {
  8062. var bindings = action._propertyBindings;
  8063. for ( var i = 0, n = bindings.length; i !== n; ++ i ) {
  8064. var binding = bindings[ i ];
  8065. if ( -- binding.referenceCount === 0 ) {
  8066. this._removeInactiveBinding( binding );
  8067. }
  8068. }
  8069. },
  8070. _lendAction: function( action ) {
  8071. // [ active actions | inactive actions ]
  8072. // [ active actions >| inactive actions ]
  8073. // s a
  8074. // <-swap->
  8075. // a s
  8076. var actions = this._actions,
  8077. prevIndex = action._cacheIndex,
  8078. lastActiveIndex = this._nActiveActions ++,
  8079. firstInactiveAction = actions[ lastActiveIndex ];
  8080. action._cacheIndex = lastActiveIndex;
  8081. actions[ lastActiveIndex ] = action;
  8082. firstInactiveAction._cacheIndex = prevIndex;
  8083. actions[ prevIndex ] = firstInactiveAction;
  8084. },
  8085. _takeBackAction: function( action ) {
  8086. // [ active actions | inactive actions ]
  8087. // [ active actions |< inactive actions ]
  8088. // a s
  8089. // <-swap->
  8090. // s a
  8091. var actions = this._actions,
  8092. prevIndex = action._cacheIndex,
  8093. firstInactiveIndex = -- this._nActiveActions,
  8094. lastActiveAction = actions[ firstInactiveIndex ];
  8095. action._cacheIndex = firstInactiveIndex;
  8096. actions[ firstInactiveIndex ] = action;
  8097. lastActiveAction._cacheIndex = prevIndex;
  8098. actions[ prevIndex ] = lastActiveAction;
  8099. },
  8100. // Memory management for PropertyMixer objects
  8101. _addInactiveBinding: function( binding, rootUuid, trackName ) {
  8102. var bindingsByRoot = this._bindingsByRootAndName,
  8103. bindingByName = bindingsByRoot[ rootUuid ],
  8104. bindings = this._bindings;
  8105. if ( bindingByName === undefined ) {
  8106. bindingByName = {};
  8107. bindingsByRoot[ rootUuid ] = bindingByName;
  8108. }
  8109. bindingByName[ trackName ] = binding;
  8110. binding._cacheIndex = bindings.length;
  8111. bindings.push( binding );
  8112. },
  8113. _removeInactiveBinding: function( binding ) {
  8114. var bindings = this._bindings,
  8115. propBinding = binding.binding,
  8116. rootUuid = propBinding.rootNode.uuid,
  8117. trackName = propBinding.path,
  8118. bindingsByRoot = this._bindingsByRootAndName,
  8119. bindingByName = bindingsByRoot[ rootUuid ],
  8120. lastInactiveBinding = bindings[ bindings.length - 1 ],
  8121. cacheIndex = binding._cacheIndex;
  8122. lastInactiveBinding._cacheIndex = cacheIndex;
  8123. bindings[ cacheIndex ] = lastInactiveBinding;
  8124. bindings.pop();
  8125. delete bindingByName[ trackName ];
  8126. remove_empty_map: {
  8127. for ( var _ in bindingByName ) break remove_empty_map;
  8128. delete bindingsByRoot[ rootUuid ];
  8129. }
  8130. },
  8131. _lendBinding: function( binding ) {
  8132. var bindings = this._bindings,
  8133. prevIndex = binding._cacheIndex,
  8134. lastActiveIndex = this._nActiveBindings ++,
  8135. firstInactiveBinding = bindings[ lastActiveIndex ];
  8136. binding._cacheIndex = lastActiveIndex;
  8137. bindings[ lastActiveIndex ] = binding;
  8138. firstInactiveBinding._cacheIndex = prevIndex;
  8139. bindings[ prevIndex ] = firstInactiveBinding;
  8140. },
  8141. _takeBackBinding: function( binding ) {
  8142. var bindings = this._bindings,
  8143. prevIndex = binding._cacheIndex,
  8144. firstInactiveIndex = -- this._nActiveBindings,
  8145. lastActiveBinding = bindings[ firstInactiveIndex ];
  8146. binding._cacheIndex = firstInactiveIndex;
  8147. bindings[ firstInactiveIndex ] = binding;
  8148. lastActiveBinding._cacheIndex = prevIndex;
  8149. bindings[ prevIndex ] = lastActiveBinding;
  8150. },
  8151. // Memory management of Interpolants for weight and time scale
  8152. _lendControlInterpolant: function() {
  8153. var interpolants = this._controlInterpolants,
  8154. lastActiveIndex = this._nActiveControlInterpolants ++,
  8155. interpolant = interpolants[ lastActiveIndex ];
  8156. if ( interpolant === undefined ) {
  8157. interpolant = new THREE.LinearInterpolant(
  8158. new Float32Array( 2 ), new Float32Array( 2 ),
  8159. 1, this._controlInterpolantsResultBuffer );
  8160. interpolant.__cacheIndex = lastActiveIndex;
  8161. interpolants[ lastActiveIndex ] = interpolant;
  8162. }
  8163. return interpolant;
  8164. },
  8165. _takeBackControlInterpolant: function( interpolant ) {
  8166. var interpolants = this._controlInterpolants,
  8167. prevIndex = interpolant.__cacheIndex,
  8168. firstInactiveIndex = -- this._nActiveControlInterpolants,
  8169. lastActiveInterpolant = interpolants[ firstInactiveIndex ];
  8170. interpolant.__cacheIndex = firstInactiveIndex;
  8171. interpolants[ firstInactiveIndex ] = interpolant;
  8172. lastActiveInterpolant.__cacheIndex = prevIndex;
  8173. interpolants[ prevIndex ] = lastActiveInterpolant;
  8174. },
  8175. _controlInterpolantsResultBuffer: new Float32Array( 1 )
  8176. } );
  8177. // File:src/animation/AnimationObjectGroup.js
  8178. /**
  8179. *
  8180. * A group of objects that receives a shared animation state.
  8181. *
  8182. * Usage:
  8183. *
  8184. * - Add objects you would otherwise pass as 'root' to the
  8185. * constructor or the .clipAction method of AnimationMixer.
  8186. *
  8187. * - Instead pass this object as 'root'.
  8188. *
  8189. * - You can also add and remove objects later when the mixer
  8190. * is running.
  8191. *
  8192. * Note:
  8193. *
  8194. * Objects of this class appear as one object to the mixer,
  8195. * so cache control of the individual objects must be done
  8196. * on the group.
  8197. *
  8198. * Limitation:
  8199. *
  8200. * - The animated properties must be compatible among the
  8201. * all objects in the group.
  8202. *
  8203. * - A single property can either be controlled through a
  8204. * target group or directly, but not both.
  8205. *
  8206. * @author tschw
  8207. */
  8208. THREE.AnimationObjectGroup = function( var_args ) {
  8209. this.uuid = THREE.Math.generateUUID();
  8210. // cached objects followed by the active ones
  8211. this._objects = Array.prototype.slice.call( arguments );
  8212. this.nCachedObjects_ = 0; // threshold
  8213. // note: read by PropertyBinding.Composite
  8214. var indices = {};
  8215. this._indicesByUUID = indices; // for bookkeeping
  8216. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8217. indices[ arguments[ i ].uuid ] = i;
  8218. }
  8219. this._paths = []; // inside: string
  8220. this._parsedPaths = []; // inside: { we don't care, here }
  8221. this._bindings = []; // inside: Array< PropertyBinding >
  8222. this._bindingsIndicesByPath = {}; // inside: indices in these arrays
  8223. var scope = this;
  8224. this.stats = {
  8225. objects: {
  8226. get total() { return scope._objects.length; },
  8227. get inUse() { return this.total - scope.nCachedObjects_; }
  8228. },
  8229. get bindingsPerObject() { return scope._bindings.length; }
  8230. };
  8231. };
  8232. THREE.AnimationObjectGroup.prototype = {
  8233. constructor: THREE.AnimationObjectGroup,
  8234. add: function( var_args ) {
  8235. var objects = this._objects,
  8236. nObjects = objects.length,
  8237. nCachedObjects = this.nCachedObjects_,
  8238. indicesByUUID = this._indicesByUUID,
  8239. paths = this._paths,
  8240. parsedPaths = this._parsedPaths,
  8241. bindings = this._bindings,
  8242. nBindings = bindings.length;
  8243. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8244. var object = arguments[ i ],
  8245. uuid = object.uuid,
  8246. index = indicesByUUID[ uuid ];
  8247. if ( index === undefined ) {
  8248. // unknown object -> add it to the ACTIVE region
  8249. index = nObjects ++;
  8250. indicesByUUID[ uuid ] = index;
  8251. objects.push( object );
  8252. // accounting is done, now do the same for all bindings
  8253. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8254. bindings[ j ].push(
  8255. new THREE.PropertyBinding(
  8256. object, paths[ j ], parsedPaths[ j ] ) );
  8257. }
  8258. } else if ( index < nCachedObjects ) {
  8259. var knownObject = objects[ index ];
  8260. // move existing object to the ACTIVE region
  8261. var firstActiveIndex = -- nCachedObjects,
  8262. lastCachedObject = objects[ firstActiveIndex ];
  8263. indicesByUUID[ lastCachedObject.uuid ] = index;
  8264. objects[ index ] = lastCachedObject;
  8265. indicesByUUID[ uuid ] = firstActiveIndex;
  8266. objects[ firstActiveIndex ] = object;
  8267. // accounting is done, now do the same for all bindings
  8268. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8269. var bindingsForPath = bindings[ j ],
  8270. lastCached = bindingsForPath[ firstActiveIndex ],
  8271. binding = bindingsForPath[ index ];
  8272. bindingsForPath[ index ] = lastCached;
  8273. if ( binding === undefined ) {
  8274. // since we do not bother to create new bindings
  8275. // for objects that are cached, the binding may
  8276. // or may not exist
  8277. binding = new THREE.PropertyBinding(
  8278. object, paths[ j ], parsedPaths[ j ] );
  8279. }
  8280. bindingsForPath[ firstActiveIndex ] = binding;
  8281. }
  8282. } else if ( objects[ index ] !== knownObject) {
  8283. console.error( "Different objects with the same UUID " +
  8284. "detected. Clean the caches or recreate your " +
  8285. "infrastructure when reloading scenes..." );
  8286. } // else the object is already where we want it to be
  8287. } // for arguments
  8288. this.nCachedObjects_ = nCachedObjects;
  8289. },
  8290. remove: function( var_args ) {
  8291. var objects = this._objects,
  8292. nObjects = objects.length,
  8293. nCachedObjects = this.nCachedObjects_,
  8294. indicesByUUID = this._indicesByUUID,
  8295. bindings = this._bindings,
  8296. nBindings = bindings.length;
  8297. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8298. var object = arguments[ i ],
  8299. uuid = object.uuid,
  8300. index = indicesByUUID[ uuid ];
  8301. if ( index !== undefined && index >= nCachedObjects ) {
  8302. // move existing object into the CACHED region
  8303. var lastCachedIndex = nCachedObjects ++,
  8304. firstActiveObject = objects[ lastCachedIndex ];
  8305. indicesByUUID[ firstActiveObject.uuid ] = index;
  8306. objects[ index ] = firstActiveObject;
  8307. indicesByUUID[ uuid ] = lastCachedIndex;
  8308. objects[ lastCachedIndex ] = object;
  8309. // accounting is done, now do the same for all bindings
  8310. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8311. var bindingsForPath = bindings[ j ],
  8312. firstActive = bindingsForPath[ lastCachedIndex ],
  8313. binding = bindingsForPath[ index ];
  8314. bindingsForPath[ index ] = firstActive;
  8315. bindingsForPath[ lastCachedIndex ] = binding;
  8316. }
  8317. }
  8318. } // for arguments
  8319. this.nCachedObjects_ = nCachedObjects;
  8320. },
  8321. // remove & forget
  8322. uncache: function( var_args ) {
  8323. var objects = this._objects,
  8324. nObjects = objects.length,
  8325. nCachedObjects = this.nCachedObjects_,
  8326. indicesByUUID = this._indicesByUUID,
  8327. bindings = this._bindings,
  8328. nBindings = bindings.length;
  8329. for ( var i = 0, n = arguments.length; i !== n; ++ i ) {
  8330. var object = arguments[ i ],
  8331. uuid = object.uuid,
  8332. index = indicesByUUID[ uuid ];
  8333. if ( index !== undefined ) {
  8334. delete indicesByUUID[ uuid ];
  8335. if ( index < nCachedObjects ) {
  8336. // object is cached, shrink the CACHED region
  8337. var firstActiveIndex = -- nCachedObjects,
  8338. lastCachedObject = objects[ firstActiveIndex ],
  8339. lastIndex = -- nObjects,
  8340. lastObject = objects[ lastIndex ];
  8341. // last cached object takes this object's place
  8342. indicesByUUID[ lastCachedObject.uuid ] = index;
  8343. objects[ index ] = lastCachedObject;
  8344. // last object goes to the activated slot and pop
  8345. indicesByUUID[ lastObject.uuid ] = firstActiveIndex;
  8346. objects[ firstActiveIndex ] = lastObject;
  8347. objects.pop();
  8348. // accounting is done, now do the same for all bindings
  8349. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8350. var bindingsForPath = bindings[ j ],
  8351. lastCached = bindingsForPath[ firstActiveIndex ],
  8352. last = bindingsForPath[ lastIndex ];
  8353. bindingsForPath[ index ] = lastCached;
  8354. bindingsForPath[ firstActiveIndex ] = last;
  8355. bindingsForPath.pop();
  8356. }
  8357. } else {
  8358. // object is active, just swap with the last and pop
  8359. var lastIndex = -- nObjects,
  8360. lastObject = objects[ lastIndex ];
  8361. indicesByUUID[ lastObject.uuid ] = index;
  8362. objects[ index ] = lastObject;
  8363. objects.pop();
  8364. // accounting is done, now do the same for all bindings
  8365. for ( var j = 0, m = nBindings; j !== m; ++ j ) {
  8366. var bindingsForPath = bindings[ j ];
  8367. bindingsForPath[ index ] = bindingsForPath[ lastIndex ];
  8368. bindingsForPath.pop();
  8369. }
  8370. } // cached or active
  8371. } // if object is known
  8372. } // for arguments
  8373. this.nCachedObjects_ = nCachedObjects;
  8374. },
  8375. // Internal interface used by befriended PropertyBinding.Composite:
  8376. subscribe_: function( path, parsedPath ) {
  8377. // returns an array of bindings for the given path that is changed
  8378. // according to the contained objects in the group
  8379. var indicesByPath = this._bindingsIndicesByPath,
  8380. index = indicesByPath[ path ],
  8381. bindings = this._bindings;
  8382. if ( index !== undefined ) return bindings[ index ];
  8383. var paths = this._paths,
  8384. parsedPaths = this._parsedPaths,
  8385. objects = this._objects,
  8386. nObjects = objects.length,
  8387. nCachedObjects = this.nCachedObjects_,
  8388. bindingsForPath = new Array( nObjects );
  8389. index = bindings.length;
  8390. indicesByPath[ path ] = index;
  8391. paths.push( path );
  8392. parsedPaths.push( parsedPath );
  8393. bindings.push( bindingsForPath );
  8394. for ( var i = nCachedObjects,
  8395. n = objects.length; i !== n; ++ i ) {
  8396. var object = objects[ i ];
  8397. bindingsForPath[ i ] =
  8398. new THREE.PropertyBinding( object, path, parsedPath );
  8399. }
  8400. return bindingsForPath;
  8401. },
  8402. unsubscribe_: function( path ) {
  8403. // tells the group to forget about a property path and no longer
  8404. // update the array previously obtained with 'subscribe_'
  8405. var indicesByPath = this._bindingsIndicesByPath,
  8406. index = indicesByPath[ path ];
  8407. if ( index !== undefined ) {
  8408. var paths = this._paths,
  8409. parsedPaths = this._parsedPaths,
  8410. bindings = this._bindings,
  8411. lastBindingsIndex = bindings.length - 1,
  8412. lastBindings = bindings[ lastBindingsIndex ],
  8413. lastBindingsPath = path[ lastBindingsIndex ];
  8414. indicesByPath[ lastBindingsPath ] = index;
  8415. bindings[ index ] = lastBindings;
  8416. bindings.pop();
  8417. parsedPaths[ index ] = parsedPaths[ lastBindingsIndex ];
  8418. parsedPaths.pop();
  8419. paths[ index ] = paths[ lastBindingsIndex ];
  8420. paths.pop();
  8421. }
  8422. }
  8423. };
  8424. // File:src/animation/AnimationUtils.js
  8425. /**
  8426. * @author tschw
  8427. * @author Ben Houston / http://clara.io/
  8428. * @author David Sarno / http://lighthaus.us/
  8429. */
  8430. THREE.AnimationUtils = {
  8431. // same as Array.prototype.slice, but also works on typed arrays
  8432. arraySlice: function( array, from, to ) {
  8433. if ( THREE.AnimationUtils.isTypedArray( array ) ) {
  8434. return new array.constructor( array.subarray( from, to ) );
  8435. }
  8436. return array.slice( from, to );
  8437. },
  8438. // converts an array to a specific type
  8439. convertArray: function( array, type, forceClone ) {
  8440. if ( ! array || // let 'undefined' and 'null' pass
  8441. ! forceClone && array.constructor === type ) return array;
  8442. if ( typeof type.BYTES_PER_ELEMENT === 'number' ) {
  8443. return new type( array ); // create typed array
  8444. }
  8445. return Array.prototype.slice.call( array ); // create Array
  8446. },
  8447. isTypedArray: function( object ) {
  8448. return ArrayBuffer.isView( object ) &&
  8449. ! ( object instanceof DataView );
  8450. },
  8451. // returns an array by which times and values can be sorted
  8452. getKeyframeOrder: function( times ) {
  8453. function compareTime( i, j ) {
  8454. return times[ i ] - times[ j ];
  8455. }
  8456. var n = times.length;
  8457. var result = new Array( n );
  8458. for ( var i = 0; i !== n; ++ i ) result[ i ] = i;
  8459. result.sort( compareTime );
  8460. return result;
  8461. },
  8462. // uses the array previously returned by 'getKeyframeOrder' to sort data
  8463. sortedArray: function( values, stride, order ) {
  8464. var nValues = values.length;
  8465. var result = new values.constructor( nValues );
  8466. for ( var i = 0, dstOffset = 0; dstOffset !== nValues; ++ i ) {
  8467. var srcOffset = order[ i ] * stride;
  8468. for ( var j = 0; j !== stride; ++ j ) {
  8469. result[ dstOffset ++ ] = values[ srcOffset + j ];
  8470. }
  8471. }
  8472. return result;
  8473. },
  8474. // function for parsing AOS keyframe formats
  8475. flattenJSON: function( jsonKeys, times, values, valuePropertyName ) {
  8476. var i = 1, key = jsonKeys[ 0 ];
  8477. while ( key !== undefined && key[ valuePropertyName ] === undefined ) {
  8478. key = jsonKeys[ i ++ ];
  8479. }
  8480. if ( key === undefined ) return; // no data
  8481. var value = key[ valuePropertyName ];
  8482. if ( value === undefined ) return; // no data
  8483. if ( Array.isArray( value ) ) {
  8484. do {
  8485. value = key[ valuePropertyName ];
  8486. if ( value !== undefined ) {
  8487. times.push( key.time );
  8488. values.push.apply( values, value ); // push all elements
  8489. }
  8490. key = jsonKeys[ i ++ ];
  8491. } while ( key !== undefined );
  8492. } else if ( value.toArray !== undefined ) {
  8493. // ...assume THREE.Math-ish
  8494. do {
  8495. value = key[ valuePropertyName ];
  8496. if ( value !== undefined ) {
  8497. times.push( key.time );
  8498. value.toArray( values, values.length );
  8499. }
  8500. key = jsonKeys[ i ++ ];
  8501. } while ( key !== undefined );
  8502. } else {
  8503. // otherwise push as-is
  8504. do {
  8505. value = key[ valuePropertyName ];
  8506. if ( value !== undefined ) {
  8507. times.push( key.time );
  8508. values.push( value );
  8509. }
  8510. key = jsonKeys[ i ++ ];
  8511. } while ( key !== undefined );
  8512. }
  8513. }
  8514. };
  8515. // File:src/animation/KeyframeTrack.js
  8516. /**
  8517. *
  8518. * A timed sequence of keyframes for a specific property.
  8519. *
  8520. *
  8521. * @author Ben Houston / http://clara.io/
  8522. * @author David Sarno / http://lighthaus.us/
  8523. * @author tschw
  8524. */
  8525. THREE.KeyframeTrack = function ( name, times, values, interpolation ) {
  8526. if( name === undefined ) throw new Error( "track name is undefined" );
  8527. if( times === undefined || times.length === 0 ) {
  8528. throw new Error( "no keyframes in track named " + name );
  8529. }
  8530. this.name = name;
  8531. this.times = THREE.AnimationUtils.convertArray( times, this.TimeBufferType );
  8532. this.values = THREE.AnimationUtils.convertArray( values, this.ValueBufferType );
  8533. this.setInterpolation( interpolation || this.DefaultInterpolation );
  8534. this.validate();
  8535. this.optimize();
  8536. };
  8537. THREE.KeyframeTrack.prototype = {
  8538. constructor: THREE.KeyframeTrack,
  8539. TimeBufferType: Float32Array,
  8540. ValueBufferType: Float32Array,
  8541. DefaultInterpolation: THREE.InterpolateLinear,
  8542. InterpolantFactoryMethodDiscrete: function( result ) {
  8543. return new THREE.DiscreteInterpolant(
  8544. this.times, this.values, this.getValueSize(), result );
  8545. },
  8546. InterpolantFactoryMethodLinear: function( result ) {
  8547. return new THREE.LinearInterpolant(
  8548. this.times, this.values, this.getValueSize(), result );
  8549. },
  8550. InterpolantFactoryMethodSmooth: function( result ) {
  8551. return new THREE.CubicInterpolant(
  8552. this.times, this.values, this.getValueSize(), result );
  8553. },
  8554. setInterpolation: function( interpolation ) {
  8555. var factoryMethod = undefined;
  8556. switch ( interpolation ) {
  8557. case THREE.InterpolateDiscrete:
  8558. factoryMethod = this.InterpolantFactoryMethodDiscrete;
  8559. break;
  8560. case THREE.InterpolateLinear:
  8561. factoryMethod = this.InterpolantFactoryMethodLinear;
  8562. break;
  8563. case THREE.InterpolateSmooth:
  8564. factoryMethod = this.InterpolantFactoryMethodSmooth;
  8565. break;
  8566. }
  8567. if ( factoryMethod === undefined ) {
  8568. var message = "unsupported interpolation for " +
  8569. this.ValueTypeName + " keyframe track named " + this.name;
  8570. if ( this.createInterpolant === undefined ) {
  8571. // fall back to default, unless the default itself is messed up
  8572. if ( interpolation !== this.DefaultInterpolation ) {
  8573. this.setInterpolation( this.DefaultInterpolation );
  8574. } else {
  8575. throw new Error( message ); // fatal, in this case
  8576. }
  8577. }
  8578. console.warn( message );
  8579. return;
  8580. }
  8581. this.createInterpolant = factoryMethod;
  8582. },
  8583. getInterpolation: function() {
  8584. switch ( this.createInterpolant ) {
  8585. case this.InterpolantFactoryMethodDiscrete:
  8586. return THREE.InterpolateDiscrete;
  8587. case this.InterpolantFactoryMethodLinear:
  8588. return THREE.InterpolateLinear;
  8589. case this.InterpolantFactoryMethodSmooth:
  8590. return THREE.InterpolateSmooth;
  8591. }
  8592. },
  8593. getValueSize: function() {
  8594. return this.values.length / this.times.length;
  8595. },
  8596. // move all keyframes either forwards or backwards in time
  8597. shift: function( timeOffset ) {
  8598. if( timeOffset !== 0.0 ) {
  8599. var times = this.times;
  8600. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8601. times[ i ] += timeOffset;
  8602. }
  8603. }
  8604. return this;
  8605. },
  8606. // scale all keyframe times by a factor (useful for frame <-> seconds conversions)
  8607. scale: function( timeScale ) {
  8608. if( timeScale !== 1.0 ) {
  8609. var times = this.times;
  8610. for( var i = 0, n = times.length; i !== n; ++ i ) {
  8611. times[ i ] *= timeScale;
  8612. }
  8613. }
  8614. return this;
  8615. },
  8616. // removes keyframes before and after animation without changing any values within the range [startTime, endTime].
  8617. // IMPORTANT: We do not shift around keys to the start of the track time, because for interpolated keys this will change their values
  8618. trim: function( startTime, endTime ) {
  8619. var times = this.times,
  8620. nKeys = times.length,
  8621. from = 0,
  8622. to = nKeys - 1;
  8623. while ( from !== nKeys && times[ from ] < startTime ) ++ from;
  8624. while ( to !== -1 && times[ to ] > endTime ) -- to;
  8625. ++ to; // inclusive -> exclusive bound
  8626. if( from !== 0 || to !== nKeys ) {
  8627. // empty tracks are forbidden, so keep at least one keyframe
  8628. if ( from >= to ) to = Math.max( to , 1 ), from = to - 1;
  8629. var stride = this.getValueSize();
  8630. this.times = THREE.AnimationUtils.arraySlice( times, from, to );
  8631. this.values = THREE.AnimationUtils.
  8632. arraySlice( this.values, from * stride, to * stride );
  8633. }
  8634. return this;
  8635. },
  8636. // ensure we do not get a GarbageInGarbageOut situation, make sure tracks are at least minimally viable
  8637. validate: function() {
  8638. var valid = true;
  8639. var valueSize = this.getValueSize();
  8640. if ( valueSize - Math.floor( valueSize ) !== 0 ) {
  8641. console.error( "invalid value size in track", this );
  8642. valid = false;
  8643. }
  8644. var times = this.times,
  8645. values = this.values,
  8646. nKeys = times.length;
  8647. if( nKeys === 0 ) {
  8648. console.error( "track is empty", this );
  8649. valid = false;
  8650. }
  8651. var prevTime = null;
  8652. for( var i = 0; i !== nKeys; i ++ ) {
  8653. var currTime = times[ i ];
  8654. if ( typeof currTime === 'number' && isNaN( currTime ) ) {
  8655. console.error( "time is not a valid number", this, i, currTime );
  8656. valid = false;
  8657. break;
  8658. }
  8659. if( prevTime !== null && prevTime > currTime ) {
  8660. console.error( "out of order keys", this, i, currTime, prevTime );
  8661. valid = false;
  8662. break;
  8663. }
  8664. prevTime = currTime;
  8665. }
  8666. if ( values !== undefined ) {
  8667. if ( THREE.AnimationUtils.isTypedArray( values ) ) {
  8668. for ( var i = 0, n = values.length; i !== n; ++ i ) {
  8669. var value = values[ i ];
  8670. if ( isNaN( value ) ) {
  8671. console.error( "value is not a valid number", this, i, value );
  8672. valid = false;
  8673. break;
  8674. }
  8675. }
  8676. }
  8677. }
  8678. return valid;
  8679. },
  8680. // removes equivalent sequential keys as common in morph target sequences
  8681. // (0,0,0,0,1,1,1,0,0,0,0,0,0,0) --> (0,0,1,1,0,0)
  8682. optimize: function() {
  8683. var times = this.times,
  8684. values = this.values,
  8685. stride = this.getValueSize(),
  8686. writeIndex = 1;
  8687. for( var i = 1, n = times.length - 1; i <= n; ++ i ) {
  8688. var keep = false;
  8689. var time = times[ i ];
  8690. var timeNext = times[ i + 1 ];
  8691. // remove adjacent keyframes scheduled at the same time
  8692. if ( time !== timeNext && ( i !== 1 || time !== time[ 0 ] ) ) {
  8693. // remove unnecessary keyframes same as their neighbors
  8694. var offset = i * stride,
  8695. offsetP = offset - stride,
  8696. offsetN = offset + stride;
  8697. for ( var j = 0; j !== stride; ++ j ) {
  8698. var value = values[ offset + j ];
  8699. if ( value !== values[ offsetP + j ] ||
  8700. value !== values[ offsetN + j ] ) {
  8701. keep = true;
  8702. break;
  8703. }
  8704. }
  8705. }
  8706. // in-place compaction
  8707. if ( keep ) {
  8708. if ( i !== writeIndex ) {
  8709. times[ writeIndex ] = times[ i ];
  8710. var readOffset = i * stride,
  8711. writeOffset = writeIndex * stride;
  8712. for ( var j = 0; j !== stride; ++ j ) {
  8713. values[ writeOffset + j ] = values[ readOffset + j ];
  8714. }
  8715. }
  8716. ++ writeIndex;
  8717. }
  8718. }
  8719. if ( writeIndex !== times.length ) {
  8720. this.times = THREE.AnimationUtils.arraySlice( times, 0, writeIndex );
  8721. this.values = THREE.AnimationUtils.arraySlice( values, 0, writeIndex * stride );
  8722. }
  8723. return this;
  8724. }
  8725. };
  8726. // Static methods:
  8727. Object.assign( THREE.KeyframeTrack, {
  8728. // Serialization (in static context, because of constructor invocation
  8729. // and automatic invocation of .toJSON):
  8730. parse: function( json ) {
  8731. if( json.type === undefined ) {
  8732. throw new Error( "track type undefined, can not parse" );
  8733. }
  8734. var trackType = THREE.KeyframeTrack._getTrackTypeForValueTypeName( json.type );
  8735. if ( json.times === undefined ) {
  8736. console.warn( "legacy JSON format detected, converting" );
  8737. var times = [], values = [];
  8738. THREE.AnimationUtils.flattenJSON( json.keys, times, values, 'value' );
  8739. json.times = times;
  8740. json.values = values;
  8741. }
  8742. // derived classes can define a static parse method
  8743. if ( trackType.parse !== undefined ) {
  8744. return trackType.parse( json );
  8745. } else {
  8746. // by default, we asssume a constructor compatible with the base
  8747. return new trackType(
  8748. json.name, json.times, json.values, json.interpolation );
  8749. }
  8750. },
  8751. toJSON: function( track ) {
  8752. var trackType = track.constructor;
  8753. var json;
  8754. // derived classes can define a static toJSON method
  8755. if ( trackType.toJSON !== undefined ) {
  8756. json = trackType.toJSON( track );
  8757. } else {
  8758. // by default, we assume the data can be serialized as-is
  8759. json = {
  8760. 'name': track.name,
  8761. 'times': THREE.AnimationUtils.convertArray( track.times, Array ),
  8762. 'values': THREE.AnimationUtils.convertArray( track.values, Array )
  8763. };
  8764. var interpolation = track.getInterpolation();
  8765. if ( interpolation !== track.DefaultInterpolation ) {
  8766. json.interpolation = interpolation;
  8767. }
  8768. }
  8769. json.type = track.ValueTypeName; // mandatory
  8770. return json;
  8771. },
  8772. _getTrackTypeForValueTypeName: function( typeName ) {
  8773. switch( typeName.toLowerCase() ) {
  8774. case "scalar":
  8775. case "double":
  8776. case "float":
  8777. case "number":
  8778. case "integer":
  8779. return THREE.NumberKeyframeTrack;
  8780. case "vector":
  8781. case "vector2":
  8782. case "vector3":
  8783. case "vector4":
  8784. return THREE.VectorKeyframeTrack;
  8785. case "color":
  8786. return THREE.ColorKeyframeTrack;
  8787. case "quaternion":
  8788. return THREE.QuaternionKeyframeTrack;
  8789. case "bool":
  8790. case "boolean":
  8791. return THREE.BooleanKeyframeTrack;
  8792. case "string":
  8793. return THREE.StringKeyframeTrack;
  8794. };
  8795. throw new Error( "Unsupported typeName: " + typeName );
  8796. }
  8797. } );
  8798. // File:src/animation/PropertyBinding.js
  8799. /**
  8800. *
  8801. * A reference to a real property in the scene graph.
  8802. *
  8803. *
  8804. * @author Ben Houston / http://clara.io/
  8805. * @author David Sarno / http://lighthaus.us/
  8806. * @author tschw
  8807. */
  8808. THREE.PropertyBinding = function ( rootNode, path, parsedPath ) {
  8809. this.path = path;
  8810. this.parsedPath = parsedPath ||
  8811. THREE.PropertyBinding.parseTrackName( path );
  8812. this.node = THREE.PropertyBinding.findNode(
  8813. rootNode, this.parsedPath.nodeName ) || rootNode;
  8814. this.rootNode = rootNode;
  8815. };
  8816. THREE.PropertyBinding.prototype = {
  8817. constructor: THREE.PropertyBinding,
  8818. getValue: function getValue_unbound( targetArray, offset ) {
  8819. this.bind();
  8820. this.getValue( targetArray, offset );
  8821. // Note: This class uses a State pattern on a per-method basis:
  8822. // 'bind' sets 'this.getValue' / 'setValue' and shadows the
  8823. // prototype version of these methods with one that represents
  8824. // the bound state. When the property is not found, the methods
  8825. // become no-ops.
  8826. },
  8827. setValue: function getValue_unbound( sourceArray, offset ) {
  8828. this.bind();
  8829. this.setValue( sourceArray, offset );
  8830. },
  8831. // create getter / setter pair for a property in the scene graph
  8832. bind: function() {
  8833. var targetObject = this.node,
  8834. parsedPath = this.parsedPath,
  8835. objectName = parsedPath.objectName,
  8836. propertyName = parsedPath.propertyName,
  8837. propertyIndex = parsedPath.propertyIndex;
  8838. if ( ! targetObject ) {
  8839. targetObject = THREE.PropertyBinding.findNode(
  8840. this.rootNode, parsedPath.nodeName ) || this.rootNode;
  8841. this.node = targetObject;
  8842. }
  8843. // set fail state so we can just 'return' on error
  8844. this.getValue = this._getValue_unavailable;
  8845. this.setValue = this._setValue_unavailable;
  8846. // ensure there is a value node
  8847. if ( ! targetObject ) {
  8848. console.error( " trying to update node for track: " + this.path + " but it wasn't found." );
  8849. return;
  8850. }
  8851. if( objectName ) {
  8852. var objectIndex = parsedPath.objectIndex;
  8853. // special cases were we need to reach deeper into the hierarchy to get the face materials....
  8854. switch ( objectName ) {
  8855. case 'materials':
  8856. if( ! targetObject.material ) {
  8857. console.error( ' can not bind to material as node does not have a material', this );
  8858. return;
  8859. }
  8860. if( ! targetObject.material.materials ) {
  8861. console.error( ' can not bind to material.materials as node.material does not have a materials array', this );
  8862. return;
  8863. }
  8864. targetObject = targetObject.material.materials;
  8865. break;
  8866. case 'bones':
  8867. if( ! targetObject.skeleton ) {
  8868. console.error( ' can not bind to bones as node does not have a skeleton', this );
  8869. return;
  8870. }
  8871. // potential future optimization: skip this if propertyIndex is already an integer
  8872. // and convert the integer string to a true integer.
  8873. targetObject = targetObject.skeleton.bones;
  8874. // support resolving morphTarget names into indices.
  8875. for ( var i = 0; i < targetObject.length; i ++ ) {
  8876. if ( targetObject[i].name === objectIndex ) {
  8877. objectIndex = i;
  8878. break;
  8879. }
  8880. }
  8881. break;
  8882. default:
  8883. if ( targetObject[ objectName ] === undefined ) {
  8884. console.error( ' can not bind to objectName of node, undefined', this );
  8885. return;
  8886. }
  8887. targetObject = targetObject[ objectName ];
  8888. }
  8889. if ( objectIndex !== undefined ) {
  8890. if( targetObject[ objectIndex ] === undefined ) {
  8891. console.error( " trying to bind to objectIndex of objectName, but is undefined:", this, targetObject );
  8892. return;
  8893. }
  8894. targetObject = targetObject[ objectIndex ];
  8895. }
  8896. }
  8897. // resolve property
  8898. var nodeProperty = targetObject[ propertyName ];
  8899. if ( ! nodeProperty ) {
  8900. var nodeName = parsedPath.nodeName;
  8901. console.error( " trying to update property for track: " + nodeName +
  8902. '.' + propertyName + " but it wasn't found.", targetObject );
  8903. return;
  8904. }
  8905. // determine versioning scheme
  8906. var versioning = this.Versioning.None;
  8907. if ( targetObject.needsUpdate !== undefined ) { // material
  8908. versioning = this.Versioning.NeedsUpdate;
  8909. this.targetObject = targetObject;
  8910. } else if ( targetObject.matrixWorldNeedsUpdate !== undefined ) { // node transform
  8911. versioning = this.Versioning.MatrixWorldNeedsUpdate;
  8912. this.targetObject = targetObject;
  8913. }
  8914. // determine how the property gets bound
  8915. var bindingType = this.BindingType.Direct;
  8916. if ( propertyIndex !== undefined ) {
  8917. // access a sub element of the property array (only primitives are supported right now)
  8918. if ( propertyName === "morphTargetInfluences" ) {
  8919. // potential optimization, skip this if propertyIndex is already an integer, and convert the integer string to a true integer.
  8920. // support resolving morphTarget names into indices.
  8921. if ( ! targetObject.geometry ) {
  8922. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry', this );
  8923. return;
  8924. }
  8925. if ( ! targetObject.geometry.morphTargets ) {
  8926. console.error( ' can not bind to morphTargetInfluences becasuse node does not have a geometry.morphTargets', this );
  8927. return;
  8928. }
  8929. for ( var i = 0; i < this.node.geometry.morphTargets.length; i ++ ) {
  8930. if ( targetObject.geometry.morphTargets[i].name === propertyIndex ) {
  8931. propertyIndex = i;
  8932. break;
  8933. }
  8934. }
  8935. }
  8936. bindingType = this.BindingType.ArrayElement;
  8937. this.resolvedProperty = nodeProperty;
  8938. this.propertyIndex = propertyIndex;
  8939. } else if ( nodeProperty.fromArray !== undefined && nodeProperty.toArray !== undefined ) {
  8940. // must use copy for Object3D.Euler/Quaternion
  8941. bindingType = this.BindingType.HasFromToArray;
  8942. this.resolvedProperty = nodeProperty;
  8943. } else if ( nodeProperty.length !== undefined ) {
  8944. bindingType = this.BindingType.EntireArray;
  8945. this.resolvedProperty = nodeProperty;
  8946. } else {
  8947. this.propertyName = propertyName;
  8948. }
  8949. // select getter / setter
  8950. this.getValue = this.GetterByBindingType[ bindingType ];
  8951. this.setValue = this.SetterByBindingTypeAndVersioning[ bindingType ][ versioning ];
  8952. },
  8953. unbind: function() {
  8954. this.node = null;
  8955. // back to the prototype version of getValue / setValue
  8956. // note: avoiding to mutate the shape of 'this' via 'delete'
  8957. this.getValue = this._getValue_unbound;
  8958. this.setValue = this._setValue_unbound;
  8959. }
  8960. };
  8961. Object.assign( THREE.PropertyBinding.prototype, { // prototype, continued
  8962. // these are used to "bind" a nonexistent property
  8963. _getValue_unavailable: function() {},
  8964. _setValue_unavailable: function() {},
  8965. // initial state of these methods that calls 'bind'
  8966. _getValue_unbound: THREE.PropertyBinding.prototype.getValue,
  8967. _setValue_unbound: THREE.PropertyBinding.prototype.setValue,
  8968. BindingType: {
  8969. Direct: 0,
  8970. EntireArray: 1,
  8971. ArrayElement: 2,
  8972. HasFromToArray: 3
  8973. },
  8974. Versioning: {
  8975. None: 0,
  8976. NeedsUpdate: 1,
  8977. MatrixWorldNeedsUpdate: 2
  8978. },
  8979. GetterByBindingType: [
  8980. function getValue_direct( buffer, offset ) {
  8981. buffer[ offset ] = this.node[ this.propertyName ];
  8982. },
  8983. function getValue_array( buffer, offset ) {
  8984. var source = this.resolvedProperty;
  8985. for ( var i = 0, n = source.length; i !== n; ++ i ) {
  8986. buffer[ offset ++ ] = source[ i ];
  8987. }
  8988. },
  8989. function getValue_arrayElement( buffer, offset ) {
  8990. buffer[ offset ] = this.resolvedProperty[ this.propertyIndex ];
  8991. },
  8992. function getValue_toArray( buffer, offset ) {
  8993. this.resolvedProperty.toArray( buffer, offset );
  8994. }
  8995. ],
  8996. SetterByBindingTypeAndVersioning: [
  8997. [
  8998. // Direct
  8999. function setValue_direct( buffer, offset ) {
  9000. this.node[ this.propertyName ] = buffer[ offset ];
  9001. },
  9002. function setValue_direct_setNeedsUpdate( buffer, offset ) {
  9003. this.node[ this.propertyName ] = buffer[ offset ];
  9004. this.targetObject.needsUpdate = true;
  9005. },
  9006. function setValue_direct_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9007. this.node[ this.propertyName ] = buffer[ offset ];
  9008. this.targetObject.matrixWorldNeedsUpdate = true;
  9009. }
  9010. ], [
  9011. // EntireArray
  9012. function setValue_array( buffer, offset ) {
  9013. var dest = this.resolvedProperty;
  9014. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9015. dest[ i ] = buffer[ offset ++ ];
  9016. }
  9017. },
  9018. function setValue_array_setNeedsUpdate( buffer, offset ) {
  9019. var dest = this.resolvedProperty;
  9020. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9021. dest[ i ] = buffer[ offset ++ ];
  9022. }
  9023. this.targetObject.needsUpdate = true;
  9024. },
  9025. function setValue_array_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9026. var dest = this.resolvedProperty;
  9027. for ( var i = 0, n = dest.length; i !== n; ++ i ) {
  9028. dest[ i ] = buffer[ offset ++ ];
  9029. }
  9030. this.targetObject.matrixWorldNeedsUpdate = true;
  9031. }
  9032. ], [
  9033. // ArrayElement
  9034. function setValue_arrayElement( buffer, offset ) {
  9035. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9036. },
  9037. function setValue_arrayElement_setNeedsUpdate( buffer, offset ) {
  9038. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9039. this.targetObject.needsUpdate = true;
  9040. },
  9041. function setValue_arrayElement_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9042. this.resolvedProperty[ this.propertyIndex ] = buffer[ offset ];
  9043. this.targetObject.matrixWorldNeedsUpdate = true;
  9044. }
  9045. ], [
  9046. // HasToFromArray
  9047. function setValue_fromArray( buffer, offset ) {
  9048. this.resolvedProperty.fromArray( buffer, offset );
  9049. },
  9050. function setValue_fromArray_setNeedsUpdate( buffer, offset ) {
  9051. this.resolvedProperty.fromArray( buffer, offset );
  9052. this.targetObject.needsUpdate = true;
  9053. },
  9054. function setValue_fromArray_setMatrixWorldNeedsUpdate( buffer, offset ) {
  9055. this.resolvedProperty.fromArray( buffer, offset );
  9056. this.targetObject.matrixWorldNeedsUpdate = true;
  9057. }
  9058. ]
  9059. ]
  9060. } );
  9061. THREE.PropertyBinding.Composite =
  9062. function( targetGroup, path, optionalParsedPath ) {
  9063. var parsedPath = optionalParsedPath ||
  9064. THREE.PropertyBinding.parseTrackName( path );
  9065. this._targetGroup = targetGroup;
  9066. this._bindings = targetGroup.subscribe_( path, parsedPath );
  9067. };
  9068. THREE.PropertyBinding.Composite.prototype = {
  9069. constructor: THREE.PropertyBinding.Composite,
  9070. getValue: function( array, offset ) {
  9071. this.bind(); // bind all binding
  9072. var firstValidIndex = this._targetGroup.nCachedObjects_,
  9073. binding = this._bindings[ firstValidIndex ];
  9074. // and only call .getValue on the first
  9075. if ( binding !== undefined ) binding.getValue( array, offset );
  9076. },
  9077. setValue: function( array, offset ) {
  9078. var bindings = this._bindings;
  9079. for ( var i = this._targetGroup.nCachedObjects_,
  9080. n = bindings.length; i !== n; ++ i ) {
  9081. bindings[ i ].setValue( array, offset );
  9082. }
  9083. },
  9084. bind: function() {
  9085. var bindings = this._bindings;
  9086. for ( var i = this._targetGroup.nCachedObjects_,
  9087. n = bindings.length; i !== n; ++ i ) {
  9088. bindings[ i ].bind();
  9089. }
  9090. },
  9091. unbind: function() {
  9092. var bindings = this._bindings;
  9093. for ( var i = this._targetGroup.nCachedObjects_,
  9094. n = bindings.length; i !== n; ++ i ) {
  9095. bindings[ i ].unbind();
  9096. }
  9097. }
  9098. };
  9099. THREE.PropertyBinding.create = function( root, path, parsedPath ) {
  9100. if ( ! ( root instanceof THREE.AnimationObjectGroup ) ) {
  9101. return new THREE.PropertyBinding( root, path, parsedPath );
  9102. } else {
  9103. return new THREE.PropertyBinding.Composite( root, path, parsedPath );
  9104. }
  9105. };
  9106. THREE.PropertyBinding.parseTrackName = function( trackName ) {
  9107. // matches strings in the form of:
  9108. // nodeName.property
  9109. // nodeName.property[accessor]
  9110. // nodeName.material.property[accessor]
  9111. // uuid.property[accessor]
  9112. // uuid.objectName[objectIndex].propertyName[propertyIndex]
  9113. // parentName/nodeName.property
  9114. // parentName/parentName/nodeName.property[index]
  9115. // .bone[Armature.DEF_cog].position
  9116. // created and tested via https://regex101.com/#javascript
  9117. var re = /^(([\w]+\/)*)([\w-\d]+)?(\.([\w]+)(\[([\w\d\[\]\_. ]+)\])?)?(\.([\w.]+)(\[([\w\d\[\]\_. ]+)\])?)$/;
  9118. var matches = re.exec(trackName);
  9119. if( ! matches ) {
  9120. throw new Error( "cannot parse trackName at all: " + trackName );
  9121. }
  9122. if (matches.index === re.lastIndex) {
  9123. re.lastIndex++;
  9124. }
  9125. var results = {
  9126. // directoryName: matches[1], // (tschw) currently unused
  9127. nodeName: matches[3], // allowed to be null, specified root node.
  9128. objectName: matches[5],
  9129. objectIndex: matches[7],
  9130. propertyName: matches[9],
  9131. propertyIndex: matches[11] // allowed to be null, specifies that the whole property is set.
  9132. };
  9133. if( results.propertyName === null || results.propertyName.length === 0 ) {
  9134. throw new Error( "can not parse propertyName from trackName: " + trackName );
  9135. }
  9136. return results;
  9137. };
  9138. THREE.PropertyBinding.findNode = function( root, nodeName ) {
  9139. if( ! nodeName || nodeName === "" || nodeName === "root" || nodeName === "." || nodeName === -1 || nodeName === root.name || nodeName === root.uuid ) {
  9140. return root;
  9141. }
  9142. // search into skeleton bones.
  9143. if( root.skeleton ) {
  9144. var searchSkeleton = function( skeleton ) {
  9145. for( var i = 0; i < skeleton.bones.length; i ++ ) {
  9146. var bone = skeleton.bones[i];
  9147. if( bone.name === nodeName ) {
  9148. return bone;
  9149. }
  9150. }
  9151. return null;
  9152. };
  9153. var bone = searchSkeleton( root.skeleton );
  9154. if( bone ) {
  9155. return bone;
  9156. }
  9157. }
  9158. // search into node subtree.
  9159. if( root.children ) {
  9160. var searchNodeSubtree = function( children ) {
  9161. for( var i = 0; i < children.length; i ++ ) {
  9162. var childNode = children[i];
  9163. if( childNode.name === nodeName || childNode.uuid === nodeName ) {
  9164. return childNode;
  9165. }
  9166. var result = searchNodeSubtree( childNode.children );
  9167. if( result ) return result;
  9168. }
  9169. return null;
  9170. };
  9171. var subTreeNode = searchNodeSubtree( root.children );
  9172. if( subTreeNode ) {
  9173. return subTreeNode;
  9174. }
  9175. }
  9176. return null;
  9177. }
  9178. // File:src/animation/PropertyMixer.js
  9179. /**
  9180. *
  9181. * Buffered scene graph property that allows weighted accumulation.
  9182. *
  9183. *
  9184. * @author Ben Houston / http://clara.io/
  9185. * @author David Sarno / http://lighthaus.us/
  9186. * @author tschw
  9187. */
  9188. THREE.PropertyMixer = function ( binding, typeName, valueSize ) {
  9189. this.binding = binding;
  9190. this.valueSize = valueSize;
  9191. var bufferType = Float64Array,
  9192. mixFunction;
  9193. switch ( typeName ) {
  9194. case 'quaternion': mixFunction = this._slerp; break;
  9195. case 'string':
  9196. case 'bool':
  9197. bufferType = Array, mixFunction = this._select; break;
  9198. default: mixFunction = this._lerp;
  9199. }
  9200. this.buffer = new bufferType( valueSize * 4 );
  9201. // layout: [ incoming | accu0 | accu1 | orig ]
  9202. //
  9203. // interpolators can use .buffer as their .result
  9204. // the data then goes to 'incoming'
  9205. //
  9206. // 'accu0' and 'accu1' are used frame-interleaved for
  9207. // the cumulative result and are compared to detect
  9208. // changes
  9209. //
  9210. // 'orig' stores the original state of the property
  9211. this._mixBufferRegion = mixFunction;
  9212. this.cumulativeWeight = 0;
  9213. this.useCount = 0;
  9214. this.referenceCount = 0;
  9215. };
  9216. THREE.PropertyMixer.prototype = {
  9217. constructor: THREE.PropertyMixer,
  9218. // accumulate data in the 'incoming' region into 'accu<i>'
  9219. accumulate: function( accuIndex, weight ) {
  9220. // note: happily accumulating nothing when weight = 0, the caller knows
  9221. // the weight and shouldn't have made the call in the first place
  9222. var buffer = this.buffer,
  9223. stride = this.valueSize,
  9224. offset = accuIndex * stride + stride,
  9225. currentWeight = this.cumulativeWeight;
  9226. if ( currentWeight === 0 ) {
  9227. // accuN := incoming * weight
  9228. for ( var i = 0; i !== stride; ++ i ) {
  9229. buffer[ offset + i ] = buffer[ i ];
  9230. }
  9231. currentWeight = weight;
  9232. } else {
  9233. // accuN := accuN + incoming * weight
  9234. currentWeight += weight;
  9235. var mix = weight / currentWeight;
  9236. this._mixBufferRegion( buffer, offset, 0, mix, stride );
  9237. }
  9238. this.cumulativeWeight = currentWeight;
  9239. },
  9240. // apply the state of 'accu<i>' to the binding when accus differ
  9241. apply: function( accuIndex ) {
  9242. var stride = this.valueSize,
  9243. buffer = this.buffer,
  9244. offset = accuIndex * stride + stride,
  9245. weight = this.cumulativeWeight,
  9246. binding = this.binding;
  9247. this.cumulativeWeight = 0;
  9248. if ( weight < 1 ) {
  9249. // accuN := accuN + original * ( 1 - cumulativeWeight )
  9250. var originalValueOffset = stride * 3;
  9251. this._mixBufferRegion(
  9252. buffer, offset, originalValueOffset, 1 - weight, stride );
  9253. }
  9254. for ( var i = stride, e = stride + stride; i !== e; ++ i ) {
  9255. if ( buffer[ i ] !== buffer[ i + stride ] ) {
  9256. // value has changed -> update scene graph
  9257. binding.setValue( buffer, offset );
  9258. break;
  9259. }
  9260. }
  9261. },
  9262. // remember the state of the bound property and copy it to both accus
  9263. saveOriginalState: function() {
  9264. var binding = this.binding;
  9265. var buffer = this.buffer,
  9266. stride = this.valueSize,
  9267. originalValueOffset = stride * 3;
  9268. binding.getValue( buffer, originalValueOffset );
  9269. // accu[0..1] := orig -- initially detect changes against the original
  9270. for ( var i = stride, e = originalValueOffset; i !== e; ++ i ) {
  9271. buffer[ i ] = buffer[ originalValueOffset + ( i % stride ) ];
  9272. }
  9273. this.cumulativeWeight = 0;
  9274. },
  9275. // apply the state previously taken via 'saveOriginalState' to the binding
  9276. restoreOriginalState: function() {
  9277. var originalValueOffset = this.valueSize * 3;
  9278. this.binding.setValue( this.buffer, originalValueOffset );
  9279. },
  9280. // mix functions
  9281. _select: function( buffer, dstOffset, srcOffset, t, stride ) {
  9282. if ( t >= 0.5 ) {
  9283. for ( var i = 0; i !== stride; ++ i ) {
  9284. buffer[ dstOffset + i ] = buffer[ srcOffset + i ];
  9285. }
  9286. }
  9287. },
  9288. _slerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9289. THREE.Quaternion.slerpFlat( buffer, dstOffset,
  9290. buffer, dstOffset, buffer, srcOffset, t );
  9291. },
  9292. _lerp: function( buffer, dstOffset, srcOffset, t, stride ) {
  9293. var s = 1 - t;
  9294. for ( var i = 0; i !== stride; ++ i ) {
  9295. var j = dstOffset + i;
  9296. buffer[ j ] = buffer[ j ] * s + buffer[ srcOffset + i ] * t;
  9297. }
  9298. }
  9299. };
  9300. // File:src/animation/tracks/BooleanKeyframeTrack.js
  9301. /**
  9302. *
  9303. * A Track of Boolean keyframe values.
  9304. *
  9305. *
  9306. * @author Ben Houston / http://clara.io/
  9307. * @author David Sarno / http://lighthaus.us/
  9308. * @author tschw
  9309. */
  9310. THREE.BooleanKeyframeTrack = function ( name, times, values ) {
  9311. THREE.KeyframeTrack.call( this, name, times, values );
  9312. };
  9313. THREE.BooleanKeyframeTrack.prototype =
  9314. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9315. constructor: THREE.BooleanKeyframeTrack,
  9316. ValueTypeName: 'bool',
  9317. ValueBufferType: Array,
  9318. DefaultInterpolation: THREE.IntepolateDiscrete,
  9319. InterpolantFactoryMethodLinear: undefined,
  9320. InterpolantFactoryMethodSmooth: undefined
  9321. // Note: Actually this track could have a optimized / compressed
  9322. // representation of a single value and a custom interpolant that
  9323. // computes "firstValue ^ isOdd( index )".
  9324. } );
  9325. // File:src/animation/tracks/NumberKeyframeTrack.js
  9326. /**
  9327. *
  9328. * A Track of numeric keyframe values.
  9329. *
  9330. * @author Ben Houston / http://clara.io/
  9331. * @author David Sarno / http://lighthaus.us/
  9332. * @author tschw
  9333. */
  9334. THREE.NumberKeyframeTrack = function ( name, times, values, interpolation ) {
  9335. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9336. };
  9337. THREE.NumberKeyframeTrack.prototype =
  9338. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9339. constructor: THREE.NumberKeyframeTrack,
  9340. ValueTypeName: 'number',
  9341. // ValueBufferType is inherited
  9342. // DefaultInterpolation is inherited
  9343. } );
  9344. // File:src/animation/tracks/QuaternionKeyframeTrack.js
  9345. /**
  9346. *
  9347. * A Track of quaternion keyframe values.
  9348. *
  9349. * @author Ben Houston / http://clara.io/
  9350. * @author David Sarno / http://lighthaus.us/
  9351. * @author tschw
  9352. */
  9353. THREE.QuaternionKeyframeTrack = function ( name, times, values, interpolation ) {
  9354. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9355. };
  9356. THREE.QuaternionKeyframeTrack.prototype =
  9357. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9358. constructor: THREE.QuaternionKeyframeTrack,
  9359. ValueTypeName: 'quaternion',
  9360. // ValueBufferType is inherited
  9361. DefaultInterpolation: THREE.InterpolateLinear,
  9362. InterpolantFactoryMethodLinear: function( result ) {
  9363. return new THREE.QuaternionLinearInterpolant(
  9364. this.times, this.values, this.getValueSize(), result );
  9365. },
  9366. InterpolantFactoryMethodSmooth: undefined // not yet implemented
  9367. } );
  9368. // File:src/animation/tracks/StringKeyframeTrack.js
  9369. /**
  9370. *
  9371. * A Track that interpolates Strings
  9372. *
  9373. *
  9374. * @author Ben Houston / http://clara.io/
  9375. * @author David Sarno / http://lighthaus.us/
  9376. * @author tschw
  9377. */
  9378. THREE.StringKeyframeTrack = function ( name, times, values, interpolation ) {
  9379. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9380. };
  9381. THREE.StringKeyframeTrack.prototype =
  9382. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9383. constructor: THREE.StringKeyframeTrack,
  9384. ValueTypeName: 'string',
  9385. ValueBufferType: Array,
  9386. DefaultInterpolation: THREE.IntepolateDiscrete,
  9387. InterpolantFactoryMethodLinear: undefined,
  9388. InterpolantFactoryMethodSmooth: undefined
  9389. } );
  9390. // File:src/animation/tracks/VectorKeyframeTrack.js
  9391. /**
  9392. *
  9393. * A Track of vectored keyframe values.
  9394. *
  9395. *
  9396. * @author Ben Houston / http://clara.io/
  9397. * @author David Sarno / http://lighthaus.us/
  9398. * @author tschw
  9399. */
  9400. THREE.VectorKeyframeTrack = function ( name, times, values, interpolation ) {
  9401. THREE.KeyframeTrack.call( this, name, times, values, interpolation );
  9402. };
  9403. THREE.VectorKeyframeTrack.prototype =
  9404. Object.assign( Object.create( THREE.KeyframeTrack.prototype ), {
  9405. constructor: THREE.VectorKeyframeTrack,
  9406. ValueTypeName: 'vector'
  9407. // ValueBufferType is inherited
  9408. // DefaultInterpolation is inherited
  9409. } );
  9410. // File:src/audio/Audio.js
  9411. /**
  9412. * @author mrdoob / http://mrdoob.com/
  9413. */
  9414. THREE.Audio = function ( listener ) {
  9415. THREE.Object3D.call( this );
  9416. this.type = 'Audio';
  9417. this.context = listener.context;
  9418. this.source = this.context.createBufferSource();
  9419. this.source.onended = this.onEnded.bind( this );
  9420. this.gain = this.context.createGain();
  9421. this.gain.connect( listener.getInput() );
  9422. this.autoplay = false;
  9423. this.startTime = 0;
  9424. this.playbackRate = 1;
  9425. this.isPlaying = false;
  9426. this.hasPlaybackControl = true;
  9427. this.sourceType = 'empty';
  9428. this.filter = null;
  9429. };
  9430. THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
  9431. THREE.Audio.prototype.constructor = THREE.Audio;
  9432. THREE.Audio.prototype.getOutput = function () {
  9433. return this.gain;
  9434. };
  9435. THREE.Audio.prototype.load = function ( file ) {
  9436. var buffer = new THREE.AudioBuffer( this.context );
  9437. buffer.load( file );
  9438. this.setBuffer( buffer );
  9439. return this;
  9440. };
  9441. THREE.Audio.prototype.setNodeSource = function ( audioNode ) {
  9442. this.hasPlaybackControl = false;
  9443. this.sourceType = 'audioNode';
  9444. this.source = audioNode;
  9445. this.connect();
  9446. return this;
  9447. };
  9448. THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
  9449. var scope = this;
  9450. audioBuffer.onReady( function( buffer ) {
  9451. scope.source.buffer = buffer;
  9452. scope.sourceType = 'buffer';
  9453. if ( scope.autoplay ) scope.play();
  9454. } );
  9455. return this;
  9456. };
  9457. THREE.Audio.prototype.play = function () {
  9458. if ( this.isPlaying === true ) {
  9459. console.warn( 'THREE.Audio: Audio is already playing.' );
  9460. return;
  9461. }
  9462. if ( this.hasPlaybackControl === false ) {
  9463. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9464. return;
  9465. }
  9466. var source = this.context.createBufferSource();
  9467. source.buffer = this.source.buffer;
  9468. source.loop = this.source.loop;
  9469. source.onended = this.source.onended;
  9470. source.start( 0, this.startTime );
  9471. source.playbackRate.value = this.playbackRate;
  9472. this.isPlaying = true;
  9473. this.source = source;
  9474. this.connect();
  9475. };
  9476. THREE.Audio.prototype.pause = function () {
  9477. if ( this.hasPlaybackControl === false ) {
  9478. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9479. return;
  9480. }
  9481. this.source.stop();
  9482. this.startTime = this.context.currentTime;
  9483. };
  9484. THREE.Audio.prototype.stop = function () {
  9485. if ( this.hasPlaybackControl === false ) {
  9486. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9487. return;
  9488. }
  9489. this.source.stop();
  9490. this.startTime = 0;
  9491. };
  9492. THREE.Audio.prototype.connect = function () {
  9493. if ( this.filter !== null ) {
  9494. this.source.connect( this.filter );
  9495. this.filter.connect( this.getOutput() );
  9496. } else {
  9497. this.source.connect( this.getOutput() );
  9498. }
  9499. };
  9500. THREE.Audio.prototype.disconnect = function () {
  9501. if ( this.filter !== null ) {
  9502. this.source.disconnect( this.filter );
  9503. this.filter.disconnect( this.getOutput() );
  9504. } else {
  9505. this.source.disconnect( this.getOutput() );
  9506. }
  9507. };
  9508. THREE.Audio.prototype.getFilter = function () {
  9509. return this.filter;
  9510. };
  9511. THREE.Audio.prototype.setFilter = function ( value ) {
  9512. if ( value === undefined ) value = null;
  9513. if ( this.isPlaying === true ) {
  9514. this.disconnect();
  9515. this.filter = value;
  9516. this.connect();
  9517. } else {
  9518. this.filter = value;
  9519. }
  9520. };
  9521. THREE.Audio.prototype.setPlaybackRate = function ( value ) {
  9522. if ( this.hasPlaybackControl === false ) {
  9523. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9524. return;
  9525. }
  9526. this.playbackRate = value;
  9527. if ( this.isPlaying === true ) {
  9528. this.source.playbackRate.value = this.playbackRate;
  9529. }
  9530. };
  9531. THREE.Audio.prototype.getPlaybackRate = function () {
  9532. return this.playbackRate;
  9533. };
  9534. THREE.Audio.prototype.onEnded = function() {
  9535. this.isPlaying = false;
  9536. };
  9537. THREE.Audio.prototype.setLoop = function ( value ) {
  9538. if ( this.hasPlaybackControl === false ) {
  9539. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9540. return;
  9541. }
  9542. this.source.loop = value;
  9543. };
  9544. THREE.Audio.prototype.getLoop = function () {
  9545. if ( this.hasPlaybackControl === false ) {
  9546. console.warn( 'THREE.Audio: this Audio has no playback control.' );
  9547. return false;
  9548. }
  9549. return this.source.loop;
  9550. };
  9551. THREE.Audio.prototype.setVolume = function ( value ) {
  9552. this.gain.gain.value = value;
  9553. };
  9554. THREE.Audio.prototype.getVolume = function () {
  9555. return this.gain.gain.value;
  9556. };
  9557. // File:src/audio/AudioAnalyser.js
  9558. /**
  9559. * @author mrdoob / http://mrdoob.com/
  9560. */
  9561. THREE.AudioAnalyser = function ( audio, fftSize ) {
  9562. this.analyser = audio.context.createAnalyser();
  9563. this.analyser.fftSize = fftSize !== undefined ? fftSize : 2048;
  9564. this.data = new Uint8Array( this.analyser.frequencyBinCount );
  9565. audio.getOutput().connect( this.analyser );
  9566. };
  9567. THREE.AudioAnalyser.prototype = {
  9568. constructor: THREE.AudioAnalyser,
  9569. getData: function () {
  9570. this.analyser.getByteFrequencyData( this.data );
  9571. return this.data;
  9572. }
  9573. };
  9574. // File:src/audio/AudioBuffer.js
  9575. /**
  9576. * @author mrdoob / http://mrdoob.com/
  9577. */
  9578. THREE.AudioBuffer = function ( context ) {
  9579. this.context = context;
  9580. this.ready = false;
  9581. this.readyCallbacks = [];
  9582. };
  9583. THREE.AudioBuffer.prototype.load = function ( file ) {
  9584. var scope = this;
  9585. var request = new XMLHttpRequest();
  9586. request.open( 'GET', file, true );
  9587. request.responseType = 'arraybuffer';
  9588. request.onload = function ( e ) {
  9589. scope.context.decodeAudioData( this.response, function ( buffer ) {
  9590. scope.buffer = buffer;
  9591. scope.ready = true;
  9592. for ( var i = 0; i < scope.readyCallbacks.length; i ++ ) {
  9593. scope.readyCallbacks[ i ]( scope.buffer );
  9594. }
  9595. scope.readyCallbacks = [];
  9596. } );
  9597. };
  9598. request.send();
  9599. return this;
  9600. };
  9601. THREE.AudioBuffer.prototype.onReady = function ( callback ) {
  9602. if ( this.ready ) {
  9603. callback( this.buffer );
  9604. } else {
  9605. this.readyCallbacks.push( callback );
  9606. }
  9607. };
  9608. // File:src/audio/PositionalAudio.js
  9609. /**
  9610. * @author mrdoob / http://mrdoob.com/
  9611. */
  9612. THREE.PositionalAudio = function ( listener ) {
  9613. THREE.Audio.call( this, listener );
  9614. this.panner = this.context.createPanner();
  9615. this.panner.connect( this.gain );
  9616. };
  9617. THREE.PositionalAudio.prototype = Object.create( THREE.Audio.prototype );
  9618. THREE.PositionalAudio.prototype.constructor = THREE.PositionalAudio;
  9619. THREE.PositionalAudio.prototype.getOutput = function () {
  9620. return this.panner;
  9621. };
  9622. THREE.PositionalAudio.prototype.setRefDistance = function ( value ) {
  9623. this.panner.refDistance = value;
  9624. };
  9625. THREE.PositionalAudio.prototype.getRefDistance = function () {
  9626. return this.panner.refDistance;
  9627. };
  9628. THREE.PositionalAudio.prototype.setRolloffFactor = function ( value ) {
  9629. this.panner.rolloffFactor = value;
  9630. };
  9631. THREE.PositionalAudio.prototype.getRolloffFactor = function () {
  9632. return this.panner.rolloffFactor;
  9633. };
  9634. THREE.PositionalAudio.prototype.setDistanceModel = function ( value ) {
  9635. this.panner.distanceModel = value;
  9636. };
  9637. THREE.PositionalAudio.prototype.getDistanceModel = function () {
  9638. return this.panner.distanceModel;
  9639. };
  9640. THREE.PositionalAudio.prototype.setMaxDistance = function ( value ) {
  9641. this.panner.maxDistance = value;
  9642. };
  9643. THREE.PositionalAudio.prototype.getMaxDistance = function () {
  9644. return this.panner.maxDistance;
  9645. };
  9646. THREE.PositionalAudio.prototype.updateMatrixWorld = ( function () {
  9647. var position = new THREE.Vector3();
  9648. return function updateMatrixWorld( force ) {
  9649. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9650. position.setFromMatrixPosition( this.matrixWorld );
  9651. this.panner.setPosition( position.x, position.y, position.z );
  9652. };
  9653. } )();
  9654. // File:src/audio/AudioListener.js
  9655. /**
  9656. * @author mrdoob / http://mrdoob.com/
  9657. */
  9658. THREE.AudioListener = function () {
  9659. THREE.Object3D.call( this );
  9660. this.type = 'AudioListener';
  9661. this.context = new ( window.AudioContext || window.webkitAudioContext )();
  9662. this.gain = this.context.createGain();
  9663. this.gain.connect( this.context.destination );
  9664. this.filter = null;
  9665. };
  9666. THREE.AudioListener.prototype = Object.create( THREE.Object3D.prototype );
  9667. THREE.AudioListener.prototype.constructor = THREE.AudioListener;
  9668. THREE.AudioListener.prototype.getInput = function () {
  9669. return this.gain;
  9670. };
  9671. THREE.AudioListener.prototype.removeFilter = function ( ) {
  9672. if ( this.filter !== null ) {
  9673. this.gain.disconnect( this.filter );
  9674. this.filter.disconnect( this.context.destination );
  9675. this.gain.connect( this.context.destination );
  9676. this.filter = null;
  9677. }
  9678. };
  9679. THREE.AudioListener.prototype.setFilter = function ( value ) {
  9680. if ( this.filter !== null ) {
  9681. this.gain.disconnect( this.filter );
  9682. this.filter.disconnect( this.context.destination );
  9683. } else {
  9684. this.gain.disconnect( this.context.destination );
  9685. }
  9686. this.filter = value;
  9687. this.gain.connect( this.filter );
  9688. this.filter.connect( this.context.destination );
  9689. };
  9690. THREE.AudioListener.prototype.getFilter = function () {
  9691. return this.filter;
  9692. };
  9693. THREE.AudioListener.prototype.setMasterVolume = function ( value ) {
  9694. this.gain.gain.value = value;
  9695. };
  9696. THREE.AudioListener.prototype.getMasterVolume = function () {
  9697. return this.gain.gain.value;
  9698. };
  9699. THREE.AudioListener.prototype.updateMatrixWorld = ( function () {
  9700. var position = new THREE.Vector3();
  9701. var quaternion = new THREE.Quaternion();
  9702. var scale = new THREE.Vector3();
  9703. var orientation = new THREE.Vector3();
  9704. return function updateMatrixWorld( force ) {
  9705. THREE.Object3D.prototype.updateMatrixWorld.call( this, force );
  9706. var listener = this.context.listener;
  9707. var up = this.up;
  9708. this.matrixWorld.decompose( position, quaternion, scale );
  9709. orientation.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9710. listener.setPosition( position.x, position.y, position.z );
  9711. listener.setOrientation( orientation.x, orientation.y, orientation.z, up.x, up.y, up.z );
  9712. };
  9713. } )();
  9714. // File:src/cameras/Camera.js
  9715. /**
  9716. * @author mrdoob / http://mrdoob.com/
  9717. * @author mikael emtinger / http://gomo.se/
  9718. * @author WestLangley / http://github.com/WestLangley
  9719. */
  9720. THREE.Camera = function () {
  9721. THREE.Object3D.call( this );
  9722. this.type = 'Camera';
  9723. this.matrixWorldInverse = new THREE.Matrix4();
  9724. this.projectionMatrix = new THREE.Matrix4();
  9725. };
  9726. THREE.Camera.prototype = Object.create( THREE.Object3D.prototype );
  9727. THREE.Camera.prototype.constructor = THREE.Camera;
  9728. THREE.Camera.prototype.getWorldDirection = function () {
  9729. var quaternion = new THREE.Quaternion();
  9730. return function ( optionalTarget ) {
  9731. var result = optionalTarget || new THREE.Vector3();
  9732. this.getWorldQuaternion( quaternion );
  9733. return result.set( 0, 0, - 1 ).applyQuaternion( quaternion );
  9734. };
  9735. }();
  9736. THREE.Camera.prototype.lookAt = function () {
  9737. // This routine does not support cameras with rotated and/or translated parent(s)
  9738. var m1 = new THREE.Matrix4();
  9739. return function ( vector ) {
  9740. m1.lookAt( this.position, vector, this.up );
  9741. this.quaternion.setFromRotationMatrix( m1 );
  9742. };
  9743. }();
  9744. THREE.Camera.prototype.clone = function () {
  9745. return new this.constructor().copy( this );
  9746. };
  9747. THREE.Camera.prototype.copy = function ( source ) {
  9748. THREE.Object3D.prototype.copy.call( this, source );
  9749. this.matrixWorldInverse.copy( source.matrixWorldInverse );
  9750. this.projectionMatrix.copy( source.projectionMatrix );
  9751. return this;
  9752. };
  9753. // File:src/cameras/CubeCamera.js
  9754. /**
  9755. * Camera for rendering cube maps
  9756. * - renders scene into axis-aligned cube
  9757. *
  9758. * @author alteredq / http://alteredqualia.com/
  9759. */
  9760. THREE.CubeCamera = function ( near, far, cubeResolution ) {
  9761. THREE.Object3D.call( this );
  9762. this.type = 'CubeCamera';
  9763. var fov = 90, aspect = 1;
  9764. var cameraPX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9765. cameraPX.up.set( 0, - 1, 0 );
  9766. cameraPX.lookAt( new THREE.Vector3( 1, 0, 0 ) );
  9767. this.add( cameraPX );
  9768. var cameraNX = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9769. cameraNX.up.set( 0, - 1, 0 );
  9770. cameraNX.lookAt( new THREE.Vector3( - 1, 0, 0 ) );
  9771. this.add( cameraNX );
  9772. var cameraPY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9773. cameraPY.up.set( 0, 0, 1 );
  9774. cameraPY.lookAt( new THREE.Vector3( 0, 1, 0 ) );
  9775. this.add( cameraPY );
  9776. var cameraNY = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9777. cameraNY.up.set( 0, 0, - 1 );
  9778. cameraNY.lookAt( new THREE.Vector3( 0, - 1, 0 ) );
  9779. this.add( cameraNY );
  9780. var cameraPZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9781. cameraPZ.up.set( 0, - 1, 0 );
  9782. cameraPZ.lookAt( new THREE.Vector3( 0, 0, 1 ) );
  9783. this.add( cameraPZ );
  9784. var cameraNZ = new THREE.PerspectiveCamera( fov, aspect, near, far );
  9785. cameraNZ.up.set( 0, - 1, 0 );
  9786. cameraNZ.lookAt( new THREE.Vector3( 0, 0, - 1 ) );
  9787. this.add( cameraNZ );
  9788. var options = { format: THREE.RGBFormat, magFilter: THREE.LinearFilter, minFilter: THREE.LinearFilter };
  9789. this.renderTarget = new THREE.WebGLRenderTargetCube( cubeResolution, cubeResolution, options );
  9790. this.updateCubeMap = function ( renderer, scene ) {
  9791. if ( this.parent === null ) this.updateMatrixWorld();
  9792. var renderTarget = this.renderTarget;
  9793. var generateMipmaps = renderTarget.texture.generateMipmaps;
  9794. renderTarget.texture.generateMipmaps = false;
  9795. renderTarget.activeCubeFace = 0;
  9796. renderer.render( scene, cameraPX, renderTarget );
  9797. renderTarget.activeCubeFace = 1;
  9798. renderer.render( scene, cameraNX, renderTarget );
  9799. renderTarget.activeCubeFace = 2;
  9800. renderer.render( scene, cameraPY, renderTarget );
  9801. renderTarget.activeCubeFace = 3;
  9802. renderer.render( scene, cameraNY, renderTarget );
  9803. renderTarget.activeCubeFace = 4;
  9804. renderer.render( scene, cameraPZ, renderTarget );
  9805. renderTarget.texture.generateMipmaps = generateMipmaps;
  9806. renderTarget.activeCubeFace = 5;
  9807. renderer.render( scene, cameraNZ, renderTarget );
  9808. renderer.setRenderTarget( null );
  9809. };
  9810. };
  9811. THREE.CubeCamera.prototype = Object.create( THREE.Object3D.prototype );
  9812. THREE.CubeCamera.prototype.constructor = THREE.CubeCamera;
  9813. // File:src/cameras/OrthographicCamera.js
  9814. /**
  9815. * @author alteredq / http://alteredqualia.com/
  9816. */
  9817. THREE.OrthographicCamera = function ( left, right, top, bottom, near, far ) {
  9818. THREE.Camera.call( this );
  9819. this.type = 'OrthographicCamera';
  9820. this.zoom = 1;
  9821. this.left = left;
  9822. this.right = right;
  9823. this.top = top;
  9824. this.bottom = bottom;
  9825. this.near = ( near !== undefined ) ? near : 0.1;
  9826. this.far = ( far !== undefined ) ? far : 2000;
  9827. this.updateProjectionMatrix();
  9828. };
  9829. THREE.OrthographicCamera.prototype = Object.create( THREE.Camera.prototype );
  9830. THREE.OrthographicCamera.prototype.constructor = THREE.OrthographicCamera;
  9831. THREE.OrthographicCamera.prototype.updateProjectionMatrix = function () {
  9832. var dx = ( this.right - this.left ) / ( 2 * this.zoom );
  9833. var dy = ( this.top - this.bottom ) / ( 2 * this.zoom );
  9834. var cx = ( this.right + this.left ) / 2;
  9835. var cy = ( this.top + this.bottom ) / 2;
  9836. this.projectionMatrix.makeOrthographic( cx - dx, cx + dx, cy + dy, cy - dy, this.near, this.far );
  9837. };
  9838. THREE.OrthographicCamera.prototype.copy = function ( source ) {
  9839. THREE.Camera.prototype.copy.call( this, source );
  9840. this.left = source.left;
  9841. this.right = source.right;
  9842. this.top = source.top;
  9843. this.bottom = source.bottom;
  9844. this.near = source.near;
  9845. this.far = source.far;
  9846. this.zoom = source.zoom;
  9847. return this;
  9848. };
  9849. THREE.OrthographicCamera.prototype.toJSON = function ( meta ) {
  9850. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9851. data.object.zoom = this.zoom;
  9852. data.object.left = this.left;
  9853. data.object.right = this.right;
  9854. data.object.top = this.top;
  9855. data.object.bottom = this.bottom;
  9856. data.object.near = this.near;
  9857. data.object.far = this.far;
  9858. return data;
  9859. };
  9860. // File:src/cameras/PerspectiveCamera.js
  9861. /**
  9862. * @author mrdoob / http://mrdoob.com/
  9863. * @author greggman / http://games.greggman.com/
  9864. * @author zz85 / http://www.lab4games.net/zz85/blog
  9865. */
  9866. THREE.PerspectiveCamera = function ( fov, aspect, near, far ) {
  9867. THREE.Camera.call( this );
  9868. this.type = 'PerspectiveCamera';
  9869. this.focalLength = 10;
  9870. this.zoom = 1;
  9871. this.fov = fov !== undefined ? fov : 50;
  9872. this.aspect = aspect !== undefined ? aspect : 1;
  9873. this.near = near !== undefined ? near : 0.1;
  9874. this.far = far !== undefined ? far : 2000;
  9875. this.updateProjectionMatrix();
  9876. };
  9877. THREE.PerspectiveCamera.prototype = Object.create( THREE.Camera.prototype );
  9878. THREE.PerspectiveCamera.prototype.constructor = THREE.PerspectiveCamera;
  9879. /**
  9880. * Uses Focal Length (in mm) to estimate and set FOV
  9881. * 35mm (full-frame) camera is used if frame size is not specified;
  9882. * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html
  9883. */
  9884. THREE.PerspectiveCamera.prototype.setLens = function ( focalLength, frameHeight ) {
  9885. if ( frameHeight === undefined ) frameHeight = 24;
  9886. this.fov = 2 * THREE.Math.radToDeg( Math.atan( frameHeight / ( focalLength * 2 ) ) );
  9887. this.updateProjectionMatrix();
  9888. };
  9889. /**
  9890. * Sets an offset in a larger frustum. This is useful for multi-window or
  9891. * multi-monitor/multi-machine setups.
  9892. *
  9893. * For example, if you have 3x2 monitors and each monitor is 1920x1080 and
  9894. * the monitors are in grid like this
  9895. *
  9896. * +---+---+---+
  9897. * | A | B | C |
  9898. * +---+---+---+
  9899. * | D | E | F |
  9900. * +---+---+---+
  9901. *
  9902. * then for each monitor you would call it like this
  9903. *
  9904. * var w = 1920;
  9905. * var h = 1080;
  9906. * var fullWidth = w * 3;
  9907. * var fullHeight = h * 2;
  9908. *
  9909. * --A--
  9910. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 0, w, h );
  9911. * --B--
  9912. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 0, w, h );
  9913. * --C--
  9914. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 0, w, h );
  9915. * --D--
  9916. * camera.setOffset( fullWidth, fullHeight, w * 0, h * 1, w, h );
  9917. * --E--
  9918. * camera.setOffset( fullWidth, fullHeight, w * 1, h * 1, w, h );
  9919. * --F--
  9920. * camera.setOffset( fullWidth, fullHeight, w * 2, h * 1, w, h );
  9921. *
  9922. * Note there is no reason monitors have to be the same size or in a grid.
  9923. */
  9924. THREE.PerspectiveCamera.prototype.setViewOffset = function ( fullWidth, fullHeight, x, y, width, height ) {
  9925. this.fullWidth = fullWidth;
  9926. this.fullHeight = fullHeight;
  9927. this.x = x;
  9928. this.y = y;
  9929. this.width = width;
  9930. this.height = height;
  9931. this.updateProjectionMatrix();
  9932. };
  9933. THREE.PerspectiveCamera.prototype.updateProjectionMatrix = function () {
  9934. var fov = THREE.Math.radToDeg( 2 * Math.atan( Math.tan( THREE.Math.degToRad( this.fov ) * 0.5 ) / this.zoom ) );
  9935. if ( this.fullWidth ) {
  9936. var aspect = this.fullWidth / this.fullHeight;
  9937. var top = Math.tan( THREE.Math.degToRad( fov * 0.5 ) ) * this.near;
  9938. var bottom = - top;
  9939. var left = aspect * bottom;
  9940. var right = aspect * top;
  9941. var width = Math.abs( right - left );
  9942. var height = Math.abs( top - bottom );
  9943. this.projectionMatrix.makeFrustum(
  9944. left + this.x * width / this.fullWidth,
  9945. left + ( this.x + this.width ) * width / this.fullWidth,
  9946. top - ( this.y + this.height ) * height / this.fullHeight,
  9947. top - this.y * height / this.fullHeight,
  9948. this.near,
  9949. this.far
  9950. );
  9951. } else {
  9952. this.projectionMatrix.makePerspective( fov, this.aspect, this.near, this.far );
  9953. }
  9954. };
  9955. THREE.PerspectiveCamera.prototype.copy = function ( source ) {
  9956. THREE.Camera.prototype.copy.call( this, source );
  9957. this.focalLength = source.focalLength;
  9958. this.zoom = source.zoom;
  9959. this.fov = source.fov;
  9960. this.aspect = source.aspect;
  9961. this.near = source.near;
  9962. this.far = source.far;
  9963. return this;
  9964. };
  9965. THREE.PerspectiveCamera.prototype.toJSON = function ( meta ) {
  9966. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  9967. data.object.focalLength = this.focalLength;
  9968. data.object.zoom = this.zoom;
  9969. data.object.fov = this.fov;
  9970. data.object.aspect = this.aspect;
  9971. data.object.near = this.near;
  9972. data.object.far = this.far;
  9973. return data;
  9974. };
  9975. // File:src/cameras/StereoCamera.js
  9976. /**
  9977. * @author mrdoob / http://mrdoob.com/
  9978. */
  9979. THREE.StereoCamera = function () {
  9980. this.type = 'StereoCamera';
  9981. this.aspect = 1;
  9982. this.cameraL = new THREE.PerspectiveCamera();
  9983. this.cameraL.layers.enable( 1 );
  9984. this.cameraL.matrixAutoUpdate = false;
  9985. this.cameraR = new THREE.PerspectiveCamera();
  9986. this.cameraR.layers.enable( 2 );
  9987. this.cameraR.matrixAutoUpdate = false;
  9988. };
  9989. THREE.StereoCamera.prototype = {
  9990. constructor: THREE.StereoCamera,
  9991. update: ( function () {
  9992. var focalLength, fov, aspect, near, far;
  9993. var eyeRight = new THREE.Matrix4();
  9994. var eyeLeft = new THREE.Matrix4();
  9995. return function update ( camera ) {
  9996. var needsUpdate = focalLength !== camera.focalLength || fov !== camera.fov ||
  9997. aspect !== camera.aspect * this.aspect || near !== camera.near ||
  9998. far !== camera.far;
  9999. if ( needsUpdate ) {
  10000. focalLength = camera.focalLength;
  10001. fov = camera.fov;
  10002. aspect = camera.aspect * this.aspect;
  10003. near = camera.near;
  10004. far = camera.far;
  10005. // Off-axis stereoscopic effect based on
  10006. // http://paulbourke.net/stereographics/stereorender/
  10007. var projectionMatrix = camera.projectionMatrix.clone();
  10008. var eyeSep = 0.064 / 2;
  10009. var eyeSepOnProjection = eyeSep * near / focalLength;
  10010. var ymax = near * Math.tan( THREE.Math.degToRad( fov * 0.5 ) );
  10011. var xmin, xmax;
  10012. // translate xOffset
  10013. eyeLeft.elements[ 12 ] = - eyeSep;
  10014. eyeRight.elements[ 12 ] = eyeSep;
  10015. // for left eye
  10016. xmin = - ymax * aspect + eyeSepOnProjection;
  10017. xmax = ymax * aspect + eyeSepOnProjection;
  10018. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10019. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10020. this.cameraL.projectionMatrix.copy( projectionMatrix );
  10021. // for right eye
  10022. xmin = - ymax * aspect - eyeSepOnProjection;
  10023. xmax = ymax * aspect - eyeSepOnProjection;
  10024. projectionMatrix.elements[ 0 ] = 2 * near / ( xmax - xmin );
  10025. projectionMatrix.elements[ 8 ] = ( xmax + xmin ) / ( xmax - xmin );
  10026. this.cameraR.projectionMatrix.copy( projectionMatrix );
  10027. }
  10028. this.cameraL.matrixWorld.copy( camera.matrixWorld ).multiply( eyeLeft );
  10029. this.cameraR.matrixWorld.copy( camera.matrixWorld ).multiply( eyeRight );
  10030. };
  10031. } )()
  10032. };
  10033. // File:src/lights/Light.js
  10034. /**
  10035. * @author mrdoob / http://mrdoob.com/
  10036. * @author alteredq / http://alteredqualia.com/
  10037. */
  10038. THREE.Light = function ( color, intensity ) {
  10039. THREE.Object3D.call( this );
  10040. this.type = 'Light';
  10041. this.color = new THREE.Color( color );
  10042. this.intensity = intensity !== undefined ? intensity : 1;
  10043. this.receiveShadow = undefined;
  10044. };
  10045. THREE.Light.prototype = Object.create( THREE.Object3D.prototype );
  10046. THREE.Light.prototype.constructor = THREE.Light;
  10047. THREE.Light.prototype.copy = function ( source ) {
  10048. THREE.Object3D.prototype.copy.call( this, source );
  10049. this.color.copy( source.color );
  10050. this.intensity = source.intensity;
  10051. return this;
  10052. };
  10053. THREE.Light.prototype.toJSON = function ( meta ) {
  10054. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  10055. data.object.color = this.color.getHex();
  10056. data.object.intensity = this.intensity;
  10057. if ( this.groundColor !== undefined ) data.object.groundColor = this.groundColor.getHex();
  10058. if ( this.distance !== undefined ) data.object.distance = this.distance;
  10059. if ( this.angle !== undefined ) data.object.angle = this.angle;
  10060. if ( this.decay !== undefined ) data.object.decay = this.decay;
  10061. if ( this.penumbra !== undefined ) data.object.penumbra = this.penumbra;
  10062. return data;
  10063. };
  10064. // File:src/lights/LightShadow.js
  10065. /**
  10066. * @author mrdoob / http://mrdoob.com/
  10067. */
  10068. THREE.LightShadow = function ( camera ) {
  10069. this.camera = camera;
  10070. this.bias = 0;
  10071. this.radius = 1;
  10072. this.mapSize = new THREE.Vector2( 512, 512 );
  10073. this.map = null;
  10074. this.matrix = new THREE.Matrix4();
  10075. };
  10076. THREE.LightShadow.prototype = {
  10077. constructor: THREE.LightShadow,
  10078. copy: function ( source ) {
  10079. this.camera = source.camera.clone();
  10080. this.bias = source.bias;
  10081. this.radius = source.radius;
  10082. this.mapSize.copy( source.mapSize );
  10083. return this;
  10084. },
  10085. clone: function () {
  10086. return new this.constructor().copy( this );
  10087. }
  10088. };
  10089. // File:src/lights/AmbientLight.js
  10090. /**
  10091. * @author mrdoob / http://mrdoob.com/
  10092. */
  10093. THREE.AmbientLight = function ( color, intensity ) {
  10094. THREE.Light.call( this, color, intensity );
  10095. this.type = 'AmbientLight';
  10096. this.castShadow = undefined;
  10097. };
  10098. THREE.AmbientLight.prototype = Object.create( THREE.Light.prototype );
  10099. THREE.AmbientLight.prototype.constructor = THREE.AmbientLight;
  10100. // File:src/lights/DirectionalLight.js
  10101. /**
  10102. * @author mrdoob / http://mrdoob.com/
  10103. * @author alteredq / http://alteredqualia.com/
  10104. */
  10105. THREE.DirectionalLight = function ( color, intensity ) {
  10106. THREE.Light.call( this, color, intensity );
  10107. this.type = 'DirectionalLight';
  10108. this.position.set( 0, 1, 0 );
  10109. this.updateMatrix();
  10110. this.target = new THREE.Object3D();
  10111. this.shadow = new THREE.LightShadow( new THREE.OrthographicCamera( - 5, 5, 5, - 5, 0.5, 500 ) );
  10112. };
  10113. THREE.DirectionalLight.prototype = Object.create( THREE.Light.prototype );
  10114. THREE.DirectionalLight.prototype.constructor = THREE.DirectionalLight;
  10115. THREE.DirectionalLight.prototype.copy = function ( source ) {
  10116. THREE.Light.prototype.copy.call( this, source );
  10117. this.target = source.target.clone();
  10118. this.shadow = source.shadow.clone();
  10119. return this;
  10120. };
  10121. // File:src/lights/HemisphereLight.js
  10122. /**
  10123. * @author alteredq / http://alteredqualia.com/
  10124. */
  10125. THREE.HemisphereLight = function ( skyColor, groundColor, intensity ) {
  10126. THREE.Light.call( this, skyColor, intensity );
  10127. this.type = 'HemisphereLight';
  10128. this.castShadow = undefined;
  10129. this.position.set( 0, 1, 0 );
  10130. this.updateMatrix();
  10131. this.groundColor = new THREE.Color( groundColor );
  10132. };
  10133. THREE.HemisphereLight.prototype = Object.create( THREE.Light.prototype );
  10134. THREE.HemisphereLight.prototype.constructor = THREE.HemisphereLight;
  10135. THREE.HemisphereLight.prototype.copy = function ( source ) {
  10136. THREE.Light.prototype.copy.call( this, source );
  10137. this.groundColor.copy( source.groundColor );
  10138. return this;
  10139. };
  10140. // File:src/lights/PointLight.js
  10141. /**
  10142. * @author mrdoob / http://mrdoob.com/
  10143. */
  10144. THREE.PointLight = function ( color, intensity, distance, decay ) {
  10145. THREE.Light.call( this, color, intensity );
  10146. this.type = 'PointLight';
  10147. this.distance = ( distance !== undefined ) ? distance : 0;
  10148. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10149. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 90, 1, 0.5, 500 ) );
  10150. };
  10151. THREE.PointLight.prototype = Object.create( THREE.Light.prototype );
  10152. THREE.PointLight.prototype.constructor = THREE.PointLight;
  10153. THREE.PointLight.prototype.copy = function ( source ) {
  10154. THREE.Light.prototype.copy.call( this, source );
  10155. this.distance = source.distance;
  10156. this.decay = source.decay;
  10157. this.shadow = source.shadow.clone();
  10158. return this;
  10159. };
  10160. // File:src/lights/SpotLight.js
  10161. /**
  10162. * @author alteredq / http://alteredqualia.com/
  10163. */
  10164. THREE.SpotLight = function ( color, intensity, distance, angle, penumbra, decay ) {
  10165. THREE.Light.call( this, color, intensity );
  10166. this.type = 'SpotLight';
  10167. this.position.set( 0, 1, 0 );
  10168. this.updateMatrix();
  10169. this.target = new THREE.Object3D();
  10170. this.distance = ( distance !== undefined ) ? distance : 0;
  10171. this.angle = ( angle !== undefined ) ? angle : Math.PI / 3;
  10172. this.penumbra = ( penumbra !== undefined ) ? penumbra : 0;
  10173. this.decay = ( decay !== undefined ) ? decay : 1; // for physically correct lights, should be 2.
  10174. this.shadow = new THREE.LightShadow( new THREE.PerspectiveCamera( 50, 1, 0.5, 500 ) );
  10175. };
  10176. THREE.SpotLight.prototype = Object.create( THREE.Light.prototype );
  10177. THREE.SpotLight.prototype.constructor = THREE.SpotLight;
  10178. THREE.SpotLight.prototype.copy = function ( source ) {
  10179. THREE.Light.prototype.copy.call( this, source );
  10180. this.distance = source.distance;
  10181. this.angle = source.angle;
  10182. this.penumbra = source.penumbra;
  10183. this.decay = source.decay;
  10184. this.target = source.target.clone();
  10185. this.shadow = source.shadow.clone();
  10186. return this;
  10187. };
  10188. // File:src/loaders/Cache.js
  10189. /**
  10190. * @author mrdoob / http://mrdoob.com/
  10191. */
  10192. THREE.Cache = {
  10193. enabled: false,
  10194. files: {},
  10195. add: function ( key, file ) {
  10196. if ( this.enabled === false ) return;
  10197. // console.log( 'THREE.Cache', 'Adding key:', key );
  10198. this.files[ key ] = file;
  10199. },
  10200. get: function ( key ) {
  10201. if ( this.enabled === false ) return;
  10202. // console.log( 'THREE.Cache', 'Checking key:', key );
  10203. return this.files[ key ];
  10204. },
  10205. remove: function ( key ) {
  10206. delete this.files[ key ];
  10207. },
  10208. clear: function () {
  10209. this.files = {};
  10210. }
  10211. };
  10212. // File:src/loaders/Loader.js
  10213. /**
  10214. * @author alteredq / http://alteredqualia.com/
  10215. */
  10216. THREE.Loader = function () {
  10217. this.onLoadStart = function () {};
  10218. this.onLoadProgress = function () {};
  10219. this.onLoadComplete = function () {};
  10220. };
  10221. THREE.Loader.prototype = {
  10222. constructor: THREE.Loader,
  10223. crossOrigin: undefined,
  10224. extractUrlBase: function ( url ) {
  10225. var parts = url.split( '/' );
  10226. if ( parts.length === 1 ) return './';
  10227. parts.pop();
  10228. return parts.join( '/' ) + '/';
  10229. },
  10230. initMaterials: function ( materials, texturePath, crossOrigin ) {
  10231. var array = [];
  10232. for ( var i = 0; i < materials.length; ++ i ) {
  10233. array[ i ] = this.createMaterial( materials[ i ], texturePath, crossOrigin );
  10234. }
  10235. return array;
  10236. },
  10237. createMaterial: ( function () {
  10238. var color, textureLoader, materialLoader;
  10239. return function ( m, texturePath, crossOrigin ) {
  10240. if ( color === undefined ) color = new THREE.Color();
  10241. if ( textureLoader === undefined ) textureLoader = new THREE.TextureLoader();
  10242. if ( materialLoader === undefined ) materialLoader = new THREE.MaterialLoader();
  10243. // convert from old material format
  10244. var textures = {};
  10245. function loadTexture( path, repeat, offset, wrap, anisotropy ) {
  10246. var fullPath = texturePath + path;
  10247. var loader = THREE.Loader.Handlers.get( fullPath );
  10248. var texture;
  10249. if ( loader !== null ) {
  10250. texture = loader.load( fullPath );
  10251. } else {
  10252. textureLoader.setCrossOrigin( crossOrigin );
  10253. texture = textureLoader.load( fullPath );
  10254. }
  10255. if ( repeat !== undefined ) {
  10256. texture.repeat.fromArray( repeat );
  10257. if ( repeat[ 0 ] !== 1 ) texture.wrapS = THREE.RepeatWrapping;
  10258. if ( repeat[ 1 ] !== 1 ) texture.wrapT = THREE.RepeatWrapping;
  10259. }
  10260. if ( offset !== undefined ) {
  10261. texture.offset.fromArray( offset );
  10262. }
  10263. if ( wrap !== undefined ) {
  10264. if ( wrap[ 0 ] === 'repeat' ) texture.wrapS = THREE.RepeatWrapping;
  10265. if ( wrap[ 0 ] === 'mirror' ) texture.wrapS = THREE.MirroredRepeatWrapping;
  10266. if ( wrap[ 1 ] === 'repeat' ) texture.wrapT = THREE.RepeatWrapping;
  10267. if ( wrap[ 1 ] === 'mirror' ) texture.wrapT = THREE.MirroredRepeatWrapping;
  10268. }
  10269. if ( anisotropy !== undefined ) {
  10270. texture.anisotropy = anisotropy;
  10271. }
  10272. var uuid = THREE.Math.generateUUID();
  10273. textures[ uuid ] = texture;
  10274. return uuid;
  10275. }
  10276. //
  10277. var json = {
  10278. uuid: THREE.Math.generateUUID(),
  10279. type: 'MeshLambertMaterial'
  10280. };
  10281. for ( var name in m ) {
  10282. var value = m[ name ];
  10283. switch ( name ) {
  10284. case 'DbgColor':
  10285. case 'DbgIndex':
  10286. case 'opticalDensity':
  10287. case 'illumination':
  10288. break;
  10289. case 'DbgName':
  10290. json.name = value;
  10291. break;
  10292. case 'blending':
  10293. json.blending = THREE[ value ];
  10294. break;
  10295. case 'colorAmbient':
  10296. case 'mapAmbient':
  10297. console.warn( 'THREE.Loader.createMaterial:', name, 'is no longer supported.' );
  10298. break;
  10299. case 'colorDiffuse':
  10300. json.color = color.fromArray( value ).getHex();
  10301. break;
  10302. case 'colorSpecular':
  10303. json.specular = color.fromArray( value ).getHex();
  10304. break;
  10305. case 'colorEmissive':
  10306. json.emissive = color.fromArray( value ).getHex();
  10307. break;
  10308. case 'specularCoef':
  10309. json.shininess = value;
  10310. break;
  10311. case 'shading':
  10312. if ( value.toLowerCase() === 'basic' ) json.type = 'MeshBasicMaterial';
  10313. if ( value.toLowerCase() === 'phong' ) json.type = 'MeshPhongMaterial';
  10314. break;
  10315. case 'mapDiffuse':
  10316. json.map = loadTexture( value, m.mapDiffuseRepeat, m.mapDiffuseOffset, m.mapDiffuseWrap, m.mapDiffuseAnisotropy );
  10317. break;
  10318. case 'mapDiffuseRepeat':
  10319. case 'mapDiffuseOffset':
  10320. case 'mapDiffuseWrap':
  10321. case 'mapDiffuseAnisotropy':
  10322. break;
  10323. case 'mapLight':
  10324. json.lightMap = loadTexture( value, m.mapLightRepeat, m.mapLightOffset, m.mapLightWrap, m.mapLightAnisotropy );
  10325. break;
  10326. case 'mapLightRepeat':
  10327. case 'mapLightOffset':
  10328. case 'mapLightWrap':
  10329. case 'mapLightAnisotropy':
  10330. break;
  10331. case 'mapAO':
  10332. json.aoMap = loadTexture( value, m.mapAORepeat, m.mapAOOffset, m.mapAOWrap, m.mapAOAnisotropy );
  10333. break;
  10334. case 'mapAORepeat':
  10335. case 'mapAOOffset':
  10336. case 'mapAOWrap':
  10337. case 'mapAOAnisotropy':
  10338. break;
  10339. case 'mapBump':
  10340. json.bumpMap = loadTexture( value, m.mapBumpRepeat, m.mapBumpOffset, m.mapBumpWrap, m.mapBumpAnisotropy );
  10341. break;
  10342. case 'mapBumpScale':
  10343. json.bumpScale = value;
  10344. break;
  10345. case 'mapBumpRepeat':
  10346. case 'mapBumpOffset':
  10347. case 'mapBumpWrap':
  10348. case 'mapBumpAnisotropy':
  10349. break;
  10350. case 'mapNormal':
  10351. json.normalMap = loadTexture( value, m.mapNormalRepeat, m.mapNormalOffset, m.mapNormalWrap, m.mapNormalAnisotropy );
  10352. break;
  10353. case 'mapNormalFactor':
  10354. json.normalScale = [ value, value ];
  10355. break;
  10356. case 'mapNormalRepeat':
  10357. case 'mapNormalOffset':
  10358. case 'mapNormalWrap':
  10359. case 'mapNormalAnisotropy':
  10360. break;
  10361. case 'mapSpecular':
  10362. json.specularMap = loadTexture( value, m.mapSpecularRepeat, m.mapSpecularOffset, m.mapSpecularWrap, m.mapSpecularAnisotropy );
  10363. break;
  10364. case 'mapSpecularRepeat':
  10365. case 'mapSpecularOffset':
  10366. case 'mapSpecularWrap':
  10367. case 'mapSpecularAnisotropy':
  10368. break;
  10369. case 'mapAlpha':
  10370. json.alphaMap = loadTexture( value, m.mapAlphaRepeat, m.mapAlphaOffset, m.mapAlphaWrap, m.mapAlphaAnisotropy );
  10371. break;
  10372. case 'mapAlphaRepeat':
  10373. case 'mapAlphaOffset':
  10374. case 'mapAlphaWrap':
  10375. case 'mapAlphaAnisotropy':
  10376. break;
  10377. case 'flipSided':
  10378. json.side = THREE.BackSide;
  10379. break;
  10380. case 'doubleSided':
  10381. json.side = THREE.DoubleSide;
  10382. break;
  10383. case 'transparency':
  10384. console.warn( 'THREE.Loader.createMaterial: transparency has been renamed to opacity' );
  10385. json.opacity = value;
  10386. break;
  10387. case 'depthTest':
  10388. case 'depthWrite':
  10389. case 'colorWrite':
  10390. case 'opacity':
  10391. case 'reflectivity':
  10392. case 'transparent':
  10393. case 'visible':
  10394. case 'wireframe':
  10395. json[ name ] = value;
  10396. break;
  10397. case 'vertexColors':
  10398. if ( value === true ) json.vertexColors = THREE.VertexColors;
  10399. if ( value === 'face' ) json.vertexColors = THREE.FaceColors;
  10400. break;
  10401. default:
  10402. console.error( 'THREE.Loader.createMaterial: Unsupported', name, value );
  10403. break;
  10404. }
  10405. }
  10406. if ( json.type === 'MeshBasicMaterial' ) delete json.emissive;
  10407. if ( json.type !== 'MeshPhongMaterial' ) delete json.specular;
  10408. if ( json.opacity < 1 ) json.transparent = true;
  10409. materialLoader.setTextures( textures );
  10410. return materialLoader.parse( json );
  10411. };
  10412. } )()
  10413. };
  10414. THREE.Loader.Handlers = {
  10415. handlers: [],
  10416. add: function ( regex, loader ) {
  10417. this.handlers.push( regex, loader );
  10418. },
  10419. get: function ( file ) {
  10420. var handlers = this.handlers;
  10421. for ( var i = 0, l = handlers.length; i < l; i += 2 ) {
  10422. var regex = handlers[ i ];
  10423. var loader = handlers[ i + 1 ];
  10424. if ( regex.test( file ) ) {
  10425. return loader;
  10426. }
  10427. }
  10428. return null;
  10429. }
  10430. };
  10431. // File:src/loaders/XHRLoader.js
  10432. /**
  10433. * @author mrdoob / http://mrdoob.com/
  10434. */
  10435. THREE.XHRLoader = function ( manager ) {
  10436. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10437. };
  10438. THREE.XHRLoader.prototype = {
  10439. constructor: THREE.XHRLoader,
  10440. load: function ( url, onLoad, onProgress, onError ) {
  10441. if ( this.path !== undefined ) url = this.path + url;
  10442. var scope = this;
  10443. var cached = THREE.Cache.get( url );
  10444. if ( cached !== undefined ) {
  10445. if ( onLoad ) {
  10446. setTimeout( function () {
  10447. onLoad( cached );
  10448. }, 0 );
  10449. }
  10450. return cached;
  10451. }
  10452. var request = new XMLHttpRequest();
  10453. request.overrideMimeType( 'text/plain' );
  10454. request.open( 'GET', url, true );
  10455. request.addEventListener( 'load', function ( event ) {
  10456. var response = event.target.response;
  10457. THREE.Cache.add( url, response );
  10458. if ( this.status === 200 ) {
  10459. if ( onLoad ) onLoad( response );
  10460. scope.manager.itemEnd( url );
  10461. } else if ( this.status === 0 ) {
  10462. // Some browsers return HTTP Status 0 when using non-http protocol
  10463. // e.g. 'file://' or 'data://'. Handle as success.
  10464. console.warn( 'THREE.XHRLoader: HTTP Status 0 received.' );
  10465. if ( onLoad ) onLoad( response );
  10466. scope.manager.itemEnd( url );
  10467. } else {
  10468. if ( onError ) onError( event );
  10469. scope.manager.itemError( url );
  10470. }
  10471. }, false );
  10472. if ( onProgress !== undefined ) {
  10473. request.addEventListener( 'progress', function ( event ) {
  10474. onProgress( event );
  10475. }, false );
  10476. }
  10477. request.addEventListener( 'error', function ( event ) {
  10478. if ( onError ) onError( event );
  10479. scope.manager.itemError( url );
  10480. }, false );
  10481. if ( this.responseType !== undefined ) request.responseType = this.responseType;
  10482. if ( this.withCredentials !== undefined ) request.withCredentials = this.withCredentials;
  10483. request.send( null );
  10484. scope.manager.itemStart( url );
  10485. return request;
  10486. },
  10487. setPath: function ( value ) {
  10488. this.path = value;
  10489. },
  10490. setResponseType: function ( value ) {
  10491. this.responseType = value;
  10492. },
  10493. setWithCredentials: function ( value ) {
  10494. this.withCredentials = value;
  10495. }
  10496. };
  10497. // File:src/loaders/FontLoader.js
  10498. /**
  10499. * @author mrdoob / http://mrdoob.com/
  10500. */
  10501. THREE.FontLoader = function ( manager ) {
  10502. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10503. };
  10504. THREE.FontLoader.prototype = {
  10505. constructor: THREE.FontLoader,
  10506. load: function ( url, onLoad, onProgress, onError ) {
  10507. var loader = new THREE.XHRLoader( this.manager );
  10508. loader.load( url, function ( text ) {
  10509. onLoad( new THREE.Font( JSON.parse( text.substring( 65, text.length - 2 ) ) ) );
  10510. }, onProgress, onError );
  10511. }
  10512. };
  10513. // File:src/loaders/ImageLoader.js
  10514. /**
  10515. * @author mrdoob / http://mrdoob.com/
  10516. */
  10517. THREE.ImageLoader = function ( manager ) {
  10518. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10519. };
  10520. THREE.ImageLoader.prototype = {
  10521. constructor: THREE.ImageLoader,
  10522. load: function ( url, onLoad, onProgress, onError ) {
  10523. if ( this.path !== undefined ) url = this.path + url;
  10524. var scope = this;
  10525. var cached = THREE.Cache.get( url );
  10526. if ( cached !== undefined ) {
  10527. scope.manager.itemStart( url );
  10528. if ( onLoad ) {
  10529. setTimeout( function () {
  10530. onLoad( cached );
  10531. scope.manager.itemEnd( url );
  10532. }, 0 );
  10533. } else {
  10534. scope.manager.itemEnd( url );
  10535. }
  10536. return cached;
  10537. }
  10538. var image = document.createElement( 'img' );
  10539. image.addEventListener( 'load', function ( event ) {
  10540. THREE.Cache.add( url, this );
  10541. if ( onLoad ) onLoad( this );
  10542. scope.manager.itemEnd( url );
  10543. }, false );
  10544. if ( onProgress !== undefined ) {
  10545. image.addEventListener( 'progress', function ( event ) {
  10546. onProgress( event );
  10547. }, false );
  10548. }
  10549. image.addEventListener( 'error', function ( event ) {
  10550. if ( onError ) onError( event );
  10551. scope.manager.itemError( url );
  10552. }, false );
  10553. if ( this.crossOrigin !== undefined ) image.crossOrigin = this.crossOrigin;
  10554. scope.manager.itemStart( url );
  10555. image.src = url;
  10556. return image;
  10557. },
  10558. setCrossOrigin: function ( value ) {
  10559. this.crossOrigin = value;
  10560. },
  10561. setPath: function ( value ) {
  10562. this.path = value;
  10563. }
  10564. };
  10565. // File:src/loaders/JSONLoader.js
  10566. /**
  10567. * @author mrdoob / http://mrdoob.com/
  10568. * @author alteredq / http://alteredqualia.com/
  10569. */
  10570. THREE.JSONLoader = function ( manager ) {
  10571. if ( typeof manager === 'boolean' ) {
  10572. console.warn( 'THREE.JSONLoader: showStatus parameter has been removed from constructor.' );
  10573. manager = undefined;
  10574. }
  10575. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10576. this.withCredentials = false;
  10577. };
  10578. THREE.JSONLoader.prototype = {
  10579. constructor: THREE.JSONLoader,
  10580. // Deprecated
  10581. get statusDomElement () {
  10582. if ( this._statusDomElement === undefined ) {
  10583. this._statusDomElement = document.createElement( 'div' );
  10584. }
  10585. console.warn( 'THREE.JSONLoader: .statusDomElement has been removed.' );
  10586. return this._statusDomElement;
  10587. },
  10588. load: function( url, onLoad, onProgress, onError ) {
  10589. var scope = this;
  10590. var texturePath = this.texturePath && ( typeof this.texturePath === "string" ) ? this.texturePath : THREE.Loader.prototype.extractUrlBase( url );
  10591. var loader = new THREE.XHRLoader( this.manager );
  10592. loader.setWithCredentials( this.withCredentials );
  10593. loader.load( url, function ( text ) {
  10594. var json = JSON.parse( text );
  10595. var metadata = json.metadata;
  10596. if ( metadata !== undefined ) {
  10597. var type = metadata.type;
  10598. if ( type !== undefined ) {
  10599. if ( type.toLowerCase() === 'object' ) {
  10600. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.ObjectLoader instead.' );
  10601. return;
  10602. }
  10603. if ( type.toLowerCase() === 'scene' ) {
  10604. console.error( 'THREE.JSONLoader: ' + url + ' should be loaded with THREE.SceneLoader instead.' );
  10605. return;
  10606. }
  10607. }
  10608. }
  10609. var object = scope.parse( json, texturePath );
  10610. onLoad( object.geometry, object.materials );
  10611. }, onProgress, onError );
  10612. },
  10613. setTexturePath: function ( value ) {
  10614. this.texturePath = value;
  10615. },
  10616. parse: function ( json, texturePath ) {
  10617. var geometry = new THREE.Geometry(),
  10618. scale = ( json.scale !== undefined ) ? 1.0 / json.scale : 1.0;
  10619. parseModel( scale );
  10620. parseSkin();
  10621. parseMorphing( scale );
  10622. parseAnimations();
  10623. geometry.computeFaceNormals();
  10624. geometry.computeBoundingSphere();
  10625. function parseModel( scale ) {
  10626. function isBitSet( value, position ) {
  10627. return value & ( 1 << position );
  10628. }
  10629. var i, j, fi,
  10630. offset, zLength,
  10631. colorIndex, normalIndex, uvIndex, materialIndex,
  10632. type,
  10633. isQuad,
  10634. hasMaterial,
  10635. hasFaceVertexUv,
  10636. hasFaceNormal, hasFaceVertexNormal,
  10637. hasFaceColor, hasFaceVertexColor,
  10638. vertex, face, faceA, faceB, hex, normal,
  10639. uvLayer, uv, u, v,
  10640. faces = json.faces,
  10641. vertices = json.vertices,
  10642. normals = json.normals,
  10643. colors = json.colors,
  10644. nUvLayers = 0;
  10645. if ( json.uvs !== undefined ) {
  10646. // disregard empty arrays
  10647. for ( i = 0; i < json.uvs.length; i ++ ) {
  10648. if ( json.uvs[ i ].length ) nUvLayers ++;
  10649. }
  10650. for ( i = 0; i < nUvLayers; i ++ ) {
  10651. geometry.faceVertexUvs[ i ] = [];
  10652. }
  10653. }
  10654. offset = 0;
  10655. zLength = vertices.length;
  10656. while ( offset < zLength ) {
  10657. vertex = new THREE.Vector3();
  10658. vertex.x = vertices[ offset ++ ] * scale;
  10659. vertex.y = vertices[ offset ++ ] * scale;
  10660. vertex.z = vertices[ offset ++ ] * scale;
  10661. geometry.vertices.push( vertex );
  10662. }
  10663. offset = 0;
  10664. zLength = faces.length;
  10665. while ( offset < zLength ) {
  10666. type = faces[ offset ++ ];
  10667. isQuad = isBitSet( type, 0 );
  10668. hasMaterial = isBitSet( type, 1 );
  10669. hasFaceVertexUv = isBitSet( type, 3 );
  10670. hasFaceNormal = isBitSet( type, 4 );
  10671. hasFaceVertexNormal = isBitSet( type, 5 );
  10672. hasFaceColor = isBitSet( type, 6 );
  10673. hasFaceVertexColor = isBitSet( type, 7 );
  10674. // console.log("type", type, "bits", isQuad, hasMaterial, hasFaceVertexUv, hasFaceNormal, hasFaceVertexNormal, hasFaceColor, hasFaceVertexColor);
  10675. if ( isQuad ) {
  10676. faceA = new THREE.Face3();
  10677. faceA.a = faces[ offset ];
  10678. faceA.b = faces[ offset + 1 ];
  10679. faceA.c = faces[ offset + 3 ];
  10680. faceB = new THREE.Face3();
  10681. faceB.a = faces[ offset + 1 ];
  10682. faceB.b = faces[ offset + 2 ];
  10683. faceB.c = faces[ offset + 3 ];
  10684. offset += 4;
  10685. if ( hasMaterial ) {
  10686. materialIndex = faces[ offset ++ ];
  10687. faceA.materialIndex = materialIndex;
  10688. faceB.materialIndex = materialIndex;
  10689. }
  10690. // to get face <=> uv index correspondence
  10691. fi = geometry.faces.length;
  10692. if ( hasFaceVertexUv ) {
  10693. for ( i = 0; i < nUvLayers; i ++ ) {
  10694. uvLayer = json.uvs[ i ];
  10695. geometry.faceVertexUvs[ i ][ fi ] = [];
  10696. geometry.faceVertexUvs[ i ][ fi + 1 ] = [];
  10697. for ( j = 0; j < 4; j ++ ) {
  10698. uvIndex = faces[ offset ++ ];
  10699. u = uvLayer[ uvIndex * 2 ];
  10700. v = uvLayer[ uvIndex * 2 + 1 ];
  10701. uv = new THREE.Vector2( u, v );
  10702. if ( j !== 2 ) geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10703. if ( j !== 0 ) geometry.faceVertexUvs[ i ][ fi + 1 ].push( uv );
  10704. }
  10705. }
  10706. }
  10707. if ( hasFaceNormal ) {
  10708. normalIndex = faces[ offset ++ ] * 3;
  10709. faceA.normal.set(
  10710. normals[ normalIndex ++ ],
  10711. normals[ normalIndex ++ ],
  10712. normals[ normalIndex ]
  10713. );
  10714. faceB.normal.copy( faceA.normal );
  10715. }
  10716. if ( hasFaceVertexNormal ) {
  10717. for ( i = 0; i < 4; i ++ ) {
  10718. normalIndex = faces[ offset ++ ] * 3;
  10719. normal = new THREE.Vector3(
  10720. normals[ normalIndex ++ ],
  10721. normals[ normalIndex ++ ],
  10722. normals[ normalIndex ]
  10723. );
  10724. if ( i !== 2 ) faceA.vertexNormals.push( normal );
  10725. if ( i !== 0 ) faceB.vertexNormals.push( normal );
  10726. }
  10727. }
  10728. if ( hasFaceColor ) {
  10729. colorIndex = faces[ offset ++ ];
  10730. hex = colors[ colorIndex ];
  10731. faceA.color.setHex( hex );
  10732. faceB.color.setHex( hex );
  10733. }
  10734. if ( hasFaceVertexColor ) {
  10735. for ( i = 0; i < 4; i ++ ) {
  10736. colorIndex = faces[ offset ++ ];
  10737. hex = colors[ colorIndex ];
  10738. if ( i !== 2 ) faceA.vertexColors.push( new THREE.Color( hex ) );
  10739. if ( i !== 0 ) faceB.vertexColors.push( new THREE.Color( hex ) );
  10740. }
  10741. }
  10742. geometry.faces.push( faceA );
  10743. geometry.faces.push( faceB );
  10744. } else {
  10745. face = new THREE.Face3();
  10746. face.a = faces[ offset ++ ];
  10747. face.b = faces[ offset ++ ];
  10748. face.c = faces[ offset ++ ];
  10749. if ( hasMaterial ) {
  10750. materialIndex = faces[ offset ++ ];
  10751. face.materialIndex = materialIndex;
  10752. }
  10753. // to get face <=> uv index correspondence
  10754. fi = geometry.faces.length;
  10755. if ( hasFaceVertexUv ) {
  10756. for ( i = 0; i < nUvLayers; i ++ ) {
  10757. uvLayer = json.uvs[ i ];
  10758. geometry.faceVertexUvs[ i ][ fi ] = [];
  10759. for ( j = 0; j < 3; j ++ ) {
  10760. uvIndex = faces[ offset ++ ];
  10761. u = uvLayer[ uvIndex * 2 ];
  10762. v = uvLayer[ uvIndex * 2 + 1 ];
  10763. uv = new THREE.Vector2( u, v );
  10764. geometry.faceVertexUvs[ i ][ fi ].push( uv );
  10765. }
  10766. }
  10767. }
  10768. if ( hasFaceNormal ) {
  10769. normalIndex = faces[ offset ++ ] * 3;
  10770. face.normal.set(
  10771. normals[ normalIndex ++ ],
  10772. normals[ normalIndex ++ ],
  10773. normals[ normalIndex ]
  10774. );
  10775. }
  10776. if ( hasFaceVertexNormal ) {
  10777. for ( i = 0; i < 3; i ++ ) {
  10778. normalIndex = faces[ offset ++ ] * 3;
  10779. normal = new THREE.Vector3(
  10780. normals[ normalIndex ++ ],
  10781. normals[ normalIndex ++ ],
  10782. normals[ normalIndex ]
  10783. );
  10784. face.vertexNormals.push( normal );
  10785. }
  10786. }
  10787. if ( hasFaceColor ) {
  10788. colorIndex = faces[ offset ++ ];
  10789. face.color.setHex( colors[ colorIndex ] );
  10790. }
  10791. if ( hasFaceVertexColor ) {
  10792. for ( i = 0; i < 3; i ++ ) {
  10793. colorIndex = faces[ offset ++ ];
  10794. face.vertexColors.push( new THREE.Color( colors[ colorIndex ] ) );
  10795. }
  10796. }
  10797. geometry.faces.push( face );
  10798. }
  10799. }
  10800. };
  10801. function parseSkin() {
  10802. var influencesPerVertex = ( json.influencesPerVertex !== undefined ) ? json.influencesPerVertex : 2;
  10803. if ( json.skinWeights ) {
  10804. for ( var i = 0, l = json.skinWeights.length; i < l; i += influencesPerVertex ) {
  10805. var x = json.skinWeights[ i ];
  10806. var y = ( influencesPerVertex > 1 ) ? json.skinWeights[ i + 1 ] : 0;
  10807. var z = ( influencesPerVertex > 2 ) ? json.skinWeights[ i + 2 ] : 0;
  10808. var w = ( influencesPerVertex > 3 ) ? json.skinWeights[ i + 3 ] : 0;
  10809. geometry.skinWeights.push( new THREE.Vector4( x, y, z, w ) );
  10810. }
  10811. }
  10812. if ( json.skinIndices ) {
  10813. for ( var i = 0, l = json.skinIndices.length; i < l; i += influencesPerVertex ) {
  10814. var a = json.skinIndices[ i ];
  10815. var b = ( influencesPerVertex > 1 ) ? json.skinIndices[ i + 1 ] : 0;
  10816. var c = ( influencesPerVertex > 2 ) ? json.skinIndices[ i + 2 ] : 0;
  10817. var d = ( influencesPerVertex > 3 ) ? json.skinIndices[ i + 3 ] : 0;
  10818. geometry.skinIndices.push( new THREE.Vector4( a, b, c, d ) );
  10819. }
  10820. }
  10821. geometry.bones = json.bones;
  10822. if ( geometry.bones && geometry.bones.length > 0 && ( geometry.skinWeights.length !== geometry.skinIndices.length || geometry.skinIndices.length !== geometry.vertices.length ) ) {
  10823. console.warn( 'When skinning, number of vertices (' + geometry.vertices.length + '), skinIndices (' +
  10824. geometry.skinIndices.length + '), and skinWeights (' + geometry.skinWeights.length + ') should match.' );
  10825. }
  10826. };
  10827. function parseMorphing( scale ) {
  10828. if ( json.morphTargets !== undefined ) {
  10829. for ( var i = 0, l = json.morphTargets.length; i < l; i ++ ) {
  10830. geometry.morphTargets[ i ] = {};
  10831. geometry.morphTargets[ i ].name = json.morphTargets[ i ].name;
  10832. geometry.morphTargets[ i ].vertices = [];
  10833. var dstVertices = geometry.morphTargets[ i ].vertices;
  10834. var srcVertices = json.morphTargets[ i ].vertices;
  10835. for ( var v = 0, vl = srcVertices.length; v < vl; v += 3 ) {
  10836. var vertex = new THREE.Vector3();
  10837. vertex.x = srcVertices[ v ] * scale;
  10838. vertex.y = srcVertices[ v + 1 ] * scale;
  10839. vertex.z = srcVertices[ v + 2 ] * scale;
  10840. dstVertices.push( vertex );
  10841. }
  10842. }
  10843. }
  10844. if ( json.morphColors !== undefined && json.morphColors.length > 0 ) {
  10845. console.warn( 'THREE.JSONLoader: "morphColors" no longer supported. Using them as face colors.' );
  10846. var faces = geometry.faces;
  10847. var morphColors = json.morphColors[ 0 ].colors;
  10848. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  10849. faces[ i ].color.fromArray( morphColors, i * 3 );
  10850. }
  10851. }
  10852. }
  10853. function parseAnimations() {
  10854. var outputAnimations = [];
  10855. // parse old style Bone/Hierarchy animations
  10856. var animations = [];
  10857. if ( json.animation !== undefined ) {
  10858. animations.push( json.animation );
  10859. }
  10860. if ( json.animations !== undefined ) {
  10861. if ( json.animations.length ) {
  10862. animations = animations.concat( json.animations );
  10863. } else {
  10864. animations.push( json.animations );
  10865. }
  10866. }
  10867. for ( var i = 0; i < animations.length; i ++ ) {
  10868. var clip = THREE.AnimationClip.parseAnimation( animations[ i ], geometry.bones );
  10869. if ( clip ) outputAnimations.push( clip );
  10870. }
  10871. // parse implicit morph animations
  10872. if ( geometry.morphTargets ) {
  10873. // TODO: Figure out what an appropraite FPS is for morph target animations -- defaulting to 10, but really it is completely arbitrary.
  10874. var morphAnimationClips = THREE.AnimationClip.CreateClipsFromMorphTargetSequences( geometry.morphTargets, 10 );
  10875. outputAnimations = outputAnimations.concat( morphAnimationClips );
  10876. }
  10877. if ( outputAnimations.length > 0 ) geometry.animations = outputAnimations;
  10878. };
  10879. if ( json.materials === undefined || json.materials.length === 0 ) {
  10880. return { geometry: geometry };
  10881. } else {
  10882. var materials = THREE.Loader.prototype.initMaterials( json.materials, texturePath, this.crossOrigin );
  10883. return { geometry: geometry, materials: materials };
  10884. }
  10885. }
  10886. };
  10887. // File:src/loaders/LoadingManager.js
  10888. /**
  10889. * @author mrdoob / http://mrdoob.com/
  10890. */
  10891. THREE.LoadingManager = function ( onLoad, onProgress, onError ) {
  10892. var scope = this;
  10893. var isLoading = false, itemsLoaded = 0, itemsTotal = 0;
  10894. this.onStart = undefined;
  10895. this.onLoad = onLoad;
  10896. this.onProgress = onProgress;
  10897. this.onError = onError;
  10898. this.itemStart = function ( url ) {
  10899. itemsTotal ++;
  10900. if ( isLoading === false ) {
  10901. if ( scope.onStart !== undefined ) {
  10902. scope.onStart( url, itemsLoaded, itemsTotal );
  10903. }
  10904. }
  10905. isLoading = true;
  10906. };
  10907. this.itemEnd = function ( url ) {
  10908. itemsLoaded ++;
  10909. if ( scope.onProgress !== undefined ) {
  10910. scope.onProgress( url, itemsLoaded, itemsTotal );
  10911. }
  10912. if ( itemsLoaded === itemsTotal ) {
  10913. isLoading = false;
  10914. if ( scope.onLoad !== undefined ) {
  10915. scope.onLoad();
  10916. }
  10917. }
  10918. };
  10919. this.itemError = function ( url ) {
  10920. if ( scope.onError !== undefined ) {
  10921. scope.onError( url );
  10922. }
  10923. };
  10924. };
  10925. THREE.DefaultLoadingManager = new THREE.LoadingManager();
  10926. // File:src/loaders/BufferGeometryLoader.js
  10927. /**
  10928. * @author mrdoob / http://mrdoob.com/
  10929. */
  10930. THREE.BufferGeometryLoader = function ( manager ) {
  10931. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10932. };
  10933. THREE.BufferGeometryLoader.prototype = {
  10934. constructor: THREE.BufferGeometryLoader,
  10935. load: function ( url, onLoad, onProgress, onError ) {
  10936. var scope = this;
  10937. var loader = new THREE.XHRLoader( scope.manager );
  10938. loader.load( url, function ( text ) {
  10939. onLoad( scope.parse( JSON.parse( text ) ) );
  10940. }, onProgress, onError );
  10941. },
  10942. parse: function ( json ) {
  10943. var geometry = new THREE.BufferGeometry();
  10944. var index = json.data.index;
  10945. var TYPED_ARRAYS = {
  10946. 'Int8Array': Int8Array,
  10947. 'Uint8Array': Uint8Array,
  10948. 'Uint8ClampedArray': Uint8ClampedArray,
  10949. 'Int16Array': Int16Array,
  10950. 'Uint16Array': Uint16Array,
  10951. 'Int32Array': Int32Array,
  10952. 'Uint32Array': Uint32Array,
  10953. 'Float32Array': Float32Array,
  10954. 'Float64Array': Float64Array
  10955. };
  10956. if ( index !== undefined ) {
  10957. var typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
  10958. geometry.setIndex( new THREE.BufferAttribute( typedArray, 1 ) );
  10959. }
  10960. var attributes = json.data.attributes;
  10961. for ( var key in attributes ) {
  10962. var attribute = attributes[ key ];
  10963. var typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
  10964. geometry.addAttribute( key, new THREE.BufferAttribute( typedArray, attribute.itemSize ) );
  10965. }
  10966. var groups = json.data.groups || json.data.drawcalls || json.data.offsets;
  10967. if ( groups !== undefined ) {
  10968. for ( var i = 0, n = groups.length; i !== n; ++ i ) {
  10969. var group = groups[ i ];
  10970. geometry.addGroup( group.start, group.count, group.materialIndex );
  10971. }
  10972. }
  10973. var boundingSphere = json.data.boundingSphere;
  10974. if ( boundingSphere !== undefined ) {
  10975. var center = new THREE.Vector3();
  10976. if ( boundingSphere.center !== undefined ) {
  10977. center.fromArray( boundingSphere.center );
  10978. }
  10979. geometry.boundingSphere = new THREE.Sphere( center, boundingSphere.radius );
  10980. }
  10981. return geometry;
  10982. }
  10983. };
  10984. // File:src/loaders/MaterialLoader.js
  10985. /**
  10986. * @author mrdoob / http://mrdoob.com/
  10987. */
  10988. THREE.MaterialLoader = function ( manager ) {
  10989. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  10990. this.textures = {};
  10991. };
  10992. THREE.MaterialLoader.prototype = {
  10993. constructor: THREE.MaterialLoader,
  10994. load: function ( url, onLoad, onProgress, onError ) {
  10995. var scope = this;
  10996. var loader = new THREE.XHRLoader( scope.manager );
  10997. loader.load( url, function ( text ) {
  10998. onLoad( scope.parse( JSON.parse( text ) ) );
  10999. }, onProgress, onError );
  11000. },
  11001. setTextures: function ( value ) {
  11002. this.textures = value;
  11003. },
  11004. getTexture: function ( name ) {
  11005. var textures = this.textures;
  11006. if ( textures[ name ] === undefined ) {
  11007. console.warn( 'THREE.MaterialLoader: Undefined texture', name );
  11008. }
  11009. return textures[ name ];
  11010. },
  11011. parse: function ( json ) {
  11012. var material = new THREE[ json.type ];
  11013. if ( json.uuid !== undefined ) material.uuid = json.uuid;
  11014. if ( json.name !== undefined ) material.name = json.name;
  11015. if ( json.color !== undefined ) material.color.setHex( json.color );
  11016. if ( json.roughness !== undefined ) material.roughness = json.roughness;
  11017. if ( json.metalness !== undefined ) material.metalness = json.metalness;
  11018. if ( json.emissive !== undefined ) material.emissive.setHex( json.emissive );
  11019. if ( json.specular !== undefined ) material.specular.setHex( json.specular );
  11020. if ( json.shininess !== undefined ) material.shininess = json.shininess;
  11021. if ( json.uniforms !== undefined ) material.uniforms = json.uniforms;
  11022. if ( json.vertexShader !== undefined ) material.vertexShader = json.vertexShader;
  11023. if ( json.fragmentShader !== undefined ) material.fragmentShader = json.fragmentShader;
  11024. if ( json.vertexColors !== undefined ) material.vertexColors = json.vertexColors;
  11025. if ( json.shading !== undefined ) material.shading = json.shading;
  11026. if ( json.blending !== undefined ) material.blending = json.blending;
  11027. if ( json.side !== undefined ) material.side = json.side;
  11028. if ( json.opacity !== undefined ) material.opacity = json.opacity;
  11029. if ( json.transparent !== undefined ) material.transparent = json.transparent;
  11030. if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
  11031. if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
  11032. if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
  11033. if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
  11034. if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
  11035. if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
  11036. // for PointsMaterial
  11037. if ( json.size !== undefined ) material.size = json.size;
  11038. if ( json.sizeAttenuation !== undefined ) material.sizeAttenuation = json.sizeAttenuation;
  11039. // maps
  11040. if ( json.map !== undefined ) material.map = this.getTexture( json.map );
  11041. if ( json.alphaMap !== undefined ) {
  11042. material.alphaMap = this.getTexture( json.alphaMap );
  11043. material.transparent = true;
  11044. }
  11045. if ( json.bumpMap !== undefined ) material.bumpMap = this.getTexture( json.bumpMap );
  11046. if ( json.bumpScale !== undefined ) material.bumpScale = json.bumpScale;
  11047. if ( json.normalMap !== undefined ) material.normalMap = this.getTexture( json.normalMap );
  11048. if ( json.normalScale !== undefined ) {
  11049. var normalScale = json.normalScale;
  11050. if ( Array.isArray( normalScale ) === false ) {
  11051. // Blender exporter used to export a scalar. See #7459
  11052. normalScale = [ normalScale, normalScale ];
  11053. }
  11054. material.normalScale = new THREE.Vector2().fromArray( normalScale );
  11055. }
  11056. if ( json.displacementMap !== undefined ) material.displacementMap = this.getTexture( json.displacementMap );
  11057. if ( json.displacementScale !== undefined ) material.displacementScale = json.displacementScale;
  11058. if ( json.displacementBias !== undefined ) material.displacementBias = json.displacementBias;
  11059. if ( json.roughnessMap !== undefined ) material.roughnessMap = this.getTexture( json.roughnessMap );
  11060. if ( json.metalnessMap !== undefined ) material.metalnessMap = this.getTexture( json.metalnessMap );
  11061. if ( json.emissiveMap !== undefined ) material.emissiveMap = this.getTexture( json.emissiveMap );
  11062. if ( json.emissiveIntensity !== undefined ) material.emissiveIntensity = json.emissiveIntensity;
  11063. if ( json.specularMap !== undefined ) material.specularMap = this.getTexture( json.specularMap );
  11064. if ( json.envMap !== undefined ) {
  11065. material.envMap = this.getTexture( json.envMap );
  11066. material.combine = THREE.MultiplyOperation;
  11067. }
  11068. if ( json.reflectivity ) material.reflectivity = json.reflectivity;
  11069. if ( json.lightMap !== undefined ) material.lightMap = this.getTexture( json.lightMap );
  11070. if ( json.lightMapIntensity !== undefined ) material.lightMapIntensity = json.lightMapIntensity;
  11071. if ( json.aoMap !== undefined ) material.aoMap = this.getTexture( json.aoMap );
  11072. if ( json.aoMapIntensity !== undefined ) material.aoMapIntensity = json.aoMapIntensity;
  11073. // MultiMaterial
  11074. if ( json.materials !== undefined ) {
  11075. for ( var i = 0, l = json.materials.length; i < l; i ++ ) {
  11076. material.materials.push( this.parse( json.materials[ i ] ) );
  11077. }
  11078. }
  11079. return material;
  11080. }
  11081. };
  11082. // File:src/loaders/ObjectLoader.js
  11083. /**
  11084. * @author mrdoob / http://mrdoob.com/
  11085. */
  11086. THREE.ObjectLoader = function ( manager ) {
  11087. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11088. this.texturePath = '';
  11089. };
  11090. THREE.ObjectLoader.prototype = {
  11091. constructor: THREE.ObjectLoader,
  11092. load: function ( url, onLoad, onProgress, onError ) {
  11093. if ( this.texturePath === '' ) {
  11094. this.texturePath = url.substring( 0, url.lastIndexOf( '/' ) + 1 );
  11095. }
  11096. var scope = this;
  11097. var loader = new THREE.XHRLoader( scope.manager );
  11098. loader.load( url, function ( text ) {
  11099. scope.parse( JSON.parse( text ), onLoad );
  11100. }, onProgress, onError );
  11101. },
  11102. setTexturePath: function ( value ) {
  11103. this.texturePath = value;
  11104. },
  11105. setCrossOrigin: function ( value ) {
  11106. this.crossOrigin = value;
  11107. },
  11108. parse: function ( json, onLoad ) {
  11109. var geometries = this.parseGeometries( json.geometries );
  11110. var images = this.parseImages( json.images, function () {
  11111. if ( onLoad !== undefined ) onLoad( object );
  11112. } );
  11113. var textures = this.parseTextures( json.textures, images );
  11114. var materials = this.parseMaterials( json.materials, textures );
  11115. var object = this.parseObject( json.object, geometries, materials );
  11116. if ( json.animations ) {
  11117. object.animations = this.parseAnimations( json.animations );
  11118. }
  11119. if ( json.images === undefined || json.images.length === 0 ) {
  11120. if ( onLoad !== undefined ) onLoad( object );
  11121. }
  11122. return object;
  11123. },
  11124. parseGeometries: function ( json ) {
  11125. var geometries = {};
  11126. if ( json !== undefined ) {
  11127. var geometryLoader = new THREE.JSONLoader();
  11128. var bufferGeometryLoader = new THREE.BufferGeometryLoader();
  11129. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11130. var geometry;
  11131. var data = json[ i ];
  11132. switch ( data.type ) {
  11133. case 'PlaneGeometry':
  11134. case 'PlaneBufferGeometry':
  11135. geometry = new THREE[ data.type ](
  11136. data.width,
  11137. data.height,
  11138. data.widthSegments,
  11139. data.heightSegments
  11140. );
  11141. break;
  11142. case 'BoxGeometry':
  11143. case 'CubeGeometry': // backwards compatible
  11144. geometry = new THREE.BoxGeometry(
  11145. data.width,
  11146. data.height,
  11147. data.depth,
  11148. data.widthSegments,
  11149. data.heightSegments,
  11150. data.depthSegments
  11151. );
  11152. break;
  11153. case 'CircleBufferGeometry':
  11154. geometry = new THREE.CircleBufferGeometry(
  11155. data.radius,
  11156. data.segments,
  11157. data.thetaStart,
  11158. data.thetaLength
  11159. );
  11160. break;
  11161. case 'CircleGeometry':
  11162. geometry = new THREE.CircleGeometry(
  11163. data.radius,
  11164. data.segments,
  11165. data.thetaStart,
  11166. data.thetaLength
  11167. );
  11168. break;
  11169. case 'CylinderGeometry':
  11170. geometry = new THREE.CylinderGeometry(
  11171. data.radiusTop,
  11172. data.radiusBottom,
  11173. data.height,
  11174. data.radialSegments,
  11175. data.heightSegments,
  11176. data.openEnded,
  11177. data.thetaStart,
  11178. data.thetaLength
  11179. );
  11180. break;
  11181. case 'SphereGeometry':
  11182. geometry = new THREE.SphereGeometry(
  11183. data.radius,
  11184. data.widthSegments,
  11185. data.heightSegments,
  11186. data.phiStart,
  11187. data.phiLength,
  11188. data.thetaStart,
  11189. data.thetaLength
  11190. );
  11191. break;
  11192. case 'SphereBufferGeometry':
  11193. geometry = new THREE.SphereBufferGeometry(
  11194. data.radius,
  11195. data.widthSegments,
  11196. data.heightSegments,
  11197. data.phiStart,
  11198. data.phiLength,
  11199. data.thetaStart,
  11200. data.thetaLength
  11201. );
  11202. break;
  11203. case 'DodecahedronGeometry':
  11204. geometry = new THREE.DodecahedronGeometry(
  11205. data.radius,
  11206. data.detail
  11207. );
  11208. break;
  11209. case 'IcosahedronGeometry':
  11210. geometry = new THREE.IcosahedronGeometry(
  11211. data.radius,
  11212. data.detail
  11213. );
  11214. break;
  11215. case 'OctahedronGeometry':
  11216. geometry = new THREE.OctahedronGeometry(
  11217. data.radius,
  11218. data.detail
  11219. );
  11220. break;
  11221. case 'TetrahedronGeometry':
  11222. geometry = new THREE.TetrahedronGeometry(
  11223. data.radius,
  11224. data.detail
  11225. );
  11226. break;
  11227. case 'RingGeometry':
  11228. geometry = new THREE.RingGeometry(
  11229. data.innerRadius,
  11230. data.outerRadius,
  11231. data.thetaSegments,
  11232. data.phiSegments,
  11233. data.thetaStart,
  11234. data.thetaLength
  11235. );
  11236. break;
  11237. case 'TorusGeometry':
  11238. geometry = new THREE.TorusGeometry(
  11239. data.radius,
  11240. data.tube,
  11241. data.radialSegments,
  11242. data.tubularSegments,
  11243. data.arc
  11244. );
  11245. break;
  11246. case 'TorusKnotGeometry':
  11247. geometry = new THREE.TorusKnotGeometry(
  11248. data.radius,
  11249. data.tube,
  11250. data.radialSegments,
  11251. data.tubularSegments,
  11252. data.p,
  11253. data.q,
  11254. data.heightScale
  11255. );
  11256. break;
  11257. case 'LatheGeometry':
  11258. geometry = new THREE.LatheGeometry(
  11259. data.points,
  11260. data.segments,
  11261. data.phiStart,
  11262. data.phiLength
  11263. );
  11264. break;
  11265. case 'BufferGeometry':
  11266. geometry = bufferGeometryLoader.parse( data );
  11267. break;
  11268. case 'Geometry':
  11269. geometry = geometryLoader.parse( data.data, this.texturePath ).geometry;
  11270. break;
  11271. default:
  11272. console.warn( 'THREE.ObjectLoader: Unsupported geometry type "' + data.type + '"' );
  11273. continue;
  11274. }
  11275. geometry.uuid = data.uuid;
  11276. if ( data.name !== undefined ) geometry.name = data.name;
  11277. geometries[ data.uuid ] = geometry;
  11278. }
  11279. }
  11280. return geometries;
  11281. },
  11282. parseMaterials: function ( json, textures ) {
  11283. var materials = {};
  11284. if ( json !== undefined ) {
  11285. var loader = new THREE.MaterialLoader();
  11286. loader.setTextures( textures );
  11287. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11288. var material = loader.parse( json[ i ] );
  11289. materials[ material.uuid ] = material;
  11290. }
  11291. }
  11292. return materials;
  11293. },
  11294. parseAnimations: function ( json ) {
  11295. var animations = [];
  11296. for ( var i = 0; i < json.length; i ++ ) {
  11297. var clip = THREE.AnimationClip.parse( json[ i ] );
  11298. animations.push( clip );
  11299. }
  11300. return animations;
  11301. },
  11302. parseImages: function ( json, onLoad ) {
  11303. var scope = this;
  11304. var images = {};
  11305. function loadImage( url ) {
  11306. scope.manager.itemStart( url );
  11307. return loader.load( url, function () {
  11308. scope.manager.itemEnd( url );
  11309. } );
  11310. }
  11311. if ( json !== undefined && json.length > 0 ) {
  11312. var manager = new THREE.LoadingManager( onLoad );
  11313. var loader = new THREE.ImageLoader( manager );
  11314. loader.setCrossOrigin( this.crossOrigin );
  11315. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11316. var image = json[ i ];
  11317. var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.texturePath + image.url;
  11318. images[ image.uuid ] = loadImage( path );
  11319. }
  11320. }
  11321. return images;
  11322. },
  11323. parseTextures: function ( json, images ) {
  11324. function parseConstant( value ) {
  11325. if ( typeof( value ) === 'number' ) return value;
  11326. console.warn( 'THREE.ObjectLoader.parseTexture: Constant should be in numeric form.', value );
  11327. return THREE[ value ];
  11328. }
  11329. var textures = {};
  11330. if ( json !== undefined ) {
  11331. for ( var i = 0, l = json.length; i < l; i ++ ) {
  11332. var data = json[ i ];
  11333. if ( data.image === undefined ) {
  11334. console.warn( 'THREE.ObjectLoader: No "image" specified for', data.uuid );
  11335. }
  11336. if ( images[ data.image ] === undefined ) {
  11337. console.warn( 'THREE.ObjectLoader: Undefined image', data.image );
  11338. }
  11339. var texture = new THREE.Texture( images[ data.image ] );
  11340. texture.needsUpdate = true;
  11341. texture.uuid = data.uuid;
  11342. if ( data.name !== undefined ) texture.name = data.name;
  11343. if ( data.mapping !== undefined ) texture.mapping = parseConstant( data.mapping );
  11344. if ( data.offset !== undefined ) texture.offset = new THREE.Vector2( data.offset[ 0 ], data.offset[ 1 ] );
  11345. if ( data.repeat !== undefined ) texture.repeat = new THREE.Vector2( data.repeat[ 0 ], data.repeat[ 1 ] );
  11346. if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter );
  11347. if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter );
  11348. if ( data.anisotropy !== undefined ) texture.anisotropy = data.anisotropy;
  11349. if ( Array.isArray( data.wrap ) ) {
  11350. texture.wrapS = parseConstant( data.wrap[ 0 ] );
  11351. texture.wrapT = parseConstant( data.wrap[ 1 ] );
  11352. }
  11353. textures[ data.uuid ] = texture;
  11354. }
  11355. }
  11356. return textures;
  11357. },
  11358. parseObject: function () {
  11359. var matrix = new THREE.Matrix4();
  11360. return function ( data, geometries, materials ) {
  11361. var object;
  11362. function getGeometry( name ) {
  11363. if ( geometries[ name ] === undefined ) {
  11364. console.warn( 'THREE.ObjectLoader: Undefined geometry', name );
  11365. }
  11366. return geometries[ name ];
  11367. }
  11368. function getMaterial( name ) {
  11369. if ( name === undefined ) return undefined;
  11370. if ( materials[ name ] === undefined ) {
  11371. console.warn( 'THREE.ObjectLoader: Undefined material', name );
  11372. }
  11373. return materials[ name ];
  11374. }
  11375. switch ( data.type ) {
  11376. case 'Scene':
  11377. object = new THREE.Scene();
  11378. break;
  11379. case 'PerspectiveCamera':
  11380. object = new THREE.PerspectiveCamera( data.fov, data.aspect, data.near, data.far );
  11381. break;
  11382. case 'OrthographicCamera':
  11383. object = new THREE.OrthographicCamera( data.left, data.right, data.top, data.bottom, data.near, data.far );
  11384. break;
  11385. case 'AmbientLight':
  11386. object = new THREE.AmbientLight( data.color, data.intensity );
  11387. break;
  11388. case 'DirectionalLight':
  11389. object = new THREE.DirectionalLight( data.color, data.intensity );
  11390. break;
  11391. case 'PointLight':
  11392. object = new THREE.PointLight( data.color, data.intensity, data.distance, data.decay );
  11393. break;
  11394. case 'SpotLight':
  11395. object = new THREE.SpotLight( data.color, data.intensity, data.distance, data.angle, data.penumbra, data.decay );
  11396. break;
  11397. case 'HemisphereLight':
  11398. object = new THREE.HemisphereLight( data.color, data.groundColor, data.intensity );
  11399. break;
  11400. case 'Mesh':
  11401. var geometry = getGeometry( data.geometry );
  11402. var material = getMaterial( data.material );
  11403. if ( geometry.bones && geometry.bones.length > 0 ) {
  11404. object = new THREE.SkinnedMesh( geometry, material );
  11405. } else {
  11406. object = new THREE.Mesh( geometry, material );
  11407. }
  11408. break;
  11409. case 'LOD':
  11410. object = new THREE.LOD();
  11411. break;
  11412. case 'Line':
  11413. object = new THREE.Line( getGeometry( data.geometry ), getMaterial( data.material ), data.mode );
  11414. break;
  11415. case 'PointCloud':
  11416. case 'Points':
  11417. object = new THREE.Points( getGeometry( data.geometry ), getMaterial( data.material ) );
  11418. break;
  11419. case 'Sprite':
  11420. object = new THREE.Sprite( getMaterial( data.material ) );
  11421. break;
  11422. case 'Group':
  11423. object = new THREE.Group();
  11424. break;
  11425. default:
  11426. object = new THREE.Object3D();
  11427. }
  11428. object.uuid = data.uuid;
  11429. if ( data.name !== undefined ) object.name = data.name;
  11430. if ( data.matrix !== undefined ) {
  11431. matrix.fromArray( data.matrix );
  11432. matrix.decompose( object.position, object.quaternion, object.scale );
  11433. } else {
  11434. if ( data.position !== undefined ) object.position.fromArray( data.position );
  11435. if ( data.rotation !== undefined ) object.rotation.fromArray( data.rotation );
  11436. if ( data.scale !== undefined ) object.scale.fromArray( data.scale );
  11437. }
  11438. if ( data.castShadow !== undefined ) object.castShadow = data.castShadow;
  11439. if ( data.receiveShadow !== undefined ) object.receiveShadow = data.receiveShadow;
  11440. if ( data.visible !== undefined ) object.visible = data.visible;
  11441. if ( data.userData !== undefined ) object.userData = data.userData;
  11442. if ( data.children !== undefined ) {
  11443. for ( var child in data.children ) {
  11444. object.add( this.parseObject( data.children[ child ], geometries, materials ) );
  11445. }
  11446. }
  11447. if ( data.type === 'LOD' ) {
  11448. var levels = data.levels;
  11449. for ( var l = 0; l < levels.length; l ++ ) {
  11450. var level = levels[ l ];
  11451. var child = object.getObjectByProperty( 'uuid', level.object );
  11452. if ( child !== undefined ) {
  11453. object.addLevel( child, level.distance );
  11454. }
  11455. }
  11456. }
  11457. return object;
  11458. }
  11459. }()
  11460. };
  11461. // File:src/loaders/TextureLoader.js
  11462. /**
  11463. * @author mrdoob / http://mrdoob.com/
  11464. */
  11465. THREE.TextureLoader = function ( manager ) {
  11466. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11467. };
  11468. THREE.TextureLoader.prototype = {
  11469. constructor: THREE.TextureLoader,
  11470. load: function ( url, onLoad, onProgress, onError ) {
  11471. var texture = new THREE.Texture();
  11472. var loader = new THREE.ImageLoader( this.manager );
  11473. loader.setCrossOrigin( this.crossOrigin );
  11474. loader.setPath( this.path );
  11475. loader.load( url, function ( image ) {
  11476. texture.image = image;
  11477. texture.needsUpdate = true;
  11478. if ( onLoad !== undefined ) {
  11479. onLoad( texture );
  11480. }
  11481. }, onProgress, onError );
  11482. return texture;
  11483. },
  11484. setCrossOrigin: function ( value ) {
  11485. this.crossOrigin = value;
  11486. },
  11487. setPath: function ( value ) {
  11488. this.path = value;
  11489. }
  11490. };
  11491. // File:src/loaders/CubeTextureLoader.js
  11492. /**
  11493. * @author mrdoob / http://mrdoob.com/
  11494. */
  11495. THREE.CubeTextureLoader = function ( manager ) {
  11496. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11497. };
  11498. THREE.CubeTextureLoader.prototype = {
  11499. constructor: THREE.CubeTextureLoader,
  11500. load: function ( urls, onLoad, onProgress, onError ) {
  11501. var texture = new THREE.CubeTexture( [] );
  11502. var loader = new THREE.ImageLoader( this.manager );
  11503. loader.setCrossOrigin( this.crossOrigin );
  11504. loader.setPath( this.path );
  11505. var loaded = 0;
  11506. function loadTexture( i ) {
  11507. loader.load( urls[ i ], function ( image ) {
  11508. texture.images[ i ] = image;
  11509. loaded ++;
  11510. if ( loaded === 6 ) {
  11511. texture.needsUpdate = true;
  11512. if ( onLoad ) onLoad( texture );
  11513. }
  11514. }, undefined, onError );
  11515. }
  11516. for ( var i = 0; i < urls.length; ++ i ) {
  11517. loadTexture( i );
  11518. }
  11519. return texture;
  11520. },
  11521. setCrossOrigin: function ( value ) {
  11522. this.crossOrigin = value;
  11523. },
  11524. setPath: function ( value ) {
  11525. this.path = value;
  11526. }
  11527. };
  11528. // File:src/loaders/BinaryTextureLoader.js
  11529. /**
  11530. * @author Nikos M. / https://github.com/foo123/
  11531. *
  11532. * Abstract Base class to load generic binary textures formats (rgbe, hdr, ...)
  11533. */
  11534. THREE.DataTextureLoader = THREE.BinaryTextureLoader = function ( manager ) {
  11535. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11536. // override in sub classes
  11537. this._parser = null;
  11538. };
  11539. THREE.BinaryTextureLoader.prototype = {
  11540. constructor: THREE.BinaryTextureLoader,
  11541. load: function ( url, onLoad, onProgress, onError ) {
  11542. var scope = this;
  11543. var texture = new THREE.DataTexture();
  11544. var loader = new THREE.XHRLoader( this.manager );
  11545. loader.setResponseType( 'arraybuffer' );
  11546. loader.load( url, function ( buffer ) {
  11547. var texData = scope._parser( buffer );
  11548. if ( ! texData ) return;
  11549. if ( undefined !== texData.image ) {
  11550. texture.image = texData.image;
  11551. } else if ( undefined !== texData.data ) {
  11552. texture.image.width = texData.width;
  11553. texture.image.height = texData.height;
  11554. texture.image.data = texData.data;
  11555. }
  11556. texture.wrapS = undefined !== texData.wrapS ? texData.wrapS : THREE.ClampToEdgeWrapping;
  11557. texture.wrapT = undefined !== texData.wrapT ? texData.wrapT : THREE.ClampToEdgeWrapping;
  11558. texture.magFilter = undefined !== texData.magFilter ? texData.magFilter : THREE.LinearFilter;
  11559. texture.minFilter = undefined !== texData.minFilter ? texData.minFilter : THREE.LinearMipMapLinearFilter;
  11560. texture.anisotropy = undefined !== texData.anisotropy ? texData.anisotropy : 1;
  11561. if ( undefined !== texData.format ) {
  11562. texture.format = texData.format;
  11563. }
  11564. if ( undefined !== texData.type ) {
  11565. texture.type = texData.type;
  11566. }
  11567. if ( undefined !== texData.mipmaps ) {
  11568. texture.mipmaps = texData.mipmaps;
  11569. }
  11570. if ( 1 === texData.mipmapCount ) {
  11571. texture.minFilter = THREE.LinearFilter;
  11572. }
  11573. texture.needsUpdate = true;
  11574. if ( onLoad ) onLoad( texture, texData );
  11575. }, onProgress, onError );
  11576. return texture;
  11577. }
  11578. };
  11579. // File:src/loaders/CompressedTextureLoader.js
  11580. /**
  11581. * @author mrdoob / http://mrdoob.com/
  11582. *
  11583. * Abstract Base class to block based textures loader (dds, pvr, ...)
  11584. */
  11585. THREE.CompressedTextureLoader = function ( manager ) {
  11586. this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager;
  11587. // override in sub classes
  11588. this._parser = null;
  11589. };
  11590. THREE.CompressedTextureLoader.prototype = {
  11591. constructor: THREE.CompressedTextureLoader,
  11592. load: function ( url, onLoad, onProgress, onError ) {
  11593. var scope = this;
  11594. var images = [];
  11595. var texture = new THREE.CompressedTexture();
  11596. texture.image = images;
  11597. var loader = new THREE.XHRLoader( this.manager );
  11598. loader.setPath( this.path );
  11599. loader.setResponseType( 'arraybuffer' );
  11600. function loadTexture( i ) {
  11601. loader.load( url[ i ], function ( buffer ) {
  11602. var texDatas = scope._parser( buffer, true );
  11603. images[ i ] = {
  11604. width: texDatas.width,
  11605. height: texDatas.height,
  11606. format: texDatas.format,
  11607. mipmaps: texDatas.mipmaps
  11608. };
  11609. loaded += 1;
  11610. if ( loaded === 6 ) {
  11611. if ( texDatas.mipmapCount === 1 )
  11612. texture.minFilter = THREE.LinearFilter;
  11613. texture.format = texDatas.format;
  11614. texture.needsUpdate = true;
  11615. if ( onLoad ) onLoad( texture );
  11616. }
  11617. }, onProgress, onError );
  11618. }
  11619. if ( Array.isArray( url ) ) {
  11620. var loaded = 0;
  11621. for ( var i = 0, il = url.length; i < il; ++ i ) {
  11622. loadTexture( i );
  11623. }
  11624. } else {
  11625. // compressed cubemap texture stored in a single DDS file
  11626. loader.load( url, function ( buffer ) {
  11627. var texDatas = scope._parser( buffer, true );
  11628. if ( texDatas.isCubemap ) {
  11629. var faces = texDatas.mipmaps.length / texDatas.mipmapCount;
  11630. for ( var f = 0; f < faces; f ++ ) {
  11631. images[ f ] = { mipmaps : [] };
  11632. for ( var i = 0; i < texDatas.mipmapCount; i ++ ) {
  11633. images[ f ].mipmaps.push( texDatas.mipmaps[ f * texDatas.mipmapCount + i ] );
  11634. images[ f ].format = texDatas.format;
  11635. images[ f ].width = texDatas.width;
  11636. images[ f ].height = texDatas.height;
  11637. }
  11638. }
  11639. } else {
  11640. texture.image.width = texDatas.width;
  11641. texture.image.height = texDatas.height;
  11642. texture.mipmaps = texDatas.mipmaps;
  11643. }
  11644. if ( texDatas.mipmapCount === 1 ) {
  11645. texture.minFilter = THREE.LinearFilter;
  11646. }
  11647. texture.format = texDatas.format;
  11648. texture.needsUpdate = true;
  11649. if ( onLoad ) onLoad( texture );
  11650. }, onProgress, onError );
  11651. }
  11652. return texture;
  11653. },
  11654. setPath: function ( value ) {
  11655. this.path = value;
  11656. }
  11657. };
  11658. // File:src/materials/Material.js
  11659. /**
  11660. * @author mrdoob / http://mrdoob.com/
  11661. * @author alteredq / http://alteredqualia.com/
  11662. */
  11663. THREE.Material = function () {
  11664. Object.defineProperty( this, 'id', { value: THREE.MaterialIdCount ++ } );
  11665. this.uuid = THREE.Math.generateUUID();
  11666. this.name = '';
  11667. this.type = 'Material';
  11668. this.side = THREE.FrontSide;
  11669. this.opacity = 1;
  11670. this.transparent = false;
  11671. this.blending = THREE.NormalBlending;
  11672. this.blendSrc = THREE.SrcAlphaFactor;
  11673. this.blendDst = THREE.OneMinusSrcAlphaFactor;
  11674. this.blendEquation = THREE.AddEquation;
  11675. this.blendSrcAlpha = null;
  11676. this.blendDstAlpha = null;
  11677. this.blendEquationAlpha = null;
  11678. this.depthFunc = THREE.LessEqualDepth;
  11679. this.depthTest = true;
  11680. this.depthWrite = true;
  11681. this.colorWrite = true;
  11682. this.precision = null; // override the renderer's default precision for this material
  11683. this.polygonOffset = false;
  11684. this.polygonOffsetFactor = 0;
  11685. this.polygonOffsetUnits = 0;
  11686. this.alphaTest = 0;
  11687. this.overdraw = 0; // Overdrawn pixels (typically between 0 and 1) for fixing antialiasing gaps in CanvasRenderer
  11688. this.visible = true;
  11689. this._needsUpdate = true;
  11690. };
  11691. THREE.Material.prototype = {
  11692. constructor: THREE.Material,
  11693. get needsUpdate () {
  11694. return this._needsUpdate;
  11695. },
  11696. set needsUpdate ( value ) {
  11697. if ( value === true ) this.update();
  11698. this._needsUpdate = value;
  11699. },
  11700. setValues: function ( values ) {
  11701. if ( values === undefined ) return;
  11702. for ( var key in values ) {
  11703. var newValue = values[ key ];
  11704. if ( newValue === undefined ) {
  11705. console.warn( "THREE.Material: '" + key + "' parameter is undefined." );
  11706. continue;
  11707. }
  11708. var currentValue = this[ key ];
  11709. if ( currentValue === undefined ) {
  11710. console.warn( "THREE." + this.type + ": '" + key + "' is not a property of this material." );
  11711. continue;
  11712. }
  11713. if ( currentValue instanceof THREE.Color ) {
  11714. currentValue.set( newValue );
  11715. } else if ( currentValue instanceof THREE.Vector3 && newValue instanceof THREE.Vector3 ) {
  11716. currentValue.copy( newValue );
  11717. } else if ( key === 'overdraw' ) {
  11718. // ensure overdraw is backwards-compatible with legacy boolean type
  11719. this[ key ] = Number( newValue );
  11720. } else {
  11721. this[ key ] = newValue;
  11722. }
  11723. }
  11724. },
  11725. toJSON: function ( meta ) {
  11726. var isRoot = meta === undefined;
  11727. if ( isRoot ) {
  11728. meta = {
  11729. textures: {},
  11730. images: {}
  11731. };
  11732. }
  11733. var data = {
  11734. metadata: {
  11735. version: 4.4,
  11736. type: 'Material',
  11737. generator: 'Material.toJSON'
  11738. }
  11739. };
  11740. // standard Material serialization
  11741. data.uuid = this.uuid;
  11742. data.type = this.type;
  11743. if ( this.name !== '' ) data.name = this.name;
  11744. if ( this.color instanceof THREE.Color ) data.color = this.color.getHex();
  11745. if ( this.roughness !== 0.5 ) data.roughness = this.roughness;
  11746. if ( this.metalness !== 0.5 ) data.metalness = this.metalness;
  11747. if ( this.emissive instanceof THREE.Color ) data.emissive = this.emissive.getHex();
  11748. if ( this.specular instanceof THREE.Color ) data.specular = this.specular.getHex();
  11749. if ( this.shininess !== undefined ) data.shininess = this.shininess;
  11750. if ( this.map instanceof THREE.Texture ) data.map = this.map.toJSON( meta ).uuid;
  11751. if ( this.alphaMap instanceof THREE.Texture ) data.alphaMap = this.alphaMap.toJSON( meta ).uuid;
  11752. if ( this.lightMap instanceof THREE.Texture ) data.lightMap = this.lightMap.toJSON( meta ).uuid;
  11753. if ( this.bumpMap instanceof THREE.Texture ) {
  11754. data.bumpMap = this.bumpMap.toJSON( meta ).uuid;
  11755. data.bumpScale = this.bumpScale;
  11756. }
  11757. if ( this.normalMap instanceof THREE.Texture ) {
  11758. data.normalMap = this.normalMap.toJSON( meta ).uuid;
  11759. data.normalScale = this.normalScale.toArray();
  11760. }
  11761. if ( this.displacementMap instanceof THREE.Texture ) {
  11762. data.displacementMap = this.displacementMap.toJSON( meta ).uuid;
  11763. data.displacementScale = this.displacementScale;
  11764. data.displacementBias = this.displacementBias;
  11765. }
  11766. if ( this.roughnessMap instanceof THREE.Texture ) data.roughnessMap = this.roughnessMap.toJSON( meta ).uuid;
  11767. if ( this.metalnessMap instanceof THREE.Texture ) data.metalnessMap = this.metalnessMap.toJSON( meta ).uuid;
  11768. if ( this.emissiveMap instanceof THREE.Texture ) data.emissiveMap = this.emissiveMap.toJSON( meta ).uuid;
  11769. if ( this.specularMap instanceof THREE.Texture ) data.specularMap = this.specularMap.toJSON( meta ).uuid;
  11770. if ( this.envMap instanceof THREE.Texture ) {
  11771. data.envMap = this.envMap.toJSON( meta ).uuid;
  11772. data.reflectivity = this.reflectivity; // Scale behind envMap
  11773. }
  11774. if ( this.size !== undefined ) data.size = this.size;
  11775. if ( this.sizeAttenuation !== undefined ) data.sizeAttenuation = this.sizeAttenuation;
  11776. if ( this.vertexColors !== undefined && this.vertexColors !== THREE.NoColors ) data.vertexColors = this.vertexColors;
  11777. if ( this.shading !== undefined && this.shading !== THREE.SmoothShading ) data.shading = this.shading;
  11778. if ( this.blending !== undefined && this.blending !== THREE.NormalBlending ) data.blending = this.blending;
  11779. if ( this.side !== undefined && this.side !== THREE.FrontSide ) data.side = this.side;
  11780. if ( this.opacity < 1 ) data.opacity = this.opacity;
  11781. if ( this.transparent === true ) data.transparent = this.transparent;
  11782. if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
  11783. if ( this.wireframe === true ) data.wireframe = this.wireframe;
  11784. if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
  11785. // TODO: Copied from Object3D.toJSON
  11786. function extractFromCache ( cache ) {
  11787. var values = [];
  11788. for ( var key in cache ) {
  11789. var data = cache[ key ];
  11790. delete data.metadata;
  11791. values.push( data );
  11792. }
  11793. return values;
  11794. }
  11795. if ( isRoot ) {
  11796. var textures = extractFromCache( meta.textures );
  11797. var images = extractFromCache( meta.images );
  11798. if ( textures.length > 0 ) data.textures = textures;
  11799. if ( images.length > 0 ) data.images = images;
  11800. }
  11801. return data;
  11802. },
  11803. clone: function () {
  11804. return new this.constructor().copy( this );
  11805. },
  11806. copy: function ( source ) {
  11807. this.name = source.name;
  11808. this.side = source.side;
  11809. this.opacity = source.opacity;
  11810. this.transparent = source.transparent;
  11811. this.blending = source.blending;
  11812. this.blendSrc = source.blendSrc;
  11813. this.blendDst = source.blendDst;
  11814. this.blendEquation = source.blendEquation;
  11815. this.blendSrcAlpha = source.blendSrcAlpha;
  11816. this.blendDstAlpha = source.blendDstAlpha;
  11817. this.blendEquationAlpha = source.blendEquationAlpha;
  11818. this.depthFunc = source.depthFunc;
  11819. this.depthTest = source.depthTest;
  11820. this.depthWrite = source.depthWrite;
  11821. this.colorWrite = source.colorWrite;
  11822. this.precision = source.precision;
  11823. this.polygonOffset = source.polygonOffset;
  11824. this.polygonOffsetFactor = source.polygonOffsetFactor;
  11825. this.polygonOffsetUnits = source.polygonOffsetUnits;
  11826. this.alphaTest = source.alphaTest;
  11827. this.overdraw = source.overdraw;
  11828. this.visible = source.visible;
  11829. return this;
  11830. },
  11831. update: function () {
  11832. this.dispatchEvent( { type: 'update' } );
  11833. },
  11834. dispose: function () {
  11835. this.dispatchEvent( { type: 'dispose' } );
  11836. }
  11837. };
  11838. THREE.EventDispatcher.prototype.apply( THREE.Material.prototype );
  11839. THREE.MaterialIdCount = 0;
  11840. // File:src/materials/LineBasicMaterial.js
  11841. /**
  11842. * @author mrdoob / http://mrdoob.com/
  11843. * @author alteredq / http://alteredqualia.com/
  11844. *
  11845. * parameters = {
  11846. * color: <hex>,
  11847. * opacity: <float>,
  11848. *
  11849. * blending: THREE.NormalBlending,
  11850. * depthTest: <bool>,
  11851. * depthWrite: <bool>,
  11852. *
  11853. * linewidth: <float>,
  11854. * linecap: "round",
  11855. * linejoin: "round",
  11856. *
  11857. * vertexColors: <bool>
  11858. *
  11859. * fog: <bool>
  11860. * }
  11861. */
  11862. THREE.LineBasicMaterial = function ( parameters ) {
  11863. THREE.Material.call( this );
  11864. this.type = 'LineBasicMaterial';
  11865. this.color = new THREE.Color( 0xffffff );
  11866. this.linewidth = 1;
  11867. this.linecap = 'round';
  11868. this.linejoin = 'round';
  11869. this.vertexColors = THREE.NoColors;
  11870. this.fog = true;
  11871. this.setValues( parameters );
  11872. };
  11873. THREE.LineBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11874. THREE.LineBasicMaterial.prototype.constructor = THREE.LineBasicMaterial;
  11875. THREE.LineBasicMaterial.prototype.copy = function ( source ) {
  11876. THREE.Material.prototype.copy.call( this, source );
  11877. this.color.copy( source.color );
  11878. this.linewidth = source.linewidth;
  11879. this.linecap = source.linecap;
  11880. this.linejoin = source.linejoin;
  11881. this.vertexColors = source.vertexColors;
  11882. this.fog = source.fog;
  11883. return this;
  11884. };
  11885. // File:src/materials/LineDashedMaterial.js
  11886. /**
  11887. * @author alteredq / http://alteredqualia.com/
  11888. *
  11889. * parameters = {
  11890. * color: <hex>,
  11891. * opacity: <float>,
  11892. *
  11893. * blending: THREE.NormalBlending,
  11894. * depthTest: <bool>,
  11895. * depthWrite: <bool>,
  11896. *
  11897. * linewidth: <float>,
  11898. *
  11899. * scale: <float>,
  11900. * dashSize: <float>,
  11901. * gapSize: <float>,
  11902. *
  11903. * vertexColors: THREE.NoColors / THREE.FaceColors / THREE.VertexColors
  11904. *
  11905. * fog: <bool>
  11906. * }
  11907. */
  11908. THREE.LineDashedMaterial = function ( parameters ) {
  11909. THREE.Material.call( this );
  11910. this.type = 'LineDashedMaterial';
  11911. this.color = new THREE.Color( 0xffffff );
  11912. this.linewidth = 1;
  11913. this.scale = 1;
  11914. this.dashSize = 3;
  11915. this.gapSize = 1;
  11916. this.vertexColors = THREE.NoColors;
  11917. this.fog = true;
  11918. this.setValues( parameters );
  11919. };
  11920. THREE.LineDashedMaterial.prototype = Object.create( THREE.Material.prototype );
  11921. THREE.LineDashedMaterial.prototype.constructor = THREE.LineDashedMaterial;
  11922. THREE.LineDashedMaterial.prototype.copy = function ( source ) {
  11923. THREE.Material.prototype.copy.call( this, source );
  11924. this.color.copy( source.color );
  11925. this.linewidth = source.linewidth;
  11926. this.scale = source.scale;
  11927. this.dashSize = source.dashSize;
  11928. this.gapSize = source.gapSize;
  11929. this.vertexColors = source.vertexColors;
  11930. this.fog = source.fog;
  11931. return this;
  11932. };
  11933. // File:src/materials/MeshBasicMaterial.js
  11934. /**
  11935. * @author mrdoob / http://mrdoob.com/
  11936. * @author alteredq / http://alteredqualia.com/
  11937. *
  11938. * parameters = {
  11939. * color: <hex>,
  11940. * opacity: <float>,
  11941. * map: new THREE.Texture( <Image> ),
  11942. *
  11943. * aoMap: new THREE.Texture( <Image> ),
  11944. * aoMapIntensity: <float>
  11945. *
  11946. * specularMap: new THREE.Texture( <Image> ),
  11947. *
  11948. * alphaMap: new THREE.Texture( <Image> ),
  11949. *
  11950. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  11951. * combine: THREE.Multiply,
  11952. * reflectivity: <float>,
  11953. * refractionRatio: <float>,
  11954. *
  11955. * shading: THREE.SmoothShading,
  11956. * blending: THREE.NormalBlending,
  11957. * depthTest: <bool>,
  11958. * depthWrite: <bool>,
  11959. *
  11960. * wireframe: <boolean>,
  11961. * wireframeLinewidth: <float>,
  11962. *
  11963. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  11964. *
  11965. * skinning: <bool>,
  11966. * morphTargets: <bool>,
  11967. *
  11968. * fog: <bool>
  11969. * }
  11970. */
  11971. THREE.MeshBasicMaterial = function ( parameters ) {
  11972. THREE.Material.call( this );
  11973. this.type = 'MeshBasicMaterial';
  11974. this.color = new THREE.Color( 0xffffff ); // emissive
  11975. this.map = null;
  11976. this.aoMap = null;
  11977. this.aoMapIntensity = 1.0;
  11978. this.specularMap = null;
  11979. this.alphaMap = null;
  11980. this.envMap = null;
  11981. this.combine = THREE.MultiplyOperation;
  11982. this.reflectivity = 1;
  11983. this.refractionRatio = 0.98;
  11984. this.fog = true;
  11985. this.shading = THREE.SmoothShading;
  11986. this.wireframe = false;
  11987. this.wireframeLinewidth = 1;
  11988. this.wireframeLinecap = 'round';
  11989. this.wireframeLinejoin = 'round';
  11990. this.vertexColors = THREE.NoColors;
  11991. this.skinning = false;
  11992. this.morphTargets = false;
  11993. this.setValues( parameters );
  11994. };
  11995. THREE.MeshBasicMaterial.prototype = Object.create( THREE.Material.prototype );
  11996. THREE.MeshBasicMaterial.prototype.constructor = THREE.MeshBasicMaterial;
  11997. THREE.MeshBasicMaterial.prototype.copy = function ( source ) {
  11998. THREE.Material.prototype.copy.call( this, source );
  11999. this.color.copy( source.color );
  12000. this.map = source.map;
  12001. this.aoMap = source.aoMap;
  12002. this.aoMapIntensity = source.aoMapIntensity;
  12003. this.specularMap = source.specularMap;
  12004. this.alphaMap = source.alphaMap;
  12005. this.envMap = source.envMap;
  12006. this.combine = source.combine;
  12007. this.reflectivity = source.reflectivity;
  12008. this.refractionRatio = source.refractionRatio;
  12009. this.fog = source.fog;
  12010. this.shading = source.shading;
  12011. this.wireframe = source.wireframe;
  12012. this.wireframeLinewidth = source.wireframeLinewidth;
  12013. this.wireframeLinecap = source.wireframeLinecap;
  12014. this.wireframeLinejoin = source.wireframeLinejoin;
  12015. this.vertexColors = source.vertexColors;
  12016. this.skinning = source.skinning;
  12017. this.morphTargets = source.morphTargets;
  12018. return this;
  12019. };
  12020. // File:src/materials/MeshLambertMaterial.js
  12021. /**
  12022. * @author mrdoob / http://mrdoob.com/
  12023. * @author alteredq / http://alteredqualia.com/
  12024. *
  12025. * parameters = {
  12026. * color: <hex>,
  12027. * opacity: <float>,
  12028. *
  12029. * map: new THREE.Texture( <Image> ),
  12030. *
  12031. * lightMap: new THREE.Texture( <Image> ),
  12032. * lightMapIntensity: <float>
  12033. *
  12034. * aoMap: new THREE.Texture( <Image> ),
  12035. * aoMapIntensity: <float>
  12036. *
  12037. * emissive: <hex>,
  12038. * emissiveIntensity: <float>
  12039. * emissiveMap: new THREE.Texture( <Image> ),
  12040. *
  12041. * specularMap: new THREE.Texture( <Image> ),
  12042. *
  12043. * alphaMap: new THREE.Texture( <Image> ),
  12044. *
  12045. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12046. * combine: THREE.Multiply,
  12047. * reflectivity: <float>,
  12048. * refractionRatio: <float>,
  12049. *
  12050. * blending: THREE.NormalBlending,
  12051. * depthTest: <bool>,
  12052. * depthWrite: <bool>,
  12053. *
  12054. * wireframe: <boolean>,
  12055. * wireframeLinewidth: <float>,
  12056. *
  12057. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12058. *
  12059. * skinning: <bool>,
  12060. * morphTargets: <bool>,
  12061. * morphNormals: <bool>,
  12062. *
  12063. * fog: <bool>
  12064. * }
  12065. */
  12066. THREE.MeshLambertMaterial = function ( parameters ) {
  12067. THREE.Material.call( this );
  12068. this.type = 'MeshLambertMaterial';
  12069. this.color = new THREE.Color( 0xffffff ); // diffuse
  12070. this.map = null;
  12071. this.lightMap = null;
  12072. this.lightMapIntensity = 1.0;
  12073. this.aoMap = null;
  12074. this.aoMapIntensity = 1.0;
  12075. this.emissive = new THREE.Color( 0x000000 );
  12076. this.emissiveIntensity = 1.0;
  12077. this.emissiveMap = null;
  12078. this.specularMap = null;
  12079. this.alphaMap = null;
  12080. this.envMap = null;
  12081. this.combine = THREE.MultiplyOperation;
  12082. this.reflectivity = 1;
  12083. this.refractionRatio = 0.98;
  12084. this.fog = true;
  12085. this.wireframe = false;
  12086. this.wireframeLinewidth = 1;
  12087. this.wireframeLinecap = 'round';
  12088. this.wireframeLinejoin = 'round';
  12089. this.vertexColors = THREE.NoColors;
  12090. this.skinning = false;
  12091. this.morphTargets = false;
  12092. this.morphNormals = false;
  12093. this.setValues( parameters );
  12094. };
  12095. THREE.MeshLambertMaterial.prototype = Object.create( THREE.Material.prototype );
  12096. THREE.MeshLambertMaterial.prototype.constructor = THREE.MeshLambertMaterial;
  12097. THREE.MeshLambertMaterial.prototype.copy = function ( source ) {
  12098. THREE.Material.prototype.copy.call( this, source );
  12099. this.color.copy( source.color );
  12100. this.map = source.map;
  12101. this.lightMap = source.lightMap;
  12102. this.lightMapIntensity = source.lightMapIntensity;
  12103. this.aoMap = source.aoMap;
  12104. this.aoMapIntensity = source.aoMapIntensity;
  12105. this.emissive.copy( source.emissive );
  12106. this.emissiveMap = source.emissiveMap;
  12107. this.emissiveIntensity = source.emissiveIntensity;
  12108. this.specularMap = source.specularMap;
  12109. this.alphaMap = source.alphaMap;
  12110. this.envMap = source.envMap;
  12111. this.combine = source.combine;
  12112. this.reflectivity = source.reflectivity;
  12113. this.refractionRatio = source.refractionRatio;
  12114. this.fog = source.fog;
  12115. this.wireframe = source.wireframe;
  12116. this.wireframeLinewidth = source.wireframeLinewidth;
  12117. this.wireframeLinecap = source.wireframeLinecap;
  12118. this.wireframeLinejoin = source.wireframeLinejoin;
  12119. this.vertexColors = source.vertexColors;
  12120. this.skinning = source.skinning;
  12121. this.morphTargets = source.morphTargets;
  12122. this.morphNormals = source.morphNormals;
  12123. return this;
  12124. };
  12125. // File:src/materials/MeshPhongMaterial.js
  12126. /**
  12127. * @author mrdoob / http://mrdoob.com/
  12128. * @author alteredq / http://alteredqualia.com/
  12129. *
  12130. * parameters = {
  12131. * color: <hex>,
  12132. * specular: <hex>,
  12133. * shininess: <float>,
  12134. * opacity: <float>,
  12135. *
  12136. * map: new THREE.Texture( <Image> ),
  12137. *
  12138. * lightMap: new THREE.Texture( <Image> ),
  12139. * lightMapIntensity: <float>
  12140. *
  12141. * aoMap: new THREE.Texture( <Image> ),
  12142. * aoMapIntensity: <float>
  12143. *
  12144. * emissive: <hex>,
  12145. * emissiveIntensity: <float>
  12146. * emissiveMap: new THREE.Texture( <Image> ),
  12147. *
  12148. * bumpMap: new THREE.Texture( <Image> ),
  12149. * bumpScale: <float>,
  12150. *
  12151. * normalMap: new THREE.Texture( <Image> ),
  12152. * normalScale: <Vector2>,
  12153. *
  12154. * displacementMap: new THREE.Texture( <Image> ),
  12155. * displacementScale: <float>,
  12156. * displacementBias: <float>,
  12157. *
  12158. * specularMap: new THREE.Texture( <Image> ),
  12159. *
  12160. * alphaMap: new THREE.Texture( <Image> ),
  12161. *
  12162. * envMap: new THREE.TextureCube( [posx, negx, posy, negy, posz, negz] ),
  12163. * combine: THREE.Multiply,
  12164. * reflectivity: <float>,
  12165. * refractionRatio: <float>,
  12166. *
  12167. * shading: THREE.SmoothShading,
  12168. * blending: THREE.NormalBlending,
  12169. * depthTest: <bool>,
  12170. * depthWrite: <bool>,
  12171. *
  12172. * wireframe: <boolean>,
  12173. * wireframeLinewidth: <float>,
  12174. *
  12175. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12176. *
  12177. * skinning: <bool>,
  12178. * morphTargets: <bool>,
  12179. * morphNormals: <bool>,
  12180. *
  12181. * fog: <bool>
  12182. * }
  12183. */
  12184. THREE.MeshPhongMaterial = function ( parameters ) {
  12185. THREE.Material.call( this );
  12186. this.type = 'MeshPhongMaterial';
  12187. this.color = new THREE.Color( 0xffffff ); // diffuse
  12188. this.specular = new THREE.Color( 0x111111 );
  12189. this.shininess = 30;
  12190. this.map = null;
  12191. this.lightMap = null;
  12192. this.lightMapIntensity = 1.0;
  12193. this.aoMap = null;
  12194. this.aoMapIntensity = 1.0;
  12195. this.emissive = new THREE.Color( 0x000000 );
  12196. this.emissiveIntensity = 1.0;
  12197. this.emissiveMap = null;
  12198. this.bumpMap = null;
  12199. this.bumpScale = 1;
  12200. this.normalMap = null;
  12201. this.normalScale = new THREE.Vector2( 1, 1 );
  12202. this.displacementMap = null;
  12203. this.displacementScale = 1;
  12204. this.displacementBias = 0;
  12205. this.specularMap = null;
  12206. this.alphaMap = null;
  12207. this.envMap = null;
  12208. this.combine = THREE.MultiplyOperation;
  12209. this.reflectivity = 1;
  12210. this.refractionRatio = 0.98;
  12211. this.fog = true;
  12212. this.shading = THREE.SmoothShading;
  12213. this.wireframe = false;
  12214. this.wireframeLinewidth = 1;
  12215. this.wireframeLinecap = 'round';
  12216. this.wireframeLinejoin = 'round';
  12217. this.vertexColors = THREE.NoColors;
  12218. this.skinning = false;
  12219. this.morphTargets = false;
  12220. this.morphNormals = false;
  12221. this.setValues( parameters );
  12222. };
  12223. THREE.MeshPhongMaterial.prototype = Object.create( THREE.Material.prototype );
  12224. THREE.MeshPhongMaterial.prototype.constructor = THREE.MeshPhongMaterial;
  12225. THREE.MeshPhongMaterial.prototype.copy = function ( source ) {
  12226. THREE.Material.prototype.copy.call( this, source );
  12227. this.color.copy( source.color );
  12228. this.specular.copy( source.specular );
  12229. this.shininess = source.shininess;
  12230. this.map = source.map;
  12231. this.lightMap = source.lightMap;
  12232. this.lightMapIntensity = source.lightMapIntensity;
  12233. this.aoMap = source.aoMap;
  12234. this.aoMapIntensity = source.aoMapIntensity;
  12235. this.emissive.copy( source.emissive );
  12236. this.emissiveMap = source.emissiveMap;
  12237. this.emissiveIntensity = source.emissiveIntensity;
  12238. this.bumpMap = source.bumpMap;
  12239. this.bumpScale = source.bumpScale;
  12240. this.normalMap = source.normalMap;
  12241. this.normalScale.copy( source.normalScale );
  12242. this.displacementMap = source.displacementMap;
  12243. this.displacementScale = source.displacementScale;
  12244. this.displacementBias = source.displacementBias;
  12245. this.specularMap = source.specularMap;
  12246. this.alphaMap = source.alphaMap;
  12247. this.envMap = source.envMap;
  12248. this.combine = source.combine;
  12249. this.reflectivity = source.reflectivity;
  12250. this.refractionRatio = source.refractionRatio;
  12251. this.fog = source.fog;
  12252. this.shading = source.shading;
  12253. this.wireframe = source.wireframe;
  12254. this.wireframeLinewidth = source.wireframeLinewidth;
  12255. this.wireframeLinecap = source.wireframeLinecap;
  12256. this.wireframeLinejoin = source.wireframeLinejoin;
  12257. this.vertexColors = source.vertexColors;
  12258. this.skinning = source.skinning;
  12259. this.morphTargets = source.morphTargets;
  12260. this.morphNormals = source.morphNormals;
  12261. return this;
  12262. };
  12263. // File:src/materials/MeshStandardMaterial.js
  12264. /**
  12265. * @author WestLangley / http://github.com/WestLangley
  12266. *
  12267. * parameters = {
  12268. * color: <hex>,
  12269. * roughness: <float>,
  12270. * metalness: <float>,
  12271. * opacity: <float>,
  12272. *
  12273. * map: new THREE.Texture( <Image> ),
  12274. *
  12275. * lightMap: new THREE.Texture( <Image> ),
  12276. * lightMapIntensity: <float>
  12277. *
  12278. * aoMap: new THREE.Texture( <Image> ),
  12279. * aoMapIntensity: <float>
  12280. *
  12281. * emissive: <hex>,
  12282. * emissiveIntensity: <float>
  12283. * emissiveMap: new THREE.Texture( <Image> ),
  12284. *
  12285. * bumpMap: new THREE.Texture( <Image> ),
  12286. * bumpScale: <float>,
  12287. *
  12288. * normalMap: new THREE.Texture( <Image> ),
  12289. * normalScale: <Vector2>,
  12290. *
  12291. * displacementMap: new THREE.Texture( <Image> ),
  12292. * displacementScale: <float>,
  12293. * displacementBias: <float>,
  12294. *
  12295. * roughnessMap: new THREE.Texture( <Image> ),
  12296. *
  12297. * metalnessMap: new THREE.Texture( <Image> ),
  12298. *
  12299. * alphaMap: new THREE.Texture( <Image> ),
  12300. *
  12301. * envMap: new THREE.CubeTexture( [posx, negx, posy, negy, posz, negz] ),
  12302. * envMapIntensity: <float>
  12303. *
  12304. * refractionRatio: <float>,
  12305. *
  12306. * shading: THREE.SmoothShading,
  12307. * blending: THREE.NormalBlending,
  12308. * depthTest: <bool>,
  12309. * depthWrite: <bool>,
  12310. *
  12311. * wireframe: <boolean>,
  12312. * wireframeLinewidth: <float>,
  12313. *
  12314. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12315. *
  12316. * skinning: <bool>,
  12317. * morphTargets: <bool>,
  12318. * morphNormals: <bool>,
  12319. *
  12320. * fog: <bool>
  12321. * }
  12322. */
  12323. THREE.MeshStandardMaterial = function ( parameters ) {
  12324. THREE.Material.call( this );
  12325. this.type = 'MeshStandardMaterial';
  12326. this.color = new THREE.Color( 0xffffff ); // diffuse
  12327. this.roughness = 0.5;
  12328. this.metalness = 0.5;
  12329. this.map = null;
  12330. this.lightMap = null;
  12331. this.lightMapIntensity = 1.0;
  12332. this.aoMap = null;
  12333. this.aoMapIntensity = 1.0;
  12334. this.emissive = new THREE.Color( 0x000000 );
  12335. this.emissiveIntensity = 1.0;
  12336. this.emissiveMap = null;
  12337. this.bumpMap = null;
  12338. this.bumpScale = 1;
  12339. this.normalMap = null;
  12340. this.normalScale = new THREE.Vector2( 1, 1 );
  12341. this.displacementMap = null;
  12342. this.displacementScale = 1;
  12343. this.displacementBias = 0;
  12344. this.roughnessMap = null;
  12345. this.metalnessMap = null;
  12346. this.alphaMap = null;
  12347. this.envMap = null;
  12348. this.envMapIntensity = 1.0;
  12349. this.refractionRatio = 0.98;
  12350. this.fog = true;
  12351. this.shading = THREE.SmoothShading;
  12352. this.wireframe = false;
  12353. this.wireframeLinewidth = 1;
  12354. this.wireframeLinecap = 'round';
  12355. this.wireframeLinejoin = 'round';
  12356. this.vertexColors = THREE.NoColors;
  12357. this.skinning = false;
  12358. this.morphTargets = false;
  12359. this.morphNormals = false;
  12360. this.setValues( parameters );
  12361. };
  12362. THREE.MeshStandardMaterial.prototype = Object.create( THREE.Material.prototype );
  12363. THREE.MeshStandardMaterial.prototype.constructor = THREE.MeshStandardMaterial;
  12364. THREE.MeshStandardMaterial.prototype.copy = function ( source ) {
  12365. THREE.Material.prototype.copy.call( this, source );
  12366. this.color.copy( source.color );
  12367. this.roughness = source.roughness;
  12368. this.metalness = source.metalness;
  12369. this.map = source.map;
  12370. this.lightMap = source.lightMap;
  12371. this.lightMapIntensity = source.lightMapIntensity;
  12372. this.aoMap = source.aoMap;
  12373. this.aoMapIntensity = source.aoMapIntensity;
  12374. this.emissive.copy( source.emissive );
  12375. this.emissiveMap = source.emissiveMap;
  12376. this.emissiveIntensity = source.emissiveIntensity;
  12377. this.bumpMap = source.bumpMap;
  12378. this.bumpScale = source.bumpScale;
  12379. this.normalMap = source.normalMap;
  12380. this.normalScale.copy( source.normalScale );
  12381. this.displacementMap = source.displacementMap;
  12382. this.displacementScale = source.displacementScale;
  12383. this.displacementBias = source.displacementBias;
  12384. this.roughnessMap = source.roughnessMap;
  12385. this.metalnessMap = source.metalnessMap;
  12386. this.alphaMap = source.alphaMap;
  12387. this.envMap = source.envMap;
  12388. this.envMapIntensity = source.envMapIntensity;
  12389. this.refractionRatio = source.refractionRatio;
  12390. this.fog = source.fog;
  12391. this.shading = source.shading;
  12392. this.wireframe = source.wireframe;
  12393. this.wireframeLinewidth = source.wireframeLinewidth;
  12394. this.wireframeLinecap = source.wireframeLinecap;
  12395. this.wireframeLinejoin = source.wireframeLinejoin;
  12396. this.vertexColors = source.vertexColors;
  12397. this.skinning = source.skinning;
  12398. this.morphTargets = source.morphTargets;
  12399. this.morphNormals = source.morphNormals;
  12400. return this;
  12401. };
  12402. // File:src/materials/MeshDepthMaterial.js
  12403. /**
  12404. * @author mrdoob / http://mrdoob.com/
  12405. * @author alteredq / http://alteredqualia.com/
  12406. *
  12407. * parameters = {
  12408. * opacity: <float>,
  12409. *
  12410. * blending: THREE.NormalBlending,
  12411. * depthTest: <bool>,
  12412. * depthWrite: <bool>,
  12413. *
  12414. * wireframe: <boolean>,
  12415. * wireframeLinewidth: <float>
  12416. * }
  12417. */
  12418. THREE.MeshDepthMaterial = function ( parameters ) {
  12419. THREE.Material.call( this );
  12420. this.type = 'MeshDepthMaterial';
  12421. this.morphTargets = false;
  12422. this.wireframe = false;
  12423. this.wireframeLinewidth = 1;
  12424. this.setValues( parameters );
  12425. };
  12426. THREE.MeshDepthMaterial.prototype = Object.create( THREE.Material.prototype );
  12427. THREE.MeshDepthMaterial.prototype.constructor = THREE.MeshDepthMaterial;
  12428. THREE.MeshDepthMaterial.prototype.copy = function ( source ) {
  12429. THREE.Material.prototype.copy.call( this, source );
  12430. this.wireframe = source.wireframe;
  12431. this.wireframeLinewidth = source.wireframeLinewidth;
  12432. return this;
  12433. };
  12434. // File:src/materials/MeshNormalMaterial.js
  12435. /**
  12436. * @author mrdoob / http://mrdoob.com/
  12437. *
  12438. * parameters = {
  12439. * opacity: <float>,
  12440. *
  12441. * shading: THREE.FlatShading,
  12442. * blending: THREE.NormalBlending,
  12443. * depthTest: <bool>,
  12444. * depthWrite: <bool>,
  12445. *
  12446. * wireframe: <boolean>,
  12447. * wireframeLinewidth: <float>
  12448. * }
  12449. */
  12450. THREE.MeshNormalMaterial = function ( parameters ) {
  12451. THREE.Material.call( this, parameters );
  12452. this.type = 'MeshNormalMaterial';
  12453. this.wireframe = false;
  12454. this.wireframeLinewidth = 1;
  12455. this.morphTargets = false;
  12456. this.setValues( parameters );
  12457. };
  12458. THREE.MeshNormalMaterial.prototype = Object.create( THREE.Material.prototype );
  12459. THREE.MeshNormalMaterial.prototype.constructor = THREE.MeshNormalMaterial;
  12460. THREE.MeshNormalMaterial.prototype.copy = function ( source ) {
  12461. THREE.Material.prototype.copy.call( this, source );
  12462. this.wireframe = source.wireframe;
  12463. this.wireframeLinewidth = source.wireframeLinewidth;
  12464. return this;
  12465. };
  12466. // File:src/materials/MultiMaterial.js
  12467. /**
  12468. * @author mrdoob / http://mrdoob.com/
  12469. */
  12470. THREE.MultiMaterial = function ( materials ) {
  12471. this.uuid = THREE.Math.generateUUID();
  12472. this.type = 'MultiMaterial';
  12473. this.materials = materials instanceof Array ? materials : [];
  12474. this.visible = true;
  12475. };
  12476. THREE.MultiMaterial.prototype = {
  12477. constructor: THREE.MultiMaterial,
  12478. toJSON: function ( meta ) {
  12479. var output = {
  12480. metadata: {
  12481. version: 4.2,
  12482. type: 'material',
  12483. generator: 'MaterialExporter'
  12484. },
  12485. uuid: this.uuid,
  12486. type: this.type,
  12487. materials: []
  12488. };
  12489. var materials = this.materials;
  12490. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  12491. var material = materials[ i ].toJSON( meta );
  12492. delete material.metadata;
  12493. output.materials.push( material );
  12494. }
  12495. output.visible = this.visible;
  12496. return output;
  12497. },
  12498. clone: function () {
  12499. var material = new this.constructor();
  12500. for ( var i = 0; i < this.materials.length; i ++ ) {
  12501. material.materials.push( this.materials[ i ].clone() );
  12502. }
  12503. material.visible = this.visible;
  12504. return material;
  12505. }
  12506. };
  12507. // File:src/materials/PointsMaterial.js
  12508. /**
  12509. * @author mrdoob / http://mrdoob.com/
  12510. * @author alteredq / http://alteredqualia.com/
  12511. *
  12512. * parameters = {
  12513. * color: <hex>,
  12514. * opacity: <float>,
  12515. * map: new THREE.Texture( <Image> ),
  12516. *
  12517. * size: <float>,
  12518. * sizeAttenuation: <bool>,
  12519. *
  12520. * blending: THREE.NormalBlending,
  12521. * depthTest: <bool>,
  12522. * depthWrite: <bool>,
  12523. *
  12524. * vertexColors: <bool>,
  12525. *
  12526. * fog: <bool>
  12527. * }
  12528. */
  12529. THREE.PointsMaterial = function ( parameters ) {
  12530. THREE.Material.call( this );
  12531. this.type = 'PointsMaterial';
  12532. this.color = new THREE.Color( 0xffffff );
  12533. this.map = null;
  12534. this.size = 1;
  12535. this.sizeAttenuation = true;
  12536. this.vertexColors = THREE.NoColors;
  12537. this.fog = true;
  12538. this.setValues( parameters );
  12539. };
  12540. THREE.PointsMaterial.prototype = Object.create( THREE.Material.prototype );
  12541. THREE.PointsMaterial.prototype.constructor = THREE.PointsMaterial;
  12542. THREE.PointsMaterial.prototype.copy = function ( source ) {
  12543. THREE.Material.prototype.copy.call( this, source );
  12544. this.color.copy( source.color );
  12545. this.map = source.map;
  12546. this.size = source.size;
  12547. this.sizeAttenuation = source.sizeAttenuation;
  12548. this.vertexColors = source.vertexColors;
  12549. this.fog = source.fog;
  12550. return this;
  12551. };
  12552. // File:src/materials/ShaderMaterial.js
  12553. /**
  12554. * @author alteredq / http://alteredqualia.com/
  12555. *
  12556. * parameters = {
  12557. * defines: { "label" : "value" },
  12558. * uniforms: { "parameter1": { type: "f", value: 1.0 }, "parameter2": { type: "i" value2: 2 } },
  12559. *
  12560. * fragmentShader: <string>,
  12561. * vertexShader: <string>,
  12562. *
  12563. * shading: THREE.SmoothShading,
  12564. * blending: THREE.NormalBlending,
  12565. * depthTest: <bool>,
  12566. * depthWrite: <bool>,
  12567. *
  12568. * wireframe: <boolean>,
  12569. * wireframeLinewidth: <float>,
  12570. *
  12571. * lights: <bool>,
  12572. *
  12573. * vertexColors: THREE.NoColors / THREE.VertexColors / THREE.FaceColors,
  12574. *
  12575. * skinning: <bool>,
  12576. * morphTargets: <bool>,
  12577. * morphNormals: <bool>,
  12578. *
  12579. * fog: <bool>
  12580. * }
  12581. */
  12582. THREE.ShaderMaterial = function ( parameters ) {
  12583. THREE.Material.call( this );
  12584. this.type = 'ShaderMaterial';
  12585. this.defines = {};
  12586. this.uniforms = {};
  12587. this.vertexShader = 'void main() {\n\tgl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );\n}';
  12588. this.fragmentShader = 'void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0 );\n}';
  12589. this.shading = THREE.SmoothShading;
  12590. this.linewidth = 1;
  12591. this.wireframe = false;
  12592. this.wireframeLinewidth = 1;
  12593. this.fog = false; // set to use scene fog
  12594. this.lights = false; // set to use scene lights
  12595. this.vertexColors = THREE.NoColors; // set to use "color" attribute stream
  12596. this.skinning = false; // set to use skinning attribute streams
  12597. this.morphTargets = false; // set to use morph targets
  12598. this.morphNormals = false; // set to use morph normals
  12599. this.extensions = {
  12600. derivatives: false, // set to use derivatives
  12601. fragDepth: false, // set to use fragment depth values
  12602. drawBuffers: false, // set to use draw buffers
  12603. shaderTextureLOD: false // set to use shader texture LOD
  12604. };
  12605. // When rendered geometry doesn't include these attributes but the material does,
  12606. // use these default values in WebGL. This avoids errors when buffer data is missing.
  12607. this.defaultAttributeValues = {
  12608. 'color': [ 1, 1, 1 ],
  12609. 'uv': [ 0, 0 ],
  12610. 'uv2': [ 0, 0 ]
  12611. };
  12612. this.index0AttributeName = undefined;
  12613. if ( parameters !== undefined ) {
  12614. if ( parameters.attributes !== undefined ) {
  12615. console.error( 'THREE.ShaderMaterial: attributes should now be defined in THREE.BufferGeometry instead.' );
  12616. }
  12617. this.setValues( parameters );
  12618. }
  12619. };
  12620. THREE.ShaderMaterial.prototype = Object.create( THREE.Material.prototype );
  12621. THREE.ShaderMaterial.prototype.constructor = THREE.ShaderMaterial;
  12622. THREE.ShaderMaterial.prototype.copy = function ( source ) {
  12623. THREE.Material.prototype.copy.call( this, source );
  12624. this.fragmentShader = source.fragmentShader;
  12625. this.vertexShader = source.vertexShader;
  12626. this.uniforms = THREE.UniformsUtils.clone( source.uniforms );
  12627. this.defines = source.defines;
  12628. this.shading = source.shading;
  12629. this.wireframe = source.wireframe;
  12630. this.wireframeLinewidth = source.wireframeLinewidth;
  12631. this.fog = source.fog;
  12632. this.lights = source.lights;
  12633. this.vertexColors = source.vertexColors;
  12634. this.skinning = source.skinning;
  12635. this.morphTargets = source.morphTargets;
  12636. this.morphNormals = source.morphNormals;
  12637. this.extensions = source.extensions;
  12638. return this;
  12639. };
  12640. THREE.ShaderMaterial.prototype.toJSON = function ( meta ) {
  12641. var data = THREE.Material.prototype.toJSON.call( this, meta );
  12642. data.uniforms = this.uniforms;
  12643. data.vertexShader = this.vertexShader;
  12644. data.fragmentShader = this.fragmentShader;
  12645. return data;
  12646. };
  12647. // File:src/materials/RawShaderMaterial.js
  12648. /**
  12649. * @author mrdoob / http://mrdoob.com/
  12650. */
  12651. THREE.RawShaderMaterial = function ( parameters ) {
  12652. THREE.ShaderMaterial.call( this, parameters );
  12653. this.type = 'RawShaderMaterial';
  12654. };
  12655. THREE.RawShaderMaterial.prototype = Object.create( THREE.ShaderMaterial.prototype );
  12656. THREE.RawShaderMaterial.prototype.constructor = THREE.RawShaderMaterial;
  12657. // File:src/materials/SpriteMaterial.js
  12658. /**
  12659. * @author alteredq / http://alteredqualia.com/
  12660. *
  12661. * parameters = {
  12662. * color: <hex>,
  12663. * opacity: <float>,
  12664. * map: new THREE.Texture( <Image> ),
  12665. *
  12666. * blending: THREE.NormalBlending,
  12667. * depthTest: <bool>,
  12668. * depthWrite: <bool>,
  12669. *
  12670. * uvOffset: new THREE.Vector2(),
  12671. * uvScale: new THREE.Vector2(),
  12672. *
  12673. * fog: <bool>
  12674. * }
  12675. */
  12676. THREE.SpriteMaterial = function ( parameters ) {
  12677. THREE.Material.call( this );
  12678. this.type = 'SpriteMaterial';
  12679. this.color = new THREE.Color( 0xffffff );
  12680. this.map = null;
  12681. this.rotation = 0;
  12682. this.fog = false;
  12683. // set parameters
  12684. this.setValues( parameters );
  12685. };
  12686. THREE.SpriteMaterial.prototype = Object.create( THREE.Material.prototype );
  12687. THREE.SpriteMaterial.prototype.constructor = THREE.SpriteMaterial;
  12688. THREE.SpriteMaterial.prototype.copy = function ( source ) {
  12689. THREE.Material.prototype.copy.call( this, source );
  12690. this.color.copy( source.color );
  12691. this.map = source.map;
  12692. this.rotation = source.rotation;
  12693. this.fog = source.fog;
  12694. return this;
  12695. };
  12696. // File:src/textures/Texture.js
  12697. /**
  12698. * @author mrdoob / http://mrdoob.com/
  12699. * @author alteredq / http://alteredqualia.com/
  12700. * @author szimek / https://github.com/szimek/
  12701. */
  12702. THREE.Texture = function ( image, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12703. Object.defineProperty( this, 'id', { value: THREE.TextureIdCount ++ } );
  12704. this.uuid = THREE.Math.generateUUID();
  12705. this.name = '';
  12706. this.sourceFile = '';
  12707. this.image = image !== undefined ? image : THREE.Texture.DEFAULT_IMAGE;
  12708. this.mipmaps = [];
  12709. this.mapping = mapping !== undefined ? mapping : THREE.Texture.DEFAULT_MAPPING;
  12710. this.wrapS = wrapS !== undefined ? wrapS : THREE.ClampToEdgeWrapping;
  12711. this.wrapT = wrapT !== undefined ? wrapT : THREE.ClampToEdgeWrapping;
  12712. this.magFilter = magFilter !== undefined ? magFilter : THREE.LinearFilter;
  12713. this.minFilter = minFilter !== undefined ? minFilter : THREE.LinearMipMapLinearFilter;
  12714. this.anisotropy = anisotropy !== undefined ? anisotropy : 1;
  12715. this.format = format !== undefined ? format : THREE.RGBAFormat;
  12716. this.type = type !== undefined ? type : THREE.UnsignedByteType;
  12717. this.offset = new THREE.Vector2( 0, 0 );
  12718. this.repeat = new THREE.Vector2( 1, 1 );
  12719. this.generateMipmaps = true;
  12720. this.premultiplyAlpha = false;
  12721. this.flipY = true;
  12722. this.unpackAlignment = 4; // valid values: 1, 2, 4, 8 (see http://www.khronos.org/opengles/sdk/docs/man/xhtml/glPixelStorei.xml)
  12723. this.version = 0;
  12724. this.onUpdate = null;
  12725. };
  12726. THREE.Texture.DEFAULT_IMAGE = undefined;
  12727. THREE.Texture.DEFAULT_MAPPING = THREE.UVMapping;
  12728. THREE.Texture.prototype = {
  12729. constructor: THREE.Texture,
  12730. set needsUpdate ( value ) {
  12731. if ( value === true ) this.version ++;
  12732. },
  12733. clone: function () {
  12734. return new this.constructor().copy( this );
  12735. },
  12736. copy: function ( source ) {
  12737. this.image = source.image;
  12738. this.mipmaps = source.mipmaps.slice( 0 );
  12739. this.mapping = source.mapping;
  12740. this.wrapS = source.wrapS;
  12741. this.wrapT = source.wrapT;
  12742. this.magFilter = source.magFilter;
  12743. this.minFilter = source.minFilter;
  12744. this.anisotropy = source.anisotropy;
  12745. this.format = source.format;
  12746. this.type = source.type;
  12747. this.offset.copy( source.offset );
  12748. this.repeat.copy( source.repeat );
  12749. this.generateMipmaps = source.generateMipmaps;
  12750. this.premultiplyAlpha = source.premultiplyAlpha;
  12751. this.flipY = source.flipY;
  12752. this.unpackAlignment = source.unpackAlignment;
  12753. return this;
  12754. },
  12755. toJSON: function ( meta ) {
  12756. if ( meta.textures[ this.uuid ] !== undefined ) {
  12757. return meta.textures[ this.uuid ];
  12758. }
  12759. function getDataURL( image ) {
  12760. var canvas;
  12761. if ( image.toDataURL !== undefined ) {
  12762. canvas = image;
  12763. } else {
  12764. canvas = document.createElement( 'canvas' );
  12765. canvas.width = image.width;
  12766. canvas.height = image.height;
  12767. canvas.getContext( '2d' ).drawImage( image, 0, 0, image.width, image.height );
  12768. }
  12769. if ( canvas.width > 2048 || canvas.height > 2048 ) {
  12770. return canvas.toDataURL( 'image/jpeg', 0.6 );
  12771. } else {
  12772. return canvas.toDataURL( 'image/png' );
  12773. }
  12774. }
  12775. var output = {
  12776. metadata: {
  12777. version: 4.4,
  12778. type: 'Texture',
  12779. generator: 'Texture.toJSON'
  12780. },
  12781. uuid: this.uuid,
  12782. name: this.name,
  12783. mapping: this.mapping,
  12784. repeat: [ this.repeat.x, this.repeat.y ],
  12785. offset: [ this.offset.x, this.offset.y ],
  12786. wrap: [ this.wrapS, this.wrapT ],
  12787. minFilter: this.minFilter,
  12788. magFilter: this.magFilter,
  12789. anisotropy: this.anisotropy
  12790. };
  12791. if ( this.image !== undefined ) {
  12792. // TODO: Move to THREE.Image
  12793. var image = this.image;
  12794. if ( image.uuid === undefined ) {
  12795. image.uuid = THREE.Math.generateUUID(); // UGH
  12796. }
  12797. if ( meta.images[ image.uuid ] === undefined ) {
  12798. meta.images[ image.uuid ] = {
  12799. uuid: image.uuid,
  12800. url: getDataURL( image )
  12801. };
  12802. }
  12803. output.image = image.uuid;
  12804. }
  12805. meta.textures[ this.uuid ] = output;
  12806. return output;
  12807. },
  12808. dispose: function () {
  12809. this.dispatchEvent( { type: 'dispose' } );
  12810. },
  12811. transformUv: function ( uv ) {
  12812. if ( this.mapping !== THREE.UVMapping ) return;
  12813. uv.multiply( this.repeat );
  12814. uv.add( this.offset );
  12815. if ( uv.x < 0 || uv.x > 1 ) {
  12816. switch ( this.wrapS ) {
  12817. case THREE.RepeatWrapping:
  12818. uv.x = uv.x - Math.floor( uv.x );
  12819. break;
  12820. case THREE.ClampToEdgeWrapping:
  12821. uv.x = uv.x < 0 ? 0 : 1;
  12822. break;
  12823. case THREE.MirroredRepeatWrapping:
  12824. if ( Math.abs( Math.floor( uv.x ) % 2 ) === 1 ) {
  12825. uv.x = Math.ceil( uv.x ) - uv.x;
  12826. } else {
  12827. uv.x = uv.x - Math.floor( uv.x );
  12828. }
  12829. break;
  12830. }
  12831. }
  12832. if ( uv.y < 0 || uv.y > 1 ) {
  12833. switch ( this.wrapT ) {
  12834. case THREE.RepeatWrapping:
  12835. uv.y = uv.y - Math.floor( uv.y );
  12836. break;
  12837. case THREE.ClampToEdgeWrapping:
  12838. uv.y = uv.y < 0 ? 0 : 1;
  12839. break;
  12840. case THREE.MirroredRepeatWrapping:
  12841. if ( Math.abs( Math.floor( uv.y ) % 2 ) === 1 ) {
  12842. uv.y = Math.ceil( uv.y ) - uv.y;
  12843. } else {
  12844. uv.y = uv.y - Math.floor( uv.y );
  12845. }
  12846. break;
  12847. }
  12848. }
  12849. if ( this.flipY ) {
  12850. uv.y = 1 - uv.y;
  12851. }
  12852. }
  12853. };
  12854. THREE.EventDispatcher.prototype.apply( THREE.Texture.prototype );
  12855. THREE.TextureIdCount = 0;
  12856. // File:src/textures/CanvasTexture.js
  12857. /**
  12858. * @author mrdoob / http://mrdoob.com/
  12859. */
  12860. THREE.CanvasTexture = function ( canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12861. THREE.Texture.call( this, canvas, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12862. this.needsUpdate = true;
  12863. };
  12864. THREE.CanvasTexture.prototype = Object.create( THREE.Texture.prototype );
  12865. THREE.CanvasTexture.prototype.constructor = THREE.CanvasTexture;
  12866. // File:src/textures/CubeTexture.js
  12867. /**
  12868. * @author mrdoob / http://mrdoob.com/
  12869. */
  12870. THREE.CubeTexture = function ( images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12871. mapping = mapping !== undefined ? mapping : THREE.CubeReflectionMapping;
  12872. THREE.Texture.call( this, images, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12873. this.images = images;
  12874. this.flipY = false;
  12875. };
  12876. THREE.CubeTexture.prototype = Object.create( THREE.Texture.prototype );
  12877. THREE.CubeTexture.prototype.constructor = THREE.CubeTexture;
  12878. THREE.CubeTexture.prototype.copy = function ( source ) {
  12879. THREE.Texture.prototype.copy.call( this, source );
  12880. this.images = source.images;
  12881. return this;
  12882. };
  12883. // File:src/textures/CompressedTexture.js
  12884. /**
  12885. * @author alteredq / http://alteredqualia.com/
  12886. */
  12887. THREE.CompressedTexture = function ( mipmaps, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12888. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12889. this.image = { width: width, height: height };
  12890. this.mipmaps = mipmaps;
  12891. // no flipping for cube textures
  12892. // (also flipping doesn't work for compressed textures )
  12893. this.flipY = false;
  12894. // can't generate mipmaps for compressed textures
  12895. // mips must be embedded in DDS files
  12896. this.generateMipmaps = false;
  12897. };
  12898. THREE.CompressedTexture.prototype = Object.create( THREE.Texture.prototype );
  12899. THREE.CompressedTexture.prototype.constructor = THREE.CompressedTexture;
  12900. // File:src/textures/DataTexture.js
  12901. /**
  12902. * @author alteredq / http://alteredqualia.com/
  12903. */
  12904. THREE.DataTexture = function ( data, width, height, format, type, mapping, wrapS, wrapT, magFilter, minFilter, anisotropy ) {
  12905. THREE.Texture.call( this, null, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12906. this.image = { data: data, width: width, height: height };
  12907. this.magFilter = magFilter !== undefined ? magFilter : THREE.NearestFilter;
  12908. this.minFilter = minFilter !== undefined ? minFilter : THREE.NearestFilter;
  12909. this.flipY = false;
  12910. this.generateMipmaps = false;
  12911. };
  12912. THREE.DataTexture.prototype = Object.create( THREE.Texture.prototype );
  12913. THREE.DataTexture.prototype.constructor = THREE.DataTexture;
  12914. // File:src/textures/VideoTexture.js
  12915. /**
  12916. * @author mrdoob / http://mrdoob.com/
  12917. */
  12918. THREE.VideoTexture = function ( video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy ) {
  12919. THREE.Texture.call( this, video, mapping, wrapS, wrapT, magFilter, minFilter, format, type, anisotropy );
  12920. this.generateMipmaps = false;
  12921. var scope = this;
  12922. function update() {
  12923. requestAnimationFrame( update );
  12924. if ( video.readyState === video.HAVE_ENOUGH_DATA ) {
  12925. scope.needsUpdate = true;
  12926. }
  12927. }
  12928. update();
  12929. };
  12930. THREE.VideoTexture.prototype = Object.create( THREE.Texture.prototype );
  12931. THREE.VideoTexture.prototype.constructor = THREE.VideoTexture;
  12932. // File:src/objects/Group.js
  12933. /**
  12934. * @author mrdoob / http://mrdoob.com/
  12935. */
  12936. THREE.Group = function () {
  12937. THREE.Object3D.call( this );
  12938. this.type = 'Group';
  12939. };
  12940. THREE.Group.prototype = Object.create( THREE.Object3D.prototype );
  12941. THREE.Group.prototype.constructor = THREE.Group;
  12942. // File:src/objects/Points.js
  12943. /**
  12944. * @author alteredq / http://alteredqualia.com/
  12945. */
  12946. THREE.Points = function ( geometry, material ) {
  12947. THREE.Object3D.call( this );
  12948. this.type = 'Points';
  12949. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  12950. this.material = material !== undefined ? material : new THREE.PointsMaterial( { color: Math.random() * 0xffffff } );
  12951. };
  12952. THREE.Points.prototype = Object.create( THREE.Object3D.prototype );
  12953. THREE.Points.prototype.constructor = THREE.Points;
  12954. THREE.Points.prototype.raycast = ( function () {
  12955. var inverseMatrix = new THREE.Matrix4();
  12956. var ray = new THREE.Ray();
  12957. var sphere = new THREE.Sphere();
  12958. return function raycast( raycaster, intersects ) {
  12959. var object = this;
  12960. var geometry = this.geometry;
  12961. var matrixWorld = this.matrixWorld;
  12962. var threshold = raycaster.params.Points.threshold;
  12963. // Checking boundingSphere distance to ray
  12964. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  12965. sphere.copy( geometry.boundingSphere );
  12966. sphere.applyMatrix4( matrixWorld );
  12967. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  12968. //
  12969. inverseMatrix.getInverse( matrixWorld );
  12970. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  12971. var localThreshold = threshold / ( ( this.scale.x + this.scale.y + this.scale.z ) / 3 );
  12972. var localThresholdSq = localThreshold * localThreshold;
  12973. var position = new THREE.Vector3();
  12974. function testPoint( point, index ) {
  12975. var rayPointDistanceSq = ray.distanceSqToPoint( point );
  12976. if ( rayPointDistanceSq < localThresholdSq ) {
  12977. var intersectPoint = ray.closestPointToPoint( point );
  12978. intersectPoint.applyMatrix4( matrixWorld );
  12979. var distance = raycaster.ray.origin.distanceTo( intersectPoint );
  12980. if ( distance < raycaster.near || distance > raycaster.far ) return;
  12981. intersects.push( {
  12982. distance: distance,
  12983. distanceToRay: Math.sqrt( rayPointDistanceSq ),
  12984. point: intersectPoint.clone(),
  12985. index: index,
  12986. face: null,
  12987. object: object
  12988. } );
  12989. }
  12990. }
  12991. if ( geometry instanceof THREE.BufferGeometry ) {
  12992. var index = geometry.index;
  12993. var attributes = geometry.attributes;
  12994. var positions = attributes.position.array;
  12995. if ( index !== null ) {
  12996. var indices = index.array;
  12997. for ( var i = 0, il = indices.length; i < il; i ++ ) {
  12998. var a = indices[ i ];
  12999. position.fromArray( positions, a * 3 );
  13000. testPoint( position, a );
  13001. }
  13002. } else {
  13003. for ( var i = 0, l = positions.length / 3; i < l; i ++ ) {
  13004. position.fromArray( positions, i * 3 );
  13005. testPoint( position, i );
  13006. }
  13007. }
  13008. } else {
  13009. var vertices = geometry.vertices;
  13010. for ( var i = 0, l = vertices.length; i < l; i ++ ) {
  13011. testPoint( vertices[ i ], i );
  13012. }
  13013. }
  13014. };
  13015. }() );
  13016. THREE.Points.prototype.clone = function () {
  13017. return new this.constructor( this.geometry, this.material ).copy( this );
  13018. };
  13019. // File:src/objects/Line.js
  13020. /**
  13021. * @author mrdoob / http://mrdoob.com/
  13022. */
  13023. THREE.Line = function ( geometry, material, mode ) {
  13024. if ( mode === 1 ) {
  13025. console.warn( 'THREE.Line: parameter THREE.LinePieces no longer supported. Created THREE.LineSegments instead.' );
  13026. return new THREE.LineSegments( geometry, material );
  13027. }
  13028. THREE.Object3D.call( this );
  13029. this.type = 'Line';
  13030. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13031. this.material = material !== undefined ? material : new THREE.LineBasicMaterial( { color: Math.random() * 0xffffff } );
  13032. };
  13033. THREE.Line.prototype = Object.create( THREE.Object3D.prototype );
  13034. THREE.Line.prototype.constructor = THREE.Line;
  13035. THREE.Line.prototype.raycast = ( function () {
  13036. var inverseMatrix = new THREE.Matrix4();
  13037. var ray = new THREE.Ray();
  13038. var sphere = new THREE.Sphere();
  13039. return function raycast( raycaster, intersects ) {
  13040. var precision = raycaster.linePrecision;
  13041. var precisionSq = precision * precision;
  13042. var geometry = this.geometry;
  13043. var matrixWorld = this.matrixWorld;
  13044. // Checking boundingSphere distance to ray
  13045. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13046. sphere.copy( geometry.boundingSphere );
  13047. sphere.applyMatrix4( matrixWorld );
  13048. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13049. //
  13050. inverseMatrix.getInverse( matrixWorld );
  13051. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13052. var vStart = new THREE.Vector3();
  13053. var vEnd = new THREE.Vector3();
  13054. var interSegment = new THREE.Vector3();
  13055. var interRay = new THREE.Vector3();
  13056. var step = this instanceof THREE.LineSegments ? 2 : 1;
  13057. if ( geometry instanceof THREE.BufferGeometry ) {
  13058. var index = geometry.index;
  13059. var attributes = geometry.attributes;
  13060. var positions = attributes.position.array;
  13061. if ( index !== null ) {
  13062. var indices = index.array;
  13063. for ( var i = 0, l = indices.length - 1; i < l; i += step ) {
  13064. var a = indices[ i ];
  13065. var b = indices[ i + 1 ];
  13066. vStart.fromArray( positions, a * 3 );
  13067. vEnd.fromArray( positions, b * 3 );
  13068. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13069. if ( distSq > precisionSq ) continue;
  13070. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13071. var distance = raycaster.ray.origin.distanceTo( interRay );
  13072. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13073. intersects.push( {
  13074. distance: distance,
  13075. // What do we want? intersection point on the ray or on the segment??
  13076. // point: raycaster.ray.at( distance ),
  13077. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13078. index: i,
  13079. face: null,
  13080. faceIndex: null,
  13081. object: this
  13082. } );
  13083. }
  13084. } else {
  13085. for ( var i = 0, l = positions.length / 3 - 1; i < l; i += step ) {
  13086. vStart.fromArray( positions, 3 * i );
  13087. vEnd.fromArray( positions, 3 * i + 3 );
  13088. var distSq = ray.distanceSqToSegment( vStart, vEnd, interRay, interSegment );
  13089. if ( distSq > precisionSq ) continue;
  13090. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13091. var distance = raycaster.ray.origin.distanceTo( interRay );
  13092. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13093. intersects.push( {
  13094. distance: distance,
  13095. // What do we want? intersection point on the ray or on the segment??
  13096. // point: raycaster.ray.at( distance ),
  13097. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13098. index: i,
  13099. face: null,
  13100. faceIndex: null,
  13101. object: this
  13102. } );
  13103. }
  13104. }
  13105. } else if ( geometry instanceof THREE.Geometry ) {
  13106. var vertices = geometry.vertices;
  13107. var nbVertices = vertices.length;
  13108. for ( var i = 0; i < nbVertices - 1; i += step ) {
  13109. var distSq = ray.distanceSqToSegment( vertices[ i ], vertices[ i + 1 ], interRay, interSegment );
  13110. if ( distSq > precisionSq ) continue;
  13111. interRay.applyMatrix4( this.matrixWorld ); //Move back to world space for distance calculation
  13112. var distance = raycaster.ray.origin.distanceTo( interRay );
  13113. if ( distance < raycaster.near || distance > raycaster.far ) continue;
  13114. intersects.push( {
  13115. distance: distance,
  13116. // What do we want? intersection point on the ray or on the segment??
  13117. // point: raycaster.ray.at( distance ),
  13118. point: interSegment.clone().applyMatrix4( this.matrixWorld ),
  13119. index: i,
  13120. face: null,
  13121. faceIndex: null,
  13122. object: this
  13123. } );
  13124. }
  13125. }
  13126. };
  13127. }() );
  13128. THREE.Line.prototype.clone = function () {
  13129. return new this.constructor( this.geometry, this.material ).copy( this );
  13130. };
  13131. // DEPRECATED
  13132. THREE.LineStrip = 0;
  13133. THREE.LinePieces = 1;
  13134. // File:src/objects/LineSegments.js
  13135. /**
  13136. * @author mrdoob / http://mrdoob.com/
  13137. */
  13138. THREE.LineSegments = function ( geometry, material ) {
  13139. THREE.Line.call( this, geometry, material );
  13140. this.type = 'LineSegments';
  13141. };
  13142. THREE.LineSegments.prototype = Object.create( THREE.Line.prototype );
  13143. THREE.LineSegments.prototype.constructor = THREE.LineSegments;
  13144. // File:src/objects/Mesh.js
  13145. /**
  13146. * @author mrdoob / http://mrdoob.com/
  13147. * @author alteredq / http://alteredqualia.com/
  13148. * @author mikael emtinger / http://gomo.se/
  13149. * @author jonobr1 / http://jonobr1.com/
  13150. */
  13151. THREE.Mesh = function ( geometry, material ) {
  13152. THREE.Object3D.call( this );
  13153. this.type = 'Mesh';
  13154. this.geometry = geometry !== undefined ? geometry : new THREE.Geometry();
  13155. this.material = material !== undefined ? material : new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff } );
  13156. this.drawMode = THREE.TrianglesDrawMode;
  13157. this.updateMorphTargets();
  13158. };
  13159. THREE.Mesh.prototype = Object.create( THREE.Object3D.prototype );
  13160. THREE.Mesh.prototype.constructor = THREE.Mesh;
  13161. THREE.Mesh.prototype.setDrawMode = function ( value ) {
  13162. this.drawMode = value;
  13163. };
  13164. THREE.Mesh.prototype.updateMorphTargets = function () {
  13165. if ( this.geometry.morphTargets !== undefined && this.geometry.morphTargets.length > 0 ) {
  13166. this.morphTargetBase = - 1;
  13167. this.morphTargetInfluences = [];
  13168. this.morphTargetDictionary = {};
  13169. for ( var m = 0, ml = this.geometry.morphTargets.length; m < ml; m ++ ) {
  13170. this.morphTargetInfluences.push( 0 );
  13171. this.morphTargetDictionary[ this.geometry.morphTargets[ m ].name ] = m;
  13172. }
  13173. }
  13174. };
  13175. THREE.Mesh.prototype.getMorphTargetIndexByName = function ( name ) {
  13176. if ( this.morphTargetDictionary[ name ] !== undefined ) {
  13177. return this.morphTargetDictionary[ name ];
  13178. }
  13179. console.warn( 'THREE.Mesh.getMorphTargetIndexByName: morph target ' + name + ' does not exist. Returning 0.' );
  13180. return 0;
  13181. };
  13182. THREE.Mesh.prototype.raycast = ( function () {
  13183. var inverseMatrix = new THREE.Matrix4();
  13184. var ray = new THREE.Ray();
  13185. var sphere = new THREE.Sphere();
  13186. var vA = new THREE.Vector3();
  13187. var vB = new THREE.Vector3();
  13188. var vC = new THREE.Vector3();
  13189. var tempA = new THREE.Vector3();
  13190. var tempB = new THREE.Vector3();
  13191. var tempC = new THREE.Vector3();
  13192. var uvA = new THREE.Vector2();
  13193. var uvB = new THREE.Vector2();
  13194. var uvC = new THREE.Vector2();
  13195. var barycoord = new THREE.Vector3();
  13196. var intersectionPoint = new THREE.Vector3();
  13197. var intersectionPointWorld = new THREE.Vector3();
  13198. function uvIntersection( point, p1, p2, p3, uv1, uv2, uv3 ) {
  13199. THREE.Triangle.barycoordFromPoint( point, p1, p2, p3, barycoord );
  13200. uv1.multiplyScalar( barycoord.x );
  13201. uv2.multiplyScalar( barycoord.y );
  13202. uv3.multiplyScalar( barycoord.z );
  13203. uv1.add( uv2 ).add( uv3 );
  13204. return uv1.clone();
  13205. }
  13206. function checkIntersection( object, raycaster, ray, pA, pB, pC, point ) {
  13207. var intersect;
  13208. var material = object.material;
  13209. if ( material.side === THREE.BackSide ) {
  13210. intersect = ray.intersectTriangle( pC, pB, pA, true, point );
  13211. } else {
  13212. intersect = ray.intersectTriangle( pA, pB, pC, material.side !== THREE.DoubleSide, point );
  13213. }
  13214. if ( intersect === null ) return null;
  13215. intersectionPointWorld.copy( point );
  13216. intersectionPointWorld.applyMatrix4( object.matrixWorld );
  13217. var distance = raycaster.ray.origin.distanceTo( intersectionPointWorld );
  13218. if ( distance < raycaster.near || distance > raycaster.far ) return null;
  13219. return {
  13220. distance: distance,
  13221. point: intersectionPointWorld.clone(),
  13222. object: object
  13223. };
  13224. }
  13225. function checkBufferGeometryIntersection( object, raycaster, ray, positions, uvs, a, b, c ) {
  13226. vA.fromArray( positions, a * 3 );
  13227. vB.fromArray( positions, b * 3 );
  13228. vC.fromArray( positions, c * 3 );
  13229. var intersection = checkIntersection( object, raycaster, ray, vA, vB, vC, intersectionPoint );
  13230. if ( intersection ) {
  13231. if ( uvs ) {
  13232. uvA.fromArray( uvs, a * 2 );
  13233. uvB.fromArray( uvs, b * 2 );
  13234. uvC.fromArray( uvs, c * 2 );
  13235. intersection.uv = uvIntersection( intersectionPoint, vA, vB, vC, uvA, uvB, uvC );
  13236. }
  13237. intersection.face = new THREE.Face3( a, b, c, THREE.Triangle.normal( vA, vB, vC ) );
  13238. intersection.faceIndex = a;
  13239. }
  13240. return intersection;
  13241. }
  13242. return function raycast( raycaster, intersects ) {
  13243. var geometry = this.geometry;
  13244. var material = this.material;
  13245. var matrixWorld = this.matrixWorld;
  13246. if ( material === undefined ) return;
  13247. // Checking boundingSphere distance to ray
  13248. if ( geometry.boundingSphere === null ) geometry.computeBoundingSphere();
  13249. sphere.copy( geometry.boundingSphere );
  13250. sphere.applyMatrix4( matrixWorld );
  13251. if ( raycaster.ray.intersectsSphere( sphere ) === false ) return;
  13252. //
  13253. inverseMatrix.getInverse( matrixWorld );
  13254. ray.copy( raycaster.ray ).applyMatrix4( inverseMatrix );
  13255. // Check boundingBox before continuing
  13256. if ( geometry.boundingBox !== null ) {
  13257. if ( ray.intersectsBox( geometry.boundingBox ) === false ) return;
  13258. }
  13259. var uvs, intersection;
  13260. if ( geometry instanceof THREE.BufferGeometry ) {
  13261. var a, b, c;
  13262. var index = geometry.index;
  13263. var attributes = geometry.attributes;
  13264. var positions = attributes.position.array;
  13265. if ( attributes.uv !== undefined ) {
  13266. uvs = attributes.uv.array;
  13267. }
  13268. if ( index !== null ) {
  13269. var indices = index.array;
  13270. for ( var i = 0, l = indices.length; i < l; i += 3 ) {
  13271. a = indices[ i ];
  13272. b = indices[ i + 1 ];
  13273. c = indices[ i + 2 ];
  13274. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13275. if ( intersection ) {
  13276. intersection.faceIndex = Math.floor( i / 3 ); // triangle number in indices buffer semantics
  13277. intersects.push( intersection );
  13278. }
  13279. }
  13280. } else {
  13281. for ( var i = 0, l = positions.length; i < l; i += 9 ) {
  13282. a = i / 3;
  13283. b = a + 1;
  13284. c = a + 2;
  13285. intersection = checkBufferGeometryIntersection( this, raycaster, ray, positions, uvs, a, b, c );
  13286. if ( intersection ) {
  13287. intersection.index = a; // triangle number in positions buffer semantics
  13288. intersects.push( intersection );
  13289. }
  13290. }
  13291. }
  13292. } else if ( geometry instanceof THREE.Geometry ) {
  13293. var fvA, fvB, fvC;
  13294. var isFaceMaterial = material instanceof THREE.MultiMaterial;
  13295. var materials = isFaceMaterial === true ? material.materials : null;
  13296. var vertices = geometry.vertices;
  13297. var faces = geometry.faces;
  13298. var faceVertexUvs = geometry.faceVertexUvs[ 0 ];
  13299. if ( faceVertexUvs.length > 0 ) uvs = faceVertexUvs;
  13300. for ( var f = 0, fl = faces.length; f < fl; f ++ ) {
  13301. var face = faces[ f ];
  13302. var faceMaterial = isFaceMaterial === true ? materials[ face.materialIndex ] : material;
  13303. if ( faceMaterial === undefined ) continue;
  13304. fvA = vertices[ face.a ];
  13305. fvB = vertices[ face.b ];
  13306. fvC = vertices[ face.c ];
  13307. if ( faceMaterial.morphTargets === true ) {
  13308. var morphTargets = geometry.morphTargets;
  13309. var morphInfluences = this.morphTargetInfluences;
  13310. vA.set( 0, 0, 0 );
  13311. vB.set( 0, 0, 0 );
  13312. vC.set( 0, 0, 0 );
  13313. for ( var t = 0, tl = morphTargets.length; t < tl; t ++ ) {
  13314. var influence = morphInfluences[ t ];
  13315. if ( influence === 0 ) continue;
  13316. var targets = morphTargets[ t ].vertices;
  13317. vA.addScaledVector( tempA.subVectors( targets[ face.a ], fvA ), influence );
  13318. vB.addScaledVector( tempB.subVectors( targets[ face.b ], fvB ), influence );
  13319. vC.addScaledVector( tempC.subVectors( targets[ face.c ], fvC ), influence );
  13320. }
  13321. vA.add( fvA );
  13322. vB.add( fvB );
  13323. vC.add( fvC );
  13324. fvA = vA;
  13325. fvB = vB;
  13326. fvC = vC;
  13327. }
  13328. intersection = checkIntersection( this, raycaster, ray, fvA, fvB, fvC, intersectionPoint );
  13329. if ( intersection ) {
  13330. if ( uvs ) {
  13331. var uvs_f = uvs[ f ];
  13332. uvA.copy( uvs_f[ 0 ] );
  13333. uvB.copy( uvs_f[ 1 ] );
  13334. uvC.copy( uvs_f[ 2 ] );
  13335. intersection.uv = uvIntersection( intersectionPoint, fvA, fvB, fvC, uvA, uvB, uvC );
  13336. }
  13337. intersection.face = face;
  13338. intersection.faceIndex = f;
  13339. intersects.push( intersection );
  13340. }
  13341. }
  13342. }
  13343. };
  13344. }() );
  13345. THREE.Mesh.prototype.clone = function () {
  13346. return new this.constructor( this.geometry, this.material ).copy( this );
  13347. };
  13348. // File:src/objects/Bone.js
  13349. /**
  13350. * @author mikael emtinger / http://gomo.se/
  13351. * @author alteredq / http://alteredqualia.com/
  13352. * @author ikerr / http://verold.com
  13353. */
  13354. THREE.Bone = function ( skin ) {
  13355. THREE.Object3D.call( this );
  13356. this.type = 'Bone';
  13357. this.skin = skin;
  13358. };
  13359. THREE.Bone.prototype = Object.create( THREE.Object3D.prototype );
  13360. THREE.Bone.prototype.constructor = THREE.Bone;
  13361. THREE.Bone.prototype.copy = function ( source ) {
  13362. THREE.Object3D.prototype.copy.call( this, source );
  13363. this.skin = source.skin;
  13364. return this;
  13365. };
  13366. // File:src/objects/Skeleton.js
  13367. /**
  13368. * @author mikael emtinger / http://gomo.se/
  13369. * @author alteredq / http://alteredqualia.com/
  13370. * @author michael guerrero / http://realitymeltdown.com
  13371. * @author ikerr / http://verold.com
  13372. */
  13373. THREE.Skeleton = function ( bones, boneInverses, useVertexTexture ) {
  13374. this.useVertexTexture = useVertexTexture !== undefined ? useVertexTexture : true;
  13375. this.identityMatrix = new THREE.Matrix4();
  13376. // copy the bone array
  13377. bones = bones || [];
  13378. this.bones = bones.slice( 0 );
  13379. // create a bone texture or an array of floats
  13380. if ( this.useVertexTexture ) {
  13381. // layout (1 matrix = 4 pixels)
  13382. // RGBA RGBA RGBA RGBA (=> column1, column2, column3, column4)
  13383. // with 8x8 pixel texture max 16 bones * 4 pixels = (8 * 8)
  13384. // 16x16 pixel texture max 64 bones * 4 pixels = (16 * 16)
  13385. // 32x32 pixel texture max 256 bones * 4 pixels = (32 * 32)
  13386. // 64x64 pixel texture max 1024 bones * 4 pixels = (64 * 64)
  13387. var size = Math.sqrt( this.bones.length * 4 ); // 4 pixels needed for 1 matrix
  13388. size = THREE.Math.nextPowerOfTwo( Math.ceil( size ) );
  13389. size = Math.max( size, 4 );
  13390. this.boneTextureWidth = size;
  13391. this.boneTextureHeight = size;
  13392. this.boneMatrices = new Float32Array( this.boneTextureWidth * this.boneTextureHeight * 4 ); // 4 floats per RGBA pixel
  13393. this.boneTexture = new THREE.DataTexture( this.boneMatrices, this.boneTextureWidth, this.boneTextureHeight, THREE.RGBAFormat, THREE.FloatType );
  13394. } else {
  13395. this.boneMatrices = new Float32Array( 16 * this.bones.length );
  13396. }
  13397. // use the supplied bone inverses or calculate the inverses
  13398. if ( boneInverses === undefined ) {
  13399. this.calculateInverses();
  13400. } else {
  13401. if ( this.bones.length === boneInverses.length ) {
  13402. this.boneInverses = boneInverses.slice( 0 );
  13403. } else {
  13404. console.warn( 'THREE.Skeleton bonInverses is the wrong length.' );
  13405. this.boneInverses = [];
  13406. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13407. this.boneInverses.push( new THREE.Matrix4() );
  13408. }
  13409. }
  13410. }
  13411. };
  13412. THREE.Skeleton.prototype.calculateInverses = function () {
  13413. this.boneInverses = [];
  13414. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13415. var inverse = new THREE.Matrix4();
  13416. if ( this.bones[ b ] ) {
  13417. inverse.getInverse( this.bones[ b ].matrixWorld );
  13418. }
  13419. this.boneInverses.push( inverse );
  13420. }
  13421. };
  13422. THREE.Skeleton.prototype.pose = function () {
  13423. var bone;
  13424. // recover the bind-time world matrices
  13425. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13426. bone = this.bones[ b ];
  13427. if ( bone ) {
  13428. bone.matrixWorld.getInverse( this.boneInverses[ b ] );
  13429. }
  13430. }
  13431. // compute the local matrices, positions, rotations and scales
  13432. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13433. bone = this.bones[ b ];
  13434. if ( bone ) {
  13435. if ( bone.parent ) {
  13436. bone.matrix.getInverse( bone.parent.matrixWorld );
  13437. bone.matrix.multiply( bone.matrixWorld );
  13438. } else {
  13439. bone.matrix.copy( bone.matrixWorld );
  13440. }
  13441. bone.matrix.decompose( bone.position, bone.quaternion, bone.scale );
  13442. }
  13443. }
  13444. };
  13445. THREE.Skeleton.prototype.update = ( function () {
  13446. var offsetMatrix = new THREE.Matrix4();
  13447. return function update() {
  13448. // flatten bone matrices to array
  13449. for ( var b = 0, bl = this.bones.length; b < bl; b ++ ) {
  13450. // compute the offset between the current and the original transform
  13451. var matrix = this.bones[ b ] ? this.bones[ b ].matrixWorld : this.identityMatrix;
  13452. offsetMatrix.multiplyMatrices( matrix, this.boneInverses[ b ] );
  13453. offsetMatrix.flattenToArrayOffset( this.boneMatrices, b * 16 );
  13454. }
  13455. if ( this.useVertexTexture ) {
  13456. this.boneTexture.needsUpdate = true;
  13457. }
  13458. };
  13459. } )();
  13460. THREE.Skeleton.prototype.clone = function () {
  13461. return new THREE.Skeleton( this.bones, this.boneInverses, this.useVertexTexture );
  13462. };
  13463. // File:src/objects/SkinnedMesh.js
  13464. /**
  13465. * @author mikael emtinger / http://gomo.se/
  13466. * @author alteredq / http://alteredqualia.com/
  13467. * @author ikerr / http://verold.com
  13468. */
  13469. THREE.SkinnedMesh = function ( geometry, material, useVertexTexture ) {
  13470. THREE.Mesh.call( this, geometry, material );
  13471. this.type = 'SkinnedMesh';
  13472. this.bindMode = "attached";
  13473. this.bindMatrix = new THREE.Matrix4();
  13474. this.bindMatrixInverse = new THREE.Matrix4();
  13475. // init bones
  13476. // TODO: remove bone creation as there is no reason (other than
  13477. // convenience) for THREE.SkinnedMesh to do this.
  13478. var bones = [];
  13479. if ( this.geometry && this.geometry.bones !== undefined ) {
  13480. var bone, gbone;
  13481. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13482. gbone = this.geometry.bones[ b ];
  13483. bone = new THREE.Bone( this );
  13484. bones.push( bone );
  13485. bone.name = gbone.name;
  13486. bone.position.fromArray( gbone.pos );
  13487. bone.quaternion.fromArray( gbone.rotq );
  13488. if ( gbone.scl !== undefined ) bone.scale.fromArray( gbone.scl );
  13489. }
  13490. for ( var b = 0, bl = this.geometry.bones.length; b < bl; ++ b ) {
  13491. gbone = this.geometry.bones[ b ];
  13492. if ( gbone.parent !== - 1 && gbone.parent !== null ) {
  13493. bones[ gbone.parent ].add( bones[ b ] );
  13494. } else {
  13495. this.add( bones[ b ] );
  13496. }
  13497. }
  13498. }
  13499. this.normalizeSkinWeights();
  13500. this.updateMatrixWorld( true );
  13501. this.bind( new THREE.Skeleton( bones, undefined, useVertexTexture ), this.matrixWorld );
  13502. };
  13503. THREE.SkinnedMesh.prototype = Object.create( THREE.Mesh.prototype );
  13504. THREE.SkinnedMesh.prototype.constructor = THREE.SkinnedMesh;
  13505. THREE.SkinnedMesh.prototype.bind = function( skeleton, bindMatrix ) {
  13506. this.skeleton = skeleton;
  13507. if ( bindMatrix === undefined ) {
  13508. this.updateMatrixWorld( true );
  13509. this.skeleton.calculateInverses();
  13510. bindMatrix = this.matrixWorld;
  13511. }
  13512. this.bindMatrix.copy( bindMatrix );
  13513. this.bindMatrixInverse.getInverse( bindMatrix );
  13514. };
  13515. THREE.SkinnedMesh.prototype.pose = function () {
  13516. this.skeleton.pose();
  13517. };
  13518. THREE.SkinnedMesh.prototype.normalizeSkinWeights = function () {
  13519. if ( this.geometry instanceof THREE.Geometry ) {
  13520. for ( var i = 0; i < this.geometry.skinWeights.length; i ++ ) {
  13521. var sw = this.geometry.skinWeights[ i ];
  13522. var scale = 1.0 / sw.lengthManhattan();
  13523. if ( scale !== Infinity ) {
  13524. sw.multiplyScalar( scale );
  13525. } else {
  13526. sw.set( 1, 0, 0, 0 ); // do something reasonable
  13527. }
  13528. }
  13529. } else if ( this.geometry instanceof THREE.BufferGeometry ) {
  13530. var vec = new THREE.Vector4();
  13531. var skinWeight = this.geometry.attributes.skinWeight;
  13532. for ( var i = 0; i < skinWeight.count; i ++ ) {
  13533. vec.x = skinWeight.getX( i );
  13534. vec.y = skinWeight.getY( i );
  13535. vec.z = skinWeight.getZ( i );
  13536. vec.w = skinWeight.getW( i );
  13537. var scale = 1.0 / vec.lengthManhattan();
  13538. if ( scale !== Infinity ) {
  13539. vec.multiplyScalar( scale );
  13540. } else {
  13541. vec.set( 1, 0, 0, 0 ); // do something reasonable
  13542. }
  13543. skinWeight.setXYZW( i, vec.x, vec.y, vec.z, vec.w );
  13544. }
  13545. }
  13546. };
  13547. THREE.SkinnedMesh.prototype.updateMatrixWorld = function( force ) {
  13548. THREE.Mesh.prototype.updateMatrixWorld.call( this, true );
  13549. if ( this.bindMode === "attached" ) {
  13550. this.bindMatrixInverse.getInverse( this.matrixWorld );
  13551. } else if ( this.bindMode === "detached" ) {
  13552. this.bindMatrixInverse.getInverse( this.bindMatrix );
  13553. } else {
  13554. console.warn( 'THREE.SkinnedMesh unrecognized bindMode: ' + this.bindMode );
  13555. }
  13556. };
  13557. THREE.SkinnedMesh.prototype.clone = function() {
  13558. return new this.constructor( this.geometry, this.material, this.useVertexTexture ).copy( this );
  13559. };
  13560. // File:src/objects/LOD.js
  13561. /**
  13562. * @author mikael emtinger / http://gomo.se/
  13563. * @author alteredq / http://alteredqualia.com/
  13564. * @author mrdoob / http://mrdoob.com/
  13565. */
  13566. THREE.LOD = function () {
  13567. THREE.Object3D.call( this );
  13568. this.type = 'LOD';
  13569. Object.defineProperties( this, {
  13570. levels: {
  13571. enumerable: true,
  13572. value: []
  13573. },
  13574. objects: {
  13575. get: function () {
  13576. console.warn( 'THREE.LOD: .objects has been renamed to .levels.' );
  13577. return this.levels;
  13578. }
  13579. }
  13580. } );
  13581. };
  13582. THREE.LOD.prototype = Object.create( THREE.Object3D.prototype );
  13583. THREE.LOD.prototype.constructor = THREE.LOD;
  13584. THREE.LOD.prototype.addLevel = function ( object, distance ) {
  13585. if ( distance === undefined ) distance = 0;
  13586. distance = Math.abs( distance );
  13587. var levels = this.levels;
  13588. for ( var l = 0; l < levels.length; l ++ ) {
  13589. if ( distance < levels[ l ].distance ) {
  13590. break;
  13591. }
  13592. }
  13593. levels.splice( l, 0, { distance: distance, object: object } );
  13594. this.add( object );
  13595. };
  13596. THREE.LOD.prototype.getObjectForDistance = function ( distance ) {
  13597. var levels = this.levels;
  13598. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13599. if ( distance < levels[ i ].distance ) {
  13600. break;
  13601. }
  13602. }
  13603. return levels[ i - 1 ].object;
  13604. };
  13605. THREE.LOD.prototype.raycast = ( function () {
  13606. var matrixPosition = new THREE.Vector3();
  13607. return function raycast( raycaster, intersects ) {
  13608. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13609. var distance = raycaster.ray.origin.distanceTo( matrixPosition );
  13610. this.getObjectForDistance( distance ).raycast( raycaster, intersects );
  13611. };
  13612. }() );
  13613. THREE.LOD.prototype.update = function () {
  13614. var v1 = new THREE.Vector3();
  13615. var v2 = new THREE.Vector3();
  13616. return function update( camera ) {
  13617. var levels = this.levels;
  13618. if ( levels.length > 1 ) {
  13619. v1.setFromMatrixPosition( camera.matrixWorld );
  13620. v2.setFromMatrixPosition( this.matrixWorld );
  13621. var distance = v1.distanceTo( v2 );
  13622. levels[ 0 ].object.visible = true;
  13623. for ( var i = 1, l = levels.length; i < l; i ++ ) {
  13624. if ( distance >= levels[ i ].distance ) {
  13625. levels[ i - 1 ].object.visible = false;
  13626. levels[ i ].object.visible = true;
  13627. } else {
  13628. break;
  13629. }
  13630. }
  13631. for ( ; i < l; i ++ ) {
  13632. levels[ i ].object.visible = false;
  13633. }
  13634. }
  13635. };
  13636. }();
  13637. THREE.LOD.prototype.copy = function ( source ) {
  13638. THREE.Object3D.prototype.copy.call( this, source, false );
  13639. var levels = source.levels;
  13640. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13641. var level = levels[ i ];
  13642. this.addLevel( level.object.clone(), level.distance );
  13643. }
  13644. return this;
  13645. };
  13646. THREE.LOD.prototype.toJSON = function ( meta ) {
  13647. var data = THREE.Object3D.prototype.toJSON.call( this, meta );
  13648. data.object.levels = [];
  13649. var levels = this.levels;
  13650. for ( var i = 0, l = levels.length; i < l; i ++ ) {
  13651. var level = levels[ i ];
  13652. data.object.levels.push( {
  13653. object: level.object.uuid,
  13654. distance: level.distance
  13655. } );
  13656. }
  13657. return data;
  13658. };
  13659. // File:src/objects/Sprite.js
  13660. /**
  13661. * @author mikael emtinger / http://gomo.se/
  13662. * @author alteredq / http://alteredqualia.com/
  13663. */
  13664. THREE.Sprite = ( function () {
  13665. var indices = new Uint16Array( [ 0, 1, 2, 0, 2, 3 ] );
  13666. var vertices = new Float32Array( [ - 0.5, - 0.5, 0, 0.5, - 0.5, 0, 0.5, 0.5, 0, - 0.5, 0.5, 0 ] );
  13667. var uvs = new Float32Array( [ 0, 0, 1, 0, 1, 1, 0, 1 ] );
  13668. var geometry = new THREE.BufferGeometry();
  13669. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  13670. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  13671. geometry.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  13672. return function Sprite( material ) {
  13673. THREE.Object3D.call( this );
  13674. this.type = 'Sprite';
  13675. this.geometry = geometry;
  13676. this.material = ( material !== undefined ) ? material : new THREE.SpriteMaterial();
  13677. };
  13678. } )();
  13679. THREE.Sprite.prototype = Object.create( THREE.Object3D.prototype );
  13680. THREE.Sprite.prototype.constructor = THREE.Sprite;
  13681. THREE.Sprite.prototype.raycast = ( function () {
  13682. var matrixPosition = new THREE.Vector3();
  13683. return function raycast( raycaster, intersects ) {
  13684. matrixPosition.setFromMatrixPosition( this.matrixWorld );
  13685. var distanceSq = raycaster.ray.distanceSqToPoint( matrixPosition );
  13686. var guessSizeSq = this.scale.x * this.scale.y;
  13687. if ( distanceSq > guessSizeSq ) {
  13688. return;
  13689. }
  13690. intersects.push( {
  13691. distance: Math.sqrt( distanceSq ),
  13692. point: this.position,
  13693. face: null,
  13694. object: this
  13695. } );
  13696. };
  13697. }() );
  13698. THREE.Sprite.prototype.clone = function () {
  13699. return new this.constructor( this.material ).copy( this );
  13700. };
  13701. // Backwards compatibility
  13702. THREE.Particle = THREE.Sprite;
  13703. // File:src/objects/LensFlare.js
  13704. /**
  13705. * @author mikael emtinger / http://gomo.se/
  13706. * @author alteredq / http://alteredqualia.com/
  13707. */
  13708. THREE.LensFlare = function ( texture, size, distance, blending, color ) {
  13709. THREE.Object3D.call( this );
  13710. this.lensFlares = [];
  13711. this.positionScreen = new THREE.Vector3();
  13712. this.customUpdateCallback = undefined;
  13713. if ( texture !== undefined ) {
  13714. this.add( texture, size, distance, blending, color );
  13715. }
  13716. };
  13717. THREE.LensFlare.prototype = Object.create( THREE.Object3D.prototype );
  13718. THREE.LensFlare.prototype.constructor = THREE.LensFlare;
  13719. /*
  13720. * Add: adds another flare
  13721. */
  13722. THREE.LensFlare.prototype.add = function ( texture, size, distance, blending, color, opacity ) {
  13723. if ( size === undefined ) size = - 1;
  13724. if ( distance === undefined ) distance = 0;
  13725. if ( opacity === undefined ) opacity = 1;
  13726. if ( color === undefined ) color = new THREE.Color( 0xffffff );
  13727. if ( blending === undefined ) blending = THREE.NormalBlending;
  13728. distance = Math.min( distance, Math.max( 0, distance ) );
  13729. this.lensFlares.push( {
  13730. texture: texture, // THREE.Texture
  13731. size: size, // size in pixels (-1 = use texture.width)
  13732. distance: distance, // distance (0-1) from light source (0=at light source)
  13733. x: 0, y: 0, z: 0, // screen position (-1 => 1) z = 0 is in front z = 1 is back
  13734. scale: 1, // scale
  13735. rotation: 0, // rotation
  13736. opacity: opacity, // opacity
  13737. color: color, // color
  13738. blending: blending // blending
  13739. } );
  13740. };
  13741. /*
  13742. * Update lens flares update positions on all flares based on the screen position
  13743. * Set myLensFlare.customUpdateCallback to alter the flares in your project specific way.
  13744. */
  13745. THREE.LensFlare.prototype.updateLensFlares = function () {
  13746. var f, fl = this.lensFlares.length;
  13747. var flare;
  13748. var vecX = - this.positionScreen.x * 2;
  13749. var vecY = - this.positionScreen.y * 2;
  13750. for ( f = 0; f < fl; f ++ ) {
  13751. flare = this.lensFlares[ f ];
  13752. flare.x = this.positionScreen.x + vecX * flare.distance;
  13753. flare.y = this.positionScreen.y + vecY * flare.distance;
  13754. flare.wantedRotation = flare.x * Math.PI * 0.25;
  13755. flare.rotation += ( flare.wantedRotation - flare.rotation ) * 0.25;
  13756. }
  13757. };
  13758. THREE.LensFlare.prototype.copy = function ( source ) {
  13759. THREE.Object3D.prototype.copy.call( this, source );
  13760. this.positionScreen.copy( source.positionScreen );
  13761. this.customUpdateCallback = source.customUpdateCallback;
  13762. for ( var i = 0, l = source.lensFlares.length; i < l; i ++ ) {
  13763. this.lensFlares.push( source.lensFlares[ i ] );
  13764. }
  13765. return this;
  13766. };
  13767. // File:src/scenes/Scene.js
  13768. /**
  13769. * @author mrdoob / http://mrdoob.com/
  13770. */
  13771. THREE.Scene = function () {
  13772. THREE.Object3D.call( this );
  13773. this.type = 'Scene';
  13774. this.fog = null;
  13775. this.overrideMaterial = null;
  13776. this.autoUpdate = true; // checked by the renderer
  13777. };
  13778. THREE.Scene.prototype = Object.create( THREE.Object3D.prototype );
  13779. THREE.Scene.prototype.constructor = THREE.Scene;
  13780. THREE.Scene.prototype.copy = function ( source, recursive ) {
  13781. THREE.Object3D.prototype.copy.call( this, source, recursive );
  13782. if ( source.fog !== null ) this.fog = source.fog.clone();
  13783. if ( source.overrideMaterial !== null ) this.overrideMaterial = source.overrideMaterial.clone();
  13784. this.autoUpdate = source.autoUpdate;
  13785. this.matrixAutoUpdate = source.matrixAutoUpdate;
  13786. return this;
  13787. };
  13788. // File:src/scenes/Fog.js
  13789. /**
  13790. * @author mrdoob / http://mrdoob.com/
  13791. * @author alteredq / http://alteredqualia.com/
  13792. */
  13793. THREE.Fog = function ( color, near, far ) {
  13794. this.name = '';
  13795. this.color = new THREE.Color( color );
  13796. this.near = ( near !== undefined ) ? near : 1;
  13797. this.far = ( far !== undefined ) ? far : 1000;
  13798. };
  13799. THREE.Fog.prototype.clone = function () {
  13800. return new THREE.Fog( this.color.getHex(), this.near, this.far );
  13801. };
  13802. // File:src/scenes/FogExp2.js
  13803. /**
  13804. * @author mrdoob / http://mrdoob.com/
  13805. * @author alteredq / http://alteredqualia.com/
  13806. */
  13807. THREE.FogExp2 = function ( color, density ) {
  13808. this.name = '';
  13809. this.color = new THREE.Color( color );
  13810. this.density = ( density !== undefined ) ? density : 0.00025;
  13811. };
  13812. THREE.FogExp2.prototype.clone = function () {
  13813. return new THREE.FogExp2( this.color.getHex(), this.density );
  13814. };
  13815. // File:src/renderers/shaders/ShaderChunk.js
  13816. THREE.ShaderChunk = {};
  13817. // File:src/renderers/shaders/ShaderChunk/alphamap_fragment.glsl
  13818. THREE.ShaderChunk[ 'alphamap_fragment' ] = "#ifdef USE_ALPHAMAP\n diffuseColor.a *= texture2D( alphaMap, vUv ).g;\n#endif\n";
  13819. // File:src/renderers/shaders/ShaderChunk/alphamap_pars_fragment.glsl
  13820. THREE.ShaderChunk[ 'alphamap_pars_fragment' ] = "#ifdef USE_ALPHAMAP\n uniform sampler2D alphaMap;\n#endif\n";
  13821. // File:src/renderers/shaders/ShaderChunk/alphatest_fragment.glsl
  13822. THREE.ShaderChunk[ 'alphatest_fragment' ] = "#ifdef ALPHATEST\n if ( diffuseColor.a < ALPHATEST ) discard;\n#endif\n";
  13823. // File:src/renderers/shaders/ShaderChunk/ambient_pars.glsl
  13824. THREE.ShaderChunk[ 'ambient_pars' ] = "uniform vec3 ambientLightColor;\nvec3 getAmbientLightIrradiance( const in vec3 ambientLightColor ) {\n return PI * ambientLightColor;\n}\n";
  13825. // File:src/renderers/shaders/ShaderChunk/aomap_fragment.glsl
  13826. THREE.ShaderChunk[ 'aomap_fragment' ] = "#ifdef USE_AOMAP\n reflectedLight.indirectDiffuse *= ( texture2D( aoMap, vUv2 ).r - 1.0 ) * aoMapIntensity + 1.0;\n#endif\n";
  13827. // File:src/renderers/shaders/ShaderChunk/aomap_pars_fragment.glsl
  13828. THREE.ShaderChunk[ 'aomap_pars_fragment' ] = "#ifdef USE_AOMAP\n uniform sampler2D aoMap;\n uniform float aoMapIntensity;\n#endif";
  13829. // File:src/renderers/shaders/ShaderChunk/begin_vertex.glsl
  13830. THREE.ShaderChunk[ 'begin_vertex' ] = "\nvec3 transformed = vec3( position );\n";
  13831. // File:src/renderers/shaders/ShaderChunk/beginnormal_vertex.glsl
  13832. THREE.ShaderChunk[ 'beginnormal_vertex' ] = "\nvec3 objectNormal = vec3( normal );\n";
  13833. // File:src/renderers/shaders/ShaderChunk/bsdfs.glsl
  13834. THREE.ShaderChunk[ 'bsdfs' ] = "bool testLightInRange( const in float lightDistance, const in float cutoffDistance ) {\n return any( bvec2( cutoffDistance == 0.0, lightDistance < cutoffDistance ) );\n}\nfloat calcLightAttenuation( const in float lightDistance, const in float cutoffDistance, const in float decayExponent ) {\n if ( decayExponent > 0.0 ) {\n return pow( saturate( -lightDistance / cutoffDistance + 1.0 ), decayExponent );\n }\n return 1.0;\n}\nvec3 BRDF_Diffuse_Lambert( const in vec3 diffuseColor ) {\n return RECIPROCAL_PI * diffuseColor;\n}\nvec3 F_Schlick( const in vec3 specularColor, const in float dotLH ) {\n float fresnel = exp2( ( -5.55473 * dotLH - 6.98316 ) * dotLH );\n return ( 1.0 - specularColor ) * fresnel + specularColor;\n}\nfloat G_GGX_Smith( const in float alpha, const in float dotNL, const in float dotNV ) {\n float a2 = alpha * alpha;\n float gl = dotNL + pow( a2 + ( 1.0 - a2 ) * dotNL * dotNL, 0.5 );\n float gv = dotNV + pow( a2 + ( 1.0 - a2 ) * dotNV * dotNV, 0.5 );\n return 1.0 / ( gl * gv );\n}\nfloat D_GGX( const in float alpha, const in float dotNH ) {\n float a2 = alpha * alpha;\n float denom = dotNH * dotNH * ( a2 - 1.0 ) + 1.0;\n return RECIPROCAL_PI * a2 / ( denom * denom );\n}\nvec3 BRDF_Specular_GGX( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n float alpha = roughness * roughness;\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNL = saturate( dot( geometry.normal, incidentLight.direction ) );\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_GGX_Smith( alpha, dotNL, dotNV );\n float D = D_GGX( alpha, dotNH );\n return F * ( G * D );\n}\nvec3 BRDF_Specular_GGX_Environment( const in GeometricContext geometry, const in vec3 specularColor, const in float roughness ) {\n float dotNV = saturate( dot( geometry.normal, geometry.viewDir ) );\n const vec4 c0 = vec4( - 1, - 0.0275, - 0.572, 0.022 );\n const vec4 c1 = vec4( 1, 0.0425, 1.04, - 0.04 );\n vec4 r = roughness * c0 + c1;\n float a004 = min( r.x * r.x, exp2( - 9.28 * dotNV ) ) * r.x + r.y;\n vec2 AB = vec2( -1.04, 1.04 ) * a004 + r.zw;\n return specularColor * AB.x + AB.y;\n}\nfloat G_BlinnPhong_Implicit( ) {\n return 0.25;\n}\nfloat D_BlinnPhong( const in float shininess, const in float dotNH ) {\n return RECIPROCAL_PI * ( shininess * 0.5 + 1.0 ) * pow( dotNH, shininess );\n}\nvec3 BRDF_Specular_BlinnPhong( const in IncidentLight incidentLight, const in GeometricContext geometry, const in vec3 specularColor, const in float shininess ) {\n vec3 halfDir = normalize( incidentLight.direction + geometry.viewDir );\n float dotNH = saturate( dot( geometry.normal, halfDir ) );\n float dotLH = saturate( dot( incidentLight.direction, halfDir ) );\n vec3 F = F_Schlick( specularColor, dotLH );\n float G = G_BlinnPhong_Implicit( );\n float D = D_BlinnPhong( shininess, dotNH );\n return F * ( G * D );\n}\nfloat GGXRoughnessToBlinnExponent( const in float ggxRoughness ) {\n return ( 2.0 / square( ggxRoughness + 0.0001 ) - 2.0 );\n}\n";
  13835. // File:src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl
  13836. THREE.ShaderChunk[ 'bumpmap_pars_fragment' ] = "#ifdef USE_BUMPMAP\n uniform sampler2D bumpMap;\n uniform float bumpScale;\n vec2 dHdxy_fwd() {\n vec2 dSTdx = dFdx( vUv );\n vec2 dSTdy = dFdy( vUv );\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 return vec2( dBx, dBy );\n }\n vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy ) {\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 float fDet = dot( vSigmaX, R1 );\n vec3 vGrad = sign( fDet ) * ( dHdxy.x * R1 + dHdxy.y * R2 );\n return normalize( abs( fDet ) * surf_norm - vGrad );\n }\n#endif\n";
  13837. // File:src/renderers/shaders/ShaderChunk/color_fragment.glsl
  13838. THREE.ShaderChunk[ 'color_fragment' ] = "#ifdef USE_COLOR\n diffuseColor.rgb *= vColor;\n#endif";
  13839. // File:src/renderers/shaders/ShaderChunk/color_pars_fragment.glsl
  13840. THREE.ShaderChunk[ 'color_pars_fragment' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif\n";
  13841. // File:src/renderers/shaders/ShaderChunk/color_pars_vertex.glsl
  13842. THREE.ShaderChunk[ 'color_pars_vertex' ] = "#ifdef USE_COLOR\n varying vec3 vColor;\n#endif";
  13843. // File:src/renderers/shaders/ShaderChunk/color_vertex.glsl
  13844. THREE.ShaderChunk[ 'color_vertex' ] = "#ifdef USE_COLOR\n vColor.xyz = color.xyz;\n#endif";
  13845. // File:src/renderers/shaders/ShaderChunk/common.glsl
  13846. THREE.ShaderChunk[ 'common' ] = "#define PI 3.14159\n#define PI2 6.28318\n#define RECIPROCAL_PI 0.31830988618\n#define RECIPROCAL_PI2 0.15915494\n#define LOG2 1.442695\n#define EPSILON 1e-6\n#define saturate(a) clamp( a, 0.0, 1.0 )\n#define whiteCompliment(a) ( 1.0 - saturate( a ) )\nfloat square( const in float x ) { return x*x; }\nfloat average( const in vec3 color ) { return dot( color, vec3( 0.3333 ) ); }\nstruct IncidentLight {\n vec3 color;\n vec3 direction;\n bool visible;\n};\nstruct ReflectedLight {\n vec3 directDiffuse;\n vec3 directSpecular;\n vec3 indirectDiffuse;\n vec3 indirectSpecular;\n};\nstruct GeometricContext {\n vec3 position;\n vec3 normal;\n vec3 viewDir;\n};\nvec3 transformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( matrix * vec4( dir, 0.0 ) ).xyz );\n}\nvec3 inverseTransformDirection( in vec3 dir, in mat4 matrix ) {\n return normalize( ( vec4( dir, 0.0 ) * matrix ).xyz );\n}\nvec3 projectOnPlane(in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n float distance = dot( planeNormal, point - pointOnPlane );\n return - distance * planeNormal + point;\n}\nfloat sideOfPlane( in vec3 point, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return sign( dot( point - pointOnPlane, planeNormal ) );\n}\nvec3 linePlaneIntersect( in vec3 pointOnLine, in vec3 lineDirection, in vec3 pointOnPlane, in vec3 planeNormal ) {\n return lineDirection * ( dot( planeNormal, pointOnPlane - pointOnLine ) / dot( planeNormal, lineDirection ) ) + pointOnLine;\n}\nvec3 inputToLinear( in vec3 a ) {\n #ifdef GAMMA_INPUT\n return pow( a, vec3( float( GAMMA_FACTOR ) ) );\n #else\n return a;\n #endif\n}\nvec3 linearToOutput( in vec3 a ) {\n #ifdef GAMMA_OUTPUT\n return pow( a, vec3( 1.0 / float( GAMMA_FACTOR ) ) );\n #else\n return a;\n #endif\n}\n";
  13847. // File:src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl
  13848. THREE.ShaderChunk[ 'defaultnormal_vertex' ] = "#ifdef FLIP_SIDED\n objectNormal = -objectNormal;\n#endif\nvec3 transformedNormal = normalMatrix * objectNormal;\n";
  13849. // File:src/renderers/shaders/ShaderChunk/displacementmap_vertex.glsl
  13850. THREE.ShaderChunk[ 'displacementmap_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n transformed += normal * ( texture2D( displacementMap, uv ).x * displacementScale + displacementBias );\n#endif\n";
  13851. // File:src/renderers/shaders/ShaderChunk/displacementmap_pars_vertex.glsl
  13852. THREE.ShaderChunk[ 'displacementmap_pars_vertex' ] = "#ifdef USE_DISPLACEMENTMAP\n uniform sampler2D displacementMap;\n uniform float displacementScale;\n uniform float displacementBias;\n#endif\n";
  13853. // File:src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl
  13854. THREE.ShaderChunk[ 'emissivemap_fragment' ] = "#ifdef USE_EMISSIVEMAP\n vec4 emissiveColor = texture2D( emissiveMap, vUv );\n emissiveColor.rgb = inputToLinear( emissiveColor.rgb );\n totalEmissiveLight *= emissiveColor.rgb;\n#endif\n";
  13855. // File:src/renderers/shaders/ShaderChunk/emissivemap_pars_fragment.glsl
  13856. THREE.ShaderChunk[ 'emissivemap_pars_fragment' ] = "#ifdef USE_EMISSIVEMAP\n uniform sampler2D emissiveMap;\n#endif\n";
  13857. // File:src/renderers/shaders/ShaderChunk/envmap_fragment.glsl
  13858. THREE.ShaderChunk[ 'envmap_fragment' ] = "#ifdef USE_ENVMAP\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG )\n vec3 cameraToVertex = normalize( vWorldPosition - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( cameraToVertex, worldNormal );\n #else\n vec3 reflectVec = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n #else\n vec3 reflectVec = vReflect;\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n #ifdef ENVMAP_TYPE_CUBE\n vec4 envColor = textureCube( envMap, flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\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 #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 envColor.xyz = inputToLinear( envColor.xyz );\n #ifdef ENVMAP_BLENDING_MULTIPLY\n outgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_MIX )\n outgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n #elif defined( ENVMAP_BLENDING_ADD )\n outgoingLight += envColor.xyz * specularStrength * reflectivity;\n #endif\n#endif\n";
  13859. // File:src/renderers/shaders/ShaderChunk/envmap_pars_fragment.glsl
  13860. THREE.ShaderChunk[ 'envmap_pars_fragment' ] = "#if defined( USE_ENVMAP ) || defined( STANDARD )\n uniform float reflectivity;\n uniform float envMapIntenstiy;\n#endif\n#ifdef USE_ENVMAP\n #ifdef ENVMAP_TYPE_CUBE\n uniform samplerCube envMap;\n #else\n uniform sampler2D envMap;\n #endif\n uniform float flipEnvMap;\n #if defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( PHONG ) || defined( STANDARD )\n uniform float refractionRatio;\n #else\n varying vec3 vReflect;\n #endif\n#endif\n";
  13861. // File:src/renderers/shaders/ShaderChunk/envmap_pars_vertex.glsl
  13862. THREE.ShaderChunk[ 'envmap_pars_vertex' ] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( STANDARD )\n varying vec3 vReflect;\n uniform float refractionRatio;\n#endif\n";
  13863. // File:src/renderers/shaders/ShaderChunk/envmap_vertex.glsl
  13864. THREE.ShaderChunk[ 'envmap_vertex' ] = "#if defined( USE_ENVMAP ) && ! defined( USE_BUMPMAP ) && ! defined( USE_NORMALMAP ) && ! defined( PHONG ) && ! defined( STANDARD )\n vec3 cameraToVertex = normalize( worldPosition.xyz - cameraPosition );\n vec3 worldNormal = inverseTransformDirection( transformedNormal, viewMatrix );\n #ifdef ENVMAP_MODE_REFLECTION\n vReflect = reflect( cameraToVertex, worldNormal );\n #else\n vReflect = refract( cameraToVertex, worldNormal, refractionRatio );\n #endif\n#endif\n";
  13865. // File:src/renderers/shaders/ShaderChunk/fog_fragment.glsl
  13866. THREE.ShaderChunk[ 'fog_fragment' ] = "#ifdef USE_FOG\n #ifdef USE_LOGDEPTHBUF_EXT\n float depth = gl_FragDepthEXT / gl_FragCoord.w;\n #else\n float depth = gl_FragCoord.z / gl_FragCoord.w;\n #endif\n #ifdef FOG_EXP2\n float fogFactor = whiteCompliment( exp2( - fogDensity * fogDensity * depth * depth * LOG2 ) );\n #else\n float fogFactor = smoothstep( fogNear, fogFar, depth );\n #endif\n \n outgoingLight = mix( outgoingLight, fogColor, fogFactor );\n#endif";
  13867. // File:src/renderers/shaders/ShaderChunk/fog_pars_fragment.glsl
  13868. THREE.ShaderChunk[ 'fog_pars_fragment' ] = "#ifdef USE_FOG\n uniform vec3 fogColor;\n #ifdef FOG_EXP2\n uniform float fogDensity;\n #else\n uniform float fogNear;\n uniform float fogFar;\n #endif\n#endif";
  13869. // File:src/renderers/shaders/ShaderChunk/lightmap_fragment.glsl
  13870. THREE.ShaderChunk[ 'lightmap_fragment' ] = "#ifdef USE_LIGHTMAP\n reflectedLight.indirectDiffuse += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n#endif\n";
  13871. // File:src/renderers/shaders/ShaderChunk/lightmap_pars_fragment.glsl
  13872. THREE.ShaderChunk[ 'lightmap_pars_fragment' ] = "#ifdef USE_LIGHTMAP\n uniform sampler2D lightMap;\n uniform float lightMapIntensity;\n#endif";
  13873. // File:src/renderers/shaders/ShaderChunk/lights_lambert_vertex.glsl
  13874. THREE.ShaderChunk[ 'lights_lambert_vertex' ] = "vec3 diffuse = vec3( 1.0 );\nGeometricContext geometry;\ngeometry.position = mvPosition.xyz;\ngeometry.normal = normalize( transformedNormal );\ngeometry.viewDir = normalize( -mvPosition.xyz );\nGeometricContext backGeometry;\nbackGeometry.position = geometry.position;\nbackGeometry.normal = -geometry.normal;\nbackGeometry.viewDir = geometry.viewDir;\nvLightFront = vec3( 0.0 );\n#ifdef DOUBLE_SIDED\n vLightBack = vec3( 0.0 );\n#endif\nIncidentLight directLight;\nfloat dotNL;\nvec3 directLightColor_Diffuse;\n#if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n directLight = getPointDirectLight( pointLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n directLight = getSpotDirectLight( spotLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directLight = getDirectionalDirectLight( directionalLights[ i ], geometry );\n dotNL = dot( geometry.normal, directLight.direction );\n directLightColor_Diffuse = PI * directLight.color;\n vLightFront += saturate( dotNL ) * directLightColor_Diffuse;\n #ifdef DOUBLE_SIDED\n vLightBack += saturate( -dotNL ) * directLightColor_Diffuse;\n #endif\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n vLightFront += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n #ifdef DOUBLE_SIDED\n vLightBack += getHemisphereLightIrradiance( hemisphereLights[ i ], backGeometry );\n #endif\n }\n#endif\n";
  13875. // File:src/renderers/shaders/ShaderChunk/lights_pars.glsl
  13876. THREE.ShaderChunk[ 'lights_pars' ] = "#if NUM_DIR_LIGHTS > 0\n struct DirectionalLight {\n vec3 direction;\n vec3 color;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform DirectionalLight directionalLights[ NUM_DIR_LIGHTS ];\n IncidentLight getDirectionalDirectLight( const in DirectionalLight directionalLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n directLight.color = directionalLight.color;\n directLight.direction = directionalLight.direction;\n directLight.visible = true;\n return directLight;\n }\n#endif\n#if NUM_POINT_LIGHTS > 0\n struct PointLight {\n vec3 position;\n vec3 color;\n float distance;\n float decay;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform PointLight pointLights[ NUM_POINT_LIGHTS ];\n IncidentLight getPointDirectLight( const in PointLight pointLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = pointLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n if ( testLightInRange( lightDistance, pointLight.distance ) ) {\n directLight.color = pointLight.color;\n directLight.color *= calcLightAttenuation( lightDistance, pointLight.distance, pointLight.decay );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n return directLight;\n }\n#endif\n#if NUM_SPOT_LIGHTS > 0\n struct SpotLight {\n vec3 position;\n vec3 direction;\n vec3 color;\n float distance;\n float decay;\n float angleCos;\n float penumbra;\n int shadow;\n float shadowBias;\n float shadowRadius;\n vec2 shadowMapSize;\n };\n uniform SpotLight spotLights[ NUM_SPOT_LIGHTS ];\n IncidentLight getSpotDirectLight( const in SpotLight spotLight, const in GeometricContext geometry ) {\n IncidentLight directLight;\n vec3 lVector = spotLight.position - geometry.position;\n directLight.direction = normalize( lVector );\n float lightDistance = length( lVector );\n float spotEffect = dot( directLight.direction, spotLight.direction );\n if ( all( bvec2( spotEffect > spotLight.angleCos, testLightInRange( lightDistance, spotLight.distance ) ) ) ) {\n float spotEffect = dot( spotLight.direction, directLight.direction );\n spotEffect *= clamp( ( spotEffect - spotLight.angleCos ) / spotLight.penumbra, 0.0, 1.0 );\n directLight.color = spotLight.color;\n directLight.color *= ( spotEffect * calcLightAttenuation( lightDistance, spotLight.distance, spotLight.decay ) );\n directLight.visible = true;\n } else {\n directLight.color = vec3( 0.0 );\n directLight.visible = false;\n }\n return directLight;\n }\n#endif\n#if NUM_HEMI_LIGHTS > 0\n struct HemisphereLight {\n vec3 direction;\n vec3 skyColor;\n vec3 groundColor;\n };\n uniform HemisphereLight hemisphereLights[ NUM_HEMI_LIGHTS ];\n vec3 getHemisphereLightIrradiance( const in HemisphereLight hemiLight, const in GeometricContext geometry ) {\n float dotNL = dot( geometry.normal, hemiLight.direction );\n float hemiDiffuseWeight = 0.5 * dotNL + 0.5;\n return PI * mix( hemiLight.groundColor, hemiLight.skyColor, hemiDiffuseWeight );\n }\n#endif\n#if defined( USE_ENVMAP ) && defined( STANDARD )\n vec3 getLightProbeIndirectIrradiance( const in GeometricContext geometry, const in int maxMIPLevel ) {\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n vec3 worldNormal = inverseTransformDirection( geometry.normal, viewMatrix );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryVec = flipNormal * vec3( flipEnvMap * worldNormal.x, worldNormal.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryVec, float( maxMIPLevel ) );\n #else\n vec4 envMapColor = textureCube( envMap, queryVec, float( maxMIPLevel ) );\n #endif\n #else\n vec3 envMapColor = vec3( 0.0 );\n #endif\n envMapColor.rgb = inputToLinear( envMapColor.rgb );\n return PI * envMapColor.rgb * envMapIntensity;\n }\n float getSpecularMIPLevel( const in float blinnShininessExponent, const in int maxMIPLevel ) {\n float maxMIPLevelScalar = float( maxMIPLevel );\n float desiredMIPLevel = maxMIPLevelScalar - 0.79248 - 0.5 * log2( square( blinnShininessExponent ) + 1.0 );\n return clamp( desiredMIPLevel, 0.0, maxMIPLevelScalar );\n }\n vec3 getLightProbeIndirectRadiance( const in GeometricContext geometry, const in float blinnShininessExponent, const in int maxMIPLevel ) {\n #ifdef ENVMAP_MODE_REFLECTION\n vec3 reflectVec = reflect( -geometry.viewDir, geometry.normal );\n #else\n vec3 reflectVec = refract( -geometry.viewDir, geometry.normal, refractionRatio );\n #endif\n #ifdef DOUBLE_SIDED\n float flipNormal = ( float( gl_FrontFacing ) * 2.0 - 1.0 );\n #else\n float flipNormal = 1.0;\n #endif\n reflectVec = inverseTransformDirection( reflectVec, viewMatrix );\n float specularMIPLevel = getSpecularMIPLevel( blinnShininessExponent, maxMIPLevel );\n #ifdef ENVMAP_TYPE_CUBE\n vec3 queryReflectVec = flipNormal * vec3( flipEnvMap * reflectVec.x, reflectVec.yz );\n #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = textureCubeLodEXT( envMap, queryReflectVec, specularMIPLevel );\n #else\n vec4 envMapColor = textureCube( envMap, queryReflectVec, specularMIPLevel );\n #endif\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 #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, sampleUV, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, sampleUV, specularMIPLevel );\n #endif\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 #ifdef TEXTURE_LOD_EXT\n vec4 envMapColor = texture2DLodEXT( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #else\n vec4 envMapColor = texture2D( envMap, reflectView.xy * 0.5 + 0.5, specularMIPLevel );\n #endif\n #endif\n envMapColor.rgb = inputToLinear( envMapColor.rgb );\n return envMapColor.rgb * envMapIntensity;\n }\n#endif\n";
  13877. // File:src/renderers/shaders/ShaderChunk/lights_phong_fragment.glsl
  13878. THREE.ShaderChunk[ 'lights_phong_fragment' ] = "BlinnPhongMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb;\nmaterial.specularColor = specular;\nmaterial.specularShininess = shininess;\nmaterial.specularStrength = specularStrength;\n";
  13879. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl
  13880. THREE.ShaderChunk[ 'lights_phong_pars_fragment' ] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\nvarying vec3 vViewPosition;\n#ifndef FLAT_SHADED\n varying vec3 vNormal;\n#endif\nstruct BlinnPhongMaterial {\n vec3 diffuseColor;\n vec3 specularColor;\n float specularShininess;\n float specularStrength;\n};\nvoid RE_Direct_BlinnPhong( const in IncidentLight directLight, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * PI * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_BlinnPhong( directLight, geometry, material.specularColor, material.specularShininess ) * material.specularStrength;\n}\nvoid RE_IndirectDiffuse_BlinnPhong( const in vec3 irradiance, const in GeometricContext geometry, const in BlinnPhongMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\n#define RE_Direct RE_Direct_BlinnPhong\n#define RE_IndirectDiffuse RE_IndirectDiffuse_BlinnPhong\n#define Material_LightProbeLOD( material ) (0)\n";
  13881. // File:src/renderers/shaders/ShaderChunk/lights_phong_pars_vertex.glsl
  13882. THREE.ShaderChunk[ 'lights_phong_pars_vertex' ] = "#ifdef USE_ENVMAP\n varying vec3 vWorldPosition;\n#endif\n";
  13883. // File:src/renderers/shaders/ShaderChunk/lights_phong_vertex.glsl
  13884. THREE.ShaderChunk[ 'lights_phong_vertex' ] = "#ifdef USE_ENVMAP\n vWorldPosition = worldPosition.xyz;\n#endif\n";
  13885. // File:src/renderers/shaders/ShaderChunk/lights_standard_fragment.glsl
  13886. THREE.ShaderChunk[ 'lights_standard_fragment' ] = "StandardMaterial material;\nmaterial.diffuseColor = diffuseColor.rgb * ( 1.0 - metalnessFactor );\nmaterial.specularRoughness = clamp( roughnessFactor, 0.04, 1.0 );\nmaterial.specularColor = mix( vec3( 0.04 ), diffuseColor.rgb, metalnessFactor );\n";
  13887. // File:src/renderers/shaders/ShaderChunk/lights_standard_pars_fragment.glsl
  13888. THREE.ShaderChunk[ 'lights_standard_pars_fragment' ] = "struct StandardMaterial {\n vec3 diffuseColor;\n float specularRoughness;\n vec3 specularColor;\n};\nvoid RE_Direct_Standard( const in IncidentLight directLight, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n float dotNL = saturate( dot( geometry.normal, directLight.direction ) );\n vec3 irradiance = dotNL * PI * directLight.color;\n reflectedLight.directDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n reflectedLight.directSpecular += irradiance * BRDF_Specular_GGX( directLight, geometry, material.specularColor, material.specularRoughness );\n}\nvoid RE_IndirectDiffuse_Standard( const in vec3 irradiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectDiffuse += irradiance * BRDF_Diffuse_Lambert( material.diffuseColor );\n}\nvoid RE_IndirectSpecular_Standard( const in vec3 radiance, const in GeometricContext geometry, const in StandardMaterial material, inout ReflectedLight reflectedLight ) {\n reflectedLight.indirectSpecular += radiance * BRDF_Specular_GGX_Environment( geometry, material.specularColor, material.specularRoughness );\n}\n#define RE_Direct RE_Direct_Standard\n#define RE_IndirectDiffuse RE_IndirectDiffuse_Standard\n#define RE_IndirectSpecular RE_IndirectSpecular_Standard\n#define Material_BlinnShininessExponent( material ) GGXRoughnessToBlinnExponent( material.specularRoughness )\n";
  13889. // File:src/renderers/shaders/ShaderChunk/lights_template.glsl
  13890. THREE.ShaderChunk[ 'lights_template' ] = "\nGeometricContext geometry;\ngeometry.position = - vViewPosition;\ngeometry.normal = normal;\ngeometry.viewDir = normalize( vViewPosition );\nIncidentLight directLight;\n#if ( NUM_POINT_LIGHTS > 0 ) && defined( RE_Direct )\n PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n directLight = getPointDirectLight( pointLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( pointLight.shadow, directLight.visible ) ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_SPOT_LIGHTS > 0 ) && defined( RE_Direct )\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n directLight = getSpotDirectLight( spotLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( spotLight.shadow, directLight.visible ) ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if ( NUM_DIR_LIGHTS > 0 ) && defined( RE_Direct )\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n directLight = getDirectionalDirectLight( directionalLight, geometry );\n #ifdef USE_SHADOWMAP\n directLight.color *= all( bvec2( directionalLight.shadow, directLight.visible ) ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n #endif\n RE_Direct( directLight, geometry, material, reflectedLight );\n }\n#endif\n#if defined( RE_IndirectDiffuse )\n vec3 irradiance = getAmbientLightIrradiance( ambientLightColor );\n #ifdef USE_LIGHTMAP\n irradiance += PI * texture2D( lightMap, vUv2 ).xyz * lightMapIntensity;\n #endif\n #if ( NUM_HEMI_LIGHTS > 0 )\n for ( int i = 0; i < NUM_HEMI_LIGHTS; i ++ ) {\n irradiance += getHemisphereLightIrradiance( hemisphereLights[ i ], geometry );\n }\n #endif\n RE_IndirectDiffuse( irradiance, geometry, material, reflectedLight );\n#endif\n#if defined( USE_ENVMAP ) && defined( RE_IndirectSpecular )\n vec3 radiance = getLightProbeIndirectRadiance( geometry, Material_BlinnShininessExponent( material ), 8 );\n RE_IndirectSpecular( radiance, geometry, material, reflectedLight );\n#endif\n";
  13891. // File:src/renderers/shaders/ShaderChunk/linear_to_gamma_fragment.glsl
  13892. THREE.ShaderChunk[ 'linear_to_gamma_fragment' ] = "\n outgoingLight = linearToOutput( outgoingLight );\n";
  13893. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl
  13894. THREE.ShaderChunk[ 'logdepthbuf_fragment' ] = "#if defined(USE_LOGDEPTHBUF) && defined(USE_LOGDEPTHBUF_EXT)\n gl_FragDepthEXT = log2(vFragDepth) * logDepthBufFC * 0.5;\n#endif";
  13895. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl
  13896. THREE.ShaderChunk[ 'logdepthbuf_pars_fragment' ] = "#ifdef USE_LOGDEPTHBUF\n uniform float logDepthBufFC;\n #ifdef USE_LOGDEPTHBUF_EXT\n varying float vFragDepth;\n #endif\n#endif\n";
  13897. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl
  13898. THREE.ShaderChunk[ 'logdepthbuf_pars_vertex' ] = "#ifdef USE_LOGDEPTHBUF\n #ifdef USE_LOGDEPTHBUF_EXT\n varying float vFragDepth;\n #endif\n uniform float logDepthBufFC;\n#endif";
  13899. // File:src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl
  13900. THREE.ShaderChunk[ 'logdepthbuf_vertex' ] = "#ifdef USE_LOGDEPTHBUF\n gl_Position.z = log2(max( EPSILON, gl_Position.w + 1.0 )) * logDepthBufFC;\n #ifdef USE_LOGDEPTHBUF_EXT\n vFragDepth = 1.0 + gl_Position.w;\n #else\n gl_Position.z = (gl_Position.z - 1.0) * gl_Position.w;\n #endif\n#endif\n";
  13901. // File:src/renderers/shaders/ShaderChunk/map_fragment.glsl
  13902. THREE.ShaderChunk[ 'map_fragment' ] = "#ifdef USE_MAP\n vec4 texelColor = texture2D( map, vUv );\n texelColor.xyz = inputToLinear( texelColor.xyz );\n diffuseColor *= texelColor;\n#endif\n";
  13903. // File:src/renderers/shaders/ShaderChunk/map_pars_fragment.glsl
  13904. THREE.ShaderChunk[ 'map_pars_fragment' ] = "#ifdef USE_MAP\n uniform sampler2D map;\n#endif";
  13905. // File:src/renderers/shaders/ShaderChunk/map_particle_fragment.glsl
  13906. THREE.ShaderChunk[ 'map_particle_fragment' ] = "#ifdef USE_MAP\n diffuseColor *= texture2D( map, vec2( gl_PointCoord.x, 1.0 - gl_PointCoord.y ) * offsetRepeat.zw + offsetRepeat.xy );\n#endif\n";
  13907. // File:src/renderers/shaders/ShaderChunk/map_particle_pars_fragment.glsl
  13908. THREE.ShaderChunk[ 'map_particle_pars_fragment' ] = "#ifdef USE_MAP\n uniform vec4 offsetRepeat;\n uniform sampler2D map;\n#endif\n";
  13909. // File:src/renderers/shaders/ShaderChunk/metalnessmap_fragment.glsl
  13910. THREE.ShaderChunk[ 'metalnessmap_fragment' ] = "float metalnessFactor = metalness;\n#ifdef USE_METALNESSMAP\n vec4 texelMetalness = texture2D( metalnessMap, vUv );\n metalnessFactor *= texelMetalness.r;\n#endif\n";
  13911. // File:src/renderers/shaders/ShaderChunk/metalnessmap_pars_fragment.glsl
  13912. THREE.ShaderChunk[ 'metalnessmap_pars_fragment' ] = "#ifdef USE_METALNESSMAP\n uniform sampler2D metalnessMap;\n#endif";
  13913. // File:src/renderers/shaders/ShaderChunk/morphnormal_vertex.glsl
  13914. THREE.ShaderChunk[ 'morphnormal_vertex' ] = "#ifdef USE_MORPHNORMALS\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#endif\n";
  13915. // File:src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl
  13916. THREE.ShaderChunk[ 'morphtarget_pars_vertex' ] = "#ifdef USE_MORPHTARGETS\n #ifndef USE_MORPHNORMALS\n uniform float morphTargetInfluences[ 8 ];\n #else\n uniform float morphTargetInfluences[ 4 ];\n #endif\n#endif";
  13917. // File:src/renderers/shaders/ShaderChunk/morphtarget_vertex.glsl
  13918. THREE.ShaderChunk[ 'morphtarget_vertex' ] = "#ifdef USE_MORPHTARGETS\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 #ifndef USE_MORPHNORMALS\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 #endif\n#endif\n";
  13919. // File:src/renderers/shaders/ShaderChunk/normal_fragment.glsl
  13920. THREE.ShaderChunk[ 'normal_fragment' ] = "#ifdef FLAT_SHADED\n vec3 fdx = vec3( dFdx( vViewPosition.x ), dFdx( vViewPosition.y ), dFdx( vViewPosition.z ) );\n vec3 fdy = vec3( dFdy( vViewPosition.x ), dFdy( vViewPosition.y ), dFdy( vViewPosition.z ) );\n vec3 normal = normalize( cross( fdx, fdy ) );\n#else\n vec3 normal = normalize( vNormal );\n #ifdef DOUBLE_SIDED\n normal = normal * ( -1.0 + 2.0 * float( gl_FrontFacing ) );\n #endif\n#endif\n#ifdef USE_NORMALMAP\n normal = perturbNormal2Arb( -vViewPosition, normal );\n#elif defined( USE_BUMPMAP )\n normal = perturbNormalArb( -vViewPosition, normal, dHdxy_fwd() );\n#endif\n";
  13921. // File:src/renderers/shaders/ShaderChunk/normalmap_pars_fragment.glsl
  13922. THREE.ShaderChunk[ 'normalmap_pars_fragment' ] = "#ifdef USE_NORMALMAP\n uniform sampler2D normalMap;\n uniform vec2 normalScale;\n vec3 perturbNormal2Arb( vec3 eye_pos, vec3 surf_norm ) {\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 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 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#endif\n";
  13923. // File:src/renderers/shaders/ShaderChunk/project_vertex.glsl
  13924. THREE.ShaderChunk[ 'project_vertex' ] = "#ifdef USE_SKINNING\n vec4 mvPosition = modelViewMatrix * skinned;\n#else\n vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 );\n#endif\ngl_Position = projectionMatrix * mvPosition;\n";
  13925. // File:src/renderers/shaders/ShaderChunk/roughnessmap_fragment.glsl
  13926. THREE.ShaderChunk[ 'roughnessmap_fragment' ] = "float roughnessFactor = roughness;\n#ifdef USE_ROUGHNESSMAP\n vec4 texelRoughness = texture2D( roughnessMap, vUv );\n roughnessFactor *= texelRoughness.r;\n#endif\n";
  13927. // File:src/renderers/shaders/ShaderChunk/roughnessmap_pars_fragment.glsl
  13928. THREE.ShaderChunk[ 'roughnessmap_pars_fragment' ] = "#ifdef USE_ROUGHNESSMAP\n uniform sampler2D roughnessMap;\n#endif";
  13929. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl
  13930. THREE.ShaderChunk[ 'shadowmap_pars_fragment' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform sampler2D directionalShadowMap[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform sampler2D spotShadowMap[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform sampler2D pointShadowMap[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n float unpackDepth( const in vec4 rgba_depth ) {\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 return dot( rgba_depth, bit_shift );\n }\n float texture2DCompare( sampler2D depths, vec2 uv, float compare ) {\n return step( compare, unpackDepth( texture2D( depths, uv ) ) );\n }\n float texture2DShadowLerp( sampler2D depths, vec2 size, vec2 uv, float compare ) {\n const vec2 offset = vec2( 0.0, 1.0 );\n vec2 texelSize = vec2( 1.0 ) / size;\n vec2 centroidUV = floor( uv * size + 0.5 ) / size;\n float lb = texture2DCompare( depths, centroidUV + texelSize * offset.xx, compare );\n float lt = texture2DCompare( depths, centroidUV + texelSize * offset.xy, compare );\n float rb = texture2DCompare( depths, centroidUV + texelSize * offset.yx, compare );\n float rt = texture2DCompare( depths, centroidUV + texelSize * offset.yy, compare );\n vec2 f = fract( uv * size + 0.5 );\n float a = mix( lb, lt, f.y );\n float b = mix( rb, rt, f.y );\n float c = mix( a, b, f.x );\n return c;\n }\n float getShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n shadowCoord.xyz /= shadowCoord.w;\n shadowCoord.z += shadowBias;\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 bvec2 frustumTestVec = bvec2( inFrustum, shadowCoord.z <= 1.0 );\n bool frustumTest = all( frustumTestVec );\n if ( frustumTest ) {\n #if defined( SHADOWMAP_TYPE_PCF )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DCompare( shadowMap, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #elif defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 texelSize = vec2( 1.0 ) / shadowMapSize;\n float dx0 = - texelSize.x * shadowRadius;\n float dy0 = - texelSize.y * shadowRadius;\n float dx1 = + texelSize.x * shadowRadius;\n float dy1 = + texelSize.y * shadowRadius;\n return (\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy, shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, 0.0 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( 0.0, dy1 ), shadowCoord.z ) +\n texture2DShadowLerp( shadowMap, shadowMapSize, shadowCoord.xy + vec2( dx1, dy1 ), shadowCoord.z )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, shadowCoord.xy, shadowCoord.z );\n #endif\n }\n return 1.0;\n }\n vec2 cubeToUV( vec3 v, float texelSizeY ) {\n vec3 absV = abs( v );\n float scaleToCube = 1.0 / max( absV.x, max( absV.y, absV.z ) );\n absV *= scaleToCube;\n v *= scaleToCube * ( 1.0 - 2.0 * texelSizeY );\n vec2 planar = v.xy;\n float almostATexel = 1.5 * texelSizeY;\n float almostOne = 1.0 - almostATexel;\n if ( absV.z >= almostOne ) {\n if ( v.z > 0.0 )\n planar.x = 4.0 - v.x;\n } else if ( absV.x >= almostOne ) {\n float signX = sign( v.x );\n planar.x = v.z * signX + 2.0 * signX;\n } else if ( absV.y >= almostOne ) {\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 return vec2( 0.125, 0.25 ) * planar + vec2( 0.375, 0.75 );\n }\n float getPointShadow( sampler2D shadowMap, vec2 shadowMapSize, float shadowBias, float shadowRadius, vec4 shadowCoord ) {\n vec2 texelSize = vec2( 1.0 ) / ( shadowMapSize * vec2( 4.0, 2.0 ) );\n vec3 lightToPosition = shadowCoord.xyz;\n vec3 bd3D = normalize( lightToPosition );\n float dp = ( length( lightToPosition ) - shadowBias ) / 1000.0;\n #if defined( SHADOWMAP_TYPE_PCF ) || defined( SHADOWMAP_TYPE_PCF_SOFT )\n vec2 offset = vec2( - 1, 1 ) * shadowRadius * texelSize.y;\n return (\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yyx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxy, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.xxx, texelSize.y ), dp ) +\n texture2DCompare( shadowMap, cubeToUV( bd3D + offset.yxx, texelSize.y ), dp )\n ) * ( 1.0 / 9.0 );\n #else\n return texture2DCompare( shadowMap, cubeToUV( bd3D, texelSize.y ), dp );\n #endif\n }\n#endif\n";
  13931. // File:src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl
  13932. THREE.ShaderChunk[ 'shadowmap_pars_vertex' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n uniform mat4 directionalShadowMatrix[ NUM_DIR_LIGHTS ];\n varying vec4 vDirectionalShadowCoord[ NUM_DIR_LIGHTS ];\n #endif\n #if NUM_SPOT_LIGHTS > 0\n uniform mat4 spotShadowMatrix[ NUM_SPOT_LIGHTS ];\n varying vec4 vSpotShadowCoord[ NUM_SPOT_LIGHTS ];\n #endif\n #if NUM_POINT_LIGHTS > 0\n uniform mat4 pointShadowMatrix[ NUM_POINT_LIGHTS ];\n varying vec4 vPointShadowCoord[ NUM_POINT_LIGHTS ];\n #endif\n#endif\n";
  13933. // File:src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl
  13934. THREE.ShaderChunk[ 'shadowmap_vertex' ] = "#ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n vDirectionalShadowCoord[ i ] = directionalShadowMatrix[ i ] * worldPosition;\n }\n #endif\n #if NUM_SPOT_LIGHTS > 0\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n vSpotShadowCoord[ i ] = spotShadowMatrix[ i ] * worldPosition;\n }\n #endif\n #if NUM_POINT_LIGHTS > 0\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n vPointShadowCoord[ i ] = pointShadowMatrix[ i ] * worldPosition;\n }\n #endif\n#endif\n";
  13935. // File:src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl
  13936. THREE.ShaderChunk[ 'shadowmask_pars_fragment' ] = "float getShadowMask() {\n float shadow = 1.0;\n #ifdef USE_SHADOWMAP\n #if NUM_DIR_LIGHTS > 0\n DirectionalLight directionalLight;\n for ( int i = 0; i < NUM_DIR_LIGHTS; i ++ ) {\n directionalLight = directionalLights[ i ];\n shadow *= bool( directionalLight.shadow ) ? getShadow( directionalShadowMap[ i ], directionalLight.shadowMapSize, directionalLight.shadowBias, directionalLight.shadowRadius, vDirectionalShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #if NUM_SPOT_LIGHTS > 0\n SpotLight spotLight;\n for ( int i = 0; i < NUM_SPOT_LIGHTS; i ++ ) {\n spotLight = spotLights[ i ];\n shadow *= bool( spotLight.shadow ) ? getShadow( spotShadowMap[ i ], spotLight.shadowMapSize, spotLight.shadowBias, spotLight.shadowRadius, vSpotShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #if NUM_POINT_LIGHTS > 0\n PointLight pointLight;\n for ( int i = 0; i < NUM_POINT_LIGHTS; i ++ ) {\n pointLight = pointLights[ i ];\n shadow *= bool( pointLight.shadow ) ? getPointShadow( pointShadowMap[ i ], pointLight.shadowMapSize, pointLight.shadowBias, pointLight.shadowRadius, vPointShadowCoord[ i ] ) : 1.0;\n }\n #endif\n #endif\n return shadow;\n}\n";
  13937. // File:src/renderers/shaders/ShaderChunk/skinbase_vertex.glsl
  13938. THREE.ShaderChunk[ 'skinbase_vertex' ] = "#ifdef USE_SKINNING\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#endif";
  13939. // File:src/renderers/shaders/ShaderChunk/skinning_pars_vertex.glsl
  13940. THREE.ShaderChunk[ 'skinning_pars_vertex' ] = "#ifdef USE_SKINNING\n uniform mat4 bindMatrix;\n uniform mat4 bindMatrixInverse;\n #ifdef BONE_TEXTURE\n uniform sampler2D boneTexture;\n uniform int boneTextureWidth;\n uniform int boneTextureHeight;\n mat4 getBoneMatrix( const in float i ) {\n float j = i * 4.0;\n float x = mod( j, float( boneTextureWidth ) );\n float y = floor( j / float( boneTextureWidth ) );\n float dx = 1.0 / float( boneTextureWidth );\n float dy = 1.0 / float( boneTextureHeight );\n y = dy * ( y + 0.5 );\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 mat4 bone = mat4( v1, v2, v3, v4 );\n return bone;\n }\n #else\n uniform mat4 boneGlobalMatrices[ MAX_BONES ];\n mat4 getBoneMatrix( const in float i ) {\n mat4 bone = boneGlobalMatrices[ int(i) ];\n return bone;\n }\n #endif\n#endif\n";
  13941. // File:src/renderers/shaders/ShaderChunk/skinning_vertex.glsl
  13942. THREE.ShaderChunk[ 'skinning_vertex' ] = "#ifdef USE_SKINNING\n vec4 skinVertex = bindMatrix * vec4( transformed, 1.0 );\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#endif\n";
  13943. // File:src/renderers/shaders/ShaderChunk/skinnormal_vertex.glsl
  13944. THREE.ShaderChunk[ 'skinnormal_vertex' ] = "#ifdef USE_SKINNING\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 objectNormal = vec4( skinMatrix * vec4( objectNormal, 0.0 ) ).xyz;\n#endif\n";
  13945. // File:src/renderers/shaders/ShaderChunk/specularmap_fragment.glsl
  13946. THREE.ShaderChunk[ 'specularmap_fragment' ] = "float specularStrength;\n#ifdef USE_SPECULARMAP\n vec4 texelSpecular = texture2D( specularMap, vUv );\n specularStrength = texelSpecular.r;\n#else\n specularStrength = 1.0;\n#endif";
  13947. // File:src/renderers/shaders/ShaderChunk/specularmap_pars_fragment.glsl
  13948. THREE.ShaderChunk[ 'specularmap_pars_fragment' ] = "#ifdef USE_SPECULARMAP\n uniform sampler2D specularMap;\n#endif";
  13949. // File:src/renderers/shaders/ShaderChunk/uv2_pars_fragment.glsl
  13950. THREE.ShaderChunk[ 'uv2_pars_fragment' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n varying vec2 vUv2;\n#endif";
  13951. // File:src/renderers/shaders/ShaderChunk/uv2_pars_vertex.glsl
  13952. THREE.ShaderChunk[ 'uv2_pars_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n attribute vec2 uv2;\n varying vec2 vUv2;\n#endif";
  13953. // File:src/renderers/shaders/ShaderChunk/uv2_vertex.glsl
  13954. THREE.ShaderChunk[ 'uv2_vertex' ] = "#if defined( USE_LIGHTMAP ) || defined( USE_AOMAP )\n vUv2 = uv2;\n#endif";
  13955. // File:src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl
  13956. THREE.ShaderChunk[ 'uv_pars_fragment' ] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n#endif";
  13957. // File:src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl
  13958. THREE.ShaderChunk[ 'uv_pars_vertex' ] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n varying vec2 vUv;\n uniform vec4 offsetRepeat;\n#endif\n";
  13959. // File:src/renderers/shaders/ShaderChunk/uv_vertex.glsl
  13960. THREE.ShaderChunk[ 'uv_vertex' ] = "#if defined( USE_MAP ) || defined( USE_BUMPMAP ) || defined( USE_NORMALMAP ) || defined( USE_SPECULARMAP ) || defined( USE_ALPHAMAP ) || defined( USE_EMISSIVEMAP ) || defined( USE_ROUGHNESSMAP ) || defined( USE_METALNESSMAP )\n vUv = uv * offsetRepeat.zw + offsetRepeat.xy;\n#endif";
  13961. // File:src/renderers/shaders/ShaderChunk/worldpos_vertex.glsl
  13962. THREE.ShaderChunk[ 'worldpos_vertex' ] = "#if defined( USE_ENVMAP ) || defined( PHONG ) || defined( STANDARD ) || defined( LAMBERT ) || defined ( USE_SHADOWMAP )\n #ifdef USE_SKINNING\n vec4 worldPosition = modelMatrix * skinned;\n #else\n vec4 worldPosition = modelMatrix * vec4( transformed, 1.0 );\n #endif\n#endif\n";
  13963. // File:src/renderers/shaders/UniformsUtils.js
  13964. /**
  13965. * Uniform Utilities
  13966. */
  13967. THREE.UniformsUtils = {
  13968. merge: function ( uniforms ) {
  13969. var merged = {};
  13970. for ( var u = 0; u < uniforms.length; u ++ ) {
  13971. var tmp = this.clone( uniforms[ u ] );
  13972. for ( var p in tmp ) {
  13973. merged[ p ] = tmp[ p ];
  13974. }
  13975. }
  13976. return merged;
  13977. },
  13978. clone: function ( uniforms_src ) {
  13979. var uniforms_dst = {};
  13980. for ( var u in uniforms_src ) {
  13981. uniforms_dst[ u ] = {};
  13982. for ( var p in uniforms_src[ u ] ) {
  13983. var parameter_src = uniforms_src[ u ][ p ];
  13984. if ( parameter_src instanceof THREE.Color ||
  13985. parameter_src instanceof THREE.Vector2 ||
  13986. parameter_src instanceof THREE.Vector3 ||
  13987. parameter_src instanceof THREE.Vector4 ||
  13988. parameter_src instanceof THREE.Matrix3 ||
  13989. parameter_src instanceof THREE.Matrix4 ||
  13990. parameter_src instanceof THREE.Texture ) {
  13991. uniforms_dst[ u ][ p ] = parameter_src.clone();
  13992. } else if ( Array.isArray( parameter_src ) ) {
  13993. uniforms_dst[ u ][ p ] = parameter_src.slice();
  13994. } else {
  13995. uniforms_dst[ u ][ p ] = parameter_src;
  13996. }
  13997. }
  13998. }
  13999. return uniforms_dst;
  14000. }
  14001. };
  14002. // File:src/renderers/shaders/UniformsLib.js
  14003. /**
  14004. * Uniforms library for shared webgl shaders
  14005. */
  14006. THREE.UniformsLib = {
  14007. common: {
  14008. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14009. "opacity": { type: "f", value: 1.0 },
  14010. "map": { type: "t", value: null },
  14011. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) },
  14012. "specularMap": { type: "t", value: null },
  14013. "alphaMap": { type: "t", value: null },
  14014. "envMap": { type: "t", value: null },
  14015. "flipEnvMap": { type: "f", value: - 1 },
  14016. "reflectivity": { type: "f", value: 1.0 },
  14017. "refractionRatio": { type: "f", value: 0.98 }
  14018. },
  14019. aomap: {
  14020. "aoMap": { type: "t", value: null },
  14021. "aoMapIntensity": { type: "f", value: 1 }
  14022. },
  14023. lightmap: {
  14024. "lightMap": { type: "t", value: null },
  14025. "lightMapIntensity": { type: "f", value: 1 }
  14026. },
  14027. emissivemap: {
  14028. "emissiveMap": { type: "t", value: null }
  14029. },
  14030. bumpmap: {
  14031. "bumpMap": { type: "t", value: null },
  14032. "bumpScale": { type: "f", value: 1 }
  14033. },
  14034. normalmap: {
  14035. "normalMap": { type: "t", value: null },
  14036. "normalScale": { type: "v2", value: new THREE.Vector2( 1, 1 ) }
  14037. },
  14038. displacementmap: {
  14039. "displacementMap": { type: "t", value: null },
  14040. "displacementScale": { type: "f", value: 1 },
  14041. "displacementBias": { type: "f", value: 0 }
  14042. },
  14043. roughnessmap: {
  14044. "roughnessMap": { type: "t", value: null }
  14045. },
  14046. metalnessmap: {
  14047. "metalnessMap": { type: "t", value: null }
  14048. },
  14049. fog: {
  14050. "fogDensity": { type: "f", value: 0.00025 },
  14051. "fogNear": { type: "f", value: 1 },
  14052. "fogFar": { type: "f", value: 2000 },
  14053. "fogColor": { type: "c", value: new THREE.Color( 0xffffff ) }
  14054. },
  14055. ambient: {
  14056. "ambientLightColor": { type: "fv", value: [] }
  14057. },
  14058. lights: {
  14059. "directionalLights": { type: "sa", value: [], properties: {
  14060. "direction": { type: "v3" },
  14061. "color": { type: "c" },
  14062. "shadow": { type: "i" },
  14063. "shadowBias": { type: "f" },
  14064. "shadowRadius": { type: "f" },
  14065. "shadowMapSize": { type: "v2" }
  14066. } },
  14067. "directionalShadowMap": { type: "tv", value: [] },
  14068. "directionalShadowMatrix": { type: "m4v", value: [] },
  14069. "spotLights": { type: "sa", value: [], properties: {
  14070. "color": { type: "c" },
  14071. "position": { type: "v3" },
  14072. "direction": { type: "v3" },
  14073. "distance": { type: "f" },
  14074. "angleCos": { type: "f" },
  14075. "penumbra": { type: "f" },
  14076. "decay": { type: "f" },
  14077. "shadow": { type: "i" },
  14078. "shadowBias": { type: "f" },
  14079. "shadowRadius": { type: "f" },
  14080. "shadowMapSize": { type: "v2" }
  14081. } },
  14082. "spotShadowMap": { type: "tv", value: [] },
  14083. "spotShadowMatrix": { type: "m4v", value: [] },
  14084. "pointLights": { type: "sa", value: [], properties: {
  14085. "color": { type: "c" },
  14086. "position": { type: "v3" },
  14087. "decay": { type: "f" },
  14088. "distance": { type: "f" },
  14089. "shadow": { type: "i" },
  14090. "shadowBias": { type: "f" },
  14091. "shadowRadius": { type: "f" },
  14092. "shadowMapSize": { type: "v2" }
  14093. } },
  14094. "pointShadowMap": { type: "tv", value: [] },
  14095. "pointShadowMatrix": { type: "m4v", value: [] },
  14096. "hemisphereLights": { type: "sa", value: [], properties: {
  14097. "direction": { type: "v3" },
  14098. "skyColor": { type: "c" },
  14099. "groundColor": { type: "c" }
  14100. } }
  14101. },
  14102. points: {
  14103. "diffuse": { type: "c", value: new THREE.Color( 0xeeeeee ) },
  14104. "opacity": { type: "f", value: 1.0 },
  14105. "size": { type: "f", value: 1.0 },
  14106. "scale": { type: "f", value: 1.0 },
  14107. "map": { type: "t", value: null },
  14108. "offsetRepeat": { type: "v4", value: new THREE.Vector4( 0, 0, 1, 1 ) }
  14109. }
  14110. };
  14111. // File:src/renderers/shaders/ShaderLib.js
  14112. /**
  14113. * Webgl Shader Library for three.js
  14114. *
  14115. * @author alteredq / http://alteredqualia.com/
  14116. * @author mrdoob / http://mrdoob.com/
  14117. * @author mikael emtinger / http://gomo.se/
  14118. */
  14119. THREE.ShaderLib = {
  14120. 'basic': {
  14121. uniforms: THREE.UniformsUtils.merge( [
  14122. THREE.UniformsLib[ "common" ],
  14123. THREE.UniformsLib[ "aomap" ],
  14124. THREE.UniformsLib[ "fog" ]
  14125. ] ),
  14126. vertexShader: [
  14127. THREE.ShaderChunk[ "common" ],
  14128. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14129. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14130. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14131. THREE.ShaderChunk[ "color_pars_vertex" ],
  14132. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14133. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14134. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14135. "void main() {",
  14136. THREE.ShaderChunk[ "uv_vertex" ],
  14137. THREE.ShaderChunk[ "uv2_vertex" ],
  14138. THREE.ShaderChunk[ "color_vertex" ],
  14139. THREE.ShaderChunk[ "skinbase_vertex" ],
  14140. " #ifdef USE_ENVMAP",
  14141. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14142. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14143. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14144. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14145. " #endif",
  14146. THREE.ShaderChunk[ "begin_vertex" ],
  14147. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14148. THREE.ShaderChunk[ "skinning_vertex" ],
  14149. THREE.ShaderChunk[ "project_vertex" ],
  14150. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14151. THREE.ShaderChunk[ "worldpos_vertex" ],
  14152. THREE.ShaderChunk[ "envmap_vertex" ],
  14153. "}"
  14154. ].join( "\n" ),
  14155. fragmentShader: [
  14156. "uniform vec3 diffuse;",
  14157. "uniform float opacity;",
  14158. "#ifndef FLAT_SHADED",
  14159. " varying vec3 vNormal;",
  14160. "#endif",
  14161. THREE.ShaderChunk[ "common" ],
  14162. THREE.ShaderChunk[ "color_pars_fragment" ],
  14163. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14164. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14165. THREE.ShaderChunk[ "map_pars_fragment" ],
  14166. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14167. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14168. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14169. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14170. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14171. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14172. "void main() {",
  14173. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14174. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14175. THREE.ShaderChunk[ "map_fragment" ],
  14176. THREE.ShaderChunk[ "color_fragment" ],
  14177. THREE.ShaderChunk[ "alphamap_fragment" ],
  14178. THREE.ShaderChunk[ "alphatest_fragment" ],
  14179. THREE.ShaderChunk[ "specularmap_fragment" ],
  14180. " ReflectedLight reflectedLight;",
  14181. " reflectedLight.directDiffuse = vec3( 0.0 );",
  14182. " reflectedLight.directSpecular = vec3( 0.0 );",
  14183. " reflectedLight.indirectDiffuse = diffuseColor.rgb;",
  14184. " reflectedLight.indirectSpecular = vec3( 0.0 );",
  14185. THREE.ShaderChunk[ "aomap_fragment" ],
  14186. " vec3 outgoingLight = reflectedLight.indirectDiffuse;",
  14187. THREE.ShaderChunk[ "envmap_fragment" ],
  14188. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14189. THREE.ShaderChunk[ "fog_fragment" ],
  14190. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14191. "}"
  14192. ].join( "\n" )
  14193. },
  14194. 'lambert': {
  14195. uniforms: THREE.UniformsUtils.merge( [
  14196. THREE.UniformsLib[ "common" ],
  14197. THREE.UniformsLib[ "aomap" ],
  14198. THREE.UniformsLib[ "lightmap" ],
  14199. THREE.UniformsLib[ "emissivemap" ],
  14200. THREE.UniformsLib[ "fog" ],
  14201. THREE.UniformsLib[ "ambient" ],
  14202. THREE.UniformsLib[ "lights" ],
  14203. {
  14204. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) }
  14205. }
  14206. ] ),
  14207. vertexShader: [
  14208. "#define LAMBERT",
  14209. "varying vec3 vLightFront;",
  14210. "#ifdef DOUBLE_SIDED",
  14211. " varying vec3 vLightBack;",
  14212. "#endif",
  14213. THREE.ShaderChunk[ "common" ],
  14214. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14215. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14216. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14217. THREE.ShaderChunk[ "bsdfs" ],
  14218. THREE.ShaderChunk[ "lights_pars" ],
  14219. THREE.ShaderChunk[ "color_pars_vertex" ],
  14220. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14221. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14222. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14223. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14224. "void main() {",
  14225. THREE.ShaderChunk[ "uv_vertex" ],
  14226. THREE.ShaderChunk[ "uv2_vertex" ],
  14227. THREE.ShaderChunk[ "color_vertex" ],
  14228. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14229. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14230. THREE.ShaderChunk[ "skinbase_vertex" ],
  14231. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14232. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14233. THREE.ShaderChunk[ "begin_vertex" ],
  14234. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14235. THREE.ShaderChunk[ "skinning_vertex" ],
  14236. THREE.ShaderChunk[ "project_vertex" ],
  14237. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14238. THREE.ShaderChunk[ "worldpos_vertex" ],
  14239. THREE.ShaderChunk[ "envmap_vertex" ],
  14240. THREE.ShaderChunk[ "lights_lambert_vertex" ],
  14241. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14242. "}"
  14243. ].join( "\n" ),
  14244. fragmentShader: [
  14245. "uniform vec3 diffuse;",
  14246. "uniform vec3 emissive;",
  14247. "uniform float opacity;",
  14248. "varying vec3 vLightFront;",
  14249. "#ifdef DOUBLE_SIDED",
  14250. " varying vec3 vLightBack;",
  14251. "#endif",
  14252. THREE.ShaderChunk[ "common" ],
  14253. THREE.ShaderChunk[ "color_pars_fragment" ],
  14254. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14255. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14256. THREE.ShaderChunk[ "map_pars_fragment" ],
  14257. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14258. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14259. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14260. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14261. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14262. THREE.ShaderChunk[ "bsdfs" ],
  14263. THREE.ShaderChunk[ "ambient_pars" ],
  14264. THREE.ShaderChunk[ "lights_pars" ],
  14265. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14266. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14267. THREE.ShaderChunk[ "shadowmask_pars_fragment" ],
  14268. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14269. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14270. "void main() {",
  14271. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14272. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14273. " vec3 totalEmissiveLight = emissive;",
  14274. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14275. THREE.ShaderChunk[ "map_fragment" ],
  14276. THREE.ShaderChunk[ "color_fragment" ],
  14277. THREE.ShaderChunk[ "alphamap_fragment" ],
  14278. THREE.ShaderChunk[ "alphatest_fragment" ],
  14279. THREE.ShaderChunk[ "specularmap_fragment" ],
  14280. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14281. // accumulation
  14282. " reflectedLight.indirectDiffuse = getAmbientLightIrradiance( ambientLightColor );",
  14283. THREE.ShaderChunk[ "lightmap_fragment" ],
  14284. " reflectedLight.indirectDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb );",
  14285. " #ifdef DOUBLE_SIDED",
  14286. " reflectedLight.directDiffuse = ( gl_FrontFacing ) ? vLightFront : vLightBack;",
  14287. " #else",
  14288. " reflectedLight.directDiffuse = vLightFront;",
  14289. " #endif",
  14290. " reflectedLight.directDiffuse *= BRDF_Diffuse_Lambert( diffuseColor.rgb ) * getShadowMask();",
  14291. // modulation
  14292. THREE.ShaderChunk[ "aomap_fragment" ],
  14293. " vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + totalEmissiveLight;",
  14294. THREE.ShaderChunk[ "envmap_fragment" ],
  14295. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14296. THREE.ShaderChunk[ "fog_fragment" ],
  14297. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14298. "}"
  14299. ].join( "\n" )
  14300. },
  14301. 'phong': {
  14302. uniforms: THREE.UniformsUtils.merge( [
  14303. THREE.UniformsLib[ "common" ],
  14304. THREE.UniformsLib[ "aomap" ],
  14305. THREE.UniformsLib[ "lightmap" ],
  14306. THREE.UniformsLib[ "emissivemap" ],
  14307. THREE.UniformsLib[ "bumpmap" ],
  14308. THREE.UniformsLib[ "normalmap" ],
  14309. THREE.UniformsLib[ "displacementmap" ],
  14310. THREE.UniformsLib[ "fog" ],
  14311. THREE.UniformsLib[ "ambient" ],
  14312. THREE.UniformsLib[ "lights" ],
  14313. {
  14314. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14315. "specular" : { type: "c", value: new THREE.Color( 0x111111 ) },
  14316. "shininess": { type: "f", value: 30 }
  14317. }
  14318. ] ),
  14319. vertexShader: [
  14320. "#define PHONG",
  14321. "varying vec3 vViewPosition;",
  14322. "#ifndef FLAT_SHADED",
  14323. " varying vec3 vNormal;",
  14324. "#endif",
  14325. THREE.ShaderChunk[ "common" ],
  14326. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14327. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14328. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  14329. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14330. THREE.ShaderChunk[ "lights_phong_pars_vertex" ],
  14331. THREE.ShaderChunk[ "color_pars_vertex" ],
  14332. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14333. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14334. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14335. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14336. "void main() {",
  14337. THREE.ShaderChunk[ "uv_vertex" ],
  14338. THREE.ShaderChunk[ "uv2_vertex" ],
  14339. THREE.ShaderChunk[ "color_vertex" ],
  14340. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14341. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14342. THREE.ShaderChunk[ "skinbase_vertex" ],
  14343. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14344. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14345. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  14346. " vNormal = normalize( transformedNormal );",
  14347. "#endif",
  14348. THREE.ShaderChunk[ "begin_vertex" ],
  14349. THREE.ShaderChunk[ "displacementmap_vertex" ],
  14350. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14351. THREE.ShaderChunk[ "skinning_vertex" ],
  14352. THREE.ShaderChunk[ "project_vertex" ],
  14353. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14354. " vViewPosition = - mvPosition.xyz;",
  14355. THREE.ShaderChunk[ "worldpos_vertex" ],
  14356. THREE.ShaderChunk[ "envmap_vertex" ],
  14357. THREE.ShaderChunk[ "lights_phong_vertex" ],
  14358. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14359. "}"
  14360. ].join( "\n" ),
  14361. fragmentShader: [
  14362. "#define PHONG",
  14363. "uniform vec3 diffuse;",
  14364. "uniform vec3 emissive;",
  14365. "uniform vec3 specular;",
  14366. "uniform float shininess;",
  14367. "uniform float opacity;",
  14368. THREE.ShaderChunk[ "common" ],
  14369. THREE.ShaderChunk[ "color_pars_fragment" ],
  14370. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14371. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14372. THREE.ShaderChunk[ "map_pars_fragment" ],
  14373. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14374. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14375. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14376. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14377. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14378. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14379. THREE.ShaderChunk[ "bsdfs" ],
  14380. THREE.ShaderChunk[ "ambient_pars" ],
  14381. THREE.ShaderChunk[ "lights_pars" ],
  14382. THREE.ShaderChunk[ "lights_phong_pars_fragment" ],
  14383. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14384. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14385. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14386. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14387. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14388. "void main() {",
  14389. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14390. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14391. " vec3 totalEmissiveLight = emissive;",
  14392. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14393. THREE.ShaderChunk[ "map_fragment" ],
  14394. THREE.ShaderChunk[ "color_fragment" ],
  14395. THREE.ShaderChunk[ "alphamap_fragment" ],
  14396. THREE.ShaderChunk[ "alphatest_fragment" ],
  14397. THREE.ShaderChunk[ "specularmap_fragment" ],
  14398. THREE.ShaderChunk[ "normal_fragment" ],
  14399. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14400. // accumulation
  14401. THREE.ShaderChunk[ "lights_phong_fragment" ],
  14402. THREE.ShaderChunk[ "lights_template" ],
  14403. // modulation
  14404. THREE.ShaderChunk[ "aomap_fragment" ],
  14405. "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14406. THREE.ShaderChunk[ "envmap_fragment" ],
  14407. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14408. THREE.ShaderChunk[ "fog_fragment" ],
  14409. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14410. "}"
  14411. ].join( "\n" )
  14412. },
  14413. 'standard': {
  14414. uniforms: THREE.UniformsUtils.merge( [
  14415. THREE.UniformsLib[ "common" ],
  14416. THREE.UniformsLib[ "aomap" ],
  14417. THREE.UniformsLib[ "lightmap" ],
  14418. THREE.UniformsLib[ "emissivemap" ],
  14419. THREE.UniformsLib[ "bumpmap" ],
  14420. THREE.UniformsLib[ "normalmap" ],
  14421. THREE.UniformsLib[ "displacementmap" ],
  14422. THREE.UniformsLib[ "roughnessmap" ],
  14423. THREE.UniformsLib[ "metalnessmap" ],
  14424. THREE.UniformsLib[ "fog" ],
  14425. THREE.UniformsLib[ "ambient" ],
  14426. THREE.UniformsLib[ "lights" ],
  14427. {
  14428. "emissive" : { type: "c", value: new THREE.Color( 0x000000 ) },
  14429. "roughness": { type: "f", value: 0.5 },
  14430. "metalness": { type: "f", value: 0 },
  14431. "envMapIntensity" : { type: "f", value: 1 } // temporary
  14432. }
  14433. ] ),
  14434. vertexShader: [
  14435. "#define STANDARD",
  14436. "varying vec3 vViewPosition;",
  14437. "#ifndef FLAT_SHADED",
  14438. " varying vec3 vNormal;",
  14439. "#endif",
  14440. THREE.ShaderChunk[ "common" ],
  14441. THREE.ShaderChunk[ "uv_pars_vertex" ],
  14442. THREE.ShaderChunk[ "uv2_pars_vertex" ],
  14443. THREE.ShaderChunk[ "displacementmap_pars_vertex" ],
  14444. THREE.ShaderChunk[ "envmap_pars_vertex" ],
  14445. THREE.ShaderChunk[ "color_pars_vertex" ],
  14446. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14447. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14448. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14449. THREE.ShaderChunk[ "specularmap_pars_fragment" ],
  14450. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14451. "void main() {", // STANDARD
  14452. THREE.ShaderChunk[ "uv_vertex" ],
  14453. THREE.ShaderChunk[ "uv2_vertex" ],
  14454. THREE.ShaderChunk[ "color_vertex" ],
  14455. THREE.ShaderChunk[ "beginnormal_vertex" ],
  14456. THREE.ShaderChunk[ "morphnormal_vertex" ],
  14457. THREE.ShaderChunk[ "skinbase_vertex" ],
  14458. THREE.ShaderChunk[ "skinnormal_vertex" ],
  14459. THREE.ShaderChunk[ "defaultnormal_vertex" ],
  14460. "#ifndef FLAT_SHADED", // Normal computed with derivatives when FLAT_SHADED
  14461. " vNormal = normalize( transformedNormal );",
  14462. "#endif",
  14463. THREE.ShaderChunk[ "begin_vertex" ],
  14464. THREE.ShaderChunk[ "displacementmap_vertex" ],
  14465. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14466. THREE.ShaderChunk[ "skinning_vertex" ],
  14467. THREE.ShaderChunk[ "project_vertex" ],
  14468. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14469. " vViewPosition = - mvPosition.xyz;",
  14470. THREE.ShaderChunk[ "worldpos_vertex" ],
  14471. THREE.ShaderChunk[ "envmap_vertex" ],
  14472. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14473. "}"
  14474. ].join( "\n" ),
  14475. fragmentShader: [
  14476. "#define STANDARD",
  14477. "uniform vec3 diffuse;",
  14478. "uniform vec3 emissive;",
  14479. "uniform float roughness;",
  14480. "uniform float metalness;",
  14481. "uniform float opacity;",
  14482. "uniform float envMapIntensity;", // temporary
  14483. "varying vec3 vViewPosition;",
  14484. "#ifndef FLAT_SHADED",
  14485. " varying vec3 vNormal;",
  14486. "#endif",
  14487. THREE.ShaderChunk[ "common" ],
  14488. THREE.ShaderChunk[ "color_pars_fragment" ],
  14489. THREE.ShaderChunk[ "uv_pars_fragment" ],
  14490. THREE.ShaderChunk[ "uv2_pars_fragment" ],
  14491. THREE.ShaderChunk[ "map_pars_fragment" ],
  14492. THREE.ShaderChunk[ "alphamap_pars_fragment" ],
  14493. THREE.ShaderChunk[ "aomap_pars_fragment" ],
  14494. THREE.ShaderChunk[ "lightmap_pars_fragment" ],
  14495. THREE.ShaderChunk[ "emissivemap_pars_fragment" ],
  14496. THREE.ShaderChunk[ "envmap_pars_fragment" ],
  14497. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14498. THREE.ShaderChunk[ "bsdfs" ],
  14499. THREE.ShaderChunk[ "ambient_pars" ],
  14500. THREE.ShaderChunk[ "lights_pars" ],
  14501. THREE.ShaderChunk[ "lights_standard_pars_fragment" ],
  14502. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14503. THREE.ShaderChunk[ "bumpmap_pars_fragment" ],
  14504. THREE.ShaderChunk[ "normalmap_pars_fragment" ],
  14505. THREE.ShaderChunk[ "roughnessmap_pars_fragment" ],
  14506. THREE.ShaderChunk[ "metalnessmap_pars_fragment" ],
  14507. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14508. "void main() {",
  14509. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14510. " ReflectedLight reflectedLight = ReflectedLight( vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ), vec3( 0.0 ) );",
  14511. " vec3 totalEmissiveLight = emissive;",
  14512. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14513. THREE.ShaderChunk[ "map_fragment" ],
  14514. THREE.ShaderChunk[ "color_fragment" ],
  14515. THREE.ShaderChunk[ "alphamap_fragment" ],
  14516. THREE.ShaderChunk[ "alphatest_fragment" ],
  14517. THREE.ShaderChunk[ "specularmap_fragment" ],
  14518. THREE.ShaderChunk[ "roughnessmap_fragment" ],
  14519. THREE.ShaderChunk[ "metalnessmap_fragment" ],
  14520. THREE.ShaderChunk[ "normal_fragment" ],
  14521. THREE.ShaderChunk[ "emissivemap_fragment" ],
  14522. // accumulation
  14523. THREE.ShaderChunk[ "lights_standard_fragment" ],
  14524. THREE.ShaderChunk[ "lights_template" ],
  14525. // modulation
  14526. THREE.ShaderChunk[ "aomap_fragment" ],
  14527. "vec3 outgoingLight = reflectedLight.directDiffuse + reflectedLight.indirectDiffuse + reflectedLight.directSpecular + reflectedLight.indirectSpecular + totalEmissiveLight;",
  14528. THREE.ShaderChunk[ "linear_to_gamma_fragment" ],
  14529. THREE.ShaderChunk[ "fog_fragment" ],
  14530. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14531. "}"
  14532. ].join( "\n" )
  14533. },
  14534. 'points': {
  14535. uniforms: THREE.UniformsUtils.merge( [
  14536. THREE.UniformsLib[ "points" ],
  14537. THREE.UniformsLib[ "fog" ]
  14538. ] ),
  14539. vertexShader: [
  14540. "uniform float size;",
  14541. "uniform float scale;",
  14542. THREE.ShaderChunk[ "common" ],
  14543. THREE.ShaderChunk[ "color_pars_vertex" ],
  14544. THREE.ShaderChunk[ "shadowmap_pars_vertex" ],
  14545. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14546. "void main() {",
  14547. THREE.ShaderChunk[ "color_vertex" ],
  14548. THREE.ShaderChunk[ "begin_vertex" ],
  14549. THREE.ShaderChunk[ "project_vertex" ],
  14550. " #ifdef USE_SIZEATTENUATION",
  14551. " gl_PointSize = size * ( scale / - mvPosition.z );",
  14552. " #else",
  14553. " gl_PointSize = size;",
  14554. " #endif",
  14555. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14556. THREE.ShaderChunk[ "worldpos_vertex" ],
  14557. THREE.ShaderChunk[ "shadowmap_vertex" ],
  14558. "}"
  14559. ].join( "\n" ),
  14560. fragmentShader: [
  14561. "uniform vec3 diffuse;",
  14562. "uniform float opacity;",
  14563. THREE.ShaderChunk[ "common" ],
  14564. THREE.ShaderChunk[ "color_pars_fragment" ],
  14565. THREE.ShaderChunk[ "map_particle_pars_fragment" ],
  14566. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14567. THREE.ShaderChunk[ "shadowmap_pars_fragment" ],
  14568. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14569. "void main() {",
  14570. " vec3 outgoingLight = vec3( 0.0 );",
  14571. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14572. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14573. THREE.ShaderChunk[ "map_particle_fragment" ],
  14574. THREE.ShaderChunk[ "color_fragment" ],
  14575. THREE.ShaderChunk[ "alphatest_fragment" ],
  14576. " outgoingLight = diffuseColor.rgb;",
  14577. THREE.ShaderChunk[ "fog_fragment" ],
  14578. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14579. "}"
  14580. ].join( "\n" )
  14581. },
  14582. 'dashed': {
  14583. uniforms: THREE.UniformsUtils.merge( [
  14584. THREE.UniformsLib[ "common" ],
  14585. THREE.UniformsLib[ "fog" ],
  14586. {
  14587. "scale" : { type: "f", value: 1 },
  14588. "dashSize" : { type: "f", value: 1 },
  14589. "totalSize": { type: "f", value: 2 }
  14590. }
  14591. ] ),
  14592. vertexShader: [
  14593. "uniform float scale;",
  14594. "attribute float lineDistance;",
  14595. "varying float vLineDistance;",
  14596. THREE.ShaderChunk[ "common" ],
  14597. THREE.ShaderChunk[ "color_pars_vertex" ],
  14598. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14599. "void main() {",
  14600. THREE.ShaderChunk[ "color_vertex" ],
  14601. " vLineDistance = scale * lineDistance;",
  14602. " vec4 mvPosition = modelViewMatrix * vec4( position, 1.0 );",
  14603. " gl_Position = projectionMatrix * mvPosition;",
  14604. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14605. "}"
  14606. ].join( "\n" ),
  14607. fragmentShader: [
  14608. "uniform vec3 diffuse;",
  14609. "uniform float opacity;",
  14610. "uniform float dashSize;",
  14611. "uniform float totalSize;",
  14612. "varying float vLineDistance;",
  14613. THREE.ShaderChunk[ "common" ],
  14614. THREE.ShaderChunk[ "color_pars_fragment" ],
  14615. THREE.ShaderChunk[ "fog_pars_fragment" ],
  14616. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14617. "void main() {",
  14618. " if ( mod( vLineDistance, totalSize ) > dashSize ) {",
  14619. " discard;",
  14620. " }",
  14621. " vec3 outgoingLight = vec3( 0.0 );",
  14622. " vec4 diffuseColor = vec4( diffuse, opacity );",
  14623. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14624. THREE.ShaderChunk[ "color_fragment" ],
  14625. " outgoingLight = diffuseColor.rgb;", // simple shader
  14626. THREE.ShaderChunk[ "fog_fragment" ],
  14627. " gl_FragColor = vec4( outgoingLight, diffuseColor.a );",
  14628. "}"
  14629. ].join( "\n" )
  14630. },
  14631. 'depth': {
  14632. uniforms: {
  14633. "mNear": { type: "f", value: 1.0 },
  14634. "mFar" : { type: "f", value: 2000.0 },
  14635. "opacity" : { type: "f", value: 1.0 }
  14636. },
  14637. vertexShader: [
  14638. THREE.ShaderChunk[ "common" ],
  14639. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14640. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14641. "void main() {",
  14642. THREE.ShaderChunk[ "begin_vertex" ],
  14643. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14644. THREE.ShaderChunk[ "project_vertex" ],
  14645. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14646. "}"
  14647. ].join( "\n" ),
  14648. fragmentShader: [
  14649. "uniform float mNear;",
  14650. "uniform float mFar;",
  14651. "uniform float opacity;",
  14652. THREE.ShaderChunk[ "common" ],
  14653. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14654. "void main() {",
  14655. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14656. " #ifdef USE_LOGDEPTHBUF_EXT",
  14657. " float depth = gl_FragDepthEXT / gl_FragCoord.w;",
  14658. " #else",
  14659. " float depth = gl_FragCoord.z / gl_FragCoord.w;",
  14660. " #endif",
  14661. " float color = 1.0 - smoothstep( mNear, mFar, depth );",
  14662. " gl_FragColor = vec4( vec3( color ), opacity );",
  14663. "}"
  14664. ].join( "\n" )
  14665. },
  14666. 'normal': {
  14667. uniforms: {
  14668. "opacity" : { type: "f", value: 1.0 }
  14669. },
  14670. vertexShader: [
  14671. "varying vec3 vNormal;",
  14672. THREE.ShaderChunk[ "common" ],
  14673. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14674. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14675. "void main() {",
  14676. " vNormal = normalize( normalMatrix * normal );",
  14677. THREE.ShaderChunk[ "begin_vertex" ],
  14678. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14679. THREE.ShaderChunk[ "project_vertex" ],
  14680. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14681. "}"
  14682. ].join( "\n" ),
  14683. fragmentShader: [
  14684. "uniform float opacity;",
  14685. "varying vec3 vNormal;",
  14686. THREE.ShaderChunk[ "common" ],
  14687. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14688. "void main() {",
  14689. " gl_FragColor = vec4( 0.5 * normalize( vNormal ) + 0.5, opacity );",
  14690. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14691. "}"
  14692. ].join( "\n" )
  14693. },
  14694. /* -------------------------------------------------------------------------
  14695. // Cube map shader
  14696. ------------------------------------------------------------------------- */
  14697. 'cube': {
  14698. uniforms: {
  14699. "tCube": { type: "t", value: null },
  14700. "tFlip": { type: "f", value: - 1 }
  14701. },
  14702. vertexShader: [
  14703. "varying vec3 vWorldPosition;",
  14704. THREE.ShaderChunk[ "common" ],
  14705. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14706. "void main() {",
  14707. " vWorldPosition = transformDirection( position, modelMatrix );",
  14708. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14709. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14710. "}"
  14711. ].join( "\n" ),
  14712. fragmentShader: [
  14713. "uniform samplerCube tCube;",
  14714. "uniform float tFlip;",
  14715. "varying vec3 vWorldPosition;",
  14716. THREE.ShaderChunk[ "common" ],
  14717. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14718. "void main() {",
  14719. " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14720. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14721. "}"
  14722. ].join( "\n" )
  14723. },
  14724. /* -------------------------------------------------------------------------
  14725. // Cube map shader
  14726. ------------------------------------------------------------------------- */
  14727. 'equirect': {
  14728. uniforms: {
  14729. "tEquirect": { type: "t", value: null },
  14730. "tFlip": { type: "f", value: - 1 }
  14731. },
  14732. vertexShader: [
  14733. "varying vec3 vWorldPosition;",
  14734. THREE.ShaderChunk[ "common" ],
  14735. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14736. "void main() {",
  14737. " vWorldPosition = transformDirection( position, modelMatrix );",
  14738. " gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );",
  14739. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14740. "}"
  14741. ].join( "\n" ),
  14742. fragmentShader: [
  14743. "uniform sampler2D tEquirect;",
  14744. "uniform float tFlip;",
  14745. "varying vec3 vWorldPosition;",
  14746. THREE.ShaderChunk[ "common" ],
  14747. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14748. "void main() {",
  14749. // " gl_FragColor = textureCube( tCube, vec3( tFlip * vWorldPosition.x, vWorldPosition.yz ) );",
  14750. "vec3 direction = normalize( vWorldPosition );",
  14751. "vec2 sampleUV;",
  14752. "sampleUV.y = saturate( tFlip * direction.y * -0.5 + 0.5 );",
  14753. "sampleUV.x = atan( direction.z, direction.x ) * RECIPROCAL_PI2 + 0.5;",
  14754. "gl_FragColor = texture2D( tEquirect, sampleUV );",
  14755. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14756. "}"
  14757. ].join( "\n" )
  14758. },
  14759. /* Depth encoding into RGBA texture
  14760. *
  14761. * based on SpiderGL shadow map example
  14762. * http://spidergl.org/example.php?id=6
  14763. *
  14764. * originally from
  14765. * http://www.gamedev.net/topic/442138-packing-a-float-into-a-a8r8g8b8-texture-shader/page__whichpage__1%25EF%25BF%25BD
  14766. *
  14767. * see also
  14768. * http://aras-p.info/blog/2009/07/30/encoding-floats-to-rgba-the-final/
  14769. */
  14770. 'depthRGBA': {
  14771. uniforms: {},
  14772. vertexShader: [
  14773. THREE.ShaderChunk[ "common" ],
  14774. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14775. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14776. THREE.ShaderChunk[ "logdepthbuf_pars_vertex" ],
  14777. "void main() {",
  14778. THREE.ShaderChunk[ "skinbase_vertex" ],
  14779. THREE.ShaderChunk[ "begin_vertex" ],
  14780. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14781. THREE.ShaderChunk[ "skinning_vertex" ],
  14782. THREE.ShaderChunk[ "project_vertex" ],
  14783. THREE.ShaderChunk[ "logdepthbuf_vertex" ],
  14784. "}"
  14785. ].join( "\n" ),
  14786. fragmentShader: [
  14787. THREE.ShaderChunk[ "common" ],
  14788. THREE.ShaderChunk[ "logdepthbuf_pars_fragment" ],
  14789. "vec4 pack_depth( const in float depth ) {",
  14790. " const vec4 bit_shift = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14791. " const vec4 bit_mask = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14792. " vec4 res = mod( depth * bit_shift * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );",
  14793. " res -= res.xxyz * bit_mask;",
  14794. " return res;",
  14795. "}",
  14796. "void main() {",
  14797. THREE.ShaderChunk[ "logdepthbuf_fragment" ],
  14798. " #ifdef USE_LOGDEPTHBUF_EXT",
  14799. " gl_FragData[ 0 ] = pack_depth( gl_FragDepthEXT );",
  14800. " #else",
  14801. " gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z );",
  14802. " #endif",
  14803. //"gl_FragData[ 0 ] = pack_depth( gl_FragCoord.z / gl_FragCoord.w );",
  14804. //"float z = ( ( gl_FragCoord.z / gl_FragCoord.w ) - 3.0 ) / ( 4000.0 - 3.0 );",
  14805. //"gl_FragData[ 0 ] = pack_depth( z );",
  14806. //"gl_FragData[ 0 ] = vec4( z, z, z, 1.0 );",
  14807. "}"
  14808. ].join( "\n" )
  14809. },
  14810. 'distanceRGBA': {
  14811. uniforms: {
  14812. "lightPos": { type: "v3", value: new THREE.Vector3( 0, 0, 0 ) }
  14813. },
  14814. vertexShader: [
  14815. "varying vec4 vWorldPosition;",
  14816. THREE.ShaderChunk[ "common" ],
  14817. THREE.ShaderChunk[ "morphtarget_pars_vertex" ],
  14818. THREE.ShaderChunk[ "skinning_pars_vertex" ],
  14819. "void main() {",
  14820. THREE.ShaderChunk[ "skinbase_vertex" ],
  14821. THREE.ShaderChunk[ "begin_vertex" ],
  14822. THREE.ShaderChunk[ "morphtarget_vertex" ],
  14823. THREE.ShaderChunk[ "skinning_vertex" ],
  14824. THREE.ShaderChunk[ "project_vertex" ],
  14825. THREE.ShaderChunk[ "worldpos_vertex" ],
  14826. "vWorldPosition = worldPosition;",
  14827. "}"
  14828. ].join( "\n" ),
  14829. fragmentShader: [
  14830. "uniform vec3 lightPos;",
  14831. "varying vec4 vWorldPosition;",
  14832. THREE.ShaderChunk[ "common" ],
  14833. "vec4 pack1K ( float depth ) {",
  14834. " depth /= 1000.0;",
  14835. " const vec4 bitSh = vec4( 256.0 * 256.0 * 256.0, 256.0 * 256.0, 256.0, 1.0 );",
  14836. " const vec4 bitMsk = vec4( 0.0, 1.0 / 256.0, 1.0 / 256.0, 1.0 / 256.0 );",
  14837. " vec4 res = mod( depth * bitSh * vec4( 255 ), vec4( 256 ) ) / vec4( 255 );",
  14838. " res -= res.xxyz * bitMsk;",
  14839. " return res; ",
  14840. "}",
  14841. "float unpack1K ( vec4 color ) {",
  14842. " const vec4 bitSh = vec4( 1.0 / ( 256.0 * 256.0 * 256.0 ), 1.0 / ( 256.0 * 256.0 ), 1.0 / 256.0, 1.0 );",
  14843. " return dot( color, bitSh ) * 1000.0;",
  14844. "}",
  14845. "void main () {",
  14846. " gl_FragColor = pack1K( length( vWorldPosition.xyz - lightPos.xyz ) );",
  14847. "}"
  14848. ].join( "\n" )
  14849. }
  14850. };
  14851. // File:src/renderers/WebGLRenderer.js
  14852. /**
  14853. * @author supereggbert / http://www.paulbrunt.co.uk/
  14854. * @author mrdoob / http://mrdoob.com/
  14855. * @author alteredq / http://alteredqualia.com/
  14856. * @author szimek / https://github.com/szimek/
  14857. */
  14858. THREE.WebGLRenderer = function ( parameters ) {
  14859. console.log( 'THREE.WebGLRenderer', THREE.REVISION );
  14860. parameters = parameters || {};
  14861. var _canvas = parameters.canvas !== undefined ? parameters.canvas : document.createElement( 'canvas' ),
  14862. _context = parameters.context !== undefined ? parameters.context : null,
  14863. _alpha = parameters.alpha !== undefined ? parameters.alpha : false,
  14864. _depth = parameters.depth !== undefined ? parameters.depth : true,
  14865. _stencil = parameters.stencil !== undefined ? parameters.stencil : true,
  14866. _antialias = parameters.antialias !== undefined ? parameters.antialias : false,
  14867. _premultipliedAlpha = parameters.premultipliedAlpha !== undefined ? parameters.premultipliedAlpha : true,
  14868. _preserveDrawingBuffer = parameters.preserveDrawingBuffer !== undefined ? parameters.preserveDrawingBuffer : false;
  14869. var lights = [];
  14870. var opaqueObjects = [];
  14871. var opaqueObjectsLastIndex = - 1;
  14872. var transparentObjects = [];
  14873. var transparentObjectsLastIndex = - 1;
  14874. var morphInfluences = new Float32Array( 8 );
  14875. var sprites = [];
  14876. var lensFlares = [];
  14877. // public properties
  14878. this.domElement = _canvas;
  14879. this.context = null;
  14880. // clearing
  14881. this.autoClear = true;
  14882. this.autoClearColor = true;
  14883. this.autoClearDepth = true;
  14884. this.autoClearStencil = true;
  14885. // scene graph
  14886. this.sortObjects = true;
  14887. // physically based shading
  14888. this.gammaFactor = 2.0; // for backwards compatibility
  14889. this.gammaInput = false;
  14890. this.gammaOutput = false;
  14891. // morphs
  14892. this.maxMorphTargets = 8;
  14893. this.maxMorphNormals = 4;
  14894. // flags
  14895. this.autoScaleCubemaps = true;
  14896. // internal properties
  14897. var _this = this,
  14898. // internal state cache
  14899. _currentProgram = null,
  14900. _currentRenderTarget = null,
  14901. _currentFramebuffer = null,
  14902. _currentMaterialId = - 1,
  14903. _currentGeometryProgram = '',
  14904. _currentCamera = null,
  14905. _currentScissor = new THREE.Vector4(),
  14906. _currentScissorTest = null,
  14907. _currentViewport = new THREE.Vector4(),
  14908. //
  14909. _usedTextureUnits = 0,
  14910. //
  14911. _clearColor = new THREE.Color( 0x000000 ),
  14912. _clearAlpha = 0,
  14913. _width = _canvas.width,
  14914. _height = _canvas.height,
  14915. _pixelRatio = 1,
  14916. _scissor = new THREE.Vector4( 0, 0, _width, _height ),
  14917. _scissorTest = false,
  14918. _viewport = new THREE.Vector4( 0, 0, _width, _height ),
  14919. // frustum
  14920. _frustum = new THREE.Frustum(),
  14921. // camera matrices cache
  14922. _projScreenMatrix = new THREE.Matrix4(),
  14923. _vector3 = new THREE.Vector3(),
  14924. // light arrays cache
  14925. _lights = {
  14926. hash: '',
  14927. ambient: [ 0, 0, 0 ],
  14928. directional: [],
  14929. directionalShadowMap: [],
  14930. directionalShadowMatrix: [],
  14931. spot: [],
  14932. spotShadowMap: [],
  14933. spotShadowMatrix: [],
  14934. point: [],
  14935. pointShadowMap: [],
  14936. pointShadowMatrix: [],
  14937. hemi: [],
  14938. shadows: [],
  14939. shadowsPointLight: 0
  14940. },
  14941. // info
  14942. _infoMemory = {
  14943. geometries: 0,
  14944. textures: 0
  14945. },
  14946. _infoRender = {
  14947. calls: 0,
  14948. vertices: 0,
  14949. faces: 0,
  14950. points: 0
  14951. };
  14952. this.info = {
  14953. render: _infoRender,
  14954. memory: _infoMemory,
  14955. programs: null
  14956. };
  14957. // initialize
  14958. var _gl;
  14959. try {
  14960. var attributes = {
  14961. alpha: _alpha,
  14962. depth: _depth,
  14963. stencil: _stencil,
  14964. antialias: _antialias,
  14965. premultipliedAlpha: _premultipliedAlpha,
  14966. preserveDrawingBuffer: _preserveDrawingBuffer
  14967. };
  14968. _gl = _context || _canvas.getContext( 'webgl', attributes ) || _canvas.getContext( 'experimental-webgl', attributes );
  14969. if ( _gl === null ) {
  14970. if ( _canvas.getContext( 'webgl' ) !== null ) {
  14971. throw 'Error creating WebGL context with your selected attributes.';
  14972. } else {
  14973. throw 'Error creating WebGL context.';
  14974. }
  14975. }
  14976. _canvas.addEventListener( 'webglcontextlost', onContextLost, false );
  14977. } catch ( error ) {
  14978. console.error( 'THREE.WebGLRenderer: ' + error );
  14979. }
  14980. var extensions = new THREE.WebGLExtensions( _gl );
  14981. extensions.get( 'OES_texture_float' );
  14982. extensions.get( 'OES_texture_float_linear' );
  14983. extensions.get( 'OES_texture_half_float' );
  14984. extensions.get( 'OES_texture_half_float_linear' );
  14985. extensions.get( 'OES_standard_derivatives' );
  14986. extensions.get( 'ANGLE_instanced_arrays' );
  14987. if ( extensions.get( 'OES_element_index_uint' ) ) {
  14988. THREE.BufferGeometry.MaxIndex = 4294967296;
  14989. }
  14990. var capabilities = new THREE.WebGLCapabilities( _gl, extensions, parameters );
  14991. var state = new THREE.WebGLState( _gl, extensions, paramThreeToGL );
  14992. var properties = new THREE.WebGLProperties();
  14993. var objects = new THREE.WebGLObjects( _gl, properties, this.info );
  14994. var programCache = new THREE.WebGLPrograms( this, capabilities );
  14995. var lightCache = new THREE.WebGLLights();
  14996. this.info.programs = programCache.programs;
  14997. var bufferRenderer = new THREE.WebGLBufferRenderer( _gl, extensions, _infoRender );
  14998. var indexedBufferRenderer = new THREE.WebGLIndexedBufferRenderer( _gl, extensions, _infoRender );
  14999. //
  15000. function getTargetPixelRatio() {
  15001. return _currentRenderTarget === null ? _pixelRatio : 1;
  15002. }
  15003. function glClearColor( r, g, b, a ) {
  15004. if ( _premultipliedAlpha === true ) {
  15005. r *= a; g *= a; b *= a;
  15006. }
  15007. state.clearColor( r, g, b, a );
  15008. }
  15009. function setDefaultGLState() {
  15010. state.init();
  15011. state.scissor( _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ) );
  15012. state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ) );
  15013. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  15014. }
  15015. function resetGLState() {
  15016. _currentProgram = null;
  15017. _currentCamera = null;
  15018. _currentGeometryProgram = '';
  15019. _currentMaterialId = - 1;
  15020. state.reset();
  15021. }
  15022. setDefaultGLState();
  15023. this.context = _gl;
  15024. this.capabilities = capabilities;
  15025. this.extensions = extensions;
  15026. this.properties = properties;
  15027. this.state = state;
  15028. // shadow map
  15029. var shadowMap = new THREE.WebGLShadowMap( this, _lights, objects );
  15030. this.shadowMap = shadowMap;
  15031. // Plugins
  15032. var spritePlugin = new THREE.SpritePlugin( this, sprites );
  15033. var lensFlarePlugin = new THREE.LensFlarePlugin( this, lensFlares );
  15034. // API
  15035. this.getContext = function () {
  15036. return _gl;
  15037. };
  15038. this.getContextAttributes = function () {
  15039. return _gl.getContextAttributes();
  15040. };
  15041. this.forceContextLoss = function () {
  15042. extensions.get( 'WEBGL_lose_context' ).loseContext();
  15043. };
  15044. this.getMaxAnisotropy = ( function () {
  15045. var value;
  15046. return function getMaxAnisotropy() {
  15047. if ( value !== undefined ) return value;
  15048. var extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  15049. if ( extension !== null ) {
  15050. value = _gl.getParameter( extension.MAX_TEXTURE_MAX_ANISOTROPY_EXT );
  15051. } else {
  15052. value = 0;
  15053. }
  15054. return value;
  15055. };
  15056. } )();
  15057. this.getPrecision = function () {
  15058. return capabilities.precision;
  15059. };
  15060. this.getPixelRatio = function () {
  15061. return _pixelRatio;
  15062. };
  15063. this.setPixelRatio = function ( value ) {
  15064. if ( value === undefined ) return;
  15065. _pixelRatio = value;
  15066. this.setSize( _viewport.z, _viewport.w, false );
  15067. };
  15068. this.getSize = function () {
  15069. return {
  15070. width: _width,
  15071. height: _height
  15072. };
  15073. };
  15074. this.setSize = function ( width, height, updateStyle ) {
  15075. _width = width;
  15076. _height = height;
  15077. _canvas.width = width * _pixelRatio;
  15078. _canvas.height = height * _pixelRatio;
  15079. if ( updateStyle !== false ) {
  15080. _canvas.style.width = width + 'px';
  15081. _canvas.style.height = height + 'px';
  15082. }
  15083. this.setViewport( 0, 0, width, height );
  15084. };
  15085. this.setViewport = function ( x, y, width, height ) {
  15086. state.viewport( _viewport.set( x, y, width, height ) );
  15087. };
  15088. this.setScissor = function ( x, y, width, height ) {
  15089. state.scissor( _scissor.set( x, y, width, height ) );
  15090. };
  15091. this.setScissorTest = function ( boolean ) {
  15092. state.setScissorTest( _scissorTest = boolean );
  15093. };
  15094. // Clearing
  15095. this.getClearColor = function () {
  15096. return _clearColor;
  15097. };
  15098. this.setClearColor = function ( color, alpha ) {
  15099. _clearColor.set( color );
  15100. _clearAlpha = alpha !== undefined ? alpha : 1;
  15101. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  15102. };
  15103. this.getClearAlpha = function () {
  15104. return _clearAlpha;
  15105. };
  15106. this.setClearAlpha = function ( alpha ) {
  15107. _clearAlpha = alpha;
  15108. glClearColor( _clearColor.r, _clearColor.g, _clearColor.b, _clearAlpha );
  15109. };
  15110. this.clear = function ( color, depth, stencil ) {
  15111. var bits = 0;
  15112. if ( color === undefined || color ) bits |= _gl.COLOR_BUFFER_BIT;
  15113. if ( depth === undefined || depth ) bits |= _gl.DEPTH_BUFFER_BIT;
  15114. if ( stencil === undefined || stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
  15115. _gl.clear( bits );
  15116. };
  15117. this.clearColor = function () {
  15118. this.clear( true, false, false );
  15119. };
  15120. this.clearDepth = function () {
  15121. this.clear( false, true, false );
  15122. };
  15123. this.clearStencil = function () {
  15124. this.clear( false, false, true );
  15125. };
  15126. this.clearTarget = function ( renderTarget, color, depth, stencil ) {
  15127. this.setRenderTarget( renderTarget );
  15128. this.clear( color, depth, stencil );
  15129. };
  15130. // Reset
  15131. this.resetGLState = resetGLState;
  15132. this.dispose = function() {
  15133. _canvas.removeEventListener( 'webglcontextlost', onContextLost, false );
  15134. };
  15135. // Events
  15136. function onContextLost( event ) {
  15137. event.preventDefault();
  15138. resetGLState();
  15139. setDefaultGLState();
  15140. properties.clear();
  15141. }
  15142. function onTextureDispose( event ) {
  15143. var texture = event.target;
  15144. texture.removeEventListener( 'dispose', onTextureDispose );
  15145. deallocateTexture( texture );
  15146. _infoMemory.textures --;
  15147. }
  15148. function onRenderTargetDispose( event ) {
  15149. var renderTarget = event.target;
  15150. renderTarget.removeEventListener( 'dispose', onRenderTargetDispose );
  15151. deallocateRenderTarget( renderTarget );
  15152. _infoMemory.textures --;
  15153. }
  15154. function onMaterialDispose( event ) {
  15155. var material = event.target;
  15156. material.removeEventListener( 'dispose', onMaterialDispose );
  15157. deallocateMaterial( material );
  15158. }
  15159. // Buffer deallocation
  15160. function deallocateTexture( texture ) {
  15161. var textureProperties = properties.get( texture );
  15162. if ( texture.image && textureProperties.__image__webglTextureCube ) {
  15163. // cube texture
  15164. _gl.deleteTexture( textureProperties.__image__webglTextureCube );
  15165. } else {
  15166. // 2D texture
  15167. if ( textureProperties.__webglInit === undefined ) return;
  15168. _gl.deleteTexture( textureProperties.__webglTexture );
  15169. }
  15170. // remove all webgl properties
  15171. properties.delete( texture );
  15172. }
  15173. function deallocateRenderTarget( renderTarget ) {
  15174. var renderTargetProperties = properties.get( renderTarget );
  15175. var textureProperties = properties.get( renderTarget.texture );
  15176. if ( ! renderTarget || textureProperties.__webglTexture === undefined ) return;
  15177. _gl.deleteTexture( textureProperties.__webglTexture );
  15178. if ( renderTarget instanceof THREE.WebGLRenderTargetCube ) {
  15179. for ( var i = 0; i < 6; i ++ ) {
  15180. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer[ i ] );
  15181. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer[ i ] );
  15182. }
  15183. } else {
  15184. _gl.deleteFramebuffer( renderTargetProperties.__webglFramebuffer );
  15185. _gl.deleteRenderbuffer( renderTargetProperties.__webglDepthbuffer );
  15186. }
  15187. properties.delete( renderTarget.texture );
  15188. properties.delete( renderTarget );
  15189. }
  15190. function deallocateMaterial( material ) {
  15191. releaseMaterialProgramReference( material );
  15192. properties.delete( material );
  15193. }
  15194. function releaseMaterialProgramReference( material ) {
  15195. var programInfo = properties.get( material ).program;
  15196. material.program = undefined;
  15197. if ( programInfo !== undefined ) {
  15198. programCache.releaseProgram( programInfo );
  15199. }
  15200. }
  15201. // Buffer rendering
  15202. this.renderBufferImmediate = function ( object, program, material ) {
  15203. state.initAttributes();
  15204. var buffers = properties.get( object );
  15205. if ( object.hasPositions && ! buffers.position ) buffers.position = _gl.createBuffer();
  15206. if ( object.hasNormals && ! buffers.normal ) buffers.normal = _gl.createBuffer();
  15207. if ( object.hasUvs && ! buffers.uv ) buffers.uv = _gl.createBuffer();
  15208. if ( object.hasColors && ! buffers.color ) buffers.color = _gl.createBuffer();
  15209. var attributes = program.getAttributes();
  15210. if ( object.hasPositions ) {
  15211. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.position );
  15212. _gl.bufferData( _gl.ARRAY_BUFFER, object.positionArray, _gl.DYNAMIC_DRAW );
  15213. state.enableAttribute( attributes.position );
  15214. _gl.vertexAttribPointer( attributes.position, 3, _gl.FLOAT, false, 0, 0 );
  15215. }
  15216. if ( object.hasNormals ) {
  15217. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.normal );
  15218. if ( material.type !== 'MeshPhongMaterial' && material.type !== 'MeshStandardMaterial' && material.shading === THREE.FlatShading ) {
  15219. for ( var i = 0, l = object.count * 3; i < l; i += 9 ) {
  15220. var array = object.normalArray;
  15221. var nx = ( array[ i + 0 ] + array[ i + 3 ] + array[ i + 6 ] ) / 3;
  15222. var ny = ( array[ i + 1 ] + array[ i + 4 ] + array[ i + 7 ] ) / 3;
  15223. var nz = ( array[ i + 2 ] + array[ i + 5 ] + array[ i + 8 ] ) / 3;
  15224. array[ i + 0 ] = nx;
  15225. array[ i + 1 ] = ny;
  15226. array[ i + 2 ] = nz;
  15227. array[ i + 3 ] = nx;
  15228. array[ i + 4 ] = ny;
  15229. array[ i + 5 ] = nz;
  15230. array[ i + 6 ] = nx;
  15231. array[ i + 7 ] = ny;
  15232. array[ i + 8 ] = nz;
  15233. }
  15234. }
  15235. _gl.bufferData( _gl.ARRAY_BUFFER, object.normalArray, _gl.DYNAMIC_DRAW );
  15236. state.enableAttribute( attributes.normal );
  15237. _gl.vertexAttribPointer( attributes.normal, 3, _gl.FLOAT, false, 0, 0 );
  15238. }
  15239. if ( object.hasUvs && material.map ) {
  15240. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.uv );
  15241. _gl.bufferData( _gl.ARRAY_BUFFER, object.uvArray, _gl.DYNAMIC_DRAW );
  15242. state.enableAttribute( attributes.uv );
  15243. _gl.vertexAttribPointer( attributes.uv, 2, _gl.FLOAT, false, 0, 0 );
  15244. }
  15245. if ( object.hasColors && material.vertexColors !== THREE.NoColors ) {
  15246. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffers.color );
  15247. _gl.bufferData( _gl.ARRAY_BUFFER, object.colorArray, _gl.DYNAMIC_DRAW );
  15248. state.enableAttribute( attributes.color );
  15249. _gl.vertexAttribPointer( attributes.color, 3, _gl.FLOAT, false, 0, 0 );
  15250. }
  15251. state.disableUnusedAttributes();
  15252. _gl.drawArrays( _gl.TRIANGLES, 0, object.count );
  15253. object.count = 0;
  15254. };
  15255. this.renderBufferDirect = function ( camera, fog, geometry, material, object, group ) {
  15256. setMaterial( material );
  15257. var program = setProgram( camera, fog, material, object );
  15258. var updateBuffers = false;
  15259. var geometryProgram = geometry.id + '_' + program.id + '_' + material.wireframe;
  15260. if ( geometryProgram !== _currentGeometryProgram ) {
  15261. _currentGeometryProgram = geometryProgram;
  15262. updateBuffers = true;
  15263. }
  15264. // morph targets
  15265. var morphTargetInfluences = object.morphTargetInfluences;
  15266. if ( morphTargetInfluences !== undefined ) {
  15267. var activeInfluences = [];
  15268. for ( var i = 0, l = morphTargetInfluences.length; i < l; i ++ ) {
  15269. var influence = morphTargetInfluences[ i ];
  15270. activeInfluences.push( [ influence, i ] );
  15271. }
  15272. activeInfluences.sort( absNumericalSort );
  15273. if ( activeInfluences.length > 8 ) {
  15274. activeInfluences.length = 8;
  15275. }
  15276. var morphAttributes = geometry.morphAttributes;
  15277. for ( var i = 0, l = activeInfluences.length; i < l; i ++ ) {
  15278. var influence = activeInfluences[ i ];
  15279. morphInfluences[ i ] = influence[ 0 ];
  15280. if ( influence[ 0 ] !== 0 ) {
  15281. var index = influence[ 1 ];
  15282. if ( material.morphTargets === true && morphAttributes.position ) geometry.addAttribute( 'morphTarget' + i, morphAttributes.position[ index ] );
  15283. if ( material.morphNormals === true && morphAttributes.normal ) geometry.addAttribute( 'morphNormal' + i, morphAttributes.normal[ index ] );
  15284. } else {
  15285. if ( material.morphTargets === true ) geometry.removeAttribute( 'morphTarget' + i );
  15286. if ( material.morphNormals === true ) geometry.removeAttribute( 'morphNormal' + i );
  15287. }
  15288. }
  15289. var uniforms = program.getUniforms();
  15290. if ( uniforms.morphTargetInfluences !== null ) {
  15291. _gl.uniform1fv( uniforms.morphTargetInfluences, morphInfluences );
  15292. }
  15293. updateBuffers = true;
  15294. }
  15295. //
  15296. var index = geometry.index;
  15297. var position = geometry.attributes.position;
  15298. if ( material.wireframe === true ) {
  15299. index = objects.getWireframeAttribute( geometry );
  15300. }
  15301. var renderer;
  15302. if ( index !== null ) {
  15303. renderer = indexedBufferRenderer;
  15304. renderer.setIndex( index );
  15305. } else {
  15306. renderer = bufferRenderer;
  15307. }
  15308. if ( updateBuffers ) {
  15309. setupVertexAttributes( material, program, geometry );
  15310. if ( index !== null ) {
  15311. _gl.bindBuffer( _gl.ELEMENT_ARRAY_BUFFER, objects.getAttributeBuffer( index ) );
  15312. }
  15313. }
  15314. //
  15315. var dataStart = 0;
  15316. var dataCount = Infinity;
  15317. if ( index !== null ) {
  15318. dataCount = index.count;
  15319. } else if ( position !== undefined ) {
  15320. dataCount = position.count;
  15321. }
  15322. var rangeStart = geometry.drawRange.start;
  15323. var rangeCount = geometry.drawRange.count;
  15324. var groupStart = group !== null ? group.start : 0;
  15325. var groupCount = group !== null ? group.count : Infinity;
  15326. var drawStart = Math.max( dataStart, rangeStart, groupStart );
  15327. var drawEnd = Math.min( dataStart + dataCount, rangeStart + rangeCount, groupStart + groupCount ) - 1;
  15328. var drawCount = Math.max( 0, drawEnd - drawStart + 1 );
  15329. //
  15330. if ( object instanceof THREE.Mesh ) {
  15331. if ( material.wireframe === true ) {
  15332. state.setLineWidth( material.wireframeLinewidth * getTargetPixelRatio() );
  15333. renderer.setMode( _gl.LINES );
  15334. } else {
  15335. switch ( object.drawMode ) {
  15336. case THREE.TrianglesDrawMode:
  15337. renderer.setMode( _gl.TRIANGLES );
  15338. break;
  15339. case THREE.TriangleStripDrawMode:
  15340. renderer.setMode( _gl.TRIANGLE_STRIP );
  15341. break;
  15342. case THREE.TriangleFanDrawMode:
  15343. renderer.setMode( _gl.TRIANGLE_FAN );
  15344. break;
  15345. }
  15346. }
  15347. } else if ( object instanceof THREE.Line ) {
  15348. var lineWidth = material.linewidth;
  15349. if ( lineWidth === undefined ) lineWidth = 1; // Not using Line*Material
  15350. state.setLineWidth( lineWidth * getTargetPixelRatio() );
  15351. if ( object instanceof THREE.LineSegments ) {
  15352. renderer.setMode( _gl.LINES );
  15353. } else {
  15354. renderer.setMode( _gl.LINE_STRIP );
  15355. }
  15356. } else if ( object instanceof THREE.Points ) {
  15357. renderer.setMode( _gl.POINTS );
  15358. }
  15359. if ( geometry instanceof THREE.InstancedBufferGeometry && geometry.maxInstancedCount > 0 ) {
  15360. renderer.renderInstances( geometry, drawStart, drawCount );
  15361. } else {
  15362. renderer.render( drawStart, drawCount );
  15363. }
  15364. };
  15365. function setupVertexAttributes( material, program, geometry, startIndex ) {
  15366. var extension;
  15367. if ( geometry instanceof THREE.InstancedBufferGeometry ) {
  15368. extension = extensions.get( 'ANGLE_instanced_arrays' );
  15369. if ( extension === null ) {
  15370. console.error( 'THREE.WebGLRenderer.setupVertexAttributes: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  15371. return;
  15372. }
  15373. }
  15374. if ( startIndex === undefined ) startIndex = 0;
  15375. state.initAttributes();
  15376. var geometryAttributes = geometry.attributes;
  15377. var programAttributes = program.getAttributes();
  15378. var materialDefaultAttributeValues = material.defaultAttributeValues;
  15379. for ( var name in programAttributes ) {
  15380. var programAttribute = programAttributes[ name ];
  15381. if ( programAttribute >= 0 ) {
  15382. var geometryAttribute = geometryAttributes[ name ];
  15383. if ( geometryAttribute !== undefined ) {
  15384. var size = geometryAttribute.itemSize;
  15385. var buffer = objects.getAttributeBuffer( geometryAttribute );
  15386. if ( geometryAttribute instanceof THREE.InterleavedBufferAttribute ) {
  15387. var data = geometryAttribute.data;
  15388. var stride = data.stride;
  15389. var offset = geometryAttribute.offset;
  15390. if ( data instanceof THREE.InstancedInterleavedBuffer ) {
  15391. state.enableAttributeAndDivisor( programAttribute, data.meshPerAttribute, extension );
  15392. if ( geometry.maxInstancedCount === undefined ) {
  15393. geometry.maxInstancedCount = data.meshPerAttribute * data.count;
  15394. }
  15395. } else {
  15396. state.enableAttribute( programAttribute );
  15397. }
  15398. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15399. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, stride * data.array.BYTES_PER_ELEMENT, ( startIndex * stride + offset ) * data.array.BYTES_PER_ELEMENT );
  15400. } else {
  15401. if ( geometryAttribute instanceof THREE.InstancedBufferAttribute ) {
  15402. state.enableAttributeAndDivisor( programAttribute, geometryAttribute.meshPerAttribute, extension );
  15403. if ( geometry.maxInstancedCount === undefined ) {
  15404. geometry.maxInstancedCount = geometryAttribute.meshPerAttribute * geometryAttribute.count;
  15405. }
  15406. } else {
  15407. state.enableAttribute( programAttribute );
  15408. }
  15409. _gl.bindBuffer( _gl.ARRAY_BUFFER, buffer );
  15410. _gl.vertexAttribPointer( programAttribute, size, _gl.FLOAT, false, 0, startIndex * size * 4 ); // 4 bytes per Float32
  15411. }
  15412. } else if ( materialDefaultAttributeValues !== undefined ) {
  15413. var value = materialDefaultAttributeValues[ name ];
  15414. if ( value !== undefined ) {
  15415. switch ( value.length ) {
  15416. case 2:
  15417. _gl.vertexAttrib2fv( programAttribute, value );
  15418. break;
  15419. case 3:
  15420. _gl.vertexAttrib3fv( programAttribute, value );
  15421. break;
  15422. case 4:
  15423. _gl.vertexAttrib4fv( programAttribute, value );
  15424. break;
  15425. default:
  15426. _gl.vertexAttrib1fv( programAttribute, value );
  15427. }
  15428. }
  15429. }
  15430. }
  15431. }
  15432. state.disableUnusedAttributes();
  15433. }
  15434. // Sorting
  15435. function absNumericalSort( a, b ) {
  15436. return Math.abs( b[ 0 ] ) - Math.abs( a[ 0 ] );
  15437. }
  15438. function painterSortStable ( a, b ) {
  15439. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15440. return a.object.renderOrder - b.object.renderOrder;
  15441. } else if ( a.material.id !== b.material.id ) {
  15442. return a.material.id - b.material.id;
  15443. } else if ( a.z !== b.z ) {
  15444. return a.z - b.z;
  15445. } else {
  15446. return a.id - b.id;
  15447. }
  15448. }
  15449. function reversePainterSortStable ( a, b ) {
  15450. if ( a.object.renderOrder !== b.object.renderOrder ) {
  15451. return a.object.renderOrder - b.object.renderOrder;
  15452. } if ( a.z !== b.z ) {
  15453. return b.z - a.z;
  15454. } else {
  15455. return a.id - b.id;
  15456. }
  15457. }
  15458. // Rendering
  15459. this.render = function ( scene, camera, renderTarget, forceClear ) {
  15460. if ( camera instanceof THREE.Camera === false ) {
  15461. console.error( 'THREE.WebGLRenderer.render: camera is not an instance of THREE.Camera.' );
  15462. return;
  15463. }
  15464. var fog = scene.fog;
  15465. // reset caching for this frame
  15466. _currentGeometryProgram = '';
  15467. _currentMaterialId = - 1;
  15468. _currentCamera = null;
  15469. // update scene graph
  15470. if ( scene.autoUpdate === true ) scene.updateMatrixWorld();
  15471. // update camera matrices and frustum
  15472. if ( camera.parent === null ) camera.updateMatrixWorld();
  15473. camera.matrixWorldInverse.getInverse( camera.matrixWorld );
  15474. _projScreenMatrix.multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse );
  15475. _frustum.setFromMatrix( _projScreenMatrix );
  15476. lights.length = 0;
  15477. opaqueObjectsLastIndex = - 1;
  15478. transparentObjectsLastIndex = - 1;
  15479. sprites.length = 0;
  15480. lensFlares.length = 0;
  15481. projectObject( scene, camera );
  15482. opaqueObjects.length = opaqueObjectsLastIndex + 1;
  15483. transparentObjects.length = transparentObjectsLastIndex + 1;
  15484. if ( _this.sortObjects === true ) {
  15485. opaqueObjects.sort( painterSortStable );
  15486. transparentObjects.sort( reversePainterSortStable );
  15487. }
  15488. setupLights( lights, camera );
  15489. //
  15490. shadowMap.render( scene, camera );
  15491. //
  15492. _infoRender.calls = 0;
  15493. _infoRender.vertices = 0;
  15494. _infoRender.faces = 0;
  15495. _infoRender.points = 0;
  15496. if ( renderTarget === undefined ) {
  15497. renderTarget = null;
  15498. }
  15499. this.setRenderTarget( renderTarget );
  15500. if ( this.autoClear || forceClear ) {
  15501. this.clear( this.autoClearColor, this.autoClearDepth, this.autoClearStencil );
  15502. }
  15503. //
  15504. if ( scene.overrideMaterial ) {
  15505. var overrideMaterial = scene.overrideMaterial;
  15506. renderObjects( opaqueObjects, camera, fog, overrideMaterial );
  15507. renderObjects( transparentObjects, camera, fog, overrideMaterial );
  15508. } else {
  15509. // opaque pass (front-to-back order)
  15510. state.setBlending( THREE.NoBlending );
  15511. renderObjects( opaqueObjects, camera, fog );
  15512. // transparent pass (back-to-front order)
  15513. renderObjects( transparentObjects, camera, fog );
  15514. }
  15515. // custom render plugins (post pass)
  15516. spritePlugin.render( scene, camera );
  15517. lensFlarePlugin.render( scene, camera, _currentViewport );
  15518. // Generate mipmap if we're using any kind of mipmap filtering
  15519. if ( renderTarget ) {
  15520. var texture = renderTarget.texture;
  15521. if ( texture.generateMipmaps && isPowerOfTwo( renderTarget ) &&
  15522. texture.minFilter !== THREE.NearestFilter &&
  15523. texture.minFilter !== THREE.LinearFilter ) {
  15524. updateRenderTargetMipmap( renderTarget );
  15525. }
  15526. }
  15527. // Ensure depth buffer writing is enabled so it can be cleared on next render
  15528. state.setDepthTest( true );
  15529. state.setDepthWrite( true );
  15530. state.setColorWrite( true );
  15531. // _gl.finish();
  15532. };
  15533. function pushRenderItem( object, geometry, material, z, group ) {
  15534. var array, index;
  15535. // allocate the next position in the appropriate array
  15536. if ( material.transparent ) {
  15537. array = transparentObjects;
  15538. index = ++ transparentObjectsLastIndex;
  15539. } else {
  15540. array = opaqueObjects;
  15541. index = ++ opaqueObjectsLastIndex;
  15542. }
  15543. // recycle existing render item or grow the array
  15544. var renderItem = array[ index ];
  15545. if ( renderItem !== undefined ) {
  15546. renderItem.id = object.id;
  15547. renderItem.object = object;
  15548. renderItem.geometry = geometry;
  15549. renderItem.material = material;
  15550. renderItem.z = _vector3.z;
  15551. renderItem.group = group;
  15552. } else {
  15553. renderItem = {
  15554. id: object.id,
  15555. object: object,
  15556. geometry: geometry,
  15557. material: material,
  15558. z: _vector3.z,
  15559. group: group
  15560. };
  15561. // assert( index === array.length );
  15562. array.push( renderItem );
  15563. }
  15564. }
  15565. function projectObject( object, camera ) {
  15566. if ( object.visible === false ) return;
  15567. if ( object.layers.test( camera.layers ) ) {
  15568. if ( object instanceof THREE.Light ) {
  15569. lights.push( object );
  15570. } else if ( object instanceof THREE.Sprite ) {
  15571. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15572. sprites.push( object );
  15573. }
  15574. } else if ( object instanceof THREE.LensFlare ) {
  15575. lensFlares.push( object );
  15576. } else if ( object instanceof THREE.ImmediateRenderObject ) {
  15577. if ( _this.sortObjects === true ) {
  15578. _vector3.setFromMatrixPosition( object.matrixWorld );
  15579. _vector3.applyProjection( _projScreenMatrix );
  15580. }
  15581. pushRenderItem( object, null, object.material, _vector3.z, null );
  15582. } else if ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) {
  15583. if ( object instanceof THREE.SkinnedMesh ) {
  15584. object.skeleton.update();
  15585. }
  15586. if ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) {
  15587. var material = object.material;
  15588. if ( material.visible === true ) {
  15589. if ( _this.sortObjects === true ) {
  15590. _vector3.setFromMatrixPosition( object.matrixWorld );
  15591. _vector3.applyProjection( _projScreenMatrix );
  15592. }
  15593. var geometry = objects.update( object );
  15594. if ( material instanceof THREE.MultiMaterial ) {
  15595. var groups = geometry.groups;
  15596. var materials = material.materials;
  15597. for ( var i = 0, l = groups.length; i < l; i ++ ) {
  15598. var group = groups[ i ];
  15599. var groupMaterial = materials[ group.materialIndex ];
  15600. if ( groupMaterial.visible === true ) {
  15601. pushRenderItem( object, geometry, groupMaterial, _vector3.z, group );
  15602. }
  15603. }
  15604. } else {
  15605. pushRenderItem( object, geometry, material, _vector3.z, null );
  15606. }
  15607. }
  15608. }
  15609. }
  15610. }
  15611. var children = object.children;
  15612. for ( var i = 0, l = children.length; i < l; i ++ ) {
  15613. projectObject( children[ i ], camera );
  15614. }
  15615. }
  15616. function renderObjects( renderList, camera, fog, overrideMaterial ) {
  15617. for ( var i = 0, l = renderList.length; i < l; i ++ ) {
  15618. var renderItem = renderList[ i ];
  15619. var object = renderItem.object;
  15620. var geometry = renderItem.geometry;
  15621. var material = overrideMaterial === undefined ? renderItem.material : overrideMaterial;
  15622. var group = renderItem.group;
  15623. object.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, object.matrixWorld );
  15624. object.normalMatrix.getNormalMatrix( object.modelViewMatrix );
  15625. if ( object instanceof THREE.ImmediateRenderObject ) {
  15626. setMaterial( material );
  15627. var program = setProgram( camera, fog, material, object );
  15628. _currentGeometryProgram = '';
  15629. object.render( function ( object ) {
  15630. _this.renderBufferImmediate( object, program, material );
  15631. } );
  15632. } else {
  15633. _this.renderBufferDirect( camera, fog, geometry, material, object, group );
  15634. }
  15635. }
  15636. }
  15637. function initMaterial( material, fog, object ) {
  15638. var materialProperties = properties.get( material );
  15639. var parameters = programCache.getParameters( material, _lights, fog, object );
  15640. var code = programCache.getProgramCode( material, parameters );
  15641. var program = materialProperties.program;
  15642. var programChange = true;
  15643. if ( program === undefined ) {
  15644. // new material
  15645. material.addEventListener( 'dispose', onMaterialDispose );
  15646. } else if ( program.code !== code ) {
  15647. // changed glsl or parameters
  15648. releaseMaterialProgramReference( material );
  15649. } else if ( parameters.shaderID !== undefined ) {
  15650. // same glsl and uniform list
  15651. return;
  15652. } else {
  15653. // only rebuild uniform list
  15654. programChange = false;
  15655. }
  15656. if ( programChange ) {
  15657. if ( parameters.shaderID ) {
  15658. var shader = THREE.ShaderLib[ parameters.shaderID ];
  15659. materialProperties.__webglShader = {
  15660. name: material.type,
  15661. uniforms: THREE.UniformsUtils.clone( shader.uniforms ),
  15662. vertexShader: shader.vertexShader,
  15663. fragmentShader: shader.fragmentShader
  15664. };
  15665. } else {
  15666. materialProperties.__webglShader = {
  15667. name: material.type,
  15668. uniforms: material.uniforms,
  15669. vertexShader: material.vertexShader,
  15670. fragmentShader: material.fragmentShader
  15671. };
  15672. }
  15673. material.__webglShader = materialProperties.__webglShader;
  15674. program = programCache.acquireProgram( material, parameters, code );
  15675. materialProperties.program = program;
  15676. material.program = program;
  15677. }
  15678. var attributes = program.getAttributes();
  15679. if ( material.morphTargets ) {
  15680. material.numSupportedMorphTargets = 0;
  15681. for ( var i = 0; i < _this.maxMorphTargets; i ++ ) {
  15682. if ( attributes[ 'morphTarget' + i ] >= 0 ) {
  15683. material.numSupportedMorphTargets ++;
  15684. }
  15685. }
  15686. }
  15687. if ( material.morphNormals ) {
  15688. material.numSupportedMorphNormals = 0;
  15689. for ( var i = 0; i < _this.maxMorphNormals; i ++ ) {
  15690. if ( attributes[ 'morphNormal' + i ] >= 0 ) {
  15691. material.numSupportedMorphNormals ++;
  15692. }
  15693. }
  15694. }
  15695. materialProperties.uniformsList = [];
  15696. var uniforms = materialProperties.__webglShader.uniforms,
  15697. uniformLocations = materialProperties.program.getUniforms();
  15698. for ( var u in uniforms ) {
  15699. var location = uniformLocations[ u ];
  15700. if ( location ) {
  15701. materialProperties.uniformsList.push( [ materialProperties.__webglShader.uniforms[ u ], location ] );
  15702. }
  15703. }
  15704. if ( material instanceof THREE.MeshPhongMaterial ||
  15705. material instanceof THREE.MeshLambertMaterial ||
  15706. material instanceof THREE.MeshStandardMaterial ||
  15707. material.lights ) {
  15708. // store the light setup it was created for
  15709. materialProperties.lightsHash = _lights.hash;
  15710. // wire up the material to this renderer's lighting state
  15711. uniforms.ambientLightColor.value = _lights.ambient;
  15712. uniforms.directionalLights.value = _lights.directional;
  15713. uniforms.spotLights.value = _lights.spot;
  15714. uniforms.pointLights.value = _lights.point;
  15715. uniforms.hemisphereLights.value = _lights.hemi;
  15716. uniforms.directionalShadowMap.value = _lights.directionalShadowMap;
  15717. uniforms.directionalShadowMatrix.value = _lights.directionalShadowMatrix;
  15718. uniforms.spotShadowMap.value = _lights.spotShadowMap;
  15719. uniforms.spotShadowMatrix.value = _lights.spotShadowMatrix;
  15720. uniforms.pointShadowMap.value = _lights.pointShadowMap;
  15721. uniforms.pointShadowMatrix.value = _lights.pointShadowMatrix;
  15722. }
  15723. // detect dynamic uniforms
  15724. materialProperties.hasDynamicUniforms = false;
  15725. for ( var j = 0, jl = materialProperties.uniformsList.length; j < jl; j ++ ) {
  15726. var uniform = materialProperties.uniformsList[ j ][ 0 ];
  15727. if ( uniform.dynamic === true ) {
  15728. materialProperties.hasDynamicUniforms = true;
  15729. break;
  15730. }
  15731. }
  15732. }
  15733. function setMaterial( material ) {
  15734. setMaterialFaces( material );
  15735. if ( material.transparent === true ) {
  15736. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst, material.blendEquationAlpha, material.blendSrcAlpha, material.blendDstAlpha );
  15737. } else {
  15738. state.setBlending( THREE.NoBlending );
  15739. }
  15740. state.setDepthFunc( material.depthFunc );
  15741. state.setDepthTest( material.depthTest );
  15742. state.setDepthWrite( material.depthWrite );
  15743. state.setColorWrite( material.colorWrite );
  15744. state.setPolygonOffset( material.polygonOffset, material.polygonOffsetFactor, material.polygonOffsetUnits );
  15745. }
  15746. function setMaterialFaces( material ) {
  15747. material.side !== THREE.DoubleSide ? state.enable( _gl.CULL_FACE ) : state.disable( _gl.CULL_FACE );
  15748. state.setFlipSided( material.side === THREE.BackSide );
  15749. }
  15750. function setProgram( camera, fog, material, object ) {
  15751. _usedTextureUnits = 0;
  15752. var materialProperties = properties.get( material );
  15753. if ( materialProperties.program === undefined ) {
  15754. material.needsUpdate = true;
  15755. }
  15756. if ( materialProperties.lightsHash !== undefined &&
  15757. materialProperties.lightsHash !== _lights.hash ) {
  15758. material.needsUpdate = true;
  15759. }
  15760. if ( material.needsUpdate ) {
  15761. initMaterial( material, fog, object );
  15762. material.needsUpdate = false;
  15763. }
  15764. var refreshProgram = false;
  15765. var refreshMaterial = false;
  15766. var refreshLights = false;
  15767. var program = materialProperties.program,
  15768. p_uniforms = program.getUniforms(),
  15769. m_uniforms = materialProperties.__webglShader.uniforms;
  15770. if ( program.id !== _currentProgram ) {
  15771. _gl.useProgram( program.program );
  15772. _currentProgram = program.id;
  15773. refreshProgram = true;
  15774. refreshMaterial = true;
  15775. refreshLights = true;
  15776. }
  15777. if ( material.id !== _currentMaterialId ) {
  15778. _currentMaterialId = material.id;
  15779. refreshMaterial = true;
  15780. }
  15781. if ( refreshProgram || camera !== _currentCamera ) {
  15782. _gl.uniformMatrix4fv( p_uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  15783. if ( capabilities.logarithmicDepthBuffer ) {
  15784. _gl.uniform1f( p_uniforms.logDepthBufFC, 2.0 / ( Math.log( camera.far + 1.0 ) / Math.LN2 ) );
  15785. }
  15786. if ( camera !== _currentCamera ) {
  15787. _currentCamera = camera;
  15788. // lighting uniforms depend on the camera so enforce an update
  15789. // now, in case this material supports lights - or later, when
  15790. // the next material that does gets activated:
  15791. refreshMaterial = true; // set to true on material change
  15792. refreshLights = true; // remains set until update done
  15793. }
  15794. // load material specific uniforms
  15795. // (shader material also gets them for the sake of genericity)
  15796. if ( material instanceof THREE.ShaderMaterial ||
  15797. material instanceof THREE.MeshPhongMaterial ||
  15798. material instanceof THREE.MeshStandardMaterial ||
  15799. material.envMap ) {
  15800. if ( p_uniforms.cameraPosition !== undefined ) {
  15801. _vector3.setFromMatrixPosition( camera.matrixWorld );
  15802. _gl.uniform3f( p_uniforms.cameraPosition, _vector3.x, _vector3.y, _vector3.z );
  15803. }
  15804. }
  15805. if ( material instanceof THREE.MeshPhongMaterial ||
  15806. material instanceof THREE.MeshLambertMaterial ||
  15807. material instanceof THREE.MeshBasicMaterial ||
  15808. material instanceof THREE.MeshStandardMaterial ||
  15809. material instanceof THREE.ShaderMaterial ||
  15810. material.skinning ) {
  15811. if ( p_uniforms.viewMatrix !== undefined ) {
  15812. _gl.uniformMatrix4fv( p_uniforms.viewMatrix, false, camera.matrixWorldInverse.elements );
  15813. }
  15814. }
  15815. }
  15816. // skinning uniforms must be set even if material didn't change
  15817. // auto-setting of texture unit for bone texture must go before other textures
  15818. // not sure why, but otherwise weird things happen
  15819. if ( material.skinning ) {
  15820. if ( object.bindMatrix && p_uniforms.bindMatrix !== undefined ) {
  15821. _gl.uniformMatrix4fv( p_uniforms.bindMatrix, false, object.bindMatrix.elements );
  15822. }
  15823. if ( object.bindMatrixInverse && p_uniforms.bindMatrixInverse !== undefined ) {
  15824. _gl.uniformMatrix4fv( p_uniforms.bindMatrixInverse, false, object.bindMatrixInverse.elements );
  15825. }
  15826. if ( capabilities.floatVertexTextures && object.skeleton && object.skeleton.useVertexTexture ) {
  15827. if ( p_uniforms.boneTexture !== undefined ) {
  15828. var textureUnit = getTextureUnit();
  15829. _gl.uniform1i( p_uniforms.boneTexture, textureUnit );
  15830. _this.setTexture( object.skeleton.boneTexture, textureUnit );
  15831. }
  15832. if ( p_uniforms.boneTextureWidth !== undefined ) {
  15833. _gl.uniform1i( p_uniforms.boneTextureWidth, object.skeleton.boneTextureWidth );
  15834. }
  15835. if ( p_uniforms.boneTextureHeight !== undefined ) {
  15836. _gl.uniform1i( p_uniforms.boneTextureHeight, object.skeleton.boneTextureHeight );
  15837. }
  15838. } else if ( object.skeleton && object.skeleton.boneMatrices ) {
  15839. if ( p_uniforms.boneGlobalMatrices !== undefined ) {
  15840. _gl.uniformMatrix4fv( p_uniforms.boneGlobalMatrices, false, object.skeleton.boneMatrices );
  15841. }
  15842. }
  15843. }
  15844. if ( refreshMaterial ) {
  15845. if ( material instanceof THREE.MeshPhongMaterial ||
  15846. material instanceof THREE.MeshLambertMaterial ||
  15847. material instanceof THREE.MeshStandardMaterial ||
  15848. material.lights ) {
  15849. // the current material requires lighting info
  15850. // note: all lighting uniforms are always set correctly
  15851. // they simply reference the renderer's state for their
  15852. // values
  15853. //
  15854. // use the current material's .needsUpdate flags to set
  15855. // the GL state when required
  15856. markUniformsLightsNeedsUpdate( m_uniforms, refreshLights );
  15857. }
  15858. // refresh uniforms common to several materials
  15859. if ( fog && material.fog ) {
  15860. refreshUniformsFog( m_uniforms, fog );
  15861. }
  15862. if ( material instanceof THREE.MeshBasicMaterial ||
  15863. material instanceof THREE.MeshLambertMaterial ||
  15864. material instanceof THREE.MeshPhongMaterial ||
  15865. material instanceof THREE.MeshStandardMaterial ) {
  15866. refreshUniformsCommon( m_uniforms, material );
  15867. }
  15868. // refresh single material specific uniforms
  15869. if ( material instanceof THREE.LineBasicMaterial ) {
  15870. refreshUniformsLine( m_uniforms, material );
  15871. } else if ( material instanceof THREE.LineDashedMaterial ) {
  15872. refreshUniformsLine( m_uniforms, material );
  15873. refreshUniformsDash( m_uniforms, material );
  15874. } else if ( material instanceof THREE.PointsMaterial ) {
  15875. refreshUniformsPoints( m_uniforms, material );
  15876. } else if ( material instanceof THREE.MeshLambertMaterial ) {
  15877. refreshUniformsLambert( m_uniforms, material );
  15878. } else if ( material instanceof THREE.MeshPhongMaterial ) {
  15879. refreshUniformsPhong( m_uniforms, material );
  15880. } else if ( material instanceof THREE.MeshStandardMaterial ) {
  15881. refreshUniformsStandard( m_uniforms, material );
  15882. } else if ( material instanceof THREE.MeshDepthMaterial ) {
  15883. m_uniforms.mNear.value = camera.near;
  15884. m_uniforms.mFar.value = camera.far;
  15885. m_uniforms.opacity.value = material.opacity;
  15886. } else if ( material instanceof THREE.MeshNormalMaterial ) {
  15887. m_uniforms.opacity.value = material.opacity;
  15888. }
  15889. // load common uniforms
  15890. loadUniformsGeneric( materialProperties.uniformsList );
  15891. }
  15892. loadUniformsMatrices( p_uniforms, object );
  15893. if ( p_uniforms.modelMatrix !== undefined ) {
  15894. _gl.uniformMatrix4fv( p_uniforms.modelMatrix, false, object.matrixWorld.elements );
  15895. }
  15896. if ( materialProperties.hasDynamicUniforms === true ) {
  15897. updateDynamicUniforms( materialProperties.uniformsList, object, camera );
  15898. }
  15899. return program;
  15900. }
  15901. function updateDynamicUniforms ( uniforms, object, camera ) {
  15902. var dynamicUniforms = [];
  15903. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  15904. var uniform = uniforms[ j ][ 0 ];
  15905. var onUpdateCallback = uniform.onUpdateCallback;
  15906. if ( onUpdateCallback !== undefined ) {
  15907. onUpdateCallback.bind( uniform )( object, camera );
  15908. dynamicUniforms.push( uniforms[ j ] );
  15909. }
  15910. }
  15911. loadUniformsGeneric( dynamicUniforms );
  15912. }
  15913. // Uniforms (refresh uniforms objects)
  15914. function refreshUniformsCommon ( uniforms, material ) {
  15915. uniforms.opacity.value = material.opacity;
  15916. uniforms.diffuse.value = material.color;
  15917. if ( material.emissive ) {
  15918. uniforms.emissive.value.copy( material.emissive ).multiplyScalar( material.emissiveIntensity );
  15919. }
  15920. uniforms.map.value = material.map;
  15921. uniforms.specularMap.value = material.specularMap;
  15922. uniforms.alphaMap.value = material.alphaMap;
  15923. if ( material.aoMap ) {
  15924. uniforms.aoMap.value = material.aoMap;
  15925. uniforms.aoMapIntensity.value = material.aoMapIntensity;
  15926. }
  15927. // uv repeat and offset setting priorities
  15928. // 1. color map
  15929. // 2. specular map
  15930. // 3. normal map
  15931. // 4. bump map
  15932. // 5. alpha map
  15933. // 6. emissive map
  15934. var uvScaleMap;
  15935. if ( material.map ) {
  15936. uvScaleMap = material.map;
  15937. } else if ( material.specularMap ) {
  15938. uvScaleMap = material.specularMap;
  15939. } else if ( material.displacementMap ) {
  15940. uvScaleMap = material.displacementMap;
  15941. } else if ( material.normalMap ) {
  15942. uvScaleMap = material.normalMap;
  15943. } else if ( material.bumpMap ) {
  15944. uvScaleMap = material.bumpMap;
  15945. } else if ( material.roughnessMap ) {
  15946. uvScaleMap = material.roughnessMap;
  15947. } else if ( material.metalnessMap ) {
  15948. uvScaleMap = material.metalnessMap;
  15949. } else if ( material.alphaMap ) {
  15950. uvScaleMap = material.alphaMap;
  15951. } else if ( material.emissiveMap ) {
  15952. uvScaleMap = material.emissiveMap;
  15953. }
  15954. if ( uvScaleMap !== undefined ) {
  15955. if ( uvScaleMap instanceof THREE.WebGLRenderTarget ) {
  15956. uvScaleMap = uvScaleMap.texture;
  15957. }
  15958. var offset = uvScaleMap.offset;
  15959. var repeat = uvScaleMap.repeat;
  15960. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15961. }
  15962. uniforms.envMap.value = material.envMap;
  15963. uniforms.flipEnvMap.value = ( material.envMap instanceof THREE.WebGLRenderTargetCube ) ? 1 : - 1;
  15964. uniforms.reflectivity.value = material.reflectivity;
  15965. uniforms.refractionRatio.value = material.refractionRatio;
  15966. }
  15967. function refreshUniformsLine ( uniforms, material ) {
  15968. uniforms.diffuse.value = material.color;
  15969. uniforms.opacity.value = material.opacity;
  15970. }
  15971. function refreshUniformsDash ( uniforms, material ) {
  15972. uniforms.dashSize.value = material.dashSize;
  15973. uniforms.totalSize.value = material.dashSize + material.gapSize;
  15974. uniforms.scale.value = material.scale;
  15975. }
  15976. function refreshUniformsPoints ( uniforms, material ) {
  15977. uniforms.diffuse.value = material.color;
  15978. uniforms.opacity.value = material.opacity;
  15979. uniforms.size.value = material.size * _pixelRatio;
  15980. uniforms.scale.value = _canvas.clientHeight / 2.0; // TODO: Cache this.
  15981. uniforms.map.value = material.map;
  15982. if ( material.map !== null ) {
  15983. var offset = material.map.offset;
  15984. var repeat = material.map.repeat;
  15985. uniforms.offsetRepeat.value.set( offset.x, offset.y, repeat.x, repeat.y );
  15986. }
  15987. }
  15988. function refreshUniformsFog ( uniforms, fog ) {
  15989. uniforms.fogColor.value = fog.color;
  15990. if ( fog instanceof THREE.Fog ) {
  15991. uniforms.fogNear.value = fog.near;
  15992. uniforms.fogFar.value = fog.far;
  15993. } else if ( fog instanceof THREE.FogExp2 ) {
  15994. uniforms.fogDensity.value = fog.density;
  15995. }
  15996. }
  15997. function refreshUniformsLambert ( uniforms, material ) {
  15998. if ( material.lightMap ) {
  15999. uniforms.lightMap.value = material.lightMap;
  16000. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  16001. }
  16002. if ( material.emissiveMap ) {
  16003. uniforms.emissiveMap.value = material.emissiveMap;
  16004. }
  16005. }
  16006. function refreshUniformsPhong ( uniforms, material ) {
  16007. uniforms.specular.value = material.specular;
  16008. uniforms.shininess.value = Math.max( material.shininess, 1e-4 ); // to prevent pow( 0.0, 0.0 )
  16009. if ( material.lightMap ) {
  16010. uniforms.lightMap.value = material.lightMap;
  16011. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  16012. }
  16013. if ( material.emissiveMap ) {
  16014. uniforms.emissiveMap.value = material.emissiveMap;
  16015. }
  16016. if ( material.bumpMap ) {
  16017. uniforms.bumpMap.value = material.bumpMap;
  16018. uniforms.bumpScale.value = material.bumpScale;
  16019. }
  16020. if ( material.normalMap ) {
  16021. uniforms.normalMap.value = material.normalMap;
  16022. uniforms.normalScale.value.copy( material.normalScale );
  16023. }
  16024. if ( material.displacementMap ) {
  16025. uniforms.displacementMap.value = material.displacementMap;
  16026. uniforms.displacementScale.value = material.displacementScale;
  16027. uniforms.displacementBias.value = material.displacementBias;
  16028. }
  16029. }
  16030. function refreshUniformsStandard ( uniforms, material ) {
  16031. uniforms.roughness.value = material.roughness;
  16032. uniforms.metalness.value = material.metalness;
  16033. if ( material.roughnessMap ) {
  16034. uniforms.roughnessMap.value = material.roughnessMap;
  16035. }
  16036. if ( material.metalnessMap ) {
  16037. uniforms.metalnessMap.value = material.metalnessMap;
  16038. }
  16039. if ( material.lightMap ) {
  16040. uniforms.lightMap.value = material.lightMap;
  16041. uniforms.lightMapIntensity.value = material.lightMapIntensity;
  16042. }
  16043. if ( material.emissiveMap ) {
  16044. uniforms.emissiveMap.value = material.emissiveMap;
  16045. }
  16046. if ( material.bumpMap ) {
  16047. uniforms.bumpMap.value = material.bumpMap;
  16048. uniforms.bumpScale.value = material.bumpScale;
  16049. }
  16050. if ( material.normalMap ) {
  16051. uniforms.normalMap.value = material.normalMap;
  16052. uniforms.normalScale.value.copy( material.normalScale );
  16053. }
  16054. if ( material.displacementMap ) {
  16055. uniforms.displacementMap.value = material.displacementMap;
  16056. uniforms.displacementScale.value = material.displacementScale;
  16057. uniforms.displacementBias.value = material.displacementBias;
  16058. }
  16059. if ( material.envMap ) {
  16060. //uniforms.envMap.value = material.envMap; // part of uniforms common
  16061. uniforms.envMapIntensity.value = material.envMapIntensity;
  16062. }
  16063. }
  16064. // If uniforms are marked as clean, they don't need to be loaded to the GPU.
  16065. function markUniformsLightsNeedsUpdate ( uniforms, value ) {
  16066. uniforms.ambientLightColor.needsUpdate = value;
  16067. uniforms.directionalLights.needsUpdate = value;
  16068. uniforms.pointLights.needsUpdate = value;
  16069. uniforms.spotLights.needsUpdate = value;
  16070. uniforms.hemisphereLights.needsUpdate = value;
  16071. }
  16072. // Uniforms (load to GPU)
  16073. function loadUniformsMatrices ( uniforms, object ) {
  16074. _gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, object.modelViewMatrix.elements );
  16075. if ( uniforms.normalMatrix ) {
  16076. _gl.uniformMatrix3fv( uniforms.normalMatrix, false, object.normalMatrix.elements );
  16077. }
  16078. }
  16079. function getTextureUnit() {
  16080. var textureUnit = _usedTextureUnits;
  16081. if ( textureUnit >= capabilities.maxTextures ) {
  16082. console.warn( 'WebGLRenderer: trying to use ' + textureUnit + ' texture units while this GPU supports only ' + capabilities.maxTextures );
  16083. }
  16084. _usedTextureUnits += 1;
  16085. return textureUnit;
  16086. }
  16087. function loadUniformsGeneric ( uniforms ) {
  16088. var texture, textureUnit;
  16089. for ( var j = 0, jl = uniforms.length; j < jl; j ++ ) {
  16090. var uniform = uniforms[ j ][ 0 ];
  16091. // needsUpdate property is not added to all uniforms.
  16092. if ( uniform.needsUpdate === false ) continue;
  16093. var type = uniform.type;
  16094. var value = uniform.value;
  16095. var location = uniforms[ j ][ 1 ];
  16096. switch ( type ) {
  16097. case '1i':
  16098. _gl.uniform1i( location, value );
  16099. break;
  16100. case '1f':
  16101. _gl.uniform1f( location, value );
  16102. break;
  16103. case '2f':
  16104. _gl.uniform2f( location, value[ 0 ], value[ 1 ] );
  16105. break;
  16106. case '3f':
  16107. _gl.uniform3f( location, value[ 0 ], value[ 1 ], value[ 2 ] );
  16108. break;
  16109. case '4f':
  16110. _gl.uniform4f( location, value[ 0 ], value[ 1 ], value[ 2 ], value[ 3 ] );
  16111. break;
  16112. case '1iv':
  16113. _gl.uniform1iv( location, value );
  16114. break;
  16115. case '3iv':
  16116. _gl.uniform3iv( location, value );
  16117. break;
  16118. case '1fv':
  16119. _gl.uniform1fv( location, value );
  16120. break;
  16121. case '2fv':
  16122. _gl.uniform2fv( location, value );
  16123. break;
  16124. case '3fv':
  16125. _gl.uniform3fv( location, value );
  16126. break;
  16127. case '4fv':
  16128. _gl.uniform4fv( location, value );
  16129. break;
  16130. case 'Matrix2fv':
  16131. _gl.uniformMatrix2fv( location, false, value );
  16132. break;
  16133. case 'Matrix3fv':
  16134. _gl.uniformMatrix3fv( location, false, value );
  16135. break;
  16136. case 'Matrix4fv':
  16137. _gl.uniformMatrix4fv( location, false, value );
  16138. break;
  16139. //
  16140. case 'i':
  16141. // single integer
  16142. _gl.uniform1i( location, value );
  16143. break;
  16144. case 'f':
  16145. // single float
  16146. _gl.uniform1f( location, value );
  16147. break;
  16148. case 'v2':
  16149. // single THREE.Vector2
  16150. _gl.uniform2f( location, value.x, value.y );
  16151. break;
  16152. case 'v3':
  16153. // single THREE.Vector3
  16154. _gl.uniform3f( location, value.x, value.y, value.z );
  16155. break;
  16156. case 'v4':
  16157. // single THREE.Vector4
  16158. _gl.uniform4f( location, value.x, value.y, value.z, value.w );
  16159. break;
  16160. case 'c':
  16161. // single THREE.Color
  16162. _gl.uniform3f( location, value.r, value.g, value.b );
  16163. break;
  16164. /*
  16165. case 's':
  16166. // TODO: Optimize this.
  16167. for( var propertyName in uniform.properties ) {
  16168. var property = uniform.properties[ propertyName ];
  16169. var locationProperty = location[ propertyName ];
  16170. var valueProperty = value[ propertyName ];
  16171. switch( property.type ) {
  16172. case 'i':
  16173. _gl.uniform1i( locationProperty, valueProperty );
  16174. break;
  16175. case 'f':
  16176. _gl.uniform1f( locationProperty, valueProperty );
  16177. break;
  16178. case 'v2':
  16179. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  16180. break;
  16181. case 'v3':
  16182. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  16183. break;
  16184. case 'v4':
  16185. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  16186. break;
  16187. case 'c':
  16188. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  16189. break;
  16190. };
  16191. }
  16192. break;
  16193. */
  16194. case 'sa':
  16195. // TODO: Optimize this.
  16196. for ( var i = 0; i < value.length; i ++ ) {
  16197. for ( var propertyName in uniform.properties ) {
  16198. var property = uniform.properties[ propertyName ];
  16199. var locationProperty = location[ i ][ propertyName ];
  16200. var valueProperty = value[ i ][ propertyName ];
  16201. switch ( property.type ) {
  16202. case 'i':
  16203. _gl.uniform1i( locationProperty, valueProperty );
  16204. break;
  16205. case 'f':
  16206. _gl.uniform1f( locationProperty, valueProperty );
  16207. break;
  16208. case 'v2':
  16209. _gl.uniform2f( locationProperty, valueProperty.x, valueProperty.y );
  16210. break;
  16211. case 'v3':
  16212. _gl.uniform3f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z );
  16213. break;
  16214. case 'v4':
  16215. _gl.uniform4f( locationProperty, valueProperty.x, valueProperty.y, valueProperty.z, valueProperty.w );
  16216. break;
  16217. case 'c':
  16218. _gl.uniform3f( locationProperty, valueProperty.r, valueProperty.g, valueProperty.b );
  16219. break;
  16220. case 'm4':
  16221. _gl.uniformMatrix4fv( locationProperty, false, valueProperty.elements );
  16222. break;
  16223. }
  16224. }
  16225. }
  16226. break;
  16227. case 'iv1':
  16228. // flat array of integers (JS or typed array)
  16229. _gl.uniform1iv( location, value );
  16230. break;
  16231. case 'iv':
  16232. // flat array of integers with 3 x N size (JS or typed array)
  16233. _gl.uniform3iv( location, value );
  16234. break;
  16235. case 'fv1':
  16236. // flat array of floats (JS or typed array)
  16237. _gl.uniform1fv( location, value );
  16238. break;
  16239. case 'fv':
  16240. // flat array of floats with 3 x N size (JS or typed array)
  16241. _gl.uniform3fv( location, value );
  16242. break;
  16243. case 'v2v':
  16244. // array of THREE.Vector2
  16245. if ( uniform._array === undefined ) {
  16246. uniform._array = new Float32Array( 2 * value.length );
  16247. }
  16248. for ( var i = 0, i2 = 0, il = value.length; i < il; i ++, i2 += 2 ) {
  16249. uniform._array[ i2 + 0 ] = value[ i ].x;
  16250. uniform._array[ i2 + 1 ] = value[ i ].y;
  16251. }
  16252. _gl.uniform2fv( location, uniform._array );
  16253. break;
  16254. case 'v3v':
  16255. // array of THREE.Vector3
  16256. if ( uniform._array === undefined ) {
  16257. uniform._array = new Float32Array( 3 * value.length );
  16258. }
  16259. for ( var i = 0, i3 = 0, il = value.length; i < il; i ++, i3 += 3 ) {
  16260. uniform._array[ i3 + 0 ] = value[ i ].x;
  16261. uniform._array[ i3 + 1 ] = value[ i ].y;
  16262. uniform._array[ i3 + 2 ] = value[ i ].z;
  16263. }
  16264. _gl.uniform3fv( location, uniform._array );
  16265. break;
  16266. case 'v4v':
  16267. // array of THREE.Vector4
  16268. if ( uniform._array === undefined ) {
  16269. uniform._array = new Float32Array( 4 * value.length );
  16270. }
  16271. for ( var i = 0, i4 = 0, il = value.length; i < il; i ++, i4 += 4 ) {
  16272. uniform._array[ i4 + 0 ] = value[ i ].x;
  16273. uniform._array[ i4 + 1 ] = value[ i ].y;
  16274. uniform._array[ i4 + 2 ] = value[ i ].z;
  16275. uniform._array[ i4 + 3 ] = value[ i ].w;
  16276. }
  16277. _gl.uniform4fv( location, uniform._array );
  16278. break;
  16279. case 'm2':
  16280. // single THREE.Matrix2
  16281. _gl.uniformMatrix2fv( location, false, value.elements );
  16282. break;
  16283. case 'm3':
  16284. // single THREE.Matrix3
  16285. _gl.uniformMatrix3fv( location, false, value.elements );
  16286. break;
  16287. case 'm3v':
  16288. // array of THREE.Matrix3
  16289. if ( uniform._array === undefined ) {
  16290. uniform._array = new Float32Array( 9 * value.length );
  16291. }
  16292. for ( var i = 0, il = value.length; i < il; i ++ ) {
  16293. value[ i ].flattenToArrayOffset( uniform._array, i * 9 );
  16294. }
  16295. _gl.uniformMatrix3fv( location, false, uniform._array );
  16296. break;
  16297. case 'm4':
  16298. // single THREE.Matrix4
  16299. _gl.uniformMatrix4fv( location, false, value.elements );
  16300. break;
  16301. case 'm4v':
  16302. // array of THREE.Matrix4
  16303. if ( uniform._array === undefined ) {
  16304. uniform._array = new Float32Array( 16 * value.length );
  16305. }
  16306. for ( var i = 0, il = value.length; i < il; i ++ ) {
  16307. value[ i ].flattenToArrayOffset( uniform._array, i * 16 );
  16308. }
  16309. _gl.uniformMatrix4fv( location, false, uniform._array );
  16310. break;
  16311. case 't':
  16312. // single THREE.Texture (2d or cube)
  16313. texture = value;
  16314. textureUnit = getTextureUnit();
  16315. _gl.uniform1i( location, textureUnit );
  16316. if ( ! texture ) continue;
  16317. if ( texture instanceof THREE.CubeTexture ||
  16318. ( Array.isArray( texture.image ) && texture.image.length === 6 ) ) {
  16319. // CompressedTexture can have Array in image :/
  16320. setCubeTexture( texture, textureUnit );
  16321. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16322. setCubeTextureDynamic( texture.texture, textureUnit );
  16323. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  16324. _this.setTexture( texture.texture, textureUnit );
  16325. } else {
  16326. _this.setTexture( texture, textureUnit );
  16327. }
  16328. break;
  16329. case 'tv':
  16330. // array of THREE.Texture (2d or cube)
  16331. if ( uniform._array === undefined ) {
  16332. uniform._array = [];
  16333. }
  16334. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  16335. uniform._array[ i ] = getTextureUnit();
  16336. }
  16337. _gl.uniform1iv( location, uniform._array );
  16338. for ( var i = 0, il = uniform.value.length; i < il; i ++ ) {
  16339. texture = uniform.value[ i ];
  16340. textureUnit = uniform._array[ i ];
  16341. if ( ! texture ) continue;
  16342. if ( texture instanceof THREE.CubeTexture ||
  16343. ( texture.image instanceof Array && texture.image.length === 6 ) ) {
  16344. // CompressedTexture can have Array in image :/
  16345. setCubeTexture( texture, textureUnit );
  16346. } else if ( texture instanceof THREE.WebGLRenderTarget ) {
  16347. _this.setTexture( texture.texture, textureUnit );
  16348. } else if ( texture instanceof THREE.WebGLRenderTargetCube ) {
  16349. setCubeTextureDynamic( texture.texture, textureUnit );
  16350. } else {
  16351. _this.setTexture( texture, textureUnit );
  16352. }
  16353. }
  16354. break;
  16355. default:
  16356. console.warn( 'THREE.WebGLRenderer: Unknown uniform type: ' + type );
  16357. }
  16358. }
  16359. }
  16360. function setupLights ( lights, camera ) {
  16361. var l, ll, light,
  16362. r = 0, g = 0, b = 0,
  16363. color,
  16364. intensity,
  16365. distance,
  16366. viewMatrix = camera.matrixWorldInverse,
  16367. directionalLength = 0,
  16368. pointLength = 0,
  16369. spotLength = 0,
  16370. hemiLength = 0,
  16371. shadowsLength = 0;
  16372. _lights.shadowsPointLight = 0;
  16373. for ( l = 0, ll = lights.length; l < ll; l ++ ) {
  16374. light = lights[ l ];
  16375. color = light.color;
  16376. intensity = light.intensity;
  16377. distance = light.distance;
  16378. if ( light instanceof THREE.AmbientLight ) {
  16379. r += color.r * intensity;
  16380. g += color.g * intensity;
  16381. b += color.b * intensity;
  16382. } else if ( light instanceof THREE.DirectionalLight ) {
  16383. var uniforms = lightCache.get( light );
  16384. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16385. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16386. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16387. uniforms.direction.sub( _vector3 );
  16388. uniforms.direction.transformDirection( viewMatrix );
  16389. uniforms.shadow = light.castShadow;
  16390. if ( light.castShadow ) {
  16391. uniforms.shadowBias = light.shadow.bias;
  16392. uniforms.shadowRadius = light.shadow.radius;
  16393. uniforms.shadowMapSize = light.shadow.mapSize;
  16394. _lights.shadows[ shadowsLength ++ ] = light;
  16395. }
  16396. _lights.directionalShadowMap[ directionalLength ] = light.shadow.map;
  16397. _lights.directionalShadowMatrix[ directionalLength ] = light.shadow.matrix;
  16398. _lights.directional[ directionalLength ++ ] = uniforms;
  16399. } else if ( light instanceof THREE.SpotLight ) {
  16400. var uniforms = lightCache.get( light );
  16401. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16402. uniforms.position.applyMatrix4( viewMatrix );
  16403. uniforms.color.copy( color ).multiplyScalar( intensity );
  16404. uniforms.distance = distance;
  16405. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16406. _vector3.setFromMatrixPosition( light.target.matrixWorld );
  16407. uniforms.direction.sub( _vector3 );
  16408. uniforms.direction.transformDirection( viewMatrix );
  16409. uniforms.angleCos = Math.cos( light.angle );
  16410. uniforms.penumbra = Math.cos( light.angle ) * light.penumbra;
  16411. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16412. uniforms.shadow = light.castShadow;
  16413. if ( light.castShadow ) {
  16414. uniforms.shadowBias = light.shadow.bias;
  16415. uniforms.shadowRadius = light.shadow.radius;
  16416. uniforms.shadowMapSize = light.shadow.mapSize;
  16417. _lights.shadows[ shadowsLength ++ ] = light;
  16418. }
  16419. _lights.spotShadowMap[ spotLength ] = light.shadow.map;
  16420. _lights.spotShadowMatrix[ spotLength ] = light.shadow.matrix;
  16421. _lights.spot[ spotLength ++ ] = uniforms;
  16422. } else if ( light instanceof THREE.PointLight ) {
  16423. var uniforms = lightCache.get( light );
  16424. uniforms.position.setFromMatrixPosition( light.matrixWorld );
  16425. uniforms.position.applyMatrix4( viewMatrix );
  16426. uniforms.color.copy( light.color ).multiplyScalar( light.intensity );
  16427. uniforms.distance = light.distance;
  16428. uniforms.decay = ( light.distance === 0 ) ? 0.0 : light.decay;
  16429. uniforms.shadow = light.castShadow;
  16430. if ( light.castShadow ) {
  16431. uniforms.shadowBias = light.shadow.bias;
  16432. uniforms.shadowRadius = light.shadow.radius;
  16433. uniforms.shadowMapSize = light.shadow.mapSize;
  16434. _lights.shadows[ shadowsLength ++ ] = light;
  16435. }
  16436. _lights.pointShadowMap[ pointLength ] = light.shadow.map;
  16437. if ( _lights.pointShadowMatrix[ pointLength ] === undefined ) {
  16438. _lights.pointShadowMatrix[ pointLength ] = new THREE.Matrix4();
  16439. }
  16440. // for point lights we set the shadow matrix to be a translation-only matrix
  16441. // equal to inverse of the light's position
  16442. _vector3.setFromMatrixPosition( light.matrixWorld ).negate();
  16443. _lights.pointShadowMatrix[ pointLength ].identity().setPosition( _vector3 );
  16444. _lights.point[ pointLength ++ ] = uniforms;
  16445. } else if ( light instanceof THREE.HemisphereLight ) {
  16446. var uniforms = lightCache.get( light );
  16447. uniforms.direction.setFromMatrixPosition( light.matrixWorld );
  16448. uniforms.direction.transformDirection( viewMatrix );
  16449. uniforms.direction.normalize();
  16450. uniforms.skyColor.copy( light.color ).multiplyScalar( intensity );
  16451. uniforms.groundColor.copy( light.groundColor ).multiplyScalar( intensity );
  16452. _lights.hemi[ hemiLength ++ ] = uniforms;
  16453. }
  16454. }
  16455. _lights.ambient[ 0 ] = r;
  16456. _lights.ambient[ 1 ] = g;
  16457. _lights.ambient[ 2 ] = b;
  16458. _lights.directional.length = directionalLength;
  16459. _lights.spot.length = spotLength;
  16460. _lights.point.length = pointLength;
  16461. _lights.hemi.length = hemiLength;
  16462. _lights.shadows.length = shadowsLength;
  16463. _lights.hash = directionalLength + ',' + pointLength + ',' + spotLength + ',' + hemiLength + ',' + shadowsLength;
  16464. }
  16465. // GL state setting
  16466. this.setFaceCulling = function ( cullFace, frontFaceDirection ) {
  16467. if ( cullFace === THREE.CullFaceNone ) {
  16468. state.disable( _gl.CULL_FACE );
  16469. } else {
  16470. if ( frontFaceDirection === THREE.FrontFaceDirectionCW ) {
  16471. _gl.frontFace( _gl.CW );
  16472. } else {
  16473. _gl.frontFace( _gl.CCW );
  16474. }
  16475. if ( cullFace === THREE.CullFaceBack ) {
  16476. _gl.cullFace( _gl.BACK );
  16477. } else if ( cullFace === THREE.CullFaceFront ) {
  16478. _gl.cullFace( _gl.FRONT );
  16479. } else {
  16480. _gl.cullFace( _gl.FRONT_AND_BACK );
  16481. }
  16482. state.enable( _gl.CULL_FACE );
  16483. }
  16484. };
  16485. // Textures
  16486. function setTextureParameters ( textureType, texture, isPowerOfTwoImage ) {
  16487. var extension;
  16488. if ( isPowerOfTwoImage ) {
  16489. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, paramThreeToGL( texture.wrapS ) );
  16490. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, paramThreeToGL( texture.wrapT ) );
  16491. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, paramThreeToGL( texture.magFilter ) );
  16492. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, paramThreeToGL( texture.minFilter ) );
  16493. } else {
  16494. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_S, _gl.CLAMP_TO_EDGE );
  16495. _gl.texParameteri( textureType, _gl.TEXTURE_WRAP_T, _gl.CLAMP_TO_EDGE );
  16496. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) {
  16497. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.wrapS and Texture.wrapT should be set to THREE.ClampToEdgeWrapping.', texture );
  16498. }
  16499. _gl.texParameteri( textureType, _gl.TEXTURE_MAG_FILTER, filterFallback( texture.magFilter ) );
  16500. _gl.texParameteri( textureType, _gl.TEXTURE_MIN_FILTER, filterFallback( texture.minFilter ) );
  16501. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) {
  16502. console.warn( 'THREE.WebGLRenderer: Texture is not power of two. Texture.minFilter should be set to THREE.NearestFilter or THREE.LinearFilter.', texture );
  16503. }
  16504. }
  16505. extension = extensions.get( 'EXT_texture_filter_anisotropic' );
  16506. if ( extension ) {
  16507. if ( texture.type === THREE.FloatType && extensions.get( 'OES_texture_float_linear' ) === null ) return;
  16508. if ( texture.type === THREE.HalfFloatType && extensions.get( 'OES_texture_half_float_linear' ) === null ) return;
  16509. if ( texture.anisotropy > 1 || properties.get( texture ).__currentAnisotropy ) {
  16510. _gl.texParameterf( textureType, extension.TEXTURE_MAX_ANISOTROPY_EXT, Math.min( texture.anisotropy, _this.getMaxAnisotropy() ) );
  16511. properties.get( texture ).__currentAnisotropy = texture.anisotropy;
  16512. }
  16513. }
  16514. }
  16515. function uploadTexture( textureProperties, texture, slot ) {
  16516. if ( textureProperties.__webglInit === undefined ) {
  16517. textureProperties.__webglInit = true;
  16518. texture.addEventListener( 'dispose', onTextureDispose );
  16519. textureProperties.__webglTexture = _gl.createTexture();
  16520. _infoMemory.textures ++;
  16521. }
  16522. state.activeTexture( _gl.TEXTURE0 + slot );
  16523. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16524. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16525. _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, texture.premultiplyAlpha );
  16526. _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, texture.unpackAlignment );
  16527. var image = clampToMaxSize( texture.image, capabilities.maxTextureSize );
  16528. if ( textureNeedsPowerOfTwo( texture ) && isPowerOfTwo( image ) === false ) {
  16529. image = makePowerOfTwo( image );
  16530. }
  16531. var isPowerOfTwoImage = isPowerOfTwo( image ),
  16532. glFormat = paramThreeToGL( texture.format ),
  16533. glType = paramThreeToGL( texture.type );
  16534. setTextureParameters( _gl.TEXTURE_2D, texture, isPowerOfTwoImage );
  16535. var mipmap, mipmaps = texture.mipmaps;
  16536. if ( texture instanceof THREE.DataTexture ) {
  16537. // use manually created mipmaps if available
  16538. // if there are no manual mipmaps
  16539. // set 0 level mipmap and then use GL to generate other mipmap levels
  16540. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16541. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16542. mipmap = mipmaps[ i ];
  16543. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16544. }
  16545. texture.generateMipmaps = false;
  16546. } else {
  16547. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, image.width, image.height, 0, glFormat, glType, image.data );
  16548. }
  16549. } else if ( texture instanceof THREE.CompressedTexture ) {
  16550. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16551. mipmap = mipmaps[ i ];
  16552. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16553. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16554. state.compressedTexImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16555. } else {
  16556. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .uploadTexture()" );
  16557. }
  16558. } else {
  16559. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16560. }
  16561. }
  16562. } else {
  16563. // regular Texture (image, video, canvas)
  16564. // use manually created mipmaps if available
  16565. // if there are no manual mipmaps
  16566. // set 0 level mipmap and then use GL to generate other mipmap levels
  16567. if ( mipmaps.length > 0 && isPowerOfTwoImage ) {
  16568. for ( var i = 0, il = mipmaps.length; i < il; i ++ ) {
  16569. mipmap = mipmaps[ i ];
  16570. state.texImage2D( _gl.TEXTURE_2D, i, glFormat, glFormat, glType, mipmap );
  16571. }
  16572. texture.generateMipmaps = false;
  16573. } else {
  16574. state.texImage2D( _gl.TEXTURE_2D, 0, glFormat, glFormat, glType, image );
  16575. }
  16576. }
  16577. if ( texture.generateMipmaps && isPowerOfTwoImage ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16578. textureProperties.__version = texture.version;
  16579. if ( texture.onUpdate ) texture.onUpdate( texture );
  16580. }
  16581. this.setTexture = function ( texture, slot ) {
  16582. var textureProperties = properties.get( texture );
  16583. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16584. var image = texture.image;
  16585. if ( image === undefined ) {
  16586. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is undefined', texture );
  16587. return;
  16588. }
  16589. if ( image.complete === false ) {
  16590. console.warn( 'THREE.WebGLRenderer: Texture marked for update but image is incomplete', texture );
  16591. return;
  16592. }
  16593. uploadTexture( textureProperties, texture, slot );
  16594. return;
  16595. }
  16596. state.activeTexture( _gl.TEXTURE0 + slot );
  16597. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16598. };
  16599. function clampToMaxSize ( image, maxSize ) {
  16600. if ( image.width > maxSize || image.height > maxSize ) {
  16601. // Warning: Scaling through the canvas will only work with images that use
  16602. // premultiplied alpha.
  16603. var scale = maxSize / Math.max( image.width, image.height );
  16604. var canvas = document.createElement( 'canvas' );
  16605. canvas.width = Math.floor( image.width * scale );
  16606. canvas.height = Math.floor( image.height * scale );
  16607. var context = canvas.getContext( '2d' );
  16608. context.drawImage( image, 0, 0, image.width, image.height, 0, 0, canvas.width, canvas.height );
  16609. console.warn( 'THREE.WebGLRenderer: image is too big (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16610. return canvas;
  16611. }
  16612. return image;
  16613. }
  16614. function isPowerOfTwo( image ) {
  16615. return THREE.Math.isPowerOfTwo( image.width ) && THREE.Math.isPowerOfTwo( image.height );
  16616. }
  16617. function textureNeedsPowerOfTwo( texture ) {
  16618. if ( texture.wrapS !== THREE.ClampToEdgeWrapping || texture.wrapT !== THREE.ClampToEdgeWrapping ) return true;
  16619. if ( texture.minFilter !== THREE.NearestFilter && texture.minFilter !== THREE.LinearFilter ) return true;
  16620. return false;
  16621. }
  16622. function makePowerOfTwo( image ) {
  16623. if ( image instanceof HTMLImageElement || image instanceof HTMLCanvasElement ) {
  16624. var canvas = document.createElement( 'canvas' );
  16625. canvas.width = THREE.Math.nearestPowerOfTwo( image.width );
  16626. canvas.height = THREE.Math.nearestPowerOfTwo( image.height );
  16627. var context = canvas.getContext( '2d' );
  16628. context.drawImage( image, 0, 0, canvas.width, canvas.height );
  16629. console.warn( 'THREE.WebGLRenderer: image is not power of two (' + image.width + 'x' + image.height + '). Resized to ' + canvas.width + 'x' + canvas.height, image );
  16630. return canvas;
  16631. }
  16632. return image;
  16633. }
  16634. function setCubeTexture ( texture, slot ) {
  16635. var textureProperties = properties.get( texture );
  16636. if ( texture.image.length === 6 ) {
  16637. if ( texture.version > 0 && textureProperties.__version !== texture.version ) {
  16638. if ( ! textureProperties.__image__webglTextureCube ) {
  16639. texture.addEventListener( 'dispose', onTextureDispose );
  16640. textureProperties.__image__webglTextureCube = _gl.createTexture();
  16641. _infoMemory.textures ++;
  16642. }
  16643. state.activeTexture( _gl.TEXTURE0 + slot );
  16644. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16645. _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, texture.flipY );
  16646. var isCompressed = texture instanceof THREE.CompressedTexture;
  16647. var isDataTexture = texture.image[ 0 ] instanceof THREE.DataTexture;
  16648. var cubeImage = [];
  16649. for ( var i = 0; i < 6; i ++ ) {
  16650. if ( _this.autoScaleCubemaps && ! isCompressed && ! isDataTexture ) {
  16651. cubeImage[ i ] = clampToMaxSize( texture.image[ i ], capabilities.maxCubemapSize );
  16652. } else {
  16653. cubeImage[ i ] = isDataTexture ? texture.image[ i ].image : texture.image[ i ];
  16654. }
  16655. }
  16656. var image = cubeImage[ 0 ],
  16657. isPowerOfTwoImage = isPowerOfTwo( image ),
  16658. glFormat = paramThreeToGL( texture.format ),
  16659. glType = paramThreeToGL( texture.type );
  16660. setTextureParameters( _gl.TEXTURE_CUBE_MAP, texture, isPowerOfTwoImage );
  16661. for ( var i = 0; i < 6; i ++ ) {
  16662. if ( ! isCompressed ) {
  16663. if ( isDataTexture ) {
  16664. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, cubeImage[ i ].width, cubeImage[ i ].height, 0, glFormat, glType, cubeImage[ i ].data );
  16665. } else {
  16666. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, glFormat, glFormat, glType, cubeImage[ i ] );
  16667. }
  16668. } else {
  16669. var mipmap, mipmaps = cubeImage[ i ].mipmaps;
  16670. for ( var j = 0, jl = mipmaps.length; j < jl; j ++ ) {
  16671. mipmap = mipmaps[ j ];
  16672. if ( texture.format !== THREE.RGBAFormat && texture.format !== THREE.RGBFormat ) {
  16673. if ( state.getCompressedTextureFormats().indexOf( glFormat ) > - 1 ) {
  16674. state.compressedTexImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, mipmap.data );
  16675. } else {
  16676. console.warn( "THREE.WebGLRenderer: Attempt to load unsupported compressed texture format in .setCubeTexture()" );
  16677. }
  16678. } else {
  16679. state.texImage2D( _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i, j, glFormat, mipmap.width, mipmap.height, 0, glFormat, glType, mipmap.data );
  16680. }
  16681. }
  16682. }
  16683. }
  16684. if ( texture.generateMipmaps && isPowerOfTwoImage ) {
  16685. _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16686. }
  16687. textureProperties.__version = texture.version;
  16688. if ( texture.onUpdate ) texture.onUpdate( texture );
  16689. } else {
  16690. state.activeTexture( _gl.TEXTURE0 + slot );
  16691. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__image__webglTextureCube );
  16692. }
  16693. }
  16694. }
  16695. function setCubeTextureDynamic ( texture, slot ) {
  16696. state.activeTexture( _gl.TEXTURE0 + slot );
  16697. state.bindTexture( _gl.TEXTURE_CUBE_MAP, properties.get( texture ).__webglTexture );
  16698. }
  16699. // Render targets
  16700. // Setup storage for target texture and bind it to correct framebuffer
  16701. function setupFrameBufferTexture ( framebuffer, renderTarget, attachment, textureTarget ) {
  16702. var glFormat = paramThreeToGL( renderTarget.texture.format );
  16703. var glType = paramThreeToGL( renderTarget.texture.type );
  16704. state.texImage2D( textureTarget, 0, glFormat, renderTarget.width, renderTarget.height, 0, glFormat, glType, null );
  16705. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16706. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( renderTarget.texture ).__webglTexture, 0 );
  16707. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16708. }
  16709. // Setup storage for internal depth/stencil buffers and bind to correct framebuffer
  16710. function setupRenderBufferStorage ( renderbuffer, renderTarget ) {
  16711. _gl.bindRenderbuffer( _gl.RENDERBUFFER, renderbuffer );
  16712. if ( renderTarget.depthBuffer && ! renderTarget.stencilBuffer ) {
  16713. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_COMPONENT16, renderTarget.width, renderTarget.height );
  16714. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16715. } else if ( renderTarget.depthBuffer && renderTarget.stencilBuffer ) {
  16716. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.DEPTH_STENCIL, renderTarget.width, renderTarget.height );
  16717. _gl.framebufferRenderbuffer( _gl.FRAMEBUFFER, _gl.DEPTH_STENCIL_ATTACHMENT, _gl.RENDERBUFFER, renderbuffer );
  16718. } else {
  16719. // FIXME: We don't support !depth !stencil
  16720. _gl.renderbufferStorage( _gl.RENDERBUFFER, _gl.RGBA4, renderTarget.width, renderTarget.height );
  16721. }
  16722. _gl.bindRenderbuffer( _gl.RENDERBUFFER, null );
  16723. }
  16724. // Setup GL resources for a non-texture depth buffer
  16725. function setupDepthRenderbuffer( renderTarget ) {
  16726. var renderTargetProperties = properties.get( renderTarget );
  16727. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16728. if ( isCube ) {
  16729. renderTargetProperties.__webglDepthbuffer = [];
  16730. for ( var i = 0; i < 6; i ++ ) {
  16731. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer[ i ] );
  16732. renderTargetProperties.__webglDepthbuffer[ i ] = _gl.createRenderbuffer();
  16733. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer[ i ], renderTarget );
  16734. }
  16735. } else {
  16736. _gl.bindFramebuffer( _gl.FRAMEBUFFER, renderTargetProperties.__webglFramebuffer );
  16737. renderTargetProperties.__webglDepthbuffer = _gl.createRenderbuffer();
  16738. setupRenderBufferStorage( renderTargetProperties.__webglDepthbuffer, renderTarget );
  16739. }
  16740. _gl.bindFramebuffer( _gl.FRAMEBUFFER, null );
  16741. }
  16742. // Set up GL resources for the render target
  16743. function setupRenderTarget( renderTarget ) {
  16744. var renderTargetProperties = properties.get( renderTarget );
  16745. var textureProperties = properties.get( renderTarget.texture );
  16746. renderTarget.addEventListener( 'dispose', onRenderTargetDispose );
  16747. textureProperties.__webglTexture = _gl.createTexture();
  16748. _infoMemory.textures ++;
  16749. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16750. var isTargetPowerOfTwo = THREE.Math.isPowerOfTwo( renderTarget.width ) && THREE.Math.isPowerOfTwo( renderTarget.height );
  16751. // Setup framebuffer
  16752. if ( isCube ) {
  16753. renderTargetProperties.__webglFramebuffer = [];
  16754. for ( var i = 0; i < 6; i ++ ) {
  16755. renderTargetProperties.__webglFramebuffer[ i ] = _gl.createFramebuffer();
  16756. }
  16757. } else {
  16758. renderTargetProperties.__webglFramebuffer = _gl.createFramebuffer();
  16759. }
  16760. // Setup color buffer
  16761. if ( isCube ) {
  16762. state.bindTexture( _gl.TEXTURE_CUBE_MAP, textureProperties.__webglTexture );
  16763. setTextureParameters( _gl.TEXTURE_CUBE_MAP, renderTarget.texture, isTargetPowerOfTwo );
  16764. for ( var i = 0; i < 6; i ++ ) {
  16765. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer[ i ], renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + i );
  16766. }
  16767. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_CUBE_MAP );
  16768. state.bindTexture( _gl.TEXTURE_CUBE_MAP, null );
  16769. } else {
  16770. state.bindTexture( _gl.TEXTURE_2D, textureProperties.__webglTexture );
  16771. setTextureParameters( _gl.TEXTURE_2D, renderTarget.texture, isTargetPowerOfTwo );
  16772. setupFrameBufferTexture( renderTargetProperties.__webglFramebuffer, renderTarget, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D );
  16773. if ( renderTarget.texture.generateMipmaps && isTargetPowerOfTwo ) _gl.generateMipmap( _gl.TEXTURE_2D );
  16774. state.bindTexture( _gl.TEXTURE_2D, null );
  16775. }
  16776. // Setup depth and stencil buffers
  16777. if ( renderTarget.depthBuffer ) {
  16778. setupDepthRenderbuffer( renderTarget );
  16779. }
  16780. }
  16781. this.setRenderTarget = function ( renderTarget ) {
  16782. _currentRenderTarget = renderTarget;
  16783. if ( renderTarget && properties.get( renderTarget ).__webglFramebuffer === undefined ) {
  16784. setupRenderTarget( renderTarget );
  16785. }
  16786. var isCube = ( renderTarget instanceof THREE.WebGLRenderTargetCube );
  16787. var framebuffer;
  16788. if ( renderTarget ) {
  16789. var renderTargetProperties = properties.get( renderTarget );
  16790. if ( isCube ) {
  16791. framebuffer = renderTargetProperties.__webglFramebuffer[ renderTarget.activeCubeFace ];
  16792. } else {
  16793. framebuffer = renderTargetProperties.__webglFramebuffer;
  16794. }
  16795. _currentScissor.copy( renderTarget.scissor );
  16796. _currentScissorTest = renderTarget.scissorTest;
  16797. _currentViewport.copy( renderTarget.viewport );
  16798. } else {
  16799. framebuffer = null;
  16800. _currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio );
  16801. _currentScissorTest = _scissorTest;
  16802. _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio );
  16803. }
  16804. if ( _currentFramebuffer !== framebuffer ) {
  16805. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16806. _currentFramebuffer = framebuffer;
  16807. }
  16808. state.scissor( _currentScissor );
  16809. state.setScissorTest( _currentScissorTest );
  16810. state.viewport( _currentViewport );
  16811. if ( isCube ) {
  16812. var textureProperties = properties.get( renderTarget.texture );
  16813. _gl.framebufferTexture2D( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_CUBE_MAP_POSITIVE_X + renderTarget.activeCubeFace, textureProperties.__webglTexture, 0 );
  16814. }
  16815. };
  16816. this.readRenderTargetPixels = function ( renderTarget, x, y, width, height, buffer ) {
  16817. if ( renderTarget instanceof THREE.WebGLRenderTarget === false ) {
  16818. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.' );
  16819. return;
  16820. }
  16821. var framebuffer = properties.get( renderTarget ).__webglFramebuffer;
  16822. if ( framebuffer ) {
  16823. var restore = false;
  16824. if ( framebuffer !== _currentFramebuffer ) {
  16825. _gl.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
  16826. restore = true;
  16827. }
  16828. try {
  16829. var texture = renderTarget.texture;
  16830. if ( texture.format !== THREE.RGBAFormat
  16831. && paramThreeToGL( texture.format ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_FORMAT ) ) {
  16832. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.' );
  16833. return;
  16834. }
  16835. if ( texture.type !== THREE.UnsignedByteType
  16836. && paramThreeToGL( texture.type ) !== _gl.getParameter( _gl.IMPLEMENTATION_COLOR_READ_TYPE )
  16837. && ! ( texture.type === THREE.FloatType && extensions.get( 'WEBGL_color_buffer_float' ) )
  16838. && ! ( texture.type === THREE.HalfFloatType && extensions.get( 'EXT_color_buffer_half_float' ) ) ) {
  16839. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.' );
  16840. return;
  16841. }
  16842. if ( _gl.checkFramebufferStatus( _gl.FRAMEBUFFER ) === _gl.FRAMEBUFFER_COMPLETE ) {
  16843. _gl.readPixels( x, y, width, height, paramThreeToGL( texture.format ), paramThreeToGL( texture.type ), buffer );
  16844. } else {
  16845. console.error( 'THREE.WebGLRenderer.readRenderTargetPixels: readPixels from renderTarget failed. Framebuffer not complete.' );
  16846. }
  16847. } finally {
  16848. if ( restore ) {
  16849. _gl.bindFramebuffer( _gl.FRAMEBUFFER, _currentFramebuffer );
  16850. }
  16851. }
  16852. }
  16853. };
  16854. function updateRenderTargetMipmap( renderTarget ) {
  16855. var target = renderTarget instanceof THREE.WebGLRenderTargetCube ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
  16856. var texture = properties.get( renderTarget.texture ).__webglTexture;
  16857. state.bindTexture( target, texture );
  16858. _gl.generateMipmap( target );
  16859. state.bindTexture( target, null );
  16860. }
  16861. // Fallback filters for non-power-of-2 textures
  16862. function filterFallback ( f ) {
  16863. if ( f === THREE.NearestFilter || f === THREE.NearestMipMapNearestFilter || f === THREE.NearestMipMapLinearFilter ) {
  16864. return _gl.NEAREST;
  16865. }
  16866. return _gl.LINEAR;
  16867. }
  16868. // Map three.js constants to WebGL constants
  16869. function paramThreeToGL ( p ) {
  16870. var extension;
  16871. if ( p === THREE.RepeatWrapping ) return _gl.REPEAT;
  16872. if ( p === THREE.ClampToEdgeWrapping ) return _gl.CLAMP_TO_EDGE;
  16873. if ( p === THREE.MirroredRepeatWrapping ) return _gl.MIRRORED_REPEAT;
  16874. if ( p === THREE.NearestFilter ) return _gl.NEAREST;
  16875. if ( p === THREE.NearestMipMapNearestFilter ) return _gl.NEAREST_MIPMAP_NEAREST;
  16876. if ( p === THREE.NearestMipMapLinearFilter ) return _gl.NEAREST_MIPMAP_LINEAR;
  16877. if ( p === THREE.LinearFilter ) return _gl.LINEAR;
  16878. if ( p === THREE.LinearMipMapNearestFilter ) return _gl.LINEAR_MIPMAP_NEAREST;
  16879. if ( p === THREE.LinearMipMapLinearFilter ) return _gl.LINEAR_MIPMAP_LINEAR;
  16880. if ( p === THREE.UnsignedByteType ) return _gl.UNSIGNED_BYTE;
  16881. if ( p === THREE.UnsignedShort4444Type ) return _gl.UNSIGNED_SHORT_4_4_4_4;
  16882. if ( p === THREE.UnsignedShort5551Type ) return _gl.UNSIGNED_SHORT_5_5_5_1;
  16883. if ( p === THREE.UnsignedShort565Type ) return _gl.UNSIGNED_SHORT_5_6_5;
  16884. if ( p === THREE.ByteType ) return _gl.BYTE;
  16885. if ( p === THREE.ShortType ) return _gl.SHORT;
  16886. if ( p === THREE.UnsignedShortType ) return _gl.UNSIGNED_SHORT;
  16887. if ( p === THREE.IntType ) return _gl.INT;
  16888. if ( p === THREE.UnsignedIntType ) return _gl.UNSIGNED_INT;
  16889. if ( p === THREE.FloatType ) return _gl.FLOAT;
  16890. extension = extensions.get( 'OES_texture_half_float' );
  16891. if ( extension !== null ) {
  16892. if ( p === THREE.HalfFloatType ) return extension.HALF_FLOAT_OES;
  16893. }
  16894. if ( p === THREE.AlphaFormat ) return _gl.ALPHA;
  16895. if ( p === THREE.RGBFormat ) return _gl.RGB;
  16896. if ( p === THREE.RGBAFormat ) return _gl.RGBA;
  16897. if ( p === THREE.LuminanceFormat ) return _gl.LUMINANCE;
  16898. if ( p === THREE.LuminanceAlphaFormat ) return _gl.LUMINANCE_ALPHA;
  16899. if ( p === THREE.AddEquation ) return _gl.FUNC_ADD;
  16900. if ( p === THREE.SubtractEquation ) return _gl.FUNC_SUBTRACT;
  16901. if ( p === THREE.ReverseSubtractEquation ) return _gl.FUNC_REVERSE_SUBTRACT;
  16902. if ( p === THREE.ZeroFactor ) return _gl.ZERO;
  16903. if ( p === THREE.OneFactor ) return _gl.ONE;
  16904. if ( p === THREE.SrcColorFactor ) return _gl.SRC_COLOR;
  16905. if ( p === THREE.OneMinusSrcColorFactor ) return _gl.ONE_MINUS_SRC_COLOR;
  16906. if ( p === THREE.SrcAlphaFactor ) return _gl.SRC_ALPHA;
  16907. if ( p === THREE.OneMinusSrcAlphaFactor ) return _gl.ONE_MINUS_SRC_ALPHA;
  16908. if ( p === THREE.DstAlphaFactor ) return _gl.DST_ALPHA;
  16909. if ( p === THREE.OneMinusDstAlphaFactor ) return _gl.ONE_MINUS_DST_ALPHA;
  16910. if ( p === THREE.DstColorFactor ) return _gl.DST_COLOR;
  16911. if ( p === THREE.OneMinusDstColorFactor ) return _gl.ONE_MINUS_DST_COLOR;
  16912. if ( p === THREE.SrcAlphaSaturateFactor ) return _gl.SRC_ALPHA_SATURATE;
  16913. extension = extensions.get( 'WEBGL_compressed_texture_s3tc' );
  16914. if ( extension !== null ) {
  16915. if ( p === THREE.RGB_S3TC_DXT1_Format ) return extension.COMPRESSED_RGB_S3TC_DXT1_EXT;
  16916. if ( p === THREE.RGBA_S3TC_DXT1_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT1_EXT;
  16917. if ( p === THREE.RGBA_S3TC_DXT3_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT3_EXT;
  16918. if ( p === THREE.RGBA_S3TC_DXT5_Format ) return extension.COMPRESSED_RGBA_S3TC_DXT5_EXT;
  16919. }
  16920. extension = extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  16921. if ( extension !== null ) {
  16922. if ( p === THREE.RGB_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_4BPPV1_IMG;
  16923. if ( p === THREE.RGB_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGB_PVRTC_2BPPV1_IMG;
  16924. if ( p === THREE.RGBA_PVRTC_4BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG;
  16925. if ( p === THREE.RGBA_PVRTC_2BPPV1_Format ) return extension.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG;
  16926. }
  16927. extension = extensions.get( 'WEBGL_compressed_texture_etc1' );
  16928. if ( extension !== null ) {
  16929. if ( p === THREE.RGB_ETC1_Format ) return extension.COMPRESSED_RGB_ETC1_WEBGL;
  16930. }
  16931. extension = extensions.get( 'EXT_blend_minmax' );
  16932. if ( extension !== null ) {
  16933. if ( p === THREE.MinEquation ) return extension.MIN_EXT;
  16934. if ( p === THREE.MaxEquation ) return extension.MAX_EXT;
  16935. }
  16936. return 0;
  16937. }
  16938. };
  16939. // File:src/renderers/WebGLRenderTarget.js
  16940. /**
  16941. * @author szimek / https://github.com/szimek/
  16942. * @author alteredq / http://alteredqualia.com/
  16943. * @author Marius Kintel / https://github.com/kintel
  16944. */
  16945. /*
  16946. In options, we can specify:
  16947. * Texture parameters for an auto-generated target texture
  16948. * depthBuffer/stencilBuffer: Booleans to indicate if we should generate these buffers
  16949. */
  16950. THREE.WebGLRenderTarget = function ( width, height, options ) {
  16951. this.uuid = THREE.Math.generateUUID();
  16952. this.width = width;
  16953. this.height = height;
  16954. this.scissor = new THREE.Vector4( 0, 0, width, height );
  16955. this.scissorTest = false;
  16956. this.viewport = new THREE.Vector4( 0, 0, width, height );
  16957. options = options || {};
  16958. if ( options.minFilter === undefined ) options.minFilter = THREE.LinearFilter;
  16959. this.texture = new THREE.Texture( undefined, undefined, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy );
  16960. this.depthBuffer = options.depthBuffer !== undefined ? options.depthBuffer : true;
  16961. this.stencilBuffer = options.stencilBuffer !== undefined ? options.stencilBuffer : true;
  16962. };
  16963. THREE.WebGLRenderTarget.prototype = {
  16964. constructor: THREE.WebGLRenderTarget,
  16965. setSize: function ( width, height ) {
  16966. if ( this.width !== width || this.height !== height ) {
  16967. this.width = width;
  16968. this.height = height;
  16969. this.dispose();
  16970. }
  16971. this.viewport.set( 0, 0, width, height );
  16972. this.scissor.set( 0, 0, width, height );
  16973. },
  16974. clone: function () {
  16975. return new this.constructor().copy( this );
  16976. },
  16977. copy: function ( source ) {
  16978. this.width = source.width;
  16979. this.height = source.height;
  16980. this.viewport.copy( source.viewport );
  16981. this.texture = source.texture.clone();
  16982. this.depthBuffer = source.depthBuffer;
  16983. this.stencilBuffer = source.stencilBuffer;
  16984. this.shareDepthFrom = source.shareDepthFrom;
  16985. return this;
  16986. },
  16987. dispose: function () {
  16988. this.dispatchEvent( { type: 'dispose' } );
  16989. }
  16990. };
  16991. THREE.EventDispatcher.prototype.apply( THREE.WebGLRenderTarget.prototype );
  16992. // File:src/renderers/WebGLRenderTargetCube.js
  16993. /**
  16994. * @author alteredq / http://alteredqualia.com
  16995. */
  16996. THREE.WebGLRenderTargetCube = function ( width, height, options ) {
  16997. THREE.WebGLRenderTarget.call( this, width, height, options );
  16998. this.activeCubeFace = 0; // PX 0, NX 1, PY 2, NY 3, PZ 4, NZ 5
  16999. };
  17000. THREE.WebGLRenderTargetCube.prototype = Object.create( THREE.WebGLRenderTarget.prototype );
  17001. THREE.WebGLRenderTargetCube.prototype.constructor = THREE.WebGLRenderTargetCube;
  17002. // File:src/renderers/webgl/WebGLBufferRenderer.js
  17003. /**
  17004. * @author mrdoob / http://mrdoob.com/
  17005. */
  17006. THREE.WebGLBufferRenderer = function ( _gl, extensions, _infoRender ) {
  17007. var mode;
  17008. function setMode( value ) {
  17009. mode = value;
  17010. }
  17011. function render( start, count ) {
  17012. _gl.drawArrays( mode, start, count );
  17013. _infoRender.calls ++;
  17014. _infoRender.vertices += count;
  17015. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  17016. }
  17017. function renderInstances( geometry ) {
  17018. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17019. if ( extension === null ) {
  17020. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  17021. return;
  17022. }
  17023. var position = geometry.attributes.position;
  17024. var count = 0;
  17025. if ( position instanceof THREE.InterleavedBufferAttribute ) {
  17026. count = position.data.count;
  17027. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  17028. } else {
  17029. count = position.count;
  17030. extension.drawArraysInstancedANGLE( mode, 0, count, geometry.maxInstancedCount );
  17031. }
  17032. _infoRender.calls ++;
  17033. _infoRender.vertices += count * geometry.maxInstancedCount;
  17034. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  17035. }
  17036. this.setMode = setMode;
  17037. this.render = render;
  17038. this.renderInstances = renderInstances;
  17039. };
  17040. // File:src/renderers/webgl/WebGLIndexedBufferRenderer.js
  17041. /**
  17042. * @author mrdoob / http://mrdoob.com/
  17043. */
  17044. THREE.WebGLIndexedBufferRenderer = function ( _gl, extensions, _infoRender ) {
  17045. var mode;
  17046. function setMode( value ) {
  17047. mode = value;
  17048. }
  17049. var type, size;
  17050. function setIndex( index ) {
  17051. if ( index.array instanceof Uint32Array && extensions.get( 'OES_element_index_uint' ) ) {
  17052. type = _gl.UNSIGNED_INT;
  17053. size = 4;
  17054. } else {
  17055. type = _gl.UNSIGNED_SHORT;
  17056. size = 2;
  17057. }
  17058. }
  17059. function render( start, count ) {
  17060. _gl.drawElements( mode, count, type, start * size );
  17061. _infoRender.calls ++;
  17062. _infoRender.vertices += count;
  17063. if ( mode === _gl.TRIANGLES ) _infoRender.faces += count / 3;
  17064. }
  17065. function renderInstances( geometry, start, count ) {
  17066. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  17067. if ( extension === null ) {
  17068. console.error( 'THREE.WebGLBufferRenderer: using THREE.InstancedBufferGeometry but hardware does not support extension ANGLE_instanced_arrays.' );
  17069. return;
  17070. }
  17071. extension.drawElementsInstancedANGLE( mode, count, type, start * size, geometry.maxInstancedCount );
  17072. _infoRender.calls ++;
  17073. _infoRender.vertices += count * geometry.maxInstancedCount;
  17074. if ( mode === _gl.TRIANGLES ) _infoRender.faces += geometry.maxInstancedCount * count / 3;
  17075. }
  17076. this.setMode = setMode;
  17077. this.setIndex = setIndex;
  17078. this.render = render;
  17079. this.renderInstances = renderInstances;
  17080. };
  17081. // File:src/renderers/webgl/WebGLExtensions.js
  17082. /**
  17083. * @author mrdoob / http://mrdoob.com/
  17084. */
  17085. THREE.WebGLExtensions = function ( gl ) {
  17086. var extensions = {};
  17087. this.get = function ( name ) {
  17088. if ( extensions[ name ] !== undefined ) {
  17089. return extensions[ name ];
  17090. }
  17091. var extension;
  17092. switch ( name ) {
  17093. case 'EXT_texture_filter_anisotropic':
  17094. extension = gl.getExtension( 'EXT_texture_filter_anisotropic' ) || gl.getExtension( 'MOZ_EXT_texture_filter_anisotropic' ) || gl.getExtension( 'WEBKIT_EXT_texture_filter_anisotropic' );
  17095. break;
  17096. case 'WEBGL_compressed_texture_s3tc':
  17097. extension = gl.getExtension( 'WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'MOZ_WEBGL_compressed_texture_s3tc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_s3tc' );
  17098. break;
  17099. case 'WEBGL_compressed_texture_pvrtc':
  17100. extension = gl.getExtension( 'WEBGL_compressed_texture_pvrtc' ) || gl.getExtension( 'WEBKIT_WEBGL_compressed_texture_pvrtc' );
  17101. break;
  17102. case 'WEBGL_compressed_texture_etc1':
  17103. extension = gl.getExtension( 'WEBGL_compressed_texture_etc1' );
  17104. break;
  17105. default:
  17106. extension = gl.getExtension( name );
  17107. }
  17108. if ( extension === null ) {
  17109. console.warn( 'THREE.WebGLRenderer: ' + name + ' extension not supported.' );
  17110. }
  17111. extensions[ name ] = extension;
  17112. return extension;
  17113. };
  17114. };
  17115. // File:src/renderers/webgl/WebGLCapabilities.js
  17116. THREE.WebGLCapabilities = function ( gl, extensions, parameters ) {
  17117. function getMaxPrecision( precision ) {
  17118. if ( precision === 'highp' ) {
  17119. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.HIGH_FLOAT ).precision > 0 &&
  17120. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.HIGH_FLOAT ).precision > 0 ) {
  17121. return 'highp';
  17122. }
  17123. precision = 'mediump';
  17124. }
  17125. if ( precision === 'mediump' ) {
  17126. if ( gl.getShaderPrecisionFormat( gl.VERTEX_SHADER, gl.MEDIUM_FLOAT ).precision > 0 &&
  17127. gl.getShaderPrecisionFormat( gl.FRAGMENT_SHADER, gl.MEDIUM_FLOAT ).precision > 0 ) {
  17128. return 'mediump';
  17129. }
  17130. }
  17131. return 'lowp';
  17132. }
  17133. this.getMaxPrecision = getMaxPrecision;
  17134. this.precision = parameters.precision !== undefined ? parameters.precision : 'highp',
  17135. this.logarithmicDepthBuffer = parameters.logarithmicDepthBuffer !== undefined ? parameters.logarithmicDepthBuffer : false;
  17136. this.maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  17137. this.maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
  17138. this.maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
  17139. this.maxCubemapSize = gl.getParameter( gl.MAX_CUBE_MAP_TEXTURE_SIZE );
  17140. this.maxAttributes = gl.getParameter( gl.MAX_VERTEX_ATTRIBS );
  17141. this.maxVertexUniforms = gl.getParameter( gl.MAX_VERTEX_UNIFORM_VECTORS );
  17142. this.maxVaryings = gl.getParameter( gl.MAX_VARYING_VECTORS );
  17143. this.maxFragmentUniforms = gl.getParameter( gl.MAX_FRAGMENT_UNIFORM_VECTORS );
  17144. this.vertexTextures = this.maxVertexTextures > 0;
  17145. this.floatFragmentTextures = !! extensions.get( 'OES_texture_float' );
  17146. this.floatVertexTextures = this.vertexTextures && this.floatFragmentTextures;
  17147. var _maxPrecision = getMaxPrecision( this.precision );
  17148. if ( _maxPrecision !== this.precision ) {
  17149. console.warn( 'THREE.WebGLRenderer:', this.precision, 'not supported, using', _maxPrecision, 'instead.' );
  17150. this.precision = _maxPrecision;
  17151. }
  17152. if ( this.logarithmicDepthBuffer ) {
  17153. this.logarithmicDepthBuffer = !! extensions.get( 'EXT_frag_depth' );
  17154. }
  17155. };
  17156. // File:src/renderers/webgl/WebGLGeometries.js
  17157. /**
  17158. * @author mrdoob / http://mrdoob.com/
  17159. */
  17160. THREE.WebGLGeometries = function ( gl, properties, info ) {
  17161. var geometries = {};
  17162. function get( object ) {
  17163. var geometry = object.geometry;
  17164. if ( geometries[ geometry.id ] !== undefined ) {
  17165. return geometries[ geometry.id ];
  17166. }
  17167. geometry.addEventListener( 'dispose', onGeometryDispose );
  17168. var buffergeometry;
  17169. if ( geometry instanceof THREE.BufferGeometry ) {
  17170. buffergeometry = geometry;
  17171. } else if ( geometry instanceof THREE.Geometry ) {
  17172. if ( geometry._bufferGeometry === undefined ) {
  17173. geometry._bufferGeometry = new THREE.BufferGeometry().setFromObject( object );
  17174. }
  17175. buffergeometry = geometry._bufferGeometry;
  17176. }
  17177. geometries[ geometry.id ] = buffergeometry;
  17178. info.memory.geometries ++;
  17179. return buffergeometry;
  17180. }
  17181. function onGeometryDispose( event ) {
  17182. var geometry = event.target;
  17183. var buffergeometry = geometries[ geometry.id ];
  17184. if ( buffergeometry.index !== null ) {
  17185. deleteAttribute( buffergeometry.index );
  17186. }
  17187. deleteAttributes( buffergeometry.attributes );
  17188. geometry.removeEventListener( 'dispose', onGeometryDispose );
  17189. delete geometries[ geometry.id ];
  17190. // TODO
  17191. var property = properties.get( geometry );
  17192. if ( property.wireframe ) {
  17193. deleteAttribute( property.wireframe );
  17194. }
  17195. properties.delete( geometry );
  17196. var bufferproperty = properties.get( buffergeometry );
  17197. if ( bufferproperty.wireframe ) {
  17198. deleteAttribute( bufferproperty.wireframe );
  17199. }
  17200. properties.delete( buffergeometry );
  17201. //
  17202. info.memory.geometries --;
  17203. }
  17204. function getAttributeBuffer( attribute ) {
  17205. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17206. return properties.get( attribute.data ).__webglBuffer;
  17207. }
  17208. return properties.get( attribute ).__webglBuffer;
  17209. }
  17210. function deleteAttribute( attribute ) {
  17211. var buffer = getAttributeBuffer( attribute );
  17212. if ( buffer !== undefined ) {
  17213. gl.deleteBuffer( buffer );
  17214. removeAttributeBuffer( attribute );
  17215. }
  17216. }
  17217. function deleteAttributes( attributes ) {
  17218. for ( var name in attributes ) {
  17219. deleteAttribute( attributes[ name ] );
  17220. }
  17221. }
  17222. function removeAttributeBuffer( attribute ) {
  17223. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17224. properties.delete( attribute.data );
  17225. } else {
  17226. properties.delete( attribute );
  17227. }
  17228. }
  17229. this.get = get;
  17230. };
  17231. // File:src/renderers/webgl/WebGLLights.js
  17232. /**
  17233. * @author mrdoob / http://mrdoob.com/
  17234. */
  17235. THREE.WebGLLights = function () {
  17236. var lights = {};
  17237. this.get = function ( light ) {
  17238. if ( lights[ light.id ] !== undefined ) {
  17239. return lights[ light.id ];
  17240. }
  17241. var uniforms;
  17242. switch ( light.type ) {
  17243. case 'DirectionalLight':
  17244. uniforms = {
  17245. direction: new THREE.Vector3(),
  17246. color: new THREE.Color(),
  17247. shadow: false,
  17248. shadowBias: 0,
  17249. shadowRadius: 1,
  17250. shadowMapSize: new THREE.Vector2()
  17251. };
  17252. break;
  17253. case 'SpotLight':
  17254. uniforms = {
  17255. position: new THREE.Vector3(),
  17256. direction: new THREE.Vector3(),
  17257. color: new THREE.Color(),
  17258. distance: 0,
  17259. angleCos: 0,
  17260. penumbra: 0,
  17261. decay: 0,
  17262. shadow: false,
  17263. shadowBias: 0,
  17264. shadowRadius: 1,
  17265. shadowMapSize: new THREE.Vector2()
  17266. };
  17267. break;
  17268. case 'PointLight':
  17269. uniforms = {
  17270. position: new THREE.Vector3(),
  17271. color: new THREE.Color(),
  17272. distance: 0,
  17273. decay: 0,
  17274. shadow: false,
  17275. shadowBias: 0,
  17276. shadowRadius: 1,
  17277. shadowMapSize: new THREE.Vector2()
  17278. };
  17279. break;
  17280. case 'HemisphereLight':
  17281. uniforms = {
  17282. direction: new THREE.Vector3(),
  17283. skyColor: new THREE.Color(),
  17284. groundColor: new THREE.Color()
  17285. };
  17286. break;
  17287. }
  17288. lights[ light.id ] = uniforms;
  17289. return uniforms;
  17290. };
  17291. };
  17292. // File:src/renderers/webgl/WebGLObjects.js
  17293. /**
  17294. * @author mrdoob / http://mrdoob.com/
  17295. */
  17296. THREE.WebGLObjects = function ( gl, properties, info ) {
  17297. var geometries = new THREE.WebGLGeometries( gl, properties, info );
  17298. //
  17299. function update( object ) {
  17300. // TODO: Avoid updating twice (when using shadowMap). Maybe add frame counter.
  17301. var geometry = geometries.get( object );
  17302. if ( object.geometry instanceof THREE.Geometry ) {
  17303. geometry.updateFromObject( object );
  17304. }
  17305. var index = geometry.index;
  17306. var attributes = geometry.attributes;
  17307. if ( index !== null ) {
  17308. updateAttribute( index, gl.ELEMENT_ARRAY_BUFFER );
  17309. }
  17310. for ( var name in attributes ) {
  17311. updateAttribute( attributes[ name ], gl.ARRAY_BUFFER );
  17312. }
  17313. // morph targets
  17314. var morphAttributes = geometry.morphAttributes;
  17315. for ( var name in morphAttributes ) {
  17316. var array = morphAttributes[ name ];
  17317. for ( var i = 0, l = array.length; i < l; i ++ ) {
  17318. updateAttribute( array[ i ], gl.ARRAY_BUFFER );
  17319. }
  17320. }
  17321. return geometry;
  17322. }
  17323. function updateAttribute( attribute, bufferType ) {
  17324. var data = ( attribute instanceof THREE.InterleavedBufferAttribute ) ? attribute.data : attribute;
  17325. var attributeProperties = properties.get( data );
  17326. if ( attributeProperties.__webglBuffer === undefined ) {
  17327. createBuffer( attributeProperties, data, bufferType );
  17328. } else if ( attributeProperties.version !== data.version ) {
  17329. updateBuffer( attributeProperties, data, bufferType );
  17330. }
  17331. }
  17332. function createBuffer( attributeProperties, data, bufferType ) {
  17333. attributeProperties.__webglBuffer = gl.createBuffer();
  17334. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17335. var usage = data.dynamic ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW;
  17336. gl.bufferData( bufferType, data.array, usage );
  17337. attributeProperties.version = data.version;
  17338. }
  17339. function updateBuffer( attributeProperties, data, bufferType ) {
  17340. gl.bindBuffer( bufferType, attributeProperties.__webglBuffer );
  17341. if ( data.dynamic === false || data.updateRange.count === - 1 ) {
  17342. // Not using update ranges
  17343. gl.bufferSubData( bufferType, 0, data.array );
  17344. } else if ( data.updateRange.count === 0 ) {
  17345. 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.' );
  17346. } else {
  17347. gl.bufferSubData( bufferType, data.updateRange.offset * data.array.BYTES_PER_ELEMENT,
  17348. data.array.subarray( data.updateRange.offset, data.updateRange.offset + data.updateRange.count ) );
  17349. data.updateRange.count = 0; // reset range
  17350. }
  17351. attributeProperties.version = data.version;
  17352. }
  17353. function getAttributeBuffer( attribute ) {
  17354. if ( attribute instanceof THREE.InterleavedBufferAttribute ) {
  17355. return properties.get( attribute.data ).__webglBuffer;
  17356. }
  17357. return properties.get( attribute ).__webglBuffer;
  17358. }
  17359. function getWireframeAttribute( geometry ) {
  17360. var property = properties.get( geometry );
  17361. if ( property.wireframe !== undefined ) {
  17362. return property.wireframe;
  17363. }
  17364. var indices = [];
  17365. var index = geometry.index;
  17366. var attributes = geometry.attributes;
  17367. var position = attributes.position;
  17368. // console.time( 'wireframe' );
  17369. if ( index !== null ) {
  17370. var edges = {};
  17371. var array = index.array;
  17372. for ( var i = 0, l = array.length; i < l; i += 3 ) {
  17373. var a = array[ i + 0 ];
  17374. var b = array[ i + 1 ];
  17375. var c = array[ i + 2 ];
  17376. if ( checkEdge( edges, a, b ) ) indices.push( a, b );
  17377. if ( checkEdge( edges, b, c ) ) indices.push( b, c );
  17378. if ( checkEdge( edges, c, a ) ) indices.push( c, a );
  17379. }
  17380. } else {
  17381. var array = attributes.position.array;
  17382. for ( var i = 0, l = ( array.length / 3 ) - 1; i < l; i += 3 ) {
  17383. var a = i + 0;
  17384. var b = i + 1;
  17385. var c = i + 2;
  17386. indices.push( a, b, b, c, c, a );
  17387. }
  17388. }
  17389. // console.timeEnd( 'wireframe' );
  17390. var TypeArray = position.count > 65535 ? Uint32Array : Uint16Array;
  17391. var attribute = new THREE.BufferAttribute( new TypeArray( indices ), 1 );
  17392. updateAttribute( attribute, gl.ELEMENT_ARRAY_BUFFER );
  17393. property.wireframe = attribute;
  17394. return attribute;
  17395. }
  17396. function checkEdge( edges, a, b ) {
  17397. if ( a > b ) {
  17398. var tmp = a;
  17399. a = b;
  17400. b = tmp;
  17401. }
  17402. var list = edges[ a ];
  17403. if ( list === undefined ) {
  17404. edges[ a ] = [ b ];
  17405. return true;
  17406. } else if ( list.indexOf( b ) === -1 ) {
  17407. list.push( b );
  17408. return true;
  17409. }
  17410. return false;
  17411. }
  17412. this.getAttributeBuffer = getAttributeBuffer;
  17413. this.getWireframeAttribute = getWireframeAttribute;
  17414. this.update = update;
  17415. };
  17416. // File:src/renderers/webgl/WebGLProgram.js
  17417. THREE.WebGLProgram = ( function () {
  17418. var programIdCount = 0;
  17419. // TODO: Combine the regex
  17420. var structRe = /^([\w\d_]+)\.([\w\d_]+)$/;
  17421. var arrayStructRe = /^([\w\d_]+)\[(\d+)\]\.([\w\d_]+)$/;
  17422. var arrayRe = /^([\w\d_]+)\[0\]$/;
  17423. function generateExtensions( extensions, parameters, rendererExtensions ) {
  17424. extensions = extensions || {};
  17425. var chunks = [
  17426. ( extensions.derivatives || parameters.bumpMap || parameters.normalMap || parameters.flatShading ) ? '#extension GL_OES_standard_derivatives : enable' : '',
  17427. ( extensions.fragDepth || parameters.logarithmicDepthBuffer ) && rendererExtensions.get( 'EXT_frag_depth' ) ? '#extension GL_EXT_frag_depth : enable' : '',
  17428. ( extensions.drawBuffers ) && rendererExtensions.get( 'WEBGL_draw_buffers' ) ? '#extension GL_EXT_draw_buffers : require' : '',
  17429. ( extensions.shaderTextureLOD || parameters.envMap ) && rendererExtensions.get( 'EXT_shader_texture_lod' ) ? '#extension GL_EXT_shader_texture_lod : enable' : '',
  17430. ];
  17431. return chunks.filter( filterEmptyLine ).join( '\n' );
  17432. }
  17433. function generateDefines( defines ) {
  17434. var chunks = [];
  17435. for ( var name in defines ) {
  17436. var value = defines[ name ];
  17437. if ( value === false ) continue;
  17438. chunks.push( '#define ' + name + ' ' + value );
  17439. }
  17440. return chunks.join( '\n' );
  17441. }
  17442. function fetchUniformLocations( gl, program, identifiers ) {
  17443. var uniforms = {};
  17444. var n = gl.getProgramParameter( program, gl.ACTIVE_UNIFORMS );
  17445. for ( var i = 0; i < n; i ++ ) {
  17446. var info = gl.getActiveUniform( program, i );
  17447. var name = info.name;
  17448. var location = gl.getUniformLocation( program, name );
  17449. //console.log("THREE.WebGLProgram: ACTIVE UNIFORM:", name);
  17450. var matches = structRe.exec( name );
  17451. if ( matches ) {
  17452. var structName = matches[ 1 ];
  17453. var structProperty = matches[ 2 ];
  17454. var uniformsStruct = uniforms[ structName ];
  17455. if ( ! uniformsStruct ) {
  17456. uniformsStruct = uniforms[ structName ] = {};
  17457. }
  17458. uniformsStruct[ structProperty ] = location;
  17459. continue;
  17460. }
  17461. matches = arrayStructRe.exec( name );
  17462. if ( matches ) {
  17463. var arrayName = matches[ 1 ];
  17464. var arrayIndex = matches[ 2 ];
  17465. var arrayProperty = matches[ 3 ];
  17466. var uniformsArray = uniforms[ arrayName ];
  17467. if ( ! uniformsArray ) {
  17468. uniformsArray = uniforms[ arrayName ] = [];
  17469. }
  17470. var uniformsArrayIndex = uniformsArray[ arrayIndex ];
  17471. if ( ! uniformsArrayIndex ) {
  17472. uniformsArrayIndex = uniformsArray[ arrayIndex ] = {};
  17473. }
  17474. uniformsArrayIndex[ arrayProperty ] = location;
  17475. continue;
  17476. }
  17477. matches = arrayRe.exec( name );
  17478. if ( matches ) {
  17479. var arrayName = matches[ 1 ];
  17480. uniforms[ arrayName ] = location;
  17481. continue;
  17482. }
  17483. uniforms[ name ] = location;
  17484. }
  17485. return uniforms;
  17486. }
  17487. function fetchAttributeLocations( gl, program, identifiers ) {
  17488. var attributes = {};
  17489. var n = gl.getProgramParameter( program, gl.ACTIVE_ATTRIBUTES );
  17490. for ( var i = 0; i < n; i ++ ) {
  17491. var info = gl.getActiveAttrib( program, i );
  17492. var name = info.name;
  17493. // console.log("THREE.WebGLProgram: ACTIVE VERTEX ATTRIBUTE:", name, i );
  17494. attributes[ name ] = gl.getAttribLocation( program, name );
  17495. }
  17496. return attributes;
  17497. }
  17498. function filterEmptyLine( string ) {
  17499. return string !== '';
  17500. }
  17501. function replaceLightNums( string, parameters ) {
  17502. return string
  17503. .replace( /NUM_DIR_LIGHTS/g, parameters.numDirLights )
  17504. .replace( /NUM_SPOT_LIGHTS/g, parameters.numSpotLights )
  17505. .replace( /NUM_POINT_LIGHTS/g, parameters.numPointLights )
  17506. .replace( /NUM_HEMI_LIGHTS/g, parameters.numHemiLights );
  17507. }
  17508. function unrollLoops( string ) {
  17509. var pattern = /for \( int i \= (\d+)\; i < (\d+)\; i \+\+ \) \{([\s\S]+?)(?=\})\}/g;
  17510. function replace( match, start, end, snippet ) {
  17511. var unroll = '';
  17512. for ( var i = parseInt( start ); i < parseInt( end ); i ++ ) {
  17513. unroll += snippet.replace( /\[ i \]/g, '[ ' + i + ' ]' );
  17514. }
  17515. return unroll;
  17516. }
  17517. return string.replace( pattern, replace );
  17518. }
  17519. return function WebGLProgram( renderer, code, material, parameters ) {
  17520. var gl = renderer.context;
  17521. var extensions = material.extensions;
  17522. var defines = material.defines;
  17523. var vertexShader = material.__webglShader.vertexShader;
  17524. var fragmentShader = material.__webglShader.fragmentShader;
  17525. var shadowMapTypeDefine = 'SHADOWMAP_TYPE_BASIC';
  17526. if ( parameters.shadowMapType === THREE.PCFShadowMap ) {
  17527. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF';
  17528. } else if ( parameters.shadowMapType === THREE.PCFSoftShadowMap ) {
  17529. shadowMapTypeDefine = 'SHADOWMAP_TYPE_PCF_SOFT';
  17530. }
  17531. var envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17532. var envMapModeDefine = 'ENVMAP_MODE_REFLECTION';
  17533. var envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17534. if ( parameters.envMap ) {
  17535. switch ( material.envMap.mapping ) {
  17536. case THREE.CubeReflectionMapping:
  17537. case THREE.CubeRefractionMapping:
  17538. envMapTypeDefine = 'ENVMAP_TYPE_CUBE';
  17539. break;
  17540. case THREE.EquirectangularReflectionMapping:
  17541. case THREE.EquirectangularRefractionMapping:
  17542. envMapTypeDefine = 'ENVMAP_TYPE_EQUIREC';
  17543. break;
  17544. case THREE.SphericalReflectionMapping:
  17545. envMapTypeDefine = 'ENVMAP_TYPE_SPHERE';
  17546. break;
  17547. }
  17548. switch ( material.envMap.mapping ) {
  17549. case THREE.CubeRefractionMapping:
  17550. case THREE.EquirectangularRefractionMapping:
  17551. envMapModeDefine = 'ENVMAP_MODE_REFRACTION';
  17552. break;
  17553. }
  17554. switch ( material.combine ) {
  17555. case THREE.MultiplyOperation:
  17556. envMapBlendingDefine = 'ENVMAP_BLENDING_MULTIPLY';
  17557. break;
  17558. case THREE.MixOperation:
  17559. envMapBlendingDefine = 'ENVMAP_BLENDING_MIX';
  17560. break;
  17561. case THREE.AddOperation:
  17562. envMapBlendingDefine = 'ENVMAP_BLENDING_ADD';
  17563. break;
  17564. }
  17565. }
  17566. var gammaFactorDefine = ( renderer.gammaFactor > 0 ) ? renderer.gammaFactor : 1.0;
  17567. // console.log( 'building new program ' );
  17568. //
  17569. var customExtensions = generateExtensions( extensions, parameters, renderer.extensions );
  17570. var customDefines = generateDefines( defines );
  17571. //
  17572. var program = gl.createProgram();
  17573. var prefixVertex, prefixFragment;
  17574. if ( material instanceof THREE.RawShaderMaterial ) {
  17575. prefixVertex = '';
  17576. prefixFragment = '';
  17577. } else {
  17578. prefixVertex = [
  17579. 'precision ' + parameters.precision + ' float;',
  17580. 'precision ' + parameters.precision + ' int;',
  17581. '#define SHADER_NAME ' + material.__webglShader.name,
  17582. customDefines,
  17583. parameters.supportsVertexTextures ? '#define VERTEX_TEXTURES' : '',
  17584. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17585. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17586. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17587. '#define MAX_BONES ' + parameters.maxBones,
  17588. parameters.map ? '#define USE_MAP' : '',
  17589. parameters.envMap ? '#define USE_ENVMAP' : '',
  17590. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17591. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17592. parameters.aoMap ? '#define USE_AOMAP' : '',
  17593. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17594. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17595. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17596. parameters.displacementMap && parameters.supportsVertexTextures ? '#define USE_DISPLACEMENTMAP' : '',
  17597. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17598. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17599. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17600. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17601. parameters.vertexColors ? '#define USE_COLOR' : '',
  17602. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17603. parameters.skinning ? '#define USE_SKINNING' : '',
  17604. parameters.useVertexTexture ? '#define BONE_TEXTURE' : '',
  17605. parameters.morphTargets ? '#define USE_MORPHTARGETS' : '',
  17606. parameters.morphNormals && parameters.flatShading === false ? '#define USE_MORPHNORMALS' : '',
  17607. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17608. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17609. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17610. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17611. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17612. parameters.sizeAttenuation ? '#define USE_SIZEATTENUATION' : '',
  17613. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17614. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17615. 'uniform mat4 modelMatrix;',
  17616. 'uniform mat4 modelViewMatrix;',
  17617. 'uniform mat4 projectionMatrix;',
  17618. 'uniform mat4 viewMatrix;',
  17619. 'uniform mat3 normalMatrix;',
  17620. 'uniform vec3 cameraPosition;',
  17621. 'attribute vec3 position;',
  17622. 'attribute vec3 normal;',
  17623. 'attribute vec2 uv;',
  17624. '#ifdef USE_COLOR',
  17625. ' attribute vec3 color;',
  17626. '#endif',
  17627. '#ifdef USE_MORPHTARGETS',
  17628. ' attribute vec3 morphTarget0;',
  17629. ' attribute vec3 morphTarget1;',
  17630. ' attribute vec3 morphTarget2;',
  17631. ' attribute vec3 morphTarget3;',
  17632. ' #ifdef USE_MORPHNORMALS',
  17633. ' attribute vec3 morphNormal0;',
  17634. ' attribute vec3 morphNormal1;',
  17635. ' attribute vec3 morphNormal2;',
  17636. ' attribute vec3 morphNormal3;',
  17637. ' #else',
  17638. ' attribute vec3 morphTarget4;',
  17639. ' attribute vec3 morphTarget5;',
  17640. ' attribute vec3 morphTarget6;',
  17641. ' attribute vec3 morphTarget7;',
  17642. ' #endif',
  17643. '#endif',
  17644. '#ifdef USE_SKINNING',
  17645. ' attribute vec4 skinIndex;',
  17646. ' attribute vec4 skinWeight;',
  17647. '#endif',
  17648. '\n'
  17649. ].filter( filterEmptyLine ).join( '\n' );
  17650. prefixFragment = [
  17651. customExtensions,
  17652. 'precision ' + parameters.precision + ' float;',
  17653. 'precision ' + parameters.precision + ' int;',
  17654. '#define SHADER_NAME ' + material.__webglShader.name,
  17655. customDefines,
  17656. parameters.alphaTest ? '#define ALPHATEST ' + parameters.alphaTest : '',
  17657. renderer.gammaInput ? '#define GAMMA_INPUT' : '',
  17658. renderer.gammaOutput ? '#define GAMMA_OUTPUT' : '',
  17659. '#define GAMMA_FACTOR ' + gammaFactorDefine,
  17660. ( parameters.useFog && parameters.fog ) ? '#define USE_FOG' : '',
  17661. ( parameters.useFog && parameters.fogExp ) ? '#define FOG_EXP2' : '',
  17662. parameters.map ? '#define USE_MAP' : '',
  17663. parameters.envMap ? '#define USE_ENVMAP' : '',
  17664. parameters.envMap ? '#define ' + envMapTypeDefine : '',
  17665. parameters.envMap ? '#define ' + envMapModeDefine : '',
  17666. parameters.envMap ? '#define ' + envMapBlendingDefine : '',
  17667. parameters.lightMap ? '#define USE_LIGHTMAP' : '',
  17668. parameters.aoMap ? '#define USE_AOMAP' : '',
  17669. parameters.emissiveMap ? '#define USE_EMISSIVEMAP' : '',
  17670. parameters.bumpMap ? '#define USE_BUMPMAP' : '',
  17671. parameters.normalMap ? '#define USE_NORMALMAP' : '',
  17672. parameters.specularMap ? '#define USE_SPECULARMAP' : '',
  17673. parameters.roughnessMap ? '#define USE_ROUGHNESSMAP' : '',
  17674. parameters.metalnessMap ? '#define USE_METALNESSMAP' : '',
  17675. parameters.alphaMap ? '#define USE_ALPHAMAP' : '',
  17676. parameters.vertexColors ? '#define USE_COLOR' : '',
  17677. parameters.flatShading ? '#define FLAT_SHADED' : '',
  17678. parameters.doubleSided ? '#define DOUBLE_SIDED' : '',
  17679. parameters.flipSided ? '#define FLIP_SIDED' : '',
  17680. parameters.shadowMapEnabled ? '#define USE_SHADOWMAP' : '',
  17681. parameters.shadowMapEnabled ? '#define ' + shadowMapTypeDefine : '',
  17682. parameters.pointLightShadows > 0 ? '#define POINT_LIGHT_SHADOWS' : '',
  17683. parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
  17684. parameters.logarithmicDepthBuffer && renderer.extensions.get( 'EXT_frag_depth' ) ? '#define USE_LOGDEPTHBUF_EXT' : '',
  17685. parameters.envMap && renderer.extensions.get( 'EXT_shader_texture_lod' ) ? '#define TEXTURE_LOD_EXT' : '',
  17686. 'uniform mat4 viewMatrix;',
  17687. 'uniform vec3 cameraPosition;',
  17688. '\n'
  17689. ].filter( filterEmptyLine ).join( '\n' );
  17690. }
  17691. vertexShader = replaceLightNums( vertexShader, parameters );
  17692. fragmentShader = replaceLightNums( fragmentShader, parameters );
  17693. if ( material instanceof THREE.ShaderMaterial === false ) {
  17694. vertexShader = unrollLoops( vertexShader );
  17695. fragmentShader = unrollLoops( fragmentShader );
  17696. }
  17697. var vertexGlsl = prefixVertex + vertexShader;
  17698. var fragmentGlsl = prefixFragment + fragmentShader;
  17699. // console.log( '*VERTEX*', vertexGlsl );
  17700. // console.log( '*FRAGMENT*', fragmentGlsl );
  17701. var glVertexShader = THREE.WebGLShader( gl, gl.VERTEX_SHADER, vertexGlsl );
  17702. var glFragmentShader = THREE.WebGLShader( gl, gl.FRAGMENT_SHADER, fragmentGlsl );
  17703. gl.attachShader( program, glVertexShader );
  17704. gl.attachShader( program, glFragmentShader );
  17705. // Force a particular attribute to index 0.
  17706. if ( material.index0AttributeName !== undefined ) {
  17707. gl.bindAttribLocation( program, 0, material.index0AttributeName );
  17708. } else if ( parameters.morphTargets === true ) {
  17709. // programs with morphTargets displace position out of attribute 0
  17710. gl.bindAttribLocation( program, 0, 'position' );
  17711. }
  17712. gl.linkProgram( program );
  17713. var programLog = gl.getProgramInfoLog( program );
  17714. var vertexLog = gl.getShaderInfoLog( glVertexShader );
  17715. var fragmentLog = gl.getShaderInfoLog( glFragmentShader );
  17716. var runnable = true;
  17717. var haveDiagnostics = true;
  17718. // console.log( '**VERTEX**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glVertexShader ) );
  17719. // console.log( '**FRAGMENT**', gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( glFragmentShader ) );
  17720. if ( gl.getProgramParameter( program, gl.LINK_STATUS ) === false ) {
  17721. runnable = false;
  17722. console.error( 'THREE.WebGLProgram: shader error: ', gl.getError(), 'gl.VALIDATE_STATUS', gl.getProgramParameter( program, gl.VALIDATE_STATUS ), 'gl.getProgramInfoLog', programLog, vertexLog, fragmentLog );
  17723. } else if ( programLog !== '' ) {
  17724. console.warn( 'THREE.WebGLProgram: gl.getProgramInfoLog()', programLog );
  17725. } else if ( vertexLog === '' || fragmentLog === '' ) {
  17726. haveDiagnostics = false;
  17727. }
  17728. if ( haveDiagnostics ) {
  17729. this.diagnostics = {
  17730. runnable: runnable,
  17731. material: material,
  17732. programLog: programLog,
  17733. vertexShader: {
  17734. log: vertexLog,
  17735. prefix: prefixVertex
  17736. },
  17737. fragmentShader: {
  17738. log: fragmentLog,
  17739. prefix: prefixFragment
  17740. }
  17741. };
  17742. }
  17743. // clean up
  17744. gl.deleteShader( glVertexShader );
  17745. gl.deleteShader( glFragmentShader );
  17746. // set up caching for uniform locations
  17747. var cachedUniforms;
  17748. this.getUniforms = function() {
  17749. if ( cachedUniforms === undefined ) {
  17750. cachedUniforms = fetchUniformLocations( gl, program );
  17751. }
  17752. return cachedUniforms;
  17753. };
  17754. // set up caching for attribute locations
  17755. var cachedAttributes;
  17756. this.getAttributes = function() {
  17757. if ( cachedAttributes === undefined ) {
  17758. cachedAttributes = fetchAttributeLocations( gl, program );
  17759. }
  17760. return cachedAttributes;
  17761. };
  17762. // free resource
  17763. this.destroy = function() {
  17764. gl.deleteProgram( program );
  17765. this.program = undefined;
  17766. };
  17767. // DEPRECATED
  17768. Object.defineProperties( this, {
  17769. uniforms: {
  17770. get: function() {
  17771. console.warn( 'THREE.WebGLProgram: .uniforms is now .getUniforms().' );
  17772. return this.getUniforms();
  17773. }
  17774. },
  17775. attributes: {
  17776. get: function() {
  17777. console.warn( 'THREE.WebGLProgram: .attributes is now .getAttributes().' );
  17778. return this.getAttributes();
  17779. }
  17780. }
  17781. } );
  17782. //
  17783. this.id = programIdCount ++;
  17784. this.code = code;
  17785. this.usedTimes = 1;
  17786. this.program = program;
  17787. this.vertexShader = glVertexShader;
  17788. this.fragmentShader = glFragmentShader;
  17789. return this;
  17790. };
  17791. } )();
  17792. // File:src/renderers/webgl/WebGLPrograms.js
  17793. THREE.WebGLPrograms = function ( renderer, capabilities ) {
  17794. var programs = [];
  17795. var shaderIDs = {
  17796. MeshDepthMaterial: 'depth',
  17797. MeshNormalMaterial: 'normal',
  17798. MeshBasicMaterial: 'basic',
  17799. MeshLambertMaterial: 'lambert',
  17800. MeshPhongMaterial: 'phong',
  17801. MeshStandardMaterial: 'standard',
  17802. LineBasicMaterial: 'basic',
  17803. LineDashedMaterial: 'dashed',
  17804. PointsMaterial: 'points'
  17805. };
  17806. var parameterNames = [
  17807. "precision", "supportsVertexTextures", "map", "envMap", "envMapMode",
  17808. "lightMap", "aoMap", "emissiveMap", "bumpMap", "normalMap", "displacementMap", "specularMap",
  17809. "roughnessMap", "metalnessMap",
  17810. "alphaMap", "combine", "vertexColors", "fog", "useFog", "fogExp",
  17811. "flatShading", "sizeAttenuation", "logarithmicDepthBuffer", "skinning",
  17812. "maxBones", "useVertexTexture", "morphTargets", "morphNormals",
  17813. "maxMorphTargets", "maxMorphNormals",
  17814. "numDirLights", "numPointLights", "numSpotLights", "numHemiLights",
  17815. "shadowMapEnabled", "pointLightShadows",
  17816. "shadowMapType",
  17817. "alphaTest", "doubleSided", "flipSided"
  17818. ];
  17819. function allocateBones ( object ) {
  17820. if ( capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture ) {
  17821. return 1024;
  17822. } else {
  17823. // default for when object is not specified
  17824. // ( for example when prebuilding shader to be used with multiple objects )
  17825. //
  17826. // - leave some extra space for other uniforms
  17827. // - limit here is ANGLE's 254 max uniform vectors
  17828. // (up to 54 should be safe)
  17829. var nVertexUniforms = capabilities.maxVertexUniforms;
  17830. var nVertexMatrices = Math.floor( ( nVertexUniforms - 20 ) / 4 );
  17831. var maxBones = nVertexMatrices;
  17832. if ( object !== undefined && object instanceof THREE.SkinnedMesh ) {
  17833. maxBones = Math.min( object.skeleton.bones.length, maxBones );
  17834. if ( maxBones < object.skeleton.bones.length ) {
  17835. console.warn( 'WebGLRenderer: too many bones - ' + object.skeleton.bones.length + ', this GPU supports just ' + maxBones + ' (try OpenGL instead of ANGLE)' );
  17836. }
  17837. }
  17838. return maxBones;
  17839. }
  17840. }
  17841. this.getParameters = function ( material, lights, fog, object ) {
  17842. var shaderID = shaderIDs[ material.type ];
  17843. // heuristics to create shader parameters according to lights in the scene
  17844. // (not to blow over maxLights budget)
  17845. var maxBones = allocateBones( object );
  17846. var precision = renderer.getPrecision();
  17847. if ( material.precision !== null ) {
  17848. precision = capabilities.getMaxPrecision( material.precision );
  17849. if ( precision !== material.precision ) {
  17850. console.warn( 'THREE.WebGLProgram.getParameters:', material.precision, 'not supported, using', precision, 'instead.' );
  17851. }
  17852. }
  17853. var parameters = {
  17854. shaderID: shaderID,
  17855. precision: precision,
  17856. supportsVertexTextures: capabilities.vertexTextures,
  17857. map: !! material.map,
  17858. envMap: !! material.envMap,
  17859. envMapMode: material.envMap && material.envMap.mapping,
  17860. lightMap: !! material.lightMap,
  17861. aoMap: !! material.aoMap,
  17862. emissiveMap: !! material.emissiveMap,
  17863. bumpMap: !! material.bumpMap,
  17864. normalMap: !! material.normalMap,
  17865. displacementMap: !! material.displacementMap,
  17866. roughnessMap: !! material.roughnessMap,
  17867. metalnessMap: !! material.metalnessMap,
  17868. specularMap: !! material.specularMap,
  17869. alphaMap: !! material.alphaMap,
  17870. combine: material.combine,
  17871. vertexColors: material.vertexColors,
  17872. fog: fog,
  17873. useFog: material.fog,
  17874. fogExp: fog instanceof THREE.FogExp2,
  17875. flatShading: material.shading === THREE.FlatShading,
  17876. sizeAttenuation: material.sizeAttenuation,
  17877. logarithmicDepthBuffer: capabilities.logarithmicDepthBuffer,
  17878. skinning: material.skinning,
  17879. maxBones: maxBones,
  17880. useVertexTexture: capabilities.floatVertexTextures && object && object.skeleton && object.skeleton.useVertexTexture,
  17881. morphTargets: material.morphTargets,
  17882. morphNormals: material.morphNormals,
  17883. maxMorphTargets: renderer.maxMorphTargets,
  17884. maxMorphNormals: renderer.maxMorphNormals,
  17885. numDirLights: lights.directional.length,
  17886. numPointLights: lights.point.length,
  17887. numSpotLights: lights.spot.length,
  17888. numHemiLights: lights.hemi.length,
  17889. pointLightShadows: lights.shadowsPointLight,
  17890. shadowMapEnabled: renderer.shadowMap.enabled && object.receiveShadow && lights.shadows.length > 0,
  17891. shadowMapType: renderer.shadowMap.type,
  17892. alphaTest: material.alphaTest,
  17893. doubleSided: material.side === THREE.DoubleSide,
  17894. flipSided: material.side === THREE.BackSide
  17895. };
  17896. return parameters;
  17897. };
  17898. this.getProgramCode = function ( material, parameters ) {
  17899. var chunks = [];
  17900. if ( parameters.shaderID ) {
  17901. chunks.push( parameters.shaderID );
  17902. } else {
  17903. chunks.push( material.fragmentShader );
  17904. chunks.push( material.vertexShader );
  17905. }
  17906. if ( material.defines !== undefined ) {
  17907. for ( var name in material.defines ) {
  17908. chunks.push( name );
  17909. chunks.push( material.defines[ name ] );
  17910. }
  17911. }
  17912. for ( var i = 0; i < parameterNames.length; i ++ ) {
  17913. var parameterName = parameterNames[ i ];
  17914. chunks.push( parameterName );
  17915. chunks.push( parameters[ parameterName ] );
  17916. }
  17917. return chunks.join();
  17918. };
  17919. this.acquireProgram = function ( material, parameters, code ) {
  17920. var program;
  17921. // Check if code has been already compiled
  17922. for ( var p = 0, pl = programs.length; p < pl; p ++ ) {
  17923. var programInfo = programs[ p ];
  17924. if ( programInfo.code === code ) {
  17925. program = programInfo;
  17926. ++ program.usedTimes;
  17927. break;
  17928. }
  17929. }
  17930. if ( program === undefined ) {
  17931. program = new THREE.WebGLProgram( renderer, code, material, parameters );
  17932. programs.push( program );
  17933. }
  17934. return program;
  17935. };
  17936. this.releaseProgram = function( program ) {
  17937. if ( -- program.usedTimes === 0 ) {
  17938. // Remove from unordered set
  17939. var i = programs.indexOf( program );
  17940. programs[ i ] = programs[ programs.length - 1 ];
  17941. programs.pop();
  17942. // Free WebGL resources
  17943. program.destroy();
  17944. }
  17945. };
  17946. // Exposed for resource monitoring & error feedback via renderer.info:
  17947. this.programs = programs;
  17948. };
  17949. // File:src/renderers/webgl/WebGLProperties.js
  17950. /**
  17951. * @author fordacious / fordacious.github.io
  17952. */
  17953. THREE.WebGLProperties = function () {
  17954. var properties = {};
  17955. this.get = function ( object ) {
  17956. var uuid = object.uuid;
  17957. var map = properties[ uuid ];
  17958. if ( map === undefined ) {
  17959. map = {};
  17960. properties[ uuid ] = map;
  17961. }
  17962. return map;
  17963. };
  17964. this.delete = function ( object ) {
  17965. delete properties[ object.uuid ];
  17966. };
  17967. this.clear = function () {
  17968. properties = {};
  17969. };
  17970. };
  17971. // File:src/renderers/webgl/WebGLShader.js
  17972. THREE.WebGLShader = ( function () {
  17973. function addLineNumbers( string ) {
  17974. var lines = string.split( '\n' );
  17975. for ( var i = 0; i < lines.length; i ++ ) {
  17976. lines[ i ] = ( i + 1 ) + ': ' + lines[ i ];
  17977. }
  17978. return lines.join( '\n' );
  17979. }
  17980. return function WebGLShader( gl, type, string ) {
  17981. var shader = gl.createShader( type );
  17982. gl.shaderSource( shader, string );
  17983. gl.compileShader( shader );
  17984. if ( gl.getShaderParameter( shader, gl.COMPILE_STATUS ) === false ) {
  17985. console.error( 'THREE.WebGLShader: Shader couldn\'t compile.' );
  17986. }
  17987. if ( gl.getShaderInfoLog( shader ) !== '' ) {
  17988. console.warn( 'THREE.WebGLShader: gl.getShaderInfoLog()', type === gl.VERTEX_SHADER ? 'vertex' : 'fragment', gl.getShaderInfoLog( shader ), addLineNumbers( string ) );
  17989. }
  17990. // --enable-privileged-webgl-extension
  17991. // console.log( type, gl.getExtension( 'WEBGL_debug_shaders' ).getTranslatedShaderSource( shader ) );
  17992. return shader;
  17993. };
  17994. } )();
  17995. // File:src/renderers/webgl/WebGLShadowMap.js
  17996. /**
  17997. * @author alteredq / http://alteredqualia.com/
  17998. * @author mrdoob / http://mrdoob.com/
  17999. */
  18000. THREE.WebGLShadowMap = function ( _renderer, _lights, _objects ) {
  18001. var _gl = _renderer.context,
  18002. _state = _renderer.state,
  18003. _frustum = new THREE.Frustum(),
  18004. _projScreenMatrix = new THREE.Matrix4(),
  18005. _shadowMapSize = new THREE.Vector2(),
  18006. _lookTarget = new THREE.Vector3(),
  18007. _lightPositionWorld = new THREE.Vector3(),
  18008. _renderList = [],
  18009. _MorphingFlag = 1,
  18010. _SkinningFlag = 2,
  18011. _NumberOfMaterialVariants = ( _MorphingFlag | _SkinningFlag ) + 1,
  18012. _depthMaterials = new Array( _NumberOfMaterialVariants ),
  18013. _distanceMaterials = new Array( _NumberOfMaterialVariants );
  18014. var cubeDirections = [
  18015. new THREE.Vector3( 1, 0, 0 ), new THREE.Vector3( - 1, 0, 0 ), new THREE.Vector3( 0, 0, 1 ),
  18016. new THREE.Vector3( 0, 0, - 1 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, - 1, 0 )
  18017. ];
  18018. var cubeUps = [
  18019. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 1, 0 ),
  18020. new THREE.Vector3( 0, 1, 0 ), new THREE.Vector3( 0, 0, 1 ), new THREE.Vector3( 0, 0, - 1 )
  18021. ];
  18022. var cube2DViewPorts = [
  18023. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4(),
  18024. new THREE.Vector4(), new THREE.Vector4(), new THREE.Vector4()
  18025. ];
  18026. // init
  18027. var depthShader = THREE.ShaderLib[ "depthRGBA" ];
  18028. var depthUniforms = THREE.UniformsUtils.clone( depthShader.uniforms );
  18029. var distanceShader = THREE.ShaderLib[ "distanceRGBA" ];
  18030. var distanceUniforms = THREE.UniformsUtils.clone( distanceShader.uniforms );
  18031. for ( var i = 0; i !== _NumberOfMaterialVariants; ++ i ) {
  18032. var useMorphing = ( i & _MorphingFlag ) !== 0;
  18033. var useSkinning = ( i & _SkinningFlag ) !== 0;
  18034. var depthMaterial = new THREE.ShaderMaterial( {
  18035. uniforms: depthUniforms,
  18036. vertexShader: depthShader.vertexShader,
  18037. fragmentShader: depthShader.fragmentShader,
  18038. morphTargets: useMorphing,
  18039. skinning: useSkinning
  18040. } );
  18041. depthMaterial._shadowPass = true;
  18042. _depthMaterials[ i ] = depthMaterial;
  18043. var distanceMaterial = new THREE.ShaderMaterial( {
  18044. uniforms: distanceUniforms,
  18045. vertexShader: distanceShader.vertexShader,
  18046. fragmentShader: distanceShader.fragmentShader,
  18047. morphTargets: useMorphing,
  18048. skinning: useSkinning
  18049. } );
  18050. distanceMaterial._shadowPass = true;
  18051. _distanceMaterials[ i ] = distanceMaterial;
  18052. }
  18053. //
  18054. var scope = this;
  18055. this.enabled = false;
  18056. this.autoUpdate = true;
  18057. this.needsUpdate = false;
  18058. this.type = THREE.PCFShadowMap;
  18059. this.cullFace = THREE.CullFaceFront;
  18060. this.render = function ( scene, camera ) {
  18061. var faceCount, isPointLight;
  18062. if ( scope.enabled === false ) return;
  18063. if ( scope.autoUpdate === false && scope.needsUpdate === false ) return;
  18064. // Set GL state for depth map.
  18065. _state.clearColor( 1, 1, 1, 1 );
  18066. _state.disable( _gl.BLEND );
  18067. _state.enable( _gl.CULL_FACE );
  18068. _gl.frontFace( _gl.CCW );
  18069. _gl.cullFace( scope.cullFace === THREE.CullFaceFront ? _gl.FRONT : _gl.BACK );
  18070. _state.setDepthTest( true );
  18071. _state.setScissorTest( false );
  18072. // render depth map
  18073. var shadows = _lights.shadows;
  18074. for ( var i = 0, il = shadows.length; i < il; i ++ ) {
  18075. var light = shadows[ i ];
  18076. var shadow = light.shadow;
  18077. var shadowCamera = shadow.camera;
  18078. _shadowMapSize.copy( shadow.mapSize );
  18079. if ( light instanceof THREE.PointLight ) {
  18080. faceCount = 6;
  18081. isPointLight = true;
  18082. var vpWidth = _shadowMapSize.x;
  18083. var vpHeight = _shadowMapSize.y;
  18084. // These viewports map a cube-map onto a 2D texture with the
  18085. // following orientation:
  18086. //
  18087. // xzXZ
  18088. // y Y
  18089. //
  18090. // X - Positive x direction
  18091. // x - Negative x direction
  18092. // Y - Positive y direction
  18093. // y - Negative y direction
  18094. // Z - Positive z direction
  18095. // z - Negative z direction
  18096. // positive X
  18097. cube2DViewPorts[ 0 ].set( vpWidth * 2, vpHeight, vpWidth, vpHeight );
  18098. // negative X
  18099. cube2DViewPorts[ 1 ].set( 0, vpHeight, vpWidth, vpHeight );
  18100. // positive Z
  18101. cube2DViewPorts[ 2 ].set( vpWidth * 3, vpHeight, vpWidth, vpHeight );
  18102. // negative Z
  18103. cube2DViewPorts[ 3 ].set( vpWidth, vpHeight, vpWidth, vpHeight );
  18104. // positive Y
  18105. cube2DViewPorts[ 4 ].set( vpWidth * 3, 0, vpWidth, vpHeight );
  18106. // negative Y
  18107. cube2DViewPorts[ 5 ].set( vpWidth, 0, vpWidth, vpHeight );
  18108. _shadowMapSize.x *= 4.0;
  18109. _shadowMapSize.y *= 2.0;
  18110. } else {
  18111. faceCount = 1;
  18112. isPointLight = false;
  18113. }
  18114. if ( shadow.map === null ) {
  18115. var pars = { minFilter: THREE.NearestFilter, magFilter: THREE.NearestFilter, format: THREE.RGBAFormat };
  18116. shadow.map = new THREE.WebGLRenderTarget( _shadowMapSize.x, _shadowMapSize.y, pars );
  18117. //
  18118. if ( light instanceof THREE.SpotLight ) {
  18119. shadowCamera.aspect = _shadowMapSize.x / _shadowMapSize.y;
  18120. }
  18121. shadowCamera.updateProjectionMatrix();
  18122. }
  18123. var shadowMap = shadow.map;
  18124. var shadowMatrix = shadow.matrix;
  18125. _lightPositionWorld.setFromMatrixPosition( light.matrixWorld );
  18126. shadowCamera.position.copy( _lightPositionWorld );
  18127. _renderer.setRenderTarget( shadowMap );
  18128. _renderer.clear();
  18129. // render shadow map for each cube face (if omni-directional) or
  18130. // run a single pass if not
  18131. for ( var face = 0; face < faceCount; face ++ ) {
  18132. if ( isPointLight ) {
  18133. _lookTarget.copy( shadowCamera.position );
  18134. _lookTarget.add( cubeDirections[ face ] );
  18135. shadowCamera.up.copy( cubeUps[ face ] );
  18136. shadowCamera.lookAt( _lookTarget );
  18137. var vpDimensions = cube2DViewPorts[ face ];
  18138. _state.viewport( vpDimensions );
  18139. } else {
  18140. _lookTarget.setFromMatrixPosition( light.target.matrixWorld );
  18141. shadowCamera.lookAt( _lookTarget );
  18142. }
  18143. shadowCamera.updateMatrixWorld();
  18144. shadowCamera.matrixWorldInverse.getInverse( shadowCamera.matrixWorld );
  18145. // compute shadow matrix
  18146. shadowMatrix.set(
  18147. 0.5, 0.0, 0.0, 0.5,
  18148. 0.0, 0.5, 0.0, 0.5,
  18149. 0.0, 0.0, 0.5, 0.5,
  18150. 0.0, 0.0, 0.0, 1.0
  18151. );
  18152. shadowMatrix.multiply( shadowCamera.projectionMatrix );
  18153. shadowMatrix.multiply( shadowCamera.matrixWorldInverse );
  18154. // update camera matrices and frustum
  18155. _projScreenMatrix.multiplyMatrices( shadowCamera.projectionMatrix, shadowCamera.matrixWorldInverse );
  18156. _frustum.setFromMatrix( _projScreenMatrix );
  18157. // set object matrices & frustum culling
  18158. _renderList.length = 0;
  18159. projectObject( scene, camera, shadowCamera );
  18160. // render shadow map
  18161. // render regular objects
  18162. for ( var j = 0, jl = _renderList.length; j < jl; j ++ ) {
  18163. var object = _renderList[ j ];
  18164. var geometry = _objects.update( object );
  18165. var material = object.material;
  18166. if ( material instanceof THREE.MultiMaterial ) {
  18167. var groups = geometry.groups;
  18168. var materials = material.materials;
  18169. for ( var k = 0, kl = groups.length; k < kl; k ++ ) {
  18170. var group = groups[ k ];
  18171. var groupMaterial = materials[ group.materialIndex ];
  18172. if ( groupMaterial.visible === true ) {
  18173. var depthMaterial = getDepthMaterial( object, groupMaterial, isPointLight, _lightPositionWorld );
  18174. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, group );
  18175. }
  18176. }
  18177. } else {
  18178. var depthMaterial = getDepthMaterial( object, material, isPointLight, _lightPositionWorld );
  18179. _renderer.renderBufferDirect( shadowCamera, null, geometry, depthMaterial, object, null );
  18180. }
  18181. }
  18182. }
  18183. // We must call _renderer.resetGLState() at the end of each iteration of
  18184. // the light loop in order to force material updates for each light.
  18185. _renderer.resetGLState();
  18186. }
  18187. // Restore GL state.
  18188. var clearColor = _renderer.getClearColor(),
  18189. clearAlpha = _renderer.getClearAlpha();
  18190. _renderer.setClearColor( clearColor, clearAlpha );
  18191. _state.enable( _gl.BLEND );
  18192. if ( scope.cullFace === THREE.CullFaceFront ) {
  18193. _gl.cullFace( _gl.BACK );
  18194. }
  18195. _renderer.resetGLState();
  18196. scope.needsUpdate = false;
  18197. };
  18198. function getDepthMaterial( object, material, isPointLight, lightPositionWorld ) {
  18199. var geometry = object.geometry;
  18200. var newMaterial = null;
  18201. var materialVariants = _depthMaterials;
  18202. var customMaterial = object.customDepthMaterial;
  18203. if ( isPointLight ) {
  18204. materialVariants = _distanceMaterials;
  18205. customMaterial = object.customDistanceMaterial;
  18206. }
  18207. if ( ! customMaterial ) {
  18208. var useMorphing = geometry.morphTargets !== undefined &&
  18209. geometry.morphTargets.length > 0 && material.morphTargets;
  18210. var useSkinning = object instanceof THREE.SkinnedMesh && material.skinning;
  18211. var variantIndex = 0;
  18212. if ( useMorphing ) variantIndex |= _MorphingFlag;
  18213. if ( useSkinning ) variantIndex |= _SkinningFlag;
  18214. newMaterial = materialVariants[ variantIndex ];
  18215. } else {
  18216. newMaterial = customMaterial;
  18217. }
  18218. newMaterial.visible = material.visible;
  18219. newMaterial.wireframe = material.wireframe;
  18220. newMaterial.wireframeLinewidth = material.wireframeLinewidth;
  18221. if ( isPointLight && newMaterial.uniforms.lightPos !== undefined ) {
  18222. newMaterial.uniforms.lightPos.value.copy( lightPositionWorld );
  18223. }
  18224. return newMaterial;
  18225. }
  18226. function projectObject( object, camera, shadowCamera ) {
  18227. if ( object.visible === false ) return;
  18228. if ( object.layers.test( camera.layers ) && ( object instanceof THREE.Mesh || object instanceof THREE.Line || object instanceof THREE.Points ) ) {
  18229. if ( object.castShadow && ( object.frustumCulled === false || _frustum.intersectsObject( object ) === true ) ) {
  18230. var material = object.material;
  18231. if ( material.visible === true ) {
  18232. object.modelViewMatrix.multiplyMatrices( shadowCamera.matrixWorldInverse, object.matrixWorld );
  18233. _renderList.push( object );
  18234. }
  18235. }
  18236. }
  18237. var children = object.children;
  18238. for ( var i = 0, l = children.length; i < l; i ++ ) {
  18239. projectObject( children[ i ], camera, shadowCamera );
  18240. }
  18241. }
  18242. };
  18243. // File:src/renderers/webgl/WebGLState.js
  18244. /**
  18245. * @author mrdoob / http://mrdoob.com/
  18246. */
  18247. THREE.WebGLState = function ( gl, extensions, paramThreeToGL ) {
  18248. var _this = this;
  18249. var color = new THREE.Vector4();
  18250. var newAttributes = new Uint8Array( 16 );
  18251. var enabledAttributes = new Uint8Array( 16 );
  18252. var attributeDivisors = new Uint8Array( 16 );
  18253. var capabilities = {};
  18254. var compressedTextureFormats = null;
  18255. var currentBlending = null;
  18256. var currentBlendEquation = null;
  18257. var currentBlendSrc = null;
  18258. var currentBlendDst = null;
  18259. var currentBlendEquationAlpha = null;
  18260. var currentBlendSrcAlpha = null;
  18261. var currentBlendDstAlpha = null;
  18262. var currentDepthFunc = null;
  18263. var currentDepthWrite = null;
  18264. var currentColorWrite = null;
  18265. var currentStencilWrite = null;
  18266. var currentStencilFunc = null;
  18267. var currentStencilRef = null;
  18268. var currentStencilMask = null;
  18269. var currentStencilFail = null;
  18270. var currentStencilZFail = null;
  18271. var currentStencilZPass = null;
  18272. var currentFlipSided = null;
  18273. var currentLineWidth = null;
  18274. var currentPolygonOffsetFactor = null;
  18275. var currentPolygonOffsetUnits = null;
  18276. var currentScissorTest = null;
  18277. var maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
  18278. var currentTextureSlot = undefined;
  18279. var currentBoundTextures = {};
  18280. var currentClearColor = new THREE.Vector4();
  18281. var currentClearDepth = null;
  18282. var currentClearStencil = null;
  18283. var currentScissor = new THREE.Vector4();
  18284. var currentViewport = new THREE.Vector4();
  18285. this.init = function () {
  18286. this.clearColor( 0, 0, 0, 1 );
  18287. this.clearDepth( 1 );
  18288. this.clearStencil( 0 );
  18289. this.enable( gl.DEPTH_TEST );
  18290. gl.depthFunc( gl.LEQUAL );
  18291. gl.frontFace( gl.CCW );
  18292. gl.cullFace( gl.BACK );
  18293. this.enable( gl.CULL_FACE );
  18294. this.enable( gl.BLEND );
  18295. gl.blendEquation( gl.FUNC_ADD );
  18296. gl.blendFunc( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA );
  18297. };
  18298. this.initAttributes = function () {
  18299. for ( var i = 0, l = newAttributes.length; i < l; i ++ ) {
  18300. newAttributes[ i ] = 0;
  18301. }
  18302. };
  18303. this.enableAttribute = function ( attribute ) {
  18304. newAttributes[ attribute ] = 1;
  18305. if ( enabledAttributes[ attribute ] === 0 ) {
  18306. gl.enableVertexAttribArray( attribute );
  18307. enabledAttributes[ attribute ] = 1;
  18308. }
  18309. if ( attributeDivisors[ attribute ] !== 0 ) {
  18310. var extension = extensions.get( 'ANGLE_instanced_arrays' );
  18311. extension.vertexAttribDivisorANGLE( attribute, 0 );
  18312. attributeDivisors[ attribute ] = 0;
  18313. }
  18314. };
  18315. this.enableAttributeAndDivisor = function ( attribute, meshPerAttribute, extension ) {
  18316. newAttributes[ attribute ] = 1;
  18317. if ( enabledAttributes[ attribute ] === 0 ) {
  18318. gl.enableVertexAttribArray( attribute );
  18319. enabledAttributes[ attribute ] = 1;
  18320. }
  18321. if ( attributeDivisors[ attribute ] !== meshPerAttribute ) {
  18322. extension.vertexAttribDivisorANGLE( attribute, meshPerAttribute );
  18323. attributeDivisors[ attribute ] = meshPerAttribute;
  18324. }
  18325. };
  18326. this.disableUnusedAttributes = function () {
  18327. for ( var i = 0, l = enabledAttributes.length; i < l; i ++ ) {
  18328. if ( enabledAttributes[ i ] !== newAttributes[ i ] ) {
  18329. gl.disableVertexAttribArray( i );
  18330. enabledAttributes[ i ] = 0;
  18331. }
  18332. }
  18333. };
  18334. this.enable = function ( id ) {
  18335. if ( capabilities[ id ] !== true ) {
  18336. gl.enable( id );
  18337. capabilities[ id ] = true;
  18338. }
  18339. };
  18340. this.disable = function ( id ) {
  18341. if ( capabilities[ id ] !== false ) {
  18342. gl.disable( id );
  18343. capabilities[ id ] = false;
  18344. }
  18345. };
  18346. this.getCompressedTextureFormats = function () {
  18347. if ( compressedTextureFormats === null ) {
  18348. compressedTextureFormats = [];
  18349. if ( extensions.get( 'WEBGL_compressed_texture_pvrtc' ) ||
  18350. extensions.get( 'WEBGL_compressed_texture_s3tc' ) ||
  18351. extensions.get( 'WEBGL_compressed_texture_etc1' )) {
  18352. var formats = gl.getParameter( gl.COMPRESSED_TEXTURE_FORMATS );
  18353. for ( var i = 0; i < formats.length; i ++ ) {
  18354. compressedTextureFormats.push( formats[ i ] );
  18355. }
  18356. }
  18357. }
  18358. return compressedTextureFormats;
  18359. };
  18360. this.setBlending = function ( blending, blendEquation, blendSrc, blendDst, blendEquationAlpha, blendSrcAlpha, blendDstAlpha ) {
  18361. if ( blending === THREE.NoBlending ) {
  18362. this.disable( gl.BLEND );
  18363. } else {
  18364. this.enable( gl.BLEND );
  18365. }
  18366. if ( blending !== currentBlending ) {
  18367. if ( blending === THREE.AdditiveBlending ) {
  18368. gl.blendEquation( gl.FUNC_ADD );
  18369. gl.blendFunc( gl.SRC_ALPHA, gl.ONE );
  18370. } else if ( blending === THREE.SubtractiveBlending ) {
  18371. // TODO: Find blendFuncSeparate() combination
  18372. gl.blendEquation( gl.FUNC_ADD );
  18373. gl.blendFunc( gl.ZERO, gl.ONE_MINUS_SRC_COLOR );
  18374. } else if ( blending === THREE.MultiplyBlending ) {
  18375. // TODO: Find blendFuncSeparate() combination
  18376. gl.blendEquation( gl.FUNC_ADD );
  18377. gl.blendFunc( gl.ZERO, gl.SRC_COLOR );
  18378. } else {
  18379. gl.blendEquationSeparate( gl.FUNC_ADD, gl.FUNC_ADD );
  18380. gl.blendFuncSeparate( gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ONE_MINUS_SRC_ALPHA );
  18381. }
  18382. currentBlending = blending;
  18383. }
  18384. if ( blending === THREE.CustomBlending ) {
  18385. blendEquationAlpha = blendEquationAlpha || blendEquation;
  18386. blendSrcAlpha = blendSrcAlpha || blendSrc;
  18387. blendDstAlpha = blendDstAlpha || blendDst;
  18388. if ( blendEquation !== currentBlendEquation || blendEquationAlpha !== currentBlendEquationAlpha ) {
  18389. gl.blendEquationSeparate( paramThreeToGL( blendEquation ), paramThreeToGL( blendEquationAlpha ) );
  18390. currentBlendEquation = blendEquation;
  18391. currentBlendEquationAlpha = blendEquationAlpha;
  18392. }
  18393. if ( blendSrc !== currentBlendSrc || blendDst !== currentBlendDst || blendSrcAlpha !== currentBlendSrcAlpha || blendDstAlpha !== currentBlendDstAlpha ) {
  18394. gl.blendFuncSeparate( paramThreeToGL( blendSrc ), paramThreeToGL( blendDst ), paramThreeToGL( blendSrcAlpha ), paramThreeToGL( blendDstAlpha ) );
  18395. currentBlendSrc = blendSrc;
  18396. currentBlendDst = blendDst;
  18397. currentBlendSrcAlpha = blendSrcAlpha;
  18398. currentBlendDstAlpha = blendDstAlpha;
  18399. }
  18400. } else {
  18401. currentBlendEquation = null;
  18402. currentBlendSrc = null;
  18403. currentBlendDst = null;
  18404. currentBlendEquationAlpha = null;
  18405. currentBlendSrcAlpha = null;
  18406. currentBlendDstAlpha = null;
  18407. }
  18408. };
  18409. this.setDepthFunc = function ( depthFunc ) {
  18410. if ( currentDepthFunc !== depthFunc ) {
  18411. if ( depthFunc ) {
  18412. switch ( depthFunc ) {
  18413. case THREE.NeverDepth:
  18414. gl.depthFunc( gl.NEVER );
  18415. break;
  18416. case THREE.AlwaysDepth:
  18417. gl.depthFunc( gl.ALWAYS );
  18418. break;
  18419. case THREE.LessDepth:
  18420. gl.depthFunc( gl.LESS );
  18421. break;
  18422. case THREE.LessEqualDepth:
  18423. gl.depthFunc( gl.LEQUAL );
  18424. break;
  18425. case THREE.EqualDepth:
  18426. gl.depthFunc( gl.EQUAL );
  18427. break;
  18428. case THREE.GreaterEqualDepth:
  18429. gl.depthFunc( gl.GEQUAL );
  18430. break;
  18431. case THREE.GreaterDepth:
  18432. gl.depthFunc( gl.GREATER );
  18433. break;
  18434. case THREE.NotEqualDepth:
  18435. gl.depthFunc( gl.NOTEQUAL );
  18436. break;
  18437. default:
  18438. gl.depthFunc( gl.LEQUAL );
  18439. }
  18440. } else {
  18441. gl.depthFunc( gl.LEQUAL );
  18442. }
  18443. currentDepthFunc = depthFunc;
  18444. }
  18445. };
  18446. this.setDepthTest = function ( depthTest ) {
  18447. if ( depthTest ) {
  18448. this.enable( gl.DEPTH_TEST );
  18449. } else {
  18450. this.disable( gl.DEPTH_TEST );
  18451. }
  18452. };
  18453. this.setDepthWrite = function ( depthWrite ) {
  18454. // TODO: Rename to setDepthMask
  18455. if ( currentDepthWrite !== depthWrite ) {
  18456. gl.depthMask( depthWrite );
  18457. currentDepthWrite = depthWrite;
  18458. }
  18459. };
  18460. this.setColorWrite = function ( colorWrite ) {
  18461. // TODO: Rename to setColorMask
  18462. if ( currentColorWrite !== colorWrite ) {
  18463. gl.colorMask( colorWrite, colorWrite, colorWrite, colorWrite );
  18464. currentColorWrite = colorWrite;
  18465. }
  18466. };
  18467. this.setStencilFunc = function ( stencilFunc, stencilRef, stencilMask ) {
  18468. if ( currentStencilFunc !== stencilFunc ||
  18469. currentStencilRef !== stencilRef ||
  18470. currentStencilMask !== stencilMask ) {
  18471. gl.stencilFunc( stencilFunc, stencilRef, stencilMask );
  18472. currentStencilFunc = stencilFunc;
  18473. currentStencilRef = stencilRef;
  18474. currentStencilMask = stencilMask;
  18475. }
  18476. };
  18477. this.setStencilOp = function ( stencilFail, stencilZFail, stencilZPass ) {
  18478. if ( currentStencilFail !== stencilFail ||
  18479. currentStencilZFail !== stencilZFail ||
  18480. currentStencilZPass !== stencilZPass ) {
  18481. gl.stencilOp( stencilFail, stencilZFail, stencilZPass );
  18482. currentStencilFail = stencilFail;
  18483. currentStencilZFail = stencilZFail;
  18484. currentStencilZPass = stencilZPass;
  18485. }
  18486. };
  18487. this.setStencilTest = function ( stencilTest ) {
  18488. if ( stencilTest ) {
  18489. this.enable( gl.STENCIL_TEST );
  18490. } else {
  18491. this.disable( gl.STENCIL_TEST );
  18492. }
  18493. };
  18494. this.setStencilWrite = function ( stencilWrite ) {
  18495. // TODO: Rename to setStencilMask
  18496. if ( currentStencilWrite !== stencilWrite ) {
  18497. gl.stencilMask( stencilWrite );
  18498. currentStencilWrite = stencilWrite;
  18499. }
  18500. };
  18501. this.setFlipSided = function ( flipSided ) {
  18502. if ( currentFlipSided !== flipSided ) {
  18503. if ( flipSided ) {
  18504. gl.frontFace( gl.CW );
  18505. } else {
  18506. gl.frontFace( gl.CCW );
  18507. }
  18508. currentFlipSided = flipSided;
  18509. }
  18510. };
  18511. this.setLineWidth = function ( width ) {
  18512. if ( width !== currentLineWidth ) {
  18513. gl.lineWidth( width );
  18514. currentLineWidth = width;
  18515. }
  18516. };
  18517. this.setPolygonOffset = function ( polygonOffset, factor, units ) {
  18518. if ( polygonOffset ) {
  18519. this.enable( gl.POLYGON_OFFSET_FILL );
  18520. } else {
  18521. this.disable( gl.POLYGON_OFFSET_FILL );
  18522. }
  18523. if ( polygonOffset && ( currentPolygonOffsetFactor !== factor || currentPolygonOffsetUnits !== units ) ) {
  18524. gl.polygonOffset( factor, units );
  18525. currentPolygonOffsetFactor = factor;
  18526. currentPolygonOffsetUnits = units;
  18527. }
  18528. };
  18529. this.getScissorTest = function () {
  18530. return currentScissorTest;
  18531. };
  18532. this.setScissorTest = function ( scissorTest ) {
  18533. currentScissorTest = scissorTest;
  18534. if ( scissorTest ) {
  18535. this.enable( gl.SCISSOR_TEST );
  18536. } else {
  18537. this.disable( gl.SCISSOR_TEST );
  18538. }
  18539. };
  18540. // texture
  18541. this.activeTexture = function ( webglSlot ) {
  18542. if ( webglSlot === undefined ) webglSlot = gl.TEXTURE0 + maxTextures - 1;
  18543. if ( currentTextureSlot !== webglSlot ) {
  18544. gl.activeTexture( webglSlot );
  18545. currentTextureSlot = webglSlot;
  18546. }
  18547. };
  18548. this.bindTexture = function ( webglType, webglTexture ) {
  18549. if ( currentTextureSlot === undefined ) {
  18550. _this.activeTexture();
  18551. }
  18552. var boundTexture = currentBoundTextures[ currentTextureSlot ];
  18553. if ( boundTexture === undefined ) {
  18554. boundTexture = { type: undefined, texture: undefined };
  18555. currentBoundTextures[ currentTextureSlot ] = boundTexture;
  18556. }
  18557. if ( boundTexture.type !== webglType || boundTexture.texture !== webglTexture ) {
  18558. gl.bindTexture( webglType, webglTexture );
  18559. boundTexture.type = webglType;
  18560. boundTexture.texture = webglTexture;
  18561. }
  18562. };
  18563. this.compressedTexImage2D = function () {
  18564. try {
  18565. gl.compressedTexImage2D.apply( gl, arguments );
  18566. } catch ( error ) {
  18567. console.error( error );
  18568. }
  18569. };
  18570. this.texImage2D = function () {
  18571. try {
  18572. gl.texImage2D.apply( gl, arguments );
  18573. } catch ( error ) {
  18574. console.error( error );
  18575. }
  18576. };
  18577. // clear values
  18578. this.clearColor = function ( r, g, b, a ) {
  18579. color.set( r, g, b, a );
  18580. if ( currentClearColor.equals( color ) === false ) {
  18581. gl.clearColor( r, g, b, a );
  18582. currentClearColor.copy( color );
  18583. }
  18584. };
  18585. this.clearDepth = function ( depth ) {
  18586. if ( currentClearDepth !== depth ) {
  18587. gl.clearDepth( depth );
  18588. currentClearDepth = depth;
  18589. }
  18590. };
  18591. this.clearStencil = function ( stencil ) {
  18592. if ( currentClearStencil !== stencil ) {
  18593. gl.clearStencil( stencil );
  18594. currentClearStencil = stencil;
  18595. }
  18596. };
  18597. //
  18598. this.scissor = function ( scissor ) {
  18599. if ( currentScissor.equals( scissor ) === false ) {
  18600. gl.scissor( scissor.x, scissor.y, scissor.z, scissor.w );
  18601. currentScissor.copy( scissor );
  18602. }
  18603. };
  18604. this.viewport = function ( viewport ) {
  18605. if ( currentViewport.equals( viewport ) === false ) {
  18606. gl.viewport( viewport.x, viewport.y, viewport.z, viewport.w );
  18607. currentViewport.copy( viewport );
  18608. }
  18609. };
  18610. //
  18611. this.reset = function () {
  18612. for ( var i = 0; i < enabledAttributes.length; i ++ ) {
  18613. if ( enabledAttributes[ i ] === 1 ) {
  18614. gl.disableVertexAttribArray( i );
  18615. enabledAttributes[ i ] = 0;
  18616. }
  18617. }
  18618. capabilities = {};
  18619. compressedTextureFormats = null;
  18620. currentBlending = null;
  18621. currentColorWrite = null;
  18622. currentDepthWrite = null;
  18623. currentStencilWrite = null;
  18624. currentFlipSided = null;
  18625. };
  18626. };
  18627. // File:src/renderers/webgl/plugins/LensFlarePlugin.js
  18628. /**
  18629. * @author mikael emtinger / http://gomo.se/
  18630. * @author alteredq / http://alteredqualia.com/
  18631. */
  18632. THREE.LensFlarePlugin = function ( renderer, flares ) {
  18633. var gl = renderer.context;
  18634. var state = renderer.state;
  18635. var vertexBuffer, elementBuffer;
  18636. var program, attributes, uniforms;
  18637. var hasVertexTexture;
  18638. var tempTexture, occlusionTexture;
  18639. function init() {
  18640. var vertices = new Float32Array( [
  18641. - 1, - 1, 0, 0,
  18642. 1, - 1, 1, 0,
  18643. 1, 1, 1, 1,
  18644. - 1, 1, 0, 1
  18645. ] );
  18646. var faces = new Uint16Array( [
  18647. 0, 1, 2,
  18648. 0, 2, 3
  18649. ] );
  18650. // buffers
  18651. vertexBuffer = gl.createBuffer();
  18652. elementBuffer = gl.createBuffer();
  18653. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18654. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18655. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18656. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18657. // textures
  18658. tempTexture = gl.createTexture();
  18659. occlusionTexture = gl.createTexture();
  18660. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18661. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGB, 16, 16, 0, gl.RGB, gl.UNSIGNED_BYTE, null );
  18662. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18663. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18664. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18665. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18666. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18667. gl.texImage2D( gl.TEXTURE_2D, 0, gl.RGBA, 16, 16, 0, gl.RGBA, gl.UNSIGNED_BYTE, null );
  18668. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE );
  18669. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE );
  18670. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST );
  18671. gl.texParameteri( gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST );
  18672. hasVertexTexture = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS ) > 0;
  18673. var shader;
  18674. if ( hasVertexTexture ) {
  18675. shader = {
  18676. vertexShader: [
  18677. "uniform lowp int renderType;",
  18678. "uniform vec3 screenPosition;",
  18679. "uniform vec2 scale;",
  18680. "uniform float rotation;",
  18681. "uniform sampler2D occlusionMap;",
  18682. "attribute vec2 position;",
  18683. "attribute vec2 uv;",
  18684. "varying vec2 vUV;",
  18685. "varying float vVisibility;",
  18686. "void main() {",
  18687. "vUV = uv;",
  18688. "vec2 pos = position;",
  18689. "if ( renderType == 2 ) {",
  18690. "vec4 visibility = texture2D( occlusionMap, vec2( 0.1, 0.1 ) );",
  18691. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.1 ) );",
  18692. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.1 ) );",
  18693. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) );",
  18694. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.9 ) );",
  18695. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) );",
  18696. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.9 ) );",
  18697. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) );",
  18698. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.5 ) );",
  18699. "vVisibility = visibility.r / 9.0;",
  18700. "vVisibility *= 1.0 - visibility.g / 9.0;",
  18701. "vVisibility *= visibility.b / 9.0;",
  18702. "vVisibility *= 1.0 - visibility.a / 9.0;",
  18703. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18704. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18705. "}",
  18706. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18707. "}"
  18708. ].join( "\n" ),
  18709. fragmentShader: [
  18710. "uniform lowp int renderType;",
  18711. "uniform sampler2D map;",
  18712. "uniform float opacity;",
  18713. "uniform vec3 color;",
  18714. "varying vec2 vUV;",
  18715. "varying float vVisibility;",
  18716. "void main() {",
  18717. // pink square
  18718. "if ( renderType == 0 ) {",
  18719. "gl_FragColor = vec4( 1.0, 0.0, 1.0, 0.0 );",
  18720. // restore
  18721. "} else if ( renderType == 1 ) {",
  18722. "gl_FragColor = texture2D( map, vUV );",
  18723. // flare
  18724. "} else {",
  18725. "vec4 texture = texture2D( map, vUV );",
  18726. "texture.a *= opacity * vVisibility;",
  18727. "gl_FragColor = texture;",
  18728. "gl_FragColor.rgb *= color;",
  18729. "}",
  18730. "}"
  18731. ].join( "\n" )
  18732. };
  18733. } else {
  18734. shader = {
  18735. vertexShader: [
  18736. "uniform lowp int renderType;",
  18737. "uniform vec3 screenPosition;",
  18738. "uniform vec2 scale;",
  18739. "uniform float rotation;",
  18740. "attribute vec2 position;",
  18741. "attribute vec2 uv;",
  18742. "varying vec2 vUV;",
  18743. "void main() {",
  18744. "vUV = uv;",
  18745. "vec2 pos = position;",
  18746. "if ( renderType == 2 ) {",
  18747. "pos.x = cos( rotation ) * position.x - sin( rotation ) * position.y;",
  18748. "pos.y = sin( rotation ) * position.x + cos( rotation ) * position.y;",
  18749. "}",
  18750. "gl_Position = vec4( ( pos * scale + screenPosition.xy ).xy, screenPosition.z, 1.0 );",
  18751. "}"
  18752. ].join( "\n" ),
  18753. fragmentShader: [
  18754. "precision mediump float;",
  18755. "uniform lowp int renderType;",
  18756. "uniform sampler2D map;",
  18757. "uniform sampler2D occlusionMap;",
  18758. "uniform float opacity;",
  18759. "uniform vec3 color;",
  18760. "varying vec2 vUV;",
  18761. "void main() {",
  18762. // pink square
  18763. "if ( renderType == 0 ) {",
  18764. "gl_FragColor = vec4( texture2D( map, vUV ).rgb, 0.0 );",
  18765. // restore
  18766. "} else if ( renderType == 1 ) {",
  18767. "gl_FragColor = texture2D( map, vUV );",
  18768. // flare
  18769. "} else {",
  18770. "float visibility = texture2D( occlusionMap, vec2( 0.5, 0.1 ) ).a;",
  18771. "visibility += texture2D( occlusionMap, vec2( 0.9, 0.5 ) ).a;",
  18772. "visibility += texture2D( occlusionMap, vec2( 0.5, 0.9 ) ).a;",
  18773. "visibility += texture2D( occlusionMap, vec2( 0.1, 0.5 ) ).a;",
  18774. "visibility = ( 1.0 - visibility / 4.0 );",
  18775. "vec4 texture = texture2D( map, vUV );",
  18776. "texture.a *= opacity * visibility;",
  18777. "gl_FragColor = texture;",
  18778. "gl_FragColor.rgb *= color;",
  18779. "}",
  18780. "}"
  18781. ].join( "\n" )
  18782. };
  18783. }
  18784. program = createProgram( shader );
  18785. attributes = {
  18786. vertex: gl.getAttribLocation ( program, "position" ),
  18787. uv: gl.getAttribLocation ( program, "uv" )
  18788. };
  18789. uniforms = {
  18790. renderType: gl.getUniformLocation( program, "renderType" ),
  18791. map: gl.getUniformLocation( program, "map" ),
  18792. occlusionMap: gl.getUniformLocation( program, "occlusionMap" ),
  18793. opacity: gl.getUniformLocation( program, "opacity" ),
  18794. color: gl.getUniformLocation( program, "color" ),
  18795. scale: gl.getUniformLocation( program, "scale" ),
  18796. rotation: gl.getUniformLocation( program, "rotation" ),
  18797. screenPosition: gl.getUniformLocation( program, "screenPosition" )
  18798. };
  18799. }
  18800. /*
  18801. * Render lens flares
  18802. * Method: renders 16x16 0xff00ff-colored points scattered over the light source area,
  18803. * reads these back and calculates occlusion.
  18804. */
  18805. this.render = function ( scene, camera, viewport ) {
  18806. if ( flares.length === 0 ) return;
  18807. var tempPosition = new THREE.Vector3();
  18808. var invAspect = viewport.w / viewport.z,
  18809. halfViewportWidth = viewport.z * 0.5,
  18810. halfViewportHeight = viewport.w * 0.5;
  18811. var size = 16 / viewport.w,
  18812. scale = new THREE.Vector2( size * invAspect, size );
  18813. var screenPosition = new THREE.Vector3( 1, 1, 0 ),
  18814. screenPositionPixels = new THREE.Vector2( 1, 1 );
  18815. if ( program === undefined ) {
  18816. init();
  18817. }
  18818. gl.useProgram( program );
  18819. state.initAttributes();
  18820. state.enableAttribute( attributes.vertex );
  18821. state.enableAttribute( attributes.uv );
  18822. state.disableUnusedAttributes();
  18823. // loop through all lens flares to update their occlusion and positions
  18824. // setup gl and common used attribs/uniforms
  18825. gl.uniform1i( uniforms.occlusionMap, 0 );
  18826. gl.uniform1i( uniforms.map, 1 );
  18827. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18828. gl.vertexAttribPointer( attributes.vertex, 2, gl.FLOAT, false, 2 * 8, 0 );
  18829. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  18830. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18831. state.disable( gl.CULL_FACE );
  18832. state.setDepthWrite( false );
  18833. for ( var i = 0, l = flares.length; i < l; i ++ ) {
  18834. size = 16 / viewport.w;
  18835. scale.set( size * invAspect, size );
  18836. // calc object screen position
  18837. var flare = flares[ i ];
  18838. tempPosition.set( flare.matrixWorld.elements[ 12 ], flare.matrixWorld.elements[ 13 ], flare.matrixWorld.elements[ 14 ] );
  18839. tempPosition.applyMatrix4( camera.matrixWorldInverse );
  18840. tempPosition.applyProjection( camera.projectionMatrix );
  18841. // setup arrays for gl programs
  18842. screenPosition.copy( tempPosition );
  18843. screenPositionPixels.x = screenPosition.x * halfViewportWidth + halfViewportWidth;
  18844. screenPositionPixels.y = screenPosition.y * halfViewportHeight + halfViewportHeight;
  18845. // screen cull
  18846. if ( hasVertexTexture || (
  18847. screenPositionPixels.x > 0 &&
  18848. screenPositionPixels.x < viewport.z &&
  18849. screenPositionPixels.y > 0 &&
  18850. screenPositionPixels.y < viewport.w ) ) {
  18851. // save current RGB to temp texture
  18852. state.activeTexture( gl.TEXTURE0 );
  18853. state.bindTexture( gl.TEXTURE_2D, null );
  18854. state.activeTexture( gl.TEXTURE1 );
  18855. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18856. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGB, viewport.x + screenPositionPixels.x - 8, viewport.y + screenPositionPixels.y - 8, 16, 16, 0 );
  18857. // render pink quad
  18858. gl.uniform1i( uniforms.renderType, 0 );
  18859. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18860. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18861. state.disable( gl.BLEND );
  18862. state.enable( gl.DEPTH_TEST );
  18863. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18864. // copy result to occlusionMap
  18865. state.activeTexture( gl.TEXTURE0 );
  18866. state.bindTexture( gl.TEXTURE_2D, occlusionTexture );
  18867. gl.copyTexImage2D( gl.TEXTURE_2D, 0, gl.RGBA, viewport.x + screenPositionPixels.x - 8, viewport.y + screenPositionPixels.y - 8, 16, 16, 0 );
  18868. // restore graphics
  18869. gl.uniform1i( uniforms.renderType, 1 );
  18870. state.disable( gl.DEPTH_TEST );
  18871. state.activeTexture( gl.TEXTURE1 );
  18872. state.bindTexture( gl.TEXTURE_2D, tempTexture );
  18873. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18874. // update object positions
  18875. flare.positionScreen.copy( screenPosition );
  18876. if ( flare.customUpdateCallback ) {
  18877. flare.customUpdateCallback( flare );
  18878. } else {
  18879. flare.updateLensFlares();
  18880. }
  18881. // render flares
  18882. gl.uniform1i( uniforms.renderType, 2 );
  18883. state.enable( gl.BLEND );
  18884. for ( var j = 0, jl = flare.lensFlares.length; j < jl; j ++ ) {
  18885. var sprite = flare.lensFlares[ j ];
  18886. if ( sprite.opacity > 0.001 && sprite.scale > 0.001 ) {
  18887. screenPosition.x = sprite.x;
  18888. screenPosition.y = sprite.y;
  18889. screenPosition.z = sprite.z;
  18890. size = sprite.size * sprite.scale / viewport.w;
  18891. scale.x = size * invAspect;
  18892. scale.y = size;
  18893. gl.uniform3f( uniforms.screenPosition, screenPosition.x, screenPosition.y, screenPosition.z );
  18894. gl.uniform2f( uniforms.scale, scale.x, scale.y );
  18895. gl.uniform1f( uniforms.rotation, sprite.rotation );
  18896. gl.uniform1f( uniforms.opacity, sprite.opacity );
  18897. gl.uniform3f( uniforms.color, sprite.color.r, sprite.color.g, sprite.color.b );
  18898. state.setBlending( sprite.blending, sprite.blendEquation, sprite.blendSrc, sprite.blendDst );
  18899. renderer.setTexture( sprite.texture, 1 );
  18900. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  18901. }
  18902. }
  18903. }
  18904. }
  18905. // restore gl
  18906. state.enable( gl.CULL_FACE );
  18907. state.enable( gl.DEPTH_TEST );
  18908. state.setDepthWrite( true );
  18909. renderer.resetGLState();
  18910. };
  18911. function createProgram ( shader ) {
  18912. var program = gl.createProgram();
  18913. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  18914. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  18915. var prefix = "precision " + renderer.getPrecision() + " float;\n";
  18916. gl.shaderSource( fragmentShader, prefix + shader.fragmentShader );
  18917. gl.shaderSource( vertexShader, prefix + shader.vertexShader );
  18918. gl.compileShader( fragmentShader );
  18919. gl.compileShader( vertexShader );
  18920. gl.attachShader( program, fragmentShader );
  18921. gl.attachShader( program, vertexShader );
  18922. gl.linkProgram( program );
  18923. return program;
  18924. }
  18925. };
  18926. // File:src/renderers/webgl/plugins/SpritePlugin.js
  18927. /**
  18928. * @author mikael emtinger / http://gomo.se/
  18929. * @author alteredq / http://alteredqualia.com/
  18930. */
  18931. THREE.SpritePlugin = function ( renderer, sprites ) {
  18932. var gl = renderer.context;
  18933. var state = renderer.state;
  18934. var vertexBuffer, elementBuffer;
  18935. var program, attributes, uniforms;
  18936. var texture;
  18937. // decompose matrixWorld
  18938. var spritePosition = new THREE.Vector3();
  18939. var spriteRotation = new THREE.Quaternion();
  18940. var spriteScale = new THREE.Vector3();
  18941. function init() {
  18942. var vertices = new Float32Array( [
  18943. - 0.5, - 0.5, 0, 0,
  18944. 0.5, - 0.5, 1, 0,
  18945. 0.5, 0.5, 1, 1,
  18946. - 0.5, 0.5, 0, 1
  18947. ] );
  18948. var faces = new Uint16Array( [
  18949. 0, 1, 2,
  18950. 0, 2, 3
  18951. ] );
  18952. vertexBuffer = gl.createBuffer();
  18953. elementBuffer = gl.createBuffer();
  18954. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  18955. gl.bufferData( gl.ARRAY_BUFFER, vertices, gl.STATIC_DRAW );
  18956. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  18957. gl.bufferData( gl.ELEMENT_ARRAY_BUFFER, faces, gl.STATIC_DRAW );
  18958. program = createProgram();
  18959. attributes = {
  18960. position: gl.getAttribLocation ( program, 'position' ),
  18961. uv: gl.getAttribLocation ( program, 'uv' )
  18962. };
  18963. uniforms = {
  18964. uvOffset: gl.getUniformLocation( program, 'uvOffset' ),
  18965. uvScale: gl.getUniformLocation( program, 'uvScale' ),
  18966. rotation: gl.getUniformLocation( program, 'rotation' ),
  18967. scale: gl.getUniformLocation( program, 'scale' ),
  18968. color: gl.getUniformLocation( program, 'color' ),
  18969. map: gl.getUniformLocation( program, 'map' ),
  18970. opacity: gl.getUniformLocation( program, 'opacity' ),
  18971. modelViewMatrix: gl.getUniformLocation( program, 'modelViewMatrix' ),
  18972. projectionMatrix: gl.getUniformLocation( program, 'projectionMatrix' ),
  18973. fogType: gl.getUniformLocation( program, 'fogType' ),
  18974. fogDensity: gl.getUniformLocation( program, 'fogDensity' ),
  18975. fogNear: gl.getUniformLocation( program, 'fogNear' ),
  18976. fogFar: gl.getUniformLocation( program, 'fogFar' ),
  18977. fogColor: gl.getUniformLocation( program, 'fogColor' ),
  18978. alphaTest: gl.getUniformLocation( program, 'alphaTest' )
  18979. };
  18980. var canvas = document.createElement( 'canvas' );
  18981. canvas.width = 8;
  18982. canvas.height = 8;
  18983. var context = canvas.getContext( '2d' );
  18984. context.fillStyle = 'white';
  18985. context.fillRect( 0, 0, 8, 8 );
  18986. texture = new THREE.Texture( canvas );
  18987. texture.needsUpdate = true;
  18988. }
  18989. this.render = function ( scene, camera ) {
  18990. if ( sprites.length === 0 ) return;
  18991. // setup gl
  18992. if ( program === undefined ) {
  18993. init();
  18994. }
  18995. gl.useProgram( program );
  18996. state.initAttributes();
  18997. state.enableAttribute( attributes.position );
  18998. state.enableAttribute( attributes.uv );
  18999. state.disableUnusedAttributes();
  19000. state.disable( gl.CULL_FACE );
  19001. state.enable( gl.BLEND );
  19002. gl.bindBuffer( gl.ARRAY_BUFFER, vertexBuffer );
  19003. gl.vertexAttribPointer( attributes.position, 2, gl.FLOAT, false, 2 * 8, 0 );
  19004. gl.vertexAttribPointer( attributes.uv, 2, gl.FLOAT, false, 2 * 8, 8 );
  19005. gl.bindBuffer( gl.ELEMENT_ARRAY_BUFFER, elementBuffer );
  19006. gl.uniformMatrix4fv( uniforms.projectionMatrix, false, camera.projectionMatrix.elements );
  19007. state.activeTexture( gl.TEXTURE0 );
  19008. gl.uniform1i( uniforms.map, 0 );
  19009. var oldFogType = 0;
  19010. var sceneFogType = 0;
  19011. var fog = scene.fog;
  19012. if ( fog ) {
  19013. gl.uniform3f( uniforms.fogColor, fog.color.r, fog.color.g, fog.color.b );
  19014. if ( fog instanceof THREE.Fog ) {
  19015. gl.uniform1f( uniforms.fogNear, fog.near );
  19016. gl.uniform1f( uniforms.fogFar, fog.far );
  19017. gl.uniform1i( uniforms.fogType, 1 );
  19018. oldFogType = 1;
  19019. sceneFogType = 1;
  19020. } else if ( fog instanceof THREE.FogExp2 ) {
  19021. gl.uniform1f( uniforms.fogDensity, fog.density );
  19022. gl.uniform1i( uniforms.fogType, 2 );
  19023. oldFogType = 2;
  19024. sceneFogType = 2;
  19025. }
  19026. } else {
  19027. gl.uniform1i( uniforms.fogType, 0 );
  19028. oldFogType = 0;
  19029. sceneFogType = 0;
  19030. }
  19031. // update positions and sort
  19032. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19033. var sprite = sprites[ i ];
  19034. sprite.modelViewMatrix.multiplyMatrices( camera.matrixWorldInverse, sprite.matrixWorld );
  19035. sprite.z = - sprite.modelViewMatrix.elements[ 14 ];
  19036. }
  19037. sprites.sort( painterSortStable );
  19038. // render all sprites
  19039. var scale = [];
  19040. for ( var i = 0, l = sprites.length; i < l; i ++ ) {
  19041. var sprite = sprites[ i ];
  19042. var material = sprite.material;
  19043. gl.uniform1f( uniforms.alphaTest, material.alphaTest );
  19044. gl.uniformMatrix4fv( uniforms.modelViewMatrix, false, sprite.modelViewMatrix.elements );
  19045. sprite.matrixWorld.decompose( spritePosition, spriteRotation, spriteScale );
  19046. scale[ 0 ] = spriteScale.x;
  19047. scale[ 1 ] = spriteScale.y;
  19048. var fogType = 0;
  19049. if ( scene.fog && material.fog ) {
  19050. fogType = sceneFogType;
  19051. }
  19052. if ( oldFogType !== fogType ) {
  19053. gl.uniform1i( uniforms.fogType, fogType );
  19054. oldFogType = fogType;
  19055. }
  19056. if ( material.map !== null ) {
  19057. gl.uniform2f( uniforms.uvOffset, material.map.offset.x, material.map.offset.y );
  19058. gl.uniform2f( uniforms.uvScale, material.map.repeat.x, material.map.repeat.y );
  19059. } else {
  19060. gl.uniform2f( uniforms.uvOffset, 0, 0 );
  19061. gl.uniform2f( uniforms.uvScale, 1, 1 );
  19062. }
  19063. gl.uniform1f( uniforms.opacity, material.opacity );
  19064. gl.uniform3f( uniforms.color, material.color.r, material.color.g, material.color.b );
  19065. gl.uniform1f( uniforms.rotation, material.rotation );
  19066. gl.uniform2fv( uniforms.scale, scale );
  19067. state.setBlending( material.blending, material.blendEquation, material.blendSrc, material.blendDst );
  19068. state.setDepthTest( material.depthTest );
  19069. state.setDepthWrite( material.depthWrite );
  19070. if ( material.map && material.map.image && material.map.image.width ) {
  19071. renderer.setTexture( material.map, 0 );
  19072. } else {
  19073. renderer.setTexture( texture, 0 );
  19074. }
  19075. gl.drawElements( gl.TRIANGLES, 6, gl.UNSIGNED_SHORT, 0 );
  19076. }
  19077. // restore gl
  19078. state.enable( gl.CULL_FACE );
  19079. renderer.resetGLState();
  19080. };
  19081. function createProgram () {
  19082. var program = gl.createProgram();
  19083. var vertexShader = gl.createShader( gl.VERTEX_SHADER );
  19084. var fragmentShader = gl.createShader( gl.FRAGMENT_SHADER );
  19085. gl.shaderSource( vertexShader, [
  19086. 'precision ' + renderer.getPrecision() + ' float;',
  19087. 'uniform mat4 modelViewMatrix;',
  19088. 'uniform mat4 projectionMatrix;',
  19089. 'uniform float rotation;',
  19090. 'uniform vec2 scale;',
  19091. 'uniform vec2 uvOffset;',
  19092. 'uniform vec2 uvScale;',
  19093. 'attribute vec2 position;',
  19094. 'attribute vec2 uv;',
  19095. 'varying vec2 vUV;',
  19096. 'void main() {',
  19097. 'vUV = uvOffset + uv * uvScale;',
  19098. 'vec2 alignedPosition = position * scale;',
  19099. 'vec2 rotatedPosition;',
  19100. 'rotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;',
  19101. 'rotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;',
  19102. 'vec4 finalPosition;',
  19103. 'finalPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );',
  19104. 'finalPosition.xy += rotatedPosition;',
  19105. 'finalPosition = projectionMatrix * finalPosition;',
  19106. 'gl_Position = finalPosition;',
  19107. '}'
  19108. ].join( '\n' ) );
  19109. gl.shaderSource( fragmentShader, [
  19110. 'precision ' + renderer.getPrecision() + ' float;',
  19111. 'uniform vec3 color;',
  19112. 'uniform sampler2D map;',
  19113. 'uniform float opacity;',
  19114. 'uniform int fogType;',
  19115. 'uniform vec3 fogColor;',
  19116. 'uniform float fogDensity;',
  19117. 'uniform float fogNear;',
  19118. 'uniform float fogFar;',
  19119. 'uniform float alphaTest;',
  19120. 'varying vec2 vUV;',
  19121. 'void main() {',
  19122. 'vec4 texture = texture2D( map, vUV );',
  19123. 'if ( texture.a < alphaTest ) discard;',
  19124. 'gl_FragColor = vec4( color * texture.xyz, texture.a * opacity );',
  19125. 'if ( fogType > 0 ) {',
  19126. 'float depth = gl_FragCoord.z / gl_FragCoord.w;',
  19127. 'float fogFactor = 0.0;',
  19128. 'if ( fogType == 1 ) {',
  19129. 'fogFactor = smoothstep( fogNear, fogFar, depth );',
  19130. '} else {',
  19131. 'const float LOG2 = 1.442695;',
  19132. 'fogFactor = exp2( - fogDensity * fogDensity * depth * depth * LOG2 );',
  19133. 'fogFactor = 1.0 - clamp( fogFactor, 0.0, 1.0 );',
  19134. '}',
  19135. 'gl_FragColor = mix( gl_FragColor, vec4( fogColor, gl_FragColor.w ), fogFactor );',
  19136. '}',
  19137. '}'
  19138. ].join( '\n' ) );
  19139. gl.compileShader( vertexShader );
  19140. gl.compileShader( fragmentShader );
  19141. gl.attachShader( program, vertexShader );
  19142. gl.attachShader( program, fragmentShader );
  19143. gl.linkProgram( program );
  19144. return program;
  19145. }
  19146. function painterSortStable ( a, b ) {
  19147. if ( a.renderOrder !== b.renderOrder ) {
  19148. return a.renderOrder - b.renderOrder;
  19149. } else if ( a.z !== b.z ) {
  19150. return b.z - a.z;
  19151. } else {
  19152. return b.id - a.id;
  19153. }
  19154. }
  19155. };
  19156. // File:src/Three.Legacy.js
  19157. /**
  19158. * @author mrdoob / http://mrdoob.com/
  19159. */
  19160. Object.defineProperties( THREE.Box2.prototype, {
  19161. empty: {
  19162. value: function () {
  19163. console.warn( 'THREE.Box2: .empty() has been renamed to .isEmpty().' );
  19164. return this.isEmpty();
  19165. }
  19166. },
  19167. isIntersectionBox: {
  19168. value: function ( box ) {
  19169. console.warn( 'THREE.Box2: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19170. return this.intersectsBox( box );
  19171. }
  19172. }
  19173. } );
  19174. Object.defineProperties( THREE.Box3.prototype, {
  19175. empty: {
  19176. value: function () {
  19177. console.warn( 'THREE.Box3: .empty() has been renamed to .isEmpty().' );
  19178. return this.isEmpty();
  19179. }
  19180. },
  19181. isIntersectionBox: {
  19182. value: function ( box ) {
  19183. console.warn( 'THREE.Box3: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19184. return this.intersectsBox( box );
  19185. }
  19186. },
  19187. isIntersectionSphere: {
  19188. value: function ( sphere ) {
  19189. console.warn( 'THREE.Box3: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19190. return this.intersectsSphere( sphere );
  19191. }
  19192. }
  19193. } );
  19194. Object.defineProperties( THREE.Matrix3.prototype, {
  19195. multiplyVector3: {
  19196. value: function ( vector ) {
  19197. console.warn( 'THREE.Matrix3: .multiplyVector3() has been removed. Use vector.applyMatrix3( matrix ) instead.' );
  19198. return vector.applyMatrix3( this );
  19199. }
  19200. },
  19201. multiplyVector3Array: {
  19202. value: function ( a ) {
  19203. console.warn( 'THREE.Matrix3: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19204. return this.applyToVector3Array( a );
  19205. }
  19206. }
  19207. } );
  19208. Object.defineProperties( THREE.Matrix4.prototype, {
  19209. extractPosition: {
  19210. value: function ( m ) {
  19211. console.warn( 'THREE.Matrix4: .extractPosition() has been renamed to .copyPosition().' );
  19212. return this.copyPosition( m );
  19213. }
  19214. },
  19215. setRotationFromQuaternion: {
  19216. value: function ( q ) {
  19217. console.warn( 'THREE.Matrix4: .setRotationFromQuaternion() has been renamed to .makeRotationFromQuaternion().' );
  19218. return this.makeRotationFromQuaternion( q );
  19219. }
  19220. },
  19221. multiplyVector3: {
  19222. value: function ( vector ) {
  19223. console.warn( 'THREE.Matrix4: .multiplyVector3() has been removed. Use vector.applyMatrix4( matrix ) or vector.applyProjection( matrix ) instead.' );
  19224. return vector.applyProjection( this );
  19225. }
  19226. },
  19227. multiplyVector4: {
  19228. value: function ( vector ) {
  19229. console.warn( 'THREE.Matrix4: .multiplyVector4() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19230. return vector.applyMatrix4( this );
  19231. }
  19232. },
  19233. multiplyVector3Array: {
  19234. value: function ( a ) {
  19235. console.warn( 'THREE.Matrix4: .multiplyVector3Array() has been renamed. Use matrix.applyToVector3Array( array ) instead.' );
  19236. return this.applyToVector3Array( a );
  19237. }
  19238. },
  19239. rotateAxis: {
  19240. value: function ( v ) {
  19241. console.warn( 'THREE.Matrix4: .rotateAxis() has been removed. Use Vector3.transformDirection( matrix ) instead.' );
  19242. v.transformDirection( this );
  19243. }
  19244. },
  19245. crossVector: {
  19246. value: function ( vector ) {
  19247. console.warn( 'THREE.Matrix4: .crossVector() has been removed. Use vector.applyMatrix4( matrix ) instead.' );
  19248. return vector.applyMatrix4( this );
  19249. }
  19250. },
  19251. translate: {
  19252. value: function ( v ) {
  19253. console.error( 'THREE.Matrix4: .translate() has been removed.' );
  19254. }
  19255. },
  19256. rotateX: {
  19257. value: function ( angle ) {
  19258. console.error( 'THREE.Matrix4: .rotateX() has been removed.' );
  19259. }
  19260. },
  19261. rotateY: {
  19262. value: function ( angle ) {
  19263. console.error( 'THREE.Matrix4: .rotateY() has been removed.' );
  19264. }
  19265. },
  19266. rotateZ: {
  19267. value: function ( angle ) {
  19268. console.error( 'THREE.Matrix4: .rotateZ() has been removed.' );
  19269. }
  19270. },
  19271. rotateByAxis: {
  19272. value: function ( axis, angle ) {
  19273. console.error( 'THREE.Matrix4: .rotateByAxis() has been removed.' );
  19274. }
  19275. }
  19276. } );
  19277. Object.defineProperties( THREE.Plane.prototype, {
  19278. isIntersectionLine: {
  19279. value: function ( line ) {
  19280. console.warn( 'THREE.Plane: .isIntersectionLine() has been renamed to .intersectsLine().' );
  19281. return this.intersectsLine( line );
  19282. }
  19283. }
  19284. } );
  19285. Object.defineProperties( THREE.Quaternion.prototype, {
  19286. multiplyVector3: {
  19287. value: function ( vector ) {
  19288. console.warn( 'THREE.Quaternion: .multiplyVector3() has been removed. Use is now vector.applyQuaternion( quaternion ) instead.' );
  19289. return vector.applyQuaternion( this );
  19290. }
  19291. }
  19292. } );
  19293. Object.defineProperties( THREE.Ray.prototype, {
  19294. isIntersectionBox: {
  19295. value: function ( box ) {
  19296. console.warn( 'THREE.Ray: .isIntersectionBox() has been renamed to .intersectsBox().' );
  19297. return this.intersectsBox( box );
  19298. }
  19299. },
  19300. isIntersectionPlane: {
  19301. value: function ( plane ) {
  19302. console.warn( 'THREE.Ray: .isIntersectionPlane() has been renamed to .intersectsPlane().' );
  19303. return this.intersectsPlane( plane );
  19304. }
  19305. },
  19306. isIntersectionSphere: {
  19307. value: function ( sphere ) {
  19308. console.warn( 'THREE.Ray: .isIntersectionSphere() has been renamed to .intersectsSphere().' );
  19309. return this.intersectsSphere( sphere );
  19310. }
  19311. }
  19312. } );
  19313. Object.defineProperties( THREE.Vector3.prototype, {
  19314. setEulerFromRotationMatrix: {
  19315. value: function () {
  19316. console.error( 'THREE.Vector3: .setEulerFromRotationMatrix() has been removed. Use Euler.setFromRotationMatrix() instead.' );
  19317. }
  19318. },
  19319. setEulerFromQuaternion: {
  19320. value: function () {
  19321. console.error( 'THREE.Vector3: .setEulerFromQuaternion() has been removed. Use Euler.setFromQuaternion() instead.' );
  19322. }
  19323. },
  19324. getPositionFromMatrix: {
  19325. value: function ( m ) {
  19326. console.warn( 'THREE.Vector3: .getPositionFromMatrix() has been renamed to .setFromMatrixPosition().' );
  19327. return this.setFromMatrixPosition( m );
  19328. }
  19329. },
  19330. getScaleFromMatrix: {
  19331. value: function ( m ) {
  19332. console.warn( 'THREE.Vector3: .getScaleFromMatrix() has been renamed to .setFromMatrixScale().' );
  19333. return this.setFromMatrixScale( m );
  19334. }
  19335. },
  19336. getColumnFromMatrix: {
  19337. value: function ( index, matrix ) {
  19338. console.warn( 'THREE.Vector3: .getColumnFromMatrix() has been renamed to .setFromMatrixColumn().' );
  19339. return this.setFromMatrixColumn( index, matrix );
  19340. }
  19341. }
  19342. } );
  19343. //
  19344. THREE.Face4 = function ( a, b, c, d, normal, color, materialIndex ) {
  19345. console.warn( 'THREE.Face4 has been removed. A THREE.Face3 will be created instead.' );
  19346. return new THREE.Face3( a, b, c, normal, color, materialIndex );
  19347. };
  19348. //
  19349. Object.defineProperties( THREE.Object3D.prototype, {
  19350. eulerOrder: {
  19351. get: function () {
  19352. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19353. return this.rotation.order;
  19354. },
  19355. set: function ( value ) {
  19356. console.warn( 'THREE.Object3D: .eulerOrder is now .rotation.order.' );
  19357. this.rotation.order = value;
  19358. }
  19359. },
  19360. getChildByName: {
  19361. value: function ( name ) {
  19362. console.warn( 'THREE.Object3D: .getChildByName() has been renamed to .getObjectByName().' );
  19363. return this.getObjectByName( name );
  19364. }
  19365. },
  19366. renderDepth: {
  19367. set: function ( value ) {
  19368. console.warn( 'THREE.Object3D: .renderDepth has been removed. Use .renderOrder, instead.' );
  19369. }
  19370. },
  19371. translate: {
  19372. value: function ( distance, axis ) {
  19373. console.warn( 'THREE.Object3D: .translate() has been removed. Use .translateOnAxis( axis, distance ) instead.' );
  19374. return this.translateOnAxis( axis, distance );
  19375. }
  19376. },
  19377. useQuaternion: {
  19378. get: function () {
  19379. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19380. },
  19381. set: function ( value ) {
  19382. console.warn( 'THREE.Object3D: .useQuaternion has been removed. The library now uses quaternions by default.' );
  19383. }
  19384. }
  19385. } );
  19386. //
  19387. Object.defineProperties( THREE, {
  19388. PointCloud: {
  19389. value: function ( geometry, material ) {
  19390. console.warn( 'THREE.PointCloud has been renamed to THREE.Points.' );
  19391. return new THREE.Points( geometry, material );
  19392. }
  19393. },
  19394. ParticleSystem: {
  19395. value: function ( geometry, material ) {
  19396. console.warn( 'THREE.ParticleSystem has been renamed to THREE.Points.' );
  19397. return new THREE.Points( geometry, material );
  19398. }
  19399. }
  19400. } );
  19401. //
  19402. Object.defineProperties( THREE.Light.prototype, {
  19403. onlyShadow: {
  19404. set: function ( value ) {
  19405. console.warn( 'THREE.Light: .onlyShadow has been removed.' );
  19406. }
  19407. },
  19408. shadowCameraFov: {
  19409. set: function ( value ) {
  19410. console.warn( 'THREE.Light: .shadowCameraFov is now .shadow.camera.fov.' );
  19411. this.shadow.camera.fov = value;
  19412. }
  19413. },
  19414. shadowCameraLeft: {
  19415. set: function ( value ) {
  19416. console.warn( 'THREE.Light: .shadowCameraLeft is now .shadow.camera.left.' );
  19417. this.shadow.camera.left = value;
  19418. }
  19419. },
  19420. shadowCameraRight: {
  19421. set: function ( value ) {
  19422. console.warn( 'THREE.Light: .shadowCameraRight is now .shadow.camera.right.' );
  19423. this.shadow.camera.right = value;
  19424. }
  19425. },
  19426. shadowCameraTop: {
  19427. set: function ( value ) {
  19428. console.warn( 'THREE.Light: .shadowCameraTop is now .shadow.camera.top.' );
  19429. this.shadow.camera.top = value;
  19430. }
  19431. },
  19432. shadowCameraBottom: {
  19433. set: function ( value ) {
  19434. console.warn( 'THREE.Light: .shadowCameraBottom is now .shadow.camera.bottom.' );
  19435. this.shadow.camera.bottom = value;
  19436. }
  19437. },
  19438. shadowCameraNear: {
  19439. set: function ( value ) {
  19440. console.warn( 'THREE.Light: .shadowCameraNear is now .shadow.camera.near.' );
  19441. this.shadow.camera.near = value;
  19442. }
  19443. },
  19444. shadowCameraFar: {
  19445. set: function ( value ) {
  19446. console.warn( 'THREE.Light: .shadowCameraFar is now .shadow.camera.far.' );
  19447. this.shadow.camera.far = value;
  19448. }
  19449. },
  19450. shadowCameraVisible: {
  19451. set: function ( value ) {
  19452. console.warn( 'THREE.Light: .shadowCameraVisible has been removed. Use new THREE.CameraHelper( light.shadow.camera ) instead.' );
  19453. }
  19454. },
  19455. shadowBias: {
  19456. set: function ( value ) {
  19457. console.warn( 'THREE.Light: .shadowBias is now .shadow.bias.' );
  19458. this.shadow.bias = value;
  19459. }
  19460. },
  19461. shadowDarkness: {
  19462. set: function ( value ) {
  19463. console.warn( 'THREE.Light: .shadowDarkness has been removed.' );
  19464. }
  19465. },
  19466. shadowMapWidth: {
  19467. set: function ( value ) {
  19468. console.warn( 'THREE.Light: .shadowMapWidth is now .shadow.mapSize.width.' );
  19469. this.shadow.mapSize.width = value;
  19470. }
  19471. },
  19472. shadowMapHeight: {
  19473. set: function ( value ) {
  19474. console.warn( 'THREE.Light: .shadowMapHeight is now .shadow.mapSize.height.' );
  19475. this.shadow.mapSize.height = value;
  19476. }
  19477. }
  19478. } );
  19479. //
  19480. Object.defineProperties( THREE.BufferAttribute.prototype, {
  19481. length: {
  19482. get: function () {
  19483. console.warn( 'THREE.BufferAttribute: .length has been deprecated. Please use .count.' );
  19484. return this.array.length;
  19485. }
  19486. }
  19487. } );
  19488. Object.defineProperties( THREE.BufferGeometry.prototype, {
  19489. drawcalls: {
  19490. get: function () {
  19491. console.error( 'THREE.BufferGeometry: .drawcalls has been renamed to .groups.' );
  19492. return this.groups;
  19493. }
  19494. },
  19495. offsets: {
  19496. get: function () {
  19497. console.warn( 'THREE.BufferGeometry: .offsets has been renamed to .groups.' );
  19498. return this.groups;
  19499. }
  19500. },
  19501. addIndex: {
  19502. value: function ( index ) {
  19503. console.warn( 'THREE.BufferGeometry: .addIndex() has been renamed to .setIndex().' );
  19504. this.setIndex( index );
  19505. }
  19506. },
  19507. addDrawCall: {
  19508. value: function ( start, count, indexOffset ) {
  19509. if ( indexOffset !== undefined ) {
  19510. console.warn( 'THREE.BufferGeometry: .addDrawCall() no longer supports indexOffset.' );
  19511. }
  19512. console.warn( 'THREE.BufferGeometry: .addDrawCall() is now .addGroup().' );
  19513. this.addGroup( start, count );
  19514. }
  19515. },
  19516. clearDrawCalls: {
  19517. value: function () {
  19518. console.warn( 'THREE.BufferGeometry: .clearDrawCalls() is now .clearGroups().' );
  19519. this.clearGroups();
  19520. }
  19521. },
  19522. computeTangents: {
  19523. value: function () {
  19524. console.warn( 'THREE.BufferGeometry: .computeTangents() has been removed.' );
  19525. }
  19526. },
  19527. computeOffsets: {
  19528. value: function () {
  19529. console.warn( 'THREE.BufferGeometry: .computeOffsets() has been removed.' );
  19530. }
  19531. }
  19532. } );
  19533. //
  19534. Object.defineProperties( THREE.Material.prototype, {
  19535. wrapAround: {
  19536. get: function () {
  19537. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19538. },
  19539. set: function ( value ) {
  19540. console.warn( 'THREE.' + this.type + ': .wrapAround has been removed.' );
  19541. }
  19542. },
  19543. wrapRGB: {
  19544. get: function () {
  19545. console.warn( 'THREE.' + this.type + ': .wrapRGB has been removed.' );
  19546. return new THREE.Color();
  19547. }
  19548. }
  19549. } );
  19550. Object.defineProperties( THREE, {
  19551. PointCloudMaterial: {
  19552. value: function ( parameters ) {
  19553. console.warn( 'THREE.PointCloudMaterial has been renamed to THREE.PointsMaterial.' );
  19554. return new THREE.PointsMaterial( parameters );
  19555. }
  19556. },
  19557. ParticleBasicMaterial: {
  19558. value: function ( parameters ) {
  19559. console.warn( 'THREE.ParticleBasicMaterial has been renamed to THREE.PointsMaterial.' );
  19560. return new THREE.PointsMaterial( parameters );
  19561. }
  19562. },
  19563. ParticleSystemMaterial:{
  19564. value: function ( parameters ) {
  19565. console.warn( 'THREE.ParticleSystemMaterial has been renamed to THREE.PointsMaterial.' );
  19566. return new THREE.PointsMaterial( parameters );
  19567. }
  19568. }
  19569. } );
  19570. Object.defineProperties( THREE.MeshPhongMaterial.prototype, {
  19571. metal: {
  19572. get: function () {
  19573. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead.' );
  19574. return false;
  19575. },
  19576. set: function ( value ) {
  19577. console.warn( 'THREE.MeshPhongMaterial: .metal has been removed. Use THREE.MeshStandardMaterial instead' );
  19578. }
  19579. }
  19580. } );
  19581. Object.defineProperties( THREE.ShaderMaterial.prototype, {
  19582. derivatives: {
  19583. get: function () {
  19584. console.warn( 'THREE.ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19585. return this.extensions.derivatives;
  19586. },
  19587. set: function ( value ) {
  19588. console.warn( 'THREE. ShaderMaterial: .derivatives has been moved to .extensions.derivatives.' );
  19589. this.extensions.derivatives = value;
  19590. }
  19591. }
  19592. } );
  19593. //
  19594. Object.defineProperties( THREE.WebGLRenderer.prototype, {
  19595. supportsFloatTextures: {
  19596. value: function () {
  19597. console.warn( 'THREE.WebGLRenderer: .supportsFloatTextures() is now .extensions.get( \'OES_texture_float\' ).' );
  19598. return this.extensions.get( 'OES_texture_float' );
  19599. }
  19600. },
  19601. supportsHalfFloatTextures: {
  19602. value: function () {
  19603. console.warn( 'THREE.WebGLRenderer: .supportsHalfFloatTextures() is now .extensions.get( \'OES_texture_half_float\' ).' );
  19604. return this.extensions.get( 'OES_texture_half_float' );
  19605. }
  19606. },
  19607. supportsStandardDerivatives: {
  19608. value: function () {
  19609. console.warn( 'THREE.WebGLRenderer: .supportsStandardDerivatives() is now .extensions.get( \'OES_standard_derivatives\' ).' );
  19610. return this.extensions.get( 'OES_standard_derivatives' );
  19611. }
  19612. },
  19613. supportsCompressedTextureS3TC: {
  19614. value: function () {
  19615. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTextureS3TC() is now .extensions.get( \'WEBGL_compressed_texture_s3tc\' ).' );
  19616. return this.extensions.get( 'WEBGL_compressed_texture_s3tc' );
  19617. }
  19618. },
  19619. supportsCompressedTexturePVRTC: {
  19620. value: function () {
  19621. console.warn( 'THREE.WebGLRenderer: .supportsCompressedTexturePVRTC() is now .extensions.get( \'WEBGL_compressed_texture_pvrtc\' ).' );
  19622. return this.extensions.get( 'WEBGL_compressed_texture_pvrtc' );
  19623. }
  19624. },
  19625. supportsBlendMinMax: {
  19626. value: function () {
  19627. console.warn( 'THREE.WebGLRenderer: .supportsBlendMinMax() is now .extensions.get( \'EXT_blend_minmax\' ).' );
  19628. return this.extensions.get( 'EXT_blend_minmax' );
  19629. }
  19630. },
  19631. supportsVertexTextures: {
  19632. value: function () {
  19633. return this.capabilities.vertexTextures;
  19634. }
  19635. },
  19636. supportsInstancedArrays: {
  19637. value: function () {
  19638. console.warn( 'THREE.WebGLRenderer: .supportsInstancedArrays() is now .extensions.get( \'ANGLE_instanced_arrays\' ).' );
  19639. return this.extensions.get( 'ANGLE_instanced_arrays' );
  19640. }
  19641. },
  19642. enableScissorTest: {
  19643. value: function ( boolean ) {
  19644. console.warn( 'THREE.WebGLRenderer: .enableScissorTest() is now .setScissorTest().' );
  19645. this.setScissorTest( boolean );
  19646. }
  19647. },
  19648. initMaterial: {
  19649. value: function () {
  19650. console.warn( 'THREE.WebGLRenderer: .initMaterial() has been removed.' );
  19651. }
  19652. },
  19653. addPrePlugin: {
  19654. value: function () {
  19655. console.warn( 'THREE.WebGLRenderer: .addPrePlugin() has been removed.' );
  19656. }
  19657. },
  19658. addPostPlugin: {
  19659. value: function () {
  19660. console.warn( 'THREE.WebGLRenderer: .addPostPlugin() has been removed.' );
  19661. }
  19662. },
  19663. updateShadowMap: {
  19664. value: function () {
  19665. console.warn( 'THREE.WebGLRenderer: .updateShadowMap() has been removed.' );
  19666. }
  19667. },
  19668. shadowMapEnabled: {
  19669. get: function () {
  19670. return this.shadowMap.enabled;
  19671. },
  19672. set: function ( value ) {
  19673. console.warn( 'THREE.WebGLRenderer: .shadowMapEnabled is now .shadowMap.enabled.' );
  19674. this.shadowMap.enabled = value;
  19675. }
  19676. },
  19677. shadowMapType: {
  19678. get: function () {
  19679. return this.shadowMap.type;
  19680. },
  19681. set: function ( value ) {
  19682. console.warn( 'THREE.WebGLRenderer: .shadowMapType is now .shadowMap.type.' );
  19683. this.shadowMap.type = value;
  19684. }
  19685. },
  19686. shadowMapCullFace: {
  19687. get: function () {
  19688. return this.shadowMap.cullFace;
  19689. },
  19690. set: function ( value ) {
  19691. console.warn( 'THREE.WebGLRenderer: .shadowMapCullFace is now .shadowMap.cullFace.' );
  19692. this.shadowMap.cullFace = value;
  19693. }
  19694. }
  19695. } );
  19696. //
  19697. Object.defineProperties( THREE.WebGLRenderTarget.prototype, {
  19698. wrapS: {
  19699. get: function () {
  19700. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19701. return this.texture.wrapS;
  19702. },
  19703. set: function ( value ) {
  19704. console.warn( 'THREE.WebGLRenderTarget: .wrapS is now .texture.wrapS.' );
  19705. this.texture.wrapS = value;
  19706. }
  19707. },
  19708. wrapT: {
  19709. get: function () {
  19710. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19711. return this.texture.wrapT;
  19712. },
  19713. set: function ( value ) {
  19714. console.warn( 'THREE.WebGLRenderTarget: .wrapT is now .texture.wrapT.' );
  19715. this.texture.wrapT = value;
  19716. }
  19717. },
  19718. magFilter: {
  19719. get: function () {
  19720. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19721. return this.texture.magFilter;
  19722. },
  19723. set: function ( value ) {
  19724. console.warn( 'THREE.WebGLRenderTarget: .magFilter is now .texture.magFilter.' );
  19725. this.texture.magFilter = value;
  19726. }
  19727. },
  19728. minFilter: {
  19729. get: function () {
  19730. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19731. return this.texture.minFilter;
  19732. },
  19733. set: function ( value ) {
  19734. console.warn( 'THREE.WebGLRenderTarget: .minFilter is now .texture.minFilter.' );
  19735. this.texture.minFilter = value;
  19736. }
  19737. },
  19738. anisotropy: {
  19739. get: function () {
  19740. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19741. return this.texture.anisotropy;
  19742. },
  19743. set: function ( value ) {
  19744. console.warn( 'THREE.WebGLRenderTarget: .anisotropy is now .texture.anisotropy.' );
  19745. this.texture.anisotropy = value;
  19746. }
  19747. },
  19748. offset: {
  19749. get: function () {
  19750. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19751. return this.texture.offset;
  19752. },
  19753. set: function ( value ) {
  19754. console.warn( 'THREE.WebGLRenderTarget: .offset is now .texture.offset.' );
  19755. this.texture.offset = value;
  19756. }
  19757. },
  19758. repeat: {
  19759. get: function () {
  19760. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19761. return this.texture.repeat;
  19762. },
  19763. set: function ( value ) {
  19764. console.warn( 'THREE.WebGLRenderTarget: .repeat is now .texture.repeat.' );
  19765. this.texture.repeat = value;
  19766. }
  19767. },
  19768. format: {
  19769. get: function () {
  19770. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19771. return this.texture.format;
  19772. },
  19773. set: function ( value ) {
  19774. console.warn( 'THREE.WebGLRenderTarget: .format is now .texture.format.' );
  19775. this.texture.format = value;
  19776. }
  19777. },
  19778. type: {
  19779. get: function () {
  19780. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19781. return this.texture.type;
  19782. },
  19783. set: function ( value ) {
  19784. console.warn( 'THREE.WebGLRenderTarget: .type is now .texture.type.' );
  19785. this.texture.type = value;
  19786. }
  19787. },
  19788. generateMipmaps: {
  19789. get: function () {
  19790. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19791. return this.texture.generateMipmaps;
  19792. },
  19793. set: function ( value ) {
  19794. console.warn( 'THREE.WebGLRenderTarget: .generateMipmaps is now .texture.generateMipmaps.' );
  19795. this.texture.generateMipmaps = value;
  19796. }
  19797. }
  19798. } );
  19799. //
  19800. THREE.GeometryUtils = {
  19801. merge: function ( geometry1, geometry2, materialIndexOffset ) {
  19802. console.warn( 'THREE.GeometryUtils: .merge() has been moved to Geometry. Use geometry.merge( geometry2, matrix, materialIndexOffset ) instead.' );
  19803. var matrix;
  19804. if ( geometry2 instanceof THREE.Mesh ) {
  19805. geometry2.matrixAutoUpdate && geometry2.updateMatrix();
  19806. matrix = geometry2.matrix;
  19807. geometry2 = geometry2.geometry;
  19808. }
  19809. geometry1.merge( geometry2, matrix, materialIndexOffset );
  19810. },
  19811. center: function ( geometry ) {
  19812. console.warn( 'THREE.GeometryUtils: .center() has been moved to Geometry. Use geometry.center() instead.' );
  19813. return geometry.center();
  19814. }
  19815. };
  19816. THREE.ImageUtils = {
  19817. crossOrigin: undefined,
  19818. loadTexture: function ( url, mapping, onLoad, onError ) {
  19819. console.warn( 'THREE.ImageUtils.loadTexture has been deprecated. Use THREE.TextureLoader() instead.' );
  19820. var loader = new THREE.TextureLoader();
  19821. loader.setCrossOrigin( this.crossOrigin );
  19822. var texture = loader.load( url, onLoad, undefined, onError );
  19823. if ( mapping ) texture.mapping = mapping;
  19824. return texture;
  19825. },
  19826. loadTextureCube: function ( urls, mapping, onLoad, onError ) {
  19827. console.warn( 'THREE.ImageUtils.loadTextureCube has been deprecated. Use THREE.CubeTextureLoader() instead.' );
  19828. var loader = new THREE.CubeTextureLoader();
  19829. loader.setCrossOrigin( this.crossOrigin );
  19830. var texture = loader.load( urls, onLoad, undefined, onError );
  19831. if ( mapping ) texture.mapping = mapping;
  19832. return texture;
  19833. },
  19834. loadCompressedTexture: function () {
  19835. console.error( 'THREE.ImageUtils.loadCompressedTexture has been removed. Use THREE.DDSLoader instead.' );
  19836. },
  19837. loadCompressedTextureCube: function () {
  19838. console.error( 'THREE.ImageUtils.loadCompressedTextureCube has been removed. Use THREE.DDSLoader instead.' );
  19839. }
  19840. };
  19841. //
  19842. THREE.Projector = function () {
  19843. console.error( 'THREE.Projector has been moved to /examples/js/renderers/Projector.js.' );
  19844. this.projectVector = function ( vector, camera ) {
  19845. console.warn( 'THREE.Projector: .projectVector() is now vector.project().' );
  19846. vector.project( camera );
  19847. };
  19848. this.unprojectVector = function ( vector, camera ) {
  19849. console.warn( 'THREE.Projector: .unprojectVector() is now vector.unproject().' );
  19850. vector.unproject( camera );
  19851. };
  19852. this.pickingRay = function ( vector, camera ) {
  19853. console.error( 'THREE.Projector: .pickingRay() is now raycaster.setFromCamera().' );
  19854. };
  19855. };
  19856. //
  19857. THREE.CanvasRenderer = function () {
  19858. console.error( 'THREE.CanvasRenderer has been moved to /examples/js/renderers/CanvasRenderer.js' );
  19859. this.domElement = document.createElement( 'canvas' );
  19860. this.clear = function () {};
  19861. this.render = function () {};
  19862. this.setClearColor = function () {};
  19863. this.setSize = function () {};
  19864. };
  19865. //
  19866. THREE.MeshFaceMaterial = THREE.MultiMaterial;
  19867. // File:src/extras/CurveUtils.js
  19868. /**
  19869. * @author zz85 / http://www.lab4games.net/zz85/blog
  19870. */
  19871. THREE.CurveUtils = {
  19872. tangentQuadraticBezier: function ( t, p0, p1, p2 ) {
  19873. return 2 * ( 1 - t ) * ( p1 - p0 ) + 2 * t * ( p2 - p1 );
  19874. },
  19875. // Puay Bing, thanks for helping with this derivative!
  19876. tangentCubicBezier: function ( t, p0, p1, p2, p3 ) {
  19877. return - 3 * p0 * ( 1 - t ) * ( 1 - t ) +
  19878. 3 * p1 * ( 1 - t ) * ( 1 - t ) - 6 * t * p1 * ( 1 - t ) +
  19879. 6 * t * p2 * ( 1 - t ) - 3 * t * t * p2 +
  19880. 3 * t * t * p3;
  19881. },
  19882. tangentSpline: function ( t, p0, p1, p2, p3 ) {
  19883. // To check if my formulas are correct
  19884. var h00 = 6 * t * t - 6 * t; // derived from 2t^3 − 3t^2 + 1
  19885. var h10 = 3 * t * t - 4 * t + 1; // t^3 − 2t^2 + t
  19886. var h01 = - 6 * t * t + 6 * t; // − 2t3 + 3t2
  19887. var h11 = 3 * t * t - 2 * t; // t3 − t2
  19888. return h00 + h10 + h01 + h11;
  19889. },
  19890. // Catmull-Rom
  19891. interpolate: function( p0, p1, p2, p3, t ) {
  19892. var v0 = ( p2 - p0 ) * 0.5;
  19893. var v1 = ( p3 - p1 ) * 0.5;
  19894. var t2 = t * t;
  19895. var t3 = t * t2;
  19896. return ( 2 * p1 - 2 * p2 + v0 + v1 ) * t3 + ( - 3 * p1 + 3 * p2 - 2 * v0 - v1 ) * t2 + v0 * t + p1;
  19897. }
  19898. };
  19899. // File:src/extras/SceneUtils.js
  19900. /**
  19901. * @author alteredq / http://alteredqualia.com/
  19902. */
  19903. THREE.SceneUtils = {
  19904. createMultiMaterialObject: function ( geometry, materials ) {
  19905. var group = new THREE.Group();
  19906. for ( var i = 0, l = materials.length; i < l; i ++ ) {
  19907. group.add( new THREE.Mesh( geometry, materials[ i ] ) );
  19908. }
  19909. return group;
  19910. },
  19911. detach: function ( child, parent, scene ) {
  19912. child.applyMatrix( parent.matrixWorld );
  19913. parent.remove( child );
  19914. scene.add( child );
  19915. },
  19916. attach: function ( child, scene, parent ) {
  19917. var matrixWorldInverse = new THREE.Matrix4();
  19918. matrixWorldInverse.getInverse( parent.matrixWorld );
  19919. child.applyMatrix( matrixWorldInverse );
  19920. scene.remove( child );
  19921. parent.add( child );
  19922. }
  19923. };
  19924. // File:src/extras/ShapeUtils.js
  19925. /**
  19926. * @author zz85 / http://www.lab4games.net/zz85/blog
  19927. */
  19928. THREE.ShapeUtils = {
  19929. // calculate area of the contour polygon
  19930. area: function ( contour ) {
  19931. var n = contour.length;
  19932. var a = 0.0;
  19933. for ( var p = n - 1, q = 0; q < n; p = q ++ ) {
  19934. a += contour[ p ].x * contour[ q ].y - contour[ q ].x * contour[ p ].y;
  19935. }
  19936. return a * 0.5;
  19937. },
  19938. triangulate: ( function () {
  19939. /**
  19940. * This code is a quick port of code written in C++ which was submitted to
  19941. * flipcode.com by John W. Ratcliff // July 22, 2000
  19942. * See original code and more information here:
  19943. * http://www.flipcode.com/archives/Efficient_Polygon_Triangulation.shtml
  19944. *
  19945. * ported to actionscript by Zevan Rosser
  19946. * www.actionsnippet.com
  19947. *
  19948. * ported to javascript by Joshua Koo
  19949. * http://www.lab4games.net/zz85/blog
  19950. *
  19951. */
  19952. function snip( contour, u, v, w, n, verts ) {
  19953. var p;
  19954. var ax, ay, bx, by;
  19955. var cx, cy, px, py;
  19956. ax = contour[ verts[ u ] ].x;
  19957. ay = contour[ verts[ u ] ].y;
  19958. bx = contour[ verts[ v ] ].x;
  19959. by = contour[ verts[ v ] ].y;
  19960. cx = contour[ verts[ w ] ].x;
  19961. cy = contour[ verts[ w ] ].y;
  19962. if ( Number.EPSILON > ( ( ( bx - ax ) * ( cy - ay ) ) - ( ( by - ay ) * ( cx - ax ) ) ) ) return false;
  19963. var aX, aY, bX, bY, cX, cY;
  19964. var apx, apy, bpx, bpy, cpx, cpy;
  19965. var cCROSSap, bCROSScp, aCROSSbp;
  19966. aX = cx - bx; aY = cy - by;
  19967. bX = ax - cx; bY = ay - cy;
  19968. cX = bx - ax; cY = by - ay;
  19969. for ( p = 0; p < n; p ++ ) {
  19970. px = contour[ verts[ p ] ].x;
  19971. py = contour[ verts[ p ] ].y;
  19972. if ( ( ( px === ax ) && ( py === ay ) ) ||
  19973. ( ( px === bx ) && ( py === by ) ) ||
  19974. ( ( px === cx ) && ( py === cy ) ) ) continue;
  19975. apx = px - ax; apy = py - ay;
  19976. bpx = px - bx; bpy = py - by;
  19977. cpx = px - cx; cpy = py - cy;
  19978. // see if p is inside triangle abc
  19979. aCROSSbp = aX * bpy - aY * bpx;
  19980. cCROSSap = cX * apy - cY * apx;
  19981. bCROSScp = bX * cpy - bY * cpx;
  19982. if ( ( aCROSSbp >= - Number.EPSILON ) && ( bCROSScp >= - Number.EPSILON ) && ( cCROSSap >= - Number.EPSILON ) ) return false;
  19983. }
  19984. return true;
  19985. }
  19986. // takes in an contour array and returns
  19987. return function ( contour, indices ) {
  19988. var n = contour.length;
  19989. if ( n < 3 ) return null;
  19990. var result = [],
  19991. verts = [],
  19992. vertIndices = [];
  19993. /* we want a counter-clockwise polygon in verts */
  19994. var u, v, w;
  19995. if ( THREE.ShapeUtils.area( contour ) > 0.0 ) {
  19996. for ( v = 0; v < n; v ++ ) verts[ v ] = v;
  19997. } else {
  19998. for ( v = 0; v < n; v ++ ) verts[ v ] = ( n - 1 ) - v;
  19999. }
  20000. var nv = n;
  20001. /* remove nv - 2 vertices, creating 1 triangle every time */
  20002. var count = 2 * nv; /* error detection */
  20003. for ( v = nv - 1; nv > 2; ) {
  20004. /* if we loop, it is probably a non-simple polygon */
  20005. if ( ( count -- ) <= 0 ) {
  20006. //** Triangulate: ERROR - probable bad polygon!
  20007. //throw ( "Warning, unable to triangulate polygon!" );
  20008. //return null;
  20009. // Sometimes warning is fine, especially polygons are triangulated in reverse.
  20010. console.warn( 'THREE.ShapeUtils: Unable to triangulate polygon! in triangulate()' );
  20011. if ( indices ) return vertIndices;
  20012. return result;
  20013. }
  20014. /* three consecutive vertices in current polygon, <u,v,w> */
  20015. u = v; if ( nv <= u ) u = 0; /* previous */
  20016. v = u + 1; if ( nv <= v ) v = 0; /* new v */
  20017. w = v + 1; if ( nv <= w ) w = 0; /* next */
  20018. if ( snip( contour, u, v, w, nv, verts ) ) {
  20019. var a, b, c, s, t;
  20020. /* true names of the vertices */
  20021. a = verts[ u ];
  20022. b = verts[ v ];
  20023. c = verts[ w ];
  20024. /* output Triangle */
  20025. result.push( [ contour[ a ],
  20026. contour[ b ],
  20027. contour[ c ] ] );
  20028. vertIndices.push( [ verts[ u ], verts[ v ], verts[ w ] ] );
  20029. /* remove v from the remaining polygon */
  20030. for ( s = v, t = v + 1; t < nv; s ++, t ++ ) {
  20031. verts[ s ] = verts[ t ];
  20032. }
  20033. nv --;
  20034. /* reset error detection counter */
  20035. count = 2 * nv;
  20036. }
  20037. }
  20038. if ( indices ) return vertIndices;
  20039. return result;
  20040. }
  20041. } )(),
  20042. triangulateShape: function ( contour, holes ) {
  20043. function point_in_segment_2D_colin( inSegPt1, inSegPt2, inOtherPt ) {
  20044. // inOtherPt needs to be collinear to the inSegment
  20045. if ( inSegPt1.x !== inSegPt2.x ) {
  20046. if ( inSegPt1.x < inSegPt2.x ) {
  20047. return ( ( inSegPt1.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt2.x ) );
  20048. } else {
  20049. return ( ( inSegPt2.x <= inOtherPt.x ) && ( inOtherPt.x <= inSegPt1.x ) );
  20050. }
  20051. } else {
  20052. if ( inSegPt1.y < inSegPt2.y ) {
  20053. return ( ( inSegPt1.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt2.y ) );
  20054. } else {
  20055. return ( ( inSegPt2.y <= inOtherPt.y ) && ( inOtherPt.y <= inSegPt1.y ) );
  20056. }
  20057. }
  20058. }
  20059. function intersect_segments_2D( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1, inSeg2Pt2, inExcludeAdjacentSegs ) {
  20060. var seg1dx = inSeg1Pt2.x - inSeg1Pt1.x, seg1dy = inSeg1Pt2.y - inSeg1Pt1.y;
  20061. var seg2dx = inSeg2Pt2.x - inSeg2Pt1.x, seg2dy = inSeg2Pt2.y - inSeg2Pt1.y;
  20062. var seg1seg2dx = inSeg1Pt1.x - inSeg2Pt1.x;
  20063. var seg1seg2dy = inSeg1Pt1.y - inSeg2Pt1.y;
  20064. var limit = seg1dy * seg2dx - seg1dx * seg2dy;
  20065. var perpSeg1 = seg1dy * seg1seg2dx - seg1dx * seg1seg2dy;
  20066. if ( Math.abs( limit ) > Number.EPSILON ) {
  20067. // not parallel
  20068. var perpSeg2;
  20069. if ( limit > 0 ) {
  20070. if ( ( perpSeg1 < 0 ) || ( perpSeg1 > limit ) ) return [];
  20071. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20072. if ( ( perpSeg2 < 0 ) || ( perpSeg2 > limit ) ) return [];
  20073. } else {
  20074. if ( ( perpSeg1 > 0 ) || ( perpSeg1 < limit ) ) return [];
  20075. perpSeg2 = seg2dy * seg1seg2dx - seg2dx * seg1seg2dy;
  20076. if ( ( perpSeg2 > 0 ) || ( perpSeg2 < limit ) ) return [];
  20077. }
  20078. // i.e. to reduce rounding errors
  20079. // intersection at endpoint of segment#1?
  20080. if ( perpSeg2 === 0 ) {
  20081. if ( ( inExcludeAdjacentSegs ) &&
  20082. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20083. return [ inSeg1Pt1 ];
  20084. }
  20085. if ( perpSeg2 === limit ) {
  20086. if ( ( inExcludeAdjacentSegs ) &&
  20087. ( ( perpSeg1 === 0 ) || ( perpSeg1 === limit ) ) ) return [];
  20088. return [ inSeg1Pt2 ];
  20089. }
  20090. // intersection at endpoint of segment#2?
  20091. if ( perpSeg1 === 0 ) return [ inSeg2Pt1 ];
  20092. if ( perpSeg1 === limit ) return [ inSeg2Pt2 ];
  20093. // return real intersection point
  20094. var factorSeg1 = perpSeg2 / limit;
  20095. return [ { x: inSeg1Pt1.x + factorSeg1 * seg1dx,
  20096. y: inSeg1Pt1.y + factorSeg1 * seg1dy } ];
  20097. } else {
  20098. // parallel or collinear
  20099. if ( ( perpSeg1 !== 0 ) ||
  20100. ( seg2dy * seg1seg2dx !== seg2dx * seg1seg2dy ) ) return [];
  20101. // they are collinear or degenerate
  20102. var seg1Pt = ( ( seg1dx === 0 ) && ( seg1dy === 0 ) ); // segment1 is just a point?
  20103. var seg2Pt = ( ( seg2dx === 0 ) && ( seg2dy === 0 ) ); // segment2 is just a point?
  20104. // both segments are points
  20105. if ( seg1Pt && seg2Pt ) {
  20106. if ( ( inSeg1Pt1.x !== inSeg2Pt1.x ) ||
  20107. ( inSeg1Pt1.y !== inSeg2Pt1.y ) ) return []; // they are distinct points
  20108. return [ inSeg1Pt1 ]; // they are the same point
  20109. }
  20110. // segment#1 is a single point
  20111. if ( seg1Pt ) {
  20112. if ( ! point_in_segment_2D_colin( inSeg2Pt1, inSeg2Pt2, inSeg1Pt1 ) ) return []; // but not in segment#2
  20113. return [ inSeg1Pt1 ];
  20114. }
  20115. // segment#2 is a single point
  20116. if ( seg2Pt ) {
  20117. if ( ! point_in_segment_2D_colin( inSeg1Pt1, inSeg1Pt2, inSeg2Pt1 ) ) return []; // but not in segment#1
  20118. return [ inSeg2Pt1 ];
  20119. }
  20120. // they are collinear segments, which might overlap
  20121. var seg1min, seg1max, seg1minVal, seg1maxVal;
  20122. var seg2min, seg2max, seg2minVal, seg2maxVal;
  20123. if ( seg1dx !== 0 ) {
  20124. // the segments are NOT on a vertical line
  20125. if ( inSeg1Pt1.x < inSeg1Pt2.x ) {
  20126. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.x;
  20127. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.x;
  20128. } else {
  20129. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.x;
  20130. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.x;
  20131. }
  20132. if ( inSeg2Pt1.x < inSeg2Pt2.x ) {
  20133. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.x;
  20134. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.x;
  20135. } else {
  20136. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.x;
  20137. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.x;
  20138. }
  20139. } else {
  20140. // the segments are on a vertical line
  20141. if ( inSeg1Pt1.y < inSeg1Pt2.y ) {
  20142. seg1min = inSeg1Pt1; seg1minVal = inSeg1Pt1.y;
  20143. seg1max = inSeg1Pt2; seg1maxVal = inSeg1Pt2.y;
  20144. } else {
  20145. seg1min = inSeg1Pt2; seg1minVal = inSeg1Pt2.y;
  20146. seg1max = inSeg1Pt1; seg1maxVal = inSeg1Pt1.y;
  20147. }
  20148. if ( inSeg2Pt1.y < inSeg2Pt2.y ) {
  20149. seg2min = inSeg2Pt1; seg2minVal = inSeg2Pt1.y;
  20150. seg2max = inSeg2Pt2; seg2maxVal = inSeg2Pt2.y;
  20151. } else {
  20152. seg2min = inSeg2Pt2; seg2minVal = inSeg2Pt2.y;
  20153. seg2max = inSeg2Pt1; seg2maxVal = inSeg2Pt1.y;
  20154. }
  20155. }
  20156. if ( seg1minVal <= seg2minVal ) {
  20157. if ( seg1maxVal < seg2minVal ) return [];
  20158. if ( seg1maxVal === seg2minVal ) {
  20159. if ( inExcludeAdjacentSegs ) return [];
  20160. return [ seg2min ];
  20161. }
  20162. if ( seg1maxVal <= seg2maxVal ) return [ seg2min, seg1max ];
  20163. return [ seg2min, seg2max ];
  20164. } else {
  20165. if ( seg1minVal > seg2maxVal ) return [];
  20166. if ( seg1minVal === seg2maxVal ) {
  20167. if ( inExcludeAdjacentSegs ) return [];
  20168. return [ seg1min ];
  20169. }
  20170. if ( seg1maxVal <= seg2maxVal ) return [ seg1min, seg1max ];
  20171. return [ seg1min, seg2max ];
  20172. }
  20173. }
  20174. }
  20175. function isPointInsideAngle( inVertex, inLegFromPt, inLegToPt, inOtherPt ) {
  20176. // The order of legs is important
  20177. // translation of all points, so that Vertex is at (0,0)
  20178. var legFromPtX = inLegFromPt.x - inVertex.x, legFromPtY = inLegFromPt.y - inVertex.y;
  20179. var legToPtX = inLegToPt.x - inVertex.x, legToPtY = inLegToPt.y - inVertex.y;
  20180. var otherPtX = inOtherPt.x - inVertex.x, otherPtY = inOtherPt.y - inVertex.y;
  20181. // main angle >0: < 180 deg.; 0: 180 deg.; <0: > 180 deg.
  20182. var from2toAngle = legFromPtX * legToPtY - legFromPtY * legToPtX;
  20183. var from2otherAngle = legFromPtX * otherPtY - legFromPtY * otherPtX;
  20184. if ( Math.abs( from2toAngle ) > Number.EPSILON ) {
  20185. // angle != 180 deg.
  20186. var other2toAngle = otherPtX * legToPtY - otherPtY * legToPtX;
  20187. // console.log( "from2to: " + from2toAngle + ", from2other: " + from2otherAngle + ", other2to: " + other2toAngle );
  20188. if ( from2toAngle > 0 ) {
  20189. // main angle < 180 deg.
  20190. return ( ( from2otherAngle >= 0 ) && ( other2toAngle >= 0 ) );
  20191. } else {
  20192. // main angle > 180 deg.
  20193. return ( ( from2otherAngle >= 0 ) || ( other2toAngle >= 0 ) );
  20194. }
  20195. } else {
  20196. // angle == 180 deg.
  20197. // console.log( "from2to: 180 deg., from2other: " + from2otherAngle );
  20198. return ( from2otherAngle > 0 );
  20199. }
  20200. }
  20201. function removeHoles( contour, holes ) {
  20202. var shape = contour.concat(); // work on this shape
  20203. var hole;
  20204. function isCutLineInsideAngles( inShapeIdx, inHoleIdx ) {
  20205. // Check if hole point lies within angle around shape point
  20206. var lastShapeIdx = shape.length - 1;
  20207. var prevShapeIdx = inShapeIdx - 1;
  20208. if ( prevShapeIdx < 0 ) prevShapeIdx = lastShapeIdx;
  20209. var nextShapeIdx = inShapeIdx + 1;
  20210. if ( nextShapeIdx > lastShapeIdx ) nextShapeIdx = 0;
  20211. var insideAngle = isPointInsideAngle( shape[ inShapeIdx ], shape[ prevShapeIdx ], shape[ nextShapeIdx ], hole[ inHoleIdx ] );
  20212. if ( ! insideAngle ) {
  20213. // console.log( "Vertex (Shape): " + inShapeIdx + ", Point: " + hole[inHoleIdx].x + "/" + hole[inHoleIdx].y );
  20214. return false;
  20215. }
  20216. // Check if shape point lies within angle around hole point
  20217. var lastHoleIdx = hole.length - 1;
  20218. var prevHoleIdx = inHoleIdx - 1;
  20219. if ( prevHoleIdx < 0 ) prevHoleIdx = lastHoleIdx;
  20220. var nextHoleIdx = inHoleIdx + 1;
  20221. if ( nextHoleIdx > lastHoleIdx ) nextHoleIdx = 0;
  20222. insideAngle = isPointInsideAngle( hole[ inHoleIdx ], hole[ prevHoleIdx ], hole[ nextHoleIdx ], shape[ inShapeIdx ] );
  20223. if ( ! insideAngle ) {
  20224. // console.log( "Vertex (Hole): " + inHoleIdx + ", Point: " + shape[inShapeIdx].x + "/" + shape[inShapeIdx].y );
  20225. return false;
  20226. }
  20227. return true;
  20228. }
  20229. function intersectsShapeEdge( inShapePt, inHolePt ) {
  20230. // checks for intersections with shape edges
  20231. var sIdx, nextIdx, intersection;
  20232. for ( sIdx = 0; sIdx < shape.length; sIdx ++ ) {
  20233. nextIdx = sIdx + 1; nextIdx %= shape.length;
  20234. intersection = intersect_segments_2D( inShapePt, inHolePt, shape[ sIdx ], shape[ nextIdx ], true );
  20235. if ( intersection.length > 0 ) return true;
  20236. }
  20237. return false;
  20238. }
  20239. var indepHoles = [];
  20240. function intersectsHoleEdge( inShapePt, inHolePt ) {
  20241. // checks for intersections with hole edges
  20242. var ihIdx, chkHole,
  20243. hIdx, nextIdx, intersection;
  20244. for ( ihIdx = 0; ihIdx < indepHoles.length; ihIdx ++ ) {
  20245. chkHole = holes[ indepHoles[ ihIdx ]];
  20246. for ( hIdx = 0; hIdx < chkHole.length; hIdx ++ ) {
  20247. nextIdx = hIdx + 1; nextIdx %= chkHole.length;
  20248. intersection = intersect_segments_2D( inShapePt, inHolePt, chkHole[ hIdx ], chkHole[ nextIdx ], true );
  20249. if ( intersection.length > 0 ) return true;
  20250. }
  20251. }
  20252. return false;
  20253. }
  20254. var holeIndex, shapeIndex,
  20255. shapePt, holePt,
  20256. holeIdx, cutKey, failedCuts = [],
  20257. tmpShape1, tmpShape2,
  20258. tmpHole1, tmpHole2;
  20259. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20260. indepHoles.push( h );
  20261. }
  20262. var minShapeIndex = 0;
  20263. var counter = indepHoles.length * 2;
  20264. while ( indepHoles.length > 0 ) {
  20265. counter --;
  20266. if ( counter < 0 ) {
  20267. console.log( "Infinite Loop! Holes left:" + indepHoles.length + ", Probably Hole outside Shape!" );
  20268. break;
  20269. }
  20270. // search for shape-vertex and hole-vertex,
  20271. // which can be connected without intersections
  20272. for ( shapeIndex = minShapeIndex; shapeIndex < shape.length; shapeIndex ++ ) {
  20273. shapePt = shape[ shapeIndex ];
  20274. holeIndex = - 1;
  20275. // search for hole which can be reached without intersections
  20276. for ( var h = 0; h < indepHoles.length; h ++ ) {
  20277. holeIdx = indepHoles[ h ];
  20278. // prevent multiple checks
  20279. cutKey = shapePt.x + ":" + shapePt.y + ":" + holeIdx;
  20280. if ( failedCuts[ cutKey ] !== undefined ) continue;
  20281. hole = holes[ holeIdx ];
  20282. for ( var h2 = 0; h2 < hole.length; h2 ++ ) {
  20283. holePt = hole[ h2 ];
  20284. if ( ! isCutLineInsideAngles( shapeIndex, h2 ) ) continue;
  20285. if ( intersectsShapeEdge( shapePt, holePt ) ) continue;
  20286. if ( intersectsHoleEdge( shapePt, holePt ) ) continue;
  20287. holeIndex = h2;
  20288. indepHoles.splice( h, 1 );
  20289. tmpShape1 = shape.slice( 0, shapeIndex + 1 );
  20290. tmpShape2 = shape.slice( shapeIndex );
  20291. tmpHole1 = hole.slice( holeIndex );
  20292. tmpHole2 = hole.slice( 0, holeIndex + 1 );
  20293. shape = tmpShape1.concat( tmpHole1 ).concat( tmpHole2 ).concat( tmpShape2 );
  20294. minShapeIndex = shapeIndex;
  20295. // Debug only, to show the selected cuts
  20296. // glob_CutLines.push( [ shapePt, holePt ] );
  20297. break;
  20298. }
  20299. if ( holeIndex >= 0 ) break; // hole-vertex found
  20300. failedCuts[ cutKey ] = true; // remember failure
  20301. }
  20302. if ( holeIndex >= 0 ) break; // hole-vertex found
  20303. }
  20304. }
  20305. return shape; /* shape with no holes */
  20306. }
  20307. var i, il, f, face,
  20308. key, index,
  20309. allPointsMap = {};
  20310. // 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.
  20311. var allpoints = contour.concat();
  20312. for ( var h = 0, hl = holes.length; h < hl; h ++ ) {
  20313. Array.prototype.push.apply( allpoints, holes[ h ] );
  20314. }
  20315. //console.log( "allpoints",allpoints, allpoints.length );
  20316. // prepare all points map
  20317. for ( i = 0, il = allpoints.length; i < il; i ++ ) {
  20318. key = allpoints[ i ].x + ":" + allpoints[ i ].y;
  20319. if ( allPointsMap[ key ] !== undefined ) {
  20320. console.warn( "THREE.Shape: Duplicate point", key );
  20321. }
  20322. allPointsMap[ key ] = i;
  20323. }
  20324. // remove holes by cutting paths to holes and adding them to the shape
  20325. var shapeWithoutHoles = removeHoles( contour, holes );
  20326. var triangles = THREE.ShapeUtils.triangulate( shapeWithoutHoles, false ); // True returns indices for points of spooled shape
  20327. //console.log( "triangles",triangles, triangles.length );
  20328. // check all face vertices against all points map
  20329. for ( i = 0, il = triangles.length; i < il; i ++ ) {
  20330. face = triangles[ i ];
  20331. for ( f = 0; f < 3; f ++ ) {
  20332. key = face[ f ].x + ":" + face[ f ].y;
  20333. index = allPointsMap[ key ];
  20334. if ( index !== undefined ) {
  20335. face[ f ] = index;
  20336. }
  20337. }
  20338. }
  20339. return triangles.concat();
  20340. },
  20341. isClockWise: function ( pts ) {
  20342. return THREE.ShapeUtils.area( pts ) < 0;
  20343. },
  20344. // Bezier Curves formulas obtained from
  20345. // http://en.wikipedia.org/wiki/B%C3%A9zier_curve
  20346. // Quad Bezier Functions
  20347. b2: ( function () {
  20348. function b2p0( t, p ) {
  20349. var k = 1 - t;
  20350. return k * k * p;
  20351. }
  20352. function b2p1( t, p ) {
  20353. return 2 * ( 1 - t ) * t * p;
  20354. }
  20355. function b2p2( t, p ) {
  20356. return t * t * p;
  20357. }
  20358. return function ( t, p0, p1, p2 ) {
  20359. return b2p0( t, p0 ) + b2p1( t, p1 ) + b2p2( t, p2 );
  20360. };
  20361. } )(),
  20362. // Cubic Bezier Functions
  20363. b3: ( function () {
  20364. function b3p0( t, p ) {
  20365. var k = 1 - t;
  20366. return k * k * k * p;
  20367. }
  20368. function b3p1( t, p ) {
  20369. var k = 1 - t;
  20370. return 3 * k * k * t * p;
  20371. }
  20372. function b3p2( t, p ) {
  20373. var k = 1 - t;
  20374. return 3 * k * t * t * p;
  20375. }
  20376. function b3p3( t, p ) {
  20377. return t * t * t * p;
  20378. }
  20379. return function ( t, p0, p1, p2, p3 ) {
  20380. return b3p0( t, p0 ) + b3p1( t, p1 ) + b3p2( t, p2 ) + b3p3( t, p3 );
  20381. };
  20382. } )()
  20383. };
  20384. // File:src/extras/core/Curve.js
  20385. /**
  20386. * @author zz85 / http://www.lab4games.net/zz85/blog
  20387. * Extensible curve object
  20388. *
  20389. * Some common of Curve methods
  20390. * .getPoint(t), getTangent(t)
  20391. * .getPointAt(u), getTagentAt(u)
  20392. * .getPoints(), .getSpacedPoints()
  20393. * .getLength()
  20394. * .updateArcLengths()
  20395. *
  20396. * This following classes subclasses THREE.Curve:
  20397. *
  20398. * -- 2d classes --
  20399. * THREE.LineCurve
  20400. * THREE.QuadraticBezierCurve
  20401. * THREE.CubicBezierCurve
  20402. * THREE.SplineCurve
  20403. * THREE.ArcCurve
  20404. * THREE.EllipseCurve
  20405. *
  20406. * -- 3d classes --
  20407. * THREE.LineCurve3
  20408. * THREE.QuadraticBezierCurve3
  20409. * THREE.CubicBezierCurve3
  20410. * THREE.SplineCurve3
  20411. * THREE.ClosedSplineCurve3
  20412. *
  20413. * A series of curves can be represented as a THREE.CurvePath
  20414. *
  20415. **/
  20416. /**************************************************************
  20417. * Abstract Curve base class
  20418. **************************************************************/
  20419. THREE.Curve = function () {
  20420. };
  20421. THREE.Curve.prototype = {
  20422. constructor: THREE.Curve,
  20423. // Virtual base class method to overwrite and implement in subclasses
  20424. // - t [0 .. 1]
  20425. getPoint: function ( t ) {
  20426. console.warn( "THREE.Curve: Warning, getPoint() not implemented!" );
  20427. return null;
  20428. },
  20429. // Get point at relative position in curve according to arc length
  20430. // - u [0 .. 1]
  20431. getPointAt: function ( u ) {
  20432. var t = this.getUtoTmapping( u );
  20433. return this.getPoint( t );
  20434. },
  20435. // Get sequence of points using getPoint( t )
  20436. getPoints: function ( divisions ) {
  20437. if ( ! divisions ) divisions = 5;
  20438. var d, pts = [];
  20439. for ( d = 0; d <= divisions; d ++ ) {
  20440. pts.push( this.getPoint( d / divisions ) );
  20441. }
  20442. return pts;
  20443. },
  20444. // Get sequence of points using getPointAt( u )
  20445. getSpacedPoints: function ( divisions ) {
  20446. if ( ! divisions ) divisions = 5;
  20447. var d, pts = [];
  20448. for ( d = 0; d <= divisions; d ++ ) {
  20449. pts.push( this.getPointAt( d / divisions ) );
  20450. }
  20451. return pts;
  20452. },
  20453. // Get total curve arc length
  20454. getLength: function () {
  20455. var lengths = this.getLengths();
  20456. return lengths[ lengths.length - 1 ];
  20457. },
  20458. // Get list of cumulative segment lengths
  20459. getLengths: function ( divisions ) {
  20460. if ( ! divisions ) divisions = ( this.__arcLengthDivisions ) ? ( this.__arcLengthDivisions ) : 200;
  20461. if ( this.cacheArcLengths
  20462. && ( this.cacheArcLengths.length === divisions + 1 )
  20463. && ! this.needsUpdate ) {
  20464. //console.log( "cached", this.cacheArcLengths );
  20465. return this.cacheArcLengths;
  20466. }
  20467. this.needsUpdate = false;
  20468. var cache = [];
  20469. var current, last = this.getPoint( 0 );
  20470. var p, sum = 0;
  20471. cache.push( 0 );
  20472. for ( p = 1; p <= divisions; p ++ ) {
  20473. current = this.getPoint ( p / divisions );
  20474. sum += current.distanceTo( last );
  20475. cache.push( sum );
  20476. last = current;
  20477. }
  20478. this.cacheArcLengths = cache;
  20479. return cache; // { sums: cache, sum:sum }; Sum is in the last element.
  20480. },
  20481. updateArcLengths: function() {
  20482. this.needsUpdate = true;
  20483. this.getLengths();
  20484. },
  20485. // Given u ( 0 .. 1 ), get a t to find p. This gives you points which are equidistant
  20486. getUtoTmapping: function ( u, distance ) {
  20487. var arcLengths = this.getLengths();
  20488. var i = 0, il = arcLengths.length;
  20489. var targetArcLength; // The targeted u distance value to get
  20490. if ( distance ) {
  20491. targetArcLength = distance;
  20492. } else {
  20493. targetArcLength = u * arcLengths[ il - 1 ];
  20494. }
  20495. //var time = Date.now();
  20496. // binary search for the index with largest value smaller than target u distance
  20497. var low = 0, high = il - 1, comparison;
  20498. while ( low <= high ) {
  20499. 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
  20500. comparison = arcLengths[ i ] - targetArcLength;
  20501. if ( comparison < 0 ) {
  20502. low = i + 1;
  20503. } else if ( comparison > 0 ) {
  20504. high = i - 1;
  20505. } else {
  20506. high = i;
  20507. break;
  20508. // DONE
  20509. }
  20510. }
  20511. i = high;
  20512. //console.log('b' , i, low, high, Date.now()- time);
  20513. if ( arcLengths[ i ] === targetArcLength ) {
  20514. var t = i / ( il - 1 );
  20515. return t;
  20516. }
  20517. // we could get finer grain at lengths, or use simple interpolation between two points
  20518. var lengthBefore = arcLengths[ i ];
  20519. var lengthAfter = arcLengths[ i + 1 ];
  20520. var segmentLength = lengthAfter - lengthBefore;
  20521. // determine where we are between the 'before' and 'after' points
  20522. var segmentFraction = ( targetArcLength - lengthBefore ) / segmentLength;
  20523. // add that fractional amount to t
  20524. var t = ( i + segmentFraction ) / ( il - 1 );
  20525. return t;
  20526. },
  20527. // Returns a unit vector tangent at t
  20528. // In case any sub curve does not implement its tangent derivation,
  20529. // 2 points a small delta apart will be used to find its gradient
  20530. // which seems to give a reasonable approximation
  20531. getTangent: function( t ) {
  20532. var delta = 0.0001;
  20533. var t1 = t - delta;
  20534. var t2 = t + delta;
  20535. // Capping in case of danger
  20536. if ( t1 < 0 ) t1 = 0;
  20537. if ( t2 > 1 ) t2 = 1;
  20538. var pt1 = this.getPoint( t1 );
  20539. var pt2 = this.getPoint( t2 );
  20540. var vec = pt2.clone().sub( pt1 );
  20541. return vec.normalize();
  20542. },
  20543. getTangentAt: function ( u ) {
  20544. var t = this.getUtoTmapping( u );
  20545. return this.getTangent( t );
  20546. }
  20547. };
  20548. // TODO: Transformation for Curves?
  20549. /**************************************************************
  20550. * 3D Curves
  20551. **************************************************************/
  20552. // A Factory method for creating new curve subclasses
  20553. THREE.Curve.create = function ( constructor, getPointFunc ) {
  20554. constructor.prototype = Object.create( THREE.Curve.prototype );
  20555. constructor.prototype.constructor = constructor;
  20556. constructor.prototype.getPoint = getPointFunc;
  20557. return constructor;
  20558. };
  20559. // File:src/extras/core/CurvePath.js
  20560. /**
  20561. * @author zz85 / http://www.lab4games.net/zz85/blog
  20562. *
  20563. **/
  20564. /**************************************************************
  20565. * Curved Path - a curve path is simply a array of connected
  20566. * curves, but retains the api of a curve
  20567. **************************************************************/
  20568. THREE.CurvePath = function () {
  20569. this.curves = [];
  20570. this.autoClose = false; // Automatically closes the path
  20571. };
  20572. THREE.CurvePath.prototype = Object.create( THREE.Curve.prototype );
  20573. THREE.CurvePath.prototype.constructor = THREE.CurvePath;
  20574. THREE.CurvePath.prototype.add = function ( curve ) {
  20575. this.curves.push( curve );
  20576. };
  20577. /*
  20578. THREE.CurvePath.prototype.checkConnection = function() {
  20579. // TODO
  20580. // If the ending of curve is not connected to the starting
  20581. // or the next curve, then, this is not a real path
  20582. };
  20583. */
  20584. THREE.CurvePath.prototype.closePath = function() {
  20585. // TODO Test
  20586. // and verify for vector3 (needs to implement equals)
  20587. // Add a line curve if start and end of lines are not connected
  20588. var startPoint = this.curves[ 0 ].getPoint( 0 );
  20589. var endPoint = this.curves[ this.curves.length - 1 ].getPoint( 1 );
  20590. if ( ! startPoint.equals( endPoint ) ) {
  20591. this.curves.push( new THREE.LineCurve( endPoint, startPoint ) );
  20592. }
  20593. };
  20594. // To get accurate point with reference to
  20595. // entire path distance at time t,
  20596. // following has to be done:
  20597. // 1. Length of each sub path have to be known
  20598. // 2. Locate and identify type of curve
  20599. // 3. Get t for the curve
  20600. // 4. Return curve.getPointAt(t')
  20601. THREE.CurvePath.prototype.getPoint = function( t ) {
  20602. var d = t * this.getLength();
  20603. var curveLengths = this.getCurveLengths();
  20604. var i = 0;
  20605. // To think about boundaries points.
  20606. while ( i < curveLengths.length ) {
  20607. if ( curveLengths[ i ] >= d ) {
  20608. var diff = curveLengths[ i ] - d;
  20609. var curve = this.curves[ i ];
  20610. var u = 1 - diff / curve.getLength();
  20611. return curve.getPointAt( u );
  20612. }
  20613. i ++;
  20614. }
  20615. return null;
  20616. // loop where sum != 0, sum > d , sum+1 <d
  20617. };
  20618. /*
  20619. THREE.CurvePath.prototype.getTangent = function( t ) {
  20620. };
  20621. */
  20622. // We cannot use the default THREE.Curve getPoint() with getLength() because in
  20623. // THREE.Curve, getLength() depends on getPoint() but in THREE.CurvePath
  20624. // getPoint() depends on getLength
  20625. THREE.CurvePath.prototype.getLength = function() {
  20626. var lens = this.getCurveLengths();
  20627. return lens[ lens.length - 1 ];
  20628. };
  20629. // Compute lengths and cache them
  20630. // We cannot overwrite getLengths() because UtoT mapping uses it.
  20631. THREE.CurvePath.prototype.getCurveLengths = function() {
  20632. // We use cache values if curves and cache array are same length
  20633. if ( this.cacheLengths && this.cacheLengths.length === this.curves.length ) {
  20634. return this.cacheLengths;
  20635. }
  20636. // Get length of sub-curve
  20637. // Push sums into cached array
  20638. var lengths = [], sums = 0;
  20639. for ( var i = 0, l = this.curves.length; i < l; i ++ ) {
  20640. sums += this.curves[ i ].getLength();
  20641. lengths.push( sums );
  20642. }
  20643. this.cacheLengths = lengths;
  20644. return lengths;
  20645. };
  20646. /**************************************************************
  20647. * Create Geometries Helpers
  20648. **************************************************************/
  20649. /// Generate geometry from path points (for Line or Points objects)
  20650. THREE.CurvePath.prototype.createPointsGeometry = function( divisions ) {
  20651. var pts = this.getPoints( divisions );
  20652. return this.createGeometry( pts );
  20653. };
  20654. // Generate geometry from equidistant sampling along the path
  20655. THREE.CurvePath.prototype.createSpacedPointsGeometry = function( divisions ) {
  20656. var pts = this.getSpacedPoints( divisions );
  20657. return this.createGeometry( pts );
  20658. };
  20659. THREE.CurvePath.prototype.createGeometry = function( points ) {
  20660. var geometry = new THREE.Geometry();
  20661. for ( var i = 0, l = points.length; i < l; i ++ ) {
  20662. var point = points[ i ];
  20663. geometry.vertices.push( new THREE.Vector3( point.x, point.y, point.z || 0 ) );
  20664. }
  20665. return geometry;
  20666. };
  20667. // File:src/extras/core/Font.js
  20668. /**
  20669. * @author zz85 / http://www.lab4games.net/zz85/blog
  20670. * @author mrdoob / http://mrdoob.com/
  20671. */
  20672. THREE.Font = function ( data ) {
  20673. this.data = data;
  20674. };
  20675. THREE.Font.prototype = {
  20676. constructor: THREE.Font,
  20677. generateShapes: function ( text, size, divisions ) {
  20678. function createPaths( text ) {
  20679. var chars = String( text ).split( '' );
  20680. var scale = size / data.resolution;
  20681. var offset = 0;
  20682. var paths = [];
  20683. for ( var i = 0; i < chars.length; i ++ ) {
  20684. var ret = createPath( chars[ i ], scale, offset );
  20685. offset += ret.offset;
  20686. paths.push( ret.path );
  20687. }
  20688. return paths;
  20689. }
  20690. function createPath( c, scale, offset ) {
  20691. var glyph = data.glyphs[ c ] || data.glyphs[ '?' ];
  20692. if ( ! glyph ) return;
  20693. var path = new THREE.Path();
  20694. var pts = [], b2 = THREE.ShapeUtils.b2, b3 = THREE.ShapeUtils.b3;
  20695. var x, y, cpx, cpy, cpx0, cpy0, cpx1, cpy1, cpx2, cpy2, laste;
  20696. if ( glyph.o ) {
  20697. var outline = glyph._cachedOutline || ( glyph._cachedOutline = glyph.o.split( ' ' ) );
  20698. for ( var i = 0, l = outline.length; i < l; ) {
  20699. var action = outline[ i ++ ];
  20700. switch ( action ) {
  20701. case 'm': // moveTo
  20702. x = outline[ i ++ ] * scale + offset;
  20703. y = outline[ i ++ ] * scale;
  20704. path.moveTo( x, y );
  20705. break;
  20706. case 'l': // lineTo
  20707. x = outline[ i ++ ] * scale + offset;
  20708. y = outline[ i ++ ] * scale;
  20709. path.lineTo( x, y );
  20710. break;
  20711. case 'q': // quadraticCurveTo
  20712. cpx = outline[ i ++ ] * scale + offset;
  20713. cpy = outline[ i ++ ] * scale;
  20714. cpx1 = outline[ i ++ ] * scale + offset;
  20715. cpy1 = outline[ i ++ ] * scale;
  20716. path.quadraticCurveTo( cpx1, cpy1, cpx, cpy );
  20717. laste = pts[ pts.length - 1 ];
  20718. if ( laste ) {
  20719. cpx0 = laste.x;
  20720. cpy0 = laste.y;
  20721. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20722. var t = i2 / divisions;
  20723. b2( t, cpx0, cpx1, cpx );
  20724. b2( t, cpy0, cpy1, cpy );
  20725. }
  20726. }
  20727. break;
  20728. case 'b': // bezierCurveTo
  20729. cpx = outline[ i ++ ] * scale + offset;
  20730. cpy = outline[ i ++ ] * scale;
  20731. cpx1 = outline[ i ++ ] * scale + offset;
  20732. cpy1 = outline[ i ++ ] * scale;
  20733. cpx2 = outline[ i ++ ] * scale + offset;
  20734. cpy2 = outline[ i ++ ] * scale;
  20735. path.bezierCurveTo( cpx1, cpy1, cpx2, cpy2, cpx, cpy );
  20736. laste = pts[ pts.length - 1 ];
  20737. if ( laste ) {
  20738. cpx0 = laste.x;
  20739. cpy0 = laste.y;
  20740. for ( var i2 = 1; i2 <= divisions; i2 ++ ) {
  20741. var t = i2 / divisions;
  20742. b3( t, cpx0, cpx1, cpx2, cpx );
  20743. b3( t, cpy0, cpy1, cpy2, cpy );
  20744. }
  20745. }
  20746. break;
  20747. }
  20748. }
  20749. }
  20750. return { offset: glyph.ha * scale, path: path };
  20751. }
  20752. //
  20753. if ( size === undefined ) size = 100;
  20754. if ( divisions === undefined ) divisions = 4;
  20755. var data = this.data;
  20756. var paths = createPaths( text );
  20757. var shapes = [];
  20758. for ( var p = 0, pl = paths.length; p < pl; p ++ ) {
  20759. Array.prototype.push.apply( shapes, paths[ p ].toShapes() );
  20760. }
  20761. return shapes;
  20762. }
  20763. };
  20764. // File:src/extras/core/Path.js
  20765. /**
  20766. * @author zz85 / http://www.lab4games.net/zz85/blog
  20767. * Creates free form 2d path using series of points, lines or curves.
  20768. *
  20769. **/
  20770. THREE.Path = function ( points ) {
  20771. THREE.CurvePath.call( this );
  20772. this.actions = [];
  20773. if ( points ) {
  20774. this.fromPoints( points );
  20775. }
  20776. };
  20777. THREE.Path.prototype = Object.create( THREE.CurvePath.prototype );
  20778. THREE.Path.prototype.constructor = THREE.Path;
  20779. // TODO Clean up PATH API
  20780. // Create path using straight lines to connect all points
  20781. // - vectors: array of Vector2
  20782. THREE.Path.prototype.fromPoints = function ( vectors ) {
  20783. this.moveTo( vectors[ 0 ].x, vectors[ 0 ].y );
  20784. for ( var i = 1, l = vectors.length; i < l; i ++ ) {
  20785. this.lineTo( vectors[ i ].x, vectors[ i ].y );
  20786. }
  20787. };
  20788. // startPath() endPath()?
  20789. THREE.Path.prototype.moveTo = function ( x, y ) {
  20790. this.actions.push( { action: 'moveTo', args: [ x, y ] } );
  20791. };
  20792. THREE.Path.prototype.lineTo = function ( x, y ) {
  20793. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20794. var x0 = lastargs[ lastargs.length - 2 ];
  20795. var y0 = lastargs[ lastargs.length - 1 ];
  20796. var curve = new THREE.LineCurve( new THREE.Vector2( x0, y0 ), new THREE.Vector2( x, y ) );
  20797. this.curves.push( curve );
  20798. this.actions.push( { action: 'lineTo', args: [ x, y ] } );
  20799. };
  20800. THREE.Path.prototype.quadraticCurveTo = function( aCPx, aCPy, aX, aY ) {
  20801. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20802. var x0 = lastargs[ lastargs.length - 2 ];
  20803. var y0 = lastargs[ lastargs.length - 1 ];
  20804. var curve = new THREE.QuadraticBezierCurve(
  20805. new THREE.Vector2( x0, y0 ),
  20806. new THREE.Vector2( aCPx, aCPy ),
  20807. new THREE.Vector2( aX, aY )
  20808. );
  20809. this.curves.push( curve );
  20810. this.actions.push( { action: 'quadraticCurveTo', args: [ aCPx, aCPy, aX, aY ] } );
  20811. };
  20812. THREE.Path.prototype.bezierCurveTo = function( aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ) {
  20813. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20814. var x0 = lastargs[ lastargs.length - 2 ];
  20815. var y0 = lastargs[ lastargs.length - 1 ];
  20816. var curve = new THREE.CubicBezierCurve(
  20817. new THREE.Vector2( x0, y0 ),
  20818. new THREE.Vector2( aCP1x, aCP1y ),
  20819. new THREE.Vector2( aCP2x, aCP2y ),
  20820. new THREE.Vector2( aX, aY )
  20821. );
  20822. this.curves.push( curve );
  20823. this.actions.push( { action: 'bezierCurveTo', args: [ aCP1x, aCP1y, aCP2x, aCP2y, aX, aY ] } );
  20824. };
  20825. THREE.Path.prototype.splineThru = function( pts /*Array of Vector*/ ) {
  20826. var args = Array.prototype.slice.call( arguments );
  20827. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20828. var x0 = lastargs[ lastargs.length - 2 ];
  20829. var y0 = lastargs[ lastargs.length - 1 ];
  20830. var npts = [ new THREE.Vector2( x0, y0 ) ];
  20831. Array.prototype.push.apply( npts, pts );
  20832. var curve = new THREE.SplineCurve( npts );
  20833. this.curves.push( curve );
  20834. this.actions.push( { action: 'splineThru', args: args } );
  20835. };
  20836. // FUTURE: Change the API or follow canvas API?
  20837. THREE.Path.prototype.arc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20838. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20839. var x0 = lastargs[ lastargs.length - 2 ];
  20840. var y0 = lastargs[ lastargs.length - 1 ];
  20841. this.absarc( aX + x0, aY + y0, aRadius,
  20842. aStartAngle, aEndAngle, aClockwise );
  20843. };
  20844. THREE.Path.prototype.absarc = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  20845. this.absellipse( aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  20846. };
  20847. THREE.Path.prototype.ellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20848. var lastargs = this.actions[ this.actions.length - 1 ].args;
  20849. var x0 = lastargs[ lastargs.length - 2 ];
  20850. var y0 = lastargs[ lastargs.length - 1 ];
  20851. this.absellipse( aX + x0, aY + y0, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20852. };
  20853. THREE.Path.prototype.absellipse = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  20854. var args = [
  20855. aX, aY,
  20856. xRadius, yRadius,
  20857. aStartAngle, aEndAngle,
  20858. aClockwise,
  20859. aRotation || 0 // aRotation is optional.
  20860. ];
  20861. var curve = new THREE.EllipseCurve( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation );
  20862. this.curves.push( curve );
  20863. var lastPoint = curve.getPoint( 1 );
  20864. args.push( lastPoint.x );
  20865. args.push( lastPoint.y );
  20866. this.actions.push( { action: 'ellipse', args: args } );
  20867. };
  20868. THREE.Path.prototype.getSpacedPoints = function ( divisions ) {
  20869. if ( ! divisions ) divisions = 40;
  20870. var points = [];
  20871. for ( var i = 0; i < divisions; i ++ ) {
  20872. points.push( this.getPoint( i / divisions ) );
  20873. //if ( !this.getPoint( i / divisions ) ) throw "DIE";
  20874. }
  20875. if ( this.autoClose ) {
  20876. points.push( points[ 0 ] );
  20877. }
  20878. return points;
  20879. };
  20880. /* Return an array of vectors based on contour of the path */
  20881. THREE.Path.prototype.getPoints = function( divisions ) {
  20882. divisions = divisions || 12;
  20883. var b2 = THREE.ShapeUtils.b2;
  20884. var b3 = THREE.ShapeUtils.b3;
  20885. var points = [];
  20886. var cpx, cpy, cpx2, cpy2, cpx1, cpy1, cpx0, cpy0,
  20887. laste, tx, ty;
  20888. for ( var i = 0, l = this.actions.length; i < l; i ++ ) {
  20889. var item = this.actions[ i ];
  20890. var action = item.action;
  20891. var args = item.args;
  20892. switch ( action ) {
  20893. case 'moveTo':
  20894. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20895. break;
  20896. case 'lineTo':
  20897. points.push( new THREE.Vector2( args[ 0 ], args[ 1 ] ) );
  20898. break;
  20899. case 'quadraticCurveTo':
  20900. cpx = args[ 2 ];
  20901. cpy = args[ 3 ];
  20902. cpx1 = args[ 0 ];
  20903. cpy1 = args[ 1 ];
  20904. if ( points.length > 0 ) {
  20905. laste = points[ points.length - 1 ];
  20906. cpx0 = laste.x;
  20907. cpy0 = laste.y;
  20908. } else {
  20909. laste = this.actions[ i - 1 ].args;
  20910. cpx0 = laste[ laste.length - 2 ];
  20911. cpy0 = laste[ laste.length - 1 ];
  20912. }
  20913. for ( var j = 1; j <= divisions; j ++ ) {
  20914. var t = j / divisions;
  20915. tx = b2( t, cpx0, cpx1, cpx );
  20916. ty = b2( t, cpy0, cpy1, cpy );
  20917. points.push( new THREE.Vector2( tx, ty ) );
  20918. }
  20919. break;
  20920. case 'bezierCurveTo':
  20921. cpx = args[ 4 ];
  20922. cpy = args[ 5 ];
  20923. cpx1 = args[ 0 ];
  20924. cpy1 = args[ 1 ];
  20925. cpx2 = args[ 2 ];
  20926. cpy2 = args[ 3 ];
  20927. if ( points.length > 0 ) {
  20928. laste = points[ points.length - 1 ];
  20929. cpx0 = laste.x;
  20930. cpy0 = laste.y;
  20931. } else {
  20932. laste = this.actions[ i - 1 ].args;
  20933. cpx0 = laste[ laste.length - 2 ];
  20934. cpy0 = laste[ laste.length - 1 ];
  20935. }
  20936. for ( var j = 1; j <= divisions; j ++ ) {
  20937. var t = j / divisions;
  20938. tx = b3( t, cpx0, cpx1, cpx2, cpx );
  20939. ty = b3( t, cpy0, cpy1, cpy2, cpy );
  20940. points.push( new THREE.Vector2( tx, ty ) );
  20941. }
  20942. break;
  20943. case 'splineThru':
  20944. laste = this.actions[ i - 1 ].args;
  20945. var last = new THREE.Vector2( laste[ laste.length - 2 ], laste[ laste.length - 1 ] );
  20946. var spts = [ last ];
  20947. var n = divisions * args[ 0 ].length;
  20948. spts = spts.concat( args[ 0 ] );
  20949. var spline = new THREE.SplineCurve( spts );
  20950. for ( var j = 1; j <= n; j ++ ) {
  20951. points.push( spline.getPointAt( j / n ) );
  20952. }
  20953. break;
  20954. case 'arc':
  20955. var aX = args[ 0 ], aY = args[ 1 ],
  20956. aRadius = args[ 2 ],
  20957. aStartAngle = args[ 3 ], aEndAngle = args[ 4 ],
  20958. aClockwise = !! args[ 5 ];
  20959. var deltaAngle = aEndAngle - aStartAngle;
  20960. var angle;
  20961. var tdivisions = divisions * 2;
  20962. for ( var j = 1; j <= tdivisions; j ++ ) {
  20963. var t = j / tdivisions;
  20964. if ( ! aClockwise ) {
  20965. t = 1 - t;
  20966. }
  20967. angle = aStartAngle + t * deltaAngle;
  20968. tx = aX + aRadius * Math.cos( angle );
  20969. ty = aY + aRadius * Math.sin( angle );
  20970. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  20971. points.push( new THREE.Vector2( tx, ty ) );
  20972. }
  20973. //console.log(points);
  20974. break;
  20975. case 'ellipse':
  20976. var aX = args[ 0 ], aY = args[ 1 ],
  20977. xRadius = args[ 2 ],
  20978. yRadius = args[ 3 ],
  20979. aStartAngle = args[ 4 ], aEndAngle = args[ 5 ],
  20980. aClockwise = !! args[ 6 ],
  20981. aRotation = args[ 7 ];
  20982. var deltaAngle = aEndAngle - aStartAngle;
  20983. var angle;
  20984. var tdivisions = divisions * 2;
  20985. var cos, sin;
  20986. if ( aRotation !== 0 ) {
  20987. cos = Math.cos( aRotation );
  20988. sin = Math.sin( aRotation );
  20989. }
  20990. for ( var j = 1; j <= tdivisions; j ++ ) {
  20991. var t = j / tdivisions;
  20992. if ( ! aClockwise ) {
  20993. t = 1 - t;
  20994. }
  20995. angle = aStartAngle + t * deltaAngle;
  20996. tx = aX + xRadius * Math.cos( angle );
  20997. ty = aY + yRadius * Math.sin( angle );
  20998. if ( aRotation !== 0 ) {
  20999. var x = tx, y = ty;
  21000. // Rotate the point about the center of the ellipse.
  21001. tx = ( x - aX ) * cos - ( y - aY ) * sin + aX;
  21002. ty = ( x - aX ) * sin + ( y - aY ) * cos + aY;
  21003. }
  21004. //console.log('t', t, 'angle', angle, 'tx', tx, 'ty', ty);
  21005. points.push( new THREE.Vector2( tx, ty ) );
  21006. }
  21007. //console.log(points);
  21008. break;
  21009. } // end switch
  21010. }
  21011. // Normalize to remove the closing point by default.
  21012. var lastPoint = points[ points.length - 1 ];
  21013. if ( Math.abs( lastPoint.x - points[ 0 ].x ) < Number.EPSILON &&
  21014. Math.abs( lastPoint.y - points[ 0 ].y ) < Number.EPSILON )
  21015. points.splice( points.length - 1, 1 );
  21016. if ( this.autoClose ) {
  21017. points.push( points[ 0 ] );
  21018. }
  21019. return points;
  21020. };
  21021. //
  21022. // Breaks path into shapes
  21023. //
  21024. // Assumptions (if parameter isCCW==true the opposite holds):
  21025. // - solid shapes are defined clockwise (CW)
  21026. // - holes are defined counterclockwise (CCW)
  21027. //
  21028. // If parameter noHoles==true:
  21029. // - all subPaths are regarded as solid shapes
  21030. // - definition order CW/CCW has no relevance
  21031. //
  21032. THREE.Path.prototype.toShapes = function( isCCW, noHoles ) {
  21033. function extractSubpaths( inActions ) {
  21034. var subPaths = [], lastPath = new THREE.Path();
  21035. for ( var i = 0, l = inActions.length; i < l; i ++ ) {
  21036. var item = inActions[ i ];
  21037. var args = item.args;
  21038. var action = item.action;
  21039. if ( action === 'moveTo' ) {
  21040. if ( lastPath.actions.length !== 0 ) {
  21041. subPaths.push( lastPath );
  21042. lastPath = new THREE.Path();
  21043. }
  21044. }
  21045. lastPath[ action ].apply( lastPath, args );
  21046. }
  21047. if ( lastPath.actions.length !== 0 ) {
  21048. subPaths.push( lastPath );
  21049. }
  21050. // console.log(subPaths);
  21051. return subPaths;
  21052. }
  21053. function toShapesNoHoles( inSubpaths ) {
  21054. var shapes = [];
  21055. for ( var i = 0, l = inSubpaths.length; i < l; i ++ ) {
  21056. var tmpPath = inSubpaths[ i ];
  21057. var tmpShape = new THREE.Shape();
  21058. tmpShape.actions = tmpPath.actions;
  21059. tmpShape.curves = tmpPath.curves;
  21060. shapes.push( tmpShape );
  21061. }
  21062. //console.log("shape", shapes);
  21063. return shapes;
  21064. }
  21065. function isPointInsidePolygon( inPt, inPolygon ) {
  21066. var polyLen = inPolygon.length;
  21067. // inPt on polygon contour => immediate success or
  21068. // toggling of inside/outside at every single! intersection point of an edge
  21069. // with the horizontal line through inPt, left of inPt
  21070. // not counting lowerY endpoints of edges and whole edges on that line
  21071. var inside = false;
  21072. for ( var p = polyLen - 1, q = 0; q < polyLen; p = q ++ ) {
  21073. var edgeLowPt = inPolygon[ p ];
  21074. var edgeHighPt = inPolygon[ q ];
  21075. var edgeDx = edgeHighPt.x - edgeLowPt.x;
  21076. var edgeDy = edgeHighPt.y - edgeLowPt.y;
  21077. if ( Math.abs( edgeDy ) > Number.EPSILON ) {
  21078. // not parallel
  21079. if ( edgeDy < 0 ) {
  21080. edgeLowPt = inPolygon[ q ]; edgeDx = - edgeDx;
  21081. edgeHighPt = inPolygon[ p ]; edgeDy = - edgeDy;
  21082. }
  21083. if ( ( inPt.y < edgeLowPt.y ) || ( inPt.y > edgeHighPt.y ) ) continue;
  21084. if ( inPt.y === edgeLowPt.y ) {
  21085. if ( inPt.x === edgeLowPt.x ) return true; // inPt is on contour ?
  21086. // continue; // no intersection or edgeLowPt => doesn't count !!!
  21087. } else {
  21088. var perpEdge = edgeDy * ( inPt.x - edgeLowPt.x ) - edgeDx * ( inPt.y - edgeLowPt.y );
  21089. if ( perpEdge === 0 ) return true; // inPt is on contour ?
  21090. if ( perpEdge < 0 ) continue;
  21091. inside = ! inside; // true intersection left of inPt
  21092. }
  21093. } else {
  21094. // parallel or collinear
  21095. if ( inPt.y !== edgeLowPt.y ) continue; // parallel
  21096. // edge lies on the same horizontal line as inPt
  21097. if ( ( ( edgeHighPt.x <= inPt.x ) && ( inPt.x <= edgeLowPt.x ) ) ||
  21098. ( ( edgeLowPt.x <= inPt.x ) && ( inPt.x <= edgeHighPt.x ) ) ) return true; // inPt: Point on contour !
  21099. // continue;
  21100. }
  21101. }
  21102. return inside;
  21103. }
  21104. var isClockWise = THREE.ShapeUtils.isClockWise;
  21105. var subPaths = extractSubpaths( this.actions );
  21106. if ( subPaths.length === 0 ) return [];
  21107. if ( noHoles === true ) return toShapesNoHoles( subPaths );
  21108. var solid, tmpPath, tmpShape, shapes = [];
  21109. if ( subPaths.length === 1 ) {
  21110. tmpPath = subPaths[ 0 ];
  21111. tmpShape = new THREE.Shape();
  21112. tmpShape.actions = tmpPath.actions;
  21113. tmpShape.curves = tmpPath.curves;
  21114. shapes.push( tmpShape );
  21115. return shapes;
  21116. }
  21117. var holesFirst = ! isClockWise( subPaths[ 0 ].getPoints() );
  21118. holesFirst = isCCW ? ! holesFirst : holesFirst;
  21119. // console.log("Holes first", holesFirst);
  21120. var betterShapeHoles = [];
  21121. var newShapes = [];
  21122. var newShapeHoles = [];
  21123. var mainIdx = 0;
  21124. var tmpPoints;
  21125. newShapes[ mainIdx ] = undefined;
  21126. newShapeHoles[ mainIdx ] = [];
  21127. for ( var i = 0, l = subPaths.length; i < l; i ++ ) {
  21128. tmpPath = subPaths[ i ];
  21129. tmpPoints = tmpPath.getPoints();
  21130. solid = isClockWise( tmpPoints );
  21131. solid = isCCW ? ! solid : solid;
  21132. if ( solid ) {
  21133. if ( ( ! holesFirst ) && ( newShapes[ mainIdx ] ) ) mainIdx ++;
  21134. newShapes[ mainIdx ] = { s: new THREE.Shape(), p: tmpPoints };
  21135. newShapes[ mainIdx ].s.actions = tmpPath.actions;
  21136. newShapes[ mainIdx ].s.curves = tmpPath.curves;
  21137. if ( holesFirst ) mainIdx ++;
  21138. newShapeHoles[ mainIdx ] = [];
  21139. //console.log('cw', i);
  21140. } else {
  21141. newShapeHoles[ mainIdx ].push( { h: tmpPath, p: tmpPoints[ 0 ] } );
  21142. //console.log('ccw', i);
  21143. }
  21144. }
  21145. // only Holes? -> probably all Shapes with wrong orientation
  21146. if ( ! newShapes[ 0 ] ) return toShapesNoHoles( subPaths );
  21147. if ( newShapes.length > 1 ) {
  21148. var ambiguous = false;
  21149. var toChange = [];
  21150. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21151. betterShapeHoles[ sIdx ] = [];
  21152. }
  21153. for ( var sIdx = 0, sLen = newShapes.length; sIdx < sLen; sIdx ++ ) {
  21154. var sho = newShapeHoles[ sIdx ];
  21155. for ( var hIdx = 0; hIdx < sho.length; hIdx ++ ) {
  21156. var ho = sho[ hIdx ];
  21157. var hole_unassigned = true;
  21158. for ( var s2Idx = 0; s2Idx < newShapes.length; s2Idx ++ ) {
  21159. if ( isPointInsidePolygon( ho.p, newShapes[ s2Idx ].p ) ) {
  21160. if ( sIdx !== s2Idx ) toChange.push( { froms: sIdx, tos: s2Idx, hole: hIdx } );
  21161. if ( hole_unassigned ) {
  21162. hole_unassigned = false;
  21163. betterShapeHoles[ s2Idx ].push( ho );
  21164. } else {
  21165. ambiguous = true;
  21166. }
  21167. }
  21168. }
  21169. if ( hole_unassigned ) {
  21170. betterShapeHoles[ sIdx ].push( ho );
  21171. }
  21172. }
  21173. }
  21174. // console.log("ambiguous: ", ambiguous);
  21175. if ( toChange.length > 0 ) {
  21176. // console.log("to change: ", toChange);
  21177. if ( ! ambiguous ) newShapeHoles = betterShapeHoles;
  21178. }
  21179. }
  21180. var tmpHoles;
  21181. for ( var i = 0, il = newShapes.length; i < il; i ++ ) {
  21182. tmpShape = newShapes[ i ].s;
  21183. shapes.push( tmpShape );
  21184. tmpHoles = newShapeHoles[ i ];
  21185. for ( var j = 0, jl = tmpHoles.length; j < jl; j ++ ) {
  21186. tmpShape.holes.push( tmpHoles[ j ].h );
  21187. }
  21188. }
  21189. //console.log("shape", shapes);
  21190. return shapes;
  21191. };
  21192. // File:src/extras/core/Shape.js
  21193. /**
  21194. * @author zz85 / http://www.lab4games.net/zz85/blog
  21195. * Defines a 2d shape plane using paths.
  21196. **/
  21197. // STEP 1 Create a path.
  21198. // STEP 2 Turn path into shape.
  21199. // STEP 3 ExtrudeGeometry takes in Shape/Shapes
  21200. // STEP 3a - Extract points from each shape, turn to vertices
  21201. // STEP 3b - Triangulate each shape, add faces.
  21202. THREE.Shape = function () {
  21203. THREE.Path.apply( this, arguments );
  21204. this.holes = [];
  21205. };
  21206. THREE.Shape.prototype = Object.create( THREE.Path.prototype );
  21207. THREE.Shape.prototype.constructor = THREE.Shape;
  21208. // Convenience method to return ExtrudeGeometry
  21209. THREE.Shape.prototype.extrude = function ( options ) {
  21210. return new THREE.ExtrudeGeometry( this, options );
  21211. };
  21212. // Convenience method to return ShapeGeometry
  21213. THREE.Shape.prototype.makeGeometry = function ( options ) {
  21214. return new THREE.ShapeGeometry( this, options );
  21215. };
  21216. // Get points of holes
  21217. THREE.Shape.prototype.getPointsHoles = function ( divisions ) {
  21218. var holesPts = [];
  21219. for ( var i = 0, l = this.holes.length; i < l; i ++ ) {
  21220. holesPts[ i ] = this.holes[ i ].getPoints( divisions );
  21221. }
  21222. return holesPts;
  21223. };
  21224. // Get points of shape and holes (keypoints based on segments parameter)
  21225. THREE.Shape.prototype.extractAllPoints = function ( divisions ) {
  21226. return {
  21227. shape: this.getPoints( divisions ),
  21228. holes: this.getPointsHoles( divisions )
  21229. };
  21230. };
  21231. THREE.Shape.prototype.extractPoints = function ( divisions ) {
  21232. return this.extractAllPoints( divisions );
  21233. };
  21234. // File:src/extras/curves/LineCurve.js
  21235. /**************************************************************
  21236. * Line
  21237. **************************************************************/
  21238. THREE.LineCurve = function ( v1, v2 ) {
  21239. this.v1 = v1;
  21240. this.v2 = v2;
  21241. };
  21242. THREE.LineCurve.prototype = Object.create( THREE.Curve.prototype );
  21243. THREE.LineCurve.prototype.constructor = THREE.LineCurve;
  21244. THREE.LineCurve.prototype.getPoint = function ( t ) {
  21245. var point = this.v2.clone().sub( this.v1 );
  21246. point.multiplyScalar( t ).add( this.v1 );
  21247. return point;
  21248. };
  21249. // Line curve is linear, so we can overwrite default getPointAt
  21250. THREE.LineCurve.prototype.getPointAt = function ( u ) {
  21251. return this.getPoint( u );
  21252. };
  21253. THREE.LineCurve.prototype.getTangent = function( t ) {
  21254. var tangent = this.v2.clone().sub( this.v1 );
  21255. return tangent.normalize();
  21256. };
  21257. // File:src/extras/curves/QuadraticBezierCurve.js
  21258. /**************************************************************
  21259. * Quadratic Bezier curve
  21260. **************************************************************/
  21261. THREE.QuadraticBezierCurve = function ( v0, v1, v2 ) {
  21262. this.v0 = v0;
  21263. this.v1 = v1;
  21264. this.v2 = v2;
  21265. };
  21266. THREE.QuadraticBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21267. THREE.QuadraticBezierCurve.prototype.constructor = THREE.QuadraticBezierCurve;
  21268. THREE.QuadraticBezierCurve.prototype.getPoint = function ( t ) {
  21269. var b2 = THREE.ShapeUtils.b2;
  21270. return new THREE.Vector2(
  21271. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21272. b2( t, this.v0.y, this.v1.y, this.v2.y )
  21273. );
  21274. };
  21275. THREE.QuadraticBezierCurve.prototype.getTangent = function( t ) {
  21276. var tangentQuadraticBezier = THREE.CurveUtils.tangentQuadraticBezier;
  21277. return new THREE.Vector2(
  21278. tangentQuadraticBezier( t, this.v0.x, this.v1.x, this.v2.x ),
  21279. tangentQuadraticBezier( t, this.v0.y, this.v1.y, this.v2.y )
  21280. ).normalize();
  21281. };
  21282. // File:src/extras/curves/CubicBezierCurve.js
  21283. /**************************************************************
  21284. * Cubic Bezier curve
  21285. **************************************************************/
  21286. THREE.CubicBezierCurve = function ( v0, v1, v2, v3 ) {
  21287. this.v0 = v0;
  21288. this.v1 = v1;
  21289. this.v2 = v2;
  21290. this.v3 = v3;
  21291. };
  21292. THREE.CubicBezierCurve.prototype = Object.create( THREE.Curve.prototype );
  21293. THREE.CubicBezierCurve.prototype.constructor = THREE.CubicBezierCurve;
  21294. THREE.CubicBezierCurve.prototype.getPoint = function ( t ) {
  21295. var b3 = THREE.ShapeUtils.b3;
  21296. return new THREE.Vector2(
  21297. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21298. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21299. );
  21300. };
  21301. THREE.CubicBezierCurve.prototype.getTangent = function( t ) {
  21302. var tangentCubicBezier = THREE.CurveUtils.tangentCubicBezier;
  21303. return new THREE.Vector2(
  21304. tangentCubicBezier( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21305. tangentCubicBezier( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y )
  21306. ).normalize();
  21307. };
  21308. // File:src/extras/curves/SplineCurve.js
  21309. /**************************************************************
  21310. * Spline curve
  21311. **************************************************************/
  21312. THREE.SplineCurve = function ( points /* array of Vector2 */ ) {
  21313. this.points = ( points == undefined ) ? [] : points;
  21314. };
  21315. THREE.SplineCurve.prototype = Object.create( THREE.Curve.prototype );
  21316. THREE.SplineCurve.prototype.constructor = THREE.SplineCurve;
  21317. THREE.SplineCurve.prototype.getPoint = function ( t ) {
  21318. var points = this.points;
  21319. var point = ( points.length - 1 ) * t;
  21320. var intPoint = Math.floor( point );
  21321. var weight = point - intPoint;
  21322. var point0 = points[ intPoint === 0 ? intPoint : intPoint - 1 ];
  21323. var point1 = points[ intPoint ];
  21324. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21325. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21326. var interpolate = THREE.CurveUtils.interpolate;
  21327. return new THREE.Vector2(
  21328. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21329. interpolate( point0.y, point1.y, point2.y, point3.y, weight )
  21330. );
  21331. };
  21332. // File:src/extras/curves/EllipseCurve.js
  21333. /**************************************************************
  21334. * Ellipse curve
  21335. **************************************************************/
  21336. THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
  21337. this.aX = aX;
  21338. this.aY = aY;
  21339. this.xRadius = xRadius;
  21340. this.yRadius = yRadius;
  21341. this.aStartAngle = aStartAngle;
  21342. this.aEndAngle = aEndAngle;
  21343. this.aClockwise = aClockwise;
  21344. this.aRotation = aRotation || 0;
  21345. };
  21346. THREE.EllipseCurve.prototype = Object.create( THREE.Curve.prototype );
  21347. THREE.EllipseCurve.prototype.constructor = THREE.EllipseCurve;
  21348. THREE.EllipseCurve.prototype.getPoint = function ( t ) {
  21349. var deltaAngle = this.aEndAngle - this.aStartAngle;
  21350. if ( deltaAngle < 0 ) deltaAngle += Math.PI * 2;
  21351. if ( deltaAngle > Math.PI * 2 ) deltaAngle -= Math.PI * 2;
  21352. var angle;
  21353. if ( this.aClockwise === true ) {
  21354. angle = this.aEndAngle + ( 1 - t ) * ( Math.PI * 2 - deltaAngle );
  21355. } else {
  21356. angle = this.aStartAngle + t * deltaAngle;
  21357. }
  21358. var x = this.aX + this.xRadius * Math.cos( angle );
  21359. var y = this.aY + this.yRadius * Math.sin( angle );
  21360. if ( this.aRotation !== 0 ) {
  21361. var cos = Math.cos( this.aRotation );
  21362. var sin = Math.sin( this.aRotation );
  21363. var tx = x, ty = y;
  21364. // Rotate the point about the center of the ellipse.
  21365. x = ( tx - this.aX ) * cos - ( ty - this.aY ) * sin + this.aX;
  21366. y = ( tx - this.aX ) * sin + ( ty - this.aY ) * cos + this.aY;
  21367. }
  21368. return new THREE.Vector2( x, y );
  21369. };
  21370. // File:src/extras/curves/ArcCurve.js
  21371. /**************************************************************
  21372. * Arc curve
  21373. **************************************************************/
  21374. THREE.ArcCurve = function ( aX, aY, aRadius, aStartAngle, aEndAngle, aClockwise ) {
  21375. THREE.EllipseCurve.call( this, aX, aY, aRadius, aRadius, aStartAngle, aEndAngle, aClockwise );
  21376. };
  21377. THREE.ArcCurve.prototype = Object.create( THREE.EllipseCurve.prototype );
  21378. THREE.ArcCurve.prototype.constructor = THREE.ArcCurve;
  21379. // File:src/extras/curves/LineCurve3.js
  21380. /**************************************************************
  21381. * Line3D
  21382. **************************************************************/
  21383. THREE.LineCurve3 = THREE.Curve.create(
  21384. function ( v1, v2 ) {
  21385. this.v1 = v1;
  21386. this.v2 = v2;
  21387. },
  21388. function ( t ) {
  21389. var vector = new THREE.Vector3();
  21390. vector.subVectors( this.v2, this.v1 ); // diff
  21391. vector.multiplyScalar( t );
  21392. vector.add( this.v1 );
  21393. return vector;
  21394. }
  21395. );
  21396. // File:src/extras/curves/QuadraticBezierCurve3.js
  21397. /**************************************************************
  21398. * Quadratic Bezier 3D curve
  21399. **************************************************************/
  21400. THREE.QuadraticBezierCurve3 = THREE.Curve.create(
  21401. function ( v0, v1, v2 ) {
  21402. this.v0 = v0;
  21403. this.v1 = v1;
  21404. this.v2 = v2;
  21405. },
  21406. function ( t ) {
  21407. var b2 = THREE.ShapeUtils.b2;
  21408. return new THREE.Vector3(
  21409. b2( t, this.v0.x, this.v1.x, this.v2.x ),
  21410. b2( t, this.v0.y, this.v1.y, this.v2.y ),
  21411. b2( t, this.v0.z, this.v1.z, this.v2.z )
  21412. );
  21413. }
  21414. );
  21415. // File:src/extras/curves/CubicBezierCurve3.js
  21416. /**************************************************************
  21417. * Cubic Bezier 3D curve
  21418. **************************************************************/
  21419. THREE.CubicBezierCurve3 = THREE.Curve.create(
  21420. function ( v0, v1, v2, v3 ) {
  21421. this.v0 = v0;
  21422. this.v1 = v1;
  21423. this.v2 = v2;
  21424. this.v3 = v3;
  21425. },
  21426. function ( t ) {
  21427. var b3 = THREE.ShapeUtils.b3;
  21428. return new THREE.Vector3(
  21429. b3( t, this.v0.x, this.v1.x, this.v2.x, this.v3.x ),
  21430. b3( t, this.v0.y, this.v1.y, this.v2.y, this.v3.y ),
  21431. b3( t, this.v0.z, this.v1.z, this.v2.z, this.v3.z )
  21432. );
  21433. }
  21434. );
  21435. // File:src/extras/curves/SplineCurve3.js
  21436. /**************************************************************
  21437. * Spline 3D curve
  21438. **************************************************************/
  21439. THREE.SplineCurve3 = THREE.Curve.create(
  21440. function ( points /* array of Vector3 */ ) {
  21441. console.warn( 'THREE.SplineCurve3 will be deprecated. Please use THREE.CatmullRomCurve3' );
  21442. this.points = ( points == undefined ) ? [] : points;
  21443. },
  21444. function ( t ) {
  21445. var points = this.points;
  21446. var point = ( points.length - 1 ) * t;
  21447. var intPoint = Math.floor( point );
  21448. var weight = point - intPoint;
  21449. var point0 = points[ intPoint == 0 ? intPoint : intPoint - 1 ];
  21450. var point1 = points[ intPoint ];
  21451. var point2 = points[ intPoint > points.length - 2 ? points.length - 1 : intPoint + 1 ];
  21452. var point3 = points[ intPoint > points.length - 3 ? points.length - 1 : intPoint + 2 ];
  21453. var interpolate = THREE.CurveUtils.interpolate;
  21454. return new THREE.Vector3(
  21455. interpolate( point0.x, point1.x, point2.x, point3.x, weight ),
  21456. interpolate( point0.y, point1.y, point2.y, point3.y, weight ),
  21457. interpolate( point0.z, point1.z, point2.z, point3.z, weight )
  21458. );
  21459. }
  21460. );
  21461. // File:src/extras/curves/CatmullRomCurve3.js
  21462. /**
  21463. * @author zz85 https://github.com/zz85
  21464. *
  21465. * Centripetal CatmullRom Curve - which is useful for avoiding
  21466. * cusps and self-intersections in non-uniform catmull rom curves.
  21467. * http://www.cemyuksel.com/research/catmullrom_param/catmullrom.pdf
  21468. *
  21469. * curve.type accepts centripetal(default), chordal and catmullrom
  21470. * curve.tension is used for catmullrom which defaults to 0.5
  21471. */
  21472. THREE.CatmullRomCurve3 = ( function() {
  21473. var
  21474. tmp = new THREE.Vector3(),
  21475. px = new CubicPoly(),
  21476. py = new CubicPoly(),
  21477. pz = new CubicPoly();
  21478. /*
  21479. Based on an optimized c++ solution in
  21480. - http://stackoverflow.com/questions/9489736/catmull-rom-curve-with-no-cusps-and-no-self-intersections/
  21481. - http://ideone.com/NoEbVM
  21482. This CubicPoly class could be used for reusing some variables and calculations,
  21483. but for three.js curve use, it could be possible inlined and flatten into a single function call
  21484. which can be placed in CurveUtils.
  21485. */
  21486. function CubicPoly() {
  21487. }
  21488. /*
  21489. * Compute coefficients for a cubic polynomial
  21490. * p(s) = c0 + c1*s + c2*s^2 + c3*s^3
  21491. * such that
  21492. * p(0) = x0, p(1) = x1
  21493. * and
  21494. * p'(0) = t0, p'(1) = t1.
  21495. */
  21496. CubicPoly.prototype.init = function( x0, x1, t0, t1 ) {
  21497. this.c0 = x0;
  21498. this.c1 = t0;
  21499. this.c2 = - 3 * x0 + 3 * x1 - 2 * t0 - t1;
  21500. this.c3 = 2 * x0 - 2 * x1 + t0 + t1;
  21501. };
  21502. CubicPoly.prototype.initNonuniformCatmullRom = function( x0, x1, x2, x3, dt0, dt1, dt2 ) {
  21503. // compute tangents when parameterized in [t1,t2]
  21504. var t1 = ( x1 - x0 ) / dt0 - ( x2 - x0 ) / ( dt0 + dt1 ) + ( x2 - x1 ) / dt1;
  21505. var t2 = ( x2 - x1 ) / dt1 - ( x3 - x1 ) / ( dt1 + dt2 ) + ( x3 - x2 ) / dt2;
  21506. // rescale tangents for parametrization in [0,1]
  21507. t1 *= dt1;
  21508. t2 *= dt1;
  21509. // initCubicPoly
  21510. this.init( x1, x2, t1, t2 );
  21511. };
  21512. // standard Catmull-Rom spline: interpolate between x1 and x2 with previous/following points x1/x4
  21513. CubicPoly.prototype.initCatmullRom = function( x0, x1, x2, x3, tension ) {
  21514. this.init( x1, x2, tension * ( x2 - x0 ), tension * ( x3 - x1 ) );
  21515. };
  21516. CubicPoly.prototype.calc = function( t ) {
  21517. var t2 = t * t;
  21518. var t3 = t2 * t;
  21519. return this.c0 + this.c1 * t + this.c2 * t2 + this.c3 * t3;
  21520. };
  21521. // Subclass Three.js curve
  21522. return THREE.Curve.create(
  21523. function ( p /* array of Vector3 */ ) {
  21524. this.points = p || [];
  21525. this.closed = false;
  21526. },
  21527. function ( t ) {
  21528. var points = this.points,
  21529. point, intPoint, weight, l;
  21530. l = points.length;
  21531. if ( l < 2 ) console.log( 'duh, you need at least 2 points' );
  21532. point = ( l - ( this.closed ? 0 : 1 ) ) * t;
  21533. intPoint = Math.floor( point );
  21534. weight = point - intPoint;
  21535. if ( this.closed ) {
  21536. intPoint += intPoint > 0 ? 0 : ( Math.floor( Math.abs( intPoint ) / points.length ) + 1 ) * points.length;
  21537. } else if ( weight === 0 && intPoint === l - 1 ) {
  21538. intPoint = l - 2;
  21539. weight = 1;
  21540. }
  21541. var p0, p1, p2, p3; // 4 points
  21542. if ( this.closed || intPoint > 0 ) {
  21543. p0 = points[ ( intPoint - 1 ) % l ];
  21544. } else {
  21545. // extrapolate first point
  21546. tmp.subVectors( points[ 0 ], points[ 1 ] ).add( points[ 0 ] );
  21547. p0 = tmp;
  21548. }
  21549. p1 = points[ intPoint % l ];
  21550. p2 = points[ ( intPoint + 1 ) % l ];
  21551. if ( this.closed || intPoint + 2 < l ) {
  21552. p3 = points[ ( intPoint + 2 ) % l ];
  21553. } else {
  21554. // extrapolate last point
  21555. tmp.subVectors( points[ l - 1 ], points[ l - 2 ] ).add( points[ l - 1 ] );
  21556. p3 = tmp;
  21557. }
  21558. if ( this.type === undefined || this.type === 'centripetal' || this.type === 'chordal' ) {
  21559. // init Centripetal / Chordal Catmull-Rom
  21560. var pow = this.type === 'chordal' ? 0.5 : 0.25;
  21561. var dt0 = Math.pow( p0.distanceToSquared( p1 ), pow );
  21562. var dt1 = Math.pow( p1.distanceToSquared( p2 ), pow );
  21563. var dt2 = Math.pow( p2.distanceToSquared( p3 ), pow );
  21564. // safety check for repeated points
  21565. if ( dt1 < 1e-4 ) dt1 = 1.0;
  21566. if ( dt0 < 1e-4 ) dt0 = dt1;
  21567. if ( dt2 < 1e-4 ) dt2 = dt1;
  21568. px.initNonuniformCatmullRom( p0.x, p1.x, p2.x, p3.x, dt0, dt1, dt2 );
  21569. py.initNonuniformCatmullRom( p0.y, p1.y, p2.y, p3.y, dt0, dt1, dt2 );
  21570. pz.initNonuniformCatmullRom( p0.z, p1.z, p2.z, p3.z, dt0, dt1, dt2 );
  21571. } else if ( this.type === 'catmullrom' ) {
  21572. var tension = this.tension !== undefined ? this.tension : 0.5;
  21573. px.initCatmullRom( p0.x, p1.x, p2.x, p3.x, tension );
  21574. py.initCatmullRom( p0.y, p1.y, p2.y, p3.y, tension );
  21575. pz.initCatmullRom( p0.z, p1.z, p2.z, p3.z, tension );
  21576. }
  21577. var v = new THREE.Vector3(
  21578. px.calc( weight ),
  21579. py.calc( weight ),
  21580. pz.calc( weight )
  21581. );
  21582. return v;
  21583. }
  21584. );
  21585. } )();
  21586. // File:src/extras/curves/ClosedSplineCurve3.js
  21587. /**************************************************************
  21588. * Closed Spline 3D curve
  21589. **************************************************************/
  21590. THREE.ClosedSplineCurve3 = function ( points ) {
  21591. console.warn( 'THREE.ClosedSplineCurve3 has been deprecated. Please use THREE.CatmullRomCurve3.' );
  21592. THREE.CatmullRomCurve3.call( this, points );
  21593. this.type = 'catmullrom';
  21594. this.closed = true;
  21595. };
  21596. THREE.ClosedSplineCurve3.prototype = Object.create( THREE.CatmullRomCurve3.prototype );
  21597. // File:src/extras/geometries/BoxGeometry.js
  21598. /**
  21599. * @author mrdoob / http://mrdoob.com/
  21600. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Cube.as
  21601. */
  21602. THREE.BoxGeometry = function ( width, height, depth, widthSegments, heightSegments, depthSegments ) {
  21603. THREE.Geometry.call( this );
  21604. this.type = 'BoxGeometry';
  21605. this.parameters = {
  21606. width: width,
  21607. height: height,
  21608. depth: depth,
  21609. widthSegments: widthSegments,
  21610. heightSegments: heightSegments,
  21611. depthSegments: depthSegments
  21612. };
  21613. this.widthSegments = widthSegments || 1;
  21614. this.heightSegments = heightSegments || 1;
  21615. this.depthSegments = depthSegments || 1;
  21616. var scope = this;
  21617. var width_half = width / 2;
  21618. var height_half = height / 2;
  21619. var depth_half = depth / 2;
  21620. buildPlane( 'z', 'y', - 1, - 1, depth, height, width_half, 0 ); // px
  21621. buildPlane( 'z', 'y', 1, - 1, depth, height, - width_half, 1 ); // nx
  21622. buildPlane( 'x', 'z', 1, 1, width, depth, height_half, 2 ); // py
  21623. buildPlane( 'x', 'z', 1, - 1, width, depth, - height_half, 3 ); // ny
  21624. buildPlane( 'x', 'y', 1, - 1, width, height, depth_half, 4 ); // pz
  21625. buildPlane( 'x', 'y', - 1, - 1, width, height, - depth_half, 5 ); // nz
  21626. function buildPlane( u, v, udir, vdir, width, height, depth, materialIndex ) {
  21627. var w, ix, iy,
  21628. gridX = scope.widthSegments,
  21629. gridY = scope.heightSegments,
  21630. width_half = width / 2,
  21631. height_half = height / 2,
  21632. offset = scope.vertices.length;
  21633. if ( ( u === 'x' && v === 'y' ) || ( u === 'y' && v === 'x' ) ) {
  21634. w = 'z';
  21635. } else if ( ( u === 'x' && v === 'z' ) || ( u === 'z' && v === 'x' ) ) {
  21636. w = 'y';
  21637. gridY = scope.depthSegments;
  21638. } else if ( ( u === 'z' && v === 'y' ) || ( u === 'y' && v === 'z' ) ) {
  21639. w = 'x';
  21640. gridX = scope.depthSegments;
  21641. }
  21642. var gridX1 = gridX + 1,
  21643. gridY1 = gridY + 1,
  21644. segment_width = width / gridX,
  21645. segment_height = height / gridY,
  21646. normal = new THREE.Vector3();
  21647. normal[ w ] = depth > 0 ? 1 : - 1;
  21648. for ( iy = 0; iy < gridY1; iy ++ ) {
  21649. for ( ix = 0; ix < gridX1; ix ++ ) {
  21650. var vector = new THREE.Vector3();
  21651. vector[ u ] = ( ix * segment_width - width_half ) * udir;
  21652. vector[ v ] = ( iy * segment_height - height_half ) * vdir;
  21653. vector[ w ] = depth;
  21654. scope.vertices.push( vector );
  21655. }
  21656. }
  21657. for ( iy = 0; iy < gridY; iy ++ ) {
  21658. for ( ix = 0; ix < gridX; ix ++ ) {
  21659. var a = ix + gridX1 * iy;
  21660. var b = ix + gridX1 * ( iy + 1 );
  21661. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  21662. var d = ( ix + 1 ) + gridX1 * iy;
  21663. var uva = new THREE.Vector2( ix / gridX, 1 - iy / gridY );
  21664. var uvb = new THREE.Vector2( ix / gridX, 1 - ( iy + 1 ) / gridY );
  21665. var uvc = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - ( iy + 1 ) / gridY );
  21666. var uvd = new THREE.Vector2( ( ix + 1 ) / gridX, 1 - iy / gridY );
  21667. var face = new THREE.Face3( a + offset, b + offset, d + offset );
  21668. face.normal.copy( normal );
  21669. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  21670. face.materialIndex = materialIndex;
  21671. scope.faces.push( face );
  21672. scope.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  21673. face = new THREE.Face3( b + offset, c + offset, d + offset );
  21674. face.normal.copy( normal );
  21675. face.vertexNormals.push( normal.clone(), normal.clone(), normal.clone() );
  21676. face.materialIndex = materialIndex;
  21677. scope.faces.push( face );
  21678. scope.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  21679. }
  21680. }
  21681. }
  21682. this.mergeVertices();
  21683. };
  21684. THREE.BoxGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21685. THREE.BoxGeometry.prototype.constructor = THREE.BoxGeometry;
  21686. THREE.CubeGeometry = THREE.BoxGeometry;
  21687. // File:src/extras/geometries/CircleGeometry.js
  21688. /**
  21689. * @author hughes
  21690. */
  21691. THREE.CircleGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21692. THREE.Geometry.call( this );
  21693. this.type = 'CircleGeometry';
  21694. this.parameters = {
  21695. radius: radius,
  21696. segments: segments,
  21697. thetaStart: thetaStart,
  21698. thetaLength: thetaLength
  21699. };
  21700. this.fromBufferGeometry( new THREE.CircleBufferGeometry( radius, segments, thetaStart, thetaLength ) );
  21701. };
  21702. THREE.CircleGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21703. THREE.CircleGeometry.prototype.constructor = THREE.CircleGeometry;
  21704. // File:src/extras/geometries/CircleBufferGeometry.js
  21705. /**
  21706. * @author benaadams / https://twitter.com/ben_a_adams
  21707. */
  21708. THREE.CircleBufferGeometry = function ( radius, segments, thetaStart, thetaLength ) {
  21709. THREE.BufferGeometry.call( this );
  21710. this.type = 'CircleBufferGeometry';
  21711. this.parameters = {
  21712. radius: radius,
  21713. segments: segments,
  21714. thetaStart: thetaStart,
  21715. thetaLength: thetaLength
  21716. };
  21717. radius = radius || 50;
  21718. segments = segments !== undefined ? Math.max( 3, segments ) : 8;
  21719. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21720. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  21721. var vertices = segments + 2;
  21722. var positions = new Float32Array( vertices * 3 );
  21723. var normals = new Float32Array( vertices * 3 );
  21724. var uvs = new Float32Array( vertices * 2 );
  21725. // center data is already zero, but need to set a few extras
  21726. normals[ 2 ] = 1.0;
  21727. uvs[ 0 ] = 0.5;
  21728. uvs[ 1 ] = 0.5;
  21729. for ( var s = 0, i = 3, ii = 2 ; s <= segments; s ++, i += 3, ii += 2 ) {
  21730. var segment = thetaStart + s / segments * thetaLength;
  21731. positions[ i ] = radius * Math.cos( segment );
  21732. positions[ i + 1 ] = radius * Math.sin( segment );
  21733. normals[ i + 2 ] = 1; // normal z
  21734. uvs[ ii ] = ( positions[ i ] / radius + 1 ) / 2;
  21735. uvs[ ii + 1 ] = ( positions[ i + 1 ] / radius + 1 ) / 2;
  21736. }
  21737. var indices = [];
  21738. for ( var i = 1; i <= segments; i ++ ) {
  21739. indices.push( i, i + 1, 0 );
  21740. }
  21741. this.setIndex( new THREE.BufferAttribute( new Uint16Array( indices ), 1 ) );
  21742. this.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  21743. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  21744. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  21745. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  21746. };
  21747. THREE.CircleBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21748. THREE.CircleBufferGeometry.prototype.constructor = THREE.CircleBufferGeometry;
  21749. // File:src/extras/geometries/CylinderGeometry.js
  21750. /**
  21751. * @author mrdoob / http://mrdoob.com/
  21752. */
  21753. THREE.CylinderGeometry = function ( radiusTop, radiusBottom, height, radialSegments, heightSegments, openEnded, thetaStart, thetaLength ) {
  21754. THREE.Geometry.call( this );
  21755. this.type = 'CylinderGeometry';
  21756. this.parameters = {
  21757. radiusTop: radiusTop,
  21758. radiusBottom: radiusBottom,
  21759. height: height,
  21760. radialSegments: radialSegments,
  21761. heightSegments: heightSegments,
  21762. openEnded: openEnded,
  21763. thetaStart: thetaStart,
  21764. thetaLength: thetaLength
  21765. };
  21766. radiusTop = radiusTop !== undefined ? radiusTop : 20;
  21767. radiusBottom = radiusBottom !== undefined ? radiusBottom : 20;
  21768. height = height !== undefined ? height : 100;
  21769. radialSegments = radialSegments || 8;
  21770. heightSegments = heightSegments || 1;
  21771. openEnded = openEnded !== undefined ? openEnded : false;
  21772. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  21773. thetaLength = thetaLength !== undefined ? thetaLength : 2 * Math.PI;
  21774. var heightHalf = height / 2;
  21775. var x, y, vertices = [], uvs = [];
  21776. for ( y = 0; y <= heightSegments; y ++ ) {
  21777. var verticesRow = [];
  21778. var uvsRow = [];
  21779. var v = y / heightSegments;
  21780. var radius = v * ( radiusBottom - radiusTop ) + radiusTop;
  21781. for ( x = 0; x <= radialSegments; x ++ ) {
  21782. var u = x / radialSegments;
  21783. var vertex = new THREE.Vector3();
  21784. vertex.x = radius * Math.sin( u * thetaLength + thetaStart );
  21785. vertex.y = - v * height + heightHalf;
  21786. vertex.z = radius * Math.cos( u * thetaLength + thetaStart );
  21787. this.vertices.push( vertex );
  21788. verticesRow.push( this.vertices.length - 1 );
  21789. uvsRow.push( new THREE.Vector2( u, 1 - v ) );
  21790. }
  21791. vertices.push( verticesRow );
  21792. uvs.push( uvsRow );
  21793. }
  21794. var tanTheta = ( radiusBottom - radiusTop ) / height;
  21795. var na, nb;
  21796. for ( x = 0; x < radialSegments; x ++ ) {
  21797. if ( radiusTop !== 0 ) {
  21798. na = this.vertices[ vertices[ 0 ][ x ] ].clone();
  21799. nb = this.vertices[ vertices[ 0 ][ x + 1 ] ].clone();
  21800. } else {
  21801. na = this.vertices[ vertices[ 1 ][ x ] ].clone();
  21802. nb = this.vertices[ vertices[ 1 ][ x + 1 ] ].clone();
  21803. }
  21804. na.setY( Math.sqrt( na.x * na.x + na.z * na.z ) * tanTheta ).normalize();
  21805. nb.setY( Math.sqrt( nb.x * nb.x + nb.z * nb.z ) * tanTheta ).normalize();
  21806. for ( y = 0; y < heightSegments; y ++ ) {
  21807. var v1 = vertices[ y ][ x ];
  21808. var v2 = vertices[ y + 1 ][ x ];
  21809. var v3 = vertices[ y + 1 ][ x + 1 ];
  21810. var v4 = vertices[ y ][ x + 1 ];
  21811. var n1 = na.clone();
  21812. var n2 = na.clone();
  21813. var n3 = nb.clone();
  21814. var n4 = nb.clone();
  21815. var uv1 = uvs[ y ][ x ].clone();
  21816. var uv2 = uvs[ y + 1 ][ x ].clone();
  21817. var uv3 = uvs[ y + 1 ][ x + 1 ].clone();
  21818. var uv4 = uvs[ y ][ x + 1 ].clone();
  21819. this.faces.push( new THREE.Face3( v1, v2, v4, [ n1, n2, n4 ] ) );
  21820. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv4 ] );
  21821. this.faces.push( new THREE.Face3( v2, v3, v4, [ n2.clone(), n3, n4.clone() ] ) );
  21822. this.faceVertexUvs[ 0 ].push( [ uv2.clone(), uv3, uv4.clone() ] );
  21823. }
  21824. }
  21825. // top cap
  21826. if ( openEnded === false && radiusTop > 0 ) {
  21827. this.vertices.push( new THREE.Vector3( 0, heightHalf, 0 ) );
  21828. for ( x = 0; x < radialSegments; x ++ ) {
  21829. var v1 = vertices[ 0 ][ x ];
  21830. var v2 = vertices[ 0 ][ x + 1 ];
  21831. var v3 = this.vertices.length - 1;
  21832. var n1 = new THREE.Vector3( 0, 1, 0 );
  21833. var n2 = new THREE.Vector3( 0, 1, 0 );
  21834. var n3 = new THREE.Vector3( 0, 1, 0 );
  21835. var uv1 = uvs[ 0 ][ x ].clone();
  21836. var uv2 = uvs[ 0 ][ x + 1 ].clone();
  21837. var uv3 = new THREE.Vector2( uv2.x, 0 );
  21838. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 1 ) );
  21839. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21840. }
  21841. }
  21842. // bottom cap
  21843. if ( openEnded === false && radiusBottom > 0 ) {
  21844. this.vertices.push( new THREE.Vector3( 0, - heightHalf, 0 ) );
  21845. for ( x = 0; x < radialSegments; x ++ ) {
  21846. var v1 = vertices[ heightSegments ][ x + 1 ];
  21847. var v2 = vertices[ heightSegments ][ x ];
  21848. var v3 = this.vertices.length - 1;
  21849. var n1 = new THREE.Vector3( 0, - 1, 0 );
  21850. var n2 = new THREE.Vector3( 0, - 1, 0 );
  21851. var n3 = new THREE.Vector3( 0, - 1, 0 );
  21852. var uv1 = uvs[ heightSegments ][ x + 1 ].clone();
  21853. var uv2 = uvs[ heightSegments ][ x ].clone();
  21854. var uv3 = new THREE.Vector2( uv2.x, 1 );
  21855. this.faces.push( new THREE.Face3( v1, v2, v3, [ n1, n2, n3 ], undefined, 2 ) );
  21856. this.faceVertexUvs[ 0 ].push( [ uv1, uv2, uv3 ] );
  21857. }
  21858. }
  21859. this.computeFaceNormals();
  21860. };
  21861. THREE.CylinderGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21862. THREE.CylinderGeometry.prototype.constructor = THREE.CylinderGeometry;
  21863. // File:src/extras/geometries/EdgesGeometry.js
  21864. /**
  21865. * @author WestLangley / http://github.com/WestLangley
  21866. */
  21867. THREE.EdgesGeometry = function ( geometry, thresholdAngle ) {
  21868. THREE.BufferGeometry.call( this );
  21869. thresholdAngle = ( thresholdAngle !== undefined ) ? thresholdAngle : 1;
  21870. var thresholdDot = Math.cos( THREE.Math.degToRad( thresholdAngle ) );
  21871. var edge = [ 0, 0 ], hash = {};
  21872. function sortFunction( a, b ) {
  21873. return a - b;
  21874. }
  21875. var keys = [ 'a', 'b', 'c' ];
  21876. var geometry2;
  21877. if ( geometry instanceof THREE.BufferGeometry ) {
  21878. geometry2 = new THREE.Geometry();
  21879. geometry2.fromBufferGeometry( geometry );
  21880. } else {
  21881. geometry2 = geometry.clone();
  21882. }
  21883. geometry2.mergeVertices();
  21884. geometry2.computeFaceNormals();
  21885. var vertices = geometry2.vertices;
  21886. var faces = geometry2.faces;
  21887. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  21888. var face = faces[ i ];
  21889. for ( var j = 0; j < 3; j ++ ) {
  21890. edge[ 0 ] = face[ keys[ j ] ];
  21891. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  21892. edge.sort( sortFunction );
  21893. var key = edge.toString();
  21894. if ( hash[ key ] === undefined ) {
  21895. hash[ key ] = { vert1: edge[ 0 ], vert2: edge[ 1 ], face1: i, face2: undefined };
  21896. } else {
  21897. hash[ key ].face2 = i;
  21898. }
  21899. }
  21900. }
  21901. var coords = [];
  21902. for ( var key in hash ) {
  21903. var h = hash[ key ];
  21904. if ( h.face2 === undefined || faces[ h.face1 ].normal.dot( faces[ h.face2 ].normal ) <= thresholdDot ) {
  21905. var vertex = vertices[ h.vert1 ];
  21906. coords.push( vertex.x );
  21907. coords.push( vertex.y );
  21908. coords.push( vertex.z );
  21909. vertex = vertices[ h.vert2 ];
  21910. coords.push( vertex.x );
  21911. coords.push( vertex.y );
  21912. coords.push( vertex.z );
  21913. }
  21914. }
  21915. this.addAttribute( 'position', new THREE.BufferAttribute( new Float32Array( coords ), 3 ) );
  21916. };
  21917. THREE.EdgesGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  21918. THREE.EdgesGeometry.prototype.constructor = THREE.EdgesGeometry;
  21919. // File:src/extras/geometries/ExtrudeGeometry.js
  21920. /**
  21921. * @author zz85 / http://www.lab4games.net/zz85/blog
  21922. *
  21923. * Creates extruded geometry from a path shape.
  21924. *
  21925. * parameters = {
  21926. *
  21927. * curveSegments: <int>, // number of points on the curves
  21928. * steps: <int>, // number of points for z-side extrusions / used for subdividing segments of extrude spline too
  21929. * amount: <int>, // Depth to extrude the shape
  21930. *
  21931. * bevelEnabled: <bool>, // turn on bevel
  21932. * bevelThickness: <float>, // how deep into the original shape bevel goes
  21933. * bevelSize: <float>, // how far from shape outline is bevel
  21934. * bevelSegments: <int>, // number of bevel layers
  21935. *
  21936. * extrudePath: <THREE.CurvePath> // 3d spline path to extrude shape along. (creates Frames if .frames aren't defined)
  21937. * frames: <THREE.TubeGeometry.FrenetFrames> // containing arrays of tangents, normals, binormals
  21938. *
  21939. * uvGenerator: <Object> // object that provides UV generator functions
  21940. *
  21941. * }
  21942. **/
  21943. THREE.ExtrudeGeometry = function ( shapes, options ) {
  21944. if ( typeof( shapes ) === "undefined" ) {
  21945. shapes = [];
  21946. return;
  21947. }
  21948. THREE.Geometry.call( this );
  21949. this.type = 'ExtrudeGeometry';
  21950. shapes = Array.isArray( shapes ) ? shapes : [ shapes ];
  21951. this.addShapeList( shapes, options );
  21952. this.computeFaceNormals();
  21953. // can't really use automatic vertex normals
  21954. // as then front and back sides get smoothed too
  21955. // should do separate smoothing just for sides
  21956. //this.computeVertexNormals();
  21957. //console.log( "took", ( Date.now() - startTime ) );
  21958. };
  21959. THREE.ExtrudeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  21960. THREE.ExtrudeGeometry.prototype.constructor = THREE.ExtrudeGeometry;
  21961. THREE.ExtrudeGeometry.prototype.addShapeList = function ( shapes, options ) {
  21962. var sl = shapes.length;
  21963. for ( var s = 0; s < sl; s ++ ) {
  21964. var shape = shapes[ s ];
  21965. this.addShape( shape, options );
  21966. }
  21967. };
  21968. THREE.ExtrudeGeometry.prototype.addShape = function ( shape, options ) {
  21969. var amount = options.amount !== undefined ? options.amount : 100;
  21970. var bevelThickness = options.bevelThickness !== undefined ? options.bevelThickness : 6; // 10
  21971. var bevelSize = options.bevelSize !== undefined ? options.bevelSize : bevelThickness - 2; // 8
  21972. var bevelSegments = options.bevelSegments !== undefined ? options.bevelSegments : 3;
  21973. var bevelEnabled = options.bevelEnabled !== undefined ? options.bevelEnabled : true; // false
  21974. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  21975. var steps = options.steps !== undefined ? options.steps : 1;
  21976. var extrudePath = options.extrudePath;
  21977. var extrudePts, extrudeByPath = false;
  21978. // Use default WorldUVGenerator if no UV generators are specified.
  21979. var uvgen = options.UVGenerator !== undefined ? options.UVGenerator : THREE.ExtrudeGeometry.WorldUVGenerator;
  21980. var splineTube, binormal, normal, position2;
  21981. if ( extrudePath ) {
  21982. extrudePts = extrudePath.getSpacedPoints( steps );
  21983. extrudeByPath = true;
  21984. bevelEnabled = false; // bevels not supported for path extrusion
  21985. // SETUP TNB variables
  21986. // Reuse TNB from TubeGeomtry for now.
  21987. // TODO1 - have a .isClosed in spline?
  21988. splineTube = options.frames !== undefined ? options.frames : new THREE.TubeGeometry.FrenetFrames( extrudePath, steps, false );
  21989. // console.log(splineTube, 'splineTube', splineTube.normals.length, 'steps', steps, 'extrudePts', extrudePts.length);
  21990. binormal = new THREE.Vector3();
  21991. normal = new THREE.Vector3();
  21992. position2 = new THREE.Vector3();
  21993. }
  21994. // Safeguards if bevels are not enabled
  21995. if ( ! bevelEnabled ) {
  21996. bevelSegments = 0;
  21997. bevelThickness = 0;
  21998. bevelSize = 0;
  21999. }
  22000. // Variables initialization
  22001. var ahole, h, hl; // looping of holes
  22002. var scope = this;
  22003. var shapesOffset = this.vertices.length;
  22004. var shapePoints = shape.extractPoints( curveSegments );
  22005. var vertices = shapePoints.shape;
  22006. var holes = shapePoints.holes;
  22007. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22008. if ( reverse ) {
  22009. vertices = vertices.reverse();
  22010. // Maybe we should also check if holes are in the opposite direction, just to be safe ...
  22011. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22012. ahole = holes[ h ];
  22013. if ( THREE.ShapeUtils.isClockWise( ahole ) ) {
  22014. holes[ h ] = ahole.reverse();
  22015. }
  22016. }
  22017. reverse = false; // If vertices are in order now, we shouldn't need to worry about them again (hopefully)!
  22018. }
  22019. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22020. /* Vertices */
  22021. var contour = vertices; // vertices has all points but contour has only points of circumference
  22022. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22023. ahole = holes[ h ];
  22024. vertices = vertices.concat( ahole );
  22025. }
  22026. function scalePt2 ( pt, vec, size ) {
  22027. if ( ! vec ) console.error( "THREE.ExtrudeGeometry: vec does not exist" );
  22028. return vec.clone().multiplyScalar( size ).add( pt );
  22029. }
  22030. var b, bs, t, z,
  22031. vert, vlen = vertices.length,
  22032. face, flen = faces.length;
  22033. // Find directions for point movement
  22034. function getBevelVec( inPt, inPrev, inNext ) {
  22035. // computes for inPt the corresponding point inPt' on a new contour
  22036. // shifted by 1 unit (length of normalized vector) to the left
  22037. // if we walk along contour clockwise, this new contour is outside the old one
  22038. //
  22039. // inPt' is the intersection of the two lines parallel to the two
  22040. // adjacent edges of inPt at a distance of 1 unit on the left side.
  22041. var v_trans_x, v_trans_y, shrink_by = 1; // resulting translation vector for inPt
  22042. // good reading for geometry algorithms (here: line-line intersection)
  22043. // http://geomalgorithms.com/a05-_intersect-1.html
  22044. var v_prev_x = inPt.x - inPrev.x, v_prev_y = inPt.y - inPrev.y;
  22045. var v_next_x = inNext.x - inPt.x, v_next_y = inNext.y - inPt.y;
  22046. var v_prev_lensq = ( v_prev_x * v_prev_x + v_prev_y * v_prev_y );
  22047. // check for collinear edges
  22048. var collinear0 = ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22049. if ( Math.abs( collinear0 ) > Number.EPSILON ) {
  22050. // not collinear
  22051. // length of vectors for normalizing
  22052. var v_prev_len = Math.sqrt( v_prev_lensq );
  22053. var v_next_len = Math.sqrt( v_next_x * v_next_x + v_next_y * v_next_y );
  22054. // shift adjacent points by unit vectors to the left
  22055. var ptPrevShift_x = ( inPrev.x - v_prev_y / v_prev_len );
  22056. var ptPrevShift_y = ( inPrev.y + v_prev_x / v_prev_len );
  22057. var ptNextShift_x = ( inNext.x - v_next_y / v_next_len );
  22058. var ptNextShift_y = ( inNext.y + v_next_x / v_next_len );
  22059. // scaling factor for v_prev to intersection point
  22060. var sf = ( ( ptNextShift_x - ptPrevShift_x ) * v_next_y -
  22061. ( ptNextShift_y - ptPrevShift_y ) * v_next_x ) /
  22062. ( v_prev_x * v_next_y - v_prev_y * v_next_x );
  22063. // vector from inPt to intersection point
  22064. v_trans_x = ( ptPrevShift_x + v_prev_x * sf - inPt.x );
  22065. v_trans_y = ( ptPrevShift_y + v_prev_y * sf - inPt.y );
  22066. // Don't normalize!, otherwise sharp corners become ugly
  22067. // but prevent crazy spikes
  22068. var v_trans_lensq = ( v_trans_x * v_trans_x + v_trans_y * v_trans_y );
  22069. if ( v_trans_lensq <= 2 ) {
  22070. return new THREE.Vector2( v_trans_x, v_trans_y );
  22071. } else {
  22072. shrink_by = Math.sqrt( v_trans_lensq / 2 );
  22073. }
  22074. } else {
  22075. // handle special case of collinear edges
  22076. var direction_eq = false; // assumes: opposite
  22077. if ( v_prev_x > Number.EPSILON ) {
  22078. if ( v_next_x > Number.EPSILON ) {
  22079. direction_eq = true;
  22080. }
  22081. } else {
  22082. if ( v_prev_x < - Number.EPSILON ) {
  22083. if ( v_next_x < - Number.EPSILON ) {
  22084. direction_eq = true;
  22085. }
  22086. } else {
  22087. if ( Math.sign( v_prev_y ) === Math.sign( v_next_y ) ) {
  22088. direction_eq = true;
  22089. }
  22090. }
  22091. }
  22092. if ( direction_eq ) {
  22093. // console.log("Warning: lines are a straight sequence");
  22094. v_trans_x = - v_prev_y;
  22095. v_trans_y = v_prev_x;
  22096. shrink_by = Math.sqrt( v_prev_lensq );
  22097. } else {
  22098. // console.log("Warning: lines are a straight spike");
  22099. v_trans_x = v_prev_x;
  22100. v_trans_y = v_prev_y;
  22101. shrink_by = Math.sqrt( v_prev_lensq / 2 );
  22102. }
  22103. }
  22104. return new THREE.Vector2( v_trans_x / shrink_by, v_trans_y / shrink_by );
  22105. }
  22106. var contourMovements = [];
  22107. for ( var i = 0, il = contour.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22108. if ( j === il ) j = 0;
  22109. if ( k === il ) k = 0;
  22110. // (j)---(i)---(k)
  22111. // console.log('i,j,k', i, j , k)
  22112. contourMovements[ i ] = getBevelVec( contour[ i ], contour[ j ], contour[ k ] );
  22113. }
  22114. var holesMovements = [], oneHoleMovements, verticesMovements = contourMovements.concat();
  22115. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22116. ahole = holes[ h ];
  22117. oneHoleMovements = [];
  22118. for ( i = 0, il = ahole.length, j = il - 1, k = i + 1; i < il; i ++, j ++, k ++ ) {
  22119. if ( j === il ) j = 0;
  22120. if ( k === il ) k = 0;
  22121. // (j)---(i)---(k)
  22122. oneHoleMovements[ i ] = getBevelVec( ahole[ i ], ahole[ j ], ahole[ k ] );
  22123. }
  22124. holesMovements.push( oneHoleMovements );
  22125. verticesMovements = verticesMovements.concat( oneHoleMovements );
  22126. }
  22127. // Loop bevelSegments, 1 for the front, 1 for the back
  22128. for ( b = 0; b < bevelSegments; b ++ ) {
  22129. //for ( b = bevelSegments; b > 0; b -- ) {
  22130. t = b / bevelSegments;
  22131. z = bevelThickness * ( 1 - t );
  22132. //z = bevelThickness * t;
  22133. bs = bevelSize * ( Math.sin ( t * Math.PI / 2 ) ); // curved
  22134. //bs = bevelSize * t; // linear
  22135. // contract shape
  22136. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22137. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22138. v( vert.x, vert.y, - z );
  22139. }
  22140. // expand holes
  22141. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22142. ahole = holes[ h ];
  22143. oneHoleMovements = holesMovements[ h ];
  22144. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22145. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22146. v( vert.x, vert.y, - z );
  22147. }
  22148. }
  22149. }
  22150. bs = bevelSize;
  22151. // Back facing vertices
  22152. for ( i = 0; i < vlen; i ++ ) {
  22153. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22154. if ( ! extrudeByPath ) {
  22155. v( vert.x, vert.y, 0 );
  22156. } else {
  22157. // v( vert.x, vert.y + extrudePts[ 0 ].y, extrudePts[ 0 ].x );
  22158. normal.copy( splineTube.normals[ 0 ] ).multiplyScalar( vert.x );
  22159. binormal.copy( splineTube.binormals[ 0 ] ).multiplyScalar( vert.y );
  22160. position2.copy( extrudePts[ 0 ] ).add( normal ).add( binormal );
  22161. v( position2.x, position2.y, position2.z );
  22162. }
  22163. }
  22164. // Add stepped vertices...
  22165. // Including front facing vertices
  22166. var s;
  22167. for ( s = 1; s <= steps; s ++ ) {
  22168. for ( i = 0; i < vlen; i ++ ) {
  22169. vert = bevelEnabled ? scalePt2( vertices[ i ], verticesMovements[ i ], bs ) : vertices[ i ];
  22170. if ( ! extrudeByPath ) {
  22171. v( vert.x, vert.y, amount / steps * s );
  22172. } else {
  22173. // v( vert.x, vert.y + extrudePts[ s - 1 ].y, extrudePts[ s - 1 ].x );
  22174. normal.copy( splineTube.normals[ s ] ).multiplyScalar( vert.x );
  22175. binormal.copy( splineTube.binormals[ s ] ).multiplyScalar( vert.y );
  22176. position2.copy( extrudePts[ s ] ).add( normal ).add( binormal );
  22177. v( position2.x, position2.y, position2.z );
  22178. }
  22179. }
  22180. }
  22181. // Add bevel segments planes
  22182. //for ( b = 1; b <= bevelSegments; b ++ ) {
  22183. for ( b = bevelSegments - 1; b >= 0; b -- ) {
  22184. t = b / bevelSegments;
  22185. z = bevelThickness * ( 1 - t );
  22186. //bs = bevelSize * ( 1-Math.sin ( ( 1 - t ) * Math.PI/2 ) );
  22187. bs = bevelSize * Math.sin ( t * Math.PI / 2 );
  22188. // contract shape
  22189. for ( i = 0, il = contour.length; i < il; i ++ ) {
  22190. vert = scalePt2( contour[ i ], contourMovements[ i ], bs );
  22191. v( vert.x, vert.y, amount + z );
  22192. }
  22193. // expand holes
  22194. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22195. ahole = holes[ h ];
  22196. oneHoleMovements = holesMovements[ h ];
  22197. for ( i = 0, il = ahole.length; i < il; i ++ ) {
  22198. vert = scalePt2( ahole[ i ], oneHoleMovements[ i ], bs );
  22199. if ( ! extrudeByPath ) {
  22200. v( vert.x, vert.y, amount + z );
  22201. } else {
  22202. v( vert.x, vert.y + extrudePts[ steps - 1 ].y, extrudePts[ steps - 1 ].x + z );
  22203. }
  22204. }
  22205. }
  22206. }
  22207. /* Faces */
  22208. // Top and bottom faces
  22209. buildLidFaces();
  22210. // Sides faces
  22211. buildSideFaces();
  22212. ///// Internal functions
  22213. function buildLidFaces() {
  22214. if ( bevelEnabled ) {
  22215. var layer = 0; // steps + 1
  22216. var offset = vlen * layer;
  22217. // Bottom faces
  22218. for ( i = 0; i < flen; i ++ ) {
  22219. face = faces[ i ];
  22220. f3( face[ 2 ] + offset, face[ 1 ] + offset, face[ 0 ] + offset );
  22221. }
  22222. layer = steps + bevelSegments * 2;
  22223. offset = vlen * layer;
  22224. // Top faces
  22225. for ( i = 0; i < flen; i ++ ) {
  22226. face = faces[ i ];
  22227. f3( face[ 0 ] + offset, face[ 1 ] + offset, face[ 2 ] + offset );
  22228. }
  22229. } else {
  22230. // Bottom faces
  22231. for ( i = 0; i < flen; i ++ ) {
  22232. face = faces[ i ];
  22233. f3( face[ 2 ], face[ 1 ], face[ 0 ] );
  22234. }
  22235. // Top faces
  22236. for ( i = 0; i < flen; i ++ ) {
  22237. face = faces[ i ];
  22238. f3( face[ 0 ] + vlen * steps, face[ 1 ] + vlen * steps, face[ 2 ] + vlen * steps );
  22239. }
  22240. }
  22241. }
  22242. // Create faces for the z-sides of the shape
  22243. function buildSideFaces() {
  22244. var layeroffset = 0;
  22245. sidewalls( contour, layeroffset );
  22246. layeroffset += contour.length;
  22247. for ( h = 0, hl = holes.length; h < hl; h ++ ) {
  22248. ahole = holes[ h ];
  22249. sidewalls( ahole, layeroffset );
  22250. //, true
  22251. layeroffset += ahole.length;
  22252. }
  22253. }
  22254. function sidewalls( contour, layeroffset ) {
  22255. var j, k;
  22256. i = contour.length;
  22257. while ( -- i >= 0 ) {
  22258. j = i;
  22259. k = i - 1;
  22260. if ( k < 0 ) k = contour.length - 1;
  22261. //console.log('b', i,j, i-1, k,vertices.length);
  22262. var s = 0, sl = steps + bevelSegments * 2;
  22263. for ( s = 0; s < sl; s ++ ) {
  22264. var slen1 = vlen * s;
  22265. var slen2 = vlen * ( s + 1 );
  22266. var a = layeroffset + j + slen1,
  22267. b = layeroffset + k + slen1,
  22268. c = layeroffset + k + slen2,
  22269. d = layeroffset + j + slen2;
  22270. f4( a, b, c, d, contour, s, sl, j, k );
  22271. }
  22272. }
  22273. }
  22274. function v( x, y, z ) {
  22275. scope.vertices.push( new THREE.Vector3( x, y, z ) );
  22276. }
  22277. function f3( a, b, c ) {
  22278. a += shapesOffset;
  22279. b += shapesOffset;
  22280. c += shapesOffset;
  22281. scope.faces.push( new THREE.Face3( a, b, c, null, null, 0 ) );
  22282. var uvs = uvgen.generateTopUV( scope, a, b, c );
  22283. scope.faceVertexUvs[ 0 ].push( uvs );
  22284. }
  22285. function f4( a, b, c, d, wallContour, stepIndex, stepsLength, contourIndex1, contourIndex2 ) {
  22286. a += shapesOffset;
  22287. b += shapesOffset;
  22288. c += shapesOffset;
  22289. d += shapesOffset;
  22290. scope.faces.push( new THREE.Face3( a, b, d, null, null, 1 ) );
  22291. scope.faces.push( new THREE.Face3( b, c, d, null, null, 1 ) );
  22292. var uvs = uvgen.generateSideWallUV( scope, a, b, c, d );
  22293. scope.faceVertexUvs[ 0 ].push( [ uvs[ 0 ], uvs[ 1 ], uvs[ 3 ] ] );
  22294. scope.faceVertexUvs[ 0 ].push( [ uvs[ 1 ], uvs[ 2 ], uvs[ 3 ] ] );
  22295. }
  22296. };
  22297. THREE.ExtrudeGeometry.WorldUVGenerator = {
  22298. generateTopUV: function ( geometry, indexA, indexB, indexC ) {
  22299. var vertices = geometry.vertices;
  22300. var a = vertices[ indexA ];
  22301. var b = vertices[ indexB ];
  22302. var c = vertices[ indexC ];
  22303. return [
  22304. new THREE.Vector2( a.x, a.y ),
  22305. new THREE.Vector2( b.x, b.y ),
  22306. new THREE.Vector2( c.x, c.y )
  22307. ];
  22308. },
  22309. generateSideWallUV: function ( geometry, indexA, indexB, indexC, indexD ) {
  22310. var vertices = geometry.vertices;
  22311. var a = vertices[ indexA ];
  22312. var b = vertices[ indexB ];
  22313. var c = vertices[ indexC ];
  22314. var d = vertices[ indexD ];
  22315. if ( Math.abs( a.y - b.y ) < 0.01 ) {
  22316. return [
  22317. new THREE.Vector2( a.x, 1 - a.z ),
  22318. new THREE.Vector2( b.x, 1 - b.z ),
  22319. new THREE.Vector2( c.x, 1 - c.z ),
  22320. new THREE.Vector2( d.x, 1 - d.z )
  22321. ];
  22322. } else {
  22323. return [
  22324. new THREE.Vector2( a.y, 1 - a.z ),
  22325. new THREE.Vector2( b.y, 1 - b.z ),
  22326. new THREE.Vector2( c.y, 1 - c.z ),
  22327. new THREE.Vector2( d.y, 1 - d.z )
  22328. ];
  22329. }
  22330. }
  22331. };
  22332. // File:src/extras/geometries/ShapeGeometry.js
  22333. /**
  22334. * @author jonobr1 / http://jonobr1.com
  22335. *
  22336. * Creates a one-sided polygonal geometry from a path shape. Similar to
  22337. * ExtrudeGeometry.
  22338. *
  22339. * parameters = {
  22340. *
  22341. * curveSegments: <int>, // number of points on the curves. NOT USED AT THE MOMENT.
  22342. *
  22343. * material: <int> // material index for front and back faces
  22344. * uvGenerator: <Object> // object that provides UV generator functions
  22345. *
  22346. * }
  22347. **/
  22348. THREE.ShapeGeometry = function ( shapes, options ) {
  22349. THREE.Geometry.call( this );
  22350. this.type = 'ShapeGeometry';
  22351. if ( Array.isArray( shapes ) === false ) shapes = [ shapes ];
  22352. this.addShapeList( shapes, options );
  22353. this.computeFaceNormals();
  22354. };
  22355. THREE.ShapeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22356. THREE.ShapeGeometry.prototype.constructor = THREE.ShapeGeometry;
  22357. /**
  22358. * Add an array of shapes to THREE.ShapeGeometry.
  22359. */
  22360. THREE.ShapeGeometry.prototype.addShapeList = function ( shapes, options ) {
  22361. for ( var i = 0, l = shapes.length; i < l; i ++ ) {
  22362. this.addShape( shapes[ i ], options );
  22363. }
  22364. return this;
  22365. };
  22366. /**
  22367. * Adds a shape to THREE.ShapeGeometry, based on THREE.ExtrudeGeometry.
  22368. */
  22369. THREE.ShapeGeometry.prototype.addShape = function ( shape, options ) {
  22370. if ( options === undefined ) options = {};
  22371. var curveSegments = options.curveSegments !== undefined ? options.curveSegments : 12;
  22372. var material = options.material;
  22373. var uvgen = options.UVGenerator === undefined ? THREE.ExtrudeGeometry.WorldUVGenerator : options.UVGenerator;
  22374. //
  22375. var i, l, hole;
  22376. var shapesOffset = this.vertices.length;
  22377. var shapePoints = shape.extractPoints( curveSegments );
  22378. var vertices = shapePoints.shape;
  22379. var holes = shapePoints.holes;
  22380. var reverse = ! THREE.ShapeUtils.isClockWise( vertices );
  22381. if ( reverse ) {
  22382. vertices = vertices.reverse();
  22383. // Maybe we should also check if holes are in the opposite direction, just to be safe...
  22384. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22385. hole = holes[ i ];
  22386. if ( THREE.ShapeUtils.isClockWise( hole ) ) {
  22387. holes[ i ] = hole.reverse();
  22388. }
  22389. }
  22390. reverse = false;
  22391. }
  22392. var faces = THREE.ShapeUtils.triangulateShape( vertices, holes );
  22393. // Vertices
  22394. for ( i = 0, l = holes.length; i < l; i ++ ) {
  22395. hole = holes[ i ];
  22396. vertices = vertices.concat( hole );
  22397. }
  22398. //
  22399. var vert, vlen = vertices.length;
  22400. var face, flen = faces.length;
  22401. for ( i = 0; i < vlen; i ++ ) {
  22402. vert = vertices[ i ];
  22403. this.vertices.push( new THREE.Vector3( vert.x, vert.y, 0 ) );
  22404. }
  22405. for ( i = 0; i < flen; i ++ ) {
  22406. face = faces[ i ];
  22407. var a = face[ 0 ] + shapesOffset;
  22408. var b = face[ 1 ] + shapesOffset;
  22409. var c = face[ 2 ] + shapesOffset;
  22410. this.faces.push( new THREE.Face3( a, b, c, null, null, material ) );
  22411. this.faceVertexUvs[ 0 ].push( uvgen.generateTopUV( this, a, b, c ) );
  22412. }
  22413. };
  22414. // File:src/extras/geometries/LatheGeometry.js
  22415. /**
  22416. * @author astrodud / http://astrodud.isgreat.org/
  22417. * @author zz85 / https://github.com/zz85
  22418. * @author bhouston / http://clara.io
  22419. */
  22420. // points - to create a closed torus, one must use a set of points
  22421. // like so: [ a, b, c, d, a ], see first is the same as last.
  22422. // segments - the number of circumference segments to create
  22423. // phiStart - the starting radian
  22424. // phiLength - the radian (0 to 2*PI) range of the lathed section
  22425. // 2*pi is a closed lathe, less than 2PI is a portion.
  22426. THREE.LatheGeometry = function ( points, segments, phiStart, phiLength ) {
  22427. THREE.Geometry.call( this );
  22428. this.type = 'LatheGeometry';
  22429. this.parameters = {
  22430. points: points,
  22431. segments: segments,
  22432. phiStart: phiStart,
  22433. phiLength: phiLength
  22434. };
  22435. segments = segments || 12;
  22436. phiStart = phiStart || 0;
  22437. phiLength = phiLength || 2 * Math.PI;
  22438. var inversePointLength = 1.0 / ( points.length - 1 );
  22439. var inverseSegments = 1.0 / segments;
  22440. for ( var i = 0, il = segments; i <= il; i ++ ) {
  22441. var phi = phiStart + i * inverseSegments * phiLength;
  22442. var sin = Math.sin( phi );
  22443. var cos = Math.cos( phi );
  22444. for ( var j = 0, jl = points.length; j < jl; j ++ ) {
  22445. var point = points[ j ];
  22446. var vertex = new THREE.Vector3();
  22447. vertex.x = point.x * sin;
  22448. vertex.y = point.y;
  22449. vertex.z = point.x * cos;
  22450. this.vertices.push( vertex );
  22451. }
  22452. }
  22453. var np = points.length;
  22454. for ( var i = 0, il = segments; i < il; i ++ ) {
  22455. for ( var j = 0, jl = points.length - 1; j < jl; j ++ ) {
  22456. var base = j + np * i;
  22457. var a = base;
  22458. var b = base + np;
  22459. var c = base + 1 + np;
  22460. var d = base + 1;
  22461. var u0 = i * inverseSegments;
  22462. var v0 = j * inversePointLength;
  22463. var u1 = u0 + inverseSegments;
  22464. var v1 = v0 + inversePointLength;
  22465. this.faces.push( new THREE.Face3( a, b, d ) );
  22466. this.faceVertexUvs[ 0 ].push( [
  22467. new THREE.Vector2( u0, v0 ),
  22468. new THREE.Vector2( u1, v0 ),
  22469. new THREE.Vector2( u0, v1 )
  22470. ] );
  22471. this.faces.push( new THREE.Face3( b, c, d ) );
  22472. this.faceVertexUvs[ 0 ].push( [
  22473. new THREE.Vector2( u1, v0 ),
  22474. new THREE.Vector2( u1, v1 ),
  22475. new THREE.Vector2( u0, v1 )
  22476. ] );
  22477. }
  22478. }
  22479. this.mergeVertices();
  22480. this.computeFaceNormals();
  22481. this.computeVertexNormals();
  22482. };
  22483. THREE.LatheGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22484. THREE.LatheGeometry.prototype.constructor = THREE.LatheGeometry;
  22485. // File:src/extras/geometries/PlaneGeometry.js
  22486. /**
  22487. * @author mrdoob / http://mrdoob.com/
  22488. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22489. */
  22490. THREE.PlaneGeometry = function ( width, height, widthSegments, heightSegments ) {
  22491. THREE.Geometry.call( this );
  22492. this.type = 'PlaneGeometry';
  22493. this.parameters = {
  22494. width: width,
  22495. height: height,
  22496. widthSegments: widthSegments,
  22497. heightSegments: heightSegments
  22498. };
  22499. this.fromBufferGeometry( new THREE.PlaneBufferGeometry( width, height, widthSegments, heightSegments ) );
  22500. };
  22501. THREE.PlaneGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22502. THREE.PlaneGeometry.prototype.constructor = THREE.PlaneGeometry;
  22503. // File:src/extras/geometries/PlaneBufferGeometry.js
  22504. /**
  22505. * @author mrdoob / http://mrdoob.com/
  22506. * based on http://papervision3d.googlecode.com/svn/trunk/as3/trunk/src/org/papervision3d/objects/primitives/Plane.as
  22507. */
  22508. THREE.PlaneBufferGeometry = function ( width, height, widthSegments, heightSegments ) {
  22509. THREE.BufferGeometry.call( this );
  22510. this.type = 'PlaneBufferGeometry';
  22511. this.parameters = {
  22512. width: width,
  22513. height: height,
  22514. widthSegments: widthSegments,
  22515. heightSegments: heightSegments
  22516. };
  22517. var width_half = width / 2;
  22518. var height_half = height / 2;
  22519. var gridX = Math.floor( widthSegments ) || 1;
  22520. var gridY = Math.floor( heightSegments ) || 1;
  22521. var gridX1 = gridX + 1;
  22522. var gridY1 = gridY + 1;
  22523. var segment_width = width / gridX;
  22524. var segment_height = height / gridY;
  22525. var vertices = new Float32Array( gridX1 * gridY1 * 3 );
  22526. var normals = new Float32Array( gridX1 * gridY1 * 3 );
  22527. var uvs = new Float32Array( gridX1 * gridY1 * 2 );
  22528. var offset = 0;
  22529. var offset2 = 0;
  22530. for ( var iy = 0; iy < gridY1; iy ++ ) {
  22531. var y = iy * segment_height - height_half;
  22532. for ( var ix = 0; ix < gridX1; ix ++ ) {
  22533. var x = ix * segment_width - width_half;
  22534. vertices[ offset ] = x;
  22535. vertices[ offset + 1 ] = - y;
  22536. normals[ offset + 2 ] = 1;
  22537. uvs[ offset2 ] = ix / gridX;
  22538. uvs[ offset2 + 1 ] = 1 - ( iy / gridY );
  22539. offset += 3;
  22540. offset2 += 2;
  22541. }
  22542. }
  22543. offset = 0;
  22544. var indices = new ( ( vertices.length / 3 ) > 65535 ? Uint32Array : Uint16Array )( gridX * gridY * 6 );
  22545. for ( var iy = 0; iy < gridY; iy ++ ) {
  22546. for ( var ix = 0; ix < gridX; ix ++ ) {
  22547. var a = ix + gridX1 * iy;
  22548. var b = ix + gridX1 * ( iy + 1 );
  22549. var c = ( ix + 1 ) + gridX1 * ( iy + 1 );
  22550. var d = ( ix + 1 ) + gridX1 * iy;
  22551. indices[ offset ] = a;
  22552. indices[ offset + 1 ] = b;
  22553. indices[ offset + 2 ] = d;
  22554. indices[ offset + 3 ] = b;
  22555. indices[ offset + 4 ] = c;
  22556. indices[ offset + 5 ] = d;
  22557. offset += 6;
  22558. }
  22559. }
  22560. this.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  22561. this.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  22562. this.addAttribute( 'normal', new THREE.BufferAttribute( normals, 3 ) );
  22563. this.addAttribute( 'uv', new THREE.BufferAttribute( uvs, 2 ) );
  22564. };
  22565. THREE.PlaneBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22566. THREE.PlaneBufferGeometry.prototype.constructor = THREE.PlaneBufferGeometry;
  22567. // File:src/extras/geometries/RingGeometry.js
  22568. /**
  22569. * @author Kaleb Murphy
  22570. */
  22571. THREE.RingGeometry = function ( innerRadius, outerRadius, thetaSegments, phiSegments, thetaStart, thetaLength ) {
  22572. THREE.Geometry.call( this );
  22573. this.type = 'RingGeometry';
  22574. this.parameters = {
  22575. innerRadius: innerRadius,
  22576. outerRadius: outerRadius,
  22577. thetaSegments: thetaSegments,
  22578. phiSegments: phiSegments,
  22579. thetaStart: thetaStart,
  22580. thetaLength: thetaLength
  22581. };
  22582. innerRadius = innerRadius || 0;
  22583. outerRadius = outerRadius || 50;
  22584. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22585. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI * 2;
  22586. thetaSegments = thetaSegments !== undefined ? Math.max( 3, thetaSegments ) : 8;
  22587. phiSegments = phiSegments !== undefined ? Math.max( 1, phiSegments ) : 8;
  22588. var i, o, uvs = [], radius = innerRadius, radiusStep = ( ( outerRadius - innerRadius ) / phiSegments );
  22589. for ( i = 0; i < phiSegments + 1; i ++ ) {
  22590. // concentric circles inside ring
  22591. for ( o = 0; o < thetaSegments + 1; o ++ ) {
  22592. // number of segments per circle
  22593. var vertex = new THREE.Vector3();
  22594. var segment = thetaStart + o / thetaSegments * thetaLength;
  22595. vertex.x = radius * Math.cos( segment );
  22596. vertex.y = radius * Math.sin( segment );
  22597. this.vertices.push( vertex );
  22598. uvs.push( new THREE.Vector2( ( vertex.x / outerRadius + 1 ) / 2, ( vertex.y / outerRadius + 1 ) / 2 ) );
  22599. }
  22600. radius += radiusStep;
  22601. }
  22602. var n = new THREE.Vector3( 0, 0, 1 );
  22603. for ( i = 0; i < phiSegments; i ++ ) {
  22604. // concentric circles inside ring
  22605. var thetaSegment = i * ( thetaSegments + 1 );
  22606. for ( o = 0; o < thetaSegments ; o ++ ) {
  22607. // number of segments per circle
  22608. var segment = o + thetaSegment;
  22609. var v1 = segment;
  22610. var v2 = segment + thetaSegments + 1;
  22611. var v3 = segment + thetaSegments + 2;
  22612. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  22613. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  22614. v1 = segment;
  22615. v2 = segment + thetaSegments + 2;
  22616. v3 = segment + 1;
  22617. this.faces.push( new THREE.Face3( v1, v2, v3, [ n.clone(), n.clone(), n.clone() ] ) );
  22618. this.faceVertexUvs[ 0 ].push( [ uvs[ v1 ].clone(), uvs[ v2 ].clone(), uvs[ v3 ].clone() ] );
  22619. }
  22620. }
  22621. this.computeFaceNormals();
  22622. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22623. };
  22624. THREE.RingGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22625. THREE.RingGeometry.prototype.constructor = THREE.RingGeometry;
  22626. // File:src/extras/geometries/SphereGeometry.js
  22627. /**
  22628. * @author mrdoob / http://mrdoob.com/
  22629. */
  22630. THREE.SphereGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22631. THREE.Geometry.call( this );
  22632. this.type = 'SphereGeometry';
  22633. this.parameters = {
  22634. radius: radius,
  22635. widthSegments: widthSegments,
  22636. heightSegments: heightSegments,
  22637. phiStart: phiStart,
  22638. phiLength: phiLength,
  22639. thetaStart: thetaStart,
  22640. thetaLength: thetaLength
  22641. };
  22642. this.fromBufferGeometry( new THREE.SphereBufferGeometry( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) );
  22643. };
  22644. THREE.SphereGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22645. THREE.SphereGeometry.prototype.constructor = THREE.SphereGeometry;
  22646. // File:src/extras/geometries/SphereBufferGeometry.js
  22647. /**
  22648. * @author benaadams / https://twitter.com/ben_a_adams
  22649. * based on THREE.SphereGeometry
  22650. */
  22651. THREE.SphereBufferGeometry = function ( radius, widthSegments, heightSegments, phiStart, phiLength, thetaStart, thetaLength ) {
  22652. THREE.BufferGeometry.call( this );
  22653. this.type = 'SphereBufferGeometry';
  22654. this.parameters = {
  22655. radius: radius,
  22656. widthSegments: widthSegments,
  22657. heightSegments: heightSegments,
  22658. phiStart: phiStart,
  22659. phiLength: phiLength,
  22660. thetaStart: thetaStart,
  22661. thetaLength: thetaLength
  22662. };
  22663. radius = radius || 50;
  22664. widthSegments = Math.max( 3, Math.floor( widthSegments ) || 8 );
  22665. heightSegments = Math.max( 2, Math.floor( heightSegments ) || 6 );
  22666. phiStart = phiStart !== undefined ? phiStart : 0;
  22667. phiLength = phiLength !== undefined ? phiLength : Math.PI * 2;
  22668. thetaStart = thetaStart !== undefined ? thetaStart : 0;
  22669. thetaLength = thetaLength !== undefined ? thetaLength : Math.PI;
  22670. var thetaEnd = thetaStart + thetaLength;
  22671. var vertexCount = ( ( widthSegments + 1 ) * ( heightSegments + 1 ) );
  22672. var positions = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22673. var normals = new THREE.BufferAttribute( new Float32Array( vertexCount * 3 ), 3 );
  22674. var uvs = new THREE.BufferAttribute( new Float32Array( vertexCount * 2 ), 2 );
  22675. var index = 0, vertices = [], normal = new THREE.Vector3();
  22676. for ( var y = 0; y <= heightSegments; y ++ ) {
  22677. var verticesRow = [];
  22678. var v = y / heightSegments;
  22679. for ( var x = 0; x <= widthSegments; x ++ ) {
  22680. var u = x / widthSegments;
  22681. var px = - radius * Math.cos( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22682. var py = radius * Math.cos( thetaStart + v * thetaLength );
  22683. var pz = radius * Math.sin( phiStart + u * phiLength ) * Math.sin( thetaStart + v * thetaLength );
  22684. normal.set( px, py, pz ).normalize();
  22685. positions.setXYZ( index, px, py, pz );
  22686. normals.setXYZ( index, normal.x, normal.y, normal.z );
  22687. uvs.setXY( index, u, 1 - v );
  22688. verticesRow.push( index );
  22689. index ++;
  22690. }
  22691. vertices.push( verticesRow );
  22692. }
  22693. var indices = [];
  22694. for ( var y = 0; y < heightSegments; y ++ ) {
  22695. for ( var x = 0; x < widthSegments; x ++ ) {
  22696. var v1 = vertices[ y ][ x + 1 ];
  22697. var v2 = vertices[ y ][ x ];
  22698. var v3 = vertices[ y + 1 ][ x ];
  22699. var v4 = vertices[ y + 1 ][ x + 1 ];
  22700. if ( y !== 0 || thetaStart > 0 ) indices.push( v1, v2, v4 );
  22701. if ( y !== heightSegments - 1 || thetaEnd < Math.PI ) indices.push( v2, v3, v4 );
  22702. }
  22703. }
  22704. this.setIndex( new ( positions.count > 65535 ? THREE.Uint32Attribute : THREE.Uint16Attribute )( indices, 1 ) );
  22705. this.addAttribute( 'position', positions );
  22706. this.addAttribute( 'normal', normals );
  22707. this.addAttribute( 'uv', uvs );
  22708. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  22709. };
  22710. THREE.SphereBufferGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  22711. THREE.SphereBufferGeometry.prototype.constructor = THREE.SphereBufferGeometry;
  22712. // File:src/extras/geometries/TextGeometry.js
  22713. /**
  22714. * @author zz85 / http://www.lab4games.net/zz85/blog
  22715. * @author alteredq / http://alteredqualia.com/
  22716. *
  22717. * Text = 3D Text
  22718. *
  22719. * parameters = {
  22720. * font: <THREE.Font>, // font
  22721. *
  22722. * size: <float>, // size of the text
  22723. * height: <float>, // thickness to extrude text
  22724. * curveSegments: <int>, // number of points on the curves
  22725. *
  22726. * bevelEnabled: <bool>, // turn on bevel
  22727. * bevelThickness: <float>, // how deep into text bevel goes
  22728. * bevelSize: <float> // how far from text outline is bevel
  22729. * }
  22730. */
  22731. THREE.TextGeometry = function ( text, parameters ) {
  22732. parameters = parameters || {};
  22733. var font = parameters.font;
  22734. if ( font instanceof THREE.Font === false ) {
  22735. console.error( 'THREE.TextGeometry: font parameter is not an instance of THREE.Font.' );
  22736. return new THREE.Geometry();
  22737. }
  22738. var shapes = font.generateShapes( text, parameters.size, parameters.curveSegments );
  22739. // translate parameters to ExtrudeGeometry API
  22740. parameters.amount = parameters.height !== undefined ? parameters.height : 50;
  22741. // defaults
  22742. if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
  22743. if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
  22744. if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
  22745. THREE.ExtrudeGeometry.call( this, shapes, parameters );
  22746. this.type = 'TextGeometry';
  22747. };
  22748. THREE.TextGeometry.prototype = Object.create( THREE.ExtrudeGeometry.prototype );
  22749. THREE.TextGeometry.prototype.constructor = THREE.TextGeometry;
  22750. // File:src/extras/geometries/TorusGeometry.js
  22751. /**
  22752. * @author oosmoxiecode
  22753. * @author mrdoob / http://mrdoob.com/
  22754. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3DLite/src/away3dlite/primitives/Torus.as?r=2888
  22755. */
  22756. THREE.TorusGeometry = function ( radius, tube, radialSegments, tubularSegments, arc ) {
  22757. THREE.Geometry.call( this );
  22758. this.type = 'TorusGeometry';
  22759. this.parameters = {
  22760. radius: radius,
  22761. tube: tube,
  22762. radialSegments: radialSegments,
  22763. tubularSegments: tubularSegments,
  22764. arc: arc
  22765. };
  22766. radius = radius || 100;
  22767. tube = tube || 40;
  22768. radialSegments = radialSegments || 8;
  22769. tubularSegments = tubularSegments || 6;
  22770. arc = arc || Math.PI * 2;
  22771. var center = new THREE.Vector3(), uvs = [], normals = [];
  22772. for ( var j = 0; j <= radialSegments; j ++ ) {
  22773. for ( var i = 0; i <= tubularSegments; i ++ ) {
  22774. var u = i / tubularSegments * arc;
  22775. var v = j / radialSegments * Math.PI * 2;
  22776. center.x = radius * Math.cos( u );
  22777. center.y = radius * Math.sin( u );
  22778. var vertex = new THREE.Vector3();
  22779. vertex.x = ( radius + tube * Math.cos( v ) ) * Math.cos( u );
  22780. vertex.y = ( radius + tube * Math.cos( v ) ) * Math.sin( u );
  22781. vertex.z = tube * Math.sin( v );
  22782. this.vertices.push( vertex );
  22783. uvs.push( new THREE.Vector2( i / tubularSegments, j / radialSegments ) );
  22784. normals.push( vertex.clone().sub( center ).normalize() );
  22785. }
  22786. }
  22787. for ( var j = 1; j <= radialSegments; j ++ ) {
  22788. for ( var i = 1; i <= tubularSegments; i ++ ) {
  22789. var a = ( tubularSegments + 1 ) * j + i - 1;
  22790. var b = ( tubularSegments + 1 ) * ( j - 1 ) + i - 1;
  22791. var c = ( tubularSegments + 1 ) * ( j - 1 ) + i;
  22792. var d = ( tubularSegments + 1 ) * j + i;
  22793. var face = new THREE.Face3( a, b, d, [ normals[ a ].clone(), normals[ b ].clone(), normals[ d ].clone() ] );
  22794. this.faces.push( face );
  22795. this.faceVertexUvs[ 0 ].push( [ uvs[ a ].clone(), uvs[ b ].clone(), uvs[ d ].clone() ] );
  22796. face = new THREE.Face3( b, c, d, [ normals[ b ].clone(), normals[ c ].clone(), normals[ d ].clone() ] );
  22797. this.faces.push( face );
  22798. this.faceVertexUvs[ 0 ].push( [ uvs[ b ].clone(), uvs[ c ].clone(), uvs[ d ].clone() ] );
  22799. }
  22800. }
  22801. this.computeFaceNormals();
  22802. };
  22803. THREE.TorusGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22804. THREE.TorusGeometry.prototype.constructor = THREE.TorusGeometry;
  22805. // File:src/extras/geometries/TorusKnotGeometry.js
  22806. /**
  22807. * @author oosmoxiecode
  22808. * based on http://code.google.com/p/away3d/source/browse/trunk/fp10/Away3D/src/away3d/primitives/TorusKnot.as?spec=svn2473&r=2473
  22809. */
  22810. THREE.TorusKnotGeometry = function ( radius, tube, radialSegments, tubularSegments, p, q, heightScale ) {
  22811. THREE.Geometry.call( this );
  22812. this.type = 'TorusKnotGeometry';
  22813. this.parameters = {
  22814. radius: radius,
  22815. tube: tube,
  22816. radialSegments: radialSegments,
  22817. tubularSegments: tubularSegments,
  22818. p: p,
  22819. q: q,
  22820. heightScale: heightScale
  22821. };
  22822. radius = radius || 100;
  22823. tube = tube || 40;
  22824. radialSegments = radialSegments || 64;
  22825. tubularSegments = tubularSegments || 8;
  22826. p = p || 2;
  22827. q = q || 3;
  22828. heightScale = heightScale || 1;
  22829. var grid = new Array( radialSegments );
  22830. var tang = new THREE.Vector3();
  22831. var n = new THREE.Vector3();
  22832. var bitan = new THREE.Vector3();
  22833. for ( var i = 0; i < radialSegments; ++ i ) {
  22834. grid[ i ] = new Array( tubularSegments );
  22835. var u = i / radialSegments * 2 * p * Math.PI;
  22836. var p1 = getPos( u, q, p, radius, heightScale );
  22837. var p2 = getPos( u + 0.01, q, p, radius, heightScale );
  22838. tang.subVectors( p2, p1 );
  22839. n.addVectors( p2, p1 );
  22840. bitan.crossVectors( tang, n );
  22841. n.crossVectors( bitan, tang );
  22842. bitan.normalize();
  22843. n.normalize();
  22844. for ( var j = 0; j < tubularSegments; ++ j ) {
  22845. var v = j / tubularSegments * 2 * Math.PI;
  22846. var cx = - tube * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22847. var cy = tube * Math.sin( v );
  22848. var pos = new THREE.Vector3();
  22849. pos.x = p1.x + cx * n.x + cy * bitan.x;
  22850. pos.y = p1.y + cx * n.y + cy * bitan.y;
  22851. pos.z = p1.z + cx * n.z + cy * bitan.z;
  22852. grid[ i ][ j ] = this.vertices.push( pos ) - 1;
  22853. }
  22854. }
  22855. for ( var i = 0; i < radialSegments; ++ i ) {
  22856. for ( var j = 0; j < tubularSegments; ++ j ) {
  22857. var ip = ( i + 1 ) % radialSegments;
  22858. var jp = ( j + 1 ) % tubularSegments;
  22859. var a = grid[ i ][ j ];
  22860. var b = grid[ ip ][ j ];
  22861. var c = grid[ ip ][ jp ];
  22862. var d = grid[ i ][ jp ];
  22863. var uva = new THREE.Vector2( i / radialSegments, j / tubularSegments );
  22864. var uvb = new THREE.Vector2( ( i + 1 ) / radialSegments, j / tubularSegments );
  22865. var uvc = new THREE.Vector2( ( i + 1 ) / radialSegments, ( j + 1 ) / tubularSegments );
  22866. var uvd = new THREE.Vector2( i / radialSegments, ( j + 1 ) / tubularSegments );
  22867. this.faces.push( new THREE.Face3( a, b, d ) );
  22868. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22869. this.faces.push( new THREE.Face3( b, c, d ) );
  22870. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22871. }
  22872. }
  22873. this.computeFaceNormals();
  22874. this.computeVertexNormals();
  22875. function getPos( u, in_q, in_p, radius, heightScale ) {
  22876. var cu = Math.cos( u );
  22877. var su = Math.sin( u );
  22878. var quOverP = in_q / in_p * u;
  22879. var cs = Math.cos( quOverP );
  22880. var tx = radius * ( 2 + cs ) * 0.5 * cu;
  22881. var ty = radius * ( 2 + cs ) * su * 0.5;
  22882. var tz = heightScale * radius * Math.sin( quOverP ) * 0.5;
  22883. return new THREE.Vector3( tx, ty, tz );
  22884. }
  22885. };
  22886. THREE.TorusKnotGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22887. THREE.TorusKnotGeometry.prototype.constructor = THREE.TorusKnotGeometry;
  22888. // File:src/extras/geometries/TubeGeometry.js
  22889. /**
  22890. * @author WestLangley / https://github.com/WestLangley
  22891. * @author zz85 / https://github.com/zz85
  22892. * @author miningold / https://github.com/miningold
  22893. * @author jonobr1 / https://github.com/jonobr1
  22894. *
  22895. * Modified from the TorusKnotGeometry by @oosmoxiecode
  22896. *
  22897. * Creates a tube which extrudes along a 3d spline
  22898. *
  22899. * Uses parallel transport frames as described in
  22900. * http://www.cs.indiana.edu/pub/techreports/TR425.pdf
  22901. */
  22902. THREE.TubeGeometry = function ( path, segments, radius, radialSegments, closed, taper ) {
  22903. THREE.Geometry.call( this );
  22904. this.type = 'TubeGeometry';
  22905. this.parameters = {
  22906. path: path,
  22907. segments: segments,
  22908. radius: radius,
  22909. radialSegments: radialSegments,
  22910. closed: closed,
  22911. taper: taper
  22912. };
  22913. segments = segments || 64;
  22914. radius = radius || 1;
  22915. radialSegments = radialSegments || 8;
  22916. closed = closed || false;
  22917. taper = taper || THREE.TubeGeometry.NoTaper;
  22918. var grid = [];
  22919. var scope = this,
  22920. tangent,
  22921. normal,
  22922. binormal,
  22923. numpoints = segments + 1,
  22924. u, v, r,
  22925. cx, cy,
  22926. pos, pos2 = new THREE.Vector3(),
  22927. i, j,
  22928. ip, jp,
  22929. a, b, c, d,
  22930. uva, uvb, uvc, uvd;
  22931. var frames = new THREE.TubeGeometry.FrenetFrames( path, segments, closed ),
  22932. tangents = frames.tangents,
  22933. normals = frames.normals,
  22934. binormals = frames.binormals;
  22935. // proxy internals
  22936. this.tangents = tangents;
  22937. this.normals = normals;
  22938. this.binormals = binormals;
  22939. function vert( x, y, z ) {
  22940. return scope.vertices.push( new THREE.Vector3( x, y, z ) ) - 1;
  22941. }
  22942. // construct the grid
  22943. for ( i = 0; i < numpoints; i ++ ) {
  22944. grid[ i ] = [];
  22945. u = i / ( numpoints - 1 );
  22946. pos = path.getPointAt( u );
  22947. tangent = tangents[ i ];
  22948. normal = normals[ i ];
  22949. binormal = binormals[ i ];
  22950. r = radius * taper( u );
  22951. for ( j = 0; j < radialSegments; j ++ ) {
  22952. v = j / radialSegments * 2 * Math.PI;
  22953. cx = - r * Math.cos( v ); // TODO: Hack: Negating it so it faces outside.
  22954. cy = r * Math.sin( v );
  22955. pos2.copy( pos );
  22956. pos2.x += cx * normal.x + cy * binormal.x;
  22957. pos2.y += cx * normal.y + cy * binormal.y;
  22958. pos2.z += cx * normal.z + cy * binormal.z;
  22959. grid[ i ][ j ] = vert( pos2.x, pos2.y, pos2.z );
  22960. }
  22961. }
  22962. // construct the mesh
  22963. for ( i = 0; i < segments; i ++ ) {
  22964. for ( j = 0; j < radialSegments; j ++ ) {
  22965. ip = ( closed ) ? ( i + 1 ) % segments : i + 1;
  22966. jp = ( j + 1 ) % radialSegments;
  22967. a = grid[ i ][ j ]; // *** NOT NECESSARILY PLANAR ! ***
  22968. b = grid[ ip ][ j ];
  22969. c = grid[ ip ][ jp ];
  22970. d = grid[ i ][ jp ];
  22971. uva = new THREE.Vector2( i / segments, j / radialSegments );
  22972. uvb = new THREE.Vector2( ( i + 1 ) / segments, j / radialSegments );
  22973. uvc = new THREE.Vector2( ( i + 1 ) / segments, ( j + 1 ) / radialSegments );
  22974. uvd = new THREE.Vector2( i / segments, ( j + 1 ) / radialSegments );
  22975. this.faces.push( new THREE.Face3( a, b, d ) );
  22976. this.faceVertexUvs[ 0 ].push( [ uva, uvb, uvd ] );
  22977. this.faces.push( new THREE.Face3( b, c, d ) );
  22978. this.faceVertexUvs[ 0 ].push( [ uvb.clone(), uvc, uvd.clone() ] );
  22979. }
  22980. }
  22981. this.computeFaceNormals();
  22982. this.computeVertexNormals();
  22983. };
  22984. THREE.TubeGeometry.prototype = Object.create( THREE.Geometry.prototype );
  22985. THREE.TubeGeometry.prototype.constructor = THREE.TubeGeometry;
  22986. THREE.TubeGeometry.NoTaper = function ( u ) {
  22987. return 1;
  22988. };
  22989. THREE.TubeGeometry.SinusoidalTaper = function ( u ) {
  22990. return Math.sin( Math.PI * u );
  22991. };
  22992. // For computing of Frenet frames, exposing the tangents, normals and binormals the spline
  22993. THREE.TubeGeometry.FrenetFrames = function ( path, segments, closed ) {
  22994. var normal = new THREE.Vector3(),
  22995. tangents = [],
  22996. normals = [],
  22997. binormals = [],
  22998. vec = new THREE.Vector3(),
  22999. mat = new THREE.Matrix4(),
  23000. numpoints = segments + 1,
  23001. theta,
  23002. smallest,
  23003. tx, ty, tz,
  23004. i, u;
  23005. // expose internals
  23006. this.tangents = tangents;
  23007. this.normals = normals;
  23008. this.binormals = binormals;
  23009. // compute the tangent vectors for each segment on the path
  23010. for ( i = 0; i < numpoints; i ++ ) {
  23011. u = i / ( numpoints - 1 );
  23012. tangents[ i ] = path.getTangentAt( u );
  23013. tangents[ i ].normalize();
  23014. }
  23015. initialNormal3();
  23016. /*
  23017. function initialNormal1(lastBinormal) {
  23018. // fixed start binormal. Has dangers of 0 vectors
  23019. normals[ 0 ] = new THREE.Vector3();
  23020. binormals[ 0 ] = new THREE.Vector3();
  23021. if (lastBinormal===undefined) lastBinormal = new THREE.Vector3( 0, 0, 1 );
  23022. normals[ 0 ].crossVectors( lastBinormal, tangents[ 0 ] ).normalize();
  23023. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23024. }
  23025. function initialNormal2() {
  23026. // This uses the Frenet-Serret formula for deriving binormal
  23027. var t2 = path.getTangentAt( epsilon );
  23028. normals[ 0 ] = new THREE.Vector3().subVectors( t2, tangents[ 0 ] ).normalize();
  23029. binormals[ 0 ] = new THREE.Vector3().crossVectors( tangents[ 0 ], normals[ 0 ] );
  23030. normals[ 0 ].crossVectors( binormals[ 0 ], tangents[ 0 ] ).normalize(); // last binormal x tangent
  23031. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] ).normalize();
  23032. }
  23033. */
  23034. function initialNormal3() {
  23035. // select an initial normal vector perpendicular to the first tangent vector,
  23036. // and in the direction of the smallest tangent xyz component
  23037. normals[ 0 ] = new THREE.Vector3();
  23038. binormals[ 0 ] = new THREE.Vector3();
  23039. smallest = Number.MAX_VALUE;
  23040. tx = Math.abs( tangents[ 0 ].x );
  23041. ty = Math.abs( tangents[ 0 ].y );
  23042. tz = Math.abs( tangents[ 0 ].z );
  23043. if ( tx <= smallest ) {
  23044. smallest = tx;
  23045. normal.set( 1, 0, 0 );
  23046. }
  23047. if ( ty <= smallest ) {
  23048. smallest = ty;
  23049. normal.set( 0, 1, 0 );
  23050. }
  23051. if ( tz <= smallest ) {
  23052. normal.set( 0, 0, 1 );
  23053. }
  23054. vec.crossVectors( tangents[ 0 ], normal ).normalize();
  23055. normals[ 0 ].crossVectors( tangents[ 0 ], vec );
  23056. binormals[ 0 ].crossVectors( tangents[ 0 ], normals[ 0 ] );
  23057. }
  23058. // compute the slowly-varying normal and binormal vectors for each segment on the path
  23059. for ( i = 1; i < numpoints; i ++ ) {
  23060. normals[ i ] = normals[ i - 1 ].clone();
  23061. binormals[ i ] = binormals[ i - 1 ].clone();
  23062. vec.crossVectors( tangents[ i - 1 ], tangents[ i ] );
  23063. if ( vec.length() > Number.EPSILON ) {
  23064. vec.normalize();
  23065. theta = Math.acos( THREE.Math.clamp( tangents[ i - 1 ].dot( tangents[ i ] ), - 1, 1 ) ); // clamp for floating pt errors
  23066. normals[ i ].applyMatrix4( mat.makeRotationAxis( vec, theta ) );
  23067. }
  23068. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23069. }
  23070. // if the curve is closed, postprocess the vectors so the first and last normal vectors are the same
  23071. if ( closed ) {
  23072. theta = Math.acos( THREE.Math.clamp( normals[ 0 ].dot( normals[ numpoints - 1 ] ), - 1, 1 ) );
  23073. theta /= ( numpoints - 1 );
  23074. if ( tangents[ 0 ].dot( vec.crossVectors( normals[ 0 ], normals[ numpoints - 1 ] ) ) > 0 ) {
  23075. theta = - theta;
  23076. }
  23077. for ( i = 1; i < numpoints; i ++ ) {
  23078. // twist a little...
  23079. normals[ i ].applyMatrix4( mat.makeRotationAxis( tangents[ i ], theta * i ) );
  23080. binormals[ i ].crossVectors( tangents[ i ], normals[ i ] );
  23081. }
  23082. }
  23083. };
  23084. // File:src/extras/geometries/PolyhedronGeometry.js
  23085. /**
  23086. * @author clockworkgeek / https://github.com/clockworkgeek
  23087. * @author timothypratley / https://github.com/timothypratley
  23088. * @author WestLangley / http://github.com/WestLangley
  23089. */
  23090. THREE.PolyhedronGeometry = function ( vertices, indices, radius, detail ) {
  23091. THREE.Geometry.call( this );
  23092. this.type = 'PolyhedronGeometry';
  23093. this.parameters = {
  23094. vertices: vertices,
  23095. indices: indices,
  23096. radius: radius,
  23097. detail: detail
  23098. };
  23099. radius = radius || 1;
  23100. detail = detail || 0;
  23101. var that = this;
  23102. for ( var i = 0, l = vertices.length; i < l; i += 3 ) {
  23103. prepare( new THREE.Vector3( vertices[ i ], vertices[ i + 1 ], vertices[ i + 2 ] ) );
  23104. }
  23105. var p = this.vertices;
  23106. var faces = [];
  23107. for ( var i = 0, j = 0, l = indices.length; i < l; i += 3, j ++ ) {
  23108. var v1 = p[ indices[ i ] ];
  23109. var v2 = p[ indices[ i + 1 ] ];
  23110. var v3 = p[ indices[ i + 2 ] ];
  23111. faces[ j ] = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, j );
  23112. }
  23113. var centroid = new THREE.Vector3();
  23114. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23115. subdivide( faces[ i ], detail );
  23116. }
  23117. // Handle case when face straddles the seam
  23118. for ( var i = 0, l = this.faceVertexUvs[ 0 ].length; i < l; i ++ ) {
  23119. var uvs = this.faceVertexUvs[ 0 ][ i ];
  23120. var x0 = uvs[ 0 ].x;
  23121. var x1 = uvs[ 1 ].x;
  23122. var x2 = uvs[ 2 ].x;
  23123. var max = Math.max( x0, x1, x2 );
  23124. var min = Math.min( x0, x1, x2 );
  23125. if ( max > 0.9 && min < 0.1 ) {
  23126. // 0.9 is somewhat arbitrary
  23127. if ( x0 < 0.2 ) uvs[ 0 ].x += 1;
  23128. if ( x1 < 0.2 ) uvs[ 1 ].x += 1;
  23129. if ( x2 < 0.2 ) uvs[ 2 ].x += 1;
  23130. }
  23131. }
  23132. // Apply radius
  23133. for ( var i = 0, l = this.vertices.length; i < l; i ++ ) {
  23134. this.vertices[ i ].multiplyScalar( radius );
  23135. }
  23136. // Merge vertices
  23137. this.mergeVertices();
  23138. this.computeFaceNormals();
  23139. this.boundingSphere = new THREE.Sphere( new THREE.Vector3(), radius );
  23140. // Project vector onto sphere's surface
  23141. function prepare( vector ) {
  23142. var vertex = vector.normalize().clone();
  23143. vertex.index = that.vertices.push( vertex ) - 1;
  23144. // Texture coords are equivalent to map coords, calculate angle and convert to fraction of a circle.
  23145. var u = azimuth( vector ) / 2 / Math.PI + 0.5;
  23146. var v = inclination( vector ) / Math.PI + 0.5;
  23147. vertex.uv = new THREE.Vector2( u, 1 - v );
  23148. return vertex;
  23149. }
  23150. // Approximate a curved face with recursively sub-divided triangles.
  23151. function make( v1, v2, v3, materialIndex ) {
  23152. var face = new THREE.Face3( v1.index, v2.index, v3.index, [ v1.clone(), v2.clone(), v3.clone() ], undefined, materialIndex );
  23153. that.faces.push( face );
  23154. centroid.copy( v1 ).add( v2 ).add( v3 ).divideScalar( 3 );
  23155. var azi = azimuth( centroid );
  23156. that.faceVertexUvs[ 0 ].push( [
  23157. correctUV( v1.uv, v1, azi ),
  23158. correctUV( v2.uv, v2, azi ),
  23159. correctUV( v3.uv, v3, azi )
  23160. ] );
  23161. }
  23162. // Analytically subdivide a face to the required detail level.
  23163. function subdivide( face, detail ) {
  23164. var cols = Math.pow( 2, detail );
  23165. var a = prepare( that.vertices[ face.a ] );
  23166. var b = prepare( that.vertices[ face.b ] );
  23167. var c = prepare( that.vertices[ face.c ] );
  23168. var v = [];
  23169. var materialIndex = face.materialIndex;
  23170. // Construct all of the vertices for this subdivision.
  23171. for ( var i = 0 ; i <= cols; i ++ ) {
  23172. v[ i ] = [];
  23173. var aj = prepare( a.clone().lerp( c, i / cols ) );
  23174. var bj = prepare( b.clone().lerp( c, i / cols ) );
  23175. var rows = cols - i;
  23176. for ( var j = 0; j <= rows; j ++ ) {
  23177. if ( j === 0 && i === cols ) {
  23178. v[ i ][ j ] = aj;
  23179. } else {
  23180. v[ i ][ j ] = prepare( aj.clone().lerp( bj, j / rows ) );
  23181. }
  23182. }
  23183. }
  23184. // Construct all of the faces.
  23185. for ( var i = 0; i < cols ; i ++ ) {
  23186. for ( var j = 0; j < 2 * ( cols - i ) - 1; j ++ ) {
  23187. var k = Math.floor( j / 2 );
  23188. if ( j % 2 === 0 ) {
  23189. make(
  23190. v[ i ][ k + 1 ],
  23191. v[ i + 1 ][ k ],
  23192. v[ i ][ k ],
  23193. materialIndex
  23194. );
  23195. } else {
  23196. make(
  23197. v[ i ][ k + 1 ],
  23198. v[ i + 1 ][ k + 1 ],
  23199. v[ i + 1 ][ k ],
  23200. materialIndex
  23201. );
  23202. }
  23203. }
  23204. }
  23205. }
  23206. // Angle around the Y axis, counter-clockwise when looking from above.
  23207. function azimuth( vector ) {
  23208. return Math.atan2( vector.z, - vector.x );
  23209. }
  23210. // Angle above the XZ plane.
  23211. function inclination( vector ) {
  23212. return Math.atan2( - vector.y, Math.sqrt( ( vector.x * vector.x ) + ( vector.z * vector.z ) ) );
  23213. }
  23214. // Texture fixing helper. Spheres have some odd behaviours.
  23215. function correctUV( uv, vector, azimuth ) {
  23216. if ( ( azimuth < 0 ) && ( uv.x === 1 ) ) uv = new THREE.Vector2( uv.x - 1, uv.y );
  23217. if ( ( vector.x === 0 ) && ( vector.z === 0 ) ) uv = new THREE.Vector2( azimuth / 2 / Math.PI + 0.5, uv.y );
  23218. return uv.clone();
  23219. }
  23220. };
  23221. THREE.PolyhedronGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23222. THREE.PolyhedronGeometry.prototype.constructor = THREE.PolyhedronGeometry;
  23223. // File:src/extras/geometries/DodecahedronGeometry.js
  23224. /**
  23225. * @author Abe Pazos / https://hamoid.com
  23226. */
  23227. THREE.DodecahedronGeometry = function ( radius, detail ) {
  23228. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23229. var r = 1 / t;
  23230. var vertices = [
  23231. // (±1, ±1, ±1)
  23232. - 1, - 1, - 1, - 1, - 1, 1,
  23233. - 1, 1, - 1, - 1, 1, 1,
  23234. 1, - 1, - 1, 1, - 1, 1,
  23235. 1, 1, - 1, 1, 1, 1,
  23236. // (0, ±1/φ, ±φ)
  23237. 0, - r, - t, 0, - r, t,
  23238. 0, r, - t, 0, r, t,
  23239. // (±1/φ, ±φ, 0)
  23240. - r, - t, 0, - r, t, 0,
  23241. r, - t, 0, r, t, 0,
  23242. // (±φ, 0, ±1/φ)
  23243. - t, 0, - r, t, 0, - r,
  23244. - t, 0, r, t, 0, r
  23245. ];
  23246. var indices = [
  23247. 3, 11, 7, 3, 7, 15, 3, 15, 13,
  23248. 7, 19, 17, 7, 17, 6, 7, 6, 15,
  23249. 17, 4, 8, 17, 8, 10, 17, 10, 6,
  23250. 8, 0, 16, 8, 16, 2, 8, 2, 10,
  23251. 0, 12, 1, 0, 1, 18, 0, 18, 16,
  23252. 6, 10, 2, 6, 2, 13, 6, 13, 15,
  23253. 2, 16, 18, 2, 18, 3, 2, 3, 13,
  23254. 18, 1, 9, 18, 9, 11, 18, 11, 3,
  23255. 4, 14, 12, 4, 12, 0, 4, 0, 8,
  23256. 11, 9, 5, 11, 5, 19, 11, 19, 7,
  23257. 19, 5, 14, 19, 14, 4, 19, 4, 17,
  23258. 1, 12, 14, 1, 14, 5, 1, 5, 9
  23259. ];
  23260. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23261. this.type = 'DodecahedronGeometry';
  23262. this.parameters = {
  23263. radius: radius,
  23264. detail: detail
  23265. };
  23266. };
  23267. THREE.DodecahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23268. THREE.DodecahedronGeometry.prototype.constructor = THREE.DodecahedronGeometry;
  23269. // File:src/extras/geometries/IcosahedronGeometry.js
  23270. /**
  23271. * @author timothypratley / https://github.com/timothypratley
  23272. */
  23273. THREE.IcosahedronGeometry = function ( radius, detail ) {
  23274. var t = ( 1 + Math.sqrt( 5 ) ) / 2;
  23275. var vertices = [
  23276. - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t, 0,
  23277. 0, - 1, t, 0, 1, t, 0, - 1, - t, 0, 1, - t,
  23278. t, 0, - 1, t, 0, 1, - t, 0, - 1, - t, 0, 1
  23279. ];
  23280. var indices = [
  23281. 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11,
  23282. 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8,
  23283. 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9,
  23284. 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1
  23285. ];
  23286. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23287. this.type = 'IcosahedronGeometry';
  23288. this.parameters = {
  23289. radius: radius,
  23290. detail: detail
  23291. };
  23292. };
  23293. THREE.IcosahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23294. THREE.IcosahedronGeometry.prototype.constructor = THREE.IcosahedronGeometry;
  23295. // File:src/extras/geometries/OctahedronGeometry.js
  23296. /**
  23297. * @author timothypratley / https://github.com/timothypratley
  23298. */
  23299. THREE.OctahedronGeometry = function ( radius, detail ) {
  23300. var vertices = [
  23301. 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1, 0, 0, 0, 1, 0, 0, - 1
  23302. ];
  23303. var indices = [
  23304. 0, 2, 4, 0, 4, 3, 0, 3, 5, 0, 5, 2, 1, 2, 5, 1, 5, 3, 1, 3, 4, 1, 4, 2
  23305. ];
  23306. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23307. this.type = 'OctahedronGeometry';
  23308. this.parameters = {
  23309. radius: radius,
  23310. detail: detail
  23311. };
  23312. };
  23313. THREE.OctahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23314. THREE.OctahedronGeometry.prototype.constructor = THREE.OctahedronGeometry;
  23315. // File:src/extras/geometries/TetrahedronGeometry.js
  23316. /**
  23317. * @author timothypratley / https://github.com/timothypratley
  23318. */
  23319. THREE.TetrahedronGeometry = function ( radius, detail ) {
  23320. var vertices = [
  23321. 1, 1, 1, - 1, - 1, 1, - 1, 1, - 1, 1, - 1, - 1
  23322. ];
  23323. var indices = [
  23324. 2, 1, 0, 0, 3, 2, 1, 3, 0, 2, 3, 1
  23325. ];
  23326. THREE.PolyhedronGeometry.call( this, vertices, indices, radius, detail );
  23327. this.type = 'TetrahedronGeometry';
  23328. this.parameters = {
  23329. radius: radius,
  23330. detail: detail
  23331. };
  23332. };
  23333. THREE.TetrahedronGeometry.prototype = Object.create( THREE.PolyhedronGeometry.prototype );
  23334. THREE.TetrahedronGeometry.prototype.constructor = THREE.TetrahedronGeometry;
  23335. // File:src/extras/geometries/ParametricGeometry.js
  23336. /**
  23337. * @author zz85 / https://github.com/zz85
  23338. * Parametric Surfaces Geometry
  23339. * based on the brilliant article by @prideout http://prideout.net/blog/?p=44
  23340. *
  23341. * new THREE.ParametricGeometry( parametricFunction, uSegments, ySegements );
  23342. *
  23343. */
  23344. THREE.ParametricGeometry = function ( func, slices, stacks ) {
  23345. THREE.Geometry.call( this );
  23346. this.type = 'ParametricGeometry';
  23347. this.parameters = {
  23348. func: func,
  23349. slices: slices,
  23350. stacks: stacks
  23351. };
  23352. var verts = this.vertices;
  23353. var faces = this.faces;
  23354. var uvs = this.faceVertexUvs[ 0 ];
  23355. var i, j, p;
  23356. var u, v;
  23357. var sliceCount = slices + 1;
  23358. for ( i = 0; i <= stacks; i ++ ) {
  23359. v = i / stacks;
  23360. for ( j = 0; j <= slices; j ++ ) {
  23361. u = j / slices;
  23362. p = func( u, v );
  23363. verts.push( p );
  23364. }
  23365. }
  23366. var a, b, c, d;
  23367. var uva, uvb, uvc, uvd;
  23368. for ( i = 0; i < stacks; i ++ ) {
  23369. for ( j = 0; j < slices; j ++ ) {
  23370. a = i * sliceCount + j;
  23371. b = i * sliceCount + j + 1;
  23372. c = ( i + 1 ) * sliceCount + j + 1;
  23373. d = ( i + 1 ) * sliceCount + j;
  23374. uva = new THREE.Vector2( j / slices, i / stacks );
  23375. uvb = new THREE.Vector2( ( j + 1 ) / slices, i / stacks );
  23376. uvc = new THREE.Vector2( ( j + 1 ) / slices, ( i + 1 ) / stacks );
  23377. uvd = new THREE.Vector2( j / slices, ( i + 1 ) / stacks );
  23378. faces.push( new THREE.Face3( a, b, d ) );
  23379. uvs.push( [ uva, uvb, uvd ] );
  23380. faces.push( new THREE.Face3( b, c, d ) );
  23381. uvs.push( [ uvb.clone(), uvc, uvd.clone() ] );
  23382. }
  23383. }
  23384. // console.log(this);
  23385. // magic bullet
  23386. // var diff = this.mergeVertices();
  23387. // console.log('removed ', diff, ' vertices by merging');
  23388. this.computeFaceNormals();
  23389. this.computeVertexNormals();
  23390. };
  23391. THREE.ParametricGeometry.prototype = Object.create( THREE.Geometry.prototype );
  23392. THREE.ParametricGeometry.prototype.constructor = THREE.ParametricGeometry;
  23393. // File:src/extras/geometries/WireframeGeometry.js
  23394. /**
  23395. * @author mrdoob / http://mrdoob.com/
  23396. */
  23397. THREE.WireframeGeometry = function ( geometry ) {
  23398. THREE.BufferGeometry.call( this );
  23399. var edge = [ 0, 0 ], hash = {};
  23400. function sortFunction( a, b ) {
  23401. return a - b;
  23402. }
  23403. var keys = [ 'a', 'b', 'c' ];
  23404. if ( geometry instanceof THREE.Geometry ) {
  23405. var vertices = geometry.vertices;
  23406. var faces = geometry.faces;
  23407. var numEdges = 0;
  23408. // allocate maximal size
  23409. var edges = new Uint32Array( 6 * faces.length );
  23410. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23411. var face = faces[ i ];
  23412. for ( var j = 0; j < 3; j ++ ) {
  23413. edge[ 0 ] = face[ keys[ j ] ];
  23414. edge[ 1 ] = face[ keys[ ( j + 1 ) % 3 ] ];
  23415. edge.sort( sortFunction );
  23416. var key = edge.toString();
  23417. if ( hash[ key ] === undefined ) {
  23418. edges[ 2 * numEdges ] = edge[ 0 ];
  23419. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23420. hash[ key ] = true;
  23421. numEdges ++;
  23422. }
  23423. }
  23424. }
  23425. var coords = new Float32Array( numEdges * 2 * 3 );
  23426. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23427. for ( var j = 0; j < 2; j ++ ) {
  23428. var vertex = vertices[ edges [ 2 * i + j ] ];
  23429. var index = 6 * i + 3 * j;
  23430. coords[ index + 0 ] = vertex.x;
  23431. coords[ index + 1 ] = vertex.y;
  23432. coords[ index + 2 ] = vertex.z;
  23433. }
  23434. }
  23435. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23436. } else if ( geometry instanceof THREE.BufferGeometry ) {
  23437. if ( geometry.index !== null ) {
  23438. // Indexed BufferGeometry
  23439. var indices = geometry.index.array;
  23440. var vertices = geometry.attributes.position;
  23441. var groups = geometry.groups;
  23442. var numEdges = 0;
  23443. if ( groups.length === 0 ) {
  23444. geometry.addGroup( 0, indices.length );
  23445. }
  23446. // allocate maximal size
  23447. var edges = new Uint32Array( 2 * indices.length );
  23448. for ( var o = 0, ol = groups.length; o < ol; ++ o ) {
  23449. var group = groups[ o ];
  23450. var start = group.start;
  23451. var count = group.count;
  23452. for ( var i = start, il = start + count; i < il; i += 3 ) {
  23453. for ( var j = 0; j < 3; j ++ ) {
  23454. edge[ 0 ] = indices[ i + j ];
  23455. edge[ 1 ] = indices[ i + ( j + 1 ) % 3 ];
  23456. edge.sort( sortFunction );
  23457. var key = edge.toString();
  23458. if ( hash[ key ] === undefined ) {
  23459. edges[ 2 * numEdges ] = edge[ 0 ];
  23460. edges[ 2 * numEdges + 1 ] = edge[ 1 ];
  23461. hash[ key ] = true;
  23462. numEdges ++;
  23463. }
  23464. }
  23465. }
  23466. }
  23467. var coords = new Float32Array( numEdges * 2 * 3 );
  23468. for ( var i = 0, l = numEdges; i < l; i ++ ) {
  23469. for ( var j = 0; j < 2; j ++ ) {
  23470. var index = 6 * i + 3 * j;
  23471. var index2 = edges[ 2 * i + j ];
  23472. coords[ index + 0 ] = vertices.getX( index2 );
  23473. coords[ index + 1 ] = vertices.getY( index2 );
  23474. coords[ index + 2 ] = vertices.getZ( index2 );
  23475. }
  23476. }
  23477. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23478. } else {
  23479. // non-indexed BufferGeometry
  23480. var vertices = geometry.attributes.position.array;
  23481. var numEdges = vertices.length / 3;
  23482. var numTris = numEdges / 3;
  23483. var coords = new Float32Array( numEdges * 2 * 3 );
  23484. for ( var i = 0, l = numTris; i < l; i ++ ) {
  23485. for ( var j = 0; j < 3; j ++ ) {
  23486. var index = 18 * i + 6 * j;
  23487. var index1 = 9 * i + 3 * j;
  23488. coords[ index + 0 ] = vertices[ index1 ];
  23489. coords[ index + 1 ] = vertices[ index1 + 1 ];
  23490. coords[ index + 2 ] = vertices[ index1 + 2 ];
  23491. var index2 = 9 * i + 3 * ( ( j + 1 ) % 3 );
  23492. coords[ index + 3 ] = vertices[ index2 ];
  23493. coords[ index + 4 ] = vertices[ index2 + 1 ];
  23494. coords[ index + 5 ] = vertices[ index2 + 2 ];
  23495. }
  23496. }
  23497. this.addAttribute( 'position', new THREE.BufferAttribute( coords, 3 ) );
  23498. }
  23499. }
  23500. };
  23501. THREE.WireframeGeometry.prototype = Object.create( THREE.BufferGeometry.prototype );
  23502. THREE.WireframeGeometry.prototype.constructor = THREE.WireframeGeometry;
  23503. // File:src/extras/helpers/AxisHelper.js
  23504. /**
  23505. * @author sroucheray / http://sroucheray.org/
  23506. * @author mrdoob / http://mrdoob.com/
  23507. */
  23508. THREE.AxisHelper = function ( size ) {
  23509. size = size || 1;
  23510. var vertices = new Float32Array( [
  23511. 0, 0, 0, size, 0, 0,
  23512. 0, 0, 0, 0, size, 0,
  23513. 0, 0, 0, 0, 0, size
  23514. ] );
  23515. var colors = new Float32Array( [
  23516. 1, 0, 0, 1, 0.6, 0,
  23517. 0, 1, 0, 0.6, 1, 0,
  23518. 0, 0, 1, 0, 0.6, 1
  23519. ] );
  23520. var geometry = new THREE.BufferGeometry();
  23521. geometry.addAttribute( 'position', new THREE.BufferAttribute( vertices, 3 ) );
  23522. geometry.addAttribute( 'color', new THREE.BufferAttribute( colors, 3 ) );
  23523. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23524. THREE.LineSegments.call( this, geometry, material );
  23525. };
  23526. THREE.AxisHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23527. THREE.AxisHelper.prototype.constructor = THREE.AxisHelper;
  23528. // File:src/extras/helpers/ArrowHelper.js
  23529. /**
  23530. * @author WestLangley / http://github.com/WestLangley
  23531. * @author zz85 / http://github.com/zz85
  23532. * @author bhouston / http://clara.io
  23533. *
  23534. * Creates an arrow for visualizing directions
  23535. *
  23536. * Parameters:
  23537. * dir - Vector3
  23538. * origin - Vector3
  23539. * length - Number
  23540. * color - color in hex value
  23541. * headLength - Number
  23542. * headWidth - Number
  23543. */
  23544. THREE.ArrowHelper = ( function () {
  23545. var lineGeometry = new THREE.Geometry();
  23546. lineGeometry.vertices.push( new THREE.Vector3( 0, 0, 0 ), new THREE.Vector3( 0, 1, 0 ) );
  23547. var coneGeometry = new THREE.CylinderGeometry( 0, 0.5, 1, 5, 1 );
  23548. coneGeometry.translate( 0, - 0.5, 0 );
  23549. return function ArrowHelper( dir, origin, length, color, headLength, headWidth ) {
  23550. // dir is assumed to be normalized
  23551. THREE.Object3D.call( this );
  23552. if ( color === undefined ) color = 0xffff00;
  23553. if ( length === undefined ) length = 1;
  23554. if ( headLength === undefined ) headLength = 0.2 * length;
  23555. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23556. this.position.copy( origin );
  23557. this.line = new THREE.Line( lineGeometry, new THREE.LineBasicMaterial( { color: color } ) );
  23558. this.line.matrixAutoUpdate = false;
  23559. this.add( this.line );
  23560. this.cone = new THREE.Mesh( coneGeometry, new THREE.MeshBasicMaterial( { color: color } ) );
  23561. this.cone.matrixAutoUpdate = false;
  23562. this.add( this.cone );
  23563. this.setDirection( dir );
  23564. this.setLength( length, headLength, headWidth );
  23565. }
  23566. }() );
  23567. THREE.ArrowHelper.prototype = Object.create( THREE.Object3D.prototype );
  23568. THREE.ArrowHelper.prototype.constructor = THREE.ArrowHelper;
  23569. THREE.ArrowHelper.prototype.setDirection = ( function () {
  23570. var axis = new THREE.Vector3();
  23571. var radians;
  23572. return function setDirection( dir ) {
  23573. // dir is assumed to be normalized
  23574. if ( dir.y > 0.99999 ) {
  23575. this.quaternion.set( 0, 0, 0, 1 );
  23576. } else if ( dir.y < - 0.99999 ) {
  23577. this.quaternion.set( 1, 0, 0, 0 );
  23578. } else {
  23579. axis.set( dir.z, 0, - dir.x ).normalize();
  23580. radians = Math.acos( dir.y );
  23581. this.quaternion.setFromAxisAngle( axis, radians );
  23582. }
  23583. };
  23584. }() );
  23585. THREE.ArrowHelper.prototype.setLength = function ( length, headLength, headWidth ) {
  23586. if ( headLength === undefined ) headLength = 0.2 * length;
  23587. if ( headWidth === undefined ) headWidth = 0.2 * headLength;
  23588. this.line.scale.set( 1, Math.max( 0, length - headLength ), 1 );
  23589. this.line.updateMatrix();
  23590. this.cone.scale.set( headWidth, headLength, headWidth );
  23591. this.cone.position.y = length;
  23592. this.cone.updateMatrix();
  23593. };
  23594. THREE.ArrowHelper.prototype.setColor = function ( color ) {
  23595. this.line.material.color.set( color );
  23596. this.cone.material.color.set( color );
  23597. };
  23598. // File:src/extras/helpers/BoxHelper.js
  23599. /**
  23600. * @author mrdoob / http://mrdoob.com/
  23601. */
  23602. THREE.BoxHelper = function ( object ) {
  23603. 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 ] );
  23604. var positions = new Float32Array( 8 * 3 );
  23605. var geometry = new THREE.BufferGeometry();
  23606. geometry.setIndex( new THREE.BufferAttribute( indices, 1 ) );
  23607. geometry.addAttribute( 'position', new THREE.BufferAttribute( positions, 3 ) );
  23608. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: 0xffff00 } ) );
  23609. if ( object !== undefined ) {
  23610. this.update( object );
  23611. }
  23612. };
  23613. THREE.BoxHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23614. THREE.BoxHelper.prototype.constructor = THREE.BoxHelper;
  23615. THREE.BoxHelper.prototype.update = ( function () {
  23616. var box = new THREE.Box3();
  23617. return function ( object ) {
  23618. box.setFromObject( object );
  23619. if ( box.isEmpty() ) return;
  23620. var min = box.min;
  23621. var max = box.max;
  23622. /*
  23623. 5____4
  23624. 1/___0/|
  23625. | 6__|_7
  23626. 2/___3/
  23627. 0: max.x, max.y, max.z
  23628. 1: min.x, max.y, max.z
  23629. 2: min.x, min.y, max.z
  23630. 3: max.x, min.y, max.z
  23631. 4: max.x, max.y, min.z
  23632. 5: min.x, max.y, min.z
  23633. 6: min.x, min.y, min.z
  23634. 7: max.x, min.y, min.z
  23635. */
  23636. var position = this.geometry.attributes.position;
  23637. var array = position.array;
  23638. array[ 0 ] = max.x; array[ 1 ] = max.y; array[ 2 ] = max.z;
  23639. array[ 3 ] = min.x; array[ 4 ] = max.y; array[ 5 ] = max.z;
  23640. array[ 6 ] = min.x; array[ 7 ] = min.y; array[ 8 ] = max.z;
  23641. array[ 9 ] = max.x; array[ 10 ] = min.y; array[ 11 ] = max.z;
  23642. array[ 12 ] = max.x; array[ 13 ] = max.y; array[ 14 ] = min.z;
  23643. array[ 15 ] = min.x; array[ 16 ] = max.y; array[ 17 ] = min.z;
  23644. array[ 18 ] = min.x; array[ 19 ] = min.y; array[ 20 ] = min.z;
  23645. array[ 21 ] = max.x; array[ 22 ] = min.y; array[ 23 ] = min.z;
  23646. position.needsUpdate = true;
  23647. this.geometry.computeBoundingSphere();
  23648. };
  23649. } )();
  23650. // File:src/extras/helpers/BoundingBoxHelper.js
  23651. /**
  23652. * @author WestLangley / http://github.com/WestLangley
  23653. */
  23654. // a helper to show the world-axis-aligned bounding box for an object
  23655. THREE.BoundingBoxHelper = function ( object, hex ) {
  23656. var color = ( hex !== undefined ) ? hex : 0x888888;
  23657. this.object = object;
  23658. this.box = new THREE.Box3();
  23659. THREE.Mesh.call( this, new THREE.BoxGeometry( 1, 1, 1 ), new THREE.MeshBasicMaterial( { color: color, wireframe: true } ) );
  23660. };
  23661. THREE.BoundingBoxHelper.prototype = Object.create( THREE.Mesh.prototype );
  23662. THREE.BoundingBoxHelper.prototype.constructor = THREE.BoundingBoxHelper;
  23663. THREE.BoundingBoxHelper.prototype.update = function () {
  23664. this.box.setFromObject( this.object );
  23665. this.box.size( this.scale );
  23666. this.box.center( this.position );
  23667. };
  23668. // File:src/extras/helpers/CameraHelper.js
  23669. /**
  23670. * @author alteredq / http://alteredqualia.com/
  23671. *
  23672. * - shows frustum, line of sight and up of the camera
  23673. * - suitable for fast updates
  23674. * - based on frustum visualization in lightgl.js shadowmap example
  23675. * http://evanw.github.com/lightgl.js/tests/shadowmap.html
  23676. */
  23677. THREE.CameraHelper = function ( camera ) {
  23678. var geometry = new THREE.Geometry();
  23679. var material = new THREE.LineBasicMaterial( { color: 0xffffff, vertexColors: THREE.FaceColors } );
  23680. var pointMap = {};
  23681. // colors
  23682. var hexFrustum = 0xffaa00;
  23683. var hexCone = 0xff0000;
  23684. var hexUp = 0x00aaff;
  23685. var hexTarget = 0xffffff;
  23686. var hexCross = 0x333333;
  23687. // near
  23688. addLine( "n1", "n2", hexFrustum );
  23689. addLine( "n2", "n4", hexFrustum );
  23690. addLine( "n4", "n3", hexFrustum );
  23691. addLine( "n3", "n1", hexFrustum );
  23692. // far
  23693. addLine( "f1", "f2", hexFrustum );
  23694. addLine( "f2", "f4", hexFrustum );
  23695. addLine( "f4", "f3", hexFrustum );
  23696. addLine( "f3", "f1", hexFrustum );
  23697. // sides
  23698. addLine( "n1", "f1", hexFrustum );
  23699. addLine( "n2", "f2", hexFrustum );
  23700. addLine( "n3", "f3", hexFrustum );
  23701. addLine( "n4", "f4", hexFrustum );
  23702. // cone
  23703. addLine( "p", "n1", hexCone );
  23704. addLine( "p", "n2", hexCone );
  23705. addLine( "p", "n3", hexCone );
  23706. addLine( "p", "n4", hexCone );
  23707. // up
  23708. addLine( "u1", "u2", hexUp );
  23709. addLine( "u2", "u3", hexUp );
  23710. addLine( "u3", "u1", hexUp );
  23711. // target
  23712. addLine( "c", "t", hexTarget );
  23713. addLine( "p", "c", hexCross );
  23714. // cross
  23715. addLine( "cn1", "cn2", hexCross );
  23716. addLine( "cn3", "cn4", hexCross );
  23717. addLine( "cf1", "cf2", hexCross );
  23718. addLine( "cf3", "cf4", hexCross );
  23719. function addLine( a, b, hex ) {
  23720. addPoint( a, hex );
  23721. addPoint( b, hex );
  23722. }
  23723. function addPoint( id, hex ) {
  23724. geometry.vertices.push( new THREE.Vector3() );
  23725. geometry.colors.push( new THREE.Color( hex ) );
  23726. if ( pointMap[ id ] === undefined ) {
  23727. pointMap[ id ] = [];
  23728. }
  23729. pointMap[ id ].push( geometry.vertices.length - 1 );
  23730. }
  23731. THREE.LineSegments.call( this, geometry, material );
  23732. this.camera = camera;
  23733. this.camera.updateProjectionMatrix();
  23734. this.matrix = camera.matrixWorld;
  23735. this.matrixAutoUpdate = false;
  23736. this.pointMap = pointMap;
  23737. this.update();
  23738. };
  23739. THREE.CameraHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23740. THREE.CameraHelper.prototype.constructor = THREE.CameraHelper;
  23741. THREE.CameraHelper.prototype.update = function () {
  23742. var geometry, pointMap;
  23743. var vector = new THREE.Vector3();
  23744. var camera = new THREE.Camera();
  23745. function setPoint( point, x, y, z ) {
  23746. vector.set( x, y, z ).unproject( camera );
  23747. var points = pointMap[ point ];
  23748. if ( points !== undefined ) {
  23749. for ( var i = 0, il = points.length; i < il; i ++ ) {
  23750. geometry.vertices[ points[ i ] ].copy( vector );
  23751. }
  23752. }
  23753. }
  23754. return function () {
  23755. geometry = this.geometry;
  23756. pointMap = this.pointMap;
  23757. var w = 1, h = 1;
  23758. // we need just camera projection matrix
  23759. // world matrix must be identity
  23760. camera.projectionMatrix.copy( this.camera.projectionMatrix );
  23761. // center / target
  23762. setPoint( "c", 0, 0, - 1 );
  23763. setPoint( "t", 0, 0, 1 );
  23764. // near
  23765. setPoint( "n1", - w, - h, - 1 );
  23766. setPoint( "n2", w, - h, - 1 );
  23767. setPoint( "n3", - w, h, - 1 );
  23768. setPoint( "n4", w, h, - 1 );
  23769. // far
  23770. setPoint( "f1", - w, - h, 1 );
  23771. setPoint( "f2", w, - h, 1 );
  23772. setPoint( "f3", - w, h, 1 );
  23773. setPoint( "f4", w, h, 1 );
  23774. // up
  23775. setPoint( "u1", w * 0.7, h * 1.1, - 1 );
  23776. setPoint( "u2", - w * 0.7, h * 1.1, - 1 );
  23777. setPoint( "u3", 0, h * 2, - 1 );
  23778. // cross
  23779. setPoint( "cf1", - w, 0, 1 );
  23780. setPoint( "cf2", w, 0, 1 );
  23781. setPoint( "cf3", 0, - h, 1 );
  23782. setPoint( "cf4", 0, h, 1 );
  23783. setPoint( "cn1", - w, 0, - 1 );
  23784. setPoint( "cn2", w, 0, - 1 );
  23785. setPoint( "cn3", 0, - h, - 1 );
  23786. setPoint( "cn4", 0, h, - 1 );
  23787. geometry.verticesNeedUpdate = true;
  23788. };
  23789. }();
  23790. // File:src/extras/helpers/DirectionalLightHelper.js
  23791. /**
  23792. * @author alteredq / http://alteredqualia.com/
  23793. * @author mrdoob / http://mrdoob.com/
  23794. * @author WestLangley / http://github.com/WestLangley
  23795. */
  23796. THREE.DirectionalLightHelper = function ( light, size ) {
  23797. THREE.Object3D.call( this );
  23798. this.light = light;
  23799. this.light.updateMatrixWorld();
  23800. this.matrix = light.matrixWorld;
  23801. this.matrixAutoUpdate = false;
  23802. size = size || 1;
  23803. var geometry = new THREE.Geometry();
  23804. geometry.vertices.push(
  23805. new THREE.Vector3( - size, size, 0 ),
  23806. new THREE.Vector3( size, size, 0 ),
  23807. new THREE.Vector3( size, - size, 0 ),
  23808. new THREE.Vector3( - size, - size, 0 ),
  23809. new THREE.Vector3( - size, size, 0 )
  23810. );
  23811. var material = new THREE.LineBasicMaterial( { fog: false } );
  23812. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23813. this.lightPlane = new THREE.Line( geometry, material );
  23814. this.add( this.lightPlane );
  23815. geometry = new THREE.Geometry();
  23816. geometry.vertices.push(
  23817. new THREE.Vector3(),
  23818. new THREE.Vector3()
  23819. );
  23820. material = new THREE.LineBasicMaterial( { fog: false } );
  23821. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23822. this.targetLine = new THREE.Line( geometry, material );
  23823. this.add( this.targetLine );
  23824. this.update();
  23825. };
  23826. THREE.DirectionalLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23827. THREE.DirectionalLightHelper.prototype.constructor = THREE.DirectionalLightHelper;
  23828. THREE.DirectionalLightHelper.prototype.dispose = function () {
  23829. this.lightPlane.geometry.dispose();
  23830. this.lightPlane.material.dispose();
  23831. this.targetLine.geometry.dispose();
  23832. this.targetLine.material.dispose();
  23833. };
  23834. THREE.DirectionalLightHelper.prototype.update = function () {
  23835. var v1 = new THREE.Vector3();
  23836. var v2 = new THREE.Vector3();
  23837. var v3 = new THREE.Vector3();
  23838. return function () {
  23839. v1.setFromMatrixPosition( this.light.matrixWorld );
  23840. v2.setFromMatrixPosition( this.light.target.matrixWorld );
  23841. v3.subVectors( v2, v1 );
  23842. this.lightPlane.lookAt( v3 );
  23843. this.lightPlane.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  23844. this.targetLine.geometry.vertices[ 1 ].copy( v3 );
  23845. this.targetLine.geometry.verticesNeedUpdate = true;
  23846. this.targetLine.material.color.copy( this.lightPlane.material.color );
  23847. };
  23848. }();
  23849. // File:src/extras/helpers/EdgesHelper.js
  23850. /**
  23851. * @author WestLangley / http://github.com/WestLangley
  23852. * @param object THREE.Mesh whose geometry will be used
  23853. * @param hex line color
  23854. * @param thresholdAngle the minimum angle (in degrees),
  23855. * between the face normals of adjacent faces,
  23856. * that is required to render an edge. A value of 10 means
  23857. * an edge is only rendered if the angle is at least 10 degrees.
  23858. */
  23859. THREE.EdgesHelper = function ( object, hex, thresholdAngle ) {
  23860. var color = ( hex !== undefined ) ? hex : 0xffffff;
  23861. THREE.LineSegments.call( this, new THREE.EdgesGeometry( object.geometry, thresholdAngle ), new THREE.LineBasicMaterial( { color: color } ) );
  23862. this.matrix = object.matrixWorld;
  23863. this.matrixAutoUpdate = false;
  23864. };
  23865. THREE.EdgesHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23866. THREE.EdgesHelper.prototype.constructor = THREE.EdgesHelper;
  23867. // File:src/extras/helpers/FaceNormalsHelper.js
  23868. /**
  23869. * @author mrdoob / http://mrdoob.com/
  23870. * @author WestLangley / http://github.com/WestLangley
  23871. */
  23872. THREE.FaceNormalsHelper = function ( object, size, hex, linewidth ) {
  23873. // FaceNormalsHelper only supports THREE.Geometry
  23874. this.object = object;
  23875. this.size = ( size !== undefined ) ? size : 1;
  23876. var color = ( hex !== undefined ) ? hex : 0xffff00;
  23877. var width = ( linewidth !== undefined ) ? linewidth : 1;
  23878. //
  23879. var nNormals = 0;
  23880. var objGeometry = this.object.geometry;
  23881. if ( objGeometry instanceof THREE.Geometry ) {
  23882. nNormals = objGeometry.faces.length;
  23883. } else {
  23884. console.warn( 'THREE.FaceNormalsHelper: only THREE.Geometry is supported. Use THREE.VertexNormalsHelper, instead.' );
  23885. }
  23886. //
  23887. var geometry = new THREE.BufferGeometry();
  23888. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  23889. geometry.addAttribute( 'position', positions );
  23890. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  23891. //
  23892. this.matrixAutoUpdate = false;
  23893. this.update();
  23894. };
  23895. THREE.FaceNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23896. THREE.FaceNormalsHelper.prototype.constructor = THREE.FaceNormalsHelper;
  23897. THREE.FaceNormalsHelper.prototype.update = ( function () {
  23898. var v1 = new THREE.Vector3();
  23899. var v2 = new THREE.Vector3();
  23900. var normalMatrix = new THREE.Matrix3();
  23901. return function update() {
  23902. this.object.updateMatrixWorld( true );
  23903. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  23904. var matrixWorld = this.object.matrixWorld;
  23905. var position = this.geometry.attributes.position;
  23906. //
  23907. var objGeometry = this.object.geometry;
  23908. var vertices = objGeometry.vertices;
  23909. var faces = objGeometry.faces;
  23910. var idx = 0;
  23911. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  23912. var face = faces[ i ];
  23913. var normal = face.normal;
  23914. v1.copy( vertices[ face.a ] )
  23915. .add( vertices[ face.b ] )
  23916. .add( vertices[ face.c ] )
  23917. .divideScalar( 3 )
  23918. .applyMatrix4( matrixWorld );
  23919. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  23920. position.setXYZ( idx, v1.x, v1.y, v1.z );
  23921. idx = idx + 1;
  23922. position.setXYZ( idx, v2.x, v2.y, v2.z );
  23923. idx = idx + 1;
  23924. }
  23925. position.needsUpdate = true;
  23926. return this;
  23927. }
  23928. }() );
  23929. // File:src/extras/helpers/GridHelper.js
  23930. /**
  23931. * @author mrdoob / http://mrdoob.com/
  23932. */
  23933. THREE.GridHelper = function ( size, step ) {
  23934. var geometry = new THREE.Geometry();
  23935. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors } );
  23936. this.color1 = new THREE.Color( 0x444444 );
  23937. this.color2 = new THREE.Color( 0x888888 );
  23938. for ( var i = - size; i <= size; i += step ) {
  23939. geometry.vertices.push(
  23940. new THREE.Vector3( - size, 0, i ), new THREE.Vector3( size, 0, i ),
  23941. new THREE.Vector3( i, 0, - size ), new THREE.Vector3( i, 0, size )
  23942. );
  23943. var color = i === 0 ? this.color1 : this.color2;
  23944. geometry.colors.push( color, color, color, color );
  23945. }
  23946. THREE.LineSegments.call( this, geometry, material );
  23947. };
  23948. THREE.GridHelper.prototype = Object.create( THREE.LineSegments.prototype );
  23949. THREE.GridHelper.prototype.constructor = THREE.GridHelper;
  23950. THREE.GridHelper.prototype.setColors = function( colorCenterLine, colorGrid ) {
  23951. this.color1.set( colorCenterLine );
  23952. this.color2.set( colorGrid );
  23953. this.geometry.colorsNeedUpdate = true;
  23954. };
  23955. // File:src/extras/helpers/HemisphereLightHelper.js
  23956. /**
  23957. * @author alteredq / http://alteredqualia.com/
  23958. * @author mrdoob / http://mrdoob.com/
  23959. */
  23960. THREE.HemisphereLightHelper = function ( light, sphereSize ) {
  23961. THREE.Object3D.call( this );
  23962. this.light = light;
  23963. this.light.updateMatrixWorld();
  23964. this.matrix = light.matrixWorld;
  23965. this.matrixAutoUpdate = false;
  23966. this.colors = [ new THREE.Color(), new THREE.Color() ];
  23967. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  23968. geometry.rotateX( - Math.PI / 2 );
  23969. for ( var i = 0, il = 8; i < il; i ++ ) {
  23970. geometry.faces[ i ].color = this.colors[ i < 4 ? 0 : 1 ];
  23971. }
  23972. var material = new THREE.MeshBasicMaterial( { vertexColors: THREE.FaceColors, wireframe: true } );
  23973. this.lightSphere = new THREE.Mesh( geometry, material );
  23974. this.add( this.lightSphere );
  23975. this.update();
  23976. };
  23977. THREE.HemisphereLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  23978. THREE.HemisphereLightHelper.prototype.constructor = THREE.HemisphereLightHelper;
  23979. THREE.HemisphereLightHelper.prototype.dispose = function () {
  23980. this.lightSphere.geometry.dispose();
  23981. this.lightSphere.material.dispose();
  23982. };
  23983. THREE.HemisphereLightHelper.prototype.update = function () {
  23984. var vector = new THREE.Vector3();
  23985. return function () {
  23986. this.colors[ 0 ].copy( this.light.color ).multiplyScalar( this.light.intensity );
  23987. this.colors[ 1 ].copy( this.light.groundColor ).multiplyScalar( this.light.intensity );
  23988. this.lightSphere.lookAt( vector.setFromMatrixPosition( this.light.matrixWorld ).negate() );
  23989. this.lightSphere.geometry.colorsNeedUpdate = true;
  23990. }
  23991. }();
  23992. // File:src/extras/helpers/PointLightHelper.js
  23993. /**
  23994. * @author alteredq / http://alteredqualia.com/
  23995. * @author mrdoob / http://mrdoob.com/
  23996. */
  23997. THREE.PointLightHelper = function ( light, sphereSize ) {
  23998. this.light = light;
  23999. this.light.updateMatrixWorld();
  24000. var geometry = new THREE.SphereGeometry( sphereSize, 4, 2 );
  24001. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24002. material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24003. THREE.Mesh.call( this, geometry, material );
  24004. this.matrix = this.light.matrixWorld;
  24005. this.matrixAutoUpdate = false;
  24006. /*
  24007. var distanceGeometry = new THREE.IcosahedronGeometry( 1, 2 );
  24008. var distanceMaterial = new THREE.MeshBasicMaterial( { color: hexColor, fog: false, wireframe: true, opacity: 0.1, transparent: true } );
  24009. this.lightSphere = new THREE.Mesh( bulbGeometry, bulbMaterial );
  24010. this.lightDistance = new THREE.Mesh( distanceGeometry, distanceMaterial );
  24011. var d = light.distance;
  24012. if ( d === 0.0 ) {
  24013. this.lightDistance.visible = false;
  24014. } else {
  24015. this.lightDistance.scale.set( d, d, d );
  24016. }
  24017. this.add( this.lightDistance );
  24018. */
  24019. };
  24020. THREE.PointLightHelper.prototype = Object.create( THREE.Mesh.prototype );
  24021. THREE.PointLightHelper.prototype.constructor = THREE.PointLightHelper;
  24022. THREE.PointLightHelper.prototype.dispose = function () {
  24023. this.geometry.dispose();
  24024. this.material.dispose();
  24025. };
  24026. THREE.PointLightHelper.prototype.update = function () {
  24027. this.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24028. /*
  24029. var d = this.light.distance;
  24030. if ( d === 0.0 ) {
  24031. this.lightDistance.visible = false;
  24032. } else {
  24033. this.lightDistance.visible = true;
  24034. this.lightDistance.scale.set( d, d, d );
  24035. }
  24036. */
  24037. };
  24038. // File:src/extras/helpers/SkeletonHelper.js
  24039. /**
  24040. * @author Sean Griffin / http://twitter.com/sgrif
  24041. * @author Michael Guerrero / http://realitymeltdown.com
  24042. * @author mrdoob / http://mrdoob.com/
  24043. * @author ikerr / http://verold.com
  24044. */
  24045. THREE.SkeletonHelper = function ( object ) {
  24046. this.bones = this.getBoneList( object );
  24047. var geometry = new THREE.Geometry();
  24048. for ( var i = 0; i < this.bones.length; i ++ ) {
  24049. var bone = this.bones[ i ];
  24050. if ( bone.parent instanceof THREE.Bone ) {
  24051. geometry.vertices.push( new THREE.Vector3() );
  24052. geometry.vertices.push( new THREE.Vector3() );
  24053. geometry.colors.push( new THREE.Color( 0, 0, 1 ) );
  24054. geometry.colors.push( new THREE.Color( 0, 1, 0 ) );
  24055. }
  24056. }
  24057. geometry.dynamic = true;
  24058. var material = new THREE.LineBasicMaterial( { vertexColors: THREE.VertexColors, depthTest: false, depthWrite: false, transparent: true } );
  24059. THREE.LineSegments.call( this, geometry, material );
  24060. this.root = object;
  24061. this.matrix = object.matrixWorld;
  24062. this.matrixAutoUpdate = false;
  24063. this.update();
  24064. };
  24065. THREE.SkeletonHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24066. THREE.SkeletonHelper.prototype.constructor = THREE.SkeletonHelper;
  24067. THREE.SkeletonHelper.prototype.getBoneList = function( object ) {
  24068. var boneList = [];
  24069. if ( object instanceof THREE.Bone ) {
  24070. boneList.push( object );
  24071. }
  24072. for ( var i = 0; i < object.children.length; i ++ ) {
  24073. boneList.push.apply( boneList, this.getBoneList( object.children[ i ] ) );
  24074. }
  24075. return boneList;
  24076. };
  24077. THREE.SkeletonHelper.prototype.update = function () {
  24078. var geometry = this.geometry;
  24079. var matrixWorldInv = new THREE.Matrix4().getInverse( this.root.matrixWorld );
  24080. var boneMatrix = new THREE.Matrix4();
  24081. var j = 0;
  24082. for ( var i = 0; i < this.bones.length; i ++ ) {
  24083. var bone = this.bones[ i ];
  24084. if ( bone.parent instanceof THREE.Bone ) {
  24085. boneMatrix.multiplyMatrices( matrixWorldInv, bone.matrixWorld );
  24086. geometry.vertices[ j ].setFromMatrixPosition( boneMatrix );
  24087. boneMatrix.multiplyMatrices( matrixWorldInv, bone.parent.matrixWorld );
  24088. geometry.vertices[ j + 1 ].setFromMatrixPosition( boneMatrix );
  24089. j += 2;
  24090. }
  24091. }
  24092. geometry.verticesNeedUpdate = true;
  24093. geometry.computeBoundingSphere();
  24094. };
  24095. // File:src/extras/helpers/SpotLightHelper.js
  24096. /**
  24097. * @author alteredq / http://alteredqualia.com/
  24098. * @author mrdoob / http://mrdoob.com/
  24099. * @author WestLangley / http://github.com/WestLangley
  24100. */
  24101. THREE.SpotLightHelper = function ( light ) {
  24102. THREE.Object3D.call( this );
  24103. this.light = light;
  24104. this.light.updateMatrixWorld();
  24105. this.matrix = light.matrixWorld;
  24106. this.matrixAutoUpdate = false;
  24107. var geometry = new THREE.CylinderGeometry( 0, 1, 1, 8, 1, true );
  24108. geometry.translate( 0, - 0.5, 0 );
  24109. geometry.rotateX( - Math.PI / 2 );
  24110. var material = new THREE.MeshBasicMaterial( { wireframe: true, fog: false } );
  24111. this.cone = new THREE.Mesh( geometry, material );
  24112. this.add( this.cone );
  24113. this.update();
  24114. };
  24115. THREE.SpotLightHelper.prototype = Object.create( THREE.Object3D.prototype );
  24116. THREE.SpotLightHelper.prototype.constructor = THREE.SpotLightHelper;
  24117. THREE.SpotLightHelper.prototype.dispose = function () {
  24118. this.cone.geometry.dispose();
  24119. this.cone.material.dispose();
  24120. };
  24121. THREE.SpotLightHelper.prototype.update = function () {
  24122. var vector = new THREE.Vector3();
  24123. var vector2 = new THREE.Vector3();
  24124. return function () {
  24125. var coneLength = this.light.distance ? this.light.distance : 10000;
  24126. var coneWidth = coneLength * Math.tan( this.light.angle );
  24127. this.cone.scale.set( coneWidth, coneWidth, coneLength );
  24128. vector.setFromMatrixPosition( this.light.matrixWorld );
  24129. vector2.setFromMatrixPosition( this.light.target.matrixWorld );
  24130. this.cone.lookAt( vector2.sub( vector ) );
  24131. this.cone.material.color.copy( this.light.color ).multiplyScalar( this.light.intensity );
  24132. };
  24133. }();
  24134. // File:src/extras/helpers/VertexNormalsHelper.js
  24135. /**
  24136. * @author mrdoob / http://mrdoob.com/
  24137. * @author WestLangley / http://github.com/WestLangley
  24138. */
  24139. THREE.VertexNormalsHelper = function ( object, size, hex, linewidth ) {
  24140. this.object = object;
  24141. this.size = ( size !== undefined ) ? size : 1;
  24142. var color = ( hex !== undefined ) ? hex : 0xff0000;
  24143. var width = ( linewidth !== undefined ) ? linewidth : 1;
  24144. //
  24145. var nNormals = 0;
  24146. var objGeometry = this.object.geometry;
  24147. if ( objGeometry instanceof THREE.Geometry ) {
  24148. nNormals = objGeometry.faces.length * 3;
  24149. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24150. nNormals = objGeometry.attributes.normal.count
  24151. }
  24152. //
  24153. var geometry = new THREE.BufferGeometry();
  24154. var positions = new THREE.Float32Attribute( nNormals * 2 * 3, 3 );
  24155. geometry.addAttribute( 'position', positions );
  24156. THREE.LineSegments.call( this, geometry, new THREE.LineBasicMaterial( { color: color, linewidth: width } ) );
  24157. //
  24158. this.matrixAutoUpdate = false;
  24159. this.update();
  24160. };
  24161. THREE.VertexNormalsHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24162. THREE.VertexNormalsHelper.prototype.constructor = THREE.VertexNormalsHelper;
  24163. THREE.VertexNormalsHelper.prototype.update = ( function () {
  24164. var v1 = new THREE.Vector3();
  24165. var v2 = new THREE.Vector3();
  24166. var normalMatrix = new THREE.Matrix3();
  24167. return function update() {
  24168. var keys = [ 'a', 'b', 'c' ];
  24169. this.object.updateMatrixWorld( true );
  24170. normalMatrix.getNormalMatrix( this.object.matrixWorld );
  24171. var matrixWorld = this.object.matrixWorld;
  24172. var position = this.geometry.attributes.position;
  24173. //
  24174. var objGeometry = this.object.geometry;
  24175. if ( objGeometry instanceof THREE.Geometry ) {
  24176. var vertices = objGeometry.vertices;
  24177. var faces = objGeometry.faces;
  24178. var idx = 0;
  24179. for ( var i = 0, l = faces.length; i < l; i ++ ) {
  24180. var face = faces[ i ];
  24181. for ( var j = 0, jl = face.vertexNormals.length; j < jl; j ++ ) {
  24182. var vertex = vertices[ face[ keys[ j ] ] ];
  24183. var normal = face.vertexNormals[ j ];
  24184. v1.copy( vertex ).applyMatrix4( matrixWorld );
  24185. v2.copy( normal ).applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24186. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24187. idx = idx + 1;
  24188. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24189. idx = idx + 1;
  24190. }
  24191. }
  24192. } else if ( objGeometry instanceof THREE.BufferGeometry ) {
  24193. var objPos = objGeometry.attributes.position;
  24194. var objNorm = objGeometry.attributes.normal;
  24195. var idx = 0;
  24196. // for simplicity, ignore index and drawcalls, and render every normal
  24197. for ( var j = 0, jl = objPos.count; j < jl; j ++ ) {
  24198. v1.set( objPos.getX( j ), objPos.getY( j ), objPos.getZ( j ) ).applyMatrix4( matrixWorld );
  24199. v2.set( objNorm.getX( j ), objNorm.getY( j ), objNorm.getZ( j ) );
  24200. v2.applyMatrix3( normalMatrix ).normalize().multiplyScalar( this.size ).add( v1 );
  24201. position.setXYZ( idx, v1.x, v1.y, v1.z );
  24202. idx = idx + 1;
  24203. position.setXYZ( idx, v2.x, v2.y, v2.z );
  24204. idx = idx + 1;
  24205. }
  24206. }
  24207. position.needsUpdate = true;
  24208. return this;
  24209. }
  24210. }() );
  24211. // File:src/extras/helpers/WireframeHelper.js
  24212. /**
  24213. * @author mrdoob / http://mrdoob.com/
  24214. */
  24215. THREE.WireframeHelper = function ( object, hex ) {
  24216. var color = ( hex !== undefined ) ? hex : 0xffffff;
  24217. THREE.LineSegments.call( this, new THREE.WireframeGeometry( object.geometry ), new THREE.LineBasicMaterial( { color: color } ) );
  24218. this.matrix = object.matrixWorld;
  24219. this.matrixAutoUpdate = false;
  24220. };
  24221. THREE.WireframeHelper.prototype = Object.create( THREE.LineSegments.prototype );
  24222. THREE.WireframeHelper.prototype.constructor = THREE.WireframeHelper;
  24223. // File:src/extras/objects/ImmediateRenderObject.js
  24224. /**
  24225. * @author alteredq / http://alteredqualia.com/
  24226. */
  24227. THREE.ImmediateRenderObject = function ( material ) {
  24228. THREE.Object3D.call( this );
  24229. this.material = material;
  24230. this.render = function ( renderCallback ) {};
  24231. };
  24232. THREE.ImmediateRenderObject.prototype = Object.create( THREE.Object3D.prototype );
  24233. THREE.ImmediateRenderObject.prototype.constructor = THREE.ImmediateRenderObject;
  24234. // File:src/extras/objects/MorphBlendMesh.js
  24235. /**
  24236. * @author alteredq / http://alteredqualia.com/
  24237. */
  24238. THREE.MorphBlendMesh = function( geometry, material ) {
  24239. THREE.Mesh.call( this, geometry, material );
  24240. this.animationsMap = {};
  24241. this.animationsList = [];
  24242. // prepare default animation
  24243. // (all frames played together in 1 second)
  24244. var numFrames = this.geometry.morphTargets.length;
  24245. var name = "__default";
  24246. var startFrame = 0;
  24247. var endFrame = numFrames - 1;
  24248. var fps = numFrames / 1;
  24249. this.createAnimation( name, startFrame, endFrame, fps );
  24250. this.setAnimationWeight( name, 1 );
  24251. };
  24252. THREE.MorphBlendMesh.prototype = Object.create( THREE.Mesh.prototype );
  24253. THREE.MorphBlendMesh.prototype.constructor = THREE.MorphBlendMesh;
  24254. THREE.MorphBlendMesh.prototype.createAnimation = function ( name, start, end, fps ) {
  24255. var animation = {
  24256. start: start,
  24257. end: end,
  24258. length: end - start + 1,
  24259. fps: fps,
  24260. duration: ( end - start ) / fps,
  24261. lastFrame: 0,
  24262. currentFrame: 0,
  24263. active: false,
  24264. time: 0,
  24265. direction: 1,
  24266. weight: 1,
  24267. directionBackwards: false,
  24268. mirroredLoop: false
  24269. };
  24270. this.animationsMap[ name ] = animation;
  24271. this.animationsList.push( animation );
  24272. };
  24273. THREE.MorphBlendMesh.prototype.autoCreateAnimations = function ( fps ) {
  24274. var pattern = /([a-z]+)_?(\d+)/i;
  24275. var firstAnimation, frameRanges = {};
  24276. var geometry = this.geometry;
  24277. for ( var i = 0, il = geometry.morphTargets.length; i < il; i ++ ) {
  24278. var morph = geometry.morphTargets[ i ];
  24279. var chunks = morph.name.match( pattern );
  24280. if ( chunks && chunks.length > 1 ) {
  24281. var name = chunks[ 1 ];
  24282. if ( ! frameRanges[ name ] ) frameRanges[ name ] = { start: Infinity, end: - Infinity };
  24283. var range = frameRanges[ name ];
  24284. if ( i < range.start ) range.start = i;
  24285. if ( i > range.end ) range.end = i;
  24286. if ( ! firstAnimation ) firstAnimation = name;
  24287. }
  24288. }
  24289. for ( var name in frameRanges ) {
  24290. var range = frameRanges[ name ];
  24291. this.createAnimation( name, range.start, range.end, fps );
  24292. }
  24293. this.firstAnimation = firstAnimation;
  24294. };
  24295. THREE.MorphBlendMesh.prototype.setAnimationDirectionForward = function ( name ) {
  24296. var animation = this.animationsMap[ name ];
  24297. if ( animation ) {
  24298. animation.direction = 1;
  24299. animation.directionBackwards = false;
  24300. }
  24301. };
  24302. THREE.MorphBlendMesh.prototype.setAnimationDirectionBackward = function ( name ) {
  24303. var animation = this.animationsMap[ name ];
  24304. if ( animation ) {
  24305. animation.direction = - 1;
  24306. animation.directionBackwards = true;
  24307. }
  24308. };
  24309. THREE.MorphBlendMesh.prototype.setAnimationFPS = function ( name, fps ) {
  24310. var animation = this.animationsMap[ name ];
  24311. if ( animation ) {
  24312. animation.fps = fps;
  24313. animation.duration = ( animation.end - animation.start ) / animation.fps;
  24314. }
  24315. };
  24316. THREE.MorphBlendMesh.prototype.setAnimationDuration = function ( name, duration ) {
  24317. var animation = this.animationsMap[ name ];
  24318. if ( animation ) {
  24319. animation.duration = duration;
  24320. animation.fps = ( animation.end - animation.start ) / animation.duration;
  24321. }
  24322. };
  24323. THREE.MorphBlendMesh.prototype.setAnimationWeight = function ( name, weight ) {
  24324. var animation = this.animationsMap[ name ];
  24325. if ( animation ) {
  24326. animation.weight = weight;
  24327. }
  24328. };
  24329. THREE.MorphBlendMesh.prototype.setAnimationTime = function ( name, time ) {
  24330. var animation = this.animationsMap[ name ];
  24331. if ( animation ) {
  24332. animation.time = time;
  24333. }
  24334. };
  24335. THREE.MorphBlendMesh.prototype.getAnimationTime = function ( name ) {
  24336. var time = 0;
  24337. var animation = this.animationsMap[ name ];
  24338. if ( animation ) {
  24339. time = animation.time;
  24340. }
  24341. return time;
  24342. };
  24343. THREE.MorphBlendMesh.prototype.getAnimationDuration = function ( name ) {
  24344. var duration = - 1;
  24345. var animation = this.animationsMap[ name ];
  24346. if ( animation ) {
  24347. duration = animation.duration;
  24348. }
  24349. return duration;
  24350. };
  24351. THREE.MorphBlendMesh.prototype.playAnimation = function ( name ) {
  24352. var animation = this.animationsMap[ name ];
  24353. if ( animation ) {
  24354. animation.time = 0;
  24355. animation.active = true;
  24356. } else {
  24357. console.warn( "THREE.MorphBlendMesh: animation[" + name + "] undefined in .playAnimation()" );
  24358. }
  24359. };
  24360. THREE.MorphBlendMesh.prototype.stopAnimation = function ( name ) {
  24361. var animation = this.animationsMap[ name ];
  24362. if ( animation ) {
  24363. animation.active = false;
  24364. }
  24365. };
  24366. THREE.MorphBlendMesh.prototype.update = function ( delta ) {
  24367. for ( var i = 0, il = this.animationsList.length; i < il; i ++ ) {
  24368. var animation = this.animationsList[ i ];
  24369. if ( ! animation.active ) continue;
  24370. var frameTime = animation.duration / animation.length;
  24371. animation.time += animation.direction * delta;
  24372. if ( animation.mirroredLoop ) {
  24373. if ( animation.time > animation.duration || animation.time < 0 ) {
  24374. animation.direction *= - 1;
  24375. if ( animation.time > animation.duration ) {
  24376. animation.time = animation.duration;
  24377. animation.directionBackwards = true;
  24378. }
  24379. if ( animation.time < 0 ) {
  24380. animation.time = 0;
  24381. animation.directionBackwards = false;
  24382. }
  24383. }
  24384. } else {
  24385. animation.time = animation.time % animation.duration;
  24386. if ( animation.time < 0 ) animation.time += animation.duration;
  24387. }
  24388. var keyframe = animation.start + THREE.Math.clamp( Math.floor( animation.time / frameTime ), 0, animation.length - 1 );
  24389. var weight = animation.weight;
  24390. if ( keyframe !== animation.currentFrame ) {
  24391. this.morphTargetInfluences[ animation.lastFrame ] = 0;
  24392. this.morphTargetInfluences[ animation.currentFrame ] = 1 * weight;
  24393. this.morphTargetInfluences[ keyframe ] = 0;
  24394. animation.lastFrame = animation.currentFrame;
  24395. animation.currentFrame = keyframe;
  24396. }
  24397. var mix = ( animation.time % frameTime ) / frameTime;
  24398. if ( animation.directionBackwards ) mix = 1 - mix;
  24399. if ( animation.currentFrame !== animation.lastFrame ) {
  24400. this.morphTargetInfluences[ animation.currentFrame ] = mix * weight;
  24401. this.morphTargetInfluences[ animation.lastFrame ] = ( 1 - mix ) * weight;
  24402. } else {
  24403. this.morphTargetInfluences[ animation.currentFrame ] = weight;
  24404. }
  24405. }
  24406. };